Struct pixelflut::Color [−][src]
Expand description
RGB color type with optional alpha channel
Fields
r: u8
g: u8
b: u8
a: 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));
Trait Implementations
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());
type Err = PixelflutError
type Err = PixelflutError
The associated error which can be returned from parsing.
Auto Trait Implementations
impl RefUnwindSafe for Color
impl UnwindSafe for Color
Blanket Implementations
Mutably borrows from an owned value. Read more