TJTransformer

Package org.libjpegturbo.turbojpeg

## Class TJTransformer

- java.lang.Object
- - org.libjpegturbo.turbojpeg.TJDecompressor
  - - org.libjpegturbo.turbojpeg.TJTransformer

- All Implemented Interfaces:
    `java.io.Closeable`, `java.lang.AutoCloseable`

      public class TJTransformer
      extends TJDecompressor

  TurboJPEG lossless transformer

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `TJTransformer()` | Create a TurboJPEG lossless transformer instance.
    `TJTransformer​(byte[] jpegImage)` | Create a TurboJPEG lossless transformer instance and associate the JPEG source image stored in `jpegImage` with the newly created instance.
    `TJTransformer​(byte[] jpegImage, int imageSize)` | Create a TurboJPEG lossless transformer instance and associate the JPEG source image of length `imageSize` bytes stored in `jpegImage` with the newly created instance.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `int` | `bufSize​(TJTransform transform)` | Returns the maximum size of the buffer (in bytes) required to hold a JPEG image transformed, with the given transform parameters and/or cropping region, from the JPEG source image associated with this transformer instance.
    `int[]` | `getTransformedSizes()` | Returns an array containing the sizes of the transformed JPEG images (in bytes) generated by the most recent transform operation.
    `void` | `setICCProfile​(byte[] iccBuf)` | Embed an ICC (International Color Consortium) color management profile in JPEG images generated by subsequent transform operations.
    `void` | `transform​(byte[][] dstBufs, TJTransform[] transforms)` | Losslessly transform the JPEG source image associated with this transformer instance into one or more JPEG images stored in the given destination buffers.
    `TJDecompressor[]` | `transform​(TJTransform[] transforms)` | Losslessly transform the JPEG source image associated with this transformer instance and return an array of `TJDecompressor` instances, each of which has a transformed JPEG image associated with it.

    - ### Methods inherited from class org.libjpegturbo.turbojpeg.TJDecompressor

      `close, decompress12, decompress12, decompress16, decompress16, decompress8, decompress8, decompress8, decompress8, decompress8, decompressToYUV, decompressToYUV, decompressToYUV, finalize, get, getHeight, getICCProfile, getICCSize, getJPEGBuf, getJPEGSize, getWidth, saveImage, set, setCroppingRegion, setScalingFactor, setSourceImage, setSourceImage`

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

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

- - ### Constructor Detail

    - #### TJTransformer

          public TJTransformer()
                        throws TJException

      Create a TurboJPEG lossless transformer instance.
      Throws:
        `TJException`

    - #### TJTransformer

          public TJTransformer​(byte[] jpegImage)
                        throws TJException

      Create a TurboJPEG lossless transformer instance and associate the JPEG source image stored in `jpegImage` with the newly created instance.
      Parameters:
        `jpegImage` - buffer containing the JPEG source image to transform. (The size of the JPEG image is assumed to be the length of the array.) This buffer is not modified.
      Throws:
        `TJException`

    - #### TJTransformer

          public TJTransformer​(byte[] jpegImage,
                               int imageSize)
                        throws TJException

      Create a TurboJPEG lossless transformer instance and associate the JPEG source image of length `imageSize` bytes stored in `jpegImage` with the newly created instance.
      Parameters:
        `jpegImage` - buffer containing the JPEG source image to transform. This buffer is not modified.
        `imageSize` - size of the JPEG source image (in bytes)
      Throws:
        `TJException`

  - ### Method Detail

    - #### setICCProfile

          public void setICCProfile​(byte[] iccBuf)
                             throws TJException

      Embed an ICC (International Color Consortium) color management profile in JPEG images generated by subsequent transform operations.
      Parameters:
        `iccBuf` - buffer containing an ICC profile. (The size of the ICC profile is assumed to be the length of the array.) A copy is made of the ICC profile, so this buffer can be reused as soon as this method returns. Setting this parameter to null removes any ICC profile that was previously associated with this transformer instance.
      Throws:
        `TJException`

    - #### bufSize

          public int bufSize​(TJTransform transform)
                      throws TJException

      Returns the maximum size of the buffer (in bytes) required to hold a JPEG image transformed, with the given transform parameters and/or cropping region, from the JPEG source image associated with this transformer instance. This method is a wrapper for `TJ.bufSize()` that takes into account cropping, transposition of the width and height (which affects the destination image dimensions and level of chrominance subsampling), grayscale conversion, and the ICC profile (if any) that was previously associated with this transformer instance (see `setICCProfile()`) or extracted from the source image (see `TJDecompressor.getICCProfile()` and `TJ.PARAM_SAVEMARKERS`.)
      Parameters:
        `transform` - a `TJTransform` instance that specifies the transform parameters and/or cropping region for the transformed JPEG image.
      Returns:
        the maximum size of the buffer (in bytes) required to hold a JPEG image transformed, with the given transform parameters and/or cropping region, from the JPEG source image associated with this transformer instance
      Throws:
        `TJException`

    - #### transform

          public void transform​(byte[][] dstBufs,
                                TJTransform[] transforms)
                         throws TJException

      Losslessly transform the JPEG source image associated with this transformer instance into one or more JPEG images stored in the given destination buffers. Lossless transforms work by moving the raw coefficients from one JPEG image structure to another without altering the values of the coefficients. While this is typically faster than decompressing the image, transforming it, and re-compressing it, lossless transforms are not free. Each lossless transform requires reading and performing Huffman decoding on all of the coefficients in the source image, regardless of the size of the destination image. Thus, this method provides a means of generating multiple transformed images from the same source or of applying multiple transformations simultaneously, in order to eliminate the need to read the source coefficients multiple times.
      Parameters:
        `dstBufs` - an array of JPEG destination buffers. `dstbufs[i]` will receive a JPEG image that has been transformed using the parameters in `transforms[i]`. Use `bufSize()` to determine the maximum size for each buffer.
        `transforms` - an array of `TJTransform` instances, each of which specifies the transform parameters and/or cropping region for the corresponding transformed JPEG image
      Throws:
        `TJException`

    - #### transform

          public TJDecompressor[] transform​(TJTransform[] transforms)
                                     throws TJException

      Losslessly transform the JPEG source image associated with this transformer instance and return an array of `TJDecompressor` instances, each of which has a transformed JPEG image associated with it.
      Parameters:
        `transforms` - an array of `TJTransform` instances, each of which specifies the transform parameters and/or cropping region for the corresponding transformed JPEG image
      Returns:
        an array of `TJDecompressor` instances, each of which has a transformed JPEG image associated with it.
      Throws:
        `TJException`

    - #### getTransformedSizes

          public int[] getTransformedSizes()

      Returns an array containing the sizes of the transformed JPEG images (in bytes) generated by the most recent transform operation.
      Returns:
        an array containing the sizes of the transformed JPEG images (in bytes) generated by the most recent transform operation.