Skip to main content

jxl_encoder/
lib.rs

1// Copyright (c) Imazen LLC and the JPEG XL Project Authors.
2// Algorithms and constants derived from libjxl (BSD-3-Clause).
3// Licensed under AGPL-3.0-or-later. Commercial licenses at https://www.imazen.io/pricing
4
5//! JPEG XL encoder in pure Rust.
6//!
7//! This crate provides a complete JPEG XL encoder implementation, supporting
8//! both lossless (modular) and lossy (VarDCT) encoding modes.
9
10#![cfg_attr(not(feature = "unsafe-performance"), forbid(unsafe_code))]
11#![cfg_attr(feature = "unsafe-performance", deny(unsafe_code))]
12
13extern crate alloc;
14
15pub mod api;
16pub mod bit_writer;
17pub mod color;
18pub mod container;
19pub mod debug_rect;
20// `effort` carries internal effort-derived knobs. Kept `pub` for
21// backwards-compatibility with 0.3.0 (which re-exported `EffortProfile`
22// at the crate root). The actual sweep / picker escape-hatch entry point
23// (`LosslessConfig::with_effort_profile_override` / its lossy twin) is
24// gated behind the `__expert` feature.
25pub mod effort;
26pub mod entropy_coding;
27pub mod error;
28#[allow(dead_code)] // Used by upcoming lf_frame module
29pub(crate) mod f16;
30pub mod headers;
31pub(crate) mod icc;
32pub mod image;
33#[cfg(feature = "jpeg-reencoding")]
34pub mod jpeg;
35pub mod modular;
36pub(crate) mod parallel;
37pub mod trace;
38pub mod validation;
39#[cfg(test)]
40mod validation_tests;
41pub mod vardct;
42
43#[cfg(feature = "convenience")]
44pub mod convenience;
45
46// Re-export new API as primary
47pub use api::{
48    AnimationFrame, AnimationParams, At, EncodeError, EncodeMode, EncodeRequest, EncodeResult,
49    EncodeStats, EncoderMode, ImageMetadata, Limits, LosslessConfig, LosslessEncoder, LossyConfig,
50    LossyEncoder, Lz77Method, PixelLayout, ProgressiveMode, Quality, ResultAtExt, Stop,
51    Unstoppable, at, calibrated_jxl_quality, quality_to_distance,
52};
53// `EffortProfile` was re-exported at the crate root in 0.3.0; it is now an
54// **internal** type that drives the encoder's effort-derived decisions.
55// The public picker / sweep escape hatch is the segmented
56// `LossyInternalParams` / `LosslessInternalParams` pair, applied via
57// `LossyConfig::with_internal_params` / `LosslessConfig::with_internal_params`
58// (gated behind `__expert`). `EntropyMulTable` remains reachable because
59// `LossyInternalParams::entropy_mul_table` carries it. The `EffortProfile`
60// re-export is `#[doc(hidden)]` to discourage new use; existing callers
61// that still reference it keep working.
62#[doc(hidden)]
63pub use effort::EffortProfile;
64pub use effort::EntropyMulTable;
65#[cfg(feature = "__expert")]
66pub use effort::{LosslessInternalParams, LossyInternalParams};
67pub use headers::color_encoding::{
68    CIExy, ColorEncoding, ColorSpace, CustomPrimaries, Primaries, RenderingIntent,
69    TransferFunction, WhitePoint,
70};
71pub use validation::ValidationError;
72pub use vardct::splines::{Spline, SplinePoint};
73
74#[cfg(feature = "convenience")]
75pub use convenience::{
76    encode_bgra8, encode_bgra8_lossless, encode_gray8, encode_gray8_lossless, encode_rgb8,
77    encode_rgb8_lossless, encode_rgba8, encode_rgba8_lossless,
78};
79
80/// Group dimension in pixels (256x256 groups).
81pub const GROUP_DIM: usize = 256;
82
83/// DCT block dimension (8x8 blocks).
84pub const BLOCK_DIM: usize = 8;
85
86/// Size of a single DCT block (64 coefficients).
87pub const BLOCK_SIZE: usize = BLOCK_DIM * BLOCK_DIM;
88
89/// JXL signature bytes.
90pub const JXL_SIGNATURE: [u8; 2] = [0xFF, 0x0A];
91
92/// Test path helpers for integration tests and examples.
93///
94/// Provides configurable paths via environment variables for corpus directories,
95/// tool binaries, and output directories. Not part of the public API.
96#[doc(hidden)]
97pub mod test_helpers;
98
99#[cfg(test)]
100mod tests;
101
102#[cfg(test)]
103#[path = "api_tests.rs"]
104mod api_tests;
105
106#[cfg(all(test, feature = "__expert"))]
107#[path = "effort_expert_tests.rs"]
108mod effort_expert_tests;