A safe JPEGXL wrapper over libjxl
library. Check out the original library
and the bindings.
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
.
Currently, u8
, u16
, f16
and f32
are supported as pixel types.
```rust
let mut decoder = decoder_builder().build()?;
let (Metadata { width, height, ..}, pixels) = decoder.decode(&sample)?;
match pixels {
Pixels::Float(data) => { /* do something with Vec
// Multi-threading use jpegxlrs::ThreadsRunner; let runner = ThreadsRunner::default(); let mut decoder = decoderbuilder() .parallel_runner(&runner) .build()?;
// Customize pixel format let mut decoder = decoderbuilder() .pixelformat(PixelFormat { num_channels: 3, endianness: Endianness::Big, align: 8 }) .build()?;
decoder.decode_with::
// 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)?; match data { Data::Jpeg(jpeg) => {/* do something with the JPEG data /} Data::Pixels(pixels) => {/ do something with the pixels data */} }
```
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 integrationThe 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 mut decoder = decoderbuilder().build()?;
let img = decoder.decodetoimage(&sample)?;
let img = decoder.decodetoimagewith::
License: GPL-3.0-or-later