Struct palette::Rgb
[−]
[src]
pub struct Rgb { pub red: f32, pub green: f32, pub blue: f32, pub alpha: f32, }
Linear RGB with an alpha component.
RGB is probably the most common color space, when it comes to computer graphics, and it's defined as an additive mixture of red, green and blue light, where gray scale colors are created when these three channels are equal in strength. This version of RGB is based on sRGB, which is pretty much the standard RGB model today.
Conversions and operations on this color space assumes that it's linear, meaning that gamma correction is required when converting to and from a displayable RGB, such as sRGB.
Fields
red: f32
The amount of red light, where 0.0 is no red light and 1.0 is the highest displayable amount.
green: f32
The amount of green light, where 0.0 is no green light and 1.0 is the highest displayable amount.
blue: f32
The amount of blue light, where 0.0 is no blue light and 1.0 is the highest displayable amount.
alpha: f32
The transparency of the color. 0.0 is completely transparent and 1.0 is completely opaque.
Methods
impl Rgb
[src]
Creation from linear RGB.
fn linear_rgb(red: f32, green: f32, blue: f32) -> Rgb
Linear RGB.
fn linear_rgba(red: f32, green: f32, blue: f32, alpha: f32) -> Rgb
Linear RGB with transparency.
fn linear_rgb8(red: u8, green: u8, blue: u8) -> Rgb
Linear RGB from 8 bit values.
fn linear_rgba8(red: u8, green: u8, blue: u8, alpha: u8) -> Rgb
Linear RGB with transparency from 8 bit values.
fn linear_pixel<P: RgbPixel>(pixel: &P) -> Rgb
Linear RGB from a linear pixel value.
impl Rgb
[src]
Creation from sRGB.
fn srgb(red: f32, green: f32, blue: f32) -> Rgb
Linear RGB from sRGB.
fn srgba(red: f32, green: f32, blue: f32, alpha: f32) -> Rgb
Linear RGB from sRGB with transparency.
fn srgb8(red: u8, green: u8, blue: u8) -> Rgb
Linear RGB from 8 bit sRGB.
fn srgba8(red: u8, green: u8, blue: u8, alpha: u8) -> Rgb
Linear RGB from 8 bit sRGB with transparency.
fn srgb_pixel<P: RgbPixel>(pixel: &P) -> Rgb
Linear RGB from an sRGB pixel value.
impl Rgb
[src]
Creation from gamma corrected RGB.
fn gamma_rgb(red: f32, green: f32, blue: f32, gamma: f32) -> Rgb
Linear RGB from gamma corrected RGB.
fn gamma_rgba(red: f32, green: f32, blue: f32, alpha: f32, gamma: f32) -> Rgb
Linear RGB from gamma corrected RGB with transparency.
fn gamma_rgb8(red: u8, green: u8, blue: u8, gamma: f32) -> Rgb
Linear RGB from 8 bit gamma corrected RGB.
fn gamma_rgba8(red: u8, green: u8, blue: u8, alpha: u8, gamma: f32) -> Rgb
Linear RGB from 8 bit gamma corrected RGB with transparency.
fn gamma_pixel<P: RgbPixel>(pixel: &P, gamma: f32) -> Rgb
Linear RGB from a gamma corrected pixel value.
impl Rgb
[src]
Conversion to "pixel space".
fn to_linear<P: RgbPixel>(&self) -> P
Convert to a linear RGB pixel. Rgb
is already assumed to be linear,
so the components will just be clamped to [0.0, 1.0] before conversion.
use palette::Rgb; let c = Rgb::linear_rgb(0.5, 0.3, 0.1); assert_eq!((c.red, c.green, c.blue), c.to_linear()); assert_eq!((0.5, 0.3, 0.1), c.to_linear());
fn to_srgb<P: RgbPixel>(&self) -> P
Convert to an sRGB pixel.
use palette::Rgb; let c = Rgb::srgb(0.5, 0.3, 0.1); assert_eq!((0.5, 0.3, 0.1), c.to_srgb());
fn to_gamma<P: RgbPixel>(&self, gamma: f32) -> P
Convert to a gamma corrected RGB pixel.
use palette::Rgb; let c = Rgb::gamma_rgb8(128, 64, 32, 2.2); assert_eq!((128, 64, 32), c.to_gamma(2.2));
Trait Implementations
impl PartialEq for Rgb
[src]
fn eq(&self, __arg_0: &Rgb) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Rgb) -> bool
This method tests for !=
.
impl Debug for Rgb
[src]
impl Copy for Rgb
[src]
impl Clone for Rgb
[src]
fn clone(&self) -> Rgb
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl ColorSpace for Rgb
[src]
fn is_valid(&self) -> bool
Check if the color's components are within the expected ranges.
fn clamp(&self) -> Rgb
Return a new color where the components has been clamped to the nearest valid values. Read more
fn clamp_self(&mut self)
Clamp the color's components to the nearest valid values.
impl Mix for Rgb
[src]
fn mix(&self, other: &Rgb, factor: f32) -> Rgb
Mix the color with an other color, by factor
. Read more
impl Shade for Rgb
[src]
fn lighten(&self, amount: f32) -> Rgb
Lighten the color by amount
.
fn darken(&self, amount: f32) -> Self
Darken the color by amount
.
impl GetHue for Rgb
[src]
type Hue = RgbHue
The kind of hue unit this color space uses. Read more
fn get_hue(&self) -> Option<RgbHue>
Calculate a hue if possible. Read more