line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Graphics::Color::HSV; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
1
|
|
|
1
|
|
52938
|
$Graphics::Color::HSV::VERSION = '0.29'; |
4
|
|
|
|
|
|
|
} |
5
|
1
|
|
|
1
|
|
430
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use MooseX::Aliases; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
extends qw(Graphics::Color); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
with 'Graphics::Color::Equal'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use Graphics::Color::Types qw(Number360OrLess NumberOneOrLess); |
13
|
|
|
|
|
|
|
use Graphics::Color::RGB; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has 'hue' => ( |
17
|
|
|
|
|
|
|
is => 'rw', |
18
|
|
|
|
|
|
|
isa => Number360OrLess, |
19
|
|
|
|
|
|
|
default => 1, |
20
|
|
|
|
|
|
|
alias => 'h' |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has 'saturation' => ( |
25
|
|
|
|
|
|
|
is => 'rw', |
26
|
|
|
|
|
|
|
isa => NumberOneOrLess, |
27
|
|
|
|
|
|
|
default => 1, |
28
|
|
|
|
|
|
|
alias => 's' |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
has 'value' => ( |
33
|
|
|
|
|
|
|
is => 'rw', |
34
|
|
|
|
|
|
|
isa => NumberOneOrLess, |
35
|
|
|
|
|
|
|
default => 1, |
36
|
|
|
|
|
|
|
alias => 'v' |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
has 'alpha' => ( |
41
|
|
|
|
|
|
|
is => 'rw', |
42
|
|
|
|
|
|
|
isa => NumberOneOrLess, |
43
|
|
|
|
|
|
|
default => 1, |
44
|
|
|
|
|
|
|
alias => 'a' |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
has 'name' => ( is => 'rw', isa => 'Str' ); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub as_string { |
52
|
|
|
|
|
|
|
my ($self) = @_; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
return sprintf('%d,%0.2f,%0.2f,%0.2f', |
55
|
|
|
|
|
|
|
$self->hue, $self->saturation, $self->value, $self->alpha |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub as_percent_string { |
61
|
|
|
|
|
|
|
my ($self) = @_; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
return sprintf("%d, %d%%, %d%%, %0.2f", |
64
|
|
|
|
|
|
|
$self->hue, $self->saturation * 100, $self->value * 100, |
65
|
|
|
|
|
|
|
$self->alpha |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub as_array { |
71
|
|
|
|
|
|
|
my ($self) = @_; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
return ($self->hue, $self->saturation, $self->value); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub as_array_with_alpha { |
78
|
|
|
|
|
|
|
my ($self) = @_; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
return ($self->hue, $self->saturation, $self->value, $self->alpha); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub equal_to { |
85
|
|
|
|
|
|
|
my ($self, $other) = @_; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
return 0 unless defined($other); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
unless($self->hue == $other->hue) { |
90
|
|
|
|
|
|
|
return 0; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
unless($self->saturation == $other->saturation) { |
93
|
|
|
|
|
|
|
return 0; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
unless($self->value == $other->value) { |
96
|
|
|
|
|
|
|
return 0; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
unless($self->alpha == $other->alpha) { |
99
|
|
|
|
|
|
|
return 0; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
return 1; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub to_rgb { |
108
|
|
|
|
|
|
|
my ($self) = @_; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
my ($h, $s, $v) = ($self->h, $self->s, $self->v); |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
my ($red, $green, $blue); |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
if($v == 0) { |
115
|
|
|
|
|
|
|
($red, $green, $blue) = (0, 0, 0); |
116
|
|
|
|
|
|
|
} elsif($s == 0) { |
117
|
|
|
|
|
|
|
($red, $green, $blue) = ($v, $v, $v); |
118
|
|
|
|
|
|
|
} else { |
119
|
|
|
|
|
|
|
my $hf = $h / 60; |
120
|
|
|
|
|
|
|
my $i = int($hf); |
121
|
|
|
|
|
|
|
my $f = $hf - $i; |
122
|
|
|
|
|
|
|
my $pv = $v * (1 - $s); |
123
|
|
|
|
|
|
|
my $qv = $v * (1 - $s * $f); |
124
|
|
|
|
|
|
|
my $tv = $v * (1 - $s * (1 - $f)); |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
if($i == 0) { |
127
|
|
|
|
|
|
|
$red = $v; |
128
|
|
|
|
|
|
|
$green = $tv; |
129
|
|
|
|
|
|
|
$blue = $pv; |
130
|
|
|
|
|
|
|
} elsif($i == 1) { |
131
|
|
|
|
|
|
|
$red = $qv; |
132
|
|
|
|
|
|
|
$green = $v; |
133
|
|
|
|
|
|
|
$blue = $pv; |
134
|
|
|
|
|
|
|
} elsif($i == 2) { |
135
|
|
|
|
|
|
|
$red = $pv; |
136
|
|
|
|
|
|
|
$green = $v; |
137
|
|
|
|
|
|
|
$blue = $tv; |
138
|
|
|
|
|
|
|
} elsif($i == 3) { |
139
|
|
|
|
|
|
|
$red = $pv; |
140
|
|
|
|
|
|
|
$green = $qv; |
141
|
|
|
|
|
|
|
$blue = $v; |
142
|
|
|
|
|
|
|
} elsif($i == 4) { |
143
|
|
|
|
|
|
|
$red = $tv; |
144
|
|
|
|
|
|
|
$green = $pv; |
145
|
|
|
|
|
|
|
$blue = $v; |
146
|
|
|
|
|
|
|
} elsif($i == 5) { |
147
|
|
|
|
|
|
|
$red = $v; |
148
|
|
|
|
|
|
|
$green = $pv; |
149
|
|
|
|
|
|
|
$blue = $qv; |
150
|
|
|
|
|
|
|
} elsif($i == 6) { |
151
|
|
|
|
|
|
|
$red = $v; |
152
|
|
|
|
|
|
|
$blue = $tv; |
153
|
|
|
|
|
|
|
$green = $pv; |
154
|
|
|
|
|
|
|
} elsif($i == -1) { |
155
|
|
|
|
|
|
|
$red = $v; |
156
|
|
|
|
|
|
|
$green = $pv; |
157
|
|
|
|
|
|
|
$blue = $qv; |
158
|
|
|
|
|
|
|
} else { |
159
|
|
|
|
|
|
|
die('Invalid HSV -> RGB conversion.') |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
return Graphics::Color::RGB->new( |
164
|
|
|
|
|
|
|
red => $red, green => $green, blue => $blue |
165
|
|
|
|
|
|
|
); |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
no Moose; |
171
|
|
|
|
|
|
|
1; |
172
|
|
|
|
|
|
|
__END__ |
173
|
|
|
|
|
|
|
=pod |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 NAME |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Graphics::Color::HSV |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 VERSION |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
version 0.29 |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 SYNOPSIS |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
use Graphics::Color::HSV; |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
my $color = Graphics::Color::HSV->new({ |
188
|
|
|
|
|
|
|
hue => 120, |
189
|
|
|
|
|
|
|
saturation => .5, |
190
|
|
|
|
|
|
|
value => .25, |
191
|
|
|
|
|
|
|
}); |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head1 DESCRIPTION |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
Graphics::Color::HSV represents a Color in an RGB color space. HSLV stands for |
196
|
|
|
|
|
|
|
B<Hue> B<Saturation> and B<Value>. HSV is closely related to HSL. |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
=head2 hue |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head2 h |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
Set/Get the hue component of this Color. |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=head2 saturation |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head2 s |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
Set/Get the saturation component of this Color. |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head2 value |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
=head2 v |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
Set/Get the value component of this Color. |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
=head2 alpha |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
Set/Get the alpha component of this Color. |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
=head2 name |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
Get the name of this color. Only valid if the color was created by name. |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=head1 METHODS |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=head2 as_string |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
Get a string version of this Color in the form of |
231
|
|
|
|
|
|
|
HUE,SATURATION,VALUE,ALPHA. |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=head2 as_percent_string |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
Return a percent formatted value for this color. This format is suitable for |
236
|
|
|
|
|
|
|
CSS HSV values. |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=head2 as_array |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
Get the HSV values as an array |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=head2 as_array_with_alpha> |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
Get the HSVA values as an array |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=head2 equal_to |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
Compares this color to the provided one. Returns 1 if true, else 0; |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=head2 not_equal_to |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
The opposite of equal_to. |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=head2 to_rgb |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
Creates this HSV color in RGB space. Returns a L<Graphics::Color::RGB> object. |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=head1 AUTHOR |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
Cory G Watson <gphat@cpan.org> |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
This software is copyright (c) 2011 by Cold Hard Code, LLC. |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
267
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=cut |
270
|
|
|
|
|
|
|
|