static void skipNullHeader(final ImageInputStream pStream) throws IOException { // NOTE: Only skip if FILE FORMAT, not needed for Mac OS DnD // Spec says "platform dependent", may not be all nulls.. pStream.skipBytes(PICT.PICT_NULL_HEADER_SIZE); }
/** * This default implementation simply skips the data. * * @param pInput the input * @throws IOException if an I/O exception occurs */ protected void readData(final ImageInputStream pInput) throws IOException { // TODO: This design is ugly, as subclasses readData is invoked BEFORE their respective constructor... pInput.skipBytes(size); }
public long skip(long pLength) throws IOException { long skipped = input.skipBytes(findMaxLen(pLength)); // Skips 0 or more, never -1 left -= skipped; return skipped; } }
private void initReader(final int pIndex) throws IOException { init(); String name = catalog.getStreamName(pIndex); Entry entry = root.getChildEntry(name); // TODO: It might be possible to speed this up, with less wrapping... // Use in-memory input stream for max speed, images are small ImageInputStream input = new MemoryCacheImageInputStream(entry.getInputStream()); input.skipBytes(THUMBNAIL_OFFSET); reader.setInput(input); }
pStream.skipBytes(nullBytes);
PSDGlobalLayerMask(final ImageInputStream pInput, final long globalLayerMaskLength) throws IOException { colorSpace = pInput.readUnsignedShort(); // Undocumented pInput.readFully(colors, 0, colors.length); opacity = pInput.readUnsignedShort(); // 0-100 // Kind: 0: Selected (ie inverted), 1: Color protected, 128: Use value stored per layer (actually, the value is 80, not 0x80) kind = pInput.readUnsignedByte(); // Skip "Variable: Filler zeros" pInput.skipBytes(globalLayerMaskLength - 17); }
@Override protected void readData(final ImageInputStream pInput) throws IOException { version = pInput.readUnsignedShort(); cropMasks = pInput.readBoolean(); field = pInput.readUnsignedByte(); // TODO: Is this really pad? bleedWidth = pInput.readUnsignedInt(); bleedScale = pInput.readUnsignedShort(); pInput.skipBytes(size - 10); }
imageInput.skipBytes(rowDataByte.length);
private Raster readMask(final IconResource resource) throws IOException { Dimension size = resource.size(); int width = size.width; int height = size.height; byte[] mask = new byte[width * height]; imageInput.seek(resource.start + ICNS.RESOURCE_HEADER_SIZE); if (resource.isMaskType()) { // 8 bit mask imageInput.readFully(mask, 0, resource.length - ICNS.RESOURCE_HEADER_SIZE); } else if (resource.hasMask()) { // Embedded 1bit mask byte[] maskData = new byte[(resource.length - ICNS.RESOURCE_HEADER_SIZE) / 2]; imageInput.skipBytes(maskData.length); // Skip the 1 bit image data imageInput.readFully(maskData); // Unpack 1bit mask to 8 bit int bitPos = 0x80; for (int i = 0, maskLength = mask.length; i < maskLength; i++) { mask[i] = (byte) ((maskData[i / 8] & bitPos) != 0 ? 0xff : 0x00); if ((bitPos >>= 1) == 0) { bitPos = 0x80; } } } else { throw new IllegalArgumentException(String.format("Not a mask resource: %s", resource)); } return Raster.createBandedRaster(new DataBufferByte(mask, mask.length), width, height, width, new int[]{0}, new int[]{0}, null); }
private void readRowByte(int height, Rectangle srcRegion, int[] scanlineOffsets, int[] scanlineLengths, int compression, int xSub, int ySub, int c, byte[] rowDataByte, WritableRaster destChannel, Raster srcChannel, int y) throws IOException { // If subsampled or outside source region, skip entire row if (y % ySub != 0 || height - 1 - y < srcRegion.y || height - 1 - y >= srcRegion.y + srcRegion.height) { if (compression == SGI.COMPRESSION_NONE) { imageInput.skipBytes(rowDataByte.length); } return; } // Wrap input DataInput input; if (compression == SGI.COMPRESSION_RLE) { int scanLineIndex = c * height + y; imageInput.seek(scanlineOffsets[scanLineIndex]); input = new DataInputStream(new DecoderStream(IIOUtil.createStreamAdapter(imageInput, scanlineLengths[scanLineIndex]), new RLEDecoder())); } else { input = imageInput; } input.readFully(rowDataByte, 0, rowDataByte.length); // Subsample horizontal if (xSub != 1) { for (int x = 0; x < srcRegion.width / xSub; x++) { rowDataByte[srcRegion.x + x] = rowDataByte[srcRegion.x + x * xSub]; } } normalize(rowDataByte, 9, srcRegion.width / xSub); // Flip into position (SGI images are stored bottom/up) int dstY = (height - 1 - y - srcRegion.y) / ySub; destChannel.setDataElements(0, dstY, srcChannel); }
@Override protected void readData(final ImageInputStream pInput) throws IOException { labels = pInput.readBoolean(); cropMasks = pInput.readBoolean(); colorBars = pInput.readBoolean(); registrationMarks = pInput.readBoolean(); negative = pInput.readBoolean(); flip = pInput.readBoolean(); interpolate = pInput.readBoolean(); // Photoshop 2.5 and before has shorter struct if (size > 7) { caption = pInput.readBoolean(); pInput.skipBytes(size - 8); } }
imageInput.skipBytes(length);
private void readRowUShort(int height, Rectangle srcRegion, int[] scanlineOffsets, int[] scanlineLengths, int compression, int xSub, int ySub, int c, short[] rowDataUShort, WritableRaster destChannel, Raster srcChannel, int y) throws IOException { // If subsampled or outside source region, skip entire row if (y % ySub != 0 || height - 1 - y < srcRegion.y || height - 1 - y >= srcRegion.y + srcRegion.height) { if (compression == SGI.COMPRESSION_NONE) { imageInput.skipBytes(rowDataUShort.length * 2); } return; } // Wrap input DataInput input; if (compression == SGI.COMPRESSION_RLE) { int scanLineIndex = c * height + y; imageInput.seek(scanlineOffsets[scanLineIndex]); input = new DataInputStream(new DecoderStream(IIOUtil.createStreamAdapter(imageInput, scanlineLengths[scanLineIndex]), new RLEDecoder())); } else { input = imageInput; } readFully(input, rowDataUShort); // Subsample horizontal if (xSub != 1) { for (int x = 0; x < srcRegion.width / xSub; x++) { rowDataUShort[srcRegion.x + x] = rowDataUShort[srcRegion.x + x * xSub]; } } normalize(rowDataUShort, 9, srcRegion.width / xSub); // Flip into position (SGI images are stored bottom/up) int dstY = (height - 1 - y - srcRegion.y) / ySub; destChannel.setDataElements(0, dstY, srcChannel); }
private static void skipToEnd(final ImageInputStream stream) throws IOException { if (stream.length() > 0) { // Seek to end of file stream.seek(stream.length()); } else { // Skip to end long lastGood = stream.getStreamPosition(); while (stream.read() != -1) { lastGood = stream.getStreamPosition(); stream.skipBytes(1024); } stream.seek(lastGood); while (true) { if (stream.read() == -1) { break; } // Just continue reading to EOF... } } }
private static long skipToEOF(final ImageInputStream stream) throws IOException { long length = stream.length(); if (length > 0) { // Known length, skip there and we're done. stream.seek(length); } else { // Otherwise, seek to EOF the hard way. // First, store stream position... long pos = stream.getStreamPosition(); // ...skip 1k blocks until we're passed EOF... while (stream.skipBytes(1024L) > 0) { if (stream.read() == -1) { break; } pos = stream.getStreamPosition(); } // ...go back to last known pos... stream.seek(pos); // ...finally seek until EOF one byte at a time. Done. while (stream.read() != -1) { } } return stream.getStreamPosition(); }
extensions.jobId = readString(stream, 41); stream.skipBytes(6); // Job time, 3 shorts, hours/minutes/seconds elapsed
@Override protected void readData(ImageInputStream pInput) throws IOException { if (size % 14 != 0) { throw new IIOException("Display info length expected to be mod 14: " + size); } // long left = size; // while (left > 0) { colorSpace = pInput.readShort(); // Color[4]...? colors = new short[4]; colors[0] = pInput.readShort(); colors[1] = pInput.readShort(); colors[2] = pInput.readShort(); colors[3] = pInput.readShort(); opacity = pInput.readShort(); kind = pInput.readByte(); pInput.readByte(); // Pad // left -= 14; // } pInput.skipBytes(size - 14); }
imageInput.skipBytes(404);
int offset = (pBitmap.getHeight() - y - 1) * scanlineStride; imageInput.readFully(pixels, offset, scanlineStride); imageInput.skipBytes(rowSizeBytes - scanlineStride);
@Test public void testRead() throws IOException { ImageInputStream wrapped = createStream(42); wrapped.skipBytes(13); ImageInputStream stream = new SubImageInputStream(wrapped, 27); assertEquals(0, stream.getStreamPosition()); assertEquals(27, stream.length()); stream.read(); assertEquals(1, stream.getStreamPosition()); assertEquals(27, stream.length()); stream.readFully(new byte[11]); assertEquals(12, stream.getStreamPosition()); assertEquals(27, stream.length()); assertEquals(25, wrapped.getStreamPosition()); }