[go: up one dir, main page]

Struct coolor::Rgb

source ·
pub struct Rgb {
    pub r: u8,
    pub g: u8,
    pub b: u8,
}
Expand description

RGB color, with u8 components

Fields§

§r: u8

red

§g: u8

green

§b: u8

blue

Implementations§

source§

impl Rgb

source

pub const fn new(r: u8, g: u8, b: u8) -> Self

Create a new RGB color from its components

source

pub const fn is_grey(self) -> bool

source

pub fn to_ansi_slow(self) -> AnsiColor

Return the nearest ANSI color

This is a slow function as it literally tries all ANSI colors and picks the nearest one.

source

pub fn to_ansi(self) -> AnsiColor

Return the nearest ANSI color

This uses the excellent ansi_colours crate, as it’s very fast and gives rather good conversions

source

pub fn mix(c1: Self, w1: f32, c2: Self, w2: f32) -> Self

source

pub fn to_hsl(self) -> Hsl

source

pub fn rp(self) -> f32

red part in [0,1]

source

pub fn gp(self) -> f32

green part in [0,1]

source

pub fn bp(self) -> f32

blue part in [0,1]

source

pub fn parts(self) -> (f32, f32, f32)

source

pub fn luma(self) -> f32

Compute the Luma value characterizing the “light” of the color, going from 0 (black) to 1 (white).

Reference: https://en.wikipedia.org/wiki/Luma_(video)

source

pub fn distance_to<O: Into<Rgb>>(self, other: O) -> f32

tentatively perceptual distance between two RGB colors (adapted from the ansi_colours crate, by mina86, who adapted a formula found at https://www.compuphase.com/cmetric.htm)

Trait Implementations§

source§

impl Clone for Rgb

source§

fn clone(&self) -> Rgb

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 Debug for Rgb

source§

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

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

impl From<(f32, f32, f32)> for Rgb

source§

fn from(c: (f32, f32, f32)) -> Self

Convert from a (r,g,b) float tupples with components in [0,1[

source§

impl From<Rgb> for Color

source§

fn from(rgb: Rgb) -> Self

Converts to this type from the input type.
source§

impl From<Rgb> for Hsl

source§

fn from(rgb: Rgb) -> Self

Converts to this type from the input type.
source§

impl PartialEq<Rgb> for Rgb

source§

fn eq(&self, other: &Rgb) -> 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 Copy for Rgb

source§

impl Eq for Rgb

source§

impl StructuralEq for Rgb

source§

impl StructuralPartialEq for Rgb

Auto Trait Implementations§

§

impl RefUnwindSafe for Rgb

§

impl Send for Rgb

§

impl Sync for Rgb

§

impl Unpin for Rgb

§

impl UnwindSafe for Rgb

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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> TryFrom<U> for Twhere 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> TryInto<U> for Twhere 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.