Package org.libjpegturbo.turbojpeg
Class TJDecompressor
java.lang.Object
org.libjpegturbo.turbojpeg.TJDecompressor
- Direct Known Subclasses:
TJTransformer
TurboJPEG decompressor
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreate a TurboJPEG decompresssor instance.TJDecompressor(byte[] jpegImage) Create a TurboJPEG decompressor instance and associate the JPEG image stored injpegImagewith the newly-created instance.TJDecompressor(byte[] jpegImage, int imageSize) Create a TurboJPEG decompressor instance and associate the JPEG image of lengthimageSizebytes stored injpegImagewith the newly-created instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Free the native structures associated with this decompressor instance.private voiddecompress(byte[] srcBuf, int size, byte[] dstBuf, int desiredWidth, int pitch, int desiredHeight, int pixelFormat, int flags) private voiddecompress(byte[] srcBuf, int size, int[] dstBuf, int desiredWidth, int pitch, int desiredHeight, int pixelFormat, int flags) voiddecompress(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.decompress(int desiredWidth, int desiredHeight, int bufferedImageType, int flags) Decompress the JPEG source image associated with this decompressor instance and return aBufferedImageinstance 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.voiddecompress(BufferedImage dstImage, int flags) Decompress the JPEG source image associated with this decompressor instance and output a decompressed image to the givenBufferedImageinstance.private voiddecompressHeader(byte[] srcBuf, int size) voiddecompressToYUV(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.private voiddecompressToYUV(byte[] srcBuf, int size, byte[] dstBuf, int flags) byte[]decompressToYUV(int flags) Decompress the JPEG source image associated with this decompressor instance and return a buffer containing a YUV planar image.private voiddestroy()protected voidfinalize()intReturns the height of the JPEG image associated with this decompressor instance.byte[]Returns the JPEG image buffer associated with this decompressor instance.intReturns the size of the JPEG image (in bytes) associated with this decompressor instance.intgetScaledHeight(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.intgetScaledWidth(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.intReturns the level of chrominance subsampling used in the JPEG image associated with this decompressor instance.intgetWidth()Returns the width of the JPEG image associated with this decompressor instance.private voidinit()voidsetJPEGImage(byte[] jpegImage, int imageSize) Associate the JPEG image of lengthimageSizebytes stored injpegImagewith this decompressor instance.
-
Field Details
-
NO_ASSOC_ERROR
- See Also:
-
handle
protected long handle -
jpegBuf
protected byte[] jpegBuf -
jpegBufSize
protected int jpegBufSize -
jpegWidth
protected int jpegWidth -
jpegHeight
protected int jpegHeight -
jpegSubsamp
protected int jpegSubsamp -
byteOrder
-
-
Constructor Details
-
TJDecompressor
Create a TurboJPEG decompresssor instance.- Throws:
Exception
-
TJDecompressor
Create a TurboJPEG decompressor instance and associate the JPEG image stored injpegImagewith the newly-created instance.- Parameters:
jpegImage- JPEG image buffer (size of the JPEG image is assumed to be the length of the array)- Throws:
Exception
-
TJDecompressor
Create a TurboJPEG decompressor instance and associate the JPEG image of lengthimageSizebytes stored injpegImagewith the newly-created instance.- Parameters:
jpegImage- JPEG image bufferimageSize- size of the JPEG image (in bytes)- Throws:
Exception
-
-
Method Details
-
setJPEGImage
Associate the JPEG image of lengthimageSizebytes stored injpegImagewith this decompressor instance. This image will be used as the source image for subsequent decompress operations.- Parameters:
jpegImage- JPEG image bufferimageSize- size of the JPEG image (in bytes)- Throws:
Exception
-
getWidth
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:
Exception
-
getHeight
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:
Exception
-
getSubsamp
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:
Exception
-
getJPEGBuf
Returns the JPEG image buffer associated with this decompressor instance.- Returns:
- the JPEG image buffer associated with this decompressor instance
- Throws:
Exception
-
getJPEGSize
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:
Exception
-
getScaledWidth
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:
Exception
-
getScaledHeight
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:
Exception
-
decompress
public void decompress(byte[] dstBuf, int desiredWidth, int pitch, int desiredHeight, int pixelFormat, int flags) throws Exception Decompress the JPEG source image associated with this decompressor instance and output a decompressed image to the given destination buffer.- Parameters:
dstBuf- buffer that will receive the decompressed image. This buffer should normally bepitch * scaledHeightbytes in size, wherescaledHeightcan be determined by callingscalingFactor.with one of the scaling factors returned fromgetScaled(jpegHeight)TJ.getScalingFactors()or by callinggetScaledHeight(int, int).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. 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.)pitch- bytes per line of the destination image. Normally, this should be set toscaledWidth * 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:scaledWidthcan be determined by callingscalingFactor.or by callinggetScaled(jpegWidth)getScaledWidth(int, int). Setting this parameter to 0 is the equivalent of setting it toscaledWidth * TJ.pixelSize(pixelFormat).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. 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.)pixelFormat- pixel format of the decompressed image (one ofTJ.PF_*)flags- the bitwise OR of one or more ofTJ.FLAG_*- Throws:
Exception
-
decompress
public byte[] decompress(int desiredWidth, int pitch, int desiredHeight, int pixelFormat, int flags) throws Exception Decompress the JPEG source image associated with this decompressor instance and return a buffer containing the decompressed image.- Parameters:
desiredWidth- seedecompress(byte[], int, int, int, int, int)for descriptionpitch- seedecompress(byte[], int, int, int, int, int)for descriptiondesiredHeight- seedecompress(byte[], int, int, int, int, int)for descriptionpixelFormat- pixel format of the decompressed image (one ofTJ.PF_*)flags- the bitwise OR of one or more ofTJ.FLAG_*- Returns:
- a buffer containing the decompressed image
- Throws:
Exception
-
decompressToYUV
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 byTJCompressor.encodeYUV(byte[], int). Note that, if the width or height of the image is not an even multiple of the MCU block size (seeTJ.getMCUWidth(int)andTJ.getMCUHeight(int)), then an intermediate buffer copy will be performed within TurboJPEG.- Parameters:
dstBuf- buffer that will receive the YUV planar image. UseTJ.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 ofTJ.FLAG_*- Throws:
Exception
-
decompressToYUV
Decompress the JPEG source image associated with this decompressor instance and return a buffer containing a YUV planar image. SeedecompressToYUV(byte[], int)for more detail. -
decompress
Decompress the JPEG source image associated with this decompressor instance and output a decompressed image to the givenBufferedImageinstance. -
decompress
public BufferedImage decompress(int desiredWidth, int desiredHeight, int bufferedImageType, int flags) throws Exception Decompress the JPEG source image associated with this decompressor instance and return aBufferedImageinstance containing the decompressed image.- Parameters:
desiredWidth- seedecompress(byte[], int, int, int, int, int)for descriptiondesiredHeight- seedecompress(byte[], int, int, int, int, int)for descriptionbufferedImageType- the image type of the newly-createdBufferedImageinstance (for instance,BufferedImage.TYPE_INT_RGB)flags- the bitwise OR of one or more ofTJ.FLAG_*- Returns:
- a
BufferedImageinstance containing the decompressed image - Throws:
Exception
-
close
Free the native structures associated with this decompressor instance.- Throws:
Exception
-
finalize
-
init
- Throws:
Exception
-
destroy
- Throws:
Exception
-
decompressHeader
- Throws:
Exception
-
decompress
private void decompress(byte[] srcBuf, int size, byte[] dstBuf, int desiredWidth, int pitch, int desiredHeight, int pixelFormat, int flags) throws Exception - Throws:
Exception
-
decompress
private void decompress(byte[] srcBuf, int size, int[] dstBuf, int desiredWidth, int pitch, int desiredHeight, int pixelFormat, int flags) throws Exception - Throws:
Exception
-
decompressToYUV
- Throws:
Exception
-