Skip to content

Latest commit

 

History

History
51 lines (31 loc) · 1.36 KB

File metadata and controls

51 lines (31 loc) · 1.36 KB

image-webp-decoder

Pure-Java WebP still image decoder for Java 8+. It is a mostly machine-translated port of the Rust library image-rs/image-webp, with only limited manual review. As a result, this port may still contain bugs and decoding differences, including issues not present in the original library.

Installation

Gradle (Groovy):

dependencies {
  implementation 'org.ngengine:image-webp-decoder:<version>'
}

Usage

The decoder returns tightly-packed RGBA8888 data in a ByteBuffer.

import org.ngengine.webp.decoder.DecodedWebP;
import org.ngengine.webp.decoder.WebPDecoder;

import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.Paths;

byte[] webp = Files.readAllBytes(Paths.get("image.webp"));

// Default allocator uses ByteBuffer.allocate(...)
DecodedWebP decoded = WebPDecoder.decode(webp);

// Or provide your own allocator (e.g. allocateDirect / engine allocator)
// DecodedWebP decoded = WebPDecoder.decode(webp, ByteBuffer::allocateDirect);

System.out.println(decoded.width + "x" + decoded.height + ", alpha=" + decoded.hasAlpha);
ByteBuffer rgba = decoded.rgba; // position=0, limit=width*height*4

Development

  • Run tests: ./gradlew test
  • Manual AWT viewer (test-scope helper): ./gradlew runAwtViewer -Pwebp=/path/to/file.webp

License

MIT