Color/Space/Instance/HSB.pm

filter: Statementstmt 100% 28 / 28 Branchbran 75.0% 15 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 2 totaltotal 87.2% 48 / 55 CC 11 SCAR 16.5
CC
11
Cov
90%
to_rgb
7.1
from_rgb
5.0
BEGIN
1.0
CRAP 5.2
« Color/Space/Format.pm ↑ Summary Color/Values.pm »
1  
2 # HSB color space specific code
3  
4 package Graphics::Toolkit::Color::Space::Instance::HSB;
5 16 ▶use v5.12;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 16 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 16 ▶use Graphics::Toolkit::Color::Space qw/min max/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 5 ▶sub from_rgb {
Subroutine from_rgb: called CC=5 SCAR=16.2
Pod undocumented
10 5 my ($r, $g, $b) = @{$_[0]};
11 5 my $vmin = min($r, $g, $b);
12 5 my $br = my $vmax = max($r, $g, $b);
13 5 ▶ return ([0, 0, $br]) if $vmax == $vmin;
Branch: 1 branch
BranchTrueFalseTotal
if $vmax == $vmin 3 2 5
14  
15 2 my $d = $vmax - $vmin;
16 2 my $s = $d / $vmax;
17 2 ▶ my $h = ($vmax == $r) ? (($g - $b) / $d + ($g < $b ? 6 : 0)) :
Branch: 3 branches
BranchTrueFalseTotal
$vmax == $r ? : 1 1 2
$g < $b ? : 1 0 1
$vmax == $g ? : 0 1 1
18 ($vmax == $g) ? (($b - $r) / $d + 2)
19 : (($r - $g) / $d + 4);
20 2 return ([$h/6, $s, $br]);
21 }
22 6 ▶sub to_rgb {
Subroutine to_rgb: called CC=7 SCAR=19.6
Pod undocumented
23 6 my ($h, $s, $b) = @{$_[0]};
24 6 ▶ return ([$b, $b, $b]) if $s == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $s == 0 3 3 6
25 3 my $hi = int( $h * 6 );
26 3 my $f = ( $h * 6 ) - $hi;
27 3 my $p = $b * (1 - $s );
28 3 my $q = $b * (1 - ($s * $f));
29 3 my $t = $b * (1 - ($s * (1 - $f)));
30 3 ▶ my @rgb = ($hi == 1) ? ($q, $b, $p)
Branch: 5 branches
BranchTrueFalseTotal
$hi == 1 ? : 1 2 3
$hi == 2 ? : 0 2 2
$hi == 3 ? : 0 2 2
$hi == 4 ? : 1 1 2
$hi == 5 ? : 1 0 1
31 : ($hi == 2) ? ($p, $b, $t)
32 : ($hi == 3) ? ($p, $q, $b)
33 : ($hi == 4) ? ($t, $p, $b)
34 : ($hi == 5) ? ($b, $p, $q)
35 : ($b, $t, $p);
36 3 return \@rgb;
37 }
38  
39 16 Graphics::Toolkit::Color::Space->new (
40 family => 'HSV',
41 axis => [qw/hue saturation brightness/],
42 role => [qw/hue saturation value/],
43 range => [360, 100, 100],
44 precision => 0,
45 type => [qw/angular linear linear/],
46 suffix => ['', '%', '%'],
47 constraint => {cone => {checker => '$_[0][1] <= $_[0][2]',
48 error => 'Saturation can not be greater than Value',
49 remedy => '[$_[0][0], $_[0][2], $_[0][2]]', }},
50 convert => {RGB => [\&to_rgb, \&from_rgb]},
51 );
« Color/Space/Format.pm ↑ Summary Color/Values.pm »