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 srcColorspace
           
protected  int srcHeight
           
protected  int srcSubsamp
           
protected  int srcWidth
           
protected  YUVImage yuvImage
           
 
Constructor Summary
TJDecompressor()
          Create a TurboJPEG decompresssor instance.
TJDecompressor(byte[] jpegImage)
          Create a TurboJPEG decompressor instance and associate the JPEG source image stored in jpegImage with the newly created instance.
TJDecompressor(byte[] jpegImage, int imageSize)
          Create a TurboJPEG decompressor instance and associate the JPEG source image of length imageSize bytes stored in jpegImage with the newly created instance.
TJDecompressor(YUVImage yuvImage)
          Create a TurboJPEG decompressor instance and associate the YUV planar source image stored in yuvImage 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 or decode the YUV source image associated with this decompressor instance and output a decompressed/decoded image to the given BufferedImage instance.
 void decompress(byte[] dstBuf, int desiredWidth, int pitch, int desiredHeight, int pixelFormat, int flags)
          Deprecated. Use decompress(byte[], int, int, int, int, int, int, int) instead.
 void decompress(byte[] dstBuf, int x, int y, int desiredWidth, int pitch, int desiredHeight, int pixelFormat, int flags)
          Decompress the JPEG source image or decode the YUV source image associated with this decompressor instance and output a grayscale, RGB, or CMYK image to the given destination buffer.
 void decompress(int[] dstBuf, int x, int y, int desiredWidth, int stride, int desiredHeight, int pixelFormat, int flags)
          Decompress the JPEG source image or decode the YUV source image associated with this decompressor instance and output a grayscale, RGB, or CMYK image to the given destination buffer.
 java.awt.image.BufferedImage decompress(int desiredWidth, int desiredHeight, int bufferedImageType, int flags)
          Decompress the JPEG source image or decode the YUV source image associated with this decompressor instance and return a BufferedImage instance containing the decompressed/decoded 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)
          Deprecated. Use decompressToYUV(YUVImage, int) instead.
 byte[] decompressToYUV(int flags)
          Deprecated. Use decompressToYUV(int, int, int, int) instead.
 YUVImage decompressToYUV(int desiredWidth, int pad, int desiredHeight, int flags)
          Decompress the JPEG source image associated with this decompressor instance into a YUV planar image and return a YUVImage instance containing the decompressed image.
 void decompressToYUV(YUVImage dstImage, int flags)
          Decompress the JPEG source image associated with this decompressor instance into a YUV planar image and store it in the given YUVImage instance.
protected  void finalize()
           
 int getColorspace()
          Returns the colorspace used in the source image (JPEG or YUV) associated with this decompressor instance.
 int getHeight()
          Returns the height of the source image (JPEG or YUV) associated with this decompressor instance.
 byte[] getJPEGBuf()
          Deprecated. Use getSourceBuf() instead.
 int getJPEGSize()
          Deprecated. Use getSourceSize() instead.
 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.
 byte[] getSourceBuf()
          Returns the source image buffer associated with this decompressor instance.
 int getSourceSize()
          Returns the size of the source image (in bytes) associated with this decompressor instance.
 int getSubsamp()
          Returns the level of chrominance subsampling used in the source image (JPEG or YUV) associated with this decompressor instance.
 int getWidth()
          Returns the width of the source image (JPEG or YUV) associated with this decompressor instance.
 void setJPEGImage(byte[] jpegImage, int imageSize)
          Deprecated. Use setSourceImage(byte[], int) instead.
 void setSourceImage(byte[] srcImage, int imageSize)
          Associate the JPEG image of length imageSize bytes stored in srcImage with this decompressor instance.
 void setSourceImage(YUVImage srcImage)
          Associate the specified YUV planar source image 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

yuvImage

protected YUVImage yuvImage

srcWidth

protected int srcWidth

srcHeight

protected int srcHeight

srcSubsamp

protected int srcSubsamp

srcColorspace

protected int srcColorspace
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 source image stored in jpegImage with the newly created instance.

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

TJDecompressor

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

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

TJDecompressor

public TJDecompressor(YUVImage yuvImage)
               throws java.lang.Exception
Create a TurboJPEG decompressor instance and associate the YUV planar source image stored in yuvImage with the newly created instance.

Parameters:
yuvImage - YUVImage instance containing a YUV planar image to be decoded
Throws:
java.lang.Exception
Method Detail

setSourceImage

public void setSourceImage(byte[] srcImage,
                           int imageSize)
                    throws java.lang.Exception
Associate the JPEG image of length imageSize bytes stored in srcImage with this decompressor instance. This image will be used as the source image for subsequent decompress operations.

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

setJPEGImage

@Deprecated
public void setJPEGImage(byte[] jpegImage,
                                    int imageSize)
                  throws java.lang.Exception
Deprecated. Use setSourceImage(byte[], int) instead.

Throws:
java.lang.Exception

setSourceImage

public void setSourceImage(YUVImage srcImage)
                    throws java.lang.Exception
Associate the specified YUV planar source image with this decompressor instance. Subsequent decompress operations will decode this image into an RGB or grayscale destination image.

Parameters:
srcImage - YUVImage instance containing a YUV planar image to be decoded
Throws:
java.lang.Exception

getWidth

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

Returns:
the width of the source image (JPEG or YUV) associated with this decompressor instance
Throws:
java.lang.Exception

getHeight

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

Returns:
the height of the source image (JPEG or YUV) 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 source image (JPEG or YUV) associated with this decompressor instance. See TJ.SAMP_*.

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

getColorspace

public int getColorspace()
                  throws java.lang.Exception
Returns the colorspace used in the source image (JPEG or YUV) associated with this decompressor instance. See TJ.CS_*. If the source image is YUV, then this always returns TJ.CS_YCbCr.

Returns:
the colorspace used in the source image (JPEG or YUV) associated with this decompressor instance
Throws:
java.lang.Exception

getSourceBuf

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

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

getJPEGBuf

@Deprecated
public byte[] getJPEGBuf()
                  throws java.lang.Exception
Deprecated. Use getSourceBuf() instead.

Throws:
java.lang.Exception

getSourceSize

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

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

getJPEGSize

@Deprecated
public int getJPEGSize()
                throws java.lang.Exception
Deprecated. Use getSourceSize() instead.

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. Setting this to 0 is the same as setting it to the width of the JPEG image (in other words, the width will not be considered when determining the scaled image size.)
desiredHeight - desired height (in pixels) of the decompressed image. Setting this to 0 is the same as setting it to the height of the JPEG image (in other words, the height will not 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. Setting this to 0 is the same as setting it to the width of the JPEG image (in other words, the width will not be considered when determining the scaled image size.)
desiredHeight - desired height (in pixels) of the decompressed image. Setting this to 0 is the same as setting it to the height of the JPEG image (in other words, the height will not 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 x,
                       int y,
                       int desiredWidth,
                       int pitch,
                       int desiredHeight,
                       int pixelFormat,
                       int flags)
                throws java.lang.Exception
Decompress the JPEG source image or decode the YUV source image associated with this decompressor instance and output a grayscale, RGB, or CMYK image to the given destination buffer.

Parameters:
dstBuf - buffer that will receive the decompressed/decoded image. If the source image is a JPEG image, then this buffer should normally be pitch * scaledHeight bytes in size, where scaledHeight can be determined by calling scalingFactor.getScaled(jpegHeight) with one of the scaling factors returned from TJ.getScalingFactors() or by calling getScaledHeight(int, int). If the source image is a YUV image, then this buffer should normally be pitch * height bytes in size, where height is the height of the YUV image. However, the buffer may also be larger than the dimensions of the source image, in which case the x, y, and pitch parameters can be used to specify the region into which the source image should be decompressed/decoded.
x - x offset (in pixels) of the region in the destination image into which the source image should be decompressed/decoded
y - y offset (in pixels) of the region in the destination image into which the source image should be decompressed/decoded
desiredWidth - If the source image is a JPEG image, then this specifies the desired width (in pixels) of the decompressed image (or image region.) If the desired destination image dimensions are different than the source image dimensions, then TurboJPEG will use scaling in the JPEG decompressor to generate the largest possible image that will fit within the desired dimensions. Setting this to 0 is the same as setting it to the width of the JPEG image (in other words, the width will not be considered when determining the scaled image size.) This parameter is ignored if the source image is a YUV image.
pitch - bytes per line of the destination image. Normally, this should be set to scaledWidth * TJ.pixelSize(pixelFormat) if the destination image is unpadded, but you can use this to, for instance, pad each line of the destination image to a 4-byte boundary or to decompress/decode the source image into a region of a larger image. NOTE: if the source image is a JPEG image, then scaledWidth can be determined by calling scalingFactor.getScaled(jpegWidth) or by calling getScaledWidth(int, int). If the source image is a YUV image, then scaledWidth is the width of the YUV image. Setting this parameter to 0 is the equivalent of setting it to scaledWidth * TJ.pixelSize(pixelFormat).
desiredHeight - If the source image is a JPEG image, then this specifies the desired height (in pixels) of the decompressed image (or image region.) If the desired destination image dimensions are different than the source image dimensions, then TurboJPEG will use scaling in the JPEG decompressor to generate the largest possible image that will fit within the desired dimensions. Setting this to 0 is the same as setting it to the height of the JPEG image (in other words, the height will not be considered when determining the scaled image size.) This parameter is ignored if the source image is a YUV image.
pixelFormat - pixel format of the decompressed/decoded image (one of TJ.PF_*)
flags - the bitwise OR of one or more of TJ.FLAG_*
Throws:
java.lang.Exception

decompress

@Deprecated
public void decompress(byte[] dstBuf,
                                  int desiredWidth,
                                  int pitch,
                                  int desiredHeight,
                                  int pixelFormat,
                                  int flags)
                throws java.lang.Exception
Deprecated. Use decompress(byte[], int, int, int, int, int, int, int) instead.

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, int, int) for description
pitch - see decompress(byte[], int, int, int, int, int, int, int) for description
desiredHeight - see decompress(byte[], int, int, int, int, int, int, int) for description
pixelFormat - pixel format of the decompressed image (one of TJ.PF_*)
flags - the bitwise OR of one or more of TJ.FLAG_*
Returns:
a buffer containing the decompressed image
Throws:
java.lang.Exception

decompressToYUV

public void decompressToYUV(YUVImage dstImage,
                            int flags)
                     throws java.lang.Exception
Decompress the JPEG source image associated with this decompressor instance into a YUV planar image and store it in the given YUVImage instance. This method performs JPEG decompression but leaves out the color conversion step, so a planar YUV image is generated instead of an RGB or grayscale image. This method cannot be used to decompress JPEG source images with the CMYK or YCCK colorspace.

Parameters:
dstImage - YUVImage instance that will receive the YUV planar image. The level of subsampling specified in this YUVImage instance must match that of the JPEG image, and the width and height specified in the YUVImage instance must match one of the scaled image sizes that TurboJPEG is capable of generating from the JPEG source image.
flags - the bitwise OR of one or more of TJ.FLAG_*
Throws:
java.lang.Exception

decompressToYUV

@Deprecated
public void decompressToYUV(byte[] dstBuf,
                                       int flags)
                     throws java.lang.Exception
Deprecated. Use decompressToYUV(YUVImage, int) instead.

Throws:
java.lang.Exception

decompressToYUV

public YUVImage decompressToYUV(int desiredWidth,
                                int pad,
                                int desiredHeight,
                                int flags)
                         throws java.lang.Exception
Decompress the JPEG source image associated with this decompressor instance into a YUV planar image and return a YUVImage instance containing the decompressed image. This method performs JPEG decompression but leaves out the color conversion step, so a planar YUV image is generated instead of an RGB or grayscale image. This method cannot be used to decompress JPEG source images with the CMYK or YCCK colorspace.

Parameters:
desiredWidth - desired width (in pixels) of the YUV image. If the desired image dimensions are different 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. Setting this to 0 is the same as setting it to the width of the JPEG image (in other words, the width will not be considered when determining the scaled image size.)
pad - the width of each line in each plane of the YUV image will be padded to the nearest multiple of this number of bytes (must be a power of 2.)
desiredHeight - desired height (in pixels) of the YUV image. If the desired image dimensions are different 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. Setting this to 0 is the same as setting it to the height of the JPEG image (in other words, the height will not be considered when determining the scaled image size.)
flags - the bitwise OR of one or more of TJ.FLAG_*
Returns:
a YUV planar image
Throws:
java.lang.Exception

decompressToYUV

@Deprecated
public byte[] decompressToYUV(int flags)
                       throws java.lang.Exception
Deprecated. Use decompressToYUV(int, int, int, int) instead.

Throws:
java.lang.Exception

decompress

public void decompress(int[] dstBuf,
                       int x,
                       int y,
                       int desiredWidth,
                       int stride,
                       int desiredHeight,
                       int pixelFormat,
                       int flags)
                throws java.lang.Exception
Decompress the JPEG source image or decode the YUV source image associated with this decompressor instance and output a grayscale, RGB, or CMYK image to the given destination buffer.

Parameters:
dstBuf - buffer that will receive the decompressed/decoded image. If the source image is a JPEG image, then this buffer should normally be stride * scaledHeight pixels in size, where scaledHeight can be determined by calling scalingFactor.getScaled(jpegHeight) with one of the scaling factors returned from TJ.getScalingFactors() or by calling getScaledHeight(int, int). If the source image is a YUV image, then this buffer should normally be stride * height pixels in size, where height is the height of the YUV image. However, the buffer may also be larger than the dimensions of the JPEG image, in which case the x, y, and stride parameters can be used to specify the region into which the source image should be decompressed.
x - x offset (in pixels) of the region in the destination image into which the source image should be decompressed/decoded
y - y offset (in pixels) of the region in the destination image into which the source image should be decompressed/decoded
desiredWidth - If the source image is a JPEG image, then this specifies the desired width (in pixels) of the decompressed image (or image region.) If the desired destination image dimensions are different than the source image dimensions, then TurboJPEG will use scaling in the JPEG decompressor to generate the largest possible image that will fit within the desired dimensions. Setting this to 0 is the same as setting it to the width of the JPEG image (in other words, the width will not be considered when determining the scaled image size.) This parameter is ignored if the source image is a YUV image.
stride - pixels per line of the destination image. Normally, this should be set to scaledWidth, but you can use this to, for instance, decompress the JPEG image into a region of a larger image. NOTE: if the source image is a JPEG image, then scaledWidth can be determined by calling scalingFactor.getScaled(jpegWidth) or by calling getScaledWidth(int, int). If the source image is a YUV image, then scaledWidth is the width of the YUV image. Setting this parameter to 0 is the equivalent of setting it to scaledWidth.
desiredHeight - If the source image is a JPEG image, then this specifies the desired height (in pixels) of the decompressed image (or image region.) If the desired destination image dimensions are different than the source image dimensions, then TurboJPEG will use scaling in the JPEG decompressor to generate the largest possible image that will fit within the desired dimensions. Setting this to 0 is the same as setting it to the height of the JPEG image (in other words, the height will not be considered when determining the scaled image size.) This parameter is ignored if the source image is a YUV image.
pixelFormat - pixel format of the decompressed image (one of TJ.PF_*)
flags - the bitwise OR of one or more of TJ.FLAG_*
Throws:
java.lang.Exception

decompress

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

Parameters:
dstImage - a BufferedImage instance that will receive the decompressed/decoded image. If the source image is a JPEG image, then the width and height of the BufferedImage instance must match one of the scaled image sizes that TurboJPEG is capable of generating from the JPEG image. If the source image is a YUV image, then the width and height of the BufferedImage instance must match the width and height of the YUV image.
flags - the bitwise OR of one or more of TJ.FLAG_*
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 or decode the YUV source image associated with this decompressor instance and return a BufferedImage instance containing the decompressed/decoded image.

Parameters:
desiredWidth - see decompress(byte[], int, int, int, int, int, int, int) for description
desiredHeight - see decompress(byte[], int, int, int, int, int, int, int) for description
bufferedImageType - the image type of the BufferedImage instance that will be created (for instance, BufferedImage.TYPE_INT_RGB)
flags - the bitwise OR of one or more of TJ.FLAG_*
Returns:
a BufferedImage instance containing the decompressed/decoded 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