Skip to main content

FormatCow

Enum FormatCow 

Source
pub enum FormatCow<'a> {
    Borrowed(&'a PixelFormat),
    Owned(Arc<PixelFormat>),
}
Expand description

Borrowed-or-owned PixelFormat carried inside PixelView<'a> and PixelViewMut<'a>.

Eliminates Arc refcount bumps on PixelBuf::as_view(), as_view_mut(), crop(), and sub_rows(), while storing owned specs behind an Arc so PixelView and PixelViewMut stay compact (size_of::<FormatCow<'_>>() == 16).

Ordinary view constructors (PixelView::new, PixelViewMut::new) accept &'a PixelFormat directly (guaranteed zero heap allocation — pass &formats::RGB8_SRGB or &local_spec). When a view genuinely needs to own a dynamically constructed PixelFormat, pass an explicit FormatCow via PixelView::new_with_format_cow using FormatCow::from_owned or FormatCow::from_arc.

Variants§

§

Borrowed(&'a PixelFormat)

Zero-clone reference to an PixelFormat owned by a buffer, caller, or static preset.

§

Owned(Arc<PixelFormat>)

Heap-shared owned PixelFormat (e.g. a dynamically constructed custom or ICC spec).

Implementations§

Source§

impl<'a> FormatCow<'a>

Source

pub fn from_owned(format: PixelFormat) -> FormatCow<'a>

Wrap an owned PixelFormat, borrowing a zero-allocation &'static PixelFormat when format matches a built-in preset, or allocating an Arc<PixelFormat> otherwise.

Source

pub const fn from_arc(format: Arc<PixelFormat>) -> FormatCow<'a>

Wrap an existing Arc<PixelFormat> with zero additional allocation.

Source

pub fn as_format(&self) -> &PixelFormat

Borrow the underlying PixelFormat.

Source

pub fn to_borrowed(&self) -> FormatCow<'_>

Re-borrow as a zero-clone FormatCow::Borrowed tied to &self.

Source

pub fn into_owned(self) -> PixelFormat

Convert into an owned PixelFormat (cloning only if borrowed or shared).

Methods from Deref<Target = PixelFormat>§

Source

pub const RGB8_SRGB: PixelFormat

Source

pub const RGBA8_SRGB: PixelFormat

Source

pub const BGR8_SRGB: PixelFormat

Source

pub const BGRA8_SRGB: PixelFormat

Source

pub const RGBX8_SRGB: PixelFormat

Source

pub const BGRX8_SRGB: PixelFormat

Source

pub const RGB16_SRGB: PixelFormat

Source

pub const RGBA16_SRGB: PixelFormat

Source

pub const RGB8_DISPLAY_P3: PixelFormat

Source

pub const RGB16_DISPLAY_P3: PixelFormat

Source

pub const RGBA8_DISPLAY_P3: PixelFormat

Source

pub const RGBA16_DISPLAY_P3: PixelFormat

Source

pub const RGBF32_LINEAR: PixelFormat

Source

pub const RGBAF32_LINEAR: PixelFormat

Source

pub const RGBF16_LINEAR: PixelFormat

Source

pub const RGBAF16_LINEAR: PixelFormat

Source

pub const GRAY8_SRGB: PixelFormat

Source

pub const GRAYA8_SRGB: PixelFormat

Source

pub const GRAY16_SRGB: PixelFormat

Source

pub const GRAYF32_LINEAR: PixelFormat

Source

pub const RGB16_BT2100_PQ: PixelFormat

Source

pub const RGB16_BT2100_HLG_SCENE: PixelFormat

Source

pub const RGB16_BT2100_HLG_1000: PixelFormat

Source

pub const OKLAB_F32: PixelFormat

Source

pub const OKLABA_F32: PixelFormat

Source

pub fn layout(&self) -> SampleLayout

Physical storage and channel layout.

Source

pub 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 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 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<'a> Clone for FormatCow<'a>

Source§

fn clone(&self) -> FormatCow<'a>

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<'a> Debug for FormatCow<'a>

Source§

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

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

impl Deref for FormatCow<'_>

Source§

type Target = PixelFormat

The resulting type after dereferencing.
Source§

fn deref(&self) -> &PixelFormat

Dereferences the value.
Source§

impl Eq for FormatCow<'_>

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 From<Arc<PixelFormat>> for FormatCow<'_>

Source§

fn from(spec: Arc<PixelFormat>) -> FormatCow<'_>

Converts to this type from the input type.
Source§

impl Hash for FormatCow<'_>

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 FormatCow<'_>

Source§

fn eq(&self, other: &FormatCow<'_>) -> bool

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

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

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for FormatCow<'a>

§

impl<'a> RefUnwindSafe for FormatCow<'a>

§

impl<'a> Send for FormatCow<'a>

§

impl<'a> Sync for FormatCow<'a>

§

impl<'a> Unpin for FormatCow<'a>

§

impl<'a> UnsafeUnpin for FormatCow<'a>

§

impl<'a> UnwindSafe for FormatCow<'a>

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.