From 9b55b2a84bf9ae8b712a883a00cb6c4ee462904b Mon Sep 17 00:00:00 2001 From: vadimr Date: Sun, 23 Jan 2022 18:51:47 +0000 Subject: [PATCH] fix t_xyz2lab --- CHANGES | 2 ++ lib/PDL/Transform/Color.pm | 4 +--- t/color.t | 8 +++++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index 0bdd542..98b24aa 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,5 @@ +- fix t_xyz2lab - thanks @vadim-160102 + 1.005 2020-09-17 - eliminate // to keep 5.006 compat diff --git a/lib/PDL/Transform/Color.pm b/lib/PDL/Transform/Color.pm index 9560a0a..a25c58b 100644 --- a/lib/PDL/Transform/Color.pm +++ b/lib/PDL/Transform/Color.pm @@ -1539,9 +1539,7 @@ sub t_xyz2lab { my $wp_xyy = xyy_from_illuminant($me->{params}->{white}); $me->{params}->{wp_xyz} = $wp_xyy->copy; $me->{params}->{wp_xyz}->slice('2') .= 1 - $wp_xyy->slice('0') - $wp_xyy->slice('1'); - $me->{params}->{wp_xyz} *= $wp_xyy->slice('2'); - - + $me->{params}->{wp_xyz} *= $wp_xyy->slice('2') / $wp_xyy->slice('1'); # input is XYZ by the time it gets here $me->{func} = sub { my($in,$opt) = @_; diff --git a/t/color.t b/t/color.t index fdfba5e..05a9ce7 100644 --- a/t/color.t +++ b/t/color.t @@ -167,11 +167,17 @@ ok(all( ($aa > $a -1e-10) & ($aa < $a + 1e-10) ),"decoding undoes coding"); # (minimal testing) $a = xvals(101)/100; eval {$t = t_pc();}; -ok(($@ && $@=~m/^Usage\:/), "t_pc with no arguments died and threw out an info message"); +like $@, qr/^Usage\:/, "t_pc with no arguments died and threw out an info message"; eval {$t = t_pc('sepia');}; is $@, '', "t_pc('sepia') ran OK"; eval {$b=$a->apply($t);}; is $@, '', "t_pc applied OK"; ok($b->ndims==2 && $b->dim(0)==3, "t_pc created an RGB output"); +eval {$t = t_xyz2lab();}; +is $@, '', "t_xyz2lab ran OK"; +eval {$b=pdl(1,1,1)->apply($t);}; +is $@, '', "t_xyz2lab applied OK"; +ok all(approx $b, pdl(100, 8.5841461, 5.5183538)), 't_xyz2lab right values' or diag "got=$b"; + done_testing;