Color/Space/Instance/HunterLAB.pm

filter: Statementstmt 100% 26 / 26 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 2 totaltotal 94.5% 35 / 37 CC 3 SCAR 6.2
CC
3
Cov
100%
to_lab
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.9
« Color/Space/Instance/OKHSV.pm ↑ Summary Color/Space/Instance/Helper/OK.pm »
1  
2 # Hunter lab color space, pre CIELAB, for Illuminant D65 and Observer 2 degree
3  
4 package Graphics::Toolkit::Color::Space::Instance::HunterLAB;
5 16 ▶use v5.12;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 16 ▶use Graphics::Toolkit::Color::Space qw/round_decimals/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 16 my @D65 = (0.95047, 1, 1.08883); # illuminant
10 16 my %K = ( a => round_decimals(175.0 / 198.04 * ($D65[1] + $D65[0]) * 100, 5),
11 b => round_decimals( 70.0 / 218.11 * ($D65[1] + $D65[2]) * 100, 5), );
12  
13  
14 5 ▶sub from_lab {
Subroutine from_lab: called CC=1 SCAR=0.0
Pod undocumented
15 5 my ($lab) = shift;
16 5 my $l = $lab->[0];
17 5 my $a = ($lab->[1] - .5) * 2;
18 5 my $b = ($lab->[2] - .5) * 2;
19 5 my $y = $l ** 2;
20 5 my $x = ($a * $l) + $y;
21 5 my $z = $y - ($b * $l);
22 5 return ([$x, $y, $z]);
23 }
24 4 ▶sub to_lab {
Subroutine to_lab: called CC=3 SCAR=11.0
Pod undocumented
25 4 my ($xyz) = shift;
26 4 my $l = sqrt $xyz->[1];
27 4 ▶ my $a = $l ? (($xyz->[0] - $xyz->[1])/$l) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$l ? : 3 1 4
28 4 ▶ my $b = $l ? (($xyz->[1] - $xyz->[2])/$l) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$l ? : 3 1 4
29 4 $a = ($a / 2) + .5;
30 4 $b = ($b / 2) + .5;
31 4 return ([$l, $a, $b]);
32 }
33  
34 Graphics::Toolkit::Color::Space->new(
35 name => 'HunterLAB',
36 family => 'LAB',
37 axis => [qw/l a b/], # same as short
38 16 range => [100, [-$K{'a'}, $K{'a'}], [-$K{'b'}, $K{'b'}]], # cyan-orange, magenta-green
39 precision => 3,
40 convert => {XYZ => [\&from_lab, \&to_lab]},
41 );
« Color/Space/Instance/OKHSV.pm ↑ Summary Color/Space/Instance/Helper/OK.pm »