jpegxl-rs 0.3.3

Safe Rust wrapper for JPEG XL reference implementation
docs.rs failed to build jpegxl-rs-0.3.3
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: jpegxl-rs-0.10.3+libjxl-0.10.2

jpegxl-rs

Documentation Crates.io CI License: GPL-3.0-or-later

jpegxl-rs is a safe wrapper over jpeg-xl library. Check out the original library and the bindings.

Building

The library build jpeg-xl and link to libc++ by default. Optionally, you can set --features without-build, then set the include path and lib path with DEP_JXL_INCLUDE and DEP_JXL_LIB respectively.

If you don't want to depend on C++ standard library, use --features without-threads to disable default threadpool.

You need to have a working llvm environment.

Usage

Decoding

use jpegxl_rs::decoder_builder;
let sample = std::fs::read("test/sample.jxl")?;
let mut runner = ThreadsRunner::default();
let mut decoder = decoder_builder().parallel_runner(&runner).build()?;
let (info, buffer) = decoder.decode::<u8>(&sample)?;

Set output pixel parameters

let mut decoder = decoder_builder()
                      .num_channel(3)
                      .endianness(Endianness::Big)
                      .align(8)
                      .build()?;

Encoding

use jpegxl_rs::*;
use image::io::Reader as ImageReader;

let sample = ImageReader::open("test/sample.png")?.decode()?.to_rgba16();
let mut runner = ThreadsRunner::default();
let mut encoder = encoder_builder().parallel_runner(&runner).build()?;
let buffer: Vec<u8> = encoder.encode(
                          &sample, 
                          sample.width(), 
                          sample.height()
                      )?;

image crate integration

The integration is enabled by default. If you don't need it, use without-image feature.

use jpegxl_rs::image::*;
use image::DynamicImage;

let sample = std::fs::read("test/sample.jxl")?;
let decoder: JxlImageDecoder<u16> = JxlImageDecoder::new(&sample)?;
let img = DynamicImage::from_decoder(decoder)?;