- java.lang.Object
-
- de.bernd_michaely.x3f.types.X3fImageData
-
public class X3fImageData extends Object
Class for representing image data contained in X3F data.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
X3fImageData(RandomAccessData data, int dataLength, int rotation)
Constructor to parse and collect information contained in a X3F image section.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BufferedImage
getBufferedImage(RandomAccessData data)
Returns a processed for preview image decoded as a BufferedImage.EnumX3fImageDataFormat
getDataFormat()
Returns the data format.UInt32
getDataFormatNumericValue()
Returns the numeric value of the data format.int
getDataLength()
Returns the length of the image data in bytes.long
getDataOffset()
Returns the offset in bytes of the image data from the start of the data.String[]
getHuffmanCodeWordTableDescription()
Returns a bitwise string representation of the Huffman code word table entries.ByteArray
getImageData(RandomAccessData data)
Returns raw image data stream contained in a byte array.VersionNumber
getImageFormatVersion()
Returns the image format version.ImageSize
getImageSize()
Returns the size of the image.UInt32
getRowSize()
Returns row size in bytes.UInt32
getTypeImageData()
Returns the type of image data.boolean
isImageFormatVersionSupported()
Returns true, if the data version is supported by the parser.boolean
isProcessedForPreview()
Returns true, if the image is processed for preview.BufferedImage
rotateImage(BufferedImage src)
Rotates the given image according to the rotation given in the X3F header.boolean
writeImage(RandomAccessData data, OutputStream os)
Writes this image as JPEG to an OutputStream.
-
-
-
Constructor Detail
-
X3fImageData
protected X3fImageData(RandomAccessData data, int dataLength, int rotation) throws RandomAccessDataException, HuffmanTree.PrefixException
Constructor to parse and collect information contained in a X3F image section. It is assumed, that the current offset pointer of the data source is positioned just after the image data section identifier "SECi".- Parameters:
data
- the data source containing the X3F data to parsedataLength
- the length of the image data in bytesrotation
- image rotation as given in X3F header- Throws:
RandomAccessDataException
- if RandomAccessData source is invalidHuffmanTree.PrefixException
- if the Huffman code word table is not prefix free
-
-
Method Detail
-
isImageFormatVersionSupported
public boolean isImageFormatVersionSupported()
Returns true, if the data version is supported by the parser.- Returns:
- true, if the data version is supported
-
getImageFormatVersion
public VersionNumber getImageFormatVersion()
Returns the image format version.- Returns:
- the image format version
-
getTypeImageData
public UInt32 getTypeImageData()
Returns the type of image data.- Returns:
- the type of image data
-
getDataFormat
public EnumX3fImageDataFormat getDataFormat()
Returns the data format.data formats data format description 3 Uncompressed 24-bit 8/8/8 RGB 11 Huffman-encoded DPCM 8/8/8 RGB 18 JPEG-compressed 8/8/8 RGB others RESERVED - Returns:
- the data format
-
getDataFormatNumericValue
public UInt32 getDataFormatNumericValue()
Returns the numeric value of the data format.- Returns:
- the numeric value of the data format
-
getImageSize
public ImageSize getImageSize()
Returns the size of the image.- Returns:
- the size of the image
-
getRowSize
public UInt32 getRowSize()
Returns row size in bytes. Will always be a multiple of 4 (32-bit aligned). A value of zero here means that rows are variable-length (as in Huffman data).- Returns:
- row size in bytes
-
getImageData
public ByteArray getImageData(RandomAccessData data) throws RandomAccessDataException
Returns raw image data stream contained in a byte array.- Parameters:
data
- the data source (it's current offset will be changed)- Returns:
- a JPEG image contained in a byte array or null
- Throws:
RandomAccessDataException
- if RandomAccessData source is invalid
-
isProcessedForPreview
public boolean isProcessedForPreview()
Returns true, if the image is processed for preview.- Returns:
- true, if the image is processed for preview
-
getDataOffset
public long getDataOffset()
Returns the offset in bytes of the image data from the start of the data.- Returns:
- the offset in bytes of the image data
-
getDataLength
public int getDataLength()
Returns the length of the image data in bytes.- Returns:
- the length of the image data
-
getHuffmanCodeWordTableDescription
public String[] getHuffmanCodeWordTableDescription()
Returns a bitwise string representation of the Huffman code word table entries.- Returns:
- an array of strings, each containing a bitwise string representation of the Huffman code word table entry
-
getBufferedImage
public BufferedImage getBufferedImage(RandomAccessData data) throws RandomAccessDataException
Returns a processed for preview image decoded as a BufferedImage. If the image is not processed for preview or the data format is not supported, null is returned.- Parameters:
data
- the data source (it's current offset will be changed)- Returns:
- processed for preview image decoded as a BufferedImage
- Throws:
RandomAccessDataException
- if RandomAccessData source is invalid
-
rotateImage
public BufferedImage rotateImage(BufferedImage src)
Rotates the given image according to the rotation given in the X3F header.- Parameters:
src
- given image to rotate- Returns:
- rotated image
-
writeImage
public boolean writeImage(RandomAccessData data, OutputStream os) throws IOException, RandomAccessDataException
Writes this image as JPEG to an OutputStream.- Parameters:
data
- the data source (it's current offset will be changed)os
- the OutputStream to write to- Returns:
- true, if image was written successfully
- Throws:
IOException
- when a writing error occursRandomAccessDataException
- when a reading error occurs
-
-