Skip to main content

LossyEncoder

Struct LossyEncoder 

Source
pub struct LossyEncoder { /* private fields */ }
Expand description

Streaming lossy (VarDCT) 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::{LossyConfig, PixelLayout};

let mut enc = LossyConfig::new(1.0)
    .encoder(800, 600, PixelLayout::Rgb8)?;

// Push rows from a streaming source (e.g. PNG decoder)
for chunk in source_rows.chunks(row_bytes * 100) {
    enc.push_rows(chunk, 100)?;
}

let jxl_bytes = enc.finish()?;

Implementations§

Source§

impl LossyEncoder

Source

pub fn with_icc_profile(self, data: &[u8]) -> Self

Attach an ICC color profile.

Source

pub fn with_exif(self, data: &[u8]) -> Self

Attach EXIF data.

Source

pub fn with_xmp(self, data: &[u8]) -> Self

Attach XMP data.

Source

pub fn with_source_gamma(self, gamma: f32) -> Self

Specify that source pixels use a custom gamma transfer function.

Source

pub fn with_color_encoding(self, ce: ColorEncoding) -> Self

Override the color encoding written to the JXL header.

Source

pub fn with_intensity_target(self, nits: f32) -> Self

Set the peak display luminance in nits for HDR content.

Source

pub fn with_min_nits(self, nits: f32) -> Self

Set the minimum display luminance in nits.

Source

pub fn with_intrinsic_size(self, width: u32, height: u32) -> Self

Set the intrinsic display size.

Source

pub fn rows_pushed(&self) -> u32

Number of rows pushed so far.

Source

pub fn height(&self) -> u32

Total expected height.

Source

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 converted to the internal linear f32 format immediately, so the caller can free the source buffer after this call returns.

Source

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.

Source

pub fn finish_with_stats(self) -> Result<EncodeResult>

Encode and return JXL bytes together with EncodeStats.

Source

pub fn finish_into(self, out: &mut Vec<u8>) -> Result<EncodeResult>

Encode, appending to an existing buffer.

Source

pub fn finish_to(self, dest: impl Write) -> Result<EncodeResult>

Encode, writing to a std::io::Write destination.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.