File Coverage

lib/Graphics/Toolkit/Color/Space/Instance/AdobeRGB.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             # Adobe RGB (1998) color space, D65 IEC 61966-2-5:2007, ISO 12640-4:2011
3              
4             package Graphics::Toolkit::Color::Space::Instance::AdobeRGB;
5 16     16   279651 use v5.12;
  16         60  
6 16     16   58 use warnings;
  16         22  
  16         682  
7 16     16   416 use Graphics::Toolkit::Color::Space qw/spow mult_matrix_vector_3/;
  16         22  
  16         5486  
8              
9             my @D65 = (.95047, 1, 1.08883);
10             my $gamma = 563/256;
11              
12             sub from_rgb {
13 4     4 0 5 my $rgb = shift;
14 4         18 $rgb = [map {spow($_, $gamma)} @$rgb];
  12         15  
15 4         11 my @xyz = mult_matrix_vector_3( [[ 0.5767309, 0.1855540, 0.1881852 ],
16             [ 0.2973769, 0.6273491, 0.0752741 ],
17             [ 0.0270343, 0.0706872, 0.9911085 ] ], @$rgb);
18 4         16 $xyz[$_] /= $D65[ $_ ] for 0 .. 2;
19 4         10 return \@xyz;
20             }
21             sub to_rgb {
22 4     4 0 5 my ($xyz) = [ @{$_[0]} ];
  4         5  
23 4         16 $xyz->[$_] *= $D65[ $_ ] for 0 .. 2;
24 4         14 my @rgb = mult_matrix_vector_3( [[ 2.0413690, -0.5649464, -0.3446944 ],
25             [ -0.9692660, 1.8760108, 0.0415560 ],
26             [ 0.0134474, -0.1183897, 1.0154096 ] ], @$xyz);
27 4         10 return [map {spow($_, 1 / $gamma)} @rgb];
  12         16  
28             }
29            
30             Graphics::Toolkit::Color::Space->new(
31             name => 'AdobeRGB',
32             alias_name => 'opRGB',
33             family => 'RGB',
34             axis => [qw/red green blue/],
35             precision => 6,
36             convert => {CIEXYZ => [\&from_rgb, \&to_rgb]},
37             );