Skip to main content

PixelFormat

Struct PixelFormat 

Source
#[non_exhaustive]
pub struct PixelFormat { /* private fields */ }
Expand description

Full re-export of zenpixels core types (zero module name collisions!). Complete, validated description of an interleaved pixel: physical SampleLayout + algebraic ColorSpace.

Implementations§

Source§

impl PixelFormat

Source

pub const RGB8_SRGB: PixelFormat

8-bit sRGB RGB (RGB8).

For a 'static borrowed reference (&'static PixelFormat) in PixelView::new, borrow &formats::RGB8_SRGB.

Source

pub const RGBA8_SRGB: PixelFormat

8-bit sRGB RGBA straight alpha (RGBA8). Borrow &formats::RGBA8_SRGB for views.

Source

pub const BGR8_SRGB: PixelFormat

8-bit sRGB BGR (BGR8). Borrow &formats::BGR8_SRGB for views.

Source

pub const BGRA8_SRGB: PixelFormat

8-bit sRGB BGRA straight alpha (BGRA8). Borrow &formats::BGRA8_SRGB for views.

Source

pub const RGBX8_SRGB: PixelFormat

8-bit sRGB RGBx (4th byte undefined padding). Borrow &formats::RGBX8_SRGB for views.

Source

pub const BGRX8_SRGB: PixelFormat

8-bit sRGB BGRx (4th byte undefined padding). Borrow &formats::BGRX8_SRGB for views.

Source

pub const RGB16_SRGB: PixelFormat

16-bit sRGB RGB (RGB16). Borrow &formats::RGB16_SRGB for views.

Source

pub const RGBA16_SRGB: PixelFormat

16-bit sRGB RGBA straight alpha (RGBA16). Borrow &formats::RGBA16_SRGB for views.

Source

pub const RGB8_DISPLAY_P3: PixelFormat

8-bit full-range Display P3 RGB with the sRGB transfer curve. Borrow &formats::RGB8_DISPLAY_P3 for views.

Source

pub const RGB16_DISPLAY_P3: PixelFormat

16-bit full-range Display P3 RGB with the sRGB transfer curve. Borrow &formats::RGB16_DISPLAY_P3 for views.

Source

pub const RGBA8_DISPLAY_P3: PixelFormat

8-bit full-range Display P3 RGBA with straight alpha and the sRGB transfer curve. Borrow &formats::RGBA8_DISPLAY_P3 for views.

Source

pub const RGBA16_DISPLAY_P3: PixelFormat

16-bit full-range Display P3 RGBA with straight alpha and the sRGB transfer curve. Borrow &formats::RGBA16_DISPLAY_P3 for views.

Source

pub const RGBF32_LINEAR: PixelFormat

32-bit float linear RGB (RGBF32). Borrow &formats::RGBF32_LINEAR for views.

Source

pub const RGBAF32_LINEAR: PixelFormat

32-bit float linear RGBA straight alpha (RGBAF32). Borrow &formats::RGBAF32_LINEAR for views.

Source

pub const RGBF16_LINEAR: PixelFormat

16-bit half-float linear RGB (RGBF16). Borrow &formats::RGBF16_LINEAR for views.

Source

pub const RGBAF16_LINEAR: PixelFormat

16-bit half-float linear RGBA straight alpha (RGBAF16). Borrow &formats::RGBAF16_LINEAR for views.

Source

pub const GRAY8_SRGB: PixelFormat

8-bit sRGB grayscale (GRAY8). Borrow &formats::GRAY8_SRGB for views.

Source

pub const GRAYA8_SRGB: PixelFormat

8-bit sRGB grayscale + straight alpha (GRAYA8). Borrow &formats::GRAYA8_SRGB for views.

Source

pub const GRAY16_SRGB: PixelFormat

16-bit sRGB grayscale (GRAY16). Borrow &formats::GRAY16_SRGB for views.

Source

pub const GRAYF32_LINEAR: PixelFormat

32-bit float linear grayscale (GRAYF32). Borrow &formats::GRAYF32_LINEAR for views.

Source

pub const RGB16_BT2100_PQ: PixelFormat

16-bit BT.2100 PQ HDR RGB (RGB16, BT.2020, ST 2084). Borrow &formats::RGB16_BT2100_PQ for views.

Source

pub const RGB16_BT2100_HLG_SCENE: PixelFormat

16-bit BT.2100 HLG HDR RGB, scene-referred. Borrow &formats::RGB16_BT2100_HLG_SCENE for views.

Source

pub const RGB16_BT2100_HLG_1000: PixelFormat

16-bit BT.2100 HLG HDR RGB with explicit 1000-nit reference rendering. Borrow &formats::RGB16_BT2100_HLG_1000 for views.

Source

pub const OKLAB_F32: PixelFormat

32-bit float Oklab (no alpha). Borrow &formats::OKLAB_F32 for views.

Source

pub const OKLABA_F32: PixelFormat

32-bit float Oklab + straight alpha. Borrow &formats::OKLABA_F32 for views.

Source

pub const fn layout(&self) -> SampleLayout

Physical storage and channel layout.

Source

pub const fn color(&self) -> &ColorSpace

Authoritative interpretation of the samples.

Source

pub fn as_static_ref(&self) -> Option<&'static PixelFormat>

Return a 'static preset reference if self equals one of the built-in common specs.

Used by FormatCow::from_owned and interop bridges (from_pixels_with_color, from_imgref, from_image_buffer) to avoid heap allocation for sRGB, Display P3, linear, HDR, and Oklab presets.

Source

pub fn new( layout: SampleLayout, color: ColorSpace, ) -> Result<PixelFormat, At<ColorError>>

Construct a format after checking layout and color compatibility.

An attached active ICC profile is checked for structure and compatible channels. Use ColorOrigin to retain raw container declarations independently of this format.

Source

pub const fn new_const(layout: SampleLayout, color: ColorSpace) -> PixelFormat

Construct a checked format in a constant.

Use Self::new for runtime input, ICC profiles, and owned custom RGB primaries. For encoder capability tables, declare a const slice or borrow an array in an inline const block.

§Panics

Panics if the layout and color are incompatible, or if the color contains an ICC profile or owned custom RGB primaries.

use zenpixels::{ColorSpace, PixelFormat, SampleLayout};

const CAPS: &[PixelFormat] = &[
    PixelFormat::RGB8_DISPLAY_P3,
    PixelFormat::new_const(SampleLayout::RGB16, ColorSpace::LINEAR_SRGB),
];
assert_eq!(CAPS[1].layout(), SampleLayout::RGB16);

An incompatible layout and color fail constant evaluation.

ⓘ
use zenpixels::{ColorSpace, PixelFormat, SampleLayout};

const INVALID: PixelFormat =
    PixelFormat::new_const(SampleLayout::RGBX8, ColorSpace::SRGB_ALPHA);
Source

pub fn cmyk8(icc: Option<Arc<[u8]>>) -> Result<PixelFormat, At<ColorError>>

8-bit CMYK (0 = no ink), checking any supplied CMYK ICC profile.

Source

pub fn with_primaries( self, primaries: Primaries, ) -> Result<PixelFormat, At<ColorError>>

Replace RGB primaries, checking compatibility with the format. Other color models are unchanged.

Source

pub fn try_with_primaries(self, primaries: Primaries) -> Option<PixelFormat>

Replace RGB primaries. Returns None for other models or incompatible primaries.

Source

pub fn with_custom_primaries( self, primaries: CustomPrimaries, ) -> Result<PixelFormat, At<ColorError>>

Replace RGB primaries with CustomPrimaries, checking format compatibility.

Source

pub fn try_with_custom_primaries( self, primaries: CustomPrimaries, ) -> Option<PixelFormat>

Replace RGB primaries with CustomPrimaries. Returns None for other models or incompatible primaries.

Source

pub fn with_transfer( self, transfer: Transfer, ) -> Result<PixelFormat, At<ColorError>>

Replace the RGB or Gray transfer, checking compatibility with the format.

Source

pub fn try_with_transfer(self, transfer: Transfer) -> Option<PixelFormat>

Replace the RGB or Gray transfer. Returns None for other models or an incompatible transfer.

Source

pub fn with_range( self, range: SignalRange, ) -> Result<PixelFormat, At<ColorError>>

Replace the RGB or Gray signal range, checking compatibility with the format.

Source

pub fn try_with_range(self, range: SignalRange) -> Option<PixelFormat>

Replace the RGB or Gray range. Returns None for other models or an incompatible range.

Source

pub fn with_alpha(self, alpha: AlphaMode) -> Result<PixelFormat, At<ColorError>>

Replace alpha mode, returning an error if it disagrees with the layout.

Source

pub fn with_diffuse_white(self, diffuse_white: DiffuseWhite) -> PixelFormat

Attach a DiffuseWhite anchor (no-op on non-RGB/Gray/XYZ variants).

Source

pub fn try_with_diffuse_white( self, diffuse_white: DiffuseWhite, ) -> Option<PixelFormat>

Attach a DiffuseWhite anchor, returning None on non-RGB/Gray/XYZ variants.

Source

pub fn can_represent_hdr(&self) -> bool

Whether this spec can represent HDR light levels above SDR diffuse white (> 1.0).

Returns true for PQ and HLG transfers (any sample type), linear floating-point RGB/Gray (F16/F32/F64), floating-point CIE XYZ, and ICC profiles backed by floating-point storage or carrying an HDR (PQ/HLG) cicp tag.

Source

pub fn from_layout_assuming_color( layout: SampleLayout, ) -> Result<PixelFormat, At<ColorError>>

Construct a validated PixelFormat by assuming a conventional default color space for layout.

Assumption, not signal detection: chooses full-range sRGB for integer RGB/Gray layouts, linear sRGB/Gray for floating-point layouts, D65 for XYZ, straight/undefined alpha matching the layout’s alpha/padding slot, and untagged otherwise. Prefer explicit color spaces whenever container metadata is available.

Source

pub fn validate(&self) -> Result<(), At<ColorError>>

Validate that layout and color agree on channels, alpha/padding, range, and sample types.

Source

pub fn supports_interop(&self, target: InteropTarget) -> bool

Check whether this spec satisfies an InteropTarget’s zero-copy contract.

Trait Implementations§

Source§

impl AsRef<PixelFormat> for FormatCow<'_>

Source§

fn as_ref(&self) -> &PixelFormat

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl AsRef<PixelFormat> for PixelFormat

Source§

fn as_ref(&self) -> &PixelFormat

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for PixelFormat

Source§

fn clone(&self) -> PixelFormat

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

impl Debug for PixelFormat

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Eq for PixelFormat

Source§

impl<'a> From<&'a PixelFormat> for FormatCow<'a>

Source§

fn from(spec: &'a PixelFormat) -> FormatCow<'a>

Converts to this type from the input type.
Source§

impl Hash for PixelFormat

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for PixelFormat

Source§

fn eq(&self, other: &PixelFormat) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for PixelFormat

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.