java/doc/org/libjpegturbo/turbojpeg/TJCompressor.html
Package org.libjpegturbo.turbojpeg
java.lang.Object
All Implemented Interfaces:java.io.Closeable, java.lang.AutoCloseable
public classTJCompressorextends java.lang.Object
implements java.io.Closeable
TurboJPEG compressor
Constructors | Constructor | Description |
| --- | --- |
| TJCompressor() |
Create a TurboJPEG compressor instance.
|
| TJCompressor(byte[] srcImage, int x, int y, int width, int pitch, int height, int pixelFormat) |
Create a TurboJPEG compressor instance and associate the 8-bit-per-sample packed-pixel source image stored in srcImage with the newly created instance.
|
| TJCompressor(java.awt.image.BufferedImage srcImage, int x, int y, int width, int height) |
Create a TurboJPEG compressor instance and associate the 8-bit-per-sample packed-pixel source image stored in srcImage with the newly created instance.
|
All Methods Instance Methods Concrete Methods Deprecated Methods | Modifier and Type | Method | Description |
| --- | --- | --- |
| void | close() |
Free the native structures associated with this compressor instance.
|
| byte[] | compress() |
Compress the packed-pixel or planar YUV source image associated with this compressor instance and return a buffer containing a JPEG image.
|
| void | compress(byte[] dstBuf) |
Compress the packed-pixel or planar YUV source image associated with this compressor instance and output a JPEG image to the given destination buffer.
|
| void | compress(byte[] dstBuf, int flags) |
Deprecated.
Use set() and compress(byte[]) instead.
|
| byte[] | compress(int flags) |
Deprecated.
Use set() and compress() instead.
|
| YUVImage | encodeYUV(int align) |
Encode the 8-bit-per-sample packed-pixel source image associated with this compressor instance into an 8-bit-per-sample unified planar YUV image and return a YUVImage instance containing the encoded image.
|
| YUVImage | encodeYUV(int[] strides) |
Encode the 8-bit-per-sample packed-pixel source image associated with this compressor instance into separate 8-bit-per-sample Y, U (Cb), and V (Cr) image planes and return a YUVImage instance containing the encoded image planes.
|
| YUVImage | encodeYUV(int[] strides, int flags) |
Deprecated.
Use set() and encodeYUV(int[]) instead.
|
| YUVImage | encodeYUV(int align, int flags) |
Deprecated.
Use set() and encodeYUV(int) instead.
|
| void | encodeYUV(YUVImage dstImage) |
Encode the 8-bit-per-sample packed-pixel source image associated with this compressor instance into an 8-bit-per-sample planar YUV image and store it in the given YUVImage instance.
|
| void | encodeYUV(YUVImage dstImage, int flags) |
Deprecated.
Use set() and encodeYUV(YUVImage) instead.
|
| protected void | finalize() | |
| int | get(int param) |
Get the value of a compression parameter.
|
| int | getCompressedSize() |
Returns the size of the image (in bytes) generated by the most recent compression operation.
|
| void | set(int param, int value) |
Set the value of a compression parameter.
|
| void | setJPEGQuality(int quality) |
Deprecated.
Use set(TJ.PARAM_QUALITY, ...) instead.
|
| void | setSourceImage(byte[] srcImage, int x, int y, int width, int pitch, int height, int pixelFormat) |
Associate an 8-bit-per-sample packed-pixel RGB, grayscale, or CMYK source image with this compressor instance.
|
| void | setSourceImage(java.awt.image.BufferedImage srcImage, int x, int y, int width, int height) |
Associate an 8-bit-per-sample packed-pixel RGB or grayscale source image with this compressor instance.
|
| void | setSourceImage(YUVImage srcImage) |
Associate an 8-bit-per-sample planar YUV source image with this compressor instance.
|
| void | setSourceImage12(short[] srcImage, int x, int y, int width, int pitch, int height, int pixelFormat) |
Associate a 12-bit-per-sample packed-pixel RGB, grayscale, or CMYK source image with this compressor instance.
|
| void | setSourceImage16(short[] srcImage, int x, int y, int width, int pitch, int height, int pixelFormat) |
Associate a 16-bit-per-sample packed-pixel RGB, grayscale, or CMYK source image with this compressor instance.
|
| void | setSubsamp(int subsamp) |
Deprecated.
Use set(TJ.PARAM_SUBSAMP, ...) instead.
|
-
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
public TJCompressor()
throws[TJException](TJException.html "class in org.libjpegturbo.turbojpeg")
Create a TurboJPEG compressor instance.
Throws:TJException
-
public TJCompressor(byte[] srcImage,
int x,
int y,
int width,
int pitch,
int height,
int pixelFormat)
throws[TJException](TJException.html "class in org.libjpegturbo.turbojpeg")
Create a TurboJPEG compressor instance and associate the 8-bit-per-sample packed-pixel source image stored in srcImage with the newly created instance.
Parameters:srcImage - see setSourceImage(byte[], int, int, int, int, int, int) for descriptionx - see setSourceImage(byte[], int, int, int, int, int, int) for descriptiony - see setSourceImage(byte[], int, int, int, int, int, int) for descriptionwidth - see setSourceImage(byte[], int, int, int, int, int, int) for descriptionpitch - see setSourceImage(byte[], int, int, int, int, int, int) for descriptionheight - see setSourceImage(byte[], int, int, int, int, int, int) for descriptionpixelFormat - pixel format of the source image (one of TJ.PF_*)Throws:TJException
-
public TJCompressor(java.awt.image.BufferedImage srcImage,
int x,
int y,
int width,
int height)
throws[TJException](TJException.html "class in org.libjpegturbo.turbojpeg")
Create a TurboJPEG compressor instance and associate the 8-bit-per-sample packed-pixel source image stored in srcImage with the newly created instance.
Parameters:srcImage - see setSourceImage(BufferedImage, int, int, int, int) for descriptionx - see setSourceImage(BufferedImage, int, int, int, int) for descriptiony - see setSourceImage(BufferedImage, int, int, int, int) for descriptionwidth - see setSourceImage(BufferedImage, int, int, int, int) for descriptionheight - see setSourceImage(BufferedImage, int, int, int, int) for descriptionThrows:TJException
-
public void setSourceImage(byte[] srcImage,
int x,
int y,
int width,
int pitch,
int height,
int pixelFormat)
throws[TJException](TJException.html "class in org.libjpegturbo.turbojpeg")
Associate an 8-bit-per-sample packed-pixel RGB, grayscale, or CMYK source image with this compressor instance.
Parameters:srcImage - buffer containing a packed-pixel RGB, grayscale, or CMYK source image to be compressed or encoded. This buffer is not modified.x - x offset (in pixels) of the region in the source image from which the JPEG or YUV image should be compressed/encodedy - y offset (in pixels) of the region in the source image from which the JPEG or YUV image should be compressed/encodedwidth - width (in pixels) of the region in the source image from which the JPEG or YUV image should be compressed/encodedpitch - bytes per row in the source image. Normally this should be width * TJ.getPixelSize(pixelFormat), if the source image is unpadded. (Setting this parameter to 0 is the equivalent of setting it to width * TJ.getPixelSize(pixelFormat).) However, you can also use this parameter to specify the row alignment/padding of the source image, to skip rows, or to compress/encode a JPEG or YUV image from a specific region of a larger source image.height - height (in pixels) of the region in the source image from which the JPEG or YUV image should be compressed/encodedpixelFormat - pixel format of the source image (one of TJ.PF_*)Throws:TJException
-
public void setSourceImage12(short[] srcImage,
int x,
int y,
int width,
int pitch,
int height,
int pixelFormat)
throws[TJException](TJException.html "class in org.libjpegturbo.turbojpeg")
Associate a 12-bit-per-sample packed-pixel RGB, grayscale, or CMYK source image with this compressor instance. Note that 12-bit-per-sample packed-pixel source images can only be compressed into 12-bit-per-sample JPEG images.
Parameters:srcImage - buffer containing a packed-pixel RGB, grayscale, or CMYK source image to be compressed. This buffer is not modified.x - x offset (in pixels) of the region in the source image from which the JPEG image should be compressedy - y offset (in pixels) of the region in the source image from which the JPEG image should be compressedwidth - width (in pixels) of the region in the source image from which the JPEG image should be compressedpitch - samples per row in the source image. Normally this should be width * TJ.getPixelSize(pixelFormat), if the source image is unpadded. (Setting this parameter to 0 is the equivalent of setting it to width * TJ.getPixelSize(pixelFormat).) However, you can also use this parameter to specify the row alignment/padding of the source image, to skip rows, or to compress a JPEG image from a specific region of a larger source image.height - height (in pixels) of the region in the source image from which the JPEG image should be compressedpixelFormat - pixel format of the source image (one of TJ.PF_*)Throws:TJException
-
public void setSourceImage16(short[] srcImage,
int x,
int y,
int width,
int pitch,
int height,
int pixelFormat)
throws[TJException](TJException.html "class in org.libjpegturbo.turbojpeg")
Associate a 16-bit-per-sample packed-pixel RGB, grayscale, or CMYK source image with this compressor instance. Note that 16-bit-per-sample packed-pixel source images can only be compressed into 16-bit-per-sample lossless JPEG images.
Parameters:srcImage - buffer containing a packed-pixel RGB, grayscale, or CMYK source image to be compressed. This buffer is not modified.x - x offset (in pixels) of the region in the source image from which the JPEG image should be compressedy - y offset (in pixels) of the region in the source image from which the JPEG image should be compressedwidth - width (in pixels) of the region in the source image from which the JPEG image should be compressedpitch - samples per row in the source image. Normally this should be width * TJ.getPixelSize(pixelFormat), if the source image is unpadded. (Setting this parameter to 0 is the equivalent of setting it to width * TJ.getPixelSize(pixelFormat).) However, you can also use this parameter to specify the row alignment/padding of the source image, to skip rows, or to compress a JPEG image from a specific region of a larger source image.height - height (in pixels) of the region in the source image from which the JPEG image should be compressedpixelFormat - pixel format of the source image (one of TJ.PF_*)Throws:TJException
-
public void setSourceImage(java.awt.image.BufferedImage srcImage,
int x,
int y,
int width,
int height)
throws[TJException](TJException.html "class in org.libjpegturbo.turbojpeg")
Associate an 8-bit-per-sample packed-pixel RGB or grayscale source image with this compressor instance.
Parameters:srcImage - a BufferedImage instance containing a packed-pixel RGB or grayscale source image to be compressed or encoded. This image is not modified.x - x offset (in pixels) of the region in the source image from which the JPEG or YUV image should be compressed/encodedy - y offset (in pixels) of the region in the source image from which the JPEG or YUV image should be compressed/encodedwidth - width (in pixels) of the region in the source image from which the JPEG or YUV image should be compressed/encoded (0 = use the width of the source image)height - height (in pixels) of the region in the source image from which the JPEG or YUV image should be compressed/encoded (0 = use the height of the source image)Throws:TJException
-
public void setSourceImage([YUVImage](YUVImage.html "class in org.libjpegturbo.turbojpeg")srcImage)
throws[TJException](TJException.html "class in org.libjpegturbo.turbojpeg")
Associate an 8-bit-per-sample planar YUV source image with this compressor instance. This method sets TJ.PARAM_SUBSAMP to the chrominance subsampling level of the source image.
Parameters:srcImage - planar YUV source image to be compressed. This image is not modified.Throws:TJException
-
public void set(int param,
int value)
Set the value of a compression parameter.
Parameters:param - one of TJ.PARAM_*value - value of the compression parameter (refer to parameter documentation)
-
public int get(int param)
Get the value of a compression parameter.
Parameters:param - one of TJ.PARAM_*Returns:the value of the specified compression parameter, or -1 if the value is unknown.
-
@Deprecated
public void setSubsamp(int subsamp)
Deprecated.
Use set(TJ.PARAM_SUBSAMP, ...) instead.
-
@Deprecated
public void setJPEGQuality(int quality)
Deprecated.
Use set(TJ.PARAM_QUALITY, ...) instead.
-
public void compress(byte[] dstBuf)
throws[TJException](TJException.html "class in org.libjpegturbo.turbojpeg")
Compress the packed-pixel or planar YUV 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. Use TJ.bufSize() to determine the maximum size for this buffer based on the source image's width and height and the desired level of chrominance subsampling (see TJ.PARAM_SUBSAMP.)Throws:TJException
-
@Deprecated
public void compress(byte[] dstBuf,
int flags)
throws[TJException](TJException.html "class in org.libjpegturbo.turbojpeg")
Deprecated.
Use set() and compress(byte[]) instead.
Throws:TJException
-
public byte[] compress()
throws[TJException](TJException.html "class in org.libjpegturbo.turbojpeg")
Compress the packed-pixel or planar YUV source image associated with this compressor instance and return a buffer containing a JPEG image.
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:TJException
-
@Deprecated
public byte[] compress(int flags)
throws[TJException](TJException.html "class in org.libjpegturbo.turbojpeg")
Deprecated.
Use set() and compress() instead.
Throws:TJException
-
public void encodeYUV([YUVImage](YUVImage.html "class in org.libjpegturbo.turbojpeg")dstImage)
throws[TJException](TJException.html "class in org.libjpegturbo.turbojpeg")
Encode the 8-bit-per-sample packed-pixel source image associated with this compressor instance into an 8-bit-per-sample planar YUV image and store it in the given YUVImage instance. This method performs color conversion (which is accelerated in the libjpeg-turbo implementation) but does not execute any of the other steps in the JPEG compression process. Encoding CMYK source images into YUV images is not supported. This method sets TJ.PARAM_SUBSAMP to the chrominance subsampling level of the destination image.
Parameters:dstImage - YUVImage instance that will receive the planar YUV imageThrows:TJException
-
@Deprecated
public void encodeYUV([YUVImage](YUVImage.html "class in org.libjpegturbo.turbojpeg")dstImage,
int flags)
throws[TJException](TJException.html "class in org.libjpegturbo.turbojpeg")
Deprecated.
Use set() and encodeYUV(YUVImage) instead.
Throws:TJException
-
public[YUVImage](YUVImage.html "class in org.libjpegturbo.turbojpeg")encodeYUV(int align)
throws[TJException](TJException.html "class in org.libjpegturbo.turbojpeg")
Encode the 8-bit-per-sample packed-pixel source image associated with this compressor instance into an 8-bit-per-sample unified planar YUV image and return a YUVImage instance containing the encoded image. This method performs color conversion (which is accelerated in the libjpeg-turbo implementation) but does not execute any of the other steps in the JPEG compression process. Encoding CMYK source images into YUV images is not supported.
Parameters:align - row alignment (in bytes) of the YUV image (must be a power of 2.) Setting this parameter to n will cause each row in each plane of the YUV image to be padded to the nearest multiple of n bytes (1 = unpadded.)Returns:a YUVImage instance containing the unified planar YUV encoded imageThrows:TJException
-
@Deprecated
public[YUVImage](YUVImage.html "class in org.libjpegturbo.turbojpeg")encodeYUV(int align,
int flags)
throws[TJException](TJException.html "class in org.libjpegturbo.turbojpeg")
Deprecated.
Use set() and encodeYUV(int) instead.
Throws:TJException
-
public[YUVImage](YUVImage.html "class in org.libjpegturbo.turbojpeg")encodeYUV(int[] strides)
throws[TJException](TJException.html "class in org.libjpegturbo.turbojpeg")
Encode the 8-bit-per-sample packed-pixel source image associated with this compressor instance into separate 8-bit-per-sample Y, U (Cb), and V (Cr) image planes and return a YUVImage instance containing the encoded image planes. This method performs color conversion (which is accelerated in the libjpeg-turbo implementation) but does not execute any of the other steps in the JPEG compression process. Encoding CMYK source images into YUV images is not supported.
Parameters:strides - an array of integers, each specifying the number of bytes per row in the corresponding plane of the YUV source image. Setting the stride for any plane to 0 is the same as setting it to the plane width (see YUVImage.) If strides is null, then the strides for all planes will be set to their respective plane widths. You can adjust the strides in order to add an arbitrary amount of row padding to each plane.Returns:a YUVImage instance containing the encoded image planesThrows:TJException
-
@Deprecated
public[YUVImage](YUVImage.html "class in org.libjpegturbo.turbojpeg")encodeYUV(int[] strides,
int flags)
throws[TJException](TJException.html "class in org.libjpegturbo.turbojpeg")
Deprecated.
Use set() and encodeYUV(int[]) instead.
Throws:TJException
-
public int getCompressedSize()
Returns the size of the image (in bytes) generated by the most recent compression operation. Returns:the size of the image (in bytes) generated by the most recent compression operation.
-
public void close()
throws[TJException](TJException.html "class in org.libjpegturbo.turbojpeg")
Free the native structures associated with this compressor instance.
Specified by:close in interface java.lang.AutoCloseableSpecified by:close in interface java.io.CloseableThrows:TJException
-
protected void finalize()
throws java.lang.Throwable
Overrides:finalize in class java.lang.ObjectThrows:java.lang.Throwable