jpegxl-rs

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

A safe JPEGXL wrapper over libjxl library. Check out the original library and the bindings.

Building

If you wish to specify a custom library path, set the DEP_JXL_LIB environment variable.

Building libjxl and statically linking can be enabled by using the vendored feature.

If you don't want to depend on C++ standard library, disable the feature threads.

Usage

Currently, u8, u16, f16 and f32 are supported as pixel types.

Decoding

```rust let mut decoder = decoder_builder().build()?; let DecoderResult { width, height, data ,..} = decoder.decode(&sample)?; match data { Data::U8(data) => { /* do something with Vec data / }, Data::U16(data) => { / do something with Vec data / }, Data::F16(data) => { / do something with Vec data / }, Data::F32(data) => { / do something with Vec data */ }, }

// Multi-threading use jpegxlrs::ThreadsRunner; let runner = ThreadsRunner::default(); let mut decoder = decoderbuilder() .parallel_runner(&runner) .build()?;

// Customize pixel format let mut decoder = decoderbuilder() .numchannels(3) .endianness(Endianness::Big) .align(8) .build()?;

decoder.decode_to::(&sample);

// You can change the settings after initialization decoder.num_channels = 1; decoder.endianness = Endianness::Native; ```

Encoding

rust use image::io::Reader as ImageReader; let sample = ImageReader::open("../samples/sample.png")?.decode()?.to_rgba16(); let mut encoder = encoder_builder().build()?; let buffer: EncoderResult<f32> = encoder.encode(&sample, sample.width(), sample.height())?;

Set encoder options

rust let mut encoder = encoder_builder() .lossless(true) .speed(EncoderSpeed::Falcon) .build()?; // You can change the settings after initialization encoder.lossless = false; encoder.quality = 3.0;

image crate integration

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

```rust use jpegxlrs::image::ToDynamic; use jpegxlrs::decoder_builder; use image::DynamicImage;

let sample = std::fs::read("../samples/sample.jxl")?; let decoder = decoderbuilder().build()?; let img = decoder.decode(&sample)?.intodynamic_image(); ```

License: GPL-3.0-or-later