pub struct Color {
    pub r: u8,
    pub g: u8,
    pub b: u8,
    pub a: u8,
}
Expand description

This represents an RGBA color and is used to store a pixel by Image and PixelsWrapper

Fields§

§r: u8§g: u8§b: u8§a: u8

Implementations§

source§

impl Color

source

pub fn new(r: f32, g: f32, b: f32, a: f32) -> Self

Converts 0.0..=1.0 to 0..=255 Values outside 0.0..=1.0 are clamped

source

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

Create new color with alpha set to 255

source

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

source

pub const fn gray(value: u8) -> Self

Create a new color with red, green and blue set to value and alpha set to 255

source

pub const fn from_i32(value: i32) -> Self

Convert an i32 into a Color where bytes match the format [R,G,B,A]

source

pub fn from_f32_array(array: [f32; 4]) -> Self

Convert f32 array in the format [R,G,B,A] to color where 0.0 = 0, and 1.0 = 255

source

pub fn from_hex(hex: &str) -> Result<Color, ColorError>

source§

impl Color

source

pub fn as_array(&self) -> [u8; 4]

Split color into array in the format [R,G,B,A]

source

pub fn as_i32(&self) -> i32

Convert color to i32 in the format [R,G,B,A]

source

pub fn as_f32_array(&self) -> [f32; 4]

Convert color to f32 array in the format [R,G,B,A] where 0.0 = 0, and 1.0 = 255

source

pub fn blend(&self, other: Color) -> Color

source

pub fn brightness(&self) -> f32

ignores alpha

source

pub fn is_dark(&self) -> bool

source

pub fn is_transparent(&self) -> bool

source

pub fn darken(&self) -> Color

source

pub fn lighten(&self) -> Color

source

pub fn with_brightness(&self, amount: f32) -> Color

Copy color with brightness

source

pub fn with_saturate(&self, amount: f32) -> Color

De/saturate color by percentage Negative amount increases saturation

source

pub fn desaturate(&self) -> Color

Decrease saturation by 10%

source

pub fn saturate(&self) -> Color

Increase saturation by 10%

source

pub fn to_hex(&self) -> String

Trait Implementations§

source§

impl Clone for Color

source§

fn clone(&self) -> Color

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 Color

source§

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

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

impl Default for Color

source§

fn default() -> Self

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

impl<'de> Deserialize<'de> for Color

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 From<Color> for TextFormat

source§

fn from(color: Color) -> Self

Converts to this type from the input type.
source§

impl Hash for Color

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 PartialEq<Color> for Color

source§

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

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 Tint for Color

source§

fn tint_add( &mut self, r_diff: isize, g_diff: isize, b_diff: isize, a_diff: isize )

Add to the RGBA channels by the amounts specified Read more
source§

fn tint_mul(&mut self, r_diff: f32, g_diff: f32, b_diff: f32, a_diff: f32)

Multiple the RGBA channels by the amounts specified Read more
source§

impl ToIci for Color

source§

impl Copy for Color

source§

impl Eq for Color

source§

impl StructuralEq for Color

source§

impl StructuralPartialEq for Color

Auto Trait Implementations§

§

impl RefUnwindSafe for Color

§

impl Send for Color

§

impl Sync for Color

§

impl Unpin for Color

§

impl UnwindSafe for Color

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> AnyToAny for Twhere T: 'static,

source§

fn as_any(&self) -> &(dyn Any + 'static)

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> ToOwned for Twhere 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, 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.
source§

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