Struct x11rb::image::PixelLayout
source · pub struct PixelLayout { /* private fields */ }
Expand description
A collection of color components describing the red, green, and blue components of a pixel.
A ColorComponent
describes a single color component in an image. This structure describes
the red
, green
, and blue
color components by containing a ColorComponent
for each of
them.
Implementations§
source§impl PixelLayout
impl PixelLayout
sourcepub fn new(
red: ColorComponent,
green: ColorComponent,
blue: ColorComponent
) -> Self
pub fn new( red: ColorComponent, green: ColorComponent, blue: ColorComponent ) -> Self
Create a new pixel layout from the description of each component
sourcepub fn from_visual_type(visual: Visualtype) -> Result<Self, ParseError>
pub fn from_visual_type(visual: Visualtype) -> Result<Self, ParseError>
Create a new pixel layout
This function errors if the visual has a different class than TrueColor
or DirectColor
,
because color pallets and grayscales are not supported. This function also errors if the
mask components of the visual are malformed.
sourcepub fn depth(self) -> u8
pub fn depth(self) -> u8
Get the depth of this pixel layout.
The depth is the number of significant bits of each pixel value.
sourcepub fn decode(self, pixel: u32) -> (u16, u16, u16)
pub fn decode(self, pixel: u32) -> (u16, u16, u16)
Decode a pixel value into its red, green, and blue components.
This function returns each component expanded to width 16.
let layout = PixelLayout::new(
ColorComponent::new(8, 16)?,
ColorComponent::new(8, 8)?,
ColorComponent::new(8, 0)?,
);
assert_eq!((0xABAB, 0x4343, 0x2121), layout.decode(0x78AB_4321));
sourcepub fn encode(self, (red, green, blue): (u16, u16, u16)) -> u32
pub fn encode(self, (red, green, blue): (u16, u16, u16)) -> u32
Encode a color value according to this layout.
let layout = PixelLayout::new(
ColorComponent::new(8, 16)?,
ColorComponent::new(8, 8)?,
ColorComponent::new(8, 0)?,
);
assert_eq!(0x00AB_4321, layout.encode((0xABAB, 0x4343, 0x2121)));
Trait Implementations§
source§impl Clone for PixelLayout
impl Clone for PixelLayout
source§fn clone(&self) -> PixelLayout
fn clone(&self) -> PixelLayout
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for PixelLayout
impl Debug for PixelLayout
source§impl PartialEq for PixelLayout
impl PartialEq for PixelLayout
source§fn eq(&self, other: &PixelLayout) -> bool
fn eq(&self, other: &PixelLayout) -> bool
self
and other
values to be equal, and is used
by ==
.