[][src]Struct pixelflut::pixel::Color

pub struct Color { /* fields omitted */ }

Methods

impl Color[src]

pub fn rgb(r: u8, g: u8, b: u8) -> Color[src]

Constructs a new Color without using an alpha channel.

Examples

Basic usage:

use pixelflut::Color;
Color::rgb(255, 255, 255);

pub fn rgba(r: u8, g: u8, b: u8, a: u8) -> Color[src]

Constructs a new Color using an alpha channel.

Examples

Basic usage:

use pixelflut::Color;
Color::rgba(255, 255, 255, 255);

pub fn packed(r: u8, g: u8, b: u8, a: u8) -> Color[src]

Constructs a new Color using the alpha channel only, if a != 255.

Examples

Basic usage:

use pixelflut::Color;
assert_eq!(Color::packed(123, 23, 42, 255), Color::rgb(123, 23, 42));
assert_eq!(Color::packed(123, 23, 42, 64), Color::rgba(123, 23, 42, 64));

pub fn pack(&self) -> Color[src]

Strips the alpha channel if not existent or value is 255.Color

Examples

Basic usage:

use pixelflut::Color;
assert_eq!(Color::rgba(12, 34, 56, 255).pack(), Color::rgb(12, 34, 56));
assert_eq!(Color::rgb(12, 34, 56).pack(), Color::rgb(12, 34, 56));
assert_eq!(Color::rgba(12, 34, 56, 78).pack(), Color::rgba(12, 34, 56, 78));

pub fn normalized(self) -> (u8, u8, u8, u8)[src]

Returns a 4-Tuple with the components red, green, blue and alpha

If no alpha channel is present, 255 is returned as the alpha channel.

Examples

use pixelflut::Color;
assert_eq!((255, 0, 0, 255), Color::rgb(255, 0, 0).normalized())

Trait Implementations

impl Into<(u8, u8, u8)> for Color[src]

impl Into<(u8, u8, u8, u8)> for Color[src]

impl Copy for Color[src]

impl PartialEq<Color> for Color[src]

impl From<(u8, u8, u8)> for Color[src]

fn from(color: (u8, u8, u8)) -> Color[src]

Returns a RGB Color

impl From<(u8, u8, u8, u8)> for Color[src]

fn from(color: (u8, u8, u8, u8)) -> Color[src]

Returns a RGBA Color

impl Clone for Color[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Display for Color[src]

impl Debug for Color[src]

impl Hash for Color[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl FromStr for Color[src]

type Err = Error

The associated error which can be returned from parsing.

fn from_str(s: &str) -> Result<Color>[src]

Converts a string to a color

Examples

use pixelflut::Color;
assert_eq!(Color::rgb(0x11, 0x22, 0x33), "112233".parse().unwrap());
assert_eq!(Color::rgba(0x11, 0x22, 0x33, 0xee), "112233ee".parse().unwrap());
assert!("".parse::<Color>().is_err());
assert!("123".parse::<Color>().is_err());
assert!("12345".parse::<Color>().is_err());
assert!(" 1 2 3".parse::<Color>().is_err());
assert!("112g33".parse::<Color>().is_err());

Auto Trait Implementations

impl Send for Color

impl Sync for Color

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> From for T[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.