#jxl #jpeg-xl

jpegxl-rs

Safe Rust wrapper for JPEG XL reference implementation

12 releases

new 0.3.7 Apr 13, 2021
0.3.5 Mar 25, 2021
0.3.2 Feb 16, 2021
0.3.0 Jan 30, 2021
0.1.4 Aug 25, 2020

#42 in Images

Download history 5/week @ 2020-12-31 54/week @ 2021-01-07 47/week @ 2021-01-14 5/week @ 2021-01-21 16/week @ 2021-01-28 8/week @ 2021-02-04 177/week @ 2021-02-11 22/week @ 2021-02-18 10/week @ 2021-02-25 9/week @ 2021-03-04 15/week @ 2021-03-11 2/week @ 2021-03-18 74/week @ 2021-03-25 15/week @ 2021-04-01 33/week @ 2021-04-08

140 downloads per month

GPL-3.0-or-later

65KB
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

Decoding

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

// Use multithread
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)
                      .endian(Endianness::Big)
                      .align(8)
                      .build()?;

// Set custom memory manager
use jpegxl_rs::memory::MallocManager;
let manager = MallocManager::default();
let mut decoder = decoder_builder()
                      .memory_manager(&manager)
                      .build()?;

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.set_lossless(false);
encoder.set_quality(3.0);

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)?;

License: GPL-3.0-or-later

Dependencies

~0.4–1.3MB
~31K SLoC