Struct x11rb::image::ColorComponent
source · pub struct ColorComponent { /* private fields */ }
Expand description
The description of a single color component.
For example, in an RGB image, pixels are often saved as 0xRRGGBB
, where each letter
represents the respective color component. In the example, green has a width
of 8 (it takes
up 8 bits) and a shift
of 16
(there are 16 less significant bits beyond it). This info is
represented as a ColorComponent
.
Implementations§
source§impl ColorComponent
impl ColorComponent
sourcepub fn new(width: u8, shift: u8) -> Result<Self, ParseError>
pub fn new(width: u8, shift: u8) -> Result<Self, ParseError>
Create a new color component with the given information.
The following conditions must be satisfied:
width <= 16
: color components have at most 16 bits.shift < 32
: pixel values have at most 32 bits.shift + width <= 32
: pixel values have at most 32 bits.
sourcepub fn mask(self) -> u32
pub fn mask(self) -> u32
Get the pixel mask representing this color component.
The mask can be used to mask off other colors in a pixel value. Only the bits that correspond to this color component are set.
let red = ColorComponent::new(8, 16)?;
assert_eq!(red.mask(), 0xff0000);
sourcepub fn from_mask(mask: u32) -> Result<Self, ParseError>
pub fn from_mask(mask: u32) -> Result<Self, ParseError>
Create a new color component from a color mask.
This turns a color mask into its individual components.
let red1 = ColorComponent::new(8, 16);
let red2 = ColorComponent::from_mask(0xff0000);
§Errors
This function fails if the given value is not a well-formed mask. This means that at least one bit must be set and the set bits must be consecutive.
Trait Implementations§
source§impl Clone for ColorComponent
impl Clone for ColorComponent
source§fn clone(&self) -> ColorComponent
fn clone(&self) -> ColorComponent
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for ColorComponent
impl Debug for ColorComponent
source§impl PartialEq for ColorComponent
impl PartialEq for ColorComponent
source§fn eq(&self, other: &ColorComponent) -> bool
fn eq(&self, other: &ColorComponent) -> bool
self
and other
values to be equal, and is used
by ==
.