line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
8
|
|
|
8
|
|
804
|
use v5.12; |
|
8
|
|
|
|
|
28
|
|
2
|
8
|
|
|
8
|
|
43
|
use warnings; |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
375
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# HSL color space specific code |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Graphics::Toolkit::Color::Space::Instance::HSL; |
7
|
8
|
|
|
8
|
|
49
|
use Graphics::Toolkit::Color::Space::Util ':all'; |
|
8
|
|
|
|
|
57
|
|
|
8
|
|
|
|
|
977
|
|
8
|
8
|
|
|
8
|
|
554
|
use Graphics::Toolkit::Color::Space; |
|
8
|
|
|
|
|
11
|
|
|
8
|
|
|
|
|
2935
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my $hsl_def = Graphics::Toolkit::Color::Space->new( axis => [qw/hue saturation lightness/], |
11
|
|
|
|
|
|
|
range => [ 360, 100, 100 ], |
12
|
|
|
|
|
|
|
type => [qw/angle linear linear/]); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$hsl_def->add_converter('RGB', \&to_rgb, \&from_rgb ); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub from_rgb { |
18
|
155
|
|
|
155
|
0
|
300
|
my ($r, $g, $b) = @_; |
19
|
155
|
|
|
|
|
360
|
my $vmax = max($r, $g, $b), |
20
|
|
|
|
|
|
|
my $vmin = min($r, $g, $b); |
21
|
155
|
|
|
|
|
314
|
my $l = ($vmax + $vmin) / 2; |
22
|
155
|
100
|
|
|
|
394
|
return (0, 0, $l) if $vmax == $vmin; |
23
|
132
|
|
|
|
|
203
|
my $d = $vmax - $vmin; |
24
|
132
|
50
|
|
|
|
318
|
my $s = ($l > 0.5) ? ($d / (2 - $vmax - $vmin)) : ($d / ($vmax + $vmin)); |
25
|
132
|
100
|
|
|
|
369
|
my $h = ($vmax == $r) ? (($g - $b) / $d + ($g < $b ? 6 : 0)) : |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
26
|
|
|
|
|
|
|
($vmax == $g) ? (($b - $r) / $d + 2) |
27
|
|
|
|
|
|
|
: (($r - $g) / $d + 4); |
28
|
132
|
|
|
|
|
528
|
return ($h/6, $s, $l); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub to_rgb { |
32
|
121
|
|
|
121
|
0
|
286
|
my ($h, $s, $l) = @_; |
33
|
121
|
|
|
|
|
188
|
$h *= 6; |
34
|
121
|
|
|
|
|
272
|
my $C = $s * (1 - abs($l * 2 - 1)); |
35
|
121
|
|
|
|
|
289
|
my $X = $C * (1 - abs( rmod($h, 2) - 1) ); |
36
|
121
|
|
|
|
|
212
|
my $m = $l - ($C / 2); |
37
|
121
|
100
|
|
|
|
830
|
return ($h < 1) ? ($C + $m, $X + $m, $m) |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
38
|
|
|
|
|
|
|
: ($h < 2) ? ($X + $m, $C + $m, $m) |
39
|
|
|
|
|
|
|
: ($h < 3) ? ( $m, $C + $m, $X + $m) |
40
|
|
|
|
|
|
|
: ($h < 4) ? ( $m, $X + $m, $C + $m) |
41
|
|
|
|
|
|
|
: ($h < 5) ? ($X + $m, $m, $C + $m) |
42
|
|
|
|
|
|
|
: ($C + $m, $m, $X + $m); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
$hsl_def; |