line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# You may distribute under the terms of either the GNU General Public License |
2
|
|
|
|
|
|
|
# or the Artistic License (the same terms as Perl itself) |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# (C) Paul Evans, 2009-2022 -- leonerd@leonerd.org.uk |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package # hide from CPAN |
7
|
|
|
|
|
|
|
Convert::Color::HueChromaBased; |
8
|
|
|
|
|
|
|
|
9
|
15
|
|
|
15
|
|
195
|
use v5.14; |
|
15
|
|
|
|
|
56
|
|
10
|
15
|
|
|
15
|
|
79
|
use warnings; |
|
15
|
|
|
|
|
47
|
|
|
15
|
|
|
|
|
441
|
|
11
|
15
|
|
|
15
|
|
106
|
use base qw( Convert::Color ); |
|
15
|
|
|
|
|
29
|
|
|
15
|
|
|
|
|
4138
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# For converting degrees to radians |
14
|
|
|
|
|
|
|
# atan2(1,0) == PI/2 |
15
|
15
|
|
|
15
|
|
139
|
use constant PIover180 => atan2(1,0) / 90; |
|
15
|
|
|
|
|
34
|
|
|
15
|
|
|
|
|
1255
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# No space name since we're not a complete space |
18
|
|
|
|
|
|
|
|
19
|
15
|
|
|
15
|
|
103
|
use List::Util qw( max min ); |
|
15
|
|
|
|
|
32
|
|
|
15
|
|
|
|
|
5148
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# HSV and HSL are related, using some common elements. |
22
|
|
|
|
|
|
|
# See also |
23
|
|
|
|
|
|
|
# http://en.wikipedia.org/wiki/HSV_color_space |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _hue_min_max |
26
|
|
|
|
|
|
|
{ |
27
|
10
|
|
|
10
|
|
16
|
my $class = shift; |
28
|
10
|
|
|
|
|
20
|
my ( $r, $g, $b ) = @_; |
29
|
|
|
|
|
|
|
|
30
|
10
|
|
|
|
|
33
|
my $max = max $r, $g, $b; |
31
|
10
|
|
|
|
|
21
|
my $min = min $r, $g, $b; |
32
|
|
|
|
|
|
|
|
33
|
10
|
|
|
|
|
17
|
my $hue; |
34
|
|
|
|
|
|
|
|
35
|
10
|
100
|
|
|
|
32
|
if( $max == $min ) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
36
|
4
|
|
|
|
|
7
|
$hue = 0; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
elsif( $max == $r ) { |
39
|
2
|
|
|
|
|
5
|
$hue = 60 * ( $g - $b ) / ( $max - $min ); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
elsif( $max == $g ) { |
42
|
2
|
|
|
|
|
8
|
$hue = 60 * ( $b - $r ) / ( $max - $min ) + 120; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
elsif( $max == $b ) { |
45
|
2
|
|
|
|
|
8
|
$hue = 60 * ( $r - $g ) / ( $max - $min ) + 240; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
10
|
|
|
|
|
30
|
return ( $hue, $min, $max ); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# Useful for distance calculations - calculates the square of the distance |
52
|
|
|
|
|
|
|
# between two points in polar space |
53
|
|
|
|
|
|
|
sub _huechroma_dst_squ |
54
|
|
|
|
|
|
|
{ |
55
|
24
|
|
|
24
|
|
48
|
my ( $col1, $col2 ) = @_; |
56
|
|
|
|
|
|
|
|
57
|
24
|
|
|
|
|
52
|
my $r1 = $col1->chroma; |
58
|
24
|
|
|
|
|
53
|
my $r2 = $col2->chroma; |
59
|
|
|
|
|
|
|
|
60
|
24
|
|
|
|
|
55
|
my $dhue = $col1->hue - $col2->hue; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Square of polar distance |
63
|
24
|
|
|
|
|
237
|
return $r1*$r1 + $r2*$r2 - 2*$r1*$r2*cos( $dhue * PIover180 ); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
0x55AA; |