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 15     15   302750 use v5.12;
  15         62  
6 15     15   87 use warnings;
  15         65  
  15         953  
7 15     15   800 use Graphics::Toolkit::Color::Space qw/mult_matrix_vector_3/;
  15         30  
  15         6649  
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_rgb {
13 4     4 0 10 my ($rgb) = shift;
14 4         31 my ($y, $i, $q) = mult_matrix_vector_3([[0.299, 0.587, 0.114 ],
15             [0.5959, -0.2746, -0.3213],
16             [0.2115, -0.5227, 0.3112]], @$rgb);
17 4         44 $i = ($i + $i_max) / $i_range_size;
18 4         7 $q = ($q + $q_max) / $q_range_size;
19 4         20 return [$y, $i, $q];
20             }
21             sub to_rgb {
22 5     5 0 13 my ($yiq) = shift;
23 5         19 $yiq->[1] = $yiq->[1] * $i_range_size - $i_max;
24 5         12 $yiq->[2] = $yiq->[2] * $q_range_size - $q_max;
25 5         48 return [ mult_matrix_vector_3([[1, 0.95605, 0.620755],
26             [1, -0.272052, -0.647206],
27             [1, -1.1067, 1.70442 ]], @$yiq) ];
28             }
29              
30             Graphics::Toolkit::Color::Space->new(
31             axis => [qw/luminance in_phase quadrature/],
32             short => [qw/Y I Q/],
33             range => [1, [-$i_max, $i_max], [-$q_max, $q_max]],
34             convert => {RGB => [\&to_rgb, \&from_rgb]},
35             );