org.libjpegturbo.turbojpeg

## 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 and 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` | `FLAG_ACCURATEDCT` Use the most accurate DCT/IDCT algorithm available in the underlying codec.
    `static int` | `FLAG_BOTTOMUP` The uncompressed source/destination image is stored in bottom-up (Windows, OpenGL) order, not top-down (X11) order.
    `static int` | `FLAG_FASTDCT` Use the fastest DCT/IDCT algorithm available in the underlying codec.
    `static int` | `FLAG_FASTUPSAMPLE` When decompressing an image that was compressed using chrominance subsampling, use the fastest chrominance upsampling algorithm available in the underlying codec.
    `static int` | `FLAG_FORCEMMX` Deprecated.
    `static int` | `FLAG_FORCESSE` Deprecated.
    `static int` | `FLAG_FORCESSE2` Deprecated.
    `static int` | `FLAG_FORCESSE3` Deprecated.
    `static int` | `NUMCS` The number of JPEG colorspaces
    `static int` | `NUMPF` The number of pixel formats
    `static int` | `NUMSAMP` The number of chrominance subsampling options
    `static 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_444` 4:4:4 chrominance subsampling (no chrominance subsampling).
    `static int` | `SAMP_GRAY` Grayscale.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `TJ()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and 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 height, int subsamp)` Deprecated. Use `bufSizeYUV(int, int, int, int)` instead.
    `static int` | `bufSizeYUV(int width, int pad, int height, int subsamp)` Returns the size of the buffer (in bytes) required to hold a YUV planar image with the given width, height, and level of chrominance subsampling.
    `static int` | `getBlueOffset(int pixelFormat)` For the given pixel format, returns the number of bytes 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 bytes 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 bytes) for the given pixel format.
    `static int` | `getRedOffset(int pixelFormat)` For the given pixel format, returns the number of bytes 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 in this implementation of TurboJPEG 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.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 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

    - #### 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-byte pixels in the order R, G, B from lowest to highest byte 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-byte pixels in the order B, G, R from lowest to highest byte 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-byte pixels in the order R, G, B from lowest to highest byte 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-byte pixels in the order B, G, R from lowest to highest byte 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-byte pixels in the order R, G, B from highest to lowest byte 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-byte pixels in the order B, G, R from highest to lowest byte 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-byte pixel represents a luminance (brightness) level from 0 to 255.
      See Also:
        Constant Field Values

    - #### PF_RGBA

          public static final int PF_RGBA

      RGBA pixel format. This is the same as `PF_RGBX`, except that when decompressing, the X byte is guaranteed to be 0xFF, 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 as `PF_BGRX`, except that when decompressing, the X byte is guaranteed to be 0xFF, 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 as `PF_XBGR`, except that when decompressing, the X byte is guaranteed to be 0xFF, 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 as `PF_XRGB`, except that when decompressing, the X byte is guaranteed to be 0xFF, 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 CMYK pixels into a YCCK JPEG image (see `CS_YCCK`) and decompressing YCCK JPEG images into CMYK pixels.
      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 decompressed to any of the extended RGB pixel formats or grayscale, but they cannot be decompressed to 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 bandwidth or disk space. YCbCr is the most common JPEG colorspace, and YCbCr JPEG images can be compressed from and decompressed to any of the extended RGB pixel formats or grayscale, or they can be decompressed to YUV planar 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 any of the extended RGB pixel formats or grayscale, or they can be decompressed to YUV planar 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 decompressed to CMYK pixels.
      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 CMYK pixels.
      See Also:
        Constant Field Values

    - #### FLAG_BOTTOMUP

          public static final int FLAG_BOTTOMUP

      The uncompressed source/destination image is stored in bottom-up (Windows, OpenGL) order, not top-down (X11) order.
      See Also:
        Constant Field Values

    - #### FLAG_FORCEMMX

          @Deprecated
          public static final int FLAG_FORCEMMX

      Deprecated.
      See Also:
        Constant Field Values

    - #### FLAG_FORCESSE

          @Deprecated
          public static final int FLAG_FORCESSE

      Deprecated.
      See Also:
        Constant Field Values

    - #### FLAG_FORCESSE2

          @Deprecated
          public static final int FLAG_FORCESSE2

      Deprecated.
      See Also:
        Constant Field Values

    - #### FLAG_FORCESSE3

          @Deprecated
          public static final int FLAG_FORCESSE3

      Deprecated.
      See Also:
        Constant Field Values

    - #### FLAG_FASTUPSAMPLE

          public static final int FLAG_FASTUPSAMPLE

      When decompressing an image that was compressed using chrominance subsampling, use the fastest chrominance upsampling algorithm available in the underlying codec. The default is to use smooth upsampling, which creates a smooth transition between neighboring chrominance components in order to reduce upsampling artifacts in the decompressed image.
      See Also:
        Constant Field Values

    - #### FLAG_FASTDCT

          public static final int FLAG_FASTDCT

      Use the fastest DCT/IDCT algorithm available in the underlying codec. The default if this flag is not specified is implementation-specific. For example, the implementation of TurboJPEG for libjpeg[-turbo] uses the fast algorithm by default when compressing, because this has been shown to have only a very slight effect on accuracy, but it uses the accurate algorithm when decompressing, because this has been shown to have a larger effect.
      See Also:
        Constant Field Values

    - #### FLAG_ACCURATEDCT

          public static final int FLAG_ACCURATEDCT

      Use the most accurate DCT/IDCT algorithm available in the underlying codec. The default if this flag is not specified is implementation-specific. For example, the implementation of TurboJPEG for libjpeg[-turbo] uses the fast algorithm by default when compressing, because this has been shown to have only a very slight effect on accuracy, but it uses the accurate algorithm when decompressing, because this has been shown to have a larger effect.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### TJ

          public TJ()

  - ### Method Detail

    - #### getMCUWidth

          public static int getMCUWidth(int subsamp)
                                 throws java.lang.Exception

      Returns the MCU block width for the given level of chrominance subsampling.
      Parameters:
        `subsamp` - the level of chrominance subsampling (one of `SAMP_*`)
      Returns:
        the MCU block width for the given level of chrominance subsampling.
      Throws:
        `java.lang.Exception`

    - #### getMCUHeight

          public static int getMCUHeight(int subsamp)
                                  throws java.lang.Exception

      Returns the MCU block height for the given level of chrominance subsampling.
      Parameters:
        `subsamp` - the level of chrominance subsampling (one of `SAMP_*`)
      Returns:
        the MCU block height for the given level of chrominance subsampling.
      Throws:
        `java.lang.Exception`

    - #### getPixelSize

          public static int getPixelSize(int pixelFormat)
                                  throws java.lang.Exception

      Returns the pixel size (in bytes) for the given pixel format.
      Parameters:
        `pixelFormat` - the pixel format (one of `PF_*`)
      Returns:
        the pixel size (in bytes) for the given pixel format.
      Throws:
        `java.lang.Exception`

    - #### getRedOffset

          public static int getRedOffset(int pixelFormat)
                                  throws java.lang.Exception

      For the given pixel format, returns the number of bytes that the red component is offset from the start of the pixel. For instance, if a pixel of format `TJ.PF_BGRX` is stored in `char pixel[]`, then the red component will be `pixel[TJ.getRedOffset(TJ.PF_BGRX)]`.
      Parameters:
        `pixelFormat` - the pixel format (one of `PF_*`)
      Returns:
        the red offset for the given pixel format.
      Throws:
        `java.lang.Exception`

    - #### getGreenOffset

          public static int getGreenOffset(int pixelFormat)
                                    throws java.lang.Exception

      For the given pixel format, returns the number of bytes that the green component is offset from the start of the pixel. For instance, if a pixel of format `TJ.PF_BGRX` is stored in `char pixel[]`, then the green component will be `pixel[TJ.getGreenOffset(TJ.PF_BGRX)]`.
      Parameters:
        `pixelFormat` - the pixel format (one of `PF_*`)
      Returns:
        the green offset for the given pixel format.
      Throws:
        `java.lang.Exception`

    - #### getBlueOffset

          public static int getBlueOffset(int pixelFormat)
                                   throws java.lang.Exception

      For the given pixel format, returns the number of bytes that the blue component is offset from the start of the pixel. For instance, if a pixel of format `TJ.PF_BGRX` is stored in `char pixel[]`, then the blue component will be `pixel[TJ.getBlueOffset(TJ.PF_BGRX)]`.
      Parameters:
        `pixelFormat` - the pixel format (one of `PF_*`)
      Returns:
        the blue offset for the given pixel format.
      Throws:
        `java.lang.Exception`

    - #### bufSize

          public static int bufSize(int width,
                    int height,
                    int jpegSubsamp)
                             throws java.lang.Exception

      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 image
        `height` - the height (in pixels) of the JPEG image
        `jpegSubsamp` - the level of chrominance subsampling to be used when generating the JPEG image (one of `TJ.SAMP_*`)
      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.
      Throws:
        `java.lang.Exception`

    - #### bufSizeYUV

          public static int bufSizeYUV(int width,
                       int pad,
                       int height,
                       int subsamp)
                                throws java.lang.Exception

      Returns the size of the buffer (in bytes) required to hold a YUV planar image with the given width, height, and level of chrominance subsampling.
      Parameters:
        `width` - the width (in pixels) of the YUV image
        `pad` - the width of each line in each plane of the image is padded to the nearest multiple of this number of bytes (must be a power of 2.)
        `height` - the height (in pixels) of the YUV image
        `subsamp` - the level of chrominance subsampling used in the YUV image (one of `TJ.SAMP_*`)
      Returns:
        the size of the buffer (in bytes) required to hold a YUV planar image with the given width, height, and level of chrominance subsampling.
      Throws:
        `java.lang.Exception`

    - #### bufSizeYUV

          @Deprecated
          public static int bufSizeYUV(int width,
                                  int height,
                                  int subsamp)
                                throws java.lang.Exception

      Deprecated. Use `bufSizeYUV(int, int, int, int)` instead.
      Throws:
        `java.lang.Exception`

    - #### planeSizeYUV

          public static int planeSizeYUV(int componentID,
                         int width,
                         int stride,
                         int height,
                         int subsamp)
                                  throws java.lang.Exception

      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 line 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 of `TJ.SAMP_*`)
      Returns:
        the size of the buffer (in bytes) required to hold a YUV planar image with the given parameters.
      Throws:
        `java.lang.Exception`

    - #### planeWidth

          public static int planeWidth(int componentID,
                       int width,
                       int subsamp)
                                throws java.lang.Exception

      Returns the plane width of a YUV image plane with the given parameters. Refer to `YUVImage` 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 image
        `subsamp` - the level of chrominance subsampling used in the YUV image (one of `TJ.SAMP_*`)
      Returns:
        the plane width of a YUV image plane with the given parameters.
      Throws:
        `java.lang.Exception`

    - #### planeHeight

          public static int planeHeight(int componentID,
                        int height,
                        int subsamp)
                                 throws java.lang.Exception

      Returns the plane height of a YUV image plane with the given parameters. Refer to `YUVImage` 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 image
        `subsamp` - the level of chrominance subsampling used in the YUV image (one of `TJ.SAMP_*`)
      Returns:
        the plane height of a YUV image plane with the given parameters.
      Throws:
        `java.lang.Exception`

    - #### getScalingFactors

          public static TJScalingFactor[] getScalingFactors()
                                                     throws java.lang.Exception

      Returns a list of fractional scaling factors that the JPEG decompressor in this implementation of TurboJPEG supports.
      Returns:
        a list of fractional scaling factors that the JPEG decompressor in this implementation of TurboJPEG supports.
      Throws:
        `java.lang.Exception`