pub struct LosslessConfig { /* private fields */ }Expand description
Lossless (modular) encoding configuration.
Has a sensible Default — lossless has no quality ambiguity.
Implementations§
Source§impl LosslessConfig
impl LosslessConfig
Sourcepub fn with_effort(self, effort: u8) -> Self
pub fn with_effort(self, effort: u8) -> Self
Set effort level (1–10). Higher effort = slower, better compression.
This adjusts all effort-dependent defaults:
- e1–3: Huffman encoding
- e4–6: + ANS entropy coding
- e7: + content-adaptive tree learning, LZ77 RLE
- e8: + LZ77 greedy hash chain
- e9–10: + LZ77 optimal (Viterbi DP)
Individual with_*() calls after with_effort() override these defaults.
Sourcepub fn with_mode(self, mode: EncoderMode) -> Self
pub fn with_mode(self, mode: EncoderMode) -> Self
Set encoder mode (default: EncoderMode::Reference).
Reference matches libjxl’s algorithm choices for comparable output.
Experimental enables encoder-specific improvements.
Sourcepub fn mode(&self) -> EncoderMode
pub fn mode(&self) -> EncoderMode
Current encoder mode.
Sourcepub fn with_patches(self, enable: bool) -> Self
pub fn with_patches(self, enable: bool) -> Self
Enable/disable patches (dictionary-based repeated pattern detection). Default: true at effort >= 5. Huge wins on screenshots, zero cost on photos.
Sourcepub fn with_squeeze(self, enable: bool) -> Self
pub fn with_squeeze(self, enable: bool) -> Self
Enable/disable squeeze (Haar wavelet) transform (default: false).
Squeeze is disabled by default because tree learning provides better
compression on both photos and screenshots. Squeeze can still be
enabled via .with_squeeze(true) for experimentation.
Sourcepub fn with_tree_learning(self, enable: bool) -> Self
pub fn with_tree_learning(self, enable: bool) -> Self
Enable/disable content-adaptive tree learning (default: false).
Sourcepub fn with_lz77(self, enable: bool) -> Self
pub fn with_lz77(self, enable: bool) -> Self
Enable/disable LZ77 backward references (default: false).
Sourcepub fn with_lz77_method(self, method: Lz77Method) -> Self
pub fn with_lz77_method(self, method: Lz77Method) -> Self
Set LZ77 method (default: Greedy). Only effective when LZ77 is enabled.
Sourcepub fn with_lossy_palette(self, enable: bool) -> Self
pub fn with_lossy_palette(self, enable: bool) -> Self
Enable/disable lossy delta palette (default: false).
When enabled, uses quantized palette with delta entries and error diffusion for near-lossless encoding. This is NOT pixel-exact — it trades some color accuracy for significantly smaller files on images with many colors. Matching libjxl’s modular lossy palette mode.
Sourcepub fn with_threads(self, threads: usize) -> Self
pub fn with_threads(self, threads: usize) -> Self
Set thread count for parallel encoding.
0(default): use the ambient rayon pool. The caller can control thread count by wrapping the encode call inpool.install(|| ...).1: force sequential encoding (no rayon).N >= 2: create a dedicated N-thread pool for this encode.
Requires the parallel feature. When parallel is not enabled,
this value is ignored and encoding is always sequential.
Sourcepub fn tree_learning(&self) -> bool
pub fn tree_learning(&self) -> bool
Whether content-adaptive tree learning is enabled.
Sourcepub fn lz77_method(&self) -> Lz77Method
pub fn lz77_method(&self) -> Lz77Method
Current LZ77 method.
Sourcepub fn patches(&self) -> bool
pub fn patches(&self) -> bool
Whether patches (dictionary-based repeated pattern detection) are enabled.
Sourcepub fn lossy_palette(&self) -> bool
pub fn lossy_palette(&self) -> bool
Whether lossy delta palette is enabled.
Sourcepub fn encode_request(
&self,
width: u32,
height: u32,
layout: PixelLayout,
) -> EncodeRequest<'_>
pub fn encode_request( &self, width: u32, height: u32, layout: PixelLayout, ) -> EncodeRequest<'_>
Create an encode request for an image with this config.
Use this when you need to attach metadata, limits, or cancellation.
Sourcepub fn encode(
&self,
pixels: &[u8],
width: u32,
height: u32,
layout: PixelLayout,
) -> Result<Vec<u8>>
pub fn encode( &self, pixels: &[u8], width: u32, height: u32, layout: PixelLayout, ) -> Result<Vec<u8>>
Encode pixels directly with this config. Shortcut for simple cases.
let jxl = jxl_encoder::LosslessConfig::new()
.encode(&pixels, 100, 100, jxl_encoder::PixelLayout::Rgb8)?;Sourcepub fn encode_into(
&self,
pixels: &[u8],
width: u32,
height: u32,
layout: PixelLayout,
out: &mut Vec<u8>,
) -> Result<()>
pub fn encode_into( &self, pixels: &[u8], width: u32, height: u32, layout: PixelLayout, out: &mut Vec<u8>, ) -> Result<()>
Encode pixels, appending to an existing buffer.
Sourcepub fn encode_animation(
&self,
width: u32,
height: u32,
layout: PixelLayout,
animation: &AnimationParams,
frames: &[AnimationFrame<'_>],
) -> Result<Vec<u8>>
pub fn encode_animation( &self, width: u32, height: u32, layout: PixelLayout, animation: &AnimationParams, frames: &[AnimationFrame<'_>], ) -> Result<Vec<u8>>
Encode a multi-frame animation as a lossless JXL.
Each frame must have the same dimensions and pixel layout. Returns the complete JXL codestream bytes.
Source§impl LosslessConfig
impl LosslessConfig
Sourcepub fn encoder(
&self,
width: u32,
height: u32,
layout: PixelLayout,
) -> Result<LosslessEncoder>
pub fn encoder( &self, width: u32, height: u32, layout: PixelLayout, ) -> Result<LosslessEncoder>
Create a streaming encoder for incremental row input.
Per-channel planes are pre-allocated and filled as rows are pushed via
LosslessEncoder::push_rows, allowing callers to free source buffers
incrementally rather than materializing the entire image.
Trait Implementations§
Source§impl Clone for LosslessConfig
impl Clone for LosslessConfig
Source§fn clone(&self) -> LosslessConfig
fn clone(&self) -> LosslessConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for LosslessConfig
impl Debug for LosslessConfig
Auto Trait Implementations§
impl Freeze for LosslessConfig
impl RefUnwindSafe for LosslessConfig
impl Send for LosslessConfig
impl Sync for LosslessConfig
impl Unpin for LosslessConfig
impl UnsafeUnpin for LosslessConfig
impl UnwindSafe for LosslessConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more