Crate jpegxl_rs[][src]

Documentation Crates.io CI 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 libc++ by default. Optionally, you can set --features=system-jpegxl to dynamically link to it. If you don’t have it in 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, use --features without-threads to disable default threadpool.

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

Re-exports

pub use parallel::ThreadsRunner;

Modules

image

image crate integration

memory

Memory manager interface

parallel

Parallel runner interface

Structs

DecoderResult

Result of decoding

DecoderResultInfo

Extra info of the result

EncoderFrame

A frame for the encoder, consisting of the pixels and its options

EncoderResult

Encoder result

JxlDecoder

JPEG XL Decoder

JxlDecoderBuilder

Builder for JxlDecoder

JxlEncoder

JPEG XL Encoder

JxlEncoderBuilder

Builder for JxlEncoder

MultiFrames

A wrapper type for encoding multiple frames

Enums

ColorEncoding

Encoding color profile

DecodeError

Errors derived from JxlDecoderStatus

EncodeError

Errors derived from JxlEncoderStatus

EncoderSpeed

Encoding speed, default at Squirrel(7)

Traits

PixelType

Pixel data type. Currently u8, u16, u32 and f32 are supported.

Functions

decoder_builder

Return a JxlDecoderBuilder with default settings

encoder_builder

Return a JxlEncoderBuilder with default settings

Type Definitions

BasicInfo

Basic Information

Endianness

Endianness of the pixels