Package dev.matrixlab.webp4j.internal
Class NativeWebP
java.lang.Object
dev.matrixlab.webp4j.internal.NativeWebP
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleandecodeAnimatedWebP(byte[] webPData, AnimatedWebPData result) Decodes an animated WebP image into individual frames.static booleandecodeRGBAInto(byte[] data, byte[] outputBuffer, int outputStride) uint8_t* WebPDecodeRGBAInto(const uint8_t* data, size_t data_size, uint8_t* output_buffer, int output_buffer_size, int output_stride);static booleandecodeRGBInto(byte[] data, byte[] outputBuffer, int outputStride) uint8_t* WebPDecodeRGBInto(const uint8_t* data, size_t data_size, uint8_t* output_buffer, int output_buffer_size, int output_stride);static byte[]encodeAnimatedWebP(byte[][] frames, int[] delays, int width, int height, float quality, boolean lossless, int compressionMethod, int loopCount, int kmin, int kmax, boolean minimizeSize, boolean allowMixed) Encodes animated WebP from Java-decoded GIF frames.static byte[]encodeGifToWebP(byte[] gifData, float quality, boolean lossless, int compressionMethod, boolean extractFirstFrameOnly, int loopCount, int kmin, int kmax, boolean minimizeSize, boolean allowMixed) Converts GIF data to WebP format using native giflib decoder.static byte[]encodeLosslessRGB(byte[] image, int width, int height, int stride) size_t WebPEncodeLosslessRGB(const uint8_t* rgb, int width, int height, int stride, uint8_t** output);static byte[]encodeLosslessRGBA(byte[] image, int width, int height, int stride) size_t WebPEncodeLosslessRGBA(const uint8_t* rgba, int width, int height, int stride, uint8_t** output);static byte[]encodeRGB(byte[] image, int width, int height, int stride, float quality) size_t WebPEncodeRGB(const uint8_t* rgb, int width, int height, int stride, float quality_factor, uint8_t** output);static byte[]encodeRGBA(byte[] image, int width, int height, int stride, float quality) size_t WebPEncodeRGBA(const uint8_t* rgba, int width, int height, int stride, float quality_factor, uint8_t** output);static intgetFeatures(byte[] data, int dataSize, WebPBitstreamFeatures features) VP8StatusCode WebPGetFeatures(const uint8_t* data, size_t data_size, WebPBitstreamFeatures* features);static booleangetGifInfo(byte[] gifData, AnimationInfo info) Gets information about a GIF file using native giflib.static booleangetInfo(byte[] data, int[] dimensions) int WebPGetInfo(const uint8_t* data, size_t data_size, int* width, int* height);static booleanChecks if the native library has been successfully loaded.static ThrowableReturns the cause of unavailability if the native library failed to load.
-
Method Details
-
getInfo
public static boolean getInfo(byte[] data, int[] dimensions) int WebPGetInfo(const uint8_t* data, size_t data_size, int* width, int* height); -
getFeatures
VP8StatusCode WebPGetFeatures(const uint8_t* data, size_t data_size, WebPBitstreamFeatures* features); -
encodeRGB
public static byte[] encodeRGB(byte[] image, int width, int height, int stride, float quality) size_t WebPEncodeRGB(const uint8_t* rgb, int width, int height, int stride, float quality_factor, uint8_t** output); -
encodeRGBA
public static byte[] encodeRGBA(byte[] image, int width, int height, int stride, float quality) size_t WebPEncodeRGBA(const uint8_t* rgba, int width, int height, int stride, float quality_factor, uint8_t** output); -
encodeLosslessRGB
public static byte[] encodeLosslessRGB(byte[] image, int width, int height, int stride) size_t WebPEncodeLosslessRGB(const uint8_t* rgb, int width, int height, int stride, uint8_t** output); -
encodeLosslessRGBA
public static byte[] encodeLosslessRGBA(byte[] image, int width, int height, int stride) size_t WebPEncodeLosslessRGBA(const uint8_t* rgba, int width, int height, int stride, uint8_t** output); -
decodeRGBInto
public static boolean decodeRGBInto(byte[] data, byte[] outputBuffer, int outputStride) uint8_t* WebPDecodeRGBInto(const uint8_t* data, size_t data_size, uint8_t* output_buffer, int output_buffer_size, int output_stride); -
decodeRGBAInto
public static boolean decodeRGBAInto(byte[] data, byte[] outputBuffer, int outputStride) uint8_t* WebPDecodeRGBAInto(const uint8_t* data, size_t data_size, uint8_t* output_buffer, int output_buffer_size, int output_stride); -
getGifInfo
Gets information about a GIF file using native giflib.- Parameters:
gifData- GIF image bytesinfo- AnimationInfo object to populate (via JNI field access)- Returns:
- True on success, false on failure
-
encodeGifToWebP
public static byte[] encodeGifToWebP(byte[] gifData, float quality, boolean lossless, int compressionMethod, boolean extractFirstFrameOnly, int loopCount, int kmin, int kmax, boolean minimizeSize, boolean allowMixed) Converts GIF data to WebP format using native giflib decoder. This is the primary (fast) path using native GIF decoding.- Parameters:
gifData- GIF image bytesquality- Quality factor (0-100)lossless- True for lossless encodingcompressionMethod- Compression method (0-6)extractFirstFrameOnly- True to extract only first frameloopCount- Loop count (0=infinite, -1=use GIF's)kmin- Minimum key-frame distancekmax- Maximum key-frame distanceminimizeSize- True to minimize output sizeallowMixed- True to allow mixed compression- Returns:
- WebP encoded byte array, or null on failure
-
encodeAnimatedWebP
public static byte[] encodeAnimatedWebP(byte[][] frames, int[] delays, int width, int height, float quality, boolean lossless, int compressionMethod, int loopCount, int kmin, int kmax, boolean minimizeSize, boolean allowMixed) Encodes animated WebP from Java-decoded GIF frames. This is used when GIF is decoded by Java ImageIO (fallback path). Uses WebPAnimEncoder API to create animated WebP.- Parameters:
frames- Array of RGBA frame data (each frame is width * height * 4 bytes)delays- Array of frame delays in millisecondswidth- Canvas widthheight- Canvas heightquality- Quality factor (0-100)lossless- True for lossless encodingcompressionMethod- Compression method (0-6)loopCount- Loop count (0=infinite)kmin- Minimum key-frame distancekmax- Maximum key-frame distanceminimizeSize- True to minimize output sizeallowMixed- True to allow mixed compression- Returns:
- WebP encoded byte array, or null on failure
-
decodeAnimatedWebP
Decodes an animated WebP image into individual frames.Uses the libwebp WebPAnimDecoder API to extract all frames as RGBA data along with their cumulative timestamps.
The result object will have its fields populated: - canvasWidth, canvasHeight, loopCount, bgcolor, frameCount (metadata) - rawFrameData (byte[][] of RGBA frame data) - timestamps (int[] of cumulative timestamps in milliseconds)
- Parameters:
webPData- The animated WebP image dataresult- AnimatedWebPData object to populate with decoded frames- Returns:
- true on success, false on failure
-
isAvailable
public static boolean isAvailable()Checks if the native library has been successfully loaded.This method can be used to determine if WebP operations are available on the current platform without actually attempting to encode/decode.
- Returns:
- true if the native library is loaded and available, false otherwise
-