[][src]Struct palette::rgb::Rgb

#[repr(C)]
pub struct Rgb<S: RgbStandard = Srgb, T: Component = f32> {
    pub red: T,
    pub green: T,
    pub blue: T,
    pub standard: PhantomData<S>,
}

Generic RGB.

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.

Many conversions and operations on this color space requires that it's linear, meaning that gamma correction is required when converting to and from a displayable RGB, such as sRGB. See the pixel module for encoding formats.

Fields

red: T

The amount of red light, where 0.0 is no red light and 1.0f (or 255u8) is the highest displayable amount.

green: T

The amount of green light, where 0.0 is no green light and 1.0f (or 255u8) is the highest displayable amount.

blue: T

The amount of blue light, where 0.0 is no blue light and 1.0f (or 255u8) is the highest displayable amount.

standard: PhantomData<S>

The kind of RGB standard. sRGB is the default.

Methods

impl<S: RgbStandard, T: Component> Rgb<S, T>[src]

pub fn new(red: T, green: T, blue: T) -> Rgb<S, T>[src]

Create an RGB color.

pub fn into_format<U: Component>(self) -> Rgb<S, U>[src]

Convert into another component type.

pub fn from_format<U: Component>(color: Rgb<S, U>) -> Self[src]

Convert from another component type.

pub fn into_components(self) -> (T, T, T)[src]

Convert to a (red, green, blue) tuple.

pub fn from_components((red, green, blue): (T, T, T)) -> Self[src]

Convert from a (red, green, blue) tuple.

impl<S: RgbStandard, T: Component + Float> Rgb<S, T>[src]

pub fn into_linear(self) -> Rgb<Linear<S::Space>, T>[src]

Convert the color to linear RGB.

pub fn from_linear(color: Rgb<Linear<S::Space>, T>) -> Rgb<S, T>[src]

Convert linear RGB to nonlinear RGB.

pub fn into_encoding<St: RgbStandard<Space = S::Space>>(self) -> Rgb<St, T>[src]

Convert the color to a different encoding.

pub fn from_encoding<St: RgbStandard<Space = S::Space>>(
    color: Rgb<St, T>
) -> Rgb<S, T>
[src]

Convert RGB from a different encoding.

Trait Implementations

impl<S, T> Blend for Rgb<S, T> where
    S: RgbStandard<TransferFn = LinearFn>,
    T: Component + Float
[src]

type Color = Rgb<S, T>

The core color type. Typically Self for color types without alpha.

fn blend<F>(self, destination: Self, blend_function: F) -> Self where
    F: BlendFunction<Self::Color>, 
[src]

Blend self, as the source color, with destination, using blend_function. Anything that implements BlendFunction is acceptable, including functions and closures. Read more

fn over(self, other: Self) -> Self[src]

Place self over other. This is the good old common alpha composition equation. Read more

fn inside(self, other: Self) -> Self[src]

Results in the parts of self that overlaps the visible parts of other. Read more

fn outside(self, other: Self) -> Self[src]

Results in the parts of self that lies outside the visible parts of other. Read more

fn atop(self, other: Self) -> Self[src]

Place self over only the visible parts of other.

fn xor(self, other: Self) -> Self[src]

Results in either self or other, where they do not overlap.

fn plus(self, other: Self) -> Self[src]

Add self and other. This uses the alpha component to regulate the effect, so it's not just plain component wise addition. Read more

fn multiply(self, other: Self) -> Self[src]

Multiply self with other. This uses the alpha component to regulate the effect, so it's not just plain component wise multiplication. Read more

fn screen(self, other: Self) -> Self[src]

Make a color which is at least as light as self or other.

fn overlay(self, other: Self) -> Self[src]

Multiply self or other if other is dark, or screen them if other is light. This results in an S curve. Read more

fn darken(self, other: Self) -> Self[src]

Return the darkest parts of self and other.

fn lighten(self, other: Self) -> Self[src]

Return the lightest parts of self and other.

fn dodge(self, other: Self) -> Self[src]

Lighten other to reflect self. Results in other if self is black. Read more

fn burn(self, other: Self) -> Self[src]

Darken other to reflect self. Results in other if self is white. Read more

fn hard_light(self, other: Self) -> Self[src]

Multiply self or other if other is dark, or screen them if self is light. This is similar to overlay, but depends on self instead of other. Read more

fn soft_light(self, other: Self) -> Self[src]

Lighten other if self is light, or darken other as if it's burned if self is dark. The effect is increased if the components of self is further from 0.5. Read more

fn difference(self, other: Self) -> Self[src]

Return the absolute difference between self and other. It's basically abs(self - other), but regulated by the alpha component. Read more

fn exclusion(self, other: Self) -> Self[src]

Similar to difference, but appears to result in a lower contrast. other is inverted if self is white, and preserved if self is black. Read more

impl<S: RgbStandard, T: Component> FromColor<<<S as RgbStandard>::Space as RgbSpace>::WhitePoint, T> for Rgb<S, T> where
    T: Component + Float
[src]

fn from_yxy(inp: Yxy<Wp, T>) -> Self[src]

Convert from Yxy color space

fn from_lab(inp: Lab<Wp, T>) -> Self[src]

Convert from Lab* color space

fn from_lch(inp: Lch<Wp, T>) -> Self[src]

Convert from LCh° color space

fn from_hwb<S: RgbSpace<WhitePoint = Wp>>(inp: Hwb<S, T>) -> Self[src]

Convert from HWB color space

impl<S, T, Wp> IntoColor<Wp, T> for Rgb<S, T> where
    S: RgbStandard,
    T: Component + Float,
    Wp: WhitePoint,
    S::Space: RgbSpace<WhitePoint = Wp>, 
[src]

impl<S: RgbStandard, T: Component> Pixel<T> for Rgb<S, T>[src]

fn as_raw<P: RawPixel<T> + ?Sized>(&self) -> &P[src]

Cast as a reference to raw color components.

fn as_raw_mut<P: RawPixel<T> + ?Sized>(&mut self) -> &mut P[src]

Cast as a mutable reference to raw color components.

fn into_raw<P: RawPixelSized<T>>(self) -> P[src]

Convert from raw color components.

fn from_raw<P: RawPixel<T> + ?Sized>(pixel: &P) -> &Self[src]

Cast from a reference to raw color components.

fn from_raw_mut<P: RawPixel<T> + ?Sized>(pixel: &mut P) -> &mut Self[src]

Cast from a mutable reference to raw color components.

fn from_raw_slice(slice: &[T]) -> &[Self][src]

Cast a slice of raw color components to a slice of colors. Read more

fn from_raw_slice_mut(slice: &mut [T]) -> &mut [Self][src]

Cast a mutable slice of raw color components to a mutable slice of colors. Read more

fn into_raw_slice(slice: &[Self]) -> &[T][src]

Cast a slice of colors to a slice of raw color components. Read more

fn into_raw_slice_mut(slice: &mut [Self]) -> &mut [T][src]

Cast a mutable slice of colors to a mutable slice of raw color components. Read more

impl<S, T> Limited for Rgb<S, T> where
    S: RgbStandard,
    T: Component
[src]

impl<S, T> Mix for Rgb<S, T> where
    S: RgbStandard<TransferFn = LinearFn>,
    T: Component + Float
[src]

type Scalar = T

The type of the mixing factor.

impl<S, T> Shade for Rgb<S, T> where
    S: RgbStandard<TransferFn = LinearFn>,
    T: Component + Float
[src]

type Scalar = T

The type of the lighten/darken amount.

fn darken(&self, amount: Self::Scalar) -> Self[src]

Darken the color by amount.

impl<S, T> GetHue for Rgb<S, T> where
    S: RgbStandard<TransferFn = LinearFn>,
    T: Component + Float
[src]

type Hue = RgbHue<T>

The kind of hue unit this color space uses. Read more

impl<S, T> ComponentWise for Rgb<S, T> where
    S: RgbStandard,
    T: Component
[src]

type Scalar = T

The scalar type for color components.

impl<S: RgbStandard, T: Component> Copy for Rgb<S, T>[src]

impl<S, T, P: ?Sized> AsRef<P> for Rgb<S, T> where
    T: Component,
    S: RgbStandard,
    P: RawPixel<T>, 
[src]

fn as_ref(&self) -> &P[src]

Convert to a raw pixel format.

use palette::Srgb;

let mut rgb = Srgb::new(38, 42, 19);
let raw: &[u8] = rgb.as_ref();

assert_eq!(raw[1], 42);

impl<S, T> Default for Rgb<S, T> where
    T: Component,
    S: RgbStandard
[src]

impl<S: RgbStandard, T: Component> Clone for Rgb<S, T>[src]

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

Performs copy-assignment from source. Read more

impl<S: PartialEq + RgbStandard, T: PartialEq + Component> PartialEq<Rgb<S, T>> for Rgb<S, T>[src]

impl<S, T, _S> From<Rgb<_S, T>> for Hsl<S, T> where
    T: Component + Float,
    S: RgbSpace,
    T: Component + Float,
    _S: RgbStandard<Space = S>, 
[src]

impl<S, T, _S> From<Rgb<_S, T>> for Alpha<Hsl<S, T>, T> where
    T: Component + Float,
    S: RgbSpace,
    T: Component + Float,
    _S: RgbStandard<Space = S>, 
[src]

impl<S, T, _S> From<Rgb<_S, T>> for Hsv<S, T> where
    T: Component + Float,
    S: RgbSpace,
    T: Component + Float,
    _S: RgbStandard<Space = S>, 
[src]

impl<S, T, _S> From<Rgb<_S, T>> for Alpha<Hsv<S, T>, T> where
    T: Component + Float,
    S: RgbSpace,
    T: Component + Float,
    _S: RgbStandard<Space = S>, 
[src]

impl<S, T, _S> From<Rgb<_S, T>> for Hwb<S, T> where
    T: Component + Float,
    S: RgbSpace,
    T: Component + Float,
    _S: RgbStandard<Space = S>, 
[src]

impl<S, T, _S> From<Rgb<_S, T>> for Alpha<Hwb<S, T>, T> where
    T: Component + Float,
    S: RgbSpace,
    T: Component + Float,
    _S: RgbStandard<Space = S>, 
[src]

impl<Wp, T, _S> From<Rgb<_S, T>> for Lab<Wp, T> where
    T: Component + Float,
    Wp: WhitePoint,
    T: Component + Float,
    _S: RgbStandard,
    _S::Space: RgbSpace<WhitePoint = Wp>, 
[src]

impl<Wp, T, _S> From<Rgb<_S, T>> for Alpha<Lab<Wp, T>, T> where
    T: Component + Float,
    Wp: WhitePoint,
    T: Component + Float,
    _S: RgbStandard,
    _S::Space: RgbSpace<WhitePoint = Wp>, 
[src]

impl<Wp, T, _S> From<Rgb<_S, T>> for Lch<Wp, T> where
    T: Component + Float,
    Wp: WhitePoint,
    T: Component + Float,
    _S: RgbStandard,
    _S::Space: RgbSpace<WhitePoint = Wp>, 
[src]

impl<Wp, T, _S> From<Rgb<_S, T>> for Alpha<Lch<Wp, T>, T> where
    T: Component + Float,
    Wp: WhitePoint,
    T: Component + Float,
    _S: RgbStandard,
    _S::Space: RgbSpace<WhitePoint = Wp>, 
[src]

impl<S, T, _S> From<Rgb<_S, T>> for Luma<S, T> where
    T: Component,
    S: LumaStandard,
    T: Component + Float,
    _S: RgbStandard,
    _S::Space: RgbSpace<WhitePoint = S::WhitePoint>, 
[src]

impl<S, T, _S> From<Rgb<_S, T>> for Alpha<Luma<S, T>, T> where
    T: Component,
    S: LumaStandard,
    T: Component + Float,
    _S: RgbStandard,
    _S::Space: RgbSpace<WhitePoint = S::WhitePoint>, 
[src]

impl<S: RgbStandard, T: Component, _S> From<Alpha<Rgb<_S, T>, T>> for Rgb<S, T> where
    T: Component + Float,
    _S: RgbStandard<Space = S::Space>, 
[src]

impl<S: RgbStandard, T: Component, _S> From<Alpha<Luma<_S, T>, T>> for Rgb<S, T> where
    T: Component + Float,
    _S: LumaStandard<WhitePoint = <S::Space as RgbSpace>::WhitePoint>, 
[src]

impl<S: RgbStandard, T: Component> From<Alpha<Hsl<<S as RgbStandard>::Space, T>, T>> for Rgb<S, T> where
    T: Component + Float
[src]

impl<S: RgbStandard, T: Component> From<Alpha<Hsv<<S as RgbStandard>::Space, T>, T>> for Rgb<S, T> where
    T: Component + Float
[src]

impl<S: RgbStandard, T: Component> From<Hwb<<S as RgbStandard>::Space, T>> for Rgb<S, T> where
    T: Component + Float
[src]

impl<S: RgbStandard, T: Component> From<Alpha<Hwb<<S as RgbStandard>::Space, T>, T>> for Rgb<S, T> where
    T: Component + Float
[src]

impl<S: RgbStandard, T: Component> From<Lab<<<S as RgbStandard>::Space as RgbSpace>::WhitePoint, T>> for Rgb<S, T> where
    T: Component + Float
[src]

impl<S: RgbStandard, T: Component> From<Alpha<Lab<<<S as RgbStandard>::Space as RgbSpace>::WhitePoint, T>, T>> for Rgb<S, T> where
    T: Component + Float
[src]

impl<S: RgbStandard, T: Component> From<Lch<<<S as RgbStandard>::Space as RgbSpace>::WhitePoint, T>> for Rgb<S, T> where
    T: Component + Float
[src]

impl<S: RgbStandard, T: Component> From<Alpha<Lch<<<S as RgbStandard>::Space as RgbSpace>::WhitePoint, T>, T>> for Rgb<S, T> where
    T: Component + Float
[src]

impl<S: RgbStandard, T: Component> From<Alpha<Xyz<<<S as RgbStandard>::Space as RgbSpace>::WhitePoint, T>, T>> for Rgb<S, T> where
    T: Component + Float
[src]

impl<S: RgbStandard, T: Component> From<Yxy<<<S as RgbStandard>::Space as RgbSpace>::WhitePoint, T>> for Rgb<S, T> where
    T: Component + Float
[src]

impl<S: RgbStandard, T: Component> From<Alpha<Yxy<<<S as RgbStandard>::Space as RgbSpace>::WhitePoint, T>, T>> for Rgb<S, T> where
    T: Component + Float
[src]

impl<S: RgbStandard, T: Component> From<Color<<S as RgbStandard>::Space, T>> for Rgb<S, T> where
    T: Component + Float
[src]

impl<S: RgbStandard, T: Component> From<Alpha<Color<<S as RgbStandard>::Space, T>, T>> for Rgb<S, T> where
    T: Component + Float
[src]

impl<S, Wp, T> From<Xyz<Wp, T>> for Rgb<S, T> where
    S: RgbStandard,
    T: Component + Float,
    Wp: WhitePoint,
    S::Space: RgbSpace<WhitePoint = Wp>, 
[src]

impl<S, T, Sp, Wp> From<Hsl<Sp, T>> for Rgb<S, T> where
    S: RgbStandard,
    T: Component + Float,
    Wp: WhitePoint,
    S::Space: RgbSpace<WhitePoint = Wp>,
    Sp: RgbSpace<WhitePoint = Wp>, 
[src]

impl<S, T, Sp, Wp> From<Hsv<Sp, T>> for Rgb<S, T> where
    S: RgbStandard,
    T: Component + Float,
    Wp: WhitePoint,
    S::Space: RgbSpace<WhitePoint = Wp>,
    Sp: RgbSpace<WhitePoint = Wp>, 
[src]

impl<S, T, St, Wp> From<Luma<St, T>> for Rgb<S, T> where
    S: RgbStandard,
    T: Component + Float,
    Wp: WhitePoint,
    S::Space: RgbSpace<WhitePoint = Wp>,
    St: LumaStandard<WhitePoint = Wp>, 
[src]

impl<S: RgbStandard, T: Component> From<(T, T, T)> for Rgb<S, T>[src]

impl<Wp, T, _S> From<Rgb<_S, T>> for Alpha<Xyz<Wp, T>, T> where
    T: Component + Float,
    Wp: WhitePoint,
    T: Component + Float,
    _S: RgbStandard,
    _S::Space: RgbSpace<WhitePoint = Wp>, 
[src]

impl<Wp, T, S> From<Rgb<S, T>> for Xyz<Wp, T> where
    T: Component + Float,
    Wp: WhitePoint,
    S: RgbStandard,
    S::Space: RgbSpace<WhitePoint = Wp>, 
[src]

impl<Wp, T, _S> From<Rgb<_S, T>> for Yxy<Wp, T> where
    T: Component + Float,
    Wp: WhitePoint,
    T: Component + Float,
    _S: RgbStandard,
    _S::Space: RgbSpace<WhitePoint = Wp>, 
[src]

impl<Wp, T, _S> From<Rgb<_S, T>> for Alpha<Yxy<Wp, T>, T> where
    T: Component + Float,
    Wp: WhitePoint,
    T: Component + Float,
    _S: RgbStandard,
    _S::Space: RgbSpace<WhitePoint = Wp>, 
[src]

impl<S, T> From<Rgb<Linear<S>, T>> for Color<S, T> where
    T: Float + Component,
    S: RgbSpace
[src]

impl<S: RgbStandard, T: Component> Into<(T, T, T)> for Rgb<S, T>[src]

impl<S, T, P: ?Sized> AsMut<P> for Rgb<S, T> where
    T: Component,
    S: RgbStandard,
    P: RawPixel<T>, 
[src]

fn as_mut(&mut self) -> &mut P[src]

Convert to a raw pixel format.

use palette::Srgb;

let mut rgb = Srgb::new(38, 42, 19);
{
    let raw: &mut [u8] = rgb.as_mut();
    raw[1] = 5;
}

assert_eq!(rgb.green, 5);

impl<S: Debug + RgbStandard, T: Debug + Component> Debug for Rgb<S, T>[src]

impl<S, T> Add<Rgb<S, T>> for Rgb<S, T> where
    S: RgbStandard<TransferFn = LinearFn>,
    T: Component + Add,
    <T as Add>::Output: Component
[src]

type Output = Rgb<S, <T as Add>::Output>

The resulting type after applying the + operator.

impl<S, T> Add<T> for Rgb<S, T> where
    S: RgbStandard<TransferFn = LinearFn>,
    T: Component + Add,
    <T as Add>::Output: Component
[src]

type Output = Rgb<S, <T as Add>::Output>

The resulting type after applying the + operator.

impl<S, T> Sub<Rgb<S, T>> for Rgb<S, T> where
    S: RgbStandard<TransferFn = LinearFn>,
    T: Component + Sub,
    <T as Sub>::Output: Component
[src]

type Output = Rgb<S, <T as Sub>::Output>

The resulting type after applying the - operator.

impl<S, T> Sub<T> for Rgb<S, T> where
    S: RgbStandard<TransferFn = LinearFn>,
    T: Component + Sub,
    <T as Sub>::Output: Component
[src]

type Output = Rgb<S, <T as Sub>::Output>

The resulting type after applying the - operator.

impl<S, T> Mul<Rgb<S, T>> for Rgb<S, T> where
    S: RgbStandard<TransferFn = LinearFn>,
    T: Component + Mul,
    <T as Mul>::Output: Component
[src]

type Output = Rgb<S, <T as Mul>::Output>

The resulting type after applying the * operator.

impl<S, T> Mul<T> for Rgb<S, T> where
    S: RgbStandard<TransferFn = LinearFn>,
    T: Component + Mul,
    <T as Mul>::Output: Component
[src]

type Output = Rgb<S, <T as Mul>::Output>

The resulting type after applying the * operator.

impl<S, T> Div<Rgb<S, T>> for Rgb<S, T> where
    S: RgbStandard<TransferFn = LinearFn>,
    T: Component + Div,
    <T as Div>::Output: Component
[src]

type Output = Rgb<S, <T as Div>::Output>

The resulting type after applying the / operator.

impl<S, T> Div<T> for Rgb<S, T> where
    S: RgbStandard<TransferFn = LinearFn>,
    T: Component + Div,
    <T as Div>::Output: Component
[src]

type Output = Rgb<S, <T as Div>::Output>

The resulting type after applying the / operator.

impl<S, T> LowerHex for Rgb<S, T> where
    T: Component + LowerHex,
    S: RgbStandard
[src]

impl<S, T> UpperHex for Rgb<S, T> where
    T: Component + UpperHex,
    S: RgbStandard
[src]

impl<S, T> ApproxEq for Rgb<S, T> where
    T: Component + ApproxEq,
    T::Epsilon: Copy,
    S: RgbStandard
[src]

type Epsilon = <T as ApproxEq>::Epsilon

Used for specifying relative comparisons.

fn relative_ne(
    &self,
    other: &Self,
    epsilon: Self::Epsilon,
    max_relative: Self::Epsilon
) -> bool
[src]

The inverse of ApproxEq::relative_eq.

fn ulps_ne(&self, other: &Self, epsilon: Self::Epsilon, max_ulps: u32) -> bool[src]

The inverse of ApproxEq::ulps_eq.

impl<S: RgbStandard, T: Component> Serialize for Rgb<S, T> where
    T: Serialize
[src]

impl<'de, S: RgbStandard, T: Component> Deserialize<'de> for Rgb<S, T> where
    T: Deserialize<'de>, 
[src]

Auto Trait Implementations

impl<S, T> Unpin for Rgb<S, T> where
    S: Unpin,
    T: Unpin

impl<S, T> Sync for Rgb<S, T> where
    S: Sync,
    T: Sync

impl<S, T> Send for Rgb<S, T> where
    S: Send,
    T: Send

impl<S, T> UnwindSafe for Rgb<S, T> where
    S: UnwindSafe,
    T: UnwindSafe

impl<S, T> RefUnwindSafe for Rgb<S, T> where
    S: RefUnwindSafe,
    T: RefUnwindSafe

Blanket Implementations

impl<S, D, Swp, Dwp, T> AdaptFrom<S, Swp, Dwp, T> for D where
    D: FromColor<Dwp, T>,
    Dwp: WhitePoint,
    S: IntoColor<Swp, T>,
    Swp: WhitePoint,
    T: Component + Float
[src]

fn adapt_from(color: S) -> Self[src]

Convert the source color to the destination color using the bradford method by default Read more

impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S where
    D: AdaptFrom<S, Swp, Dwp, T>,
    Dwp: WhitePoint,
    Swp: WhitePoint,
    T: Component + Float
[src]

fn adapt_into(self) -> D[src]

Convert the source color to the destination color using the bradford method by default Read more

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

type Owned = T

The resulting type after obtaining ownership.

impl<T> From<T> for T[src]

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

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.

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

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

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

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]