#[non_exhaustive]pub enum Observer {
Cie1931,
Cie1964,
Cie2015,
Cie2015_10,
}Expand description
Light-weight identifier added to the XYZ and RGB datasets,
representing the colorimetric standard observer used.
No data included here, which would be the Rust way, but that does not work with wasm-bindgen. This can be directly used in JavaScript, and has the benefit to be just an index.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Implementations§
Source§impl Observer
impl Observer
Sourcepub fn xyz2rgb_matrix(&self, rgb_space: RgbSpace) -> &'static Matrix3<f64>
pub fn xyz2rgb_matrix(&self, rgb_space: RgbSpace) -> &'static Matrix3<f64>
Returns the XYZ to Rgb conversion matrix for the given RGB space.
Source§impl Observer
impl Observer
Sourcepub fn rgb2xyz_matrix(&self, rgb_space: RgbSpace) -> &'static Matrix3<f64>
pub fn rgb2xyz_matrix(&self, rgb_space: RgbSpace) -> &'static Matrix3<f64>
Returns the RGB to XYZ conversion matrix for the given RGB space.
Source§impl Observer
impl Observer
Sourcepub fn spectral_locus(&self) -> &SpectralLocus
pub fn spectral_locus(&self) -> &SpectralLocus
Returns the spectral locus for this observer.
The spectral locus is the boundary of the area of all physical colors in a chromiticity diagram.
pub fn rel_xyz(&self, light: &dyn Light, filter: &dyn Filter) -> RelXYZ
Sourcepub fn xyz(&self, light: &dyn Light, filter: Option<&dyn Filter>) -> XYZ
pub fn xyz(&self, light: &dyn Light, filter: Option<&dyn Filter>) -> XYZ
Calulates Tristimulus values for an object implementing the Light trait, and an optional Filter, filtering the light.
The Light trait is implemented by CieIlluminant and Illuminant.
Colorant implments the Filter trait.
Rgb, which represents a display pixel, implements both in this library.
As a light, it is the light emitted from the pixel, as a filter it is the RGB-composite
filter which is applied to the underlying standard illuminant of color space.
Sourcepub fn lab(&self, light: &dyn Light, filter: &dyn Filter) -> CieLab
pub fn lab(&self, light: &dyn Light, filter: &dyn Filter) -> CieLab
Calculates the Lab* CIELAB values for a light source and filter combination. This method is used to compute the color appearance of a light source when filtered by a colorant or filter. It returns the CIELAB values normalized to a white reference luminance of 100.0,
§Arguments
light- A reference to an object implementing the Light trait, such asCieIlluminant.filter- A reference to an object implementing the Filter trait, such asColorant.
§Returns
CieLab- The computed CIELAB color representation for the light and filter combination.
Sourcepub fn lab_d65(&self, filter: &dyn Filter) -> CieLab
pub fn lab_d65(&self, filter: &dyn Filter) -> CieLab
Calculates the Lab* CIELAB D65 values of a Colorant, using D65 as an illuminant.
Convenience method for lab with D65 illuminant, and using an illuminance value of 100.0.
Sourcepub fn lab_d50(&self, filter: &dyn Filter) -> CieLab
pub fn lab_d50(&self, filter: &dyn Filter) -> CieLab
Calculates the Lab* CIELAB D50 values of a Colorant, using D50 as an illuminant.
Convenience method for lab with D50 illuminant, and using an illuminance value of 100.0.
Sourcepub fn ciecam16(
&self,
light: &dyn Light,
filter: &dyn Filter,
vc: ViewConditions,
) -> CieCam16
pub fn ciecam16( &self, light: &dyn Light, filter: &dyn Filter, vc: ViewConditions, ) -> CieCam16
Calculates the CIECAM16 color appearance model values for a light source and filter combination. This method is used to compute the color appearance of a light source when filtered by a colorant or filter, using the CIECAM16 model. It returns the CIECAM16 values normalized to a white reference luminance of 100.0.
§Arguments
light- A reference to an object implementing the Light trait, such asCieIlluminant.filter- A reference to an object implementing the Filter trait, such asColorant.vc- The view conditions to use for the CIECAM16 calculation.
§Returns
CieCam16- The computed CIECAM16 color appearance model representation for the light and filter combination.
Sourcepub fn ciecam02(
&self,
light: &dyn Light,
filter: &dyn Filter,
vc: ViewConditions,
) -> CieCam02
pub fn ciecam02( &self, light: &dyn Light, filter: &dyn Filter, vc: ViewConditions, ) -> CieCam02
Calculates the CIECAM02 color appearance model values for a light source and filter combination. This method is used to compute the color appearance of a light source when filtered by a colorant or filter, using the CIECAM02 model. It returns the CIECAM02 values normalized to a white reference luminance of 100.0.
§Arguments
light- A reference to an object implementing the Light trait, such asCieIlluminant.filter- A reference to an object implementing the Filter trait, such asColorant.vc- The view conditions to use for the CIECAM02 calculation.
§Returns
CieCam02- The computed CIECAM02 color appearance model representation for the light and filter combination.
Sourcepub fn xyz_from_spectrum(&self, spectrum: &Spectrum) -> XYZ
pub fn xyz_from_spectrum(&self, spectrum: &Spectrum) -> XYZ
Calculates Tristimulus valus, in form of an XYZ object of a general spectrum. If a reference white is given (rhs), it will copy its tristimulus value, and the spectrum is interpreted as a stimulus, being a combination of an illuminant with a colorant. If no reference white is given, the spectrum is interpreted as an illuminant. This method produces the raw XYZ data, not normalized to 100.0
Sourcepub fn y_from_spectrum(&self, spectrum: &Spectrum) -> f64
pub fn y_from_spectrum(&self, spectrum: &Spectrum) -> f64
Calculates the lumimous value or Y tristimulus value for a general spectrum.
Sourcepub fn xyz_at_wavelength(&self, wavelength: usize) -> Result<XYZ, Error>
pub fn xyz_at_wavelength(&self, wavelength: usize) -> Result<XYZ, Error>
Returns the observer’s color matching function (CMF) data as an XYZ tristimulus value for the given wavelength.
This allows access to the underlying data for the entire range of wavelengths, 380-780nm.
However, please read the documentation for the
spectral_locus_wavelength_range method on
situations where you might not want to sample the full range.
Sourcepub fn monochromes(&self, ref_white: CieIlluminant) -> Vec<(usize, RelXYZ)>
pub fn monochromes(&self, ref_white: CieIlluminant) -> Vec<(usize, RelXYZ)>
Calculates the relative XYZ tristimulus values of monochromatic stimuli.
Monochromatic stimuli are pure spectral colors, like those seen when white light is dispersed by a prism. This method computes their XYZ values under a given illuminant.
§Details
- Computes XYZ values for wavelengths from 380nm to 780nm in 1nm steps
- Multiplies observer color matching functions by illuminant spectrum
- Normalizes results relative to the illuminant’s white point
- Scales output to 100 lux illuminance
§Difference from Spectral Locus
While the spectral locus shows only chromaticity coordinates (x,y) of pure spectral colors, this method provides full XYZ values including luminance information.
§Implementation Notes
- Each wavelength is treated as a monochromatic stimulus (delta function)
- Results are typically low in magnitude due to the narrow bandwidth
- Values are normalized relative to the illuminant’s total energy
§Parameters
ref_white: Reference illuminant (e.g., D65, D50) for normalization
§Returns
Vector of (wavelength, RelXYZ) pairs, where:
- wavelength: nanometers (380-780nm)
- RelXYZ: relative tristimulus values scaled to 100 lux
pub fn trimmed_spectral_locus( &self, ref_white: CieIlluminant, ) -> Vec<(usize, RelXYZ)>
Sourcepub fn xyz_cie_table(
&self,
std_illuminant: &CieIlluminant,
illuminance: Option<f64>,
) -> XYZ
pub fn xyz_cie_table( &self, std_illuminant: &CieIlluminant, illuminance: Option<f64>, ) -> XYZ
Tristimulus values for the Standard Illuminants in this library.
Values are not normalized by default, unless an illuminance value is provided.
TODO: buffer values
Sourcepub fn xyz_d65(&self) -> XYZ
pub fn xyz_d65(&self) -> XYZ
XYZ tristimulus values for the CIE standard daylight illuminant D65 (buffered).
Sourcepub fn xyz_d50(&self) -> XYZ
pub fn xyz_d50(&self) -> XYZ
XYZ tristimulus values for the CIE standard daylight illuminant D50 (buffered).
Sourcepub fn xyz_planckian_locus(&self, cct: f64) -> XYZ
pub fn xyz_planckian_locus(&self, cct: f64) -> XYZ
Calculates XYZ tristimulus values for a Planckian emitter for this
observer. The to_wavelength`` function is used, as planck functions requires the wavelength to be in units of meters, and the xyz_from_illuminant_as_fn` uses functions over a domain from 0.0 to
1.0.
Sourcepub fn planckian_locus(&self) -> Vec<(f64, f64)>
pub fn planckian_locus(&self) -> Vec<(f64, f64)>
Calculates the chromaticity coordinates (x, y) of the Planckian locus over a range from 1000K to 100_000K.
Sourcepub fn xyz_planckian_locus_slope(&self, cct: f64) -> XYZ
pub fn xyz_planckian_locus_slope(&self, cct: f64) -> XYZ
The slope of the Plancking locus as a (dX/dT, dY/dT, dZ/dT) contained in a XYZ object.
Sourcepub fn calc_rgb2xyz_matrix_with_alt_white(
&self,
rgbspace: RgbSpace,
opt_white: Option<XYZ>,
) -> Matrix3<f64>
pub fn calc_rgb2xyz_matrix_with_alt_white( &self, rgbspace: RgbSpace, opt_white: Option<XYZ>, ) -> Matrix3<f64>
Calculates the RGB to XYZ matrix, for a particular color space, and an optional whitepoint. If no whitepoint is specified, the whitepoint of the colorspace will be used.
The main use for specifying whitepoints different than the RGB-space’s
default is with creating ICC color profiles, which requred the color space
to have a D50 whitepoint. Many colorspaces use D65. Setting the whitepoint
here to D50, the resulting column values can be used for the rXYZ, gXYZ, and
`bXYZ`` tags.
§Notes
- For default whitepoints, all the rgb2xyz matrices are already included in the [observer::rgbxyz.rs] module.
- XYZ is used here, instead of a spectrum, to explicitely use the XYZ values as required by the ICC profile standard.
Sourcepub fn calc_rgb2xyz_matrix(&self, rgbspace: RgbSpace) -> Matrix3<f64>
pub fn calc_rgb2xyz_matrix(&self, rgbspace: RgbSpace) -> Matrix3<f64>
Calculates the RGB to XYZ matrix, for a particular color space.
Don’t use this directly, as all the matrices are available through
Observer::rgb2xyz_matrix. The only use for this function is through
the xtask gen function, used when the library is extended with new
observers or new color spaces.
Sourcepub fn calc_xyz2rgb_matrix(&self, rgbspace: RgbSpace) -> Matrix3<f64>
pub fn calc_xyz2rgb_matrix(&self, rgbspace: RgbSpace) -> Matrix3<f64>
Calculates the XYZ to RGB matrix, for a particular color space. Don’t use this directly, as they are all precalculated and available through Observer::xyz2rgb.
Sourcepub fn spectral_locus_wavelength_range(&self) -> RangeInclusive<usize>
pub fn spectral_locus_wavelength_range(&self) -> RangeInclusive<usize>
Returns the wavelength range (in nanometer) for the horse shoe, the boundary of the area of all physical colors in a chromiticity diagram, for this observer.
Spectral locus points tend to freeze, or even fold back to lower wavelength values at the blue and red perimeter ends. This can be quite anoying, for example when trying to calculate dominant wavelength, or when creating plots. See Wikipedia’s CIE 1931 Color Space.
To help with the above problem, this method returns the wavelength range for which the spectral locus points are unique, meaning each wavelength has a chromaticity coordinate different from the wavelength below or above it.
To get the tristimulus values of the spectral locus, use
xyz_at_wavelength.
Sourcepub fn xyz_from_fn(&self, f: impl Fn(f64) -> f64) -> XYZ
pub fn xyz_from_fn(&self, f: impl Fn(f64) -> f64) -> XYZ
Calculates the XYZ tristimulus values for a spectrum defined by a function.
The input function f should accept a floating-point value in the range [0.0, 1.0],
where 0.0 corresponds to a wavelength of 380 nm and 1.0 to 780 nm.
The function will be called once for each wavelength step (401 times at 1 nm intervals).
§Arguments
f- A function that takes a floating-point value in the range[0.0, 1.0]and returns the spectral value at that wavelength, in units of watts per square meter per nanometer (W/m²/nm) for illuminants, or Watts per square meter per steradian per nanometer (W/m²/sr/nm) for stimuli.
§Notes
- This method is used in the library to compute the Planckian locus (the color of blackbody radiators), as described by Planck’s law.
- For colorants, use
xyz_from_colorant_fn.
Sourcepub fn xyz_from_colorant_fn(
&self,
illuminant: &CieIlluminant,
f: impl Fn(f64) -> f64,
) -> XYZ
pub fn xyz_from_colorant_fn( &self, illuminant: &CieIlluminant, f: impl Fn(f64) -> f64, ) -> XYZ
Calculates XYZ tristimulus values for an analytic representation of a spectral distribution of a filter or a color patch, using a normalized wavelength domain ranging from a value of 0.0 to 1.0, illuminated with a standard illuminant.
The spectral values should be defined within a range from 0.0 to 1.0, and are clamped otherwise. The resulting XYZ value will have relative Y values in the range from 0 to 100.0.
§Examples
A linear high pass filter, with a value of 0.0 for a wavelength of 380nm, and a value of 1.0 for 780nm, and converting the resulting value to RGB values.
use colorimetry::{rgb::RgbSpace::SRGB, observer::Observer::Cie1931, illuminant::CieIlluminant};
let rgb: [u8;3] = Cie1931.xyz_from_colorant_fn(&CieIlluminant::D65, |x|x).rgb(SRGB).clamp().into();
assert_eq!(rgb, [212, 171, 109]);Linear low pass filter, with a value of 1.0 for a wavelength of 380nm, and a value of 0.0 for 780nm, and converting the resulting value to RGB values.
use colorimetry::{rgb::RgbSpace::SRGB, observer::Observer::Cie1931, illuminant::CieIlluminant};
let rgb: [u8;3] = Cie1931.xyz_from_colorant_fn(&CieIlluminant::D65, |x|1.0-x).rgb(SRGB).clamp().into();
assert_eq!(rgb, [158, 202, 237]);Trait Implementations§
Source§impl<'de> Deserialize<'de> for Observer
impl<'de> Deserialize<'de> for Observer
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 IntoEnumIterator for Observer
impl IntoEnumIterator for Observer
type Iterator = ObserverIter
fn iter() -> ObserverIter ⓘ
impl Copy for Observer
impl Eq for Observer
impl StructuralPartialEq for Observer
Auto Trait Implementations§
impl Freeze for Observer
impl RefUnwindSafe for Observer
impl Send for Observer
impl Sync for Observer
impl Unpin for Observer
impl UnwindSafe for Observer
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§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).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.