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
impl RowConverter
Sourcepub fn new(
from: PixelDescriptor,
to: PixelDescriptor,
) -> Result<Self, At<ConvertError>>
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.
Sourcepub fn new_explicit(
from: PixelDescriptor,
to: PixelDescriptor,
options: &ConvertOptions,
) -> Result<Self, At<ConvertError>>
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.
Sourcepub fn new_explicit_with_cms(
from: PixelDescriptor,
to: PixelDescriptor,
options: &ConvertOptions,
cms: Option<&dyn PluggableCms>,
) -> Result<Self, At<ConvertError>>
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.
Sourcepub fn from_plan(plan: ConvertPlan) -> Self
pub fn from_plan(plan: ConvertPlan) -> Self
Create a converter from a pre-computed plan.
Sourcepub fn convert_row(&mut self, src: &[u8], dst: &mut [u8], width: u32)
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.
Sourcepub fn convert_rows(
&mut self,
src: &[u8],
src_stride: usize,
dst: &mut [u8],
dst_stride: usize,
width: u32,
rows: u32,
) -> Result<(), At<ConvertError>>
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.
Sourcepub fn is_identity(&self) -> bool
pub fn is_identity(&self) -> bool
True if the conversion is a no-op (formats are identical).
Sourcepub fn from_descriptor(&self) -> PixelDescriptor
pub fn from_descriptor(&self) -> PixelDescriptor
Source pixel format.
Sourcepub fn to_descriptor(&self) -> PixelDescriptor
pub fn to_descriptor(&self) -> PixelDescriptor
Target pixel format.
Sourcepub fn compose(&self, other: &Self) -> Option<Self>
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).
Sourcepub fn plan(&self) -> &ConvertPlan
pub fn plan(&self) -> &ConvertPlan
Access the underlying conversion plan.