Skip to main content

PixelFormat

Enum PixelFormat 

Source
#[non_exhaustive]
#[repr(u8)]
pub enum PixelFormat {
Show 22 variants Rgb8 = 1, Rgba8 = 2, Rgb16 = 3, Rgba16 = 4, RgbF32 = 5, RgbaF32 = 6, Gray8 = 7, Gray16 = 8, GrayF32 = 9, GrayA8 = 10, GrayA16 = 11, GrayAF32 = 12, Bgra8 = 13, Rgbx8 = 14, Bgrx8 = 15, OklabF32 = 16, OklabaF32 = 17, Cmyk8 = 18, RgbF16 = 19, RgbaF16 = 20, GrayF16 = 21, GrayAF16 = 22,
}
Expand description

Physical pixel layout for match-based format dispatch.

Each variant encodes the channel type (U8/U16/F32) and layout (RGB/RGBA/ Gray/etc.) in one discriminant. Transfer function and alpha mode live on PixelDescriptor, not here.

Use this enum when you need exhaustive match dispatch over known pixel layouts.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Rgb8 = 1

§

Rgba8 = 2

§

Rgb16 = 3

§

Rgba16 = 4

§

RgbF32 = 5

§

RgbaF32 = 6

§

Gray8 = 7

§

Gray16 = 8

§

GrayF32 = 9

§

GrayA8 = 10

§

GrayA16 = 11

§

GrayAF32 = 12

§

Bgra8 = 13

§

Rgbx8 = 14

§

Bgrx8 = 15

§

OklabF32 = 16

§

OklabaF32 = 17

§

Cmyk8 = 18

8-bit CMYK (4 bytes per pixel, no transfer function).

§

RgbF16 = 19

f16 (IEEE 754 half-precision) RGB.

§

RgbaF16 = 20

f16 (IEEE 754 half-precision) RGBA.

§

GrayF16 = 21

f16 (IEEE 754 half-precision) grayscale.

§

GrayAF16 = 22

f16 (IEEE 754 half-precision) grayscale with alpha.

Implementations§

Source§

impl PixelFormat

Source

pub const fn channel_type(self) -> ChannelType

Channel storage type.

Source

pub const fn layout(self) -> ChannelLayout

Channel layout.

Source

pub const fn color_model(self) -> ColorModel

Color model (what the channels represent).

Source

pub const fn byte_order(self) -> ByteOrder

Byte order (Native or BGR).

Source

pub const fn channels(self) -> usize

Number of channels (including alpha/padding if present).

Source

pub const fn bytes_per_pixel(self) -> usize

Bytes per pixel.

Source

pub const fn has_alpha_bytes(self) -> bool

Whether this format has alpha or padding bytes (4th channel).

Source

pub const fn is_grayscale(self) -> bool

Whether this format is grayscale.

Source

pub const fn default_alpha(self) -> Option<AlphaMode>

Default alpha mode for this format.

  • Formats with no alpha bytes → None
  • Formats with padding (Rgbx8, Bgrx8) → Some(AlphaMode::Undefined)
  • Formats with alpha → Some(AlphaMode::Straight)
Source

pub const fn name(self) -> &'static str

Short human-readable name.

Source

pub const fn from_parts( channel_type: ChannelType, layout: ChannelLayout, alpha: Option<AlphaMode>, ) -> Option<PixelFormat>

Resolve a format from channel type, layout, and alpha presence.

Returns None for combinations that have no PixelFormat variant (e.g. (U16, Bgra, _)).

Source

pub const fn descriptor(self) -> PixelDescriptor

Base descriptor with Unknown transfer and BT.709 primaries.

Trait Implementations§

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 Copy for PixelFormat

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 Display 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 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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.