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

source

pub fn new( red: ColorComponent, green: ColorComponent, blue: ColorComponent ) -> Self

Create a new pixel layout from the description of each component

source

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.

source

pub fn depth(self) -> u8

Get the depth of this pixel layout.

The depth is the number of significant bits of each pixel value.

source

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

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

source§

fn clone(&self) -> PixelLayout

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 PixelLayout

source§

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

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

impl PartialEq for PixelLayout

source§

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

source§

impl Eq for PixelLayout

source§

impl StructuralPartialEq for PixelLayout

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