Expand description
Optional module implementing the traversal of the human visual gamut.
This module reflects a somewhat unsatisfactory compromise between what’s
possible in Rust and what’s necessary for PyO3. In particular, PyO3 requires
monomorphic enums/structs with monomorphic method implementations and does not
support generic anything. The PyO3 guide justifies this restriction with the
fact that the Rust compiler produces monomorphic code only. While correct, PyO3
complicates matters significantly by not supporting trait methods, its
#[pymethods] macro disallowing item-level macros, and its error checking
ignoring #[cfg] attributes. The impact is noticeable: Whereas Rust code
might get by with four different implementations of SpectralDistribution’s
methods, Python integration necessitates another three.
The SpectralDistribution trait defines an interface for mapping a fixed,
nanometer-aligned range of wavelengths at 1nm resolution to values. With
wavelengths restricted to integral nanometers, the interfaces uses usize
for their representation. Meanwhile, values are represented by an associated
type, which is Float for illuminants and [Float; 3] for observers.
This module includes the following implementations of the trait:
Observeris a table-driven implementation ofSpectralDistribution<Value=[Float;3]>.TabularDistributionis a table-driven implementation ofSpectralDistribution<Value=Float>.FixedDistributionis an implementation ofSpectralDistribution<Value=Float>with a fixed value.Illuminantis an implementation ofSpectralDistribution<Value=Float>that wraps aBox<dyn SpectralDistribution<Value=Float> + Send + Sync>.IlluminatedObserveris a table-driven implementation ofSpectralDistribution<Value=[Float;3]>. Its data is the result of the per-wavelength multiplication of aSpectralDistribution<Value=Float>and aSpectralDistribution<Value=[Float;3]>, i.e., an illuminant and an observer.
To play nice with PyO3 and Python, Observer and IlluminatedObserver
reimplement all but one trait method in their impl blocks. Illuminant
does the same, but is only defined if the pyffi feature is enabled. It
makes two different trait implementations appear as the same type type in
Python and allows instances to be passed back to Rust.
Using the above trait implementations, this module exports the following concrete illuminants and observers, with data directly sourced from the CIE.
CIE_ILLUMINANT_D50approximates daylight near sunrise and sunset.CIE_ILLUMINANT_D65approximates daylight around noon.CIE_ILLUMINANT_Ehas equal energy.CIE_OBSERVER_2DEG_1931is the 1931 2º color matching function.CIE_OBSERVER_10DEG_1964is the 1964 10º color matching function.
A submodule provides std_observer::x(), std_observer::y(), and
std_observer::z() as analytical approximations for the 1931 2º observer.
As such, all three functions accept floating point arguments for
wavelengths.
Finally, SpectrumTraversal is an iterator for tracing the spectral locus
or the human visual gamut. It is instantiated with
IlluminatedObserver::visual_gamut.
In Python, the constructor accepts &Illuminant and &Observer
arguments only, which makes it monomorphic. While that is insufficient
for generally overcoming PyO3’s prohibition against polymorphic anything,
in this particular case it suffices because spectrum traversal’s
constructors do not retain their inputs and instead keep the result of
premultiplying the two spectral distributions. In other words, the rest
of SpectrumTraversal’s implementation is strictly monomophic itself.
Modules§
- std_
observer - Free-standing functions related to the CIE standard observer.
Structs§
- Fixed
Distribution - A spectral distribution with a fixed floating point value.
- Illuminant
- An illuminant at nanometer resolution. Python only!
- Illuminated
Observer - An illuminated observer at nanometer resolution.
- Observer
- A standard observer at nanometer resolution.
- Spectrum
Traversal - An iterator tracing the visual gamut.
- Tabular
Distribution - A table-driven spectral distribution over floating point values.
Constants§
- ONE_
NANOMETER - A convenient constant for 1nm.
Statics§
- CIE_
ILLUMINANT_ D50 - The CIE D50 standard illuminant at 1nm resolution.
- CIE_
ILLUMINANT_ D65 - The CIE D65 standard illuminant at 1nm resolution.
- CIE_
ILLUMINANT_ E - The CIE standard illuminant E at 1nm resolution.
- CIE_
OBSERVER_ 2DEG_ 1931 - The CIE 1931 2º standard observer at 1nm resolution.
- CIE_
OBSERVER_ 10DEG_ 1964 - The CIE 1964 10º standard observer at 1nm resolution.
Traits§
- Spectral
Distribution - A spectral distribution at nanometer resolution.