public TIFFRandomFileAccess(LEDataInputStream stream) { inputStream = stream; start = current = next = inputStream.getPosition(); buffers = new byte[LIST_SIZE][]; }
/** * Don't imitate the JDK behaviour of reading a random number * of bytes when you can actually read them all. */ public int read(byte b[], int off, int len) throws IOException { int read = 0, count; while (read != len && (count = readData(b, off, len - read)) != -1) { off += count; read += count; } position += read; if (read == 0 && read != len) return -1; return read; }
int[][] loadIconHeaders(int numIcons) { int[][] headers = new int[numIcons][7]; try { for (int i = 0; i < numIcons; i++) { headers[i][0] = inputStream.read(); headers[i][1] = inputStream.read(); headers[i][2] = inputStream.readShort(); headers[i][3] = inputStream.readShort(); headers[i][4] = inputStream.readShort(); headers[i][5] = inputStream.readInt(); headers[i][6] = inputStream.readInt(); } } catch (IOException e) { SWT.error(SWT.ERROR_IO, e); } return headers; } byte[] loadInfoHeader(int[] iconHeader) {
int[] loadFileHeader() { int[] header = new int[5]; try { header[0] = inputStream.readShort(); header[1] = inputStream.readInt(); header[2] = inputStream.readShort(); header[3] = inputStream.readShort(); header[4] = inputStream.readInt(); } catch (IOException e) { SWT.error(SWT.ERROR_IO, e); } if (header[0] != 0x4D42) SWT.error(SWT.ERROR_INVALID_IMAGE); return header; } @Override
(numColors != 32) && (numColors != 256)) SWT.error(SWT.ERROR_INVALID_IMAGE); if (inputStream.getPosition() < iconHeader[6]) { inputStream.skip(iconHeader[6] - inputStream.getPosition()); } catch (IOException e) { SWT.error(SWT.ERROR_IO, e); inputStream.read(infoHeader); } catch (IOException e) { SWT.error(SWT.ERROR_IO, e);
static void skipSegmentFrom(LEDataInputStream byteStream) { try { byte[] byteArray = new byte[4]; JPEGSegment jpegSegment = new JPEGSegment(byteArray); if (byteStream.read(byteArray) != byteArray.length) { SWT.error(SWT.ERROR_INVALID_IMAGE); } if (!(byteArray[0] == -1 && byteArray[1] != 0 && byteArray[1] != -1)) { SWT.error(SWT.ERROR_INVALID_IMAGE); } int delta = jpegSegment.getSegmentLength() - 2; byteStream.skip(delta); } catch (Exception e) { SWT.error(SWT.ERROR_IO, e); } } void storeData(int[] dataUnit, int iComp, int xmcu, int ymcu, int hi, int ihi, int vi, int ivi) {
/** * Answer a short comprised of the next * two bytes of the input stream. */ public short readShort() throws IOException { byte[] buf = new byte[2]; read(buf); return (short)(((buf[1] & 0xFF) << 8) | (buf[0] & 0xFF)); }
if (inputStream.read(buf) != buf.length) SWT.error(SWT.ERROR_INVALID_IMAGE); } catch (IOException e) { if (this.compression == 3) { try { return new PaletteData(inputStream.readInt(), inputStream.readInt(), inputStream.readInt()); } catch (IOException e) { SWT.error(SWT.ERROR_IO, e); if (this.compression == 3) { try { return new PaletteData(inputStream.readInt(), inputStream.readInt(), inputStream.readInt()); } catch (IOException e) { SWT.error(SWT.ERROR_IO, e);
/** * Read the specified input stream using the specified loader, and * return the device independent image array represented by the stream. */ public static ImageData[] load(InputStream is, ImageLoader loader) { FileFormat fileFormat = null; LEDataInputStream stream = new LEDataInputStream(is); for (int i = 1; i < FORMATS.length; i++) { if (FORMATS[i] != null) { try { fileFormat = getFileFormat (stream, FORMATS[i]); if (fileFormat != null) break; } catch (ClassNotFoundException e) { FORMATS[i] = null; } catch (Exception e) { } } } if (fileFormat == null) SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT); fileFormat.loader = loader; return fileFormat.loadFromStream(stream); }
int loadFileHeader(LEDataInputStream byteStream) { int[] fileHeader = new int[3]; try { fileHeader[0] = byteStream.readShort(); fileHeader[1] = byteStream.readShort(); fileHeader[2] = byteStream.readShort(); } catch (IOException e) { SWT.error(SWT.ERROR_IO, e); } if ((fileHeader[0] != 0) || (fileHeader[1] != 1)) SWT.error(SWT.ERROR_INVALID_IMAGE); int numIcons = fileHeader[2]; if (numIcons <= 0) SWT.error(SWT.ERROR_INVALID_IMAGE); return numIcons; } int loadFileHeader(LEDataInputStream byteStream, boolean hasHeader) {
@Override boolean isFileFormat(LEDataInputStream stream) { try { JPEGStartOfImage soi = new JPEGStartOfImage(stream); stream.unread(soi.reference); return soi.verify(); // we no longer check for appN } catch (Exception e) { return false; } } boolean isZeroInColumn(int[] dataUnit, int col) {
(numColors != 32) && (numColors != 256)) SWT.error(SWT.ERROR_INVALID_IMAGE); if (inputStream.getPosition() < iconHeader[6]) { inputStream.skip(iconHeader[6] - inputStream.getPosition()); } catch (IOException e) { SWT.error(SWT.ERROR_IO, e); inputStream.read(infoHeader); } catch (IOException e) { SWT.error(SWT.ERROR_IO, e);
int[][] loadIconHeaders(int numIcons) { int[][] headers = new int[numIcons][7]; try { for (int i = 0; i < numIcons; i++) { headers[i][0] = inputStream.read(); headers[i][1] = inputStream.read(); headers[i][2] = inputStream.readShort(); headers[i][3] = inputStream.readShort(); headers[i][4] = inputStream.readShort(); headers[i][5] = inputStream.readInt(); headers[i][6] = inputStream.readInt(); } } catch (IOException e) { SWT.error(SWT.ERROR_IO, e); } return headers; } byte[] loadInfoHeader(int[] iconHeader) {
int[] loadFileHeader() { int[] header = new int[5]; try { header[0] = inputStream.readShort(); header[1] = inputStream.readInt(); header[2] = inputStream.readShort(); header[3] = inputStream.readShort(); header[4] = inputStream.readInt(); } catch (IOException e) { SWT.error(SWT.ERROR_IO, e); } if (header[0] != 0x4D42) SWT.error(SWT.ERROR_INVALID_IMAGE); return header; } ImageData[] loadFromByteStream() {
static void skipSegmentFrom(LEDataInputStream byteStream) { try { byte[] byteArray = new byte[4]; JPEGSegment jpegSegment = new JPEGSegment(byteArray); if (byteStream.read(byteArray) != byteArray.length) { SWT.error(SWT.ERROR_INVALID_IMAGE); } if (!(byteArray[0] == -1 && byteArray[1] != 0 && byteArray[1] != -1)) { SWT.error(SWT.ERROR_INVALID_IMAGE); } int delta = jpegSegment.getSegmentLength() - 2; byteStream.skip(delta); } catch (Exception e) { SWT.error(SWT.ERROR_IO, e); } } void storeData(int[] dataUnit, int iComp, int xmcu, int ymcu, int hi, int ihi, int vi, int ivi) {
/** * Skip over signature data. This has already been * verified in isFileFormat(). */ void readSignature() throws IOException { byte[] signature = new byte[SIGNATURE_LENGTH]; inputStream.read(signature); } /**
if (inputStream.read(buf) != buf.length) SWT.error(SWT.ERROR_INVALID_IMAGE); } catch (IOException e) { if (this.compression == 3) { try { return new PaletteData(inputStream.readInt(), inputStream.readInt(), inputStream.readInt()); } catch (IOException e) { SWT.error(SWT.ERROR_IO, e); if (this.compression == 3) { try { return new PaletteData(inputStream.readInt(), inputStream.readInt(), inputStream.readInt()); } catch (IOException e) { SWT.error(SWT.ERROR_IO, e);
/** * Read the specified input stream using the specified loader, and * return the device independent image array represented by the stream. */ public static ImageData[] load(InputStream is, ImageLoader loader) { FileFormat fileFormat = null; LEDataInputStream stream = new LEDataInputStream(is); for (int i = 1; i < FORMATS.length; i++) { if (FORMATS[i] != null) { try { fileFormat = getFileFormat (stream, FORMATS[i]); if (fileFormat != null) break; } catch (ClassNotFoundException e) { FORMATS[i] = null; } catch (Exception e) { } } } if (fileFormat == null) SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT); fileFormat.loader = loader; return fileFormat.loadFromStream(stream); }
int loadFileHeader(LEDataInputStream byteStream) { int[] fileHeader = new int[3]; try { fileHeader[0] = byteStream.readShort(); fileHeader[1] = byteStream.readShort(); fileHeader[2] = byteStream.readShort(); } catch (IOException e) { SWT.error(SWT.ERROR_IO, e); } if ((fileHeader[0] != 0) || (fileHeader[1] != 1)) SWT.error(SWT.ERROR_INVALID_IMAGE); int numIcons = fileHeader[2]; if (numIcons <= 0) SWT.error(SWT.ERROR_INVALID_IMAGE); return numIcons; } int loadFileHeader(LEDataInputStream byteStream, boolean hasHeader) {