Struct Rgb

Source
#[repr(C)]
pub struct Rgb<T> { /* private fields */ }
Expand description

The Rgb device-dependent cartesian color model.

Rgb<T> has three primaries: red, green blue, which are always positive and in the normalized range [0, 1]. Rgb<T> accepts both integer and float components.

It is made to be efficient and easy to use in many different applications, and can be transmuted directly to a &[T; N].

Rgb is the base device dependent color space from which all others go through to convert, which can be converted to the other device dependent spaces or to the device independent CIE spaces directly. The color space of Rgb is not specified or assumed, it is up to you to not mix color spaces improperly or use an appropriate wrapper.

§Examples:

use prisma::{Broadcast, HomogeneousColor, Lerp, Rgb};

let black = Rgb::broadcast(0.0f32);
let blue = Rgb::new(0, 0, 255u8);
// Convert blue to have float channels and compute the color halfway between blue and black
let blended = black.lerp(&blue.color_cast(), 0.5);

assert_eq!(blended, Rgb::new(0.0, 0.0, 0.5));

Implementations§

Source§

impl<T> Rgb<T>

Source

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

Construct a new Rgb instance with the given channel values

Source

pub fn color_cast<TOut>(&self) -> Rgb<TOut>

Convert the internal channel scalar format

Source

pub fn red(&self) -> T

Returns the red channel scalar

Source

pub fn green(&self) -> T

Returns the green channel scalar

Source

pub fn blue(&self) -> T

Returns the blue channel scalar

Source

pub fn red_mut(&mut self) -> &mut T

Returns a mutable reference to the red channel scalar

Source

pub fn green_mut(&mut self) -> &mut T

Returns a mutable reference to the green channel scalar

Source

pub fn blue_mut(&mut self) -> &mut T

Returns a mutable reference to the blue channel scalar

Source

pub fn set_red(&mut self, val: T)

Set the red channel value

Source

pub fn set_green(&mut self, val: T)

Set the green channel value

Source

pub fn set_blue(&mut self, val: T)

Set the blue channel value

Source§

impl<T> Rgb<T>

Source

pub fn chromaticity_coordinates(&self) -> ChromaticityCoordinates<T>

Compute the ChromaticityCooridinates for an Rgb instance

Trait Implementations§

Source§

impl<T> AbsDiffEq for Rgb<T>

Source§

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: Self::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: &Rhs, epsilon: Self::Epsilon) -> bool

The inverse of ApproxEq::abs_diff_eq.
Source§

impl<T> Bounded for Rgb<T>

Source§

fn normalize(self) -> Self

Return a value clipped inside the normalized range
Source§

fn is_normalized(&self) -> bool

Return true if the value is normalized
Source§

impl<T> Broadcast for Rgb<T>

Source§

fn broadcast(value: T) -> Self

Construct Self with each channel set to value
Source§

impl<T: Clone> Clone for Rgb<T>

Source§

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

Returns a duplicate 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<T> Color for Rgb<T>

Source§

type Tag = RgbTag

The unique tag unit struct identifying the color type
Source§

type ChannelsTuple = (T, T, T)

A tuple of types for each channel in the color
Source§

fn num_channels() -> u32

Return how many channels the color has
Source§

fn to_tuple(self) -> Self::ChannelsTuple

Convert a color into a tuple of channels
Source§

impl<T, E> ConvertToXyz<T, Rgb<T>, E> for SRgb<T>

Source§

type OutputColor = Xyz<T>

The type to output. Always some form of Xyz
Source§

fn convert_to_xyz(&self, color: &EncodedColor<Rgb<T>, E>) -> Self::OutputColor

Convert color into the XYZ space
Source§

impl<'a, T, E, EIn> ConvertToXyz<T, Rgb<T>, EIn> for &'a EncodedColorSpace<T, E>

Source§

type OutputColor = Xyz<T>

The type to output. Always some form of Xyz
Source§

fn convert_to_xyz(&self, color: &EncodedColor<Rgb<T>, EIn>) -> Self::OutputColor

Convert color into the XYZ space
Source§

impl<T, E, EIn> ConvertToXyz<T, Rgb<T>, EIn> for Arc<EncodedColorSpace<T, E>>

Source§

type OutputColor = Xyz<T>

The type to output. Always some form of Xyz
Source§

fn convert_to_xyz(&self, color: &EncodedColor<Rgb<T>, EIn>) -> Self::OutputColor

Convert color into the XYZ space
Source§

impl<T, E, EIn> ConvertToXyz<T, Rgb<T>, EIn> for EncodedColorSpace<T, E>

Source§

type OutputColor = Xyz<T>

The type to output. Always some form of Xyz
Source§

fn convert_to_xyz(&self, color: &EncodedColor<Rgb<T>, EIn>) -> Self::OutputColor

Convert color into the XYZ space
Source§

impl<T, E, EIn> ConvertToXyz<T, Rgb<T>, EIn> for Rc<EncodedColorSpace<T, E>>

Source§

type OutputColor = Xyz<T>

The type to output. Always some form of Xyz
Source§

fn convert_to_xyz(&self, color: &EncodedColor<Rgb<T>, EIn>) -> Self::OutputColor

Convert color into the XYZ space
Source§

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

Source§

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

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

impl<T> Default for Rgb<T>

Source§

fn default() -> Self

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

impl<T> Display for Rgb<T>

Source§

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

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

impl<T> EncodableColor for Rgb<T>

Source§

fn encoded_as<E>(self, encoding: E) -> EncodedColor<Self, E>
where E: ColorEncoding,

Specify what encoding the color has. This does not actually encode anything Read more
Source§

fn linear(self) -> EncodedColor<Self, LinearEncoding>

Specify that the color is linear
Source§

fn srgb_encoded(self) -> EncodedColor<Self, SrgbEncoding>

Specify that the color is sRGB encoded Read more
Source§

fn gamma_encoded<T: Float>( self, gamma: T, ) -> EncodedColor<Self, GammaEncoding<T>>

Specify that the color is gamma encoded with a given gamma
Source§

impl<T> Flatten for Rgb<T>

Source§

fn as_slice(&self) -> &[Self::ChannelFormat]

Return a slice representation of Self
Source§

fn from_slice(vals: &[T]) -> Self

Return Self constructed from values
Source§

impl<T, A> From<Hsl<T, A>> for Rgb<T>

Source§

fn from(from: Hsl<T, A>) -> Self

Converts to this type from the input type.
Source§

impl<T, A> From<Hsv<T, A>> for Rgb<T>

Source§

fn from(from: Hsv<T, A>) -> Self

Converts to this type from the input type.
Source§

impl<T, A> From<Hwb<T, A>> for Rgb<T>

Source§

fn from(from: Hwb<T, A>) -> Self

Converts to this type from the input type.
Source§

impl<T, A> From<Rgb<T>> for Hsi<T, A>

Source§

fn from(from: Rgb<T>) -> Self

Converts to this type from the input type.
Source§

impl<T, A> From<Rgb<T>> for Hsl<T, A>

Source§

fn from(from: Rgb<T>) -> Self

Converts to this type from the input type.
Source§

impl<T, A> From<Rgb<T>> for Hsv<T, A>

Source§

fn from(from: Rgb<T>) -> Self

Converts to this type from the input type.
Source§

impl<T, A> From<Rgb<T>> for Hwb<T, A>

Source§

fn from(from: Rgb<T>) -> Self

Converts to this type from the input type.
Source§

impl<T, M> From<Rgb<T>> for YCbCr<T, M>

Source§

fn from(from: Rgb<T>) -> YCbCr<T, M>

Converts to this type from the input type.
Source§

impl<T, A> From<Rgb<T>> for eHsi<T, A>

Source§

fn from(from: Rgb<T>) -> Self

Converts to this type from the input type.
Source§

impl<T, A> FromColor<Hsl<T, A>> for Rgb<T>

Source§

fn from_color(from: &Hsl<T, A>) -> Self

Construct Self from from
Source§

impl<T, A> FromColor<Hsv<T, A>> for Rgb<T>

Source§

fn from_color(from: &Hsv<T, A>) -> Self

Construct Self from from
Source§

impl<T, A> FromColor<Hwb<T, A>> for Rgb<T>

Source§

fn from_color(from: &Hwb<T, A>) -> Self

Construct Self from from
Source§

impl<T, A> FromColor<Rgb<T>> for Hsi<T, A>

Source§

fn from_color(from: &Rgb<T>) -> Self

Construct Self from from
Source§

impl<T, A> FromColor<Rgb<T>> for Hsl<T, A>

Source§

fn from_color(from: &Rgb<T>) -> Self

Construct Self from from
Source§

impl<T, A> FromColor<Rgb<T>> for Hsv<T, A>

Source§

fn from_color(from: &Rgb<T>) -> Self

Construct Self from from
Source§

impl<T, A> FromColor<Rgb<T>> for Hwb<T, A>

Source§

fn from_color(from: &Rgb<T>) -> Self

Construct Self from from
Source§

impl<T> FromColor<Rgb<T>> for Rgi<T>

Source§

fn from_color(from: &Rgb<T>) -> Self

Construct Self from from
Source§

impl<T, M> FromColor<Rgb<T>> for YCbCr<T, M>

Source§

fn from_color(from: &Rgb<T>) -> YCbCr<T, M>

Construct Self from from
Source§

impl<T, A> FromColor<Rgb<T>> for eHsi<T, A>

Source§

fn from_color(from: &Rgb<T>) -> Self

Construct Self from from
Source§

impl<T> FromColor<Rgi<T>> for Rgb<T>

Source§

fn from_color(from: &Rgi<T>) -> Self

Construct Self from from
Source§

impl<T, A> FromColor<eHsi<T, A>> for Rgb<T>

Source§

fn from_color(from: &eHsi<T, A>) -> Rgb<T>

Construct Self from from
Source§

impl<T, A> FromHsi<Hsi<T, A>> for Rgb<T>
where T: PosNormalChannelScalar + Float, A: AngularChannelScalar + Angle<Scalar = T> + IntoAngle<Rad<T>, OutputScalar = T>,

Source§

fn from_hsi(value: &Hsi<T, A>, out_of_gamut_mode: HsiOutOfGamutMode) -> Rgb<T>

Construct Self from from, describing what to do if the color is out of gamut for Self
Source§

impl<T> FromTuple for Rgb<T>

Source§

fn from_tuple(values: Self::ChannelsTuple) -> Self

Construct Self from a tuple of channel values
Source§

impl<T, M> FromYCbCr<YCbCr<T, M>> for Rgb<T>

Source§

fn from_ycbcr( from: &YCbCr<T, M>, out_of_gamut_mode: YCbCrOutOfGamutMode, ) -> Rgb<T>

Construct Self from from, describing what to do if the color is out of gamut for Self
Source§

impl<T: Hash> Hash for Rgb<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl<T> HomogeneousColor for Rgb<T>

Source§

type ChannelFormat = T

The scalar type of each channel
Source§

fn clamp(self, min: T, max: T) -> Self

Clamp the value of each channel between min and max
Source§

impl<T> Invert for Rgb<T>

Source§

fn invert(self) -> Self

Invert Self
Source§

impl<T> Lerp for Rgb<T>

Source§

type Position = <T as Lerp>::Position

The type of the pos argument
Source§

fn lerp(&self, right: &Self, pos: Self::Position) -> Self

Interpolate between self and right Read more
Source§

impl<T: Ord> Ord for Rgb<T>

Source§

fn cmp(&self, other: &Rgb<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: PartialEq> PartialEq for Rgb<T>

Source§

fn eq(&self, other: &Rgb<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialOrd> PartialOrd for Rgb<T>

Source§

fn partial_cmp(&self, other: &Rgb<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T> RelativeEq for Rgb<T>

Source§

fn default_max_relative() -> Self::Epsilon

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

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

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

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

The inverse of ApproxEq::relative_eq.
Source§

impl<T> TranscodableColor for Rgb<T>

Source§

type IntermediateColor = Rgb<f64>

The color type used internally to do conversions. This will always have floating-point channels
Source§

fn encode_color<Encoder>(self, enc: &Encoder) -> Self
where Encoder: ChannelEncoder,

Encode self using the encoder enc
Source§

fn decode_color<Decoder>(self, dec: &Decoder) -> Self
where Decoder: ChannelDecoder,

Decode self using the decoder dec
Source§

impl<T> UlpsEq for Rgb<T>

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: Self::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: &Rhs, epsilon: Self::Epsilon, max_ulps: u32) -> bool

The inverse of ApproxEq::ulps_eq.
Source§

impl<T> Color3 for Rgb<T>

Source§

impl<T: Copy> Copy for Rgb<T>

Source§

impl<T: Eq> Eq for Rgb<T>

Source§

impl<T> StructuralPartialEq for Rgb<T>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

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> 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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

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> TryInto<U> for T
where U: TryFrom<T>,

Source§

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.