Struct palette::rgb::Rgb

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

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.

§Creating a Value

RGB comes in different shapes and formats. You will probably want to start with either the Srgb or Srgba alias, which represents the common sRGB format that most images and tools use. Then, depending on your input, you can either just call new or convert from another data format.

use palette::Srgb;

let rgb_u8 = Srgb::new(171u8, 193, 35);
let rgb_f32 = Srgb::new(0.3f32, 0.8, 0.1);

// `new` is also `const`:
const RGB_U8: Srgb<u8> = Srgb::new(171, 193, 35);

// Converting from one number format to another can be as simple as this:
let rgb_u8_from_f32_1: Srgb<u8> = Srgb::new(0.3f32, 0.8, 0.1).into();

// ...or more explicitly like this:
let rgb_u8_from_f32_2 = Srgb::new(0.3f32, 0.8, 0.1).into_format::<u8>();

// Hexadecimal is also supported, with or without the #:
let rgb_from_hex1: Srgb<u8> = "#f034e6".parse().unwrap();
let rgb_from_hex2: Srgb<u8> = "f034e6".parse().unwrap();
assert_eq!(rgb_from_hex1, rgb_from_hex2);

// This includes the shorthand format:
let rgb_from_short_hex: Srgb<u8> = "f3e".parse().unwrap();
let rgb_from_long_hex: Srgb<u8> = "ff33ee".parse().unwrap();
assert_eq!(rgb_from_short_hex, rgb_from_long_hex);

// It's also possible to convert from (and to) arrays, tuples and `u32` values:
let rgb_from_array = Srgb::from([171u8, 193, 35]);
let rgb_from_tuple = Srgb::from((171u8, 193, 35));
let rgb_from_u32 = Srgb::from(0x607F00);

§Linear, sRGB and Gamma Correction

Many conversions and operations on RGB require that it’s linear, meaning that gamma correction is required when converting to and from displayable RGB, such as sRGB. It’s common to store and send RGB values where the numbers are on a non-linear scale. In a non-linear format, a value of, for example, 0.5 would not represent a light intensity of 50%, which makes some operations (such as blurring) give incorrect results.

You will probably encounter or use LinSrgb or LinSrgba at some point. These are aliases for linear sRGB and would usually be obtained by converting an Srgb value with into_linear.

use palette::{LinSrgb, Srgb};

// This function uses linear sRGB for something. But how do we interface with it?
fn uses_linear_srgb(input: LinSrgb<f32>) -> LinSrgb<f32> { todo!() }

// Linear sRGB will usually be created from non-linear sRGB:
let output = uses_linear_srgb(Srgb::new(0.3, 0.8, 0.1).into_linear());

// It's also possible to convert directly from u8 to f32 for sRGB.
// This is much faster than using `into_format` first:
let output = uses_linear_srgb(Srgb::new(171u8, 193, 35).into_linear());

// Converting the output back to `Srgb<u8>` (or `Srgb<f32>`) is just as simple:
let output_u8 = Srgb::<u8>::from_linear(output);
// ..or:
let output_u8: Srgb<u8> = output.into_encoding();

It’s of course also possible to create a linear value from constants, but it’s not necessarily as intuitive. It’s best to avoid storing them as LinSrgb<u8> (or LinRgb<_, u8>) values, to avoid banding among dark colors.

See the encoding module for built-in encoding formats.

§Storage Formats and Pixel Buffers

It’s common to read and write RGB values as bytes, hexadecimal strings, or sometimes u32 values. A single RGB value can be converted to all of these formats and more.

use palette::{Srgb, LinSrgb};

let source: LinSrgb<f32> = todo!();

let u8_array: [u8; 3] = Srgb::from_linear(source).into();
let hex_string1 = format!("#{:x}", Srgb::<u8>::from_linear(source)); // The # is optional.
let u32_value: u32 = Srgb::from_linear(source).into();

It’s also possible to control the component order. PackedArgb is one of a few aliases for Packed, which represents a color that has been “packed” into a specific data format. This can be a u32 or [u8; 4], for example. This is helpful for reading and writing colors with a different order than the default RGBA.

use palette::{rgb::PackedArgb, Srgba, LinSrgba};

let source: LinSrgba<f32> = todo!();

let u8_array: [u8; 4] = PackedArgb::from(Srgba::from_linear(source)).into();
let u32_value: u32 = PackedArgb::from(Srgba::from_linear(source)).into();

If you need to work with colors in a byte buffer, such as [u8], Vec<u8> or the image crate, there’s a quick way to borrow that buffer as a slice of RGB(A) colors. The cast module has a number of traits and functions for casting values without copying them.

use image::RgbImage;
use palette::{cast::ComponentsAsMut, Srgb};

let mut image: RgbImage = todo!();
let pixels: &mut [Srgb<u8>] = image.components_as_mut();

for pixel in pixels {
    std::mem::swap(&mut pixel.red, &mut pixel.blue);
}

Fields§

§red: T

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

§green: T

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

§blue: T

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

§standard: PhantomData<S>

The kind of RGB standard. sRGB is the default.

Implementations§

source§

impl<S, T> Rgb<S, T>

source

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

Create an RGB color.

It’s possible to create a color in one number format and convert it to another format with either into_format or into_linear.

use palette::{Srgb, LinSrgb};

// Changes only the number format:
let rgb_f32: Srgb<f32> =  Srgb::new(171u8, 193, 35).into_format();

// Changes the number format and converts to linear in one go.
// This is faster than `.into_format().into_linear()`:
let linear: LinSrgb<f32> = Srgb::new(171u8, 193, 35).into_linear();
source

pub fn into_format<U>(self) -> Rgb<S, U>
where U: FromStimulus<T>,

Convert the RGB components into another number type.

use palette::Srgb;

let rgb_u8: Srgb<u8> = Srgb::new(0.3, 0.7, 0.2).into_format();

See also into_linear and into_encoding for a faster option if you need to change between linear and non-linear encoding at the same time.

source

pub fn from_format<U>(color: Rgb<S, U>) -> Self
where T: FromStimulus<U>,

Convert the RGB components from another number type.

use palette::Srgb;

let rgb_u8 = Srgb::<u8>::from_format(Srgb::new(0.3, 0.7, 0.2));

See also from_linear and from_encoding for a faster option if you need to change between linear and non-linear encoding at the same time.

source

pub fn into_components(self) -> (T, T, T)

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

source

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

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

source§

impl<S, T> Rgb<S, T>
where T: Stimulus,

source

pub fn min_red() -> T

Return the red value minimum.

source

pub fn max_red() -> T

Return the red value maximum.

source

pub fn min_green() -> T

Return the green value minimum.

source

pub fn max_green() -> T

Return the green value maximum.

source

pub fn min_blue() -> T

Return the blue value minimum.

source

pub fn max_blue() -> T

Return the blue value maximum.

source§

impl<S> Rgb<S, u8>

source

pub fn into_u32<O>(self) -> u32
where O: ComponentOrder<Rgba<S, u8>, u32>,

Convert to a packed u32 with with specifiable component order.

use palette::{rgb, Srgb};

let integer = Srgb::new(96u8, 127, 0).into_u32::<rgb::channels::Rgba>();
assert_eq!(0x607F00FF, integer);

It’s also possible to use From and Into, which defaults to the 0xAARRGGBB component order:

use palette::Srgb;

let integer = u32::from(Srgb::new(96u8, 127, 0));
assert_eq!(0xFF607F00, integer);

See Packed for more details.

source

pub fn from_u32<O>(color: u32) -> Self
where O: ComponentOrder<Rgba<S, u8>, u32>,

Convert from a packed u32 with specifiable component order.

use palette::{rgb, Srgb};

let rgb = Srgb::from_u32::<rgb::channels::Rgba>(0x607F00FF);
assert_eq!(Srgb::new(96u8, 127, 0), rgb);

It’s also possible to use From and Into, which defaults to the 0xAARRGGBB component order:

use palette::Srgb;

let rgb = Srgb::from(0x607F00);
assert_eq!(Srgb::new(96u8, 127, 0), rgb);

See Packed for more details.

source§

impl<S: RgbStandard, T> Rgb<S, T>

source

pub fn into_linear<U>(self) -> Rgb<Linear<S::Space>, U>
where S::TransferFn: IntoLinear<U, T>,

Convert the color to linear RGB.

Some transfer functions allow the component type to be converted at the same time. This is usually offered with increased performance, compared to using into_format.

use palette::{Srgb, LinSrgb};

let linear: LinSrgb<f32> = Srgb::new(96u8, 127, 0).into_linear();

See the transfer function types in the encoding module for details and performance characteristics.

source

pub fn from_linear<U>(color: Rgb<Linear<S::Space>, U>) -> Self
where S::TransferFn: FromLinear<U, T>,

Convert linear RGB to non-linear RGB.

Some transfer functions allow the component type to be converted at the same time. This is usually offered with increased performance, compared to using into_format.

use palette::{Srgb, LinSrgb};

let encoded = Srgb::<u8>::from_linear(LinSrgb::new(0.95f32, 0.90, 0.30));

See the transfer function types in the encoding module for details and performance characteristics.

source§

impl<S: RgbSpace, T> Rgb<Linear<S>, T>

source

pub fn into_encoding<U, St>(self) -> Rgb<St, U>
where St: RgbStandard<Space = S>, St::TransferFn: FromLinear<T, U>,

Convert a linear color to a different encoding.

Some transfer functions allow the component type to be converted at the same time. This is usually offered with increased performance, compared to using into_format.

use palette::{Srgb, LinSrgb};

let encoded: Srgb<u8> = LinSrgb::new(0.95f32, 0.90, 0.30).into_encoding();

See the transfer function types in the encoding module for details and performance characteristics.

source

pub fn from_encoding<U, St>(color: Rgb<St, U>) -> Self
where St: RgbStandard<Space = S>, St::TransferFn: IntoLinear<T, U>,

Convert linear RGB from a different encoding.

Some transfer functions allow the component type to be converted at the same time. This is usually offered with increased performance, compared to using into_format.

use palette::{Srgb, LinSrgb};

let linear = LinSrgb::<f32>::from_encoding(Srgb::new(96u8, 127, 0));

See the transfer function types in the encoding module for details and performance characteristics.

source§

impl<S, T> Rgb<S, &T>

source

pub fn copied(&self) -> Rgb<S, T>
where T: Copy,

Get an owned, copied version of this color.

source

pub fn cloned(&self) -> Rgb<S, T>
where T: Clone,

Get an owned, cloned version of this color.

source§

impl<S, T> Rgb<S, &mut T>

source

pub fn set(&mut self, value: Rgb<S, T>)

Update this color with new values.

source

pub fn as_refs(&self) -> Rgb<S, &T>

Borrow this color’s components as shared references.

source

pub fn copied(&self) -> Rgb<S, T>
where T: Copy,

Get an owned, copied version of this color.

source

pub fn cloned(&self) -> Rgb<S, T>
where T: Clone,

Get an owned, cloned version of this color.

source§

impl<S, C> Rgb<S, C>

source

pub fn iter<'a>(&'a self) -> <&'a Self as IntoIterator>::IntoIter

Return an iterator over the colors in the wrapped collections.

source

pub fn iter_mut<'a>(&'a mut self) -> <&'a mut Self as IntoIterator>::IntoIter

Return an iterator that allows modifying the colors in the wrapped collections.

source

pub fn get<'a, I, T>( &'a self, index: I ) -> Option<Rgb<S, &<I as SliceIndex<[T]>>::Output>>
where T: 'a, C: AsRef<[T]>, I: SliceIndex<[T]> + Clone,

Get a color, or slice of colors, with references to the components at index. See slice::get for details.

source

pub fn get_mut<'a, I, T>( &'a mut self, index: I ) -> Option<Rgb<S, &mut <I as SliceIndex<[T]>>::Output>>
where T: 'a, C: AsMut<[T]>, I: SliceIndex<[T]> + Clone,

Get a color, or slice of colors, that allows modifying the components at index. See slice::get_mut for details.

source§

impl<S, T> Rgb<S, Vec<T>>

source

pub fn with_capacity(capacity: usize) -> Self

Create a struct of vectors with a minimum capacity. See Vec::with_capacity for details.

source

pub fn push(&mut self, value: Rgb<S, T>)

Push an additional color’s components onto the component vectors. See Vec::push for details.

source

pub fn pop(&mut self) -> Option<Rgb<S, T>>

Pop a color’s components from the component vectors. See Vec::pop for details.

source

pub fn clear(&mut self)

Clear the component vectors. See Vec::clear for details.

source

pub fn drain<R>(&mut self, range: R) -> Iter<Drain<'_, T>, S>
where R: RangeBounds<usize> + Clone,

Return an iterator that moves colors out of the specified range.

Trait Implementations§

source§

impl<S, T> AbsDiffEq for Rgb<S, T>
where T: AbsDiffEq, T::Epsilon: Clone,

§

type Epsilon = <T as AbsDiffEq>::Epsilon

Used for specifying relative comparisons.
source§

fn default_epsilon() -> Self::Epsilon

The default tolerance to use when testing values that are close together. Read more
source§

fn abs_diff_eq(&self, other: &Self, epsilon: T::Epsilon) -> bool

A test for equality that uses the absolute difference to compute the approximate equality of two numbers.
source§

fn abs_diff_ne(&self, other: &Self, epsilon: T::Epsilon) -> bool

The inverse of AbsDiffEq::abs_diff_eq.
source§

impl<S, T> Add<T> for Rgb<S, T>
where T: Add<Output = T> + Clone,

§

type Output = Rgb<S, T>

The resulting type after applying the + operator.
source§

fn add(self, c: T) -> Self::Output

Performs the + operation. Read more
source§

impl<S, T> Add for Rgb<S, T>
where T: Add<Output = T>,

§

type Output = Rgb<S, T>

The resulting type after applying the + operator.
source§

fn add(self, other: Self) -> Self::Output

Performs the + operation. Read more
source§

impl<S, T> AddAssign<T> for Rgb<S, T>
where T: AddAssign + Clone,

source§

fn add_assign(&mut self, c: T)

Performs the += operation. Read more
source§

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

source§

fn add_assign(&mut self, other: Self)

Performs the += operation. Read more
source§

impl<S, T> ArrayCast for Rgb<S, T>

§

type Array = [T; 3]

The output type of a cast to an array.
source§

impl<S, T> AsMut<[T]> for Rgb<S, T>

source§

fn as_mut(&mut self) -> &mut [T]

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl<S, T> AsMut<[T; 3]> for Rgb<S, T>

source§

fn as_mut(&mut self) -> &mut [T; 3]

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl<S, T> AsMut<Rgb<S, T>> for [T; 3]

source§

fn as_mut(&mut self) -> &mut Rgb<S, T>

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl<S, T> AsRef<[T]> for Rgb<S, T>

source§

fn as_ref(&self) -> &[T]

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<S, T> AsRef<[T; 3]> for Rgb<S, T>

source§

fn as_ref(&self) -> &[T; 3]

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<S, T> AsRef<Rgb<S, T>> for [T; 3]

source§

fn as_ref(&self) -> &Rgb<S, T>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<S, T> Clamp for Rgb<S, T>
where T: Clamp + Stimulus,

source§

fn clamp(self) -> Self

Return a new color where out-of-bounds components have been changed to the nearest valid values. Read more
source§

impl<S, T> ClampAssign for Rgb<S, T>
where T: ClampAssign + Stimulus,

source§

fn clamp_assign(&mut self)

Changes out-of-bounds components to the nearest valid values. Read more
source§

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

source§

fn clone(&self) -> Rgb<S, T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<S: Debug, T: Debug> Debug for Rgb<S, T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<S, T> Default for Rgb<S, T>
where T: Stimulus,

source§

fn default() -> Rgb<S, T>

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

impl<'de, S, T> Deserialize<'de> for Rgb<S, T>
where T: Deserialize<'de>,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<S, T> Distribution<Rgb<S, T>> for Standard

source§

fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Rgb<S, T>

Generate a random value of T, using rng as the source of randomness.
source§

fn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T>
where R: Rng, Self: Sized,

Create an iterator that generates random values of T, using rng as the source of randomness. Read more
source§

fn map<F, S>(self, func: F) -> DistMap<Self, F, T, S>
where F: Fn(T) -> S, Self: Sized,

Create a distribution of values of ‘S’ by mapping the output of Self through the closure F Read more
source§

impl<S, T> Div<T> for Rgb<S, T>
where T: Div<Output = T> + Clone,

§

type Output = Rgb<S, T>

The resulting type after applying the / operator.
source§

fn div(self, c: T) -> Self::Output

Performs the / operation. Read more
source§

impl<S, T> Div for Rgb<S, T>
where T: Div<Output = T>,

§

type Output = Rgb<S, T>

The resulting type after applying the / operator.
source§

fn div(self, other: Self) -> Self::Output

Performs the / operation. Read more
source§

impl<S, T> DivAssign<T> for Rgb<S, T>
where T: DivAssign + Clone,

source§

fn div_assign(&mut self, c: T)

Performs the /= operation. Read more
source§

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

source§

fn div_assign(&mut self, other: Self)

Performs the /= operation. Read more
source§

impl<S, T> EuclideanDistance for Rgb<S, T>
where T: Real + Sub<T, Output = T> + Add<T, Output = T> + Mul<T, Output = T> + Clone,

§

type Scalar = T

The type for the distance value.
source§

fn distance_squared(self, other: Self) -> Self::Scalar

Calculate the squared Euclidean distance from self to other. Read more
source§

impl<S, T, C> Extend<Rgb<S, T>> for Rgb<S, C>
where C: Extend<T>,

source§

fn extend<I: IntoIterator<Item = Rgb<S, T>>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<'a, S, T> From<&'a [T; 3]> for &'a Rgb<S, T>

source§

fn from(array: &'a [T; 3]) -> Self

Converts to this type from the input type.
source§

impl<'a, S, T> From<&'a Rgb<S, T>> for &'a [T]

source§

fn from(color: &'a Rgb<S, T>) -> Self

Converts to this type from the input type.
source§

impl<'a, S, T> From<&'a Rgb<S, T>> for &'a [T; 3]

source§

fn from(color: &'a Rgb<S, T>) -> Self

Converts to this type from the input type.
source§

impl<'a, S, T> From<&'a mut [T; 3]> for &'a mut Rgb<S, T>

source§

fn from(array: &'a mut [T; 3]) -> Self

Converts to this type from the input type.
source§

impl<'a, S, T> From<&'a mut Rgb<S, T>> for &'a mut [T]

source§

fn from(color: &'a mut Rgb<S, T>) -> Self

Converts to this type from the input type.
source§

impl<'a, S, T> From<&'a mut Rgb<S, T>> for &'a mut [T; 3]

source§

fn from(color: &'a mut Rgb<S, T>) -> Self

Converts to this type from the input type.
source§

impl<S, T, V, const N: usize> From<[Rgb<S, T>; N]> for Rgb<S, V>
where [T; N]: Default, V: FromScalarArray<N, Scalar = T>,

source§

fn from(colors: [Rgb<S, T>; N]) -> Self

Converts to this type from the input type.
source§

impl<S, T> From<[T; 3]> for Rgb<S, T>

source§

fn from(array: [T; 3]) -> Self

Converts to this type from the input type.
source§

impl<S, T> From<(T, T, T)> for Rgb<S, T>

source§

fn from(components: (T, T, T)) -> Self

Converts to this type from the input type.
source§

impl<S, T> From<Box<[T; 3]>> for Box<Rgb<S, T>>

source§

fn from(array: Box<[T; 3]>) -> Self

Converts to this type from the input type.
source§

impl<S, O, P> From<Packed<O, P>> for Rgb<S, u8>
where O: ComponentOrder<Rgba<S, u8>, P>,

source§

fn from(packed: Packed<O, P>) -> Self

Converts to this type from the input type.
source§

impl<S, T> From<PreAlpha<Rgb<S, T>>> for Rgb<S, T>
where Self: Premultiply<Scalar = T>,

source§

fn from(premultiplied: PreAlpha<Self>) -> Self

Converts to this type from the input type.
source§

impl<T, U> From<Rgb<Linear<Srgb>, T>> for Srgba<U>
where U: Stimulus, Srgb: RgbStandard<Space = Srgb> + FromLinear<T, U>,

source§

fn from(lin_srgb: LinSrgb<T>) -> Self

Converts to this type from the input type.
source§

impl<T, U> From<Rgb<Linear<Srgb>, T>> for Srgb<U>
where Srgb: RgbStandard<Space = Srgb> + FromLinear<T, U>,

source§

fn from(lin_srgb: LinSrgb<T>) -> Self

Converts to this type from the input type.
source§

impl<S> From<Rgb<S>> for Rgb<S, f64>

source§

fn from(color: Rgb<S, f32>) -> Self

Converts to this type from the input type.
source§

impl<S> From<Rgb<S>> for Rgb<S, u8>

source§

fn from(color: Rgb<S, f32>) -> Self

Converts to this type from the input type.
source§

impl<S, T> From<Rgb<S, T>> for [T; 3]

source§

fn from(color: Rgb<S, T>) -> Self

Converts to this type from the input type.
source§

impl<S, T> From<Rgb<S, T>> for (T, T, T)

source§

fn from(color: Rgb<S, T>) -> (T, T, T)

Converts to this type from the input type.
source§

impl<S, T, P, O> From<Rgb<S, T>> for Packed<O, P>
where O: ComponentOrder<Rgba<S, T>, P>, Rgba<S, T>: From<Rgb<S, T>>,

source§

fn from(color: Rgb<S, T>) -> Self

Converts to this type from the input type.
source§

impl<S, T, V, const N: usize> From<Rgb<S, V>> for [Rgb<S, T>; N]
where Self: Default, V: IntoScalarArray<N, Scalar = T>,

source§

fn from(color: Rgb<S, V>) -> Self

Converts to this type from the input type.
source§

impl<S> From<Rgb<S, f64>> for Rgb<S, f32>

source§

fn from(color: Rgb<S, f64>) -> Self

Converts to this type from the input type.
source§

impl<S> From<Rgb<S, f64>> for Rgb<S, u8>

source§

fn from(color: Rgb<S, f64>) -> Self

Converts to this type from the input type.
source§

impl<S> From<Rgb<S, u8>> for Rgb<S, f32>

source§

fn from(color: Rgb<S, u8>) -> Self

Converts to this type from the input type.
source§

impl<S> From<Rgb<S, u8>> for Rgb<S, f64>

source§

fn from(color: Rgb<S, u8>) -> Self

Converts to this type from the input type.
source§

impl<S> From<Rgb<S, u8>> for u32

source§

fn from(color: Rgb<S, u8>) -> Self

Converts to this type from the input type.
source§

impl<T, U> From<Rgb<Srgb, T>> for LinSrgba<U>
where U: Stimulus, Srgb: RgbStandard<Space = Srgb> + IntoLinear<U, T>,

source§

fn from(srgb: Srgb<T>) -> Self

Converts to this type from the input type.
source§

impl<T, U> From<Rgb<Srgb, T>> for LinSrgb<U>
where Srgb: RgbStandard<Space = Srgb> + IntoLinear<U, T>,

source§

fn from(srgb: Srgb<T>) -> Self

Converts to this type from the input type.
source§

impl<S> From<u32> for Rgb<S, u8>

source§

fn from(color: u32) -> Self

Converts to this type from the input type.
source§

impl<S, T, _C, _A> FromColorUnclamped<Alpha<_C, _A>> for Rgb<S, T>
where _C: IntoColorUnclamped<Self>,

source§

fn from_color_unclamped(color: Alpha<_C, _A>) -> Self

Convert from T. The resulting color might be invalid in its color space. Read more
source§

impl<S, T> FromColorUnclamped<Hsl<S, T>> for Rgb<S, T>

source§

fn from_color_unclamped(hsl: Hsl<S, T>) -> Self

Convert from T. The resulting color might be invalid in its color space. Read more
source§

impl<S, T> FromColorUnclamped<Hsluv<<<S as RgbStandard>::Space as RgbSpace>::WhitePoint, T>> for Rgb<S, T>

source§

fn from_color_unclamped( color: Hsluv<<<S as RgbStandard>::Space as RgbSpace>::WhitePoint, T> ) -> Self

Convert from T. The resulting color might be invalid in its color space. Read more
source§

impl<S, T> FromColorUnclamped<Hsv<S, T>> for Rgb<S, T>

source§

fn from_color_unclamped(hsv: Hsv<S, T>) -> Self

Convert from T. The resulting color might be invalid in its color space. Read more
source§

impl<S, T> FromColorUnclamped<Hwb<S, T>> for Rgb<S, T>
where Hsv<S, T>: FromColorUnclamped<Hwb<S, T>> + IntoColorUnclamped<Self>,

source§

fn from_color_unclamped(color: Hwb<S, T>) -> Self

Convert from T. The resulting color might be invalid in its color space. Read more
source§

impl<S, T> FromColorUnclamped<Lab<<<S as RgbStandard>::Space as RgbSpace>::WhitePoint, T>> for Rgb<S, T>

source§

fn from_color_unclamped( color: Lab<<<S as RgbStandard>::Space as RgbSpace>::WhitePoint, T> ) -> Self

Convert from T. The resulting color might be invalid in its color space. Read more
source§

impl<S, T> FromColorUnclamped<Lch<<<S as RgbStandard>::Space as RgbSpace>::WhitePoint, T>> for Rgb<S, T>

source§

fn from_color_unclamped( color: Lch<<<S as RgbStandard>::Space as RgbSpace>::WhitePoint, T> ) -> Self

Convert from T. The resulting color might be invalid in its color space. Read more
source§

impl<S, T> FromColorUnclamped<Lchuv<<<S as RgbStandard>::Space as RgbSpace>::WhitePoint, T>> for Rgb<S, T>

source§

fn from_color_unclamped( color: Lchuv<<<S as RgbStandard>::Space as RgbSpace>::WhitePoint, T> ) -> Self

Convert from T. The resulting color might be invalid in its color space. Read more
source§

impl<S, St, T> FromColorUnclamped<Luma<St, T>> for Rgb<S, T>
where S: RgbStandard + 'static, St: LumaStandard<WhitePoint = <S::Space as RgbSpace>::WhitePoint> + 'static, S::TransferFn: FromLinear<T, T>, St::TransferFn: IntoLinear<T, T>, T: Clone,

source§

fn from_color_unclamped(color: Luma<St, T>) -> Self

Convert from T. The resulting color might be invalid in its color space. Read more
source§

impl<S, T> FromColorUnclamped<Luv<<<S as RgbStandard>::Space as RgbSpace>::WhitePoint, T>> for Rgb<S, T>

source§

fn from_color_unclamped( color: Luv<<<S as RgbStandard>::Space as RgbSpace>::WhitePoint, T> ) -> Self

Convert from T. The resulting color might be invalid in its color space. Read more
source§

impl<S, T> FromColorUnclamped<Okhsl<T>> for Rgb<S, T>

source§

fn from_color_unclamped(color: Okhsl<T>) -> Self

Convert from T. The resulting color might be invalid in its color space. Read more
source§

impl<S, T> FromColorUnclamped<Okhsv<T>> for Rgb<S, T>

source§

fn from_color_unclamped(color: Okhsv<T>) -> Self

Convert from T. The resulting color might be invalid in its color space. Read more
source§

impl<S, T> FromColorUnclamped<Okhwb<T>> for Rgb<S, T>

source§

fn from_color_unclamped(color: Okhwb<T>) -> Self

Convert from T. The resulting color might be invalid in its color space. Read more
source§

impl<S, T> FromColorUnclamped<Oklab<T>> for Rgb<S, T>
where T: Real + Arithmetics + Copy, S: RgbStandard, S::TransferFn: FromLinear<T, T>, S::Space: RgbSpace<WhitePoint = D65> + 'static, Rgb<Linear<Srgb>, T>: IntoColorUnclamped<Self>, Xyz<D65, T>: FromColorUnclamped<Oklab<T>> + IntoColorUnclamped<Self>,

source§

fn from_color_unclamped(oklab: Oklab<T>) -> Self

Convert from T. The resulting color might be invalid in its color space. Read more
source§

impl<S, T> FromColorUnclamped<Oklch<T>> for Rgb<S, T>

source§

fn from_color_unclamped(color: Oklch<T>) -> Self

Convert from T. The resulting color might be invalid in its color space. Read more
source§

impl<S, T> FromColorUnclamped<Rgb<S, T>> for Hsl<S, T>
where T: RealAngle + Zero + One + MinMax + Arithmetics + PartialCmp + Clone, T::Mask: BoolMask + BitOps + LazySelect<T> + Clone + 'static,

source§

fn from_color_unclamped(rgb: Rgb<S, T>) -> Self

Convert from T. The resulting color might be invalid in its color space. Read more
source§

impl<S, T> FromColorUnclamped<Rgb<S, T>> for Hsv<S, T>
where T: RealAngle + One + Zero + MinMax + Arithmetics + PartialCmp + Clone, T::Mask: BoolMask + BitOps + LazySelect<T> + Clone + 'static,

source§

fn from_color_unclamped(rgb: Rgb<S, T>) -> Self

Convert from T. The resulting color might be invalid in its color space. Read more
source§

impl<S, T> FromColorUnclamped<Rgb<S, T>> for Hwb<S, T>
where Hsv<S, T>: FromColorUnclamped<Rgb<S, T>> + IntoColorUnclamped<Self>,

source§

fn from_color_unclamped(color: Rgb<S, T>) -> Self

Convert from T. The resulting color might be invalid in its color space. Read more
source§

impl<S, T> FromColorUnclamped<Rgb<S, T>> for Oklab<T>
where T: Real + Cbrt + Arithmetics + Copy, S: RgbStandard, S::TransferFn: IntoLinear<T, T>, S::Space: RgbSpace<WhitePoint = D65> + 'static, Xyz<D65, T>: FromColorUnclamped<Rgb<S, T>>,

source§

fn from_color_unclamped(rgb: Rgb<S, T>) -> Self

Convert from T. The resulting color might be invalid in its color space. Read more
source§

impl<Wp, T, S> FromColorUnclamped<Rgb<S, T>> for Xyz<Wp, T>
where T: Arithmetics + FromScalar, T::Scalar: Real + Recip + IsValidDivisor<Mask = bool> + Arithmetics + FromScalar<Scalar = T::Scalar> + Clone, Wp: WhitePoint<T::Scalar>, S: RgbStandard, S::TransferFn: IntoLinear<T, T>, S::Space: RgbSpace<WhitePoint = Wp>, <S::Space as RgbSpace>::Primaries: Primaries<T::Scalar>, Yxy<Any, T::Scalar>: IntoColorUnclamped<Xyz<Any, T::Scalar>>,

source§

fn from_color_unclamped(color: Rgb<S, T>) -> Self

Convert from T. The resulting color might be invalid in its color space. Read more
source§

impl<S1, S2, T> FromColorUnclamped<Rgb<S2, T>> for Rgb<S1, T>
where S1: RgbStandard + 'static, S2: RgbStandard + 'static, S1::TransferFn: FromLinear<T, T>, S2::TransferFn: IntoLinear<T, T>, S2::Space: RgbSpace<WhitePoint = <S1::Space as RgbSpace>::WhitePoint>, Xyz<<S2::Space as RgbSpace>::WhitePoint, T>: FromColorUnclamped<Rgb<S2, T>>, Rgb<S1, T>: FromColorUnclamped<Xyz<<S1::Space as RgbSpace>::WhitePoint, T>>,

source§

fn from_color_unclamped(rgb: Rgb<S2, T>) -> Self

Convert from T. The resulting color might be invalid in its color space. Read more
source§

impl<Wp, T, _S> FromColorUnclamped<Rgb<_S, T>> for Hsluv<Wp, T>
where _S: RgbStandard, _S::Space: RgbSpace<WhitePoint = Wp>, Wp: WhitePoint<T>, Lchuv<Wp, T>: FromColorUnclamped<Rgb<_S, T>> + IntoColorUnclamped<Self>,

source§

fn from_color_unclamped(color: Rgb<_S, T>) -> Self

Convert from T. The resulting color might be invalid in its color space. Read more
source§

impl<Wp, T, _S> FromColorUnclamped<Rgb<_S, T>> for Lab<Wp, T>
where _S: RgbStandard, _S::Space: RgbSpace<WhitePoint = Wp>, Wp: WhitePoint<T>, Xyz<Wp, T>: FromColorUnclamped<Rgb<_S, T>> + IntoColorUnclamped<Self>,

source§

fn from_color_unclamped(color: Rgb<_S, T>) -> Self

Convert from T. The resulting color might be invalid in its color space. Read more
source§

impl<Wp, T, _S> FromColorUnclamped<Rgb<_S, T>> for Lch<Wp, T>
where _S: RgbStandard, _S::Space: RgbSpace<WhitePoint = Wp>, Wp: WhitePoint<T>, Lab<Wp, T>: FromColorUnclamped<Rgb<_S, T>> + IntoColorUnclamped<Self>,

source§

fn from_color_unclamped(color: Rgb<_S, T>) -> Self

Convert from T. The resulting color might be invalid in its color space. Read more
source§

impl<Wp, T, _S> FromColorUnclamped<Rgb<_S, T>> for Lchuv<Wp, T>
where _S: RgbStandard, _S::Space: RgbSpace<WhitePoint = Wp>, Wp: WhitePoint<T>, Luv<Wp, T>: FromColorUnclamped<Rgb<_S, T>> + IntoColorUnclamped<Self>,

source§

fn from_color_unclamped(color: Rgb<_S, T>) -> Self

Convert from T. The resulting color might be invalid in its color space. Read more
source§

impl<S, T, _S> FromColorUnclamped<Rgb<_S, T>> for Luma<S, T>
where _S: RgbStandard, _S::Space: RgbSpace<WhitePoint = <S as LumaStandard>::WhitePoint>, S: LumaStandard, Xyz<<S as LumaStandard>::WhitePoint, T>: FromColorUnclamped<Rgb<_S, T>> + IntoColorUnclamped<Self>,

source§

fn from_color_unclamped(color: Rgb<_S, T>) -> Self

Convert from T. The resulting color might be invalid in its color space. Read more
source§

impl<Wp, T, _S> FromColorUnclamped<Rgb<_S, T>> for Luv<Wp, T>
where _S: RgbStandard, _S::Space: RgbSpace<WhitePoint = Wp>, Wp: WhitePoint<T>, Xyz<Wp, T>: FromColorUnclamped<Rgb<_S, T>> + IntoColorUnclamped<Self>,

source§

fn from_color_unclamped(color: Rgb<_S, T>) -> Self

Convert from T. The resulting color might be invalid in its color space. Read more
source§

impl<T, _S> FromColorUnclamped<Rgb<_S, T>> for Okhsl<T>
where _S: RgbStandard, _S::Space: RgbSpace<WhitePoint = D65>, D65: WhitePoint<T>, Oklab<T>: FromColorUnclamped<Rgb<_S, T>> + IntoColorUnclamped<Self>,

source§

fn from_color_unclamped(color: Rgb<_S, T>) -> Self

Convert from T. The resulting color might be invalid in its color space. Read more
source§

impl<T, _S> FromColorUnclamped<Rgb<_S, T>> for Okhsv<T>
where _S: RgbStandard, _S::Space: RgbSpace<WhitePoint = D65>, D65: WhitePoint<T>, Oklab<T>: FromColorUnclamped<Rgb<_S, T>> + IntoColorUnclamped<Self>,

source§

fn from_color_unclamped(color: Rgb<_S, T>) -> Self

Convert from T. The resulting color might be invalid in its color space. Read more
source§

impl<T, _S> FromColorUnclamped<Rgb<_S, T>> for Okhwb<T>
where _S: RgbStandard, _S::Space: RgbSpace<WhitePoint = D65>, D65: WhitePoint<T>, Okhsv<T>: FromColorUnclamped<Rgb<_S, T>> + IntoColorUnclamped<Self>,

source§

fn from_color_unclamped(color: Rgb<_S, T>) -> Self

Convert from T. The resulting color might be invalid in its color space. Read more
source§

impl<T, _S> FromColorUnclamped<Rgb<_S, T>> for Oklch<T>
where _S: RgbStandard, _S::Space: RgbSpace<WhitePoint = D65>, D65: WhitePoint<T>, Oklab<T>: FromColorUnclamped<Rgb<_S, T>> + IntoColorUnclamped<Self>,

source§

fn from_color_unclamped(color: Rgb<_S, T>) -> Self

Convert from T. The resulting color might be invalid in its color space. Read more
source§

impl<Wp, T, _S> FromColorUnclamped<Rgb<_S, T>> for Yxy<Wp, T>
where _S: RgbStandard, _S::Space: RgbSpace<WhitePoint = Wp>, Wp: WhitePoint<T>, Xyz<Wp, T>: FromColorUnclamped<Rgb<_S, T>> + IntoColorUnclamped<Self>,

source§

fn from_color_unclamped(color: Rgb<_S, T>) -> Self

Convert from T. The resulting color might be invalid in its color space. Read more
source§

impl<S, T> FromColorUnclamped<Xyz<<<S as RgbStandard>::Space as RgbSpace>::WhitePoint, T>> for Rgb<S, T>

source§

fn from_color_unclamped( color: Xyz<<S::Space as RgbSpace>::WhitePoint, T> ) -> Self

Convert from T. The resulting color might be invalid in its color space. Read more
source§

impl<S, T> FromColorUnclamped<Yxy<<<S as RgbStandard>::Space as RgbSpace>::WhitePoint, T>> for Rgb<S, T>

source§

fn from_color_unclamped( color: Yxy<<<S as RgbStandard>::Space as RgbSpace>::WhitePoint, T> ) -> Self

Convert from T. The resulting color might be invalid in its color space. Read more
source§

impl<S, T, C> FromIterator<Rgb<S, T>> for Rgb<S, C>
where Self: Extend<Rgb<S, T>>, C: Default,

source§

fn from_iter<I: IntoIterator<Item = Rgb<S, T>>>(iter: I) -> Self

Creates a value from an iterator. Read more
source§

impl<S> FromStr for Rgb<S, u8>

source§

fn from_str(hex: &str) -> Result<Self, Self::Err>

Parses a color hex code of format ‘#ff00bb’ or ‘#abc’ (with or without the leading ‘#’) into a Rgb<S, u8> instance.

§

type Err = FromHexError

The associated error which can be returned from parsing.
source§

impl<S, T> GetHue for Rgb<S, T>

§

type Hue = RgbHue<T>

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

fn get_hue(&self) -> RgbHue<T>

Calculate a hue if possible. Read more
source§

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

§

type Mask = <T as HasBoolMask>::Mask

The mask type to use for selecting Self values.
source§

impl<'a, 'b, S, T> IntoIterator for &'a Rgb<S, &'b [T]>

§

type Item = Rgb<S, &'a T>

The type of the elements being iterated over.
§

type IntoIter = Iter<Iter<'a, T>, S>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a, 'b, S, T> IntoIterator for &'a Rgb<S, &'b mut [T]>

§

type Item = Rgb<S, &'a T>

The type of the elements being iterated over.
§

type IntoIter = Iter<Iter<'a, T>, S>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a, S, T, const N: usize> IntoIterator for &'a Rgb<S, [T; N]>

§

type Item = Rgb<S, &'a T>

The type of the elements being iterated over.
§

type IntoIter = Iter<Iter<'a, T>, S>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a, S, T> IntoIterator for &'a Rgb<S, Box<[T]>>

§

type Item = Rgb<S, &'a T>

The type of the elements being iterated over.
§

type IntoIter = Iter<Iter<'a, T>, S>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a, S, T> IntoIterator for &'a Rgb<S, Vec<T>>

§

type Item = Rgb<S, &'a T>

The type of the elements being iterated over.
§

type IntoIter = Iter<Iter<'a, T>, S>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a, 'b, S, T> IntoIterator for &'a mut Rgb<S, &'b mut [T]>

§

type Item = Rgb<S, &'a mut T>

The type of the elements being iterated over.
§

type IntoIter = Iter<IterMut<'a, T>, S>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a, S, T, const N: usize> IntoIterator for &'a mut Rgb<S, [T; N]>

§

type Item = Rgb<S, &'a mut T>

The type of the elements being iterated over.
§

type IntoIter = Iter<IterMut<'a, T>, S>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a, S, T> IntoIterator for &'a mut Rgb<S, Box<[T]>>
where T: 'a,

§

type Item = Rgb<S, &'a mut T>

The type of the elements being iterated over.
§

type IntoIter = Iter<IterMut<'a, T>, S>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a, S, T> IntoIterator for &'a mut Rgb<S, Vec<T>>

§

type Item = Rgb<S, &'a mut T>

The type of the elements being iterated over.
§

type IntoIter = Iter<IterMut<'a, T>, S>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a, S, T> IntoIterator for Rgb<S, &'a [T]>

§

type Item = Rgb<S, &'a T>

The type of the elements being iterated over.
§

type IntoIter = Iter<Iter<'a, T>, S>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a, S, T> IntoIterator for Rgb<S, &'a mut [T]>

§

type Item = Rgb<S, &'a mut T>

The type of the elements being iterated over.
§

type IntoIter = Iter<IterMut<'a, T>, S>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<S, T, const N: usize> IntoIterator for Rgb<S, [T; N]>

§

type Item = Rgb<S, T>

The type of the elements being iterated over.
§

type IntoIter = Iter<IntoIter<T, N>, S>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<S, T> IntoIterator for Rgb<S, Vec<T>>

§

type Item = Rgb<S, T>

The type of the elements being iterated over.
§

type IntoIter = Iter<IntoIter<T>, S>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<S, T> IsWithinBounds for Rgb<S, T>
where T: PartialCmp + Stimulus, T::Mask: BitAnd<Output = T::Mask>,

source§

fn is_within_bounds(&self) -> T::Mask

Check if the color’s components are within the expected range bounds. Read more
source§

impl<S, T> Lighten for Rgb<S, T>

§

type Scalar = T

The type of the lighten modifier.
source§

fn lighten(self, factor: T) -> Self

Scale the color towards the maximum lightness by factor, a value ranging from 0.0 to 1.0. Read more
source§

fn lighten_fixed(self, amount: T) -> Self

Lighten the color by amount, a value ranging from 0.0 to 1.0. Read more
source§

impl<S, T> LightenAssign for Rgb<S, T>

§

type Scalar = T

The type of the lighten modifier.
source§

fn lighten_assign(&mut self, factor: T)

Scale the color towards the maximum lightness by factor, a value ranging from 0.0 to 1.0. Read more
source§

fn lighten_fixed_assign(&mut self, amount: T)

Lighten the color by amount, a value ranging from 0.0 to 1.0. Read more
source§

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

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter.
source§

impl<S, T> Mix for Rgb<S, T>
where T: Real + Zero + One + Arithmetics + Clamp + Clone,

§

type Scalar = T

The type of the mixing factor.
source§

fn mix(self, other: Self, factor: T) -> Self

Mix the color with an other color, by factor. Read more
source§

impl<S, T> MixAssign for Rgb<S, T>
where T: Real + Zero + One + AddAssign + Arithmetics + Clamp + Clone,

§

type Scalar = T

The type of the mixing factor.
source§

fn mix_assign(&mut self, other: Self, factor: T)

Mix the color with an other color, by factor. Read more
source§

impl<S, T> Mul<T> for Rgb<S, T>
where T: Mul<Output = T> + Clone,

§

type Output = Rgb<S, T>

The resulting type after applying the * operator.
source§

fn mul(self, c: T) -> Self::Output

Performs the * operation. Read more
source§

impl<S, T> Mul for Rgb<S, T>
where T: Mul<Output = T>,

§

type Output = Rgb<S, T>

The resulting type after applying the * operator.
source§

fn mul(self, other: Self) -> Self::Output

Performs the * operation. Read more
source§

impl<S, T> MulAssign<T> for Rgb<S, T>
where T: MulAssign + Clone,

source§

fn mul_assign(&mut self, c: T)

Performs the *= operation. Read more
source§

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

source§

fn mul_assign(&mut self, other: Self)

Performs the *= operation. Read more
source§

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

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<S, T> Premultiply for Rgb<S, T>
where T: Real + Stimulus + Zero + IsValidDivisor + Mul<T, Output = T> + Div<T, Output = T> + Clone, T::Mask: LazySelect<T> + Clone,

§

type Scalar = T

The color’s component type.
source§

fn premultiply(self, alpha: T) -> PreAlpha<Self>

Alpha mask the color. Read more
source§

fn unpremultiply(premultiplied: PreAlpha<Self>) -> (Self, T)

Alpha unmask the color, resulting in a color and transparency pair. Read more
source§

impl<S, T> RelativeContrast for Rgb<S, T>

§

type Scalar = T

👎Deprecated since 0.7.2: replaced by palette::color_difference::Wcag21RelativeContrast
The type of the contrast ratio.
source§

fn get_contrast_ratio(self, other: Self) -> T

👎Deprecated since 0.7.2: replaced by palette::color_difference::Wcag21RelativeContrast
Calculate the contrast ratio between two colors.
source§

fn has_min_contrast_text( self, other: Self ) -> <Self::Scalar as HasBoolMask>::Mask

👎Deprecated since 0.7.2: replaced by palette::color_difference::Wcag21RelativeContrast
Verify the contrast between two colors satisfies SC 1.4.3. Contrast is at least 4.5:1 (Level AA).
source§

fn has_min_contrast_large_text( self, other: Self ) -> <Self::Scalar as HasBoolMask>::Mask

👎Deprecated since 0.7.2: replaced by palette::color_difference::Wcag21RelativeContrast
Verify the contrast between two colors satisfies SC 1.4.3 for large text. Contrast is at least 3:1 (Level AA).
source§

fn has_enhanced_contrast_text( self, other: Self ) -> <Self::Scalar as HasBoolMask>::Mask

👎Deprecated since 0.7.2: replaced by palette::color_difference::Wcag21RelativeContrast
Verify the contrast between two colors satisfies SC 1.4.6. Contrast is at least 7:1 (Level AAA).
source§

fn has_enhanced_contrast_large_text( self, other: Self ) -> <Self::Scalar as HasBoolMask>::Mask

👎Deprecated since 0.7.2: replaced by palette::color_difference::Wcag21RelativeContrast
Verify the contrast between two colors satisfies SC 1.4.6 for large text. Contrast is at least 4.5:1 (Level AAA).
source§

fn has_min_contrast_graphics( self, other: Self ) -> <Self::Scalar as HasBoolMask>::Mask

👎Deprecated since 0.7.2: replaced by palette::color_difference::Wcag21RelativeContrast
Verify the contrast between two colors satisfies SC 1.4.11 for graphical objects. Contrast is at least 3:1 (Level AA).
source§

impl<S, T> RelativeEq for Rgb<S, T>
where T: RelativeEq, T::Epsilon: Clone,

source§

fn default_max_relative() -> T::Epsilon

The default relative tolerance for testing values that are far-apart. Read more
source§

fn relative_eq( &self, other: &Self, epsilon: T::Epsilon, max_relative: T::Epsilon ) -> bool

A test for equality that uses a relative comparison if the values are far apart.
source§

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

The inverse of RelativeEq::relative_eq.
source§

impl<S, T> SampleUniform for Rgb<S, T>
where T: SampleUniform + Clone,

§

type Sampler = UniformRgb<S, T>

The UniformSampler implementation supporting type X.
source§

impl<S, T> SaturatingAdd<T> for Rgb<S, T>
where T: SaturatingAdd<Output = T> + Clone,

§

type Output = Rgb<S, T>

The resulting type.
source§

fn saturating_add(self, c: T) -> Self::Output

Returns the sum of self and other, but saturates instead of overflowing.
source§

impl<S, T> SaturatingAdd for Rgb<S, T>
where T: SaturatingAdd<Output = T>,

§

type Output = Rgb<S, T>

The resulting type.
source§

fn saturating_add(self, other: Self) -> Self::Output

Returns the sum of self and other, but saturates instead of overflowing.
source§

impl<S, T> SaturatingSub<T> for Rgb<S, T>
where T: SaturatingSub<Output = T> + Clone,

§

type Output = Rgb<S, T>

The resulting type.
source§

fn saturating_sub(self, c: T) -> Self::Output

Returns the difference of self and other, but saturates instead of overflowing.
source§

impl<S, T> SaturatingSub for Rgb<S, T>
where T: SaturatingSub<Output = T>,

§

type Output = Rgb<S, T>

The resulting type.
source§

fn saturating_sub(self, other: Self) -> Self::Output

Returns the difference of self and other, but saturates instead of overflowing.
source§

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

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<S, T> Sub<T> for Rgb<S, T>
where T: Sub<Output = T> + Clone,

§

type Output = Rgb<S, T>

The resulting type after applying the - operator.
source§

fn sub(self, c: T) -> Self::Output

Performs the - operation. Read more
source§

impl<S, T> Sub for Rgb<S, T>
where T: Sub<Output = T>,

§

type Output = Rgb<S, T>

The resulting type after applying the - operator.
source§

fn sub(self, other: Self) -> Self::Output

Performs the - operation. Read more
source§

impl<S, T> SubAssign<T> for Rgb<S, T>
where T: SubAssign + Clone,

source§

fn sub_assign(&mut self, c: T)

Performs the -= operation. Read more
source§

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

source§

fn sub_assign(&mut self, other: Self)

Performs the -= operation. Read more
source§

impl<'a, S, T> TryFrom<&'a [T]> for &'a Rgb<S, T>

§

type Error = <&'a [T; 3] as TryFrom<&'a [T]>>::Error

The type returned in the event of a conversion error.
source§

fn try_from(slice: &'a [T]) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'a, S, T> TryFrom<&'a mut [T]> for &'a mut Rgb<S, T>

§

type Error = <&'a mut [T; 3] as TryFrom<&'a mut [T]>>::Error

The type returned in the event of a conversion error.
source§

fn try_from(slice: &'a mut [T]) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<S, T> UlpsEq for Rgb<S, T>
where T: UlpsEq, T::Epsilon: Clone,

source§

fn default_max_ulps() -> u32

The default ULPs to tolerate when testing values that are far-apart. Read more
source§

fn ulps_eq(&self, other: &Self, epsilon: T::Epsilon, max_ulps: u32) -> bool

A test for equality that uses units in the last place (ULP) if the values are far apart.
source§

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

The inverse of UlpsEq::ulps_eq.
source§

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

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter.
source§

impl<S, T> Wcag21RelativeContrast for Rgb<S, T>
where Self: IntoColor<Luma<Linear<D65>, T>>, S: RgbStandard<Space = Srgb>, T: Real + Add<T, Output = T> + Div<T, Output = T> + PartialCmp + MinMax,

§

type Scalar = T

The scalar type used for luminance and contrast.
source§

fn relative_luminance(self) -> Luma<Linear<D65>, Self::Scalar>

Returns the WCAG 2.1 relative luminance of self. Read more
source§

fn relative_contrast(self, other: Self) -> Self::Scalar

Returns the WCAG 2.1 relative luminance contrast between self and other. Read more
source§

fn has_min_contrast_text( self, other: Self ) -> <Self::Scalar as HasBoolMask>::Mask

Verify the contrast between two colors satisfies SC 1.4.3. Contrast is at least 4.5:1 (Level AA). Read more
source§

fn has_min_contrast_large_text( self, other: Self ) -> <Self::Scalar as HasBoolMask>::Mask

Verify the contrast between two colors satisfies SC 1.4.3 for large text. Contrast is at least 3:1 (Level AA). Read more
source§

fn has_enhanced_contrast_text( self, other: Self ) -> <Self::Scalar as HasBoolMask>::Mask

Verify the contrast between two colors satisfies SC 1.4.6. Contrast is at least 7:1 (Level AAA). Read more
source§

fn has_enhanced_contrast_large_text( self, other: Self ) -> <Self::Scalar as HasBoolMask>::Mask

Verify the contrast between two colors satisfies SC 1.4.6 for large text. Contrast is at least 4.5:1 (Level AAA). Read more
source§

fn has_min_contrast_graphics( self, other: Self ) -> <Self::Scalar as HasBoolMask>::Mask

Verify the contrast between two colors satisfies SC 1.4.11 for graphical objects. Contrast is at least 3:1 (Level AA). Read more
source§

impl<S, T, _A> WithAlpha<_A> for Rgb<S, T>
where _A: Stimulus,

§

type Color = Rgb<S, T>

The opaque color type, without any transparency. Read more
§

type WithAlpha = Alpha<Rgb<S, T>, _A>

The color type with transparency applied. Read more
source§

fn with_alpha(self, alpha: _A) -> Self::WithAlpha

Transforms the color into a transparent color with the provided alpha value. If Self already has a transparency, it is overwritten. Read more
source§

fn without_alpha(self) -> Self::Color

Removes the transparency from the color. If Self::Color has an internal transparency field, that field will be set to A::max_intensity() to make it opaque. Read more
source§

fn split(self) -> (Self::Color, _A)

Splits the color into separate color and transparency values. Read more
source§

fn opaque(self) -> Self::WithAlpha
where A: Stimulus,

Transforms the color into a fully opaque color with a transparency field. If Self already has a transparency, it is overwritten. Read more
source§

fn transparent(self) -> Self::WithAlpha
where A: Zero,

Transforms the color into a fully transparent color. If Self already has a transparency, it is overwritten. Read more
source§

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

source§

fn zeroed() -> Self

source§

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

source§

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

source§

impl<S: 'static, T> Pod for Rgb<S, T>
where T: Pod,

source§

impl<S, T> StimulusColor for Rgb<S, T>
where T: Stimulus,

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

source§

impl<S, D, Swp, Dwp, T> AdaptFrom<S, Swp, Dwp, T> for D
where T: Real + Zero + Arithmetics + Clone, Swp: WhitePoint<T>, Dwp: WhitePoint<T>, S: IntoColorUnclamped<Xyz<Swp, T>>, D: FromColorUnclamped<Xyz<Dwp, T>>,

source§

fn adapt_from_using<M>(color: S, method: M) -> D
where M: TransformMatrix<T>,

Convert the source color to the destination color using the specified method.
source§

fn adapt_from(color: S) -> Self

Convert the source color to the destination color using the bradford method by default.
source§

impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
where T: Real + Zero + Arithmetics + Clone, Swp: WhitePoint<T>, Dwp: WhitePoint<T>, D: AdaptFrom<S, Swp, Dwp, T>,

source§

fn adapt_into_using<M>(self, method: M) -> D
where M: TransformMatrix<T>,

Convert the source color to the destination color using the specified method.
source§

fn adapt_into(self) -> D

Convert the source color to the destination color using the bradford method by default.
source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T, C> ArraysFrom<C> for T
where C: IntoArrays<T>,

source§

fn arrays_from(colors: C) -> T

Cast a collection of colors into a collection of arrays.
source§

impl<T, C> ArraysInto<C> for T
where C: FromArrays<T>,

source§

fn arrays_into(self) -> C

Cast this collection of arrays into a collection of colors.
source§

impl<C, T, const N: usize> Blend for C
where C: Premultiply<Scalar = T> + StimulusColor + ArrayCast<Array = [T; N]> + Clone, T: Real + Zero + One + MinMax + Clamp + Sqrt + Abs + Arithmetics + PartialCmp + Clone, <T as HasBoolMask>::Mask: LazySelect<T>,

source§

fn multiply(self, other: C) -> C

Multiply self with other. This uses the alpha component to regulate the effect, so it’s not just plain component wise multiplication.
source§

fn screen(self, other: C) -> C

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

fn overlay(self, other: C) -> C

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

fn darken(self, other: C) -> C

Return the darkest parts of self and other.
source§

fn lighten(self, other: C) -> C

Return the lightest parts of self and other.
source§

fn dodge(self, other: C) -> C

Lighten other to reflect self. Results in other if self is black.
source§

fn burn(self, other: C) -> C

Darken other to reflect self. Results in other if self is white.
source§

fn hard_light(self, other: C) -> C

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.
source§

fn soft_light(self, other: C) -> C

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.
source§

fn difference(self, other: C) -> C

Return the absolute difference between self and other. It’s basically abs(self - other), but regulated by the alpha component.
source§

fn exclusion(self, other: C) -> C

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

impl<C> BlendWith for C

§

type Color = C

The base color type of Self.
source§

fn blend_with<F>(self, other: C, blend_function: F) -> C
where F: BlendFunction<<C as BlendWith>::Color>,

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

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for U
where T: FromCam16Unclamped<WpParam, U>,

§

type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar

The number type that’s used in parameters when converting.
source§

fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar> ) -> T

Converts self into C, using the provided parameters.
source§

impl<T> CheckedBitPattern for T
where T: AnyBitPattern,

§

type Bits = T

Self must have the same layout as the specified Bits except for the possible invalid bit patterns being checked during is_valid_bit_pattern.
source§

fn is_valid_bit_pattern(_bits: &T) -> bool

If this function returns true, then it must be valid to reinterpret bits as &Self.
source§

impl<T, C> ComponentsFrom<C> for T
where C: IntoComponents<T>,

source§

fn components_from(colors: C) -> T

Cast a collection of colors into a collection of color components.
source§

impl<C> Compose for C

source§

fn over(self, other: C) -> C

Place self over other. This is the good old common alpha composition equation.
source§

fn inside(self, other: C) -> C

Results in the parts of self that overlaps the visible parts of other.
source§

fn outside(self, other: C) -> C

Results in the parts of self that lies outside the visible parts of other.
source§

fn atop(self, other: C) -> C

Place self over only the visible parts of other.
source§

fn xor(self, other: C) -> C

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

fn plus(self, other: C) -> C

Add self and other. This uses the alpha component to regulate the effect, so it’s not just plain component wise addition.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> FromAngle<T> for T

source§

fn from_angle(angle: T) -> T

Performs a conversion from angle.
source§

impl<T, U> FromColor<T> for U
where U: FromColorUnclamped<T> + Clamp,

source§

fn from_color(t: T) -> U

Convert from T with values clamped to the color defined bounds. Read more
source§

impl<T, U> FromColorMut<U> for T
where T: FromColor<U> + ArrayCast + Clone, U: FromColor<T> + ArrayCast<Array = <T as ArrayCast>::Array> + Clone,

source§

fn from_color_mut(color: &mut U) -> FromColorMutGuard<'_, T, U>

Temporarily convert from another color type in place. Read more
source§

impl<T, U> FromColorUnclampedMut<U> for T
where T: FromColorUnclamped<U> + ArrayCast + Clone, U: FromColorUnclamped<T> + ArrayCast<Array = <T as ArrayCast>::Array> + Clone,

source§

fn from_color_unclamped_mut( color: &mut U ) -> FromColorUnclampedMutGuard<'_, T, U>

Temporarily convert from another color type in place, without clamping. Read more
source§

impl<T, U> FromStimulus<U> for T
where U: IntoStimulus<T>,

source§

fn from_stimulus(other: U) -> T

Converts other into Self, while performing the appropriate scaling, rounding and clamping.
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> IntoAngle<U> for T
where U: FromAngle<T>,

source§

fn into_angle(self) -> U

Performs a conversion into T.
source§

impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for U
where T: Cam16FromUnclamped<WpParam, U>,

§

type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar

The number type that’s used in parameters when converting.
source§

fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar> ) -> T

Converts self into C, using the provided parameters.
source§

impl<T, U> IntoColor<U> for T
where U: FromColor<T>,

source§

fn into_color(self) -> U

Convert into T with values clamped to the color defined bounds Read more
source§

impl<T, U> IntoColorMut<T> for U
where T: FromColorMut<U> + ?Sized, U: FromColorMut<T> + ?Sized,

source§

fn into_color_mut(&mut self) -> FromColorMutGuard<'_, T, U>

Temporarily convert to another color type in place. Read more
source§

impl<T, U> IntoColorUnclamped<U> for T
where U: FromColorUnclamped<T>,

source§

fn into_color_unclamped(self) -> U

Convert into T. The resulting color might be invalid in its color space Read more
source§

impl<T, U> IntoColorUnclampedMut<T> for U

source§

fn into_color_unclamped_mut(&mut self) -> FromColorUnclampedMutGuard<'_, T, U>

Temporarily convert to another color type in place, without clamping. Read more
source§

impl<T> IntoStimulus<T> for T

source§

fn into_stimulus(self) -> T

Converts self into T, while performing the appropriate scaling, rounding and clamping.
source§

impl<Borrowed> SampleBorrow<Borrowed> for Borrowed
where Borrowed: SampleUniform,

source§

fn borrow(&self) -> &Borrowed

Immutably borrows from an owned value. See Borrow::borrow
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, C> TryComponentsInto<C> for T
where C: TryFromComponents<T>,

§

type Error = <C as TryFromComponents<T>>::Error

The error for when try_into_colors fails to cast.
source§

fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>

Try to cast this collection of color components into a collection of colors. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryFromColor<T> for U
where U: FromColorUnclamped<T> + IsWithinBounds<Mask = bool>,

source§

fn try_from_color(t: T) -> Result<U, OutOfBounds<U>>

Convert from T, returning ok if the color is inside of its defined range, otherwise an OutOfBounds error is returned which contains the unclamped color. Read more
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T, U> TryIntoColor<U> for T
where U: TryFromColor<T>,

source§

fn try_into_color(self) -> Result<U, OutOfBounds<U>>

Convert into T, returning ok if the color is inside of its defined range, otherwise an OutOfBounds error is returned which contains the unclamped color. Read more
source§

impl<C, U> UintsFrom<C> for U
where C: IntoUints<U>,

source§

fn uints_from(colors: C) -> U

Cast a collection of colors into a collection of unsigned integers.
source§

impl<C, U> UintsInto<C> for U
where C: FromUints<U>,

source§

fn uints_into(self) -> C

Cast this collection of unsigned integers into a collection of colors.
source§

impl<T> AnyBitPattern for T
where T: Pod,

source§

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

source§

impl<T> NoUninit for T
where T: Pod,