Skip to content

Repository files navigation

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.

importorg.ngengine.webp.decoder.DecodedWebP;
importorg.ngengine.webp.decoder.WebPDecoder;
importjava.nio.ByteBuffer;
importjava.nio.file.Files;
importjava.nio.file.Paths;
byte[] webp = Files.readAllBytes(Paths.get("image.webp"));
// Default allocator uses ByteBuffer.allocate(...)DecodedWebPdecoded = 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);
ByteBufferrgba = 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

About

Pure-Java WebP decoder

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages