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 16     16   284480 use v5.12;
  16         46  
6 16     16   55 use warnings;
  16         24  
  16         688  
7 16     16   470 use Graphics::Toolkit::Color::Space qw/spow mult_matrix_vector_3/;
  16         37  
  16         5128  
8              
9             my @D65 = (0.95047, 1, 1.08883);
10             my $gamma = 563/256;
11              
12             sub from_rgb {
13 10     10 0 12 my $rgb = shift;
14 10         17 $rgb = [map {spow($_, $gamma)} @$rgb];
  30         41  
15 10         30 my @xyz = mult_matrix_vector_3( [[ 0.6783443412, 0.0830145686, 0.1891110902 ],
16             [ 0.2404959276, 0.7303774055, 0.0291266669 ],
17             [ 0.0035183140, 0.0552567894, 1.0300548966 ], ], @$rgb) ;
18 10         48 $xyz[$_] /= $D65[ $_ ] for 0 .. 2;
19 10         21 return \@xyz;
20             }
21             sub to_rgb {
22 10     10 0 12 my ($xyz) = [ @{$_[0]} ];
  10         18  
23 10         38 $xyz->[$_] *= $D65[ $_ ] for 0 .. 2;
24 10         30 my @rgb = mult_matrix_vector_3( [[ 1.5298411986, -0.1529595712, -0.2765432555 ],
25             [ -0.5046114854, 1.4225435133, 0.0524182519 ],
26             [ 0.0218442230, -0.0757891912, 0.9689546693 ], ], @$xyz);
27 10         23 return [map {spow($_, (1/$gamma))} @rgb];
  30         44  
28             }
29            
30             Graphics::Toolkit::Color::Space->new(
31             name => 'WideGamutRGB',
32             family => 'RGB',
33             axis => [qw/red green blue/],
34             precision => 6,
35             convert => {XYZ => [\&from_rgb, \&to_rgb]},
36             );