File Coverage

lib/Graphics/Toolkit/Color/Space/Instance/AppleRGB.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             # Apple RGB 1998 (illuminant D65, gamma 1.8)
3              
4             package Graphics::Toolkit::Color::Space::Instance::AppleRGB;
5 15     15   420245 use v5.12;
  15         59  
6 15     15   91 use warnings;
  15         27  
  15         949  
7 15     15   755 use Graphics::Toolkit::Color::Space qw/gamma_correct mult_matrix_vector_3/;
  15         26  
  15         6922  
8              
9             my @D65 = (.95047, 1, 1.08883);
10             my $gamma = 1.8;
11              
12             sub from_xyz {
13 4     4 0 8 my ($xyz) = [ @{$_[0]} ];
  4         10  
14 4         49 $xyz->[$_] *= $D65[ $_ ] for 0 .. 2;
15 4         24 my @rgb = mult_matrix_vector_3( [[ 2.9515373, -1.2894116, -0.4738445 ],
16             [ -1.0851093, 1.9908566, 0.0372026 ],
17             [ 0.0854934, -0.2694964, 1.0912975 ] ], @$xyz);
18 4         17 return [map {gamma_correct($_, 1 / $gamma)} @rgb];
  12         2510  
19             }
20             sub to_xyz {
21 4     4 0 8 my $rgb = shift;
22 4         11 $rgb = [map {gamma_correct($_, $gamma)} @$rgb];
  12         27  
23 4         22 my @xyz = mult_matrix_vector_3( [[ 0.4497288, 0.3162486, 0.1844926 ],
24             [ 0.2446525, 0.6720283, 0.0833192 ],
25             [ 0.0251848, 0.1411824, 0.9224628 ] ], @$rgb);
26 4         47 $xyz[$_] /= $D65[ $_ ] for 0 .. 2;
27 4         19 return \@xyz;
28             }
29            
30             Graphics::Toolkit::Color::Space->new(
31             name => 'AppleRGB',
32             axis => [qw/red green blue/],
33             precision => 6,
34             convert => {XYZ => [\&to_xyz, \&from_xyz]},
35             );