Package org.libjpegturbo.turbojpeg
Class TJCompressor
java.lang.Object
org.libjpegturbo.turbojpeg.TJCompressor
TurboJPEG compressor
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreate a TurboJPEG compressor instance.TJCompressor(byte[] srcImage, int width, int pitch, int height, int pixelFormat) Create a TurboJPEG compressor instance and associate the uncompressed source image stored insrcImagewith the newly-created instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Free the native structures associated with this compressor instance.voidcompress(byte[] dstBuf, int flags) Compress the uncompressed source image associated with this compressor instance and output a JPEG image to the given destination buffer.private intcompress(byte[] srcBuf, int width, int pitch, int height, int pixelFormat, byte[] dstbuf, int jpegSubsamp, int jpegQual, int flags) byte[]compress(int flags) Compress the uncompressed source image associated with this compressor instance and return a buffer containing a JPEG image.private intcompress(int[] srcBuf, int width, int pitch, int height, int pixelFormat, byte[] dstbuf, int jpegSubsamp, int jpegQual, int flags) voidcompress(BufferedImage srcImage, byte[] dstBuf, int flags) Compress the uncompressed source image stored insrcImageand output a JPEG image to the given destination buffer.byte[]compress(BufferedImage srcImage, int flags) Compress the uncompressed source image stored insrcImageand return a buffer containing a JPEG image.private voiddestroy()voidencodeYUV(byte[] dstBuf, int flags) Encode the uncompressed source image associated with this compressor instance and output a YUV planar image to the given destination buffer.private voidencodeYUV(byte[] srcBuf, int width, int pitch, int height, int pixelFormat, byte[] dstbuf, int subsamp, int flags) byte[]encodeYUV(int flags) Encode the uncompressed source image associated with this compressor instance and return a buffer containing a YUV planar image.private voidencodeYUV(int[] srcBuf, int width, int pitch, int height, int pixelFormat, byte[] dstbuf, int subsamp, int flags) voidencodeYUV(BufferedImage srcImage, byte[] dstBuf, int flags) Encode the uncompressed source image stored insrcImageand output a YUV planar image to the given destination buffer.byte[]encodeYUV(BufferedImage srcImage, int flags) Encode the uncompressed source image stored insrcImageand return a buffer containing a YUV planar image.protected voidfinalize()intReturns the size of the image (in bytes) generated by the most recent compress/encode operation.private voidinit()voidsetJPEGQuality(int quality) Set the JPEG image quality level for subsequent compress operations.voidsetSourceImage(byte[] srcImage, int width, int pitch, int height, int pixelFormat) Associate an uncompressed source image with this compressor instance.voidsetSubsamp(int newSubsamp) Set the level of chrominance subsampling for subsequent compress/encode operations.
-
Field Details
-
NO_ASSOC_ERROR
- See Also:
-
handle
private long handle -
srcBuf
private byte[] srcBuf -
srcWidth
private int srcWidth -
srcHeight
private int srcHeight -
srcPitch
private int srcPitch -
srcPixelFormat
private int srcPixelFormat -
subsamp
private int subsamp -
jpegQuality
private int jpegQuality -
compressedSize
private int compressedSize -
byteOrder
-
-
Constructor Details
-
TJCompressor
Create a TurboJPEG compressor instance.- Throws:
Exception
-
TJCompressor
public TJCompressor(byte[] srcImage, int width, int pitch, int height, int pixelFormat) throws Exception Create a TurboJPEG compressor instance and associate the uncompressed source image stored insrcImagewith the newly-created instance.- Parameters:
srcImage- seesetSourceImage(byte[], int, int, int, int)for descriptionwidth- seesetSourceImage(byte[], int, int, int, int)for descriptionpitch- seesetSourceImage(byte[], int, int, int, int)for descriptionheight- seesetSourceImage(byte[], int, int, int, int)for descriptionpixelFormat- seesetSourceImage(byte[], int, int, int, int)for description- Throws:
Exception
-
-
Method Details
-
setSourceImage
public void setSourceImage(byte[] srcImage, int width, int pitch, int height, int pixelFormat) throws Exception Associate an uncompressed source image with this compressor instance.- Parameters:
srcImage- image buffer containing RGB or grayscale pixels to be compressedwidth- width (in pixels) of the source imagepitch- bytes per line of the source image. Normally, this should bewidth * TJ.pixelSize(pixelFormat)if the source image is unpadded, but you can use this parameter to, for instance, specify that the scanlines in the source image are padded to 4-byte boundaries, as is the case for Windows bitmaps. You can also be clever and use this parameter to skip lines, etc. Setting this parameter to 0 is the equivalent of setting it towidth * TJ.pixelSize(pixelFormat).height- height (in pixels) of the source imagepixelFormat- pixel format of the source image (one ofTJ.PF_*)- Throws:
Exception
-
setSubsamp
Set the level of chrominance subsampling for subsequent compress/encode operations. -
setJPEGQuality
Set the JPEG image quality level for subsequent compress operations.- Parameters:
quality- the new JPEG image quality level (1 to 100, 1 = worst, 100 = best)- Throws:
Exception
-
compress
Compress the uncompressed source image associated with this compressor instance and output a JPEG image to the given destination buffer.- Parameters:
dstBuf- buffer that will receive the JPEG image. UseTJ.bufSize(int, int, int)to determine the maximum size for this buffer based on the image width and height.flags- the bitwise OR of one or more ofTJ.FLAG_*- Throws:
Exception
-
compress
Compress the uncompressed source image associated with this compressor instance and return a buffer containing a JPEG image.- Parameters:
flags- the bitwise OR of one or more ofTJ.FLAG_*- Returns:
- a buffer containing a JPEG image. The length of this buffer will
not be equal to the size of the JPEG image. Use
getCompressedSize()to obtain the size of the JPEG image. - Throws:
Exception
-
compress
Compress the uncompressed source image stored insrcImageand output a JPEG image to the given destination buffer.- Parameters:
srcImage- aBufferedImageinstance containing RGB or grayscale pixels to be compresseddstBuf- buffer that will receive the JPEG image. UseTJ.bufSize(int, int, int)to determine the maximum size for this buffer based on the image width and height.flags- the bitwise OR of one or more ofTJ.FLAG_*- Throws:
Exception
-
compress
Compress the uncompressed source image stored insrcImageand return a buffer containing a JPEG image.- Parameters:
srcImage- aBufferedImageinstance containing RGB or grayscale pixels to be compressedflags- the bitwise OR of one or more ofTJ.FLAG_*- Returns:
- a buffer containing a JPEG image. The length of this buffer will
not be equal to the size of the JPEG image. Use
getCompressedSize()to obtain the size of the JPEG image. - Throws:
Exception
-
encodeYUV
Encode the uncompressed source image associated with this compressor instance and output a YUV planar image to the given destination buffer. This method uses the accelerated color conversion routines in TurboJPEG's underlying codec to produce a planar YUV image that is suitable for direct video display. Specifically, if the chrominance components are subsampled along the horizontal dimension, then the width of the luminance plane is padded to 2 in the output image (same goes for the height of the luminance plane, if the chrominance components are subsampled along the vertical dimension.) Also, each line of each plane in the output image is padded to 4 bytes. Although this will work with any subsampling option, it is really only useful in combination withTJ.SAMP_420, which produces an image compatible with the I420 (AKA "YUV420P") format.- 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
-
encodeYUV
Encode the uncompressed source image associated with this compressor instance and return a buffer containing a YUV planar image. SeeencodeYUV(byte[], int)for more detail. -
encodeYUV
Encode the uncompressed source image stored insrcImageand output a YUV planar image to the given destination buffer. SeeencodeYUV(byte[], int)for more detail.- Parameters:
srcImage- aBufferedImageinstance containing RGB or grayscale pixels to be encodeddstBuf- 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
-
encodeYUV
Encode the uncompressed source image stored insrcImageand return a buffer containing a YUV planar image. SeeencodeYUV(byte[], int)for more detail. -
getCompressedSize
public int getCompressedSize()Returns the size of the image (in bytes) generated by the most recent compress/encode operation.- Returns:
- the size of the image (in bytes) generated by the most recent compress/encode operation
-
close
Free the native structures associated with this compressor instance.- Throws:
Exception
-
finalize
-
init
- Throws:
Exception
-
destroy
- Throws:
Exception
-
compress
private int compress(byte[] srcBuf, int width, int pitch, int height, int pixelFormat, byte[] dstbuf, int jpegSubsamp, int jpegQual, int flags) throws Exception - Throws:
Exception
-
compress
private int compress(int[] srcBuf, int width, int pitch, int height, int pixelFormat, byte[] dstbuf, int jpegSubsamp, int jpegQual, int flags) throws Exception - Throws:
Exception
-
encodeYUV
private void encodeYUV(byte[] srcBuf, int width, int pitch, int height, int pixelFormat, byte[] dstbuf, int subsamp, int flags) throws Exception - Throws:
Exception
-
encodeYUV
private void encodeYUV(int[] srcBuf, int width, int pitch, int height, int pixelFormat, byte[] dstbuf, int subsamp, int flags) throws Exception - Throws:
Exception
-