Class TurboJpeg


  • public class TurboJpeg
    extends Object
    Java bindings for libturbojpeg via JFFI *
    • Field Detail

      • runtime

        public jnr.ffi.Runtime runtime
    • Constructor Detail

      • TurboJpeg

        public TurboJpeg()
    • Method Detail

      • getInfo

        public Info getInfo​(byte[] jpegData)
                     throws TurboJpegException
        Return information about the JPEG image in the input buffer
        Parameters:
        jpegData - jpeg image data
        Returns:
        information about the jpeg image
        Throws:
        TurboJpegException - if decompressing header with library fails
      • decode

        public BufferedImage decode​(byte[] jpegData,
                                    Info info,
                                    Dimension size)
                             throws TurboJpegException
        Decode the JPEG image in the input buffer into a BufferedImage.
        Parameters:
        jpegData - JPEG data input buffer
        info - Information about the JPEG image in the buffer
        size - Target decompressed dimensions, must be among the available sizes (see Info.getAvailableSizes())
        Returns:
        The decoded image
        Throws:
        TurboJpegException - if decompression with library fails
      • encode

        public ByteBuffer encode​(Raster img,
                                 int quality)
                          throws TurboJpegException
        Encode an image to JPEG
        Parameters:
        img - image as rectangle of pixels
        quality - compression quality
        Returns:
        jpeg image
        Throws:
        TurboJpegException - if compression with library fails
      • transform

        public ByteBuffer transform​(byte[] jpegData,
                                    Info info,
                                    Rectangle region,
                                    int rotation)
                             throws TurboJpegException
        Transform a JPEG image without decoding it fully
        Parameters:
        jpegData - JPEG input buffer
        info - Information about the JPEG (from getInfo(byte[])
        region - Source region to crop out of JPEG
        rotation - Degrees to rotate the JPEG, must be 90, 180 or 270
        Returns:
        The transformed JPEG data
        Throws:
        TurboJpegException - if image transformation fails