File Coverage

lib/Graphics/Toolkit/Color/Space/Instance/YIQ.pm
Criterion Covered Total %
statement 17 17 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod 0 2 0.0
total 22 24 91.6


line stmt bran cond sub pod time code
1              
2             # YIQ color space specific code
3              
4             package Graphics::Toolkit::Color::Space::Instance::YIQ;
5 16     16   255305 use v5.12;
  16         45  
6 16     16   73 use warnings;
  16         28  
  16         796  
7 16     16   490 use Graphics::Toolkit::Color::Space qw/mult_matrix_vector_3/;
  16         22  
  16         4948  
8              
9             my ($i_max, $q_max) = (0.5959, 0.5227);
10             my ($i_range_size, $q_range_size) = (2 * $i_max, 2 * $q_max);
11             # cyan-orange balance, magenta-green balance
12             sub from_yiq {
13 5     5 0 8 my ($yiq) = shift;
14 5         12 $yiq->[1] = $yiq->[1] * $i_range_size - $i_max;
15 5         7 $yiq->[2] = $yiq->[2] * $q_range_size - $q_max;
16 5         21 return [ mult_matrix_vector_3([[1, 0.95605, 0.620755],
17             [1, -0.272052, -0.647206],
18             [1, -1.1067, 1.70442 ]], @$yiq) ];
19             }
20             sub to_yiq {
21 4     4 0 6 my ($rgb) = shift;
22 4         14 my ($y, $i, $q) = mult_matrix_vector_3([[0.299, 0.587, 0.114 ],
23             [0.5959, -0.2746, -0.3213],
24             [0.2115, -0.5227, 0.3112]], @$rgb);
25 4         10 $i = ($i + $i_max) / $i_range_size;
26 4         4 $q = ($q + $q_max) / $q_range_size;
27 4         13 return [$y, $i, $q];
28             }
29              
30             Graphics::Toolkit::Color::Space->new(
31             family => 'LAB',
32             axis => [qw/luminance in_phase quadrature/],
33             short => [qw/Y I Q/],
34             role => [qw/l a b/],
35             range => [1, [-$i_max, $i_max], [-$q_max, $q_max]],
36             convert => {RGB => [\&from_yiq, \&to_yiq]},
37             );