Skip to main content

colr/
lib.rs

1#![no_std]
2#![warn(missing_docs)]
3#![doc = include_str!("../README.md")]
4
5#[cfg(feature = "std")]
6extern crate std;
7
8mod operations;
9
10use core::marker::PhantomData;
11
12pub use colr_types::*;
13
14/// A color value in color model `M` backed by raw type `S`.
15///
16/// `M: BackingStore<S>` is the only construction gate. For RGB spaces the
17/// layout is encoded in `M` as `RgbSpace<P, TF, L>`.
18#[repr(transparent)]
19#[derive(Debug, Clone, Copy, PartialEq)]
20pub struct Color<S, M>
21where
22    S: Copy,
23    M: BackingStore<S>,
24{
25    storage: S,
26    _model: PhantomData<M>,
27}
28
29/// Spectral radiance on the 31-band ICC grid (400-700 nm, 10 nm).
30pub type SpectralColor31Radiance = Color<[f32; 31], model::Spectral31Radiance>;
31/// Spectral reflectance on the 31-band ICC grid (400-700 nm, 10 nm).
32pub type SpectralColor31Reflectance = Color<[f32; 31], model::Spectral31Reflectance>;
33/// Spectral transmittance on the 31-band ICC grid (400-700 nm, 10 nm).
34pub type SpectralColor31Transmittance = Color<[f32; 31], model::Spectral31Transmittance>;
35
36/// Spectral radiance on the 36-band Stam rendering grid (380-730 nm, 10 nm).
37pub type SpectralColor36Radiance = Color<[f32; 36], model::Spectral36Radiance>;
38/// Spectral reflectance on the 36-band Stam rendering grid (380-730 nm, 10 nm).
39pub type SpectralColor36Reflectance = Color<[f32; 36], model::Spectral36Reflectance>;
40/// Spectral transmittance on the 36-band Stam rendering grid (380-730 nm, 10 nm).
41pub type SpectralColor36Transmittance = Color<[f32; 36], model::Spectral36Transmittance>;
42
43/// Spectral radiance on the 41-band full-visible grid (380-780 nm, 10 nm).
44pub type SpectralColor41Radiance = Color<[f32; 41], model::Spectral41Radiance>;
45/// Spectral reflectance on the 41-band full-visible grid (380-780 nm, 10 nm).
46pub type SpectralColor41Reflectance = Color<[f32; 41], model::Spectral41Reflectance>;
47/// Spectral transmittance on the 41-band full-visible grid (380-780 nm, 10 nm).
48pub type SpectralColor41Transmittance = Color<[f32; 41], model::Spectral41Transmittance>;
49
50/// Spectral radiance on the 81-band CIE standard grid (380-780 nm, 5 nm).
51pub type SpectralColor81Radiance = Color<[f32; 81], model::Spectral81Radiance>;
52/// Spectral reflectance on the 81-band CIE standard grid (380-780 nm, 5 nm).
53pub type SpectralColor81Reflectance = Color<[f32; 81], model::Spectral81Reflectance>;
54/// Spectral transmittance on the 81-band CIE standard grid (380-780 nm, 5 nm).
55pub type SpectralColor81Transmittance = Color<[f32; 81], model::Spectral81Transmittance>;
56
57impl<S, M> Color<S, M>
58where
59    S: Copy,
60    M: BackingStore<S>,
61{
62    /// Construct without bounds checking.
63    #[inline(always)]
64    pub fn new(storage: S) -> Self {
65        Self {
66            storage,
67            _model: PhantomData,
68        }
69    }
70
71    /// Returns the underlying storage value.
72    #[inline(always)]
73    pub fn inner(&self) -> S {
74        self.storage
75    }
76}