File Coverage

lib/Graphics/Toolkit/Color/Space/Instance/WideGamutRGB.pm
Criterion Covered Total %
statement 20 20 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod 0 2 0.0
total 25 27 92.5


line stmt bran cond sub pod time code
1              
2             # Wide Gamut RGB, D50 (Adobe)
3              
4             package Graphics::Toolkit::Color::Space::Instance::WideGamutRGB;
5 15     15   432698 use v5.12;
  15         57  
6 15     15   87 use warnings;
  15         23  
  15         915  
7 15     15   512 use Graphics::Toolkit::Color::Space qw/gamma_correct mult_matrix_vector_3/;
  15         57  
  15         6806  
8              
9             my @D50 = (0.96422, 1, 0.82521);
10             my @D65 = (0.95047, 1, 1.08883);
11             my $gamma = 563/256;
12              
13             sub from_xyz {
14 4     4 0 8 my ($xyz) = [ @{$_[0]} ];
  4         10  
15 4         24 $xyz->[$_] *= $D65[ $_ ] for 0 .. 2;
16 4         24 my @rgb = mult_matrix_vector_3( [[ 1.5298411986, -0.1529595712, -0.2765432555 ],
17             [ -0.5046114854, 1.4225435133, 0.0524182519 ],
18             [ 0.0218442230, -0.0757891912, 0.9689546693 ], ], @$xyz);
19 4         18 return [map {gamma_correct($_, (1/$gamma))} @rgb];
  12         32  
20             }
21             sub to_xyz {
22 4     4 0 8 my $rgb = shift;
23 4         10 $rgb = [map {gamma_correct($_, $gamma)} @$rgb];
  12         30  
24 4         19 my @xyz = mult_matrix_vector_3( [[ 0.6783443412, 0.0830145686, 0.1891110902 ],
25             [ 0.2404959276, 0.7303774055, 0.0291266669 ],
26             [ 0.0035183140, 0.0552567894, 1.0300548966 ], ], @$rgb) ;
27 4         27 $xyz[$_] /= $D65[ $_ ] for 0 .. 2;
28 4         17 return \@xyz;
29             }
30            
31             Graphics::Toolkit::Color::Space->new(
32             name => 'WideGamutRGB',
33             axis => [qw/red green blue/],
34             precision => 6,
35             convert => {XYZ => [\&to_xyz, \&from_xyz]},
36             );