Struct pixelflut::Color[][src]

pub struct Color {
    pub r: u8,
    pub g: u8,
    pub b: u8,
    pub a: Option<u8>,
}
Expand description

RGB color type with optional alpha channel

Fields

r: u8g: u8b: u8a: Option<u8>

Implementations

Constructs a new Color without using an alpha channel.

Examples

Basic usage:

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

Constructs a new Color using an alpha channel.

Examples

Basic usage:

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

Returns the alpha channel of the Color.

If the color does not have an alpha channel, 255 will be returned.

Example

use pixelflut::Color;

let without_alpha = Color::rgb(123, 123, 123);
assert_eq!(without_alpha.alpha(), 255);

let with_alpha = Color::rgba(123, 123, 123, 123);
assert_eq!(with_alpha.alpha(), 123)

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

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

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Formats the value using the given formatter. Read more

Returns a RGBA Color

Returns a RGB Color

Performs the conversion.

Performs the conversion.

Returns a Rgb Color

Returns a Rgba Color

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

The associated error which can be returned from parsing.

Feeds this value into the given Hasher. Read more

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

Performs the conversion.

Performs the conversion.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.