Class PNGFileFormat
java.lang.Object
org.eclipse.swt.internal.image.FileFormat
org.eclipse.swt.internal.image.FileFormat.StaticImageFileFormat
org.eclipse.swt.internal.image.PNGFileFormat
-
Nested Class Summary
Nested classes/interfaces inherited from class FileFormat
FileFormat.StaticImageFileFormat -
Field Summary
FieldsModifier and TypeFieldDescription(package private) int(package private) byte[](package private) byte[](package private) byte(package private) byte(package private) PngIhdrChunk(package private) ImageData(package private) PngPlteChunk(package private) static final int(package private) static final intFields inherited from class FileFormat
compression, DEFAULT_ZOOM, inputStream, loader, outputStream -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static voidcompress16BitDepthTo8BitDepth(byte[] source, int sourceOffset, byte[] destination, int destinationOffset, int numberOfValues) SWT does not support 16-bit depth color formats.(package private) static intcompress16BitDepthTo8BitDepth(int value) SWT does not support 16-bit depth color formats.(package private) voidfilterRow(byte[] row, byte[] previousRow, int filterType) PNG supports four filtering types.(package private) voidfireInterlacedFrameEvent(int frameCount) Fire an event to let listeners know that an interlaced frame has been loaded.(package private) intAnswer the number of bytes in a word-aligned row of pixel data.(package private) intAnswer the number of bytes needed to represent a pixel.(package private) intAnswer the number of bytes in each row of the image data.(package private) intgetBytesPerRow(int rowWidthInPixels) Answer the number of bytes in a row of the given pixel width.(package private) booleanisFileFormat(LEDataInputStream stream) Return whether or not the specified input stream represents a supported file format.(package private) ImageData[]Load the PNG image from the byte stream.(package private) voidreadInterlacedImage(InputStream inputStream) Read the pixel data for an interlaced image from the data stream.(package private) voidreadInterlaceFrame(InputStream inputStream, int rowInterval, int columnInterval, int startRow, int startColumn, int frameCount) 1.(package private) voidreadNextChunk(PngChunkReader chunkReader) Read and handle the next chunk of data from the PNG file.(package private) voidreadNonInterlacedImage(InputStream inputStream) Read the pixel data for a non-interlaced image from the data stream.(package private) voidreadPixelData(PngIdatChunk chunk, PngChunkReader chunkReader) Read the image data from the data stream.(package private) voidSkip over signature data.(package private) voidsetImageDataValues(byte[] data, ImageData imageData) PNG supports some color types and bit depths that are unsupported by SWT.(package private) voidsetPixelData(byte[] data, ImageData imageData) SWT does not support greyscale as a color type.(package private) voidunloadIntoByteStream(ImageLoader loader) (package private) byte[]validateBitDepth(byte[] data) SWT does not support 16-bit depths.Methods inherited from class FileFormat.StaticImageFileFormat
loadFromByteStream, loadFromByteStreamBySizeMethods inherited from class FileFormat
canLoadAtZoom, isDynamicallySizableFormat, load, load, loadFromStream, loadFromStreamBySize, save, unloadIntoStream
-
Field Details
-
SIGNATURE_LENGTH
static final int SIGNATURE_LENGTH- See Also:
-
PRIME
static final int PRIME- See Also:
-
headerChunk
PngIhdrChunk headerChunk -
paletteChunk
PngPlteChunk paletteChunk -
imageData
ImageData imageData -
data
byte[] data -
alphaPalette
byte[] alphaPalette -
headerByte1
byte headerByte1 -
headerByte2
byte headerByte2 -
adler
int adler
-
-
Constructor Details
-
PNGFileFormat
public PNGFileFormat()
-
-
Method Details
-
readSignature
Skip over signature data. This has already been verified in isFileFormat().- Throws:
IOException
-
loadFromByteStream
ImageData[] loadFromByteStream()Load the PNG image from the byte stream.- Specified by:
loadFromByteStreamin classFileFormat.StaticImageFileFormat
-
readNextChunk
Read and handle the next chunk of data from the PNG file.- Throws:
IOException
-
unloadIntoByteStream
- Specified by:
unloadIntoByteStreamin classFileFormat
-
isFileFormat
Description copied from class:FileFormatReturn whether or not the specified input stream represents a supported file format.- Specified by:
isFileFormatin classFileFormat- Throws:
IOException
-
validateBitDepth
byte[] validateBitDepth(byte[] data) SWT does not support 16-bit depths. If this image uses 16-bit depths, convert the data to an 8-bit depth. -
setPixelData
SWT does not support greyscale as a color type. For plain grayscale, we create a palette. For Grayscale with Alpha, however, we need to convert the pixels to use RGB values. Note: This method assumes that the bit depth of the data has already been restricted to 8 or less. -
setImageDataValues
PNG supports some color types and bit depths that are unsupported by SWT. If the image uses an unsupported color type (either of the gray scale types) or bit depth (16), convert the data to an SWT-supported format. Then assign the data into the ImageData given. -
readPixelData
Read the image data from the data stream. This must handle decoding the data, filtering, and interlacing.- Throws:
IOException
-
getAlignedBytesPerRow
int getAlignedBytesPerRow()Answer the number of bytes in a word-aligned row of pixel data. -
getBytesPerRow
int getBytesPerRow()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. -
getBytesPerPixel
int getBytesPerPixel()Answer the number of bytes needed to represent a pixel. This value depends on the image's color type and bit depth. Note that this method rounds up if an image's pixel size isn't byte-aligned. -
getBytesPerRow
int getBytesPerRow(int rowWidthInPixels) Answer the number of bytes in a row of the given pixel width. Each 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. -
readInterlaceFrame
void readInterlaceFrame(InputStream inputStream, int rowInterval, int columnInterval, int startRow, int startColumn, int frameCount) throws IOException 1. Read one of the seven frames of interlaced data. 2. Update the imageData. 3. Notify the image loader's listeners of the frame load.- Throws:
IOException
-
readInterlacedImage
Read the pixel data for an interlaced image from the data stream.- Throws:
IOException
-
fireInterlacedFrameEvent
void fireInterlacedFrameEvent(int frameCount) Fire an event to let listeners know that an interlaced frame has been loaded. finalFrame should be true if the image has finished loading, false if there are more frames to come. -
readNonInterlacedImage
Read the pixel data for a non-interlaced image from the data stream. Update the imageData to reflect the new data.- Throws:
IOException
-
compress16BitDepthTo8BitDepth
static void compress16BitDepthTo8BitDepth(byte[] source, int sourceOffset, byte[] destination, int destinationOffset, int numberOfValues) SWT does not support 16-bit depth color formats. Convert the 16-bit data to 8-bit data. The correct way to do this is to multiply each 16 bit value by the value: (2^8 - 1) / (2^16 - 1). The fast way to do this is just to drop the low byte of the 16-bit value. -
compress16BitDepthTo8BitDepth
static int compress16BitDepthTo8BitDepth(int value) SWT does not support 16-bit depth color formats. Convert the 16-bit data to 8-bit data. The correct way to do this is to multiply each 16 bit value by the value: (2^8 - 1) / (2^16 - 1). The fast way to do this is just to drop the low byte of the 16-bit value. -
filterRow
void filterRow(byte[] row, byte[] previousRow, int filterType) PNG supports four filtering types. These types are applied per row of image data. This method unfilters the given row based on the filterType.
-