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: u8Implementations§
Source§impl Format
impl Format
Sourcepub const XRGB8888: Self
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.
Sourcepub 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
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.
pub const fn bits_per_pixel(self) -> u8
pub const fn bytes_per_pixel(self) -> usize
pub const fn red_mask(self) -> u32
pub const fn green_mask(self) -> u32
pub const fn blue_mask(self) -> u32
pub const fn red_shift(self) -> u8
pub const fn green_shift(self) -> u8
pub const fn blue_shift(self) -> u8
Sourcepub const fn is_supported(self) -> bool
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.
pub const fn is_xrgb8888(self) -> bool
Sourcepub const fn is_valid(self) -> bool
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).
Sourcepub const fn compatible(self, other: Self) -> bool
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.
Sourcepub const fn pack(self, rgb: Rgb) -> Packed
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.
Sourcepub const fn unpack(self, px: Packed) -> Rgb
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.
Sourcepub const fn convert(self, dst: Format, px: Packed) -> Packed
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.
Sourcepub const fn rgb(self, r: u8, g: u8, b: u8) -> Packed
pub const fn rgb(self, r: u8, g: u8, b: u8) -> Packed
Convenience: pack an RGB triple without naming the format twice.