Skip to main content

PixelBufferConvertExt

Trait PixelBufferConvertExt 

Source
pub trait PixelBufferConvertExt {
    // Required methods
    fn convert_to(
        &self,
        target: PixelDescriptor,
    ) -> Result<PixelBuffer, At<ConvertError>>;
    fn try_add_alpha(&self) -> Result<PixelBuffer, At<ConvertError>>;
    fn try_widen_to_u16(&self) -> Result<PixelBuffer, At<ConvertError>>;
    fn try_narrow_to_u8(&self) -> Result<PixelBuffer, At<ConvertError>>;
    fn linearize(&self) -> Result<PixelBuffer, At<ConvertError>>;
    fn delinearize(
        &self,
        transfer: TransferFunction,
    ) -> Result<PixelBuffer, At<ConvertError>>;
}
Expand description

Adds format conversion methods to type-erased PixelBuffer.

Required Methods§

Source

fn convert_to( &self, target: PixelDescriptor, ) -> Result<PixelBuffer, At<ConvertError>>

Convert pixel data to a different layout and depth.

Uses RowConverter for transfer-function-aware conversion. Color metadata is preserved.

Allocates a new PixelBuffer.

Source

fn try_add_alpha(&self) -> Result<PixelBuffer, At<ConvertError>>

Add an alpha channel. Allocates a new PixelBuffer.

  • Gray → GrayAlpha (opaque alpha)
  • Rgb → Rgba (opaque alpha)
  • Already has alpha → identity copy
Source

fn try_widen_to_u16(&self) -> Result<PixelBuffer, At<ConvertError>>

Widen to U16 depth (lossless, ×257). Allocates a new PixelBuffer.

Source

fn try_narrow_to_u8(&self) -> Result<PixelBuffer, At<ConvertError>>

Narrow to U8 depth (lossy, rounded). Allocates a new PixelBuffer.

Source

fn linearize(&self) -> Result<PixelBuffer, At<ConvertError>>

Convert to linear-light F32, preserving channel layout and primaries.

This is the EOTF step of a scene-referred pipeline: decoded pixels (sRGB, BT.709, PQ, HLG) are converted to linear light for processing.

Allocates a new PixelBuffer.

Source

fn delinearize( &self, transfer: TransferFunction, ) -> Result<PixelBuffer, At<ConvertError>>

Apply a transfer function to a linear-light buffer.

This is the OETF step: linear-light pixels are encoded for display or storage. The buffer should be in F32 linear light; if it is in a different transfer function, the conversion goes through linear as an intermediate step.

Allocates a new PixelBuffer.

Implementors§