Struct scarlet::colors::cielabcolor::CIELABColor
source · pub struct CIELABColor {
pub l: f64,
pub a: f64,
pub b: f64,
}
Expand description
A color in the CIELAB color space.
Example
Unlike spaces such as HSV and RGB, moving a and b linearly will create roughly smooth change in color.
// roughly blue-green
let mut color = CIELABColor{l: 50., a: -100., b: -100.};
for _i in 0..10 {
// make warmer: positive a and b direction
color.a = color.a + 20.;
color.b = color.b + 20.;
println!("{}", color.convert::<RGBColor>().to_string());
}
// prints the following:
// #0098FF
// #0092DD
// #008ABA
// #2F8298
// #777777
// #9E6956
// #BD5735
// #D73C0A
// #F00000
// #FF0000
// note that the end might have been truncated to fit in sRGB's gamut on either side
Fields§
§l: f64
The luminance (loosely, brightness) of a given color. 0 is the lowest visible value and gives black, whereas 100 is the value of diffuse white: it is perhaps possible to have a higher value for reflective surfaces.
a: f64
The first opponent color axis. By convention, this is usually between -128 and 127, with -128 being fully green and 127 being fully magenta, but note that it is still possible to create “imaginary” colors (ones that cannot normally be seen by the human eye). Additionally, depending on the other two dimensions, many colors with a value in this range will still not be in the range of human vision.
b: f64
The second opponent color axis. This is, like a
, between -128 and 127 by convention for most
visible colors, although it is possible to work with imaginary colors as well and many colors
with a value in this range are not in the range of human vision. -128 is fully blue; 127 is
fully yellow.
Trait Implementations§
source§impl Clone for CIELABColor
impl Clone for CIELABColor
source§fn clone(&self) -> CIELABColor
fn clone(&self) -> CIELABColor
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Color for CIELABColor
impl Color for CIELABColor
source§fn from_xyz(xyz: XYZColor) -> CIELABColor
fn from_xyz(xyz: XYZColor) -> CIELABColor
Converts a given CIE XYZ color to CIELAB. Because CIELAB is implicitly in a given illuminant space, and because the linear conversions within CIELAB that it uses conflict with the transform used in the rest of Scarlet, this is explicitly CIELAB D50: any other illuminant is converted to D50 outside of CIELAB conversion. This in line with programs like Photoshop, which also use CIELAB D50.
source§fn to_xyz(&self, illuminant: Illuminant) -> XYZColor
fn to_xyz(&self, illuminant: Illuminant) -> XYZColor
Returns an XYZ color that corresponds to the CIELAB color. Note that, because implicitly every CIELAB color is D50, conversion is done by first converting to a D50 XYZ color and then using a chromatic adaptation transform.
source§fn convert<T: Color>(&self) -> T
fn convert<T: Color>(&self) -> T
collect()
and other methods in the standard library, the use of
type inference will usually allow for clean syntax, but occasionally the turbofish is
necessary. Read moresource§fn hue(&self) -> f64
fn hue(&self) -> f64
source§fn set_hue(&mut self, new_hue: f64)
fn set_hue(&mut self, new_hue: f64)
source§fn lightness(&self) -> f64
fn lightness(&self) -> f64
source§fn set_lightness(&mut self, new_lightness: f64)
fn set_lightness(&mut self, new_lightness: f64)
source§fn chroma(&self) -> f64
fn chroma(&self) -> f64
source§fn set_chroma(&mut self, new_chroma: f64)
fn set_chroma(&mut self, new_chroma: f64)
source§fn saturation(&self) -> f64
fn saturation(&self) -> f64
source§fn set_saturation(&mut self, new_sat: f64)
fn set_saturation(&mut self, new_sat: f64)
source§fn grayscale(&self) -> Selfwhere
Self: Sized,
fn grayscale(&self) -> Selfwhere Self: Sized,
Color
of the same type as before, but with chromaticity removed: effectively,
a color created solely using a mix of black and white that has the same lightness as
before. This uses the CIELAB luminance definition, which is considered a good standard and is
perceptually accurate for the most part. Read moresource§fn distance<T: Color>(&self, other: &T) -> f64
fn distance<T: Color>(&self, other: &T) -> f64
source§fn visually_indistinguishable<T: Color>(&self, other: &T) -> bool
fn visually_indistinguishable<T: Color>(&self, other: &T) -> bool
source§impl Debug for CIELABColor
impl Debug for CIELABColor
source§impl<'de> Deserialize<'de> for CIELABColor
impl<'de> Deserialize<'de> for CIELABColor
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
source§impl From<CIELABColor> for Coord
impl From<CIELABColor> for Coord
source§fn from(val: CIELABColor) -> Self
fn from(val: CIELABColor) -> Self
source§impl From<Coord> for CIELABColor
impl From<Coord> for CIELABColor
source§fn from(c: Coord) -> CIELABColor
fn from(c: Coord) -> CIELABColor
source§impl Serialize for CIELABColor
impl Serialize for CIELABColor
impl Copy for CIELABColor
Auto Trait Implementations§
impl RefUnwindSafe for CIELABColor
impl Send for CIELABColor
impl Sync for CIELABColor
impl Unpin for CIELABColor
impl UnwindSafe for CIELABColor
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> ColorPoint for Twhere
T: Color + Into<Coord> + From<Coord> + Copy + Clone,
impl<T> ColorPoint for Twhere T: Color + Into<Coord> + From<Coord> + Copy + Clone,
source§fn euclidean_distance(self, other: Self) -> f64
fn euclidean_distance(self, other: Self) -> f64
distance()
function for
that.source§fn weighted_midpoint(self, other: Self, weight: f64) -> Self
fn weighted_midpoint(self, other: Self, weight: f64) -> Self
Color
. This is defined as the color corresponding to the point
along the line segment connecting the two points such that the distance to the second point
is the weight, which for most applications needs to be between 0 and 1. For example, a
weight of 0.9 would make the midpoint one-tenth as much affected by the second points as the
first.source§fn midpoint(self, other: Self) -> Self
fn midpoint(self, other: Self) -> Self
weighted_midpoint
, but with weight = 0.5
: essentially, the
Color
representing the midpoint of the two inputs in 3D space.source§fn weighted_average(
self,
others: Vec<Self>,
weights: Vec<f64>
) -> Result<Self, ColorCalcError>
fn weighted_average( self, others: Vec<Self>, weights: Vec<f64> ) -> Result<Self, ColorCalcError>
source§fn average(self, others: Vec<Self>) -> Coord
fn average(self, others: Vec<Self>) -> Coord
weighted_average
in the
case where each weight is the same.source§fn is_imaginary(&self) -> bool
fn is_imaginary(&self) -> bool
true
if the color is outside the range of human vision. Uses the CIE 1931 standard
observer spectral data.source§fn closest_real_color(&self) -> Self
fn closest_real_color(&self) -> Self
source§fn gradient_scale(&self, other: &Self, n: usize) -> Vec<Self>
fn gradient_scale(&self, other: &Self, n: usize) -> Vec<Self>
n
is the number of additional colors to add.source§fn gradient(&self, other: &Self) -> Box<dyn Fn(f64) -> Self>
fn gradient(&self, other: &Self) -> Box<dyn Fn(f64) -> Self>
self
, 1 returns other
, and anything in between returns a mix (calculated
linearly). Although it is possible to extrapolate outside of the range [0, 1], this is not
a guarantee and may change without warning. For more fine-grained control of gradients, see
the GradientColorMap
struct. Read moresource§fn cbrt_gradient(&self, other: &Self) -> Box<dyn Fn(f64) -> Self>
fn cbrt_gradient(&self, other: &Self) -> Box<dyn Fn(f64) -> Self>
self
, 1 returns other
, and anything in between returns a mix (calculated
by the cube root of the given value). Although it is possible to extrapolate outside of the
range [0, 1], this is not a guarantee and may change without warning. For more fine-grained
control of gradients, see the GradientColorMap
struct. Read moresource§fn padded_gradient(
&self,
other: &Self,
lower_pad: f64,
upper_pad: f64
) -> Box<dyn Fn(f64) -> Self>
fn padded_gradient( &self, other: &Self, lower_pad: f64, upper_pad: f64 ) -> Box<dyn Fn(f64) -> Self>
lower_pad
and upper_pad
such that an input of 0 returns the gradient at
lower_pad
, an input of 1 returns the gradient at upper_pad
, and values in-between are
mapped linearly inside that range. For more fine-grained control over gradients, see the
GradientColorMap
struct. Read more§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.