#jpeg #api-bindings #jxl

jpegxl-rs

Safe Rust wrapper for JPEG XL reference implementation

35 releases

0.14.0+libjxl-0.11.2 Mar 22, 2026
0.12.0+libjxl-0.11.1 Jan 6, 2026
0.11.2+libjxl-0.11.1 Nov 27, 2024
0.10.4+libjxl-0.10.3 Jun 30, 2024
0.1.4 Aug 25, 2020

#50 in Images

Download history 603/week @ 2026-01-22 726/week @ 2026-01-29 717/week @ 2026-02-05 536/week @ 2026-02-12 525/week @ 2026-02-19 701/week @ 2026-02-26 586/week @ 2026-03-05 545/week @ 2026-03-12 707/week @ 2026-03-19 1225/week @ 2026-03-26 812/week @ 2026-04-02 776/week @ 2026-04-09 819/week @ 2026-04-16 660/week @ 2026-04-23 894/week @ 2026-04-30 641/week @ 2026-05-07

3,169 downloads per month
Used in 5 crates

GPL-3.0-or-later

335KB
3.5K SLoC

jpegxl-rs

Documentation Crates.io dependency status 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.

To build libjxl and statically link it, use the vendored feature.

Usage

Currently, you can use u8, u16, f16, and f32 as pixel types.

Decoding

use jpegxl_rs::*;
use jpegxl_rs::decode::*;

let mut decoder = decoder_builder().build().unwrap();
let sample = include_bytes!("../../samples/sample.jxl");

let (Metadata { width, height, ..}, pixels) = decoder.decode(sample).unwrap();
match pixels {
    Pixels::Float(data) => { /* do something with Vec<f32> data */ },
    Pixels::Uint8(data) => { /* do something with Vec<u8> data */ },
    Pixels::Uint16(data) => { /* do something with Vec<u16> data */ },
    Pixels::Float16(data) => { /* do something with Vec<f16> data */ },
}

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

// Customize pixel format
let mut decoder = decoder_builder()
                      .pixel_format(PixelFormat {
                          num_channels: 3,
                          endianness: Endianness::Big,
                          align: 8
                      })
                      .build()
                      .unwrap();

decoder.decode_with::<u8>(sample);

// You can change the settings after initialization
decoder.skip_reorientation = Some(true);

// Reconstruct JPEG, fallback to pixels if JPEG reconstruction is not possible
// This operation is finished in on pass
let (metadata, data) = decoder.reconstruct(sample).unwrap();
match data {
    Data::Jpeg(jpeg) => {/* do something with the JPEG data */}
    Data::Pixels(pixels) => {/* do something with the pixels data */}
}

Encoding

use image::ImageReader;
use jpegxl_rs::encoder_builder;
use jpegxl_rs::encode::{EncoderResult, EncoderSpeed};

let sample = ImageReader::open("../samples/sample.png").unwrap().decode().unwrap().to_rgba16();
let mut encoder = encoder_builder().build().unwrap();

let buffer: EncoderResult<f32> = encoder.encode(&sample, sample.width(), sample.height()).unwrap();

// Set encoder options
let mut encoder = encoder_builder()
                    .lossless(true)
                    .speed(EncoderSpeed::Falcon)
                    .build()
                    .unwrap();

// You can change the settings after initialization
encoder.lossless = Some(false);
encoder.quality = 3.0;

image crate integration

By default, this integration uses the image integration. If you don't need it, turn off the image feature.

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

let sample = std::fs::read("../samples/sample.jxl").unwrap();
let mut decoder = decoder_builder().build().unwrap();
let img = decoder.decode_to_image(&sample).unwrap();
let img = decoder.decode_to_image_with::<f32>(&sample).unwrap();

MSRV

Following the N-2 policy: the minimum supported Rust version is two releases behind the current stable. Currently: 1.92 (stable: 1.94)

License: GPL-3.0-or-later

Dependencies

~9MB
~186K SLoC