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>
impl<'a> FormatCow<'a>
Sourcepub fn from_owned(format: PixelFormat) -> FormatCow<'a>
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.
Sourcepub const fn from_arc(format: Arc<PixelFormat>) -> FormatCow<'a>
pub const fn from_arc(format: Arc<PixelFormat>) -> FormatCow<'a>
Wrap an existing Arc<PixelFormat> with zero additional allocation.
Sourcepub fn as_format(&self) -> &PixelFormat
pub fn as_format(&self) -> &PixelFormat
Borrow the underlying PixelFormat.
Sourcepub fn to_borrowed(&self) -> FormatCow<'_>
pub fn to_borrowed(&self) -> FormatCow<'_>
Re-borrow as a zero-clone FormatCow::Borrowed tied to &self.
Sourcepub fn into_owned(self) -> PixelFormat
pub fn into_owned(self) -> PixelFormat
Convert into an owned PixelFormat (cloning only if borrowed or shared).
Methods from Deref<Target = PixelFormat>§
pub const RGB8_SRGB: PixelFormat
pub const RGBA8_SRGB: PixelFormat
pub const BGR8_SRGB: PixelFormat
pub const BGRA8_SRGB: PixelFormat
pub const RGBX8_SRGB: PixelFormat
pub const BGRX8_SRGB: PixelFormat
pub const RGB16_SRGB: PixelFormat
pub const RGBA16_SRGB: PixelFormat
pub const RGB8_DISPLAY_P3: PixelFormat
pub const RGB16_DISPLAY_P3: PixelFormat
pub const RGBA8_DISPLAY_P3: PixelFormat
pub const RGBA16_DISPLAY_P3: PixelFormat
pub const RGBF32_LINEAR: PixelFormat
pub const RGBAF32_LINEAR: PixelFormat
pub const RGBF16_LINEAR: PixelFormat
pub const RGBAF16_LINEAR: PixelFormat
pub const GRAY8_SRGB: PixelFormat
pub const GRAYA8_SRGB: PixelFormat
pub const GRAY16_SRGB: PixelFormat
pub const GRAYF32_LINEAR: PixelFormat
pub const RGB16_BT2100_PQ: PixelFormat
pub const RGB16_BT2100_HLG_SCENE: PixelFormat
pub const RGB16_BT2100_HLG_1000: PixelFormat
pub const OKLAB_F32: PixelFormat
pub const OKLABA_F32: PixelFormat
Sourcepub fn layout(&self) -> SampleLayout
pub fn layout(&self) -> SampleLayout
Physical storage and channel layout.
Sourcepub fn color(&self) -> &ColorSpace
pub fn color(&self) -> &ColorSpace
Authoritative interpretation of the samples.
Sourcepub fn as_static_ref(&self) -> Option<&'static PixelFormat>
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.
Sourcepub fn can_represent_hdr(&self) -> bool
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.
Sourcepub fn validate(&self) -> Result<(), At<ColorError>>
pub fn validate(&self) -> Result<(), At<ColorError>>
Validate that layout and color agree on channels, alpha/padding, range, and sample types.
Sourcepub fn supports_interop(&self, target: InteropTarget) -> bool
pub fn supports_interop(&self, target: InteropTarget) -> bool
Check whether this spec satisfies an InteropTarget’s zero-copy contract.