#jxl #jpeg-xl

jpegxl-rs

Safe Rust wrapper for JPEG XL reference implementation

14 unstable releases (3 breaking)

Uses new Rust 2021

0.6.1 Nov 3, 2021
0.6.0 Oct 13, 2021
0.3.7 Apr 13, 2021
0.3.5 Mar 25, 2021
0.1.4 Aug 25, 2020

#38 in Images

Download history 2/week @ 2021-08-07 31/week @ 2021-08-14 1/week @ 2021-08-21 3/week @ 2021-08-28 11/week @ 2021-09-11 5/week @ 2021-09-18 20/week @ 2021-09-25 30/week @ 2021-10-09 4/week @ 2021-10-16 26/week @ 2021-10-30 25/week @ 2021-11-06 2/week @ 2021-11-13 6/week @ 2021-11-20

59 downloads per month

GPL-3.0-or-later

4MB
1K SLoC

jpegxl-rs

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

A safe JPEGXL wrapper over jpeg-xl library. Check out the original library and the bindings.

Building

The library build jpeg-xl and link to lib(std)c++ by default. Optionally, you can use system-jxl feature to dynamically link to it. If you don't have it in the default include and library paths, set them with DEP_JXL_INCLUDE and DEP_JXL_LIB respectively.

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

Usage

Currently, u8, u16 and f32(partial) are supported as pixel types. u32 is in the header but not implemented.

Note: f32 with alpha channel is not supported in encoder.

Decoding

let mut decoder = decoder_builder().build()?;

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

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

decoder.decode_to::<u8>(&sample);

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

Encoding

use image::io::Reader as ImageReader;
let sample = ImageReader::open("test/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

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-support feature.

use jpegxl_rs::image::ToDynamic;
use jpegxl_rs::decoder_builder;
use image::DynamicImage;

let sample = std::fs::read("test/sample.jxl")?;
let decoder = decoder_builder().build()?;
let img = decoder.decode(&sample)?.into_dynamic_image();

License: GPL-3.0-or-later

Dependencies

2a