org.libjpegturbo.turbojpeg
Class TJDecompressor

java.lang.Object
  extended by org.libjpegturbo.turbojpeg.TJDecompressor
Direct Known Subclasses:
TJTransformer

public class TJDecompressor
extends java.lang.Object

TurboJPEG decompressor


Field Summary
protected  long handle
           
protected  byte[] jpegBuf
           
protected  int jpegBufSize
           
protected  int jpegHeight
           
protected  int jpegSubsamp
           
protected  int jpegWidth
           
 
Constructor Summary
TJDecompressor()
          Create a TurboJPEG decompresssor instance.
TJDecompressor(byte[] jpegImage)
          Create a TurboJPEG decompressor instance and associate the JPEG image stored in jpegImage with the newly-created instance.
TJDecompressor(byte[] jpegImage, int imageSize)
          Create a TurboJPEG decompressor instance and associate the JPEG image of length imageSize bytes stored in jpegImage with the newly-created instance.
 
Method Summary
 void close()
          Free the native structures associated with this decompressor instance.
 void decompress(java.awt.image.BufferedImage dstImage, int flags)
          Decompress the JPEG source image associated with this decompressor instance and output a decompressed image to the given BufferedImage instance.
 void decompress(byte[] dstBuf, int desiredWidth, int pitch, int desiredHeight, int pixelFormat, int flags)
          Decompress the JPEG source image associated with this decompressor instance and output a decompressed image to the given destination buffer.
 java.awt.image.BufferedImage decompress(int desiredWidth, int desiredHeight, int bufferedImageType, int flags)
          Decompress the JPEG source image associated with this decompressor instance and return a BufferedImage instance containing the decompressed image.
 byte[] decompress(int desiredWidth, int pitch, int desiredHeight, int pixelFormat, int flags)
          Decompress the JPEG source image associated with this decompressor instance and return a buffer containing the decompressed image.
 void decompressToYUV(byte[] dstBuf, int flags)
          Decompress the JPEG source image associated with this decompressor instance and output a YUV planar image to the given destination buffer.
 byte[] decompressToYUV(int flags)
          Decompress the JPEG source image associated with this decompressor instance and return a buffer containing a YUV planar image.
protected  void finalize()
           
 int getHeight()
          Returns the height of the JPEG image associated with this decompressor instance.
 byte[] getJPEGBuf()
          Returns the JPEG image buffer associated with this decompressor instance.
 int getJPEGSize()
          Returns the size of the JPEG image (in bytes) associated with this decompressor instance.
 int getScaledHeight(int desiredWidth, int desiredHeight)
          Returns the height of the largest scaled down image that the TurboJPEG decompressor can generate without exceeding the desired image width and height.
 int getScaledWidth(int desiredWidth, int desiredHeight)
          Returns the width of the largest scaled down image that the TurboJPEG decompressor can generate without exceeding the desired image width and height.
 int getSubsamp()
          Returns the level of chrominance subsampling used in the JPEG image associated with this decompressor instance.
 int getWidth()
          Returns the width of the JPEG image associated with this decompressor instance.
 void setJPEGBuffer(byte[] jpegImage, int imageSize)
          Associate a JPEG image buffer with this decompressor instance.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

handle

protected long handle

jpegBuf

protected byte[] jpegBuf

jpegBufSize

protected int jpegBufSize

jpegWidth

protected int jpegWidth

jpegHeight

protected int jpegHeight

jpegSubsamp

protected int jpegSubsamp
Constructor Detail

TJDecompressor

public TJDecompressor()
               throws java.lang.Exception
Create a TurboJPEG decompresssor instance.

Throws:
java.lang.Exception

TJDecompressor

public TJDecompressor(byte[] jpegImage)
               throws java.lang.Exception
Create a TurboJPEG decompressor instance and associate the JPEG image stored in jpegImage with the newly-created instance.

Parameters:
jpegImage - JPEG image buffer (size of JPEG image is assumed to be the length of the buffer)
Throws:
java.lang.Exception

TJDecompressor

public TJDecompressor(byte[] jpegImage,
                      int imageSize)
               throws java.lang.Exception
Create a TurboJPEG decompressor instance and associate the JPEG image of length imageSize bytes stored in jpegImage with the newly-created instance.

Parameters:
jpegImage - JPEG image buffer
imageSize - size of JPEG image (in bytes)
Throws:
java.lang.Exception
Method Detail

setJPEGBuffer

public void setJPEGBuffer(byte[] jpegImage,
                          int imageSize)
                   throws java.lang.Exception
Associate a JPEG image buffer with this decompressor instance. This buffer will be used as the source buffer for subsequent decompress operations.

Parameters:
jpegImage - JPEG image buffer
imageSize - size of JPEG image (in bytes)
Throws:
java.lang.Exception

getWidth

public int getWidth()
             throws java.lang.Exception
Returns the width of the JPEG image associated with this decompressor instance.

Returns:
the width of the JPEG image associated with this decompressor instance
Throws:
java.lang.Exception

getHeight

public int getHeight()
              throws java.lang.Exception
Returns the height of the JPEG image associated with this decompressor instance.

Returns:
the height of the JPEG image associated with this decompressor instance
Throws:
java.lang.Exception

getSubsamp

public int getSubsamp()
               throws java.lang.Exception
Returns the level of chrominance subsampling used in the JPEG image associated with this decompressor instance.

Returns:
the level of chrominance subsampling used in the JPEG image associated with this decompressor instance
Throws:
java.lang.Exception

getJPEGBuf

public byte[] getJPEGBuf()
                  throws java.lang.Exception
Returns the JPEG image buffer associated with this decompressor instance.

Returns:
the JPEG image buffer associated with this decompressor instance
Throws:
java.lang.Exception

getJPEGSize

public int getJPEGSize()
                throws java.lang.Exception
Returns the size of the JPEG image (in bytes) associated with this decompressor instance.

Returns:
the size of the JPEG image (in bytes) associated with this decompressor instance
Throws:
java.lang.Exception

getScaledWidth

public int getScaledWidth(int desiredWidth,
                          int desiredHeight)
                   throws java.lang.Exception
Returns the width of the largest scaled down image that the TurboJPEG decompressor can generate without exceeding the desired image width and height.

Parameters:
desiredWidth - desired width (in pixels) of the decompressed image. If this is set to 0, then only the height will be considered when determining the scaled image size.
desiredHeight - desired height (in pixels) of the decompressed image. If this is set to 0, then only the width will be considered when determining the scaled image size.
Returns:
the width of the largest scaled down image that the TurboJPEG decompressor can generate without exceeding the desired image width and height
Throws:
java.lang.Exception

getScaledHeight

public int getScaledHeight(int desiredWidth,
                           int desiredHeight)
                    throws java.lang.Exception
Returns the height of the largest scaled down image that the TurboJPEG decompressor can generate without exceeding the desired image width and height.

Parameters:
desiredWidth - desired width (in pixels) of the decompressed image. If this is set to 0, then only the height will be considered when determining the scaled image size.
desiredHeight - desired height (in pixels) of the decompressed image. If this is set to 0, then only the width will be considered when determining the scaled image size.
Returns:
the height of the largest scaled down image that the TurboJPEG decompressor can generate without exceeding the desired image width and height
Throws:
java.lang.Exception

decompress

public void decompress(byte[] dstBuf,
                       int desiredWidth,
                       int pitch,
                       int desiredHeight,
                       int pixelFormat,
                       int flags)
                throws java.lang.Exception
Decompress the JPEG source image associated with this decompressor instance and output a decompressed image to the given destination buffer.

Parameters:
dstBuf - buffer which will receive the decompressed image. This buffer should normally be pitch * scaledHeight bytes in size, where scaledHeight = ceil(jpegHeight * scalingFactor), and the supported scaling factors can be determined by calling TJ.getScalingFactors().
desiredWidth - desired width (in pixels) of the decompressed image. If the desired image dimensions are smaller than the dimensions of the JPEG image being decompressed, then TurboJPEG will use scaling in the JPEG decompressor to generate the largest possible image that will fit within the desired dimensions. If desiredWidth is set to 0, then only the height will be considered when determining the scaled image size.
pitch - bytes per line of the destination image. Normally, this should be set to scaledWidth * TJ.pixelSize(pixelFormat) if the decompressed image is unpadded, but you can use this to, for instance, pad each line of the decompressed image to a 4-byte boundary. NOTE: scaledWidth = ceil(jpegWidth * scalingFactor). Setting this parameter to 0 is the equivalent of setting it to scaledWidth * pixelSize.
desiredHeight - desired height (in pixels) of the decompressed image. If the desired image dimensions are smaller than the dimensions of the JPEG image being decompressed, then TurboJPEG will use scaling in the JPEG decompressor to generate the largest possible image that will fit within the desired dimensions. If desiredHeight is set to 0, then only the width will be considered when determining the scaled image size.
pixelFormat - Pixel format of the decompressed image (see TJ)
flags - the bitwise OR of one or more of the flags described in TJ
Throws:
java.lang.Exception

decompress

public byte[] decompress(int desiredWidth,
                         int pitch,
                         int desiredHeight,
                         int pixelFormat,
                         int flags)
                  throws java.lang.Exception
Decompress the JPEG source image associated with this decompressor instance and return a buffer containing the decompressed image.

Parameters:
desiredWidth - see decompress(byte[], int, int, int, int, int) for description
pitch - see decompress(byte[], int, int, int, int, int) for description
desiredHeight - see decompress(byte[], int, int, int, int, int) for description
pixelFormat - Pixel format of the decompressed image (see TJ)
flags - the bitwise OR of one or more of the flags described in TJ
Returns:
a buffer containing the decompressed image
Throws:
java.lang.Exception

decompressToYUV

public void decompressToYUV(byte[] dstBuf,
                            int flags)
                     throws java.lang.Exception
Decompress the JPEG source image associated with this decompressor instance and output a YUV planar image to the given destination buffer. This method performs JPEG decompression but leaves out the color conversion step, so a planar YUV image is generated instead of an RGB image. The padding of the planes in this image is the same as the images generated by TJCompressor.encodeYUV(byte[], int). Note that, if the width or height of the image is not an even multiple of the MCU block size (see TJ.getMCUWidth(int) and TJ.getMCUHeight(int)), then an intermediate buffer copy will be performed within TurboJPEG.

Parameters:
dstBuf - buffer which will receive the YUV planar image. Use TJ.bufSizeYUV(int, int, int) to determine the appropriate size for this buffer based on the image width, height, and level of chrominance subsampling.
flags - the bitwise OR of one or more of the flags described in TJ
Throws:
java.lang.Exception

decompressToYUV

public byte[] decompressToYUV(int flags)
                       throws java.lang.Exception
Decompress the JPEG source image associated with this decompressor instance and return a buffer containing a YUV planar image. See decompressToYUV(byte[], int) for more detail.

Parameters:
flags - the bitwise OR of one or more of the flags described in TJ
Returns:
a buffer containing a YUV planar image
Throws:
java.lang.Exception

decompress

public void decompress(java.awt.image.BufferedImage dstImage,
                       int flags)
                throws java.lang.Exception
Decompress the JPEG source image associated with this decompressor instance and output a decompressed image to the given BufferedImage instance.

Parameters:
dstImage - a BufferedImage instance which will receive the decompressed image
flags - the bitwise OR of one or more of the flags described in TJ
Throws:
java.lang.Exception

decompress

public java.awt.image.BufferedImage decompress(int desiredWidth,
                                               int desiredHeight,
                                               int bufferedImageType,
                                               int flags)
                                        throws java.lang.Exception
Decompress the JPEG source image associated with this decompressor instance and return a BufferedImage instance containing the decompressed image.

Parameters:
desiredWidth - see decompress(byte[], int, int, int, int, int) for description
desiredHeight - see decompress(byte[], int, int, int, int, int) for description
bufferedImageType - the image type of the BufferedImage instance to create (for instance, BufferedImage.TYPE_INT_RGB)
flags - the bitwise OR of one or more of the flags described in TJ
Returns:
a BufferedImage instance containing the decompressed image
Throws:
java.lang.Exception

close

public void close()
           throws java.lang.Exception
Free the native structures associated with this decompressor instance.

Throws:
java.lang.Exception

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable