File Coverage

lib/Graphics/Toolkit/Color/Space/Instance/RGBLinear.pm
Criterion Covered Total %
statement 14 14 100.0
branch 4 4 100.0
condition n/a
subroutine 5 5 100.0
pod 0 2 0.0
total 23 25 92.0


line stmt bran cond sub pod time code
1              
2             # linear standard (S)RGB, RGB with removed gamma
3              
4             package Graphics::Toolkit::Color::Space::Instance::RGBLinear;
5 16     16   256742 use v5.12;
  16         42  
6 16     16   60 use warnings;
  16         18  
  16         932  
7 16     16   462 use Graphics::Toolkit::Color::Space qw/spow/;
  16         66  
  16         3722  
8              
9             my $gamma = 2.4;
10              
11             sub from_lrgb {
12 90     90 0 121 my ($lrgb) = shift;
13 90 100       140 return [ map { (abs($_) > 0.0031308) ? ((spow($_, 1/$gamma) * 1.055) - 0.055)
  270         580  
14             : ($_ * 12.92) } @$lrgb ];
15             }
16             sub to_lrgb {
17 140     140 0 180 my ($rgb) = shift;
18 140 100       207 return [ map { (abs($_) > 0.04045) ? spow((($_ + 0.055) / 1.055 ), $gamma)
  420         1049  
19             : ($_ / 12.92) } @$rgb ];
20             }
21              
22             Graphics::Toolkit::Color::Space->new(
23             name => 'LinearRGB',
24             alias_name => 'linRGB',
25             family => 'RGB',
26             axis => [qw/red green blue/],
27             precision => 6,
28             convert => {RGB => [\&from_lrgb, \&to_lrgb]},
29             );