|
| 1 | +//! Types for the CIE CAM16 color appearance model. |
| 2 | +
|
| 3 | +use crate::{ |
| 4 | + angle::{RealAngle, SignedAngle}, |
| 5 | + bool_mask::LazySelect, |
| 6 | + num::{Abs, Arithmetics, One, PartialCmp, Powf, Real, Signum, Sqrt, Trigonometry, Zero}, |
| 7 | + white_point::{self}, |
| 8 | + Xyz, |
| 9 | +}; |
| 10 | + |
| 11 | +pub use full::*; |
| 12 | +pub use parameters::*; |
| 13 | +pub use partial::*; |
| 14 | +pub use ucs_jab::*; |
| 15 | +pub use ucs_jmh::*; |
| 16 | + |
| 17 | +mod full; |
| 18 | +mod math; |
| 19 | +mod parameters; |
| 20 | +mod partial; |
| 21 | +mod ucs_jab; |
| 22 | +mod ucs_jmh; |
| 23 | + |
| 24 | +/// Converts a color to CAM16, using a set of parameters. |
| 25 | +pub trait IntoCam16<WpParam, T> { |
| 26 | + /// Convert `self` into CAM16, with `parameters` that describe the viewing |
| 27 | + /// conditions. |
| 28 | + fn into_cam16(self, parameters: BakedParameters<WpParam, T>) -> Cam16<T>; |
| 29 | +} |
| 30 | + |
| 31 | +impl<WpParam, T> IntoCam16<WpParam, T> for Xyz<WpParam::StaticWp, T> |
| 32 | +where |
| 33 | + WpParam: WhitePointParameter<T>, |
| 34 | + T: Real + Arithmetics + Powf + Sqrt + Abs + Signum + Trigonometry + RealAngle + Clone, |
| 35 | +{ |
| 36 | + fn into_cam16(self, parameters: BakedParameters<WpParam, T>) -> Cam16<T> { |
| 37 | + math::xyz_to_cam16(self.with_white_point(), parameters.inner) |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +/// Converts CAM16 to a color, using a set of parameters. |
| 42 | +pub trait FromCam16<WpParam, T>: Sized { |
| 43 | + /// Convert `cam16` into `Self`, with `parameters` that describe the viewing |
| 44 | + /// conditions. |
| 45 | + fn from_cam16(cam16: Cam16<T>, parameters: BakedParameters<WpParam, T>) -> Self { |
| 46 | + Self::from_partial_cam16(DynPartialCam16::from(cam16), parameters) |
| 47 | + } |
| 48 | + |
| 49 | + /// Convert the partially specified `cam16` into `Self`, with `parameters` |
| 50 | + /// that describe the viewing conditions. |
| 51 | + fn from_partial_cam16<L, C>( |
| 52 | + cam16: PartialCam16<T, L, C>, |
| 53 | + parameters: BakedParameters<WpParam, T>, |
| 54 | + ) -> Self |
| 55 | + where |
| 56 | + L: Cam16Luminance<T>, |
| 57 | + C: Cam16Chromaticity<T>; |
| 58 | +} |
| 59 | + |
| 60 | +impl<WpParam, T> FromCam16<WpParam, T> for Xyz<WpParam::StaticWp, T> |
| 61 | +where |
| 62 | + WpParam: WhitePointParameter<T>, |
| 63 | + T: Real |
| 64 | + + One |
| 65 | + + Zero |
| 66 | + + Sqrt |
| 67 | + + Powf |
| 68 | + + Abs |
| 69 | + + Signum |
| 70 | + + Arithmetics |
| 71 | + + Trigonometry |
| 72 | + + RealAngle |
| 73 | + + SignedAngle |
| 74 | + + PartialCmp |
| 75 | + + Clone, |
| 76 | + T::Mask: LazySelect<Xyz<white_point::Any, T>>, |
| 77 | +{ |
| 78 | + fn from_partial_cam16<L, C>( |
| 79 | + cam16: PartialCam16<T, L, C>, |
| 80 | + parameters: BakedParameters<WpParam, T>, |
| 81 | + ) -> Self |
| 82 | + where |
| 83 | + L: Cam16Luminance<T>, |
| 84 | + C: Cam16Chromaticity<T>, |
| 85 | + { |
| 86 | + math::cam16_to_xyz(cam16.into_dynamic(), parameters.inner).with_white_point() |
| 87 | + } |
| 88 | +} |
0 commit comments