pub struct LosslessEncoder { /* private fields */ }Expand description
Streaming lossless (modular) encoder.
Accepts pixel rows incrementally via push_rows, then
encodes on finish. This allows callers to free source pixel
buffers as rows are pushed, rather than materializing the entire image in
memory before encoding.
use jxl_encoder::{LosslessConfig, PixelLayout};
let mut enc = LosslessConfig::new()
.encoder(800, 600, PixelLayout::Rgb8)?;
for chunk in source_rows.chunks(row_bytes * 100) {
enc.push_rows(chunk, 100)?;
}
let jxl_bytes = enc.finish()?;Implementations§
Source§impl LosslessEncoder
impl LosslessEncoder
Sourcepub fn with_icc_profile(self, data: &[u8]) -> Self
pub fn with_icc_profile(self, data: &[u8]) -> Self
Attach an ICC color profile.
Sourcepub fn with_source_gamma(self, gamma: f32) -> Self
pub fn with_source_gamma(self, gamma: f32) -> Self
Specify that source pixels use a custom gamma transfer function.
Sourcepub fn with_color_encoding(self, ce: ColorEncoding) -> Self
pub fn with_color_encoding(self, ce: ColorEncoding) -> Self
Override the color encoding written to the JXL header.
Sourcepub fn with_intensity_target(self, nits: f32) -> Self
pub fn with_intensity_target(self, nits: f32) -> Self
Set the peak display luminance in nits for HDR content.
Sourcepub fn with_min_nits(self, nits: f32) -> Self
pub fn with_min_nits(self, nits: f32) -> Self
Set the minimum display luminance in nits.
Sourcepub fn with_intrinsic_size(self, width: u32, height: u32) -> Self
pub fn with_intrinsic_size(self, width: u32, height: u32) -> Self
Set the intrinsic display size.
Sourcepub fn rows_pushed(&self) -> u32
pub fn rows_pushed(&self) -> u32
Number of rows pushed so far.
Sourcepub fn push_rows(&mut self, pixels: &[u8], num_rows: u32) -> Result<()>
pub fn push_rows(&mut self, pixels: &[u8], num_rows: u32) -> Result<()>
Push pixel rows into the encoder.
pixels must contain exactly width * num_rows * bytes_per_pixel bytes.
Rows are deinterleaved into per-channel planes immediately, so the caller
can free the source buffer after this call returns.
Sourcepub fn finish(self) -> Result<Vec<u8>>
pub fn finish(self) -> Result<Vec<u8>>
Encode the accumulated pixels and return the JXL bytes.
All rows must have been pushed via push_rows before
calling this. Returns an error if the image is incomplete.
Sourcepub fn finish_with_stats(self) -> Result<EncodeResult>
pub fn finish_with_stats(self) -> Result<EncodeResult>
Encode and return JXL bytes together with EncodeStats.
Sourcepub fn finish_into(self, out: &mut Vec<u8>) -> Result<EncodeResult>
pub fn finish_into(self, out: &mut Vec<u8>) -> Result<EncodeResult>
Encode, appending to an existing buffer.
Sourcepub fn finish_to(self, dest: impl Write) -> Result<EncodeResult>
pub fn finish_to(self, dest: impl Write) -> Result<EncodeResult>
Encode, writing to a std::io::Write destination.
Auto Trait Implementations§
impl Freeze for LosslessEncoder
impl RefUnwindSafe for LosslessEncoder
impl Send for LosslessEncoder
impl Sync for LosslessEncoder
impl Unpin for LosslessEncoder
impl UnsafeUnpin for LosslessEncoder
impl UnwindSafe for LosslessEncoder
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> 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