File Coverage

lib/Graphics/Toolkit/Color/Space/Instance/CIELCHuv.pm
Criterion Covered Total %
statement 21 21 100.0
branch 6 6 100.0
condition n/a
subroutine 5 5 100.0
pod 0 2 0.0
total 32 34 94.1


line stmt bran cond sub pod time code
1              
2             # CIE LCh(uv) cylindrical color space variant of CIELUV
3              
4             package Graphics::Toolkit::Color::Space::Instance::CIELCHuv;
5 15     15   295441 use v5.12;
  15         58  
6 15     15   107 use warnings;
  15         28  
  15         1009  
7 15     15   847 use Graphics::Toolkit::Color::Space qw/round_decimals/;
  15         28  
  15         6484  
8              
9             my $TAU = 6.283185307;
10              
11             sub from_luv {
12 6     6 0 15 my ($luv) = shift;
13 6         24 my $u = $luv->[1] * 354 - 134;
14 6         17 my $v = $luv->[2] * 262 - 140;
15 6 100       21 $u = 0 if round_decimals($u, 5) == 0;
16 6 100       17 $v = 0 if round_decimals($v, 5) == 0;
17 6         29 my $c = sqrt( ($u**2) + ($v**2));
18 6         93 my $h = atan2($v, $u);
19 6 100       23 $h += $TAU if $h < 0;
20 6         39 return ([$luv->[0], $c / 261, $h / $TAU ]);
21             }
22             sub to_luv {
23 6     6 0 18 my ($lch) = shift;
24 6         75 my $u = $lch->[1] * cos($lch->[2] * $TAU) * 261;
25 6         25 my $v = $lch->[1] * sin($lch->[2] * $TAU) * 261;
26 6         44 return ([$lch->[0], ($u+134) / 354, ($v+140) / 262 ]);
27             }
28              
29             Graphics::Toolkit::Color::Space->new(
30             name => 'CIELCHuv',
31             alias => 'LCHuv',
32             axis => [qw/luminance chroma hue/],
33             type => [qw/linear linear angular/],
34             range => [100, 261, 360],
35             precision => 3,
36             convert => {LUV => [\&to_luv, \&from_luv]},
37             );