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

source

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.
source

pub fn width(self) -> u8

Get the bit width of the color component.

source

pub fn shift(self) -> u8

Get the bit shift of the color component.

source

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);
source

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.

source

pub fn decode(self, pixel: u32) -> u16

Get this color component out of a pixel value.

This function gets a single pixel value and returns this color component’s value in that pixel value, expanded to width 16.

let red = ColorComponent::new(8, 16)?;
assert_eq!(0xABAB, red.decode(0x78AB_4321));
source

pub fn encode(self, intensity: u16) -> u32

Encode a color value according to this pixel format.

let red = ColorComponent::new(8, 16)?;
assert_eq!(0xAB0000, red.encode(0xABCD));

Trait Implementations§

source§

impl Clone for ColorComponent

source§

fn clone(&self) -> ColorComponent

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ColorComponent

source§

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

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

impl PartialEq for ColorComponent

source§

fn eq(&self, other: &ColorComponent) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for ColorComponent

source§

impl Eq for ColorComponent

source§

impl StructuralPartialEq for ColorComponent

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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,

§

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

§

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

§

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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more