Skip to content

Commit 683399d

Browse files
committed
Fill out invert function precision UTs
Interestingly, Oklab is the worst. IIRC I'm using his official inversions, maybe I should calc my own? Or maybe its just pow3..
1 parent e9b727e commit 683399d

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

src/tests.rs

+25-12
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const XYZ: &'static [[f64; 3]] = &[
5656
[204.19951828, 211.79115169, 588.01504694],
5757
[-0.64593653, -0.71965944, -1.20325077],
5858
];
59-
const LAB: &'static [[f64; 3]] = &[
59+
const CIELAB: &'static [[f64; 3]] = &[
6060
[0.00000000, 0.00000000, 0.00000000],
6161
[53.23288179, 80.11117774, 67.22370367],
6262
[87.73703347, -86.18285500, 83.18783466],
@@ -314,20 +314,20 @@ fn xyz_backwards() {
314314

315315
#[test]
316316
fn lab_forwards() {
317-
func_cmp(XYZ, LAB, xyz_to_cielab)
317+
func_cmp(XYZ, CIELAB, xyz_to_cielab)
318318
}
319319
#[test]
320320
fn lab_backwards() {
321-
func_cmp(LAB, XYZ, cielab_to_xyz)
321+
func_cmp(CIELAB, XYZ, cielab_to_xyz)
322322
}
323323

324324
#[test]
325325
fn lch_forwards() {
326-
func_cmp(LAB, LCH, lab_to_lch)
326+
func_cmp(CIELAB, LCH, lab_to_lch)
327327
}
328328
#[test]
329329
fn lch_backwards() {
330-
func_cmp(LCH, LAB, lch_to_lab)
330+
func_cmp(LCH, CIELAB, lch_to_lab)
331331
}
332332

333333
#[test]
@@ -349,14 +349,27 @@ fn jzazbz_backwards() {
349349
func_cmp(JZAZBZ, XYZ, jzazbz_to_xyz)
350350
}
351351

352-
// ICtCp development tests.
353-
// Inversion test in absence of solid reference
354352
#[test]
355-
fn ictcp_inversion() {
356-
let mut pixel = LRGB.to_owned();
357-
pixel.iter_mut().for_each(|p| _lrgb_to_ictcp(p));
358-
pixel.iter_mut().for_each(|p| _ictcp_to_lrgb(p));
359-
pix_cmp(&pixel, LRGB, 1e-3, &[]);
353+
fn inversions() {
354+
let runs: &[(&[[f64; 3]], fn(pixel: &mut [f64; 3]), fn(pixel: &mut [f64; 3]), &str)] = &[
355+
(SRGB, srgb_to_hsv, hsv_to_srgb, "HSV"),
356+
(SRGB, srgb_to_lrgb, lrgb_to_srgb, "LRGB"),
357+
(LRGB, lrgb_to_xyz, xyz_to_lrgb, "XYZ"), // 1e-4
358+
(LRGB, _lrgb_to_ictcp, _ictcp_to_lrgb, "ICTCP"), // 1e-4
359+
(XYZ, xyz_to_cielab, cielab_to_xyz, "CIELAB"),
360+
(XYZ, xyz_to_oklab, oklab_to_xyz, "OKLAB"), // 1e-3
361+
(XYZ, xyz_to_jzazbz, jzazbz_to_xyz, "JZAZBZ"), // 1e-4
362+
(CIELAB, lab_to_lch, lch_to_lab, "LCH"),
363+
];
364+
for (pixel, fwd, bwd, label) in runs.iter() {
365+
let mut owned = pixel.to_vec();
366+
owned.iter_mut().for_each(|p| {
367+
fwd(p);
368+
bwd(p);
369+
});
370+
println!("TEST {} INVERSION", label);
371+
pix_cmp(&owned, pixel, 1e-3, &[]);
372+
}
360373
}
361374
// Disable reference tests for public commits
362375
//

0 commit comments

Comments
 (0)