YCbCrPlanarEncoder

Struct YCbCrPlanarEncoder 

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

Encoder for planar f32 YCbCr input.

Use when you have pre-converted YCbCr from video decoders, etc. Skips RGB->YCbCr conversion entirely.

Only valid with ColorMode::YCbCr. XYB mode requires RGB input.

§YCbCr Value Range

Input values should be in the centered range:

  • Y: 0.0 to 255.0 (luma)
  • Cb, Cr: -128.0 to 127.0 (centered chroma)

This matches the output of standard RGB→YCbCr conversion with BT.601 coefficients.

§Streaming

Data can be pushed in any row count - the encoder buffers partial strips internally and flushes when a complete strip is accumulated.

Implementations§

Source§

impl YCbCrPlanarEncoder

Source

pub fn push( &mut self, planes: &YCbCrPlanes<'_>, rows: usize, stop: impl Stop, ) -> Result<()>

Push full-resolution planes. Encoder subsamples chroma as needed.

All three planes must be at full luma resolution (width × rows). The encoder will perform chroma subsampling according to the configured ChromaSubsampling mode.

Data can be pushed in any amount - the encoder buffers partial strips internally and flushes when a complete strip is accumulated.

§Arguments
  • planes: Y, Cb, Cr plane data with per-plane strides
  • rows: Number of luma rows to push
  • stop: Cancellation token (use Unstoppable if not needed)
§Value Range
  • Y: 0.0 to 255.0
  • Cb, Cr: -128.0 to 127.0
Source

pub fn push_subsampled( &mut self, planes: &YCbCrPlanes<'_>, y_rows: usize, stop: impl Stop, ) -> Result<()>

Push with pre-subsampled chroma.

Use this when your chroma planes are already at the target subsampled resolution. Y plane is still at full resolution.

Note: Unlike push(), this method does not buffer partial strips. For best results, push complete strips (multiples of strip_height rows, which is 8 for 4:4:4 or 16 for 4:2:0).

§Arguments
  • planes: Y at full resolution, Cb/Cr at subsampled resolution
  • y_rows: Number of luma rows to push
  • stop: Cancellation token
§Chroma Dimensions

The expected chroma dimensions depend on the subsampling mode:

  • 4:4:4 (None): cb/cr at full width × full height
  • 4:2:2 (HalfHorizontal): cb/cr at width/2 × full height
  • 4:2:0 (Quarter): cb/cr at width/2 × height/2
Source

pub fn width(&self) -> u32

Get image width.

Source

pub fn height(&self) -> u32

Get image height.

Source

pub fn rows_pushed(&self) -> u32

Get number of rows pushed so far (including buffered rows).

Source

pub fn rows_remaining(&self) -> u32

Get number of rows remaining.

Source

pub fn finish(self) -> Result<Vec<u8>>

Finish encoding, return JPEG bytes.

Source

pub fn finish_to<W: Write>(self, output: W) -> Result<W>

Finish encoding to Write destination.

Source

pub fn finish_to_vec(self, output: &mut Vec<u8>) -> Result<()>

Finish encoding, appending JPEG bytes to an existing Vec.

Useful for no_std environments or buffer reuse.

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, 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.