Skip to content

Commit 95b77b8

Browse files
authored
Merge 3299027 into ee54371
2 parents ee54371 + 3299027 commit 95b77b8

27 files changed

+2654
-272
lines changed

.github/workflows/ci.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,17 @@ jobs:
3131
- name: find-crate check
3232
run: cargo check -v -p palette --no-default-features --features "std find-crate"
3333
- name: Default check
34-
run: cargo check -v --workspace --exclude no_std_test
35-
- run: cargo test -v
34+
run: cargo check -v -p palette
35+
- name: Full check
36+
run: cargo check -v -p palette --all-features
37+
- run: cargo test -v -p palette --all-features
3638
- name: Test features
3739
shell: bash
3840
working-directory: palette
3941
run: bash ../scripts/test_features.sh
4042
- name: "Test #[no_std]"
4143
if: ${{ runner.os == 'Linux' && matrix.toolchain == 'nightly' }}
42-
run: cargo build -v --package no_std_test --features nightly --target thumbv6m-none-eabi
44+
run: cargo build -v --package no_std_test --all-features --target thumbv6m-none-eabi
4345
miri:
4446
name: Miri tests
4547
runs-on: ubuntu-latest

.vscode/settings.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
"random",
44
"serializing",
55
"bytemuck",
6-
"wide"
6+
"wide",
7+
"cam16"
78
],
89
"rust-analyzer.imports.granularity.enforce": true,
910
"rust-analyzer.imports.granularity.group": "crate",
1011
"rust-analyzer.imports.group.enable": true
11-
}
12+
}

no_std_test/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ bench = false
1414

1515
[features]
1616
nightly = []
17+
all_features = ["palette/libm", "palette/named_from_str", "palette/cam16"]
1718

1819
[dependencies.libc]
1920
version = "0.2"
@@ -22,4 +23,3 @@ default-features = false
2223
[dependencies.palette]
2324
path = "../palette"
2425
default-features = false
25-
features = ["libm", "named_from_str"]

palette/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ build = "build/main.rs"
2828

2929
[features]
3030
default = ["named_from_str", "std", "approx"]
31+
cam16 = ["palette_derive/cam16"]
3132
named_from_str = ["named", "phf"]
3233
named = []
3334
random = ["rand"]

palette/src/cam16.rs

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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

Comments
 (0)