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 Convert::Color::CMY 0.14; |
7
|
|
|
|
|
|
|
|
8
|
12
|
|
|
12
|
|
134911
|
use v5.14; |
|
12
|
|
|
|
|
61
|
|
9
|
12
|
|
|
12
|
|
65
|
use warnings; |
|
12
|
|
|
|
|
25
|
|
|
12
|
|
|
|
|
388
|
|
10
|
12
|
|
|
12
|
|
73
|
use base qw( Convert::Color ); |
|
12
|
|
|
|
|
33
|
|
|
12
|
|
|
|
|
2289
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
__PACKAGE__->register_color_space( 'cmy' ); |
13
|
|
|
|
|
|
|
|
14
|
12
|
|
|
12
|
|
92
|
use Carp; |
|
12
|
|
|
|
|
26
|
|
|
12
|
|
|
|
|
5727
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 NAME |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
C - a color value represented as cyan/magenta/yellow |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Directly: |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
use Convert::Color::CMY; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $red = Convert::Color::CMY->new( 0, 1, 1 ); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Can also parse strings |
29
|
|
|
|
|
|
|
my $pink = Convert::Color::CMY->new( '0,0.3,0.3' ); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Via L: |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
use Convert::Color; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $cyan = Convert::Color->new( 'cmy:1,0,0' ); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 DESCRIPTION |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Objects in this class represent a color in CMY space, as a set of three |
40
|
|
|
|
|
|
|
floating-point values in the range 0 to 1. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=cut |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=cut |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head2 new |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
$color = Convert::Color::CMY->new( $cyan, $magenta, $yellow ) |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Returns a new object to represent the set of values given. These values should |
53
|
|
|
|
|
|
|
be floating-point numbers between 0 and 1. Values outside of this range will |
54
|
|
|
|
|
|
|
be clamped. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
$color = Convert::Color::CMY->new( $string ) |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Parses C<$string> for values, and construct a new object similar to the above |
59
|
|
|
|
|
|
|
three-argument form. The string should be in the form |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
cyan,magenta,yellow |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
containing the three floating-point values in decimal notation. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub new |
68
|
|
|
|
|
|
|
{ |
69
|
17
|
|
|
17
|
1
|
207
|
my $class = shift; |
70
|
|
|
|
|
|
|
|
71
|
17
|
|
|
|
|
38
|
my ( $c, $m, $y ); |
72
|
|
|
|
|
|
|
|
73
|
17
|
100
|
|
|
|
68
|
if( @_ == 1 ) { |
|
|
50
|
|
|
|
|
|
74
|
2
|
|
|
|
|
4
|
local $_ = $_[0]; |
75
|
2
|
50
|
|
|
|
19
|
if( m/^(\d+(?:\.\d+)?),(\d+(?:\.\d+)?),(\d+(?:\.\d+)?)$/ ) { |
76
|
2
|
|
|
|
|
11
|
( $c, $m, $y ) = ( $1, $2, $3 ); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
else { |
79
|
0
|
|
|
|
|
0
|
croak "Unrecognised CMY string spec '$_'"; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
elsif( @_ == 3 ) { |
83
|
15
|
|
|
|
|
34
|
( $c, $m, $y ) = @_; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
else { |
86
|
0
|
|
|
|
|
0
|
croak "usage: Convert::Color::CMY->new( SPEC ) or ->new( C, M, Y )"; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# Clamp |
90
|
17
|
|
|
|
|
42
|
for ( $c, $m, $y ) { |
91
|
51
|
50
|
|
|
|
100
|
$_ = 0 if $_ < 0; |
92
|
51
|
50
|
|
|
|
99
|
$_ = 1 if $_ > 1; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
17
|
|
|
|
|
77
|
return bless [ $c, $m, $y ], $class; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 METHODS |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=cut |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head2 cyan |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
$c = $color->cyan |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head2 magenta |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
$m = $color->magenta |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 yellow |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
$y = $color->yellow |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Accessors for the three components of the color. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
# Simple accessors |
119
|
19
|
|
|
19
|
1
|
464
|
sub cyan { shift->[0] } |
120
|
19
|
|
|
19
|
1
|
70
|
sub magenta { shift->[1] } |
121
|
19
|
|
|
19
|
1
|
81
|
sub yellow { shift->[2] } |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 cmy |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
( $cyan, $magenta, $yellow ) = $color->cmy |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Returns the individual cyan, magenta and yellow color components of the color |
128
|
|
|
|
|
|
|
value. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub cmy |
133
|
|
|
|
|
|
|
{ |
134
|
4
|
|
|
4
|
1
|
8
|
my $self = shift; |
135
|
4
|
|
|
|
|
23
|
return @$self; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
# Conversions |
139
|
|
|
|
|
|
|
sub rgb |
140
|
|
|
|
|
|
|
{ |
141
|
5
|
|
|
5
|
1
|
9
|
my $self = shift; |
142
|
|
|
|
|
|
|
|
143
|
5
|
|
|
|
|
12
|
return 1 - $self->cyan, 1 - $self->magenta, 1 - $self->yellow; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub new_rgb |
147
|
|
|
|
|
|
|
{ |
148
|
5
|
|
|
5
|
0
|
14
|
my $class = shift; |
149
|
5
|
|
|
|
|
11
|
my ( $r, $g, $b ) = @_; |
150
|
|
|
|
|
|
|
|
151
|
5
|
|
|
|
|
14
|
$class->new( 1 - $r, 1 - $g, 1 - $b ); |
152
|
|
|
|
|
|
|
} |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 SEE ALSO |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=over 4 |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=item * |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
L - color space conversions |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=item * |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
L - a color value represented as red/green/blue |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=item * |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
L - a color value represented as cyan/magenta/yellow/key |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=back |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 AUTHOR |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Paul Evans |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=cut |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
0x55AA; |