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
|
|
197
|
use v5.14; |
|
15
|
|
|
|
|
53
|
|
10
|
15
|
|
|
15
|
|
86
|
use warnings; |
|
15
|
|
|
|
|
28
|
|
|
15
|
|
|
|
|
509
|
|
11
|
15
|
|
|
15
|
|
120
|
use base qw( Convert::Color ); |
|
15
|
|
|
|
|
45
|
|
|
15
|
|
|
|
|
4130
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# For converting degrees to radians |
14
|
|
|
|
|
|
|
# atan2(1,0) == PI/2 |
15
|
15
|
|
|
15
|
|
145
|
use constant PIover180 => atan2(1,0) / 90; |
|
15
|
|
|
|
|
62
|
|
|
15
|
|
|
|
|
1603
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# No space name since we're not a complete space |
18
|
|
|
|
|
|
|
|
19
|
15
|
|
|
15
|
|
120
|
use List::Util qw( max min ); |
|
15
|
|
|
|
|
55
|
|
|
15
|
|
|
|
|
5126
|
|
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
|
|
|
|
|
18
|
my ( $r, $g, $b ) = @_; |
29
|
|
|
|
|
|
|
|
30
|
10
|
|
|
|
|
25
|
my $max = max $r, $g, $b; |
31
|
10
|
|
|
|
|
21
|
my $min = min $r, $g, $b; |
32
|
|
|
|
|
|
|
|
33
|
10
|
|
|
|
|
14
|
my $hue; |
34
|
|
|
|
|
|
|
|
35
|
10
|
100
|
|
|
|
30
|
if( $max == $min ) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
36
|
4
|
|
|
|
|
8
|
$hue = 0; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
elsif( $max == $r ) { |
39
|
2
|
|
|
|
|
8
|
$hue = 60 * ( $g - $b ) / ( $max - $min ); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
elsif( $max == $g ) { |
42
|
2
|
|
|
|
|
7
|
$hue = 60 * ( $b - $r ) / ( $max - $min ) + 120; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
elsif( $max == $b ) { |
45
|
2
|
|
|
|
|
7
|
$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
|
|
53
|
my ( $col1, $col2 ) = @_; |
56
|
|
|
|
|
|
|
|
57
|
24
|
|
|
|
|
74
|
my $r1 = $col1->chroma; |
58
|
24
|
|
|
|
|
58
|
my $r2 = $col2->chroma; |
59
|
|
|
|
|
|
|
|
60
|
24
|
|
|
|
|
65
|
my $dhue = $col1->hue - $col2->hue; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Square of polar distance |
63
|
24
|
|
|
|
|
271
|
return $r1*$r1 + $r2*$r2 - 2*$r1*$r2*cos( $dhue * PIover180 ); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
0x55AA; |