public void seek() throws IOException { data.seek(offset); }
private void initBoolDecoder() throws IOException { value = 0; /* value = first 16 input bits */ data.seek(offset); value = data.readUnsignedByte() << 8; // value = (data[offset]) << 8; offset++; range = 255; /* initial range is full */ bit_count = 0; /* have not yet shifted out any bits */ }
private int readPartitionSize(long l) throws IOException { frame.seek(l); int size =frame.readUnsignedByte() + (frame.readUnsignedByte() << 8) + (frame.readUnsignedByte() << 16); return size; } private int readSubBlockMode(BoolDecoder bc, int A, int L) throws IOException {
segmentQuants = new SegmentQuants(); int c; frame.seek(offset++); c=frame.readUnsignedByte(); frameType = getBitAsInt(c, 0); if(frameType!=0) firstPartitionLengthInBytes += getBitAsInt(c, 6) << 1; firstPartitionLengthInBytes += getBitAsInt(c, 7) << 2; frame.seek(offset++); c=frame.readUnsignedByte(); firstPartitionLengthInBytes += c << 3; frame.seek(offset++); c=frame.readUnsignedByte(); firstPartitionLengthInBytes += c << 11; frame.seek(offset++); c=frame.readUnsignedByte(); frame.seek(offset++); c=frame.readUnsignedByte(); frame.seek(offset++); c=frame.readUnsignedByte(); frame.seek(offset++); c=frame.readUnsignedByte(); int hBytes = c; frame.seek(offset++); c=frame.readUnsignedByte(); hBytes += c << 8; width = (hBytes & 0x3fff); frame.seek(offset++); c=frame.readUnsignedByte(); int vBytes = c; frame.seek(offset++); c=frame.readUnsignedByte(); vBytes += c << 8; height = (vBytes & 0x3fff);
/** * Marks this stream as closed. * This implementation does <em>not</em> close the underlying stream. */ public void close() throws IOException { if (hasLength) { input.seek(input.getStreamPosition() + left); } left = 0; input = null; }
public void reset() throws IOException { long diff = input.getStreamPosition() - markPosition; input.seek(markPosition); left += diff; }
private DIBHeader getHeader(final DirectoryEntry pEntry) throws IOException { if (!headers.containsKey(pEntry)) { imageInput.seek(pEntry.getOffset()); DIBHeader header = DIBHeader.read(imageInput); headers.put(pEntry, header); } return headers.get(pEntry); }
private void writeData(ImageInputStream input, ImageOutputStream output, long offset, long length) throws IOException { input.seek(offset); byte[] buffer = new byte[(int) length]; stream.readFully(buffer); output.write(buffer); }
private ImageReader initReaderDelegate(int compression) throws IOException { ImageReader reader = getImageReaderDelegate(compression); imageInput.seek(pixelOffset); reader.setInput(new SubImageInputStream(imageInput, header.getImageSize())); return reader; }
private ImageReader initPNGReader(final DirectoryEntry pEntry) throws IOException { ImageReader pngReader = getPNGReader(); imageInput.seek(pEntry.getOffset()); // InputStream inputStream = IIOUtil.createStreamAdapter(imageInput, pEntry.getSize()); // ImageInputStream stream = ImageIO.createImageInputStream(inputStream); ImageInputStream stream = new SubImageInputStream(imageInput, pEntry.getSize()); // NOTE: Will throw IOException on later reads if input is not PNG pngReader.setInput(stream); return pngReader; }
private void initIndex(final int imageIndex) throws IOException { checkBounds(imageIndex); if (index != imageIndex) { imageInput.seek(header.getOffset(imageIndex)); index = imageIndex; readerDelegate.setInput(new SubImageInputStream(imageInput, Long.MAX_VALUE)); } }
private void readBody(final ImageReadParam pParam) throws IOException { imageInput.seek(bodyStart); byteRunStream = null; // NOTE: colorMap may be null for 8 bit (gray), 24 bit or 32 bit only if (colorMap != null) { IndexColorModel cm = colorMap.getIndexColorModel(header, isEHB()); readIndexed(pParam, imageInput, cm); } else { readTrueColor(pParam, imageInput); } }
private void readeFileHeader() throws IOException { assertInput(); if (length <= 0) { imageInput.seek(0); if (imageInput.readInt() != ICNS.MAGIC) { throw new IIOException("Not an Apple Icon Image"); } length = imageInput.readInt(); } }
private void readHeader() throws IOException { assertInput(); if (header == null) { imageInput.setByteOrder(ByteOrder.LITTLE_ENDIAN); header = DCXHeader.read(imageInput); if (DEBUG) { System.err.println("header: " + header); } imageInput.flushBefore(imageInput.getStreamPosition()); } imageInput.seek(imageInput.getFlushedPosition()); }
@Test public void testPhotoshopResourcePHUT() throws IOException { // Test sample contains non-8BIM resource: PHUT (PhotoDeluxe) try (ImageInputStream stream = ImageIO.createImageInputStream(getResource("/psd/friends-phut-resource.jpg"))) { stream.seek(38); Directory directory = createReader().read(new SubImageInputStream(stream, 298)); assertEquals(9, directory.size()); // 6 8BIM + 2 PHUT + 1 8 BIM } } }
@Test public void testSeekAfterEOF() throws IOException { ImageInputStream stream = new SubImageInputStream(createStream(7), 5); stream.seek(6); assertEquals(-1, stream.read()); }
@Test public void testReadBadDataZeroCount() throws IOException { // This image seems to contain bad Exif. But as other tools are able to read, so should we.. ImageInputStream stream = ImageIO.createImageInputStream(getResource("/jpeg/exif-rgb-thumbnail-bad-exif-kodak-dc210.jpg")); stream.seek(12); Directory directory = createReader().read(new SubImageInputStream(stream, 21674)); assertEquals(22, directory.size()); // Special case: Ascii string with count == 0, not ok according to spec (?), but we'll let it pass assertEquals("", directory.getEntryById(TIFF.TAG_IMAGE_DESCRIPTION).getValue()); }
@Test public void testReadBadDataZeroCount() throws IOException { // This image seems to contain bad Exif. But as other tools are able to read, so should we.. ImageInputStream stream = ImageIO.createImageInputStream(getResource("/jpeg/exif-rgb-thumbnail-bad-exif-kodak-dc210.jpg")); stream.seek(12); Directory directory = createReader().read(new SubImageInputStream(stream, 21674)); assertEquals(22, directory.size()); // Special case: Ascii string with count == 0, not ok according to spec (?), but we'll let it pass assertEquals("", directory.getEntryById(TIFF.TAG_IMAGE_DESCRIPTION).getValue()); }
@Test public void testReadBadDataRationalZeroDenominator() throws IOException { // This image seems to contain bad Exif. But as other tools are able to read, so should we.. ImageInputStream stream = ImageIO.createImageInputStream(getResource("/jpeg/exif-rgb-thumbnail-bad-exif-kodak-dc210.jpg")); stream.seek(12); Directory directory = createReader().read(new SubImageInputStream(stream, 21674)); // Special case: Rational with zero-denominator inside EXIF data Directory exif = (Directory) directory.getEntryById(TIFF.TAG_EXIF_IFD).getValue(); Entry entry = exif.getEntryById(EXIF.TAG_COMPRESSED_BITS_PER_PIXEL); assertNotNull(entry); assertEquals(Rational.NaN, entry.getValue()); }
@Test public void testReadBadDirectoryCount() throws IOException { // This image seems to contain bad Exif. But as other tools are able to read, so should we.. ImageInputStream stream = ImageIO.createImageInputStream(getResource("/jpeg/exif-bad-directory-entry-count.jpg")); stream.seek(4424 + 10); Directory directory = createReader().read(new SubImageInputStream(stream, 214 - 6)); assertEquals(7, directory.size()); // TIFF structure says 8, but the last entry isn't there Directory exif = (Directory) directory.getEntryById(TIFF.TAG_EXIF_IFD).getValue(); assertNotNull(exif); assertEquals(3, exif.size()); }