Observer

Enum Observer 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Cie1931

§

Cie1964

§

Cie2015

§

Cie2015_10

Implementations§

Source§

impl Observer

Source

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

Source

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

Source

pub fn name(&self) -> &'static str

Returns the name of the observer.

Source

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.

Source

pub fn rel_xyz(&self, light: &dyn Light, filter: &dyn Filter) -> RelXYZ

Source

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.

Source

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 as CieIlluminant.
  • filter - A reference to an object implementing the Filter trait, such as Colorant.
§Returns
  • CieLab - The computed CIELAB color representation for the light and filter combination.
Source

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.

Source

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.

Source

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 as CieIlluminant.
  • filter - A reference to an object implementing the Filter trait, such as Colorant.
  • 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.
Source

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 as CieIlluminant.
  • filter - A reference to an object implementing the Filter trait, such as Colorant.
  • 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.
Source

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

Source

pub fn y_from_spectrum(&self, spectrum: &Spectrum) -> f64

Calculates the lumimous value or Y tristimulus value for a general spectrum.

Source

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.

Source

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
Source

pub fn trimmed_spectral_locus( &self, ref_white: CieIlluminant, ) -> Vec<(usize, RelXYZ)>

Source

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

Source

pub fn xyz_d65(&self) -> XYZ

XYZ tristimulus values for the CIE standard daylight illuminant D65 (buffered).

Source

pub fn xyz_d50(&self) -> XYZ

XYZ tristimulus values for the CIE standard daylight illuminant D50 (buffered).

Source

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.

Source

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.

Source

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.

Source

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.
Source

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.

Source

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.

Source

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.

Source

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.
Source

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 AsRef<str> for Observer

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Observer

Source§

fn clone(&self) -> Observer

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

Source§

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

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

impl Default for Observer

Source§

fn default() -> Observer

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

impl<'de> Deserialize<'de> for Observer

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 Display for Observer

Source§

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

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

impl EnumCount for Observer

Source§

const COUNT: usize = 4usize

Source§

impl Hash for Observer

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 IntoEnumIterator for Observer

Source§

impl PartialEq for Observer

Source§

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

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 Copy for Observer

Source§

impl Eq for Observer

Source§

impl StructuralPartialEq for Observer

Auto Trait Implementations§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.
Source§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

Source§

fn is_within(&self, b: &G2) -> bool

Source§

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

Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,