Package de.digitalcollections.turbojpeg
Class TurboJpeg
- java.lang.Object
-
- de.digitalcollections.turbojpeg.TurboJpeg
-
public class TurboJpeg extends Object
Java bindings for libturbojpeg via JFFI *
-
-
Field Summary
Fields Modifier and Type Field Description libturbojpeg
lib
jnr.ffi.Runtime
runtime
-
Constructor Summary
Constructors Constructor Description TurboJpeg()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BufferedImage
decode(byte[] jpegData, Info info, Dimension size)
Decode the JPEG image in the input buffer into a BufferedImage.ByteBuffer
encode(Raster img, int quality)
Encode an image to JPEGInfo
getInfo(byte[] jpegData)
Return information about the JPEG image in the input bufferByteBuffer
transform(byte[] jpegData, Info info, Rectangle region, int rotation)
Transform a JPEG image without decoding it fully
-
-
-
Field Detail
-
lib
public libturbojpeg lib
-
runtime
public jnr.ffi.Runtime runtime
-
-
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 bufferinfo
- Information about the JPEG image in the buffersize
- Target decompressed dimensions, must be among the available sizes (seeInfo.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 pixelsquality
- 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 bufferinfo
- Information about the JPEG (fromgetInfo(byte[])
region
- Source region to crop out of JPEGrotation
- Degrees to rotate the JPEG, must be 90, 180 or 270- Returns:
- The transformed JPEG data
- Throws:
TurboJpegException
- if image transformation fails
-
-