Class TJ
- java.lang.Object
-
- org.libjpegturbo.turbojpeg.TJ
-
public final class TJ extends java.lang.Object
TurboJPEG utility class (cannot be instantiated)
-
-
Field Summary
Fields Modifier and Type Field Description static int
CS_CMYK
CMYK colorspace.static int
CS_GRAY
Grayscale colorspace.static int
CS_RGB
RGB colorspace.static int
CS_YCbCr
YCbCr colorspace.static int
CS_YCCK
YCCK colorspace.static int
ERR_FATAL
The error was fatal and non-recoverable.static int
ERR_WARNING
The error was non-fatal and recoverable, but the destination image may still be corrupt.static int
FLAG_ACCURATEDCT
Deprecated.UsePARAM_FASTDCT
instead.static int
FLAG_BOTTOMUP
Deprecated.UsePARAM_BOTTOMUP
instead.static int
FLAG_FASTDCT
Deprecated.UsePARAM_FASTDCT
instead.static int
FLAG_FASTUPSAMPLE
Deprecated.UsePARAM_FASTUPSAMPLE
instead.static int
FLAG_LIMITSCANS
Deprecated.UsePARAM_SCANLIMIT
instead.static int
FLAG_PROGRESSIVE
Deprecated.UsePARAM_PROGRESSIVE
instead.static int
FLAG_STOPONWARNING
Deprecated.UsePARAM_STOPONWARNING
instead.static int
NUMCS
The number of JPEG colorspacesstatic int
NUMERR
The number of error codesstatic int
NUMPF
The number of pixel formatsstatic int
NUMSAMP
The number of chrominance subsampling optionsstatic int
PARAM_ARITHMETIC
Arithmetic entropy codingstatic int
PARAM_BOTTOMUP
Row order in packed-pixel source/destination imagesstatic int
PARAM_COLORSPACE
JPEG colorspacestatic int
PARAM_DENSITYUNITS
JPEG pixel density unitsstatic int
PARAM_FASTDCT
DCT/IDCT algorithm [lossy compression and decompression]static int
PARAM_FASTUPSAMPLE
Chrominance upsampling algorithm [lossy decompression only]static int
PARAM_JPEGHEIGHT
JPEG height (in pixels) [decompression only, read-only]static int
PARAM_JPEGWIDTH
JPEG width (in pixels) [decompression only, read-only]static int
PARAM_LOSSLESS
Lossless JPEGstatic int
PARAM_LOSSLESSPSV
Lossless JPEG predictor selection value (PSV)static int
PARAM_LOSSLESSPT
Lossless JPEG point transform (Pt)static int
PARAM_MAXMEMORY
Memory limit for intermediate buffersstatic int
PARAM_MAXPIXELS
Image size limit [decompression, lossless transformation]static int
PARAM_OPTIMIZE
Optimized baseline entropy coding [lossy compression only]static int
PARAM_PRECISION
JPEG data precision (bits per sample) [decompression only, read-only]static int
PARAM_PROGRESSIVE
Progressive entropy codingstatic int
PARAM_QUALITY
Perceptual quality of lossy JPEG images [compression only]static int
PARAM_RESTARTBLOCKS
JPEG restart marker interval in MCU blocks (lossy) or samples (lossless) [compression only]static int
PARAM_RESTARTROWS
JPEG restart marker interval in MCU rows (lossy) or sample rows (lossless) [compression only]static int
PARAM_SCANLIMIT
Progressive JPEG scan limit for lossy JPEG images [decompression, lossless transformation]static int
PARAM_STOPONWARNING
Error handling behaviorstatic int
PARAM_SUBSAMP
Chrominance subsampling levelstatic int
PARAM_XDENSITY
JPEG horizontal pixel densitystatic int
PARAM_YDENSITY
JPEG vertical pixel densitystatic int
PF_ABGR
ABGR pixel format.static int
PF_ARGB
ARGB pixel format.static int
PF_BGR
BGR pixel format.static int
PF_BGRA
BGRA pixel format.static int
PF_BGRX
BGRX pixel format.static int
PF_CMYK
CMYK pixel format.static int
PF_GRAY
Grayscale pixel format.static int
PF_RGB
RGB pixel format.static int
PF_RGBA
RGBA pixel format.static int
PF_RGBX
RGBX pixel format.static int
PF_XBGR
XBGR pixel format.static int
PF_XRGB
XRGB pixel format.static int
SAMP_411
4:1:1 chrominance subsampling.static int
SAMP_420
4:2:0 chrominance subsampling.static int
SAMP_422
4:2:2 chrominance subsampling.static int
SAMP_440
4:4:0 chrominance subsampling.static int
SAMP_441
4:4:1 chrominance subsampling.static int
SAMP_444
4:4:4 chrominance subsampling (no chrominance subsampling).static int
SAMP_GRAY
Grayscale.static int
SAMP_UNKNOWN
Unknown subsampling.static java.awt.Rectangle
UNCROPPED
Ajava.awt.Rectangle
instance that specifies no croppingstatic TJScalingFactor
UNSCALED
ATJScalingFactor
instance that specifies a scaling factor of 1/1 (no scaling)
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
bufSize(int width, int height, int jpegSubsamp)
Returns the maximum size of the buffer (in bytes) required to hold a JPEG image with the given width, height, and level of chrominance subsampling.static int
bufSizeYUV(int width, int align, int height, int subsamp)
Returns the size of the buffer (in bytes) required to hold a unified planar YUV image with the given width, height, and level of chrominance subsampling.static int
getAlphaOffset(int pixelFormat)
For the given pixel format, returns the number of samples that the alpha component is offset from the start of the pixel.static int
getBlueOffset(int pixelFormat)
For the given pixel format, returns the number of samples that the blue component is offset from the start of the pixel.static int
getGreenOffset(int pixelFormat)
For the given pixel format, returns the number of samples that the green component is offset from the start of the pixel.static int
getMCUHeight(int subsamp)
Returns the MCU block height for the given level of chrominance subsampling.static int
getMCUWidth(int subsamp)
Returns the MCU block width for the given level of chrominance subsampling.static int
getPixelSize(int pixelFormat)
Returns the pixel size (in samples) for the given pixel format.static int
getRedOffset(int pixelFormat)
For the given pixel format, returns the number of samples that the red component is offset from the start of the pixel.static TJScalingFactor[]
getScalingFactors()
Returns a list of fractional scaling factors that the JPEG decompressor supports.static int
planeHeight(int componentID, int height, int subsamp)
Returns the plane height of a YUV image plane with the given parameters.static int
planeSizeYUV(int componentID, int width, int stride, int height, int subsamp)
Returns the size of the buffer (in bytes) required to hold a YUV image plane with the given parameters.static int
planeWidth(int componentID, int width, int subsamp)
Returns the plane width of a YUV image plane with the given parameters.
-
-
-
Field Detail
-
NUMSAMP
public static final int NUMSAMP
The number of chrominance subsampling options- See Also:
- Constant Field Values
-
SAMP_444
public static final int SAMP_444
4:4:4 chrominance subsampling (no chrominance subsampling). The JPEG or YUV image will contain one chrominance component for every pixel in the source image.- See Also:
- Constant Field Values
-
SAMP_422
public static final int SAMP_422
4:2:2 chrominance subsampling. The JPEG or YUV image will contain one chrominance component for every 2x1 block of pixels in the source image.- See Also:
- Constant Field Values
-
SAMP_420
public static final int SAMP_420
4:2:0 chrominance subsampling. The JPEG or YUV image will contain one chrominance component for every 2x2 block of pixels in the source image.- See Also:
- Constant Field Values
-
SAMP_GRAY
public static final int SAMP_GRAY
Grayscale. The JPEG or YUV image will contain no chrominance components.- See Also:
- Constant Field Values
-
SAMP_440
public static final int SAMP_440
4:4:0 chrominance subsampling. The JPEG or YUV image will contain one chrominance component for every 1x2 block of pixels in the source image. Note that 4:4:0 subsampling is not fully accelerated in libjpeg-turbo.- See Also:
- Constant Field Values
-
SAMP_411
public static final int SAMP_411
4:1:1 chrominance subsampling. The JPEG or YUV image will contain one chrominance component for every 4x1 block of pixels in the source image. JPEG images compressed with 4:1:1 subsampling will be almost exactly the same size as those compressed with 4:2:0 subsampling, and in the aggregate, both subsampling methods produce approximately the same perceptual quality. However, 4:1:1 is better able to reproduce sharp horizontal features. Note that 4:1:1 subsampling is not fully accelerated in libjpeg-turbo.- See Also:
- Constant Field Values
-
SAMP_441
public static final int SAMP_441
4:4:1 chrominance subsampling. The JPEG or YUV image will contain one chrominance component for every 1x4 block of pixels in the source image. JPEG images compressed with 4:4:1 subsampling will be almost exactly the same size as those compressed with 4:2:0 subsampling, and in the aggregate, both subsampling methods produce approximately the same perceptual quality. However, 4:4:1 is better able to reproduce sharp vertical features. Note that 4:4:1 subsampling is not fully accelerated in libjpeg-turbo.- See Also:
- Constant Field Values
-
SAMP_UNKNOWN
public static final int SAMP_UNKNOWN
Unknown subsampling. The JPEG image uses an unusual type of chrominance subsampling. Such images can be decompressed into packed-pixel images, but they cannot be- decompressed into planar YUV images,
- losslessly transformed if
TJTransform.OPT_CROP
is specified, or - partially decompressed using a cropping region.
- See Also:
- Constant Field Values
-
NUMPF
public static final int NUMPF
The number of pixel formats- See Also:
- Constant Field Values
-
PF_RGB
public static final int PF_RGB
RGB pixel format. The red, green, and blue components in the image are stored in 3-sample pixels in the order R, G, B from lowest to highest memory address within each pixel.- See Also:
- Constant Field Values
-
PF_BGR
public static final int PF_BGR
BGR pixel format. The red, green, and blue components in the image are stored in 3-sample pixels in the order B, G, R from lowest to highest memory address within each pixel.- See Also:
- Constant Field Values
-
PF_RGBX
public static final int PF_RGBX
RGBX pixel format. The red, green, and blue components in the image are stored in 4-sample pixels in the order R, G, B from lowest to highest memory address within each pixel. The X component is ignored when compressing and undefined when decompressing.- See Also:
- Constant Field Values
-
PF_BGRX
public static final int PF_BGRX
BGRX pixel format. The red, green, and blue components in the image are stored in 4-sample pixels in the order B, G, R from lowest to highest memory address within each pixel. The X component is ignored when compressing and undefined when decompressing.- See Also:
- Constant Field Values
-
PF_XBGR
public static final int PF_XBGR
XBGR pixel format. The red, green, and blue components in the image are stored in 4-sample pixels in the order R, G, B from highest to lowest memory address within each pixel. The X component is ignored when compressing and undefined when decompressing.- See Also:
- Constant Field Values
-
PF_XRGB
public static final int PF_XRGB
XRGB pixel format. The red, green, and blue components in the image are stored in 4-sample pixels in the order B, G, R from highest to lowest memory address within each pixel. The X component is ignored when compressing and undefined when decompressing.- See Also:
- Constant Field Values
-
PF_GRAY
public static final int PF_GRAY
Grayscale pixel format. Each 1-sample pixel represents a luminance (brightness) level from 0 to the maximum sample value (255 for 8-bit samples, 4095 for 12-bit samples, and 65535 for 16-bit samples.)- See Also:
- Constant Field Values
-
PF_RGBA
public static final int PF_RGBA
RGBA pixel format. This is the same asPF_RGBX
, except that when decompressing, the X component is guaranteed to be equal to the maximum sample value, which can be interpreted as an opaque alpha channel.- See Also:
- Constant Field Values
-
PF_BGRA
public static final int PF_BGRA
BGRA pixel format. This is the same asPF_BGRX
, except that when decompressing, the X component is guaranteed to be equal to the maximum sample value, which can be interpreted as an opaque alpha channel.- See Also:
- Constant Field Values
-
PF_ABGR
public static final int PF_ABGR
ABGR pixel format. This is the same asPF_XBGR
, except that when decompressing, the X component is guaranteed to be equal to the maximum sample value, which can be interpreted as an opaque alpha channel.- See Also:
- Constant Field Values
-
PF_ARGB
public static final int PF_ARGB
ARGB pixel format. This is the same asPF_XRGB
, except that when decompressing, the X component is guaranteed to be equal to the maximum sample value, which can be interpreted as an opaque alpha channel.- See Also:
- Constant Field Values
-
PF_CMYK
public static final int PF_CMYK
CMYK pixel format. Unlike RGB, which is an additive color model used primarily for display, CMYK (Cyan/Magenta/Yellow/Key) is a subtractive color model used primarily for printing. In the CMYK color model, the value of each color component typically corresponds to an amount of cyan, magenta, yellow, or black ink that is applied to a white background. In order to convert between CMYK and RGB, it is necessary to use a color management system (CMS.) A CMS will attempt to map colors within the printer's gamut to perceptually similar colors in the display's gamut and vice versa, but the mapping is typically not 1:1 or reversible, nor can it be defined with a simple formula. Thus, such a conversion is out of scope for a codec library. However, the TurboJPEG API allows for compressing packed-pixel CMYK images into YCCK JPEG images (seeCS_YCCK
) and decompressing YCCK JPEG images into packed-pixel CMYK images.- See Also:
- Constant Field Values
-
NUMCS
public static final int NUMCS
The number of JPEG colorspaces- See Also:
- Constant Field Values
-
CS_RGB
public static final int CS_RGB
RGB colorspace. When compressing the JPEG image, the R, G, and B components in the source image are reordered into image planes, but no colorspace conversion or subsampling is performed. RGB JPEG images can be compressed from and decompressed to packed-pixel images with any of the extended RGB or grayscale pixel formats, but they cannot be compressed from or decompressed to planar YUV images.- See Also:
- Constant Field Values
-
CS_YCbCr
public static final int CS_YCbCr
YCbCr colorspace. YCbCr is not an absolute colorspace but rather a mathematical transformation of RGB designed solely for storage and transmission. YCbCr images must be converted to RGB before they can actually be displayed. In the YCbCr colorspace, the Y (luminance) component represents the black & white portion of the original image, and the Cb and Cr (chrominance) components represent the color portion of the original image. Originally, the analog equivalent of this transformation allowed the same signal to drive both black & white and color televisions, but JPEG images use YCbCr primarily because it allows the color data to be optionally subsampled for the purposes of reducing network or disk usage. YCbCr is the most common JPEG colorspace, and YCbCr JPEG images can be compressed from and decompressed to packed-pixel images with any of the extended RGB or grayscale pixel formats. YCbCr JPEG images can also be compressed from and decompressed to planar YUV images.- See Also:
- Constant Field Values
-
CS_GRAY
public static final int CS_GRAY
Grayscale colorspace. The JPEG image retains only the luminance data (Y component), and any color data from the source image is discarded. Grayscale JPEG images can be compressed from and decompressed to packed-pixel images with any of the extended RGB or grayscale pixel formats, or they can be compressed from and decompressed to planar YUV images.- See Also:
- Constant Field Values
-
CS_CMYK
public static final int CS_CMYK
CMYK colorspace. When compressing the JPEG image, the C, M, Y, and K components in the source image are reordered into image planes, but no colorspace conversion or subsampling is performed. CMYK JPEG images can only be compressed from and decompressed to packed-pixel images with the CMYK pixel format.- See Also:
- Constant Field Values
-
CS_YCCK
public static final int CS_YCCK
YCCK colorspace. YCCK (AKA "YCbCrK") is not an absolute colorspace but rather a mathematical transformation of CMYK designed solely for storage and transmission. It is to CMYK as YCbCr is to RGB. CMYK pixels can be reversibly transformed into YCCK, and as with YCbCr, the chrominance components in the YCCK pixels can be subsampled without incurring major perceptual loss. YCCK JPEG images can only be compressed from and decompressed to packed-pixel images with the CMYK pixel format.- See Also:
- Constant Field Values
-
PARAM_STOPONWARNING
public static final int PARAM_STOPONWARNING
Error handling behaviorValue
-
0
[default] Allow the current compression/decompression/transform operation to complete unless a fatal error is encountered. -
1
Immediately discontinue the current compression/decompression/transform operation if a warning (non-fatal error) occurs.
- See Also:
- Constant Field Values
-
-
PARAM_BOTTOMUP
public static final int PARAM_BOTTOMUP
Row order in packed-pixel source/destination imagesValue
-
0
[default] top-down (X11) order -
1
bottom-up (Windows, OpenGL) order
- See Also:
- Constant Field Values
-
-
PARAM_QUALITY
public static final int PARAM_QUALITY
Perceptual quality of lossy JPEG images [compression only]Value
-
1
-100
(1
= worst quality but best compression,100
= best quality but worst compression) [no default; must be explicitly specified]
- See Also:
- Constant Field Values
-
-
PARAM_SUBSAMP
public static final int PARAM_SUBSAMP
Chrominance subsampling levelThe JPEG or YUV image uses (decompression, decoding) or will use (lossy compression, encoding) the specified level of chrominance subsampling.
When pixels are converted from RGB to YCbCr (see
CS_YCbCr
) or from CMYK to YCCK (seeCS_YCCK
) as part of the JPEG compression process, some of the Cb and Cr (chrominance) components can be discarded or averaged together to produce a smaller image with little perceptible loss of image clarity. (The human eye is more sensitive to small changes in brightness than to small changes in color.) This is called "chrominance subsampling".Value
- One of
TJ.SAMP_*
[no default; must be explicitly specified for lossy compression, encoding, and decoding]
- See Also:
- Constant Field Values
- One of
-
PARAM_JPEGWIDTH
public static final int PARAM_JPEGWIDTH
JPEG width (in pixels) [decompression only, read-only]- See Also:
- Constant Field Values
-
PARAM_JPEGHEIGHT
public static final int PARAM_JPEGHEIGHT
JPEG height (in pixels) [decompression only, read-only]- See Also:
- Constant Field Values
-
PARAM_PRECISION
public static final int PARAM_PRECISION
JPEG data precision (bits per sample) [decompression only, read-only]The JPEG image uses the specified number of bits per sample.
Value
-
8
,12
, or16
12-bit data precision implies
PARAM_OPTIMIZE
unlessPARAM_ARITHMETIC
is set.- See Also:
- Constant Field Values
-
-
PARAM_COLORSPACE
public static final int PARAM_COLORSPACE
JPEG colorspaceThe JPEG image uses (decompression) or will use (lossy compression) the specified colorspace.
Value
- One of
TJ.CS_*
[default for lossy compression: automatically selected based on the subsampling level and pixel format]
- See Also:
- Constant Field Values
- One of
-
PARAM_FASTUPSAMPLE
public static final int PARAM_FASTUPSAMPLE
Chrominance upsampling algorithm [lossy decompression only]Value
-
0
[default] Use smooth upsampling when decompressing a JPEG image that was compressed using chrominance subsampling. This creates a smooth transition between neighboring chrominance components in order to reduce upsampling artifacts in the decompressed image. -
1
Use the fastest chrominance upsampling algorithm available, which may combine upsampling with color conversion.
- See Also:
- Constant Field Values
-
-
PARAM_FASTDCT
public static final int PARAM_FASTDCT
DCT/IDCT algorithm [lossy compression and decompression]Value
-
0
[default] Use the most accurate DCT/IDCT algorithm available. -
1
Use the fastest DCT/IDCT algorithm available.
This parameter is provided mainly for backward compatibility with libjpeg, which historically implemented several different DCT/IDCT algorithms because of performance limitations with 1990s CPUs. In the libjpeg-turbo implementation of the TurboJPEG API:
- The "fast" and "accurate" DCT/IDCT algorithms perform similarly on modern x86/x86-64 CPUs that support AVX2 instructions.
- The "fast" algorithm is generally only about 5-15% faster than the "accurate" algorithm on other types of CPUs.
- The difference in accuracy between the "fast" and "accurate" algorithms is the most pronounced at JPEG quality levels above 90 and tends to be more pronounced with decompression than with compression.
- The "fast" algorithm degrades and is not fully accelerated for JPEG quality levels above 97, so it will be slower than the "accurate" algorithm.
- See Also:
- Constant Field Values
-
-
PARAM_OPTIMIZE
public static final int PARAM_OPTIMIZE
Optimized baseline entropy coding [lossy compression only]Value
-
0
[default] The JPEG image will use the default Huffman tables. -
1
Optimal Huffman tables will be computed for the JPEG image. For lossless transformation, this can also be specified usingTJTransform.OPT_OPTIMIZE
.
Optimized baseline entropy coding will improve compression slightly (generally 5% or less), but it will reduce compression performance considerably.
- See Also:
- Constant Field Values
-
-
PARAM_PROGRESSIVE
public static final int PARAM_PROGRESSIVE
Progressive entropy codingValue
-
0
[default for compression, lossless transformation] The lossy JPEG image uses (decompression) or will use (compression, lossless transformation) baseline entropy coding. -
1
The lossy JPEG image uses (decompression) or will use (compression, lossless transformation) progressive entropy coding. For lossless transformation, this can also be specified usingTJTransform.OPT_PROGRESSIVE
.
Progressive entropy coding will generally improve compression relative to baseline entropy coding, but it will reduce compression and decompression performance considerably. Can be combined with
PARAM_ARITHMETIC
. ImpliesPARAM_OPTIMIZE
unlessPARAM_ARITHMETIC
is also set.- See Also:
- Constant Field Values
-
-
PARAM_SCANLIMIT
public static final int PARAM_SCANLIMIT
Progressive JPEG scan limit for lossy JPEG images [decompression, lossless transformation]Setting this parameter will cause the decompression and transform operations to throw an error if the number of scans in a progressive JPEG image exceeds the specified limit. The primary purpose of this is to allow security-critical applications to guard against an exploit of the progressive JPEG format described in this report.
Value
- maximum number of progressive JPEG scans that the decompression and
transform operations will process [default:
0
(no limit)]
- See Also:
PARAM_PROGRESSIVE
, Constant Field Values
- maximum number of progressive JPEG scans that the decompression and
transform operations will process [default:
-
PARAM_ARITHMETIC
public static final int PARAM_ARITHMETIC
Arithmetic entropy codingValue
-
0
[default for compression, lossless transformation] The lossy JPEG image uses (decompression) or will use (compression, lossless transformation) Huffman entropy coding. -
1
The lossy JPEG image uses (decompression) or will use (compression, lossless transformation) arithmetic entropy coding. For lossless transformation, this can also be specified usingTJTransform.OPT_ARITHMETIC
.
Arithmetic entropy coding will generally improve compression relative to Huffman entropy coding, but it will reduce compression and decompression performance considerably. Can be combined with
PARAM_PROGRESSIVE
.- See Also:
- Constant Field Values
-
-
PARAM_LOSSLESS
public static final int PARAM_LOSSLESS
Lossless JPEGValue
-
0
[default for compression] The JPEG image is (decompression) or will be (compression) lossy/DCT-based. -
1
The JPEG image is (decompression) or will be (compression) lossless/predictive.
In most cases, compressing and decompressing lossless JPEG images is considerably slower than compressing and decompressing lossy JPEG images, and lossless JPEG images are much larger than lossy JPEG images. Thus, lossless JPEG images are typically used only for applications that require mathematically lossless compression. Also note that the following features are not available with lossless JPEG images:
- Colorspace conversion (lossless JPEG images always use
CS_RGB
,CS_GRAY
, orCS_CMYK
, depending on the pixel format of the source image) - Chrominance subsampling (lossless JPEG images always use
SAMP_444
) - JPEG quality selection
- DCT/IDCT algorithm selection
- Progressive entropy coding
- Arithmetic entropy coding
- Compression from/decompression to planar YUV images
- Decompression scaling
- Lossless transformation
- See Also:
PARAM_LOSSLESSPSV
,PARAM_LOSSLESSPT
, Constant Field Values
-
-
PARAM_LOSSLESSPSV
public static final int PARAM_LOSSLESSPSV
Lossless JPEG predictor selection value (PSV)Value
-
1
-7
[default for compression:1
]
Lossless JPEG compression shares no algorithms with lossy JPEG compression. Instead, it uses differential pulse-code modulation (DPCM), an algorithm whereby each sample is encoded as the difference between the sample's value and a "predictor", which is based on the values of neighboring samples. If Ra is the sample immediately to the left of the current sample, Rb is the sample immediately above the current sample, and Rc is the sample diagonally to the left and above the current sample, then the relationship between the predictor selection value and the predictor is as follows:
PSV Predictor 1 Ra 2 Rb 3 Rc 4 Ra + Rb – Rc 5 Ra + (Rb – Rc) / 2 6 Rb + (Ra – Rc) / 2 7 (Ra + Rb) / 2 Predictors 1-3 are 1-dimensional predictors, whereas Predictors 4-7 are 2-dimensional predictors. The best predictor for a particular image depends on the image.
- See Also:
PARAM_LOSSLESS
, Constant Field Values
-
-
PARAM_LOSSLESSPT
public static final int PARAM_LOSSLESSPT
Lossless JPEG point transform (Pt)Value
-
0
through precision - 1, where precision is the JPEG data precision in bits [default for compression:0
]
A point transform value of
0
is necessary in order to generate a fully lossless JPEG image. (A non-zero point transform value right-shifts the input samples by the specified number of bits, which is effectively a form of lossy color quantization.)- See Also:
PARAM_LOSSLESS
,PARAM_PRECISION
, Constant Field Values
-
-
PARAM_RESTARTBLOCKS
public static final int PARAM_RESTARTBLOCKS
JPEG restart marker interval in MCU blocks (lossy) or samples (lossless) [compression only]The nature of entropy coding is such that a corrupt JPEG image cannot be decompressed beyond the point of corruption unless it contains restart markers. A restart marker stops and restarts the entropy coding algorithm so that, if a JPEG image is corrupted, decompression can resume at the next marker. Thus, adding more restart markers improves the fault tolerance of the JPEG image, but adding too many restart markers can adversely affect the compression ratio and performance.
Value
- the number of MCU blocks or samples between each restart marker
[default:
0
(no restart markers)]
Setting this parameter to a non-zero value sets
PARAM_RESTARTROWS
to 0.- See Also:
- Constant Field Values
- the number of MCU blocks or samples between each restart marker
[default:
-
PARAM_RESTARTROWS
public static final int PARAM_RESTARTROWS
JPEG restart marker interval in MCU rows (lossy) or sample rows (lossless) [compression only]See
PARAM_RESTARTBLOCKS
for a description of restart markers.Value
- the number of MCU rows or sample rows between each restart marker
[default:
0
(no restart markers)]
Setting this parameter to a non-zero value sets
PARAM_RESTARTBLOCKS
to 0.- See Also:
- Constant Field Values
- the number of MCU rows or sample rows between each restart marker
[default:
-
PARAM_XDENSITY
public static final int PARAM_XDENSITY
JPEG horizontal pixel densityValue
- The JPEG image has (decompression) or will have (compression) the
specified horizontal pixel density [default for compression:
1
].
This value is stored in or read from the JPEG header. It does not affect the contents of the JPEG image.
- See Also:
PARAM_DENSITYUNITS
, Constant Field Values
- The JPEG image has (decompression) or will have (compression) the
specified horizontal pixel density [default for compression:
-
PARAM_YDENSITY
public static final int PARAM_YDENSITY
JPEG vertical pixel densityValue
- The JPEG image has (decompression) or will have (compression) the
specified vertical pixel density [default for compression:
1
].
This value is stored in or read from the JPEG header. It does not affect the contents of the JPEG image.
- See Also:
PARAM_DENSITYUNITS
, Constant Field Values
- The JPEG image has (decompression) or will have (compression) the
specified vertical pixel density [default for compression:
-
PARAM_DENSITYUNITS
public static final int PARAM_DENSITYUNITS
JPEG pixel density unitsValue
-
0
[default for compression] The pixel density of the JPEG image is expressed (decompression) or will be expressed (compression) in unknown units. -
1
The pixel density of the JPEG image is expressed (decompression) or will be expressed (compression) in units of pixels/inch. -
2
The pixel density of the JPEG image is expressed (decompression) or will be expressed (compression) in units of pixels/cm.
This value is stored in or read from the JPEG header. It does not affect the contents of the JPEG image.
- See Also:
PARAM_XDENSITY
,PARAM_YDENSITY
, Constant Field Values
-
-
PARAM_MAXMEMORY
public static final int PARAM_MAXMEMORY
Memory limit for intermediate buffersValue
- the maximum amount of memory (in megabytes) that will be allocated
for intermediate buffers, which are used with progressive JPEG compression
and decompression, optimized baseline entropy coding, lossless JPEG
compression, and lossless transformation [default:
0
(no limit)]
- See Also:
- Constant Field Values
- the maximum amount of memory (in megabytes) that will be allocated
for intermediate buffers, which are used with progressive JPEG compression
and decompression, optimized baseline entropy coding, lossless JPEG
compression, and lossless transformation [default:
-
PARAM_MAXPIXELS
public static final int PARAM_MAXPIXELS
Image size limit [decompression, lossless transformation]Setting this parameter will cause the decompression and transform operations to throw an error if the number of pixels in the JPEG source image exceeds the specified limit. This allows security-critical applications to guard against excessive memory consumption.
Value
- maximum number of pixels that the decompression and transform
operations will process [default:
0
(no limit)]
- See Also:
- Constant Field Values
- maximum number of pixels that the decompression and transform
operations will process [default:
-
FLAG_BOTTOMUP
@Deprecated public static final int FLAG_BOTTOMUP
Deprecated.UsePARAM_BOTTOMUP
instead.- See Also:
- Constant Field Values
-
FLAG_FASTUPSAMPLE
@Deprecated public static final int FLAG_FASTUPSAMPLE
Deprecated.UsePARAM_FASTUPSAMPLE
instead.- See Also:
- Constant Field Values
-
FLAG_FASTDCT
@Deprecated public static final int FLAG_FASTDCT
Deprecated.UsePARAM_FASTDCT
instead.- See Also:
- Constant Field Values
-
FLAG_ACCURATEDCT
@Deprecated public static final int FLAG_ACCURATEDCT
Deprecated.UsePARAM_FASTDCT
instead.- See Also:
- Constant Field Values
-
FLAG_STOPONWARNING
@Deprecated public static final int FLAG_STOPONWARNING
Deprecated.UsePARAM_STOPONWARNING
instead.- See Also:
- Constant Field Values
-
FLAG_PROGRESSIVE
@Deprecated public static final int FLAG_PROGRESSIVE
Deprecated.UsePARAM_PROGRESSIVE
instead.- See Also:
- Constant Field Values
-
FLAG_LIMITSCANS
@Deprecated public static final int FLAG_LIMITSCANS
Deprecated.UsePARAM_SCANLIMIT
instead.- See Also:
- Constant Field Values
-
NUMERR
public static final int NUMERR
The number of error codes- See Also:
- Constant Field Values
-
ERR_WARNING
public static final int ERR_WARNING
The error was non-fatal and recoverable, but the destination image may still be corrupt.NOTE: due to the design of the TurboJPEG Java API, only certain methods (specifically,
TJDecompressor.decompress*()
methods with a void return type) will complete and leave the destination image in a fully recoverable state after a non-fatal error occurs.- See Also:
- Constant Field Values
-
ERR_FATAL
public static final int ERR_FATAL
The error was fatal and non-recoverable.- See Also:
- Constant Field Values
-
UNSCALED
public static final TJScalingFactor UNSCALED
ATJScalingFactor
instance that specifies a scaling factor of 1/1 (no scaling)
-
UNCROPPED
public static final java.awt.Rectangle UNCROPPED
Ajava.awt.Rectangle
instance that specifies no cropping
-
-
Method Detail
-
getMCUWidth
public static int getMCUWidth(int subsamp)
Returns the MCU block width for the given level of chrominance subsampling.- Parameters:
subsamp
- the level of chrominance subsampling (one ofSAMP_*
)- Returns:
- the MCU block width for the given level of chrominance subsampling.
-
getMCUHeight
public static int getMCUHeight(int subsamp)
Returns the MCU block height for the given level of chrominance subsampling.- Parameters:
subsamp
- the level of chrominance subsampling (one ofSAMP_*
)- Returns:
- the MCU block height for the given level of chrominance subsampling.
-
getPixelSize
public static int getPixelSize(int pixelFormat)
Returns the pixel size (in samples) for the given pixel format.- Parameters:
pixelFormat
- the pixel format (one ofPF_*
)- Returns:
- the pixel size (in samples) for the given pixel format.
-
getRedOffset
public static int getRedOffset(int pixelFormat)
For the given pixel format, returns the number of samples that the red component is offset from the start of the pixel. For instance, if an 8-bit-per-sample pixel of formatTJ.PF_BGRX
is stored inchar pixel[]
, then the red component will bepixel[TJ.getRedOffset(TJ.PF_BGRX)]
.- Parameters:
pixelFormat
- the pixel format (one ofPF_*
)- Returns:
- the red offset for the given pixel format, or -1 if the pixel format does not have a red component.
-
getGreenOffset
public static int getGreenOffset(int pixelFormat)
For the given pixel format, returns the number of samples that the green component is offset from the start of the pixel. For instance, if an 8-bit-per-sample pixel of formatTJ.PF_BGRX
is stored inchar pixel[]
, then the green component will bepixel[TJ.getGreenOffset(TJ.PF_BGRX)]
.- Parameters:
pixelFormat
- the pixel format (one ofPF_*
)- Returns:
- the green offset for the given pixel format, or -1 if the pixel format does not have a green component.
-
getBlueOffset
public static int getBlueOffset(int pixelFormat)
For the given pixel format, returns the number of samples that the blue component is offset from the start of the pixel. For instance, if an 8-bit-per-sample pixel of formatTJ.PF_BGRX
is stored inchar pixel[]
, then the blue component will bepixel[TJ.getBlueOffset(TJ.PF_BGRX)]
.- Parameters:
pixelFormat
- the pixel format (one ofPF_*
)- Returns:
- the blue offset for the given pixel format, or -1 if the pixel format does not have a blue component.
-
getAlphaOffset
public static int getAlphaOffset(int pixelFormat)
For the given pixel format, returns the number of samples that the alpha component is offset from the start of the pixel. For instance, if an 8-bit-per-sample pixel of formatTJ.PF_BGRA
is stored inchar pixel[]
, then the alpha component will bepixel[TJ.getAlphaOffset(TJ.PF_BGRA)]
.- Parameters:
pixelFormat
- the pixel format (one ofPF_*
)- Returns:
- the alpha offset for the given pixel format, or -1 if the pixel format does not have a alpha component.
-
bufSize
public static int bufSize(int width, int height, int jpegSubsamp)
Returns the maximum size of the buffer (in bytes) required to hold a JPEG image with the given width, height, and level of chrominance subsampling.- Parameters:
width
- the width (in pixels) of the JPEG imageheight
- the height (in pixels) of the JPEG imagejpegSubsamp
- the level of chrominance subsampling to be used when generating the JPEG image (one ofTJ.SAMP_*
.)SAMP_UNKNOWN
is treated likeSAMP_444
, since a buffer large enough to hold a JPEG image with no subsampling should also be large enough to hold a JPEG image with an arbitrary level of subsampling. Note that lossless JPEG images always useSAMP_444
.- Returns:
- the maximum size of the buffer (in bytes) required to hold a JPEG image with the given width, height, and level of chrominance subsampling.
-
bufSizeYUV
public static int bufSizeYUV(int width, int align, int height, int subsamp)
Returns the size of the buffer (in bytes) required to hold a unified planar YUV image with the given width, height, and level of chrominance subsampling.- Parameters:
width
- the width (in pixels) of the YUV imagealign
- row alignment (in bytes) of the YUV image (must be a power of 2.) Setting this parameter to n specifies that each row in each plane of the YUV image will be padded to the nearest multiple of n bytes (1 = unpadded.)height
- the height (in pixels) of the YUV imagesubsamp
- the level of chrominance subsampling used in the YUV image (one ofTJ.SAMP_*
)- Returns:
- the size of the buffer (in bytes) required to hold a unified planar YUV image with the given width, height, and level of chrominance subsampling.
-
planeSizeYUV
public static int planeSizeYUV(int componentID, int width, int stride, int height, int subsamp)
Returns the size of the buffer (in bytes) required to hold a YUV image plane with the given parameters.- Parameters:
componentID
- ID number of the image plane (0 = Y, 1 = U/Cb, 2 = V/Cr)width
- width (in pixels) of the YUV image. NOTE: this is the width of the whole image, not the plane width.stride
- bytes per row in the image plane.height
- height (in pixels) of the YUV image. NOTE: this is the height of the whole image, not the plane height.subsamp
- the level of chrominance subsampling used in the YUV image (one ofTJ.SAMP_*
)- Returns:
- the size of the buffer (in bytes) required to hold a YUV image plane with the given parameters.
-
planeWidth
public static int planeWidth(int componentID, int width, int subsamp)
Returns the plane width of a YUV image plane with the given parameters. Refer toYUVImage
for a description of plane width.- Parameters:
componentID
- ID number of the image plane (0 = Y, 1 = U/Cb, 2 = V/Cr)width
- width (in pixels) of the YUV imagesubsamp
- the level of chrominance subsampling used in the YUV image (one ofTJ.SAMP_*
)- Returns:
- the plane width of a YUV image plane with the given parameters.
-
planeHeight
public static int planeHeight(int componentID, int height, int subsamp)
Returns the plane height of a YUV image plane with the given parameters. Refer toYUVImage
for a description of plane height.- Parameters:
componentID
- ID number of the image plane (0 = Y, 1 = U/Cb, 2 = V/Cr)height
- height (in pixels) of the YUV imagesubsamp
- the level of chrominance subsampling used in the YUV image (one ofTJ.SAMP_*
)- Returns:
- the plane height of a YUV image plane with the given parameters.
-
getScalingFactors
public static TJScalingFactor[] getScalingFactors()
Returns a list of fractional scaling factors that the JPEG decompressor supports.- Returns:
- a list of fractional scaling factors that the JPEG decompressor supports.
-
-