Skip to main content

Format

Struct Format 

Source
pub struct Format {
    red_mask: u32,
    red_shift: u8,
    green_mask: u32,
    green_shift: u8,
    blue_mask: u32,
    blue_shift: u8,
    bits_per_pixel: u8,
}
Expand description

Native pixel layout of a contiguous surface.

Supports the two layouts the kernel actually drives: 32 bpp and 24 bpp. 16 bpp can be represented (for info replies and future drivers) but is rejected by Canvas constructors, because the kernel SIMD paths have no 16 bpp implementation.

Fields§

§red_mask: u32§red_shift: u8§green_mask: u32§green_shift: u8§blue_mask: u32§blue_shift: u8§bits_per_pixel: u8

Implementations§

Source§

impl Format

Source

pub const XRGB8888: Self

Canonical format used by UEFI GOP on x86: 0x00RRGGBB in a 32-bit word, i.e. bytes B, G, R, X in memory.

Source

pub const BGRX8888: Self

Same 8-bit channels, but red in the low byte (0x00BBGGRR).

Source

pub const RGB888: Self

24 bpp packed, B, G, R in memory.

Source

pub const RGB565: Self

16 bpp 5-6-5 (accepted by Format, rejected by Canvas for now).

Source

pub const fn from_masks( bits_per_pixel: u8, red_mask: u32, red_shift: u8, green_mask: u32, green_shift: u8, blue_mask: u32, blue_shift: u8, ) -> Self

Build a format from explicit masks. Shifts are kept even when they could be derived, so a driver that reports them can pass them through unchanged.

Source

pub const fn bits_per_pixel(self) -> u8

Source

pub const fn bytes_per_pixel(self) -> usize

Source

pub const fn red_mask(self) -> u32

Source

pub const fn green_mask(self) -> u32

Source

pub const fn blue_mask(self) -> u32

Source

pub const fn red_shift(self) -> u8

Source

pub const fn green_shift(self) -> u8

Source

pub const fn blue_shift(self) -> u8

Source

pub const fn is_supported(self) -> bool

Whether the drawing paths can drive this layout without conversion.

24 and 32 bpp only: those are the two widths implemented by PixelOps and by the scalar fallbacks.

Source

pub const fn is_xrgb8888(self) -> bool

Source

pub const fn is_valid(self) -> bool

Whether the masks, shifts and width form a usable layout.

Self::from_masks is public so a driver can pass its reported layout through; this is the check that stops a malformed one from reaching the pixel backends (shift overflow, mask wider than the pixel, overlapping channels, or a shift that does not match the mask).

Source

pub const fn compatible(self, other: Self) -> bool

Two formats are compatible when a bulk copy can move raw words between them without touching the bytes.

Source

pub const fn pack(self, rgb: Rgb) -> Packed

Encode an RGB triple into this layout.

Channels narrower than 8 bits are truncated to their mask, never shifted into the neighbouring channel. The unused byte of a 32 bpp word is set opaque, matching the kernel’s existing pack_rgb.

Source

pub const fn unpack(self, px: Packed) -> Rgb

Decode a pixel in this layout back to 8 bits per channel.

Narrow channels are scaled (5 bits -> 8 bits) rather than shifted, so a round trip through RGB565 is visually neutral.

Source

pub const fn convert(self, dst: Format, px: Packed) -> Packed

Convert one pixel to another layout. This is the single conversion point of the crate; everything else is a raw copy.

Source

pub const fn rgb(self, r: u8, g: u8, b: u8) -> Packed

Convenience: pack an RGB triple without naming the format twice.

Source

pub const fn black(self) -> Packed

Source

pub const fn white(self) -> Packed

Trait Implementations§

Source§

impl Clone for Format

Source§

fn clone(&self) -> Self

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 Format

Source§

impl Debug for Format

Source§

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

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

impl Default for Format

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Format

Source§

impl Hash for Format

Source§

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

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 Format

Source§

fn eq(&self, other: &Self) -> 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 Format

Auto Trait Implementations§

§

impl Forget for Format

§

impl Freeze for Format

§

impl Move for Format

§

impl RefUnwindSafe for Format

§

impl Send for Format

§

impl Sync for Format

§

impl Unpin for Format

§

impl UnsafeUnpin for Format

§

impl UnwindSafe for Format

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.