Skip to main content

RowConverter

Struct RowConverter 

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

Pre-computed pixel format converter with pre-allocated scratch buffers.

Create once, then call convert_row for each row. Multi-step conversions reuse internal scratch buffers, eliminating per-row heap allocation.

§Example

use zenpixels::{RowConverter, PixelDescriptor};

let mut conv = RowConverter::new(
    PixelDescriptor::RGB8_SRGB,
    PixelDescriptor::RGBA8_SRGB,
)?;

for y in 0..height {
    conv.convert_row(&src_row, &mut dst_row, width);
}

Implementations§

Source§

impl RowConverter

Source

pub fn new( from: PixelDescriptor, to: PixelDescriptor, ) -> Result<Self, At<ConvertError>>

Create a converter from from to to.

Cross-profile conversions (different primaries or transfer) go through the default CMS dispatch chain — see new_explicit_with_cms for details. Returns Err if no conversion path exists between the formats.

Source

pub fn new_explicit( from: PixelDescriptor, to: PixelDescriptor, options: &ConvertOptions, ) -> Result<Self, At<ConvertError>>

Create a converter with explicit policy options.

Like new but validates ConvertOptions policies (alpha removal, depth reduction, RGB→Gray). Cross-profile conversions go through the default CMS dispatch chain.

Source

pub fn new_explicit_with_cms( from: PixelDescriptor, to: PixelDescriptor, options: &ConvertOptions, cms: Option<&dyn PluggableCms>, ) -> Result<Self, At<ConvertError>>

Create a converter that may delegate the color conversion to a PluggableCms.

When cms is Some and the source and destination have different primaries or transfer functions, the plugin is asked to supply a row transform for the full (from, to) pair. If it accepts, the plan becomes a single external-transform step; the built-in gamut matrix and matlut fast paths are bypassed for that conversion. If the plugin declines or there is no color work to do, behavior matches new_explicit.

Source

pub fn from_plan(plan: ConvertPlan) -> Self

Create a converter from a pre-computed plan.

Source

pub fn convert_row(&mut self, src: &[u8], dst: &mut [u8], width: u32)

Convert one row of width pixels.

src must contain at least width * from.bytes_per_pixel() bytes. dst must contain at least width * to.bytes_per_pixel() bytes.

Multi-step conversions reuse internal scratch buffers — no heap allocation after the first call at a given width.

Source

pub fn convert_rows( &mut self, src: &[u8], src_stride: usize, dst: &mut [u8], dst_stride: usize, width: u32, rows: u32, ) -> Result<(), At<ConvertError>>

Convert multiple rows from a strided source buffer to a strided destination.

The source and destination can have different strides.

Source

pub fn is_identity(&self) -> bool

True if the conversion is a no-op (formats are identical).

Source

pub fn from_descriptor(&self) -> PixelDescriptor

Source pixel format.

Source

pub fn to_descriptor(&self) -> PixelDescriptor

Target pixel format.

Source

pub fn compose(&self, other: &Self) -> Option<Self>

Compose two converters: apply self then other in a single pass.

Adjacent inverse steps cancel (e.g., sRGB→linear then linear→sRGB becomes identity). This eliminates intermediate buffers in zenpipe’s TransformSource when chaining format conversions.

Returns None if the converters are incompatible (self.to != other.from).

Source

pub fn plan(&self) -> &ConvertPlan

Access the underlying conversion plan.

Trait Implementations§

Source§

impl Clone for RowConverter

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.