/** * SWT does not support 16-bit depths. If this image uses * 16-bit depths, convert the data to an 8-bit depth. */ byte[] validateBitDepth(byte[] data) { if (headerChunk.getBitDepth() > 8) { byte[] result = new byte[data.length / 2]; compress16BitDepthTo8BitDepth(data, 0, result, 0, result.length); return result; } else { return data; } } /**
/** * Read the pixel data for a non-interlaced image from the * data stream. * Update the imageData to reflect the new data. */ void readNonInterlacedImage(InputStream inputStream) throws IOException { int dataOffset = 0; int alignedBytesPerRow = getAlignedBytesPerRow(); int bytesPerRow = getBytesPerRow(); byte[] row1 = new byte[bytesPerRow]; byte[] row2 = new byte[bytesPerRow]; byte[] currentRow = row1; byte[] lastRow = row2; int height = headerChunk.getHeight(); for (int row = 0; row < height; row++) { byte filterType = (byte)inputStream.read(); int read = 0; while (read != bytesPerRow) { read += inputStream.read(currentRow, read, bytesPerRow - read); } filterRow(currentRow, lastRow, filterType); System.arraycopy(currentRow, 0, data, dataOffset, bytesPerRow); dataOffset += alignedBytesPerRow; currentRow = (currentRow == row1) ? row2 : row1; lastRow = (lastRow == row1) ? row2 : row1; } setImageDataValues(data, imageData); } /**
/** * Read the pixel data for an interlaced image from the * data stream. */ void readInterlacedImage(InputStream inputStream) throws IOException { readInterlaceFrame(inputStream, 8, 8, 0, 0, 0); readInterlaceFrame(inputStream, 8, 8, 0, 4, 1); readInterlaceFrame(inputStream, 8, 4, 4, 0, 2); readInterlaceFrame(inputStream, 4, 4, 0, 2, 3); readInterlaceFrame(inputStream, 4, 2, 2, 0, 4); readInterlaceFrame(inputStream, 2, 2, 0, 1, 5); readInterlaceFrame(inputStream, 2, 1, 1, 0, 6); } /**
int alignedBytesPerRow = getAlignedBytesPerRow(); int height = headerChunk.getHeight(); if (startRow >= height || startColumn >= width) return; int bytesPerRow = getBytesPerRow(pixelsPerRow); byte[] row1 = new byte[bytesPerRow]; byte[] row2 = new byte[bytesPerRow]; read += inputStream.read(currentRow, read, bytesPerRow - read); filterRow(currentRow, lastRow, filterType); if (headerChunk.getBitDepth() >= 8) { int bytesPerPixel = getBytesPerPixel(); int dataOffset = (row * alignedBytesPerRow) + (startColumn * bytesPerPixel); for (int rowOffset = 0; rowOffset < currentRow.length; rowOffset += bytesPerPixel) { lastRow = (lastRow == row1) ? row2 : row1; setImageDataValues(data, imageData); fireInterlacedFrameEvent(frameCount);
readSignature(); PngChunkReader chunkReader = new PngChunkReader(inputStream); headerChunk = chunkReader.getIhdrChunk(); int width = headerChunk.getWidth(), height = headerChunk.getHeight(); if (width <= 0 || height <= 0) SWT.error(SWT.ERROR_INVALID_IMAGE); int imageSize = getAlignedBytesPerRow() * height; data = new byte[imageSize]; imageData = ImageData.internal_new( readNextChunk(chunkReader);
/** * Read the image data from the data stream. This must handle * decoding the data, filtering, and interlacing. */ @SuppressWarnings("resource") void readPixelData(PngIdatChunk chunk, PngChunkReader chunkReader) throws IOException { InputStream stream = new PngInputStream(chunk, chunkReader); //TEMPORARY CODE boolean use3_2 = System.getProperty("org.eclipse.swt.internal.image.PNGFileFormat_3.2") != null; InputStream inflaterStream = use3_2 ? null : new BufferedInputStream(new InflaterInputStream(stream)); if (inflaterStream != null) { stream = inflaterStream; } else { stream = new PngDecodingDataStream(stream); } int interlaceMethod = headerChunk.getInterlaceMethod(); if (interlaceMethod == PngIhdrChunk.INTERLACE_METHOD_NONE) { readNonInterlacedImage(stream); } else { readInterlacedImage(stream); } /* * InflaterInputStream does not consume all bytes in the stream * when it is closed. This may leave unread IDAT chunks. The fix * is to read all available bytes before closing it. */ while (stream.available() > 0) stream.read(); stream.close(); } /**
/** * Answer the number of bytes in a word-aligned row of pixel data. */ int getAlignedBytesPerRow() { return ((getBytesPerRow(headerChunk.getWidth()) + 3) / 4) * 4; } /**
int srcBytesPerLine = getAlignedBytesPerRow(); if (headerChunk.getBitDepth() > 8) srcBytesPerLine /= 2; int height = imageData.height; int destBytesPerLine = imageData.bytesPerLine; int srcBytesPerLine = getAlignedBytesPerRow(); int height = imageData.height; int destBytesPerLine = imageData.bytesPerLine; int srcBytesPerLine = getAlignedBytesPerRow();
int alignedBytesPerRow = getAlignedBytesPerRow(); int height = headerChunk.getHeight(); if (startRow >= height || startColumn >= width) return; int bytesPerRow = getBytesPerRow(pixelsPerRow); byte[] row1 = new byte[bytesPerRow]; byte[] row2 = new byte[bytesPerRow]; read += inputStream.read(currentRow, read, bytesPerRow - read); filterRow(currentRow, lastRow, filterType); if (headerChunk.getBitDepth() >= 8) { int bytesPerPixel = getBytesPerPixel(); int dataOffset = (row * alignedBytesPerRow) + (startColumn * bytesPerPixel); for (int rowOffset = 0; rowOffset < currentRow.length; rowOffset += bytesPerPixel) { lastRow = (lastRow == row1) ? row2 : row1; setImageDataValues(data, imageData); fireInterlacedFrameEvent(frameCount);
ImageData[] loadFromByteStream() { try { readSignature(); PngChunkReader chunkReader = new PngChunkReader(inputStream); headerChunk = chunkReader.getIhdrChunk(); int width = headerChunk.getWidth(), height = headerChunk.getHeight(); if (width <= 0 || height <= 0) SWT.error(SWT.ERROR_INVALID_IMAGE); int imageSize = getAlignedBytesPerRow() * height; data = new byte[imageSize]; imageData = ImageData.internal_new( readNextChunk(chunkReader);
/** * Read the image data from the data stream. This must handle * decoding the data, filtering, and interlacing. */ @SuppressWarnings("resource") void readPixelData(PngIdatChunk chunk, PngChunkReader chunkReader) throws IOException { InputStream stream = new PngInputStream(chunk, chunkReader); //TEMPORARY CODE boolean use3_2 = System.getProperty("org.eclipse.swt.internal.image.PNGFileFormat_3.2") != null; InputStream inflaterStream = use3_2 ? null : new BufferedInputStream(new InflaterInputStream(stream)); if (inflaterStream != null) { stream = inflaterStream; } else { stream = new PngDecodingDataStream(stream); } int interlaceMethod = headerChunk.getInterlaceMethod(); if (interlaceMethod == PngIhdrChunk.INTERLACE_METHOD_NONE) { readNonInterlacedImage(stream); } else { readInterlacedImage(stream); } /* * InflaterInputStream does not consume all bytes in the stream * when it is closed. This may leave unread IDAT chunks. The fix * is to read all available bytes before closing it. */ while (stream.available() > 0) stream.read(); stream.close(); } /**
/** * Answer the number of bytes in each row of the image * data. Each PNG row is byte-aligned, so images with bit * depths less than a byte may have unused bits at the * end of each row. The value of these bits is undefined. */ int getBytesPerRow() { return getBytesPerRow(headerChunk.getWidth()); } /**
int srcBytesPerLine = getAlignedBytesPerRow(); if (headerChunk.getBitDepth() > 8) srcBytesPerLine /= 2; int height = imageData.height; int destBytesPerLine = imageData.bytesPerLine; int srcBytesPerLine = getAlignedBytesPerRow(); int height = imageData.height; int destBytesPerLine = imageData.bytesPerLine; int srcBytesPerLine = getAlignedBytesPerRow();
int alignedBytesPerRow = getAlignedBytesPerRow(); int height = headerChunk.getHeight(); if (startRow >= height || startColumn >= width) return; int bytesPerRow = getBytesPerRow(pixelsPerRow); byte[] row1 = new byte[bytesPerRow]; byte[] row2 = new byte[bytesPerRow]; read += inputStream.read(currentRow, read, bytesPerRow - read); filterRow(currentRow, lastRow, filterType); if (headerChunk.getBitDepth() >= 8) { int bytesPerPixel = getBytesPerPixel(); int dataOffset = (row * alignedBytesPerRow) + (startColumn * bytesPerPixel); for (int rowOffset = 0; rowOffset < currentRow.length; rowOffset += bytesPerPixel) { lastRow = (lastRow == row1) ? row2 : row1; setImageDataValues(data, imageData); fireInterlacedFrameEvent(frameCount);
/** * Read the pixel data for a non-interlaced image from the * data stream. * Update the imageData to reflect the new data. */ void readNonInterlacedImage(InputStream inputStream) throws IOException { int dataOffset = 0; int alignedBytesPerRow = getAlignedBytesPerRow(); int bytesPerRow = getBytesPerRow(); byte[] row1 = new byte[bytesPerRow]; byte[] row2 = new byte[bytesPerRow]; byte[] currentRow = row1; byte[] lastRow = row2; int height = headerChunk.getHeight(); for (int row = 0; row < height; row++) { byte filterType = (byte)inputStream.read(); int read = 0; while (read != bytesPerRow) { read += inputStream.read(currentRow, read, bytesPerRow - read); } filterRow(currentRow, lastRow, filterType); System.arraycopy(currentRow, 0, data, dataOffset, bytesPerRow); dataOffset += alignedBytesPerRow; currentRow = (currentRow == row1) ? row2 : row1; lastRow = (lastRow == row1) ? row2 : row1; } setImageDataValues(data, imageData); } /**
ImageData[] loadFromByteStream() { try { readSignature(); PngChunkReader chunkReader = new PngChunkReader(inputStream); headerChunk = chunkReader.getIhdrChunk(); int width = headerChunk.getWidth(), height = headerChunk.getHeight(); if (width <= 0 || height <= 0) SWT.error(SWT.ERROR_INVALID_IMAGE); int imageSize = getAlignedBytesPerRow() * height; data = new byte[imageSize]; imageData = ImageData.internal_new( readNextChunk(chunkReader);
/** * Read the image data from the data stream. This must handle * decoding the data, filtering, and interlacing. */ @SuppressWarnings("resource") void readPixelData(PngIdatChunk chunk, PngChunkReader chunkReader) throws IOException { InputStream stream = new PngInputStream(chunk, chunkReader); //TEMPORARY CODE boolean use3_2 = System.getProperty("org.eclipse.swt.internal.image.PNGFileFormat_3.2") != null; InputStream inflaterStream = use3_2 ? null : new BufferedInputStream(new InflaterInputStream(stream)); if (inflaterStream != null) { stream = inflaterStream; } else { stream = new PngDecodingDataStream(stream); } int interlaceMethod = headerChunk.getInterlaceMethod(); if (interlaceMethod == PngIhdrChunk.INTERLACE_METHOD_NONE) { readNonInterlacedImage(stream); } else { readInterlacedImage(stream); } /* * InflaterInputStream does not consume all bytes in the stream * when it is closed. This may leave unread IDAT chunks. The fix * is to read all available bytes before closing it. */ while (stream.available() > 0) stream.read(); stream.close(); } /**
/** * Answer the number of bytes in a word-aligned row of pixel data. */ int getAlignedBytesPerRow() { return ((getBytesPerRow(headerChunk.getWidth()) + 3) / 4) * 4; } /**
/** * SWT does not support 16-bit depths. If this image uses * 16-bit depths, convert the data to an 8-bit depth. */ byte[] validateBitDepth(byte[] data) { if (headerChunk.getBitDepth() > 8) { byte[] result = new byte[data.length / 2]; compress16BitDepthTo8BitDepth(data, 0, result, 0, result.length); return result; } else { return data; } } /**
/** * Read the pixel data for an interlaced image from the * data stream. */ void readInterlacedImage(InputStream inputStream) throws IOException { readInterlaceFrame(inputStream, 8, 8, 0, 0, 0); readInterlaceFrame(inputStream, 8, 8, 0, 4, 1); readInterlaceFrame(inputStream, 8, 4, 4, 0, 2); readInterlaceFrame(inputStream, 4, 4, 0, 2, 3); readInterlaceFrame(inputStream, 4, 2, 2, 0, 4); readInterlaceFrame(inputStream, 2, 2, 0, 1, 5); readInterlaceFrame(inputStream, 2, 1, 1, 0, 6); } /**