line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package VRML::Color; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
############################## Copyright ############################## |
4
|
|
|
|
|
|
|
# # |
5
|
|
|
|
|
|
|
# This program is Copyright 1996,1998 by Hartmut Palm. # |
6
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or # |
7
|
|
|
|
|
|
|
# modify it under the terms of the GNU General Public License # |
8
|
|
|
|
|
|
|
# as published by the Free Software Foundation; either version 2 # |
9
|
|
|
|
|
|
|
# of the License, or (at your option) any later version. # |
10
|
|
|
|
|
|
|
# # |
11
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful, # |
12
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of # |
13
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
14
|
|
|
|
|
|
|
# GNU General Public License for more details. # |
15
|
|
|
|
|
|
|
# # |
16
|
|
|
|
|
|
|
# If you do not have a copy of the GNU General Public License write # |
17
|
|
|
|
|
|
|
# to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, # |
18
|
|
|
|
|
|
|
# MA 02139, USA. # |
19
|
|
|
|
|
|
|
# # |
20
|
|
|
|
|
|
|
####################################################################### |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
require 5.000; |
23
|
|
|
|
|
|
|
require Exporter; |
24
|
2
|
|
|
2
|
|
6
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
50
|
|
25
|
2
|
|
|
2
|
|
5
|
use vars qw(@ISA @EXPORT $VERSION %X11Color); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
1909
|
|
26
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
27
|
|
|
|
|
|
|
@EXPORT = qw(rgb_color); |
28
|
|
|
|
|
|
|
$VERSION="1.03"; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub rgb_color { |
31
|
12
|
|
|
12
|
0
|
17
|
my ($string,$colorspace) = @_; |
32
|
12
|
50
|
|
|
|
23
|
return undef unless $string; |
33
|
12
|
|
|
|
|
9
|
my ($key,$value,$intensity,$r,$g,$b); |
34
|
|
|
|
|
|
|
|
35
|
12
|
|
|
|
|
35
|
($key,$intensity) = split(/[%_]/,$string); |
36
|
12
|
50
|
|
|
|
26
|
if (defined $colorspace) { |
37
|
0
|
|
|
|
|
0
|
$value = $colorspace->{$key}; |
38
|
|
|
|
|
|
|
} else { |
39
|
12
|
|
|
|
|
30
|
$value = $X11Color{lc($key)}; |
40
|
|
|
|
|
|
|
} |
41
|
12
|
50
|
|
|
|
20
|
if ($value) { # ex. yellow |
42
|
12
|
|
|
|
|
22
|
$r = $$value[0]/255; |
43
|
12
|
|
|
|
|
13
|
$g = $$value[1]/255; |
44
|
12
|
|
|
|
|
17
|
$b = $$value[2]/255; |
45
|
|
|
|
|
|
|
} else { |
46
|
0
|
0
|
|
|
|
0
|
if ($string =~ /(\d*[\.\d]+)\s+(\d*[\.\d]+)\s+(\d*[\.\d]+)/) { # ex. "100 200 255" |
|
|
0
|
|
|
|
|
|
47
|
0
|
|
|
|
|
0
|
$r = $1; |
48
|
0
|
|
|
|
|
0
|
$g = $2; |
49
|
0
|
|
|
|
|
0
|
$b = $3; |
50
|
0
|
0
|
0
|
|
|
0
|
if ($r>1 || $g>1 || $b>1) { |
|
|
|
0
|
|
|
|
|
51
|
0
|
|
|
|
|
0
|
$r /= 255; |
52
|
0
|
|
|
|
|
0
|
$g /= 255; |
53
|
0
|
|
|
|
|
0
|
$b /= 255; |
54
|
|
|
|
|
|
|
} |
55
|
0
|
0
|
|
|
|
0
|
return ("$r $g $b",$string) if wantarray; |
56
|
0
|
|
|
|
|
0
|
return "$r $g $b"; |
57
|
|
|
|
|
|
|
} elsif ($string =~ /^([A-Fa-f0-9]{6}?)/) { # ex. "FF00FF" |
58
|
0
|
|
|
|
|
0
|
$r = hex(substr($string,0,2)) /255; |
59
|
0
|
|
|
|
|
0
|
$g = hex(substr($string,2,2)) /255; |
60
|
0
|
|
|
|
|
0
|
$b = hex(substr($string,4,2)) /255; |
61
|
0
|
0
|
|
|
|
0
|
return ("$r $g $b",$string) if wantarray; |
62
|
0
|
|
|
|
|
0
|
return "$r $g $b"; |
63
|
|
|
|
|
|
|
} else { |
64
|
0
|
0
|
|
|
|
0
|
return ("0 0 0","Invalid color \"$string\"") if wantarray; |
65
|
0
|
|
|
|
|
0
|
return "0 0 0"; # invalid color name |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
12
|
50
|
|
|
|
25
|
if (defined $intensity) { |
69
|
0
|
0
|
|
|
|
0
|
if ($key eq "gray" | $key eq "grey") { |
70
|
0
|
|
|
|
|
0
|
$r = 1-$intensity/100; |
71
|
0
|
|
|
|
|
0
|
$g = 1-$intensity/100; |
72
|
0
|
|
|
|
|
0
|
$b = 1-$intensity/100; |
73
|
|
|
|
|
|
|
} else { |
74
|
0
|
|
|
|
|
0
|
$r *= $intensity/100; |
75
|
0
|
|
|
|
|
0
|
$g *= $intensity/100; |
76
|
0
|
|
|
|
|
0
|
$b *= $intensity/100; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
12
|
50
|
|
|
|
113
|
return ("$r $g $b",$string) if wantarray; |
80
|
0
|
|
|
|
|
|
return "$r $g $b"; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
#-------------------------------------------------------------------- |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
%X11Color = ( |
86
|
|
|
|
|
|
|
"aliceblue" => [240,248,255], |
87
|
|
|
|
|
|
|
"antiquewhite" => [250,235,215], |
88
|
|
|
|
|
|
|
"aqua" => [0,255,255], |
89
|
|
|
|
|
|
|
"aquamarine" => [127,255,212], |
90
|
|
|
|
|
|
|
"azure" => [240,255,255], |
91
|
|
|
|
|
|
|
"beige" => [245,245,220], |
92
|
|
|
|
|
|
|
"bisque" => [255,228,196], |
93
|
|
|
|
|
|
|
"black" => [0,0,0], |
94
|
|
|
|
|
|
|
"blanchedalmond" => [255,235,205], |
95
|
|
|
|
|
|
|
"blue" => [0,0,255], |
96
|
|
|
|
|
|
|
"blueviolet" => [138,43,226], |
97
|
|
|
|
|
|
|
"brown" => [165,42,42], |
98
|
|
|
|
|
|
|
"burlywood" => [222,184,135], |
99
|
|
|
|
|
|
|
"cadetblue" => [95,158,160], |
100
|
|
|
|
|
|
|
"chartreuse" => [127,255,0], |
101
|
|
|
|
|
|
|
"chocolate" => [210,105,30], |
102
|
|
|
|
|
|
|
"coral" => [255,127,80], |
103
|
|
|
|
|
|
|
"cornflowerblue" => [100,149,237], |
104
|
|
|
|
|
|
|
"cornsilk" => [255,248,220], |
105
|
|
|
|
|
|
|
"crimson" => [220,20,60], |
106
|
|
|
|
|
|
|
"cyan" => [0,255,255], |
107
|
|
|
|
|
|
|
"darkblue" => [0,0,139], |
108
|
|
|
|
|
|
|
"darkcyan" => [0,139,139], |
109
|
|
|
|
|
|
|
"darkgoldenrod" => [184,134,11], |
110
|
|
|
|
|
|
|
"darkgray" => [169,169,169], |
111
|
|
|
|
|
|
|
"darkgreen" => [0,100,0], |
112
|
|
|
|
|
|
|
"darkkhaki" => [189,183,107], |
113
|
|
|
|
|
|
|
"darkmagenta" => [139,0,139], |
114
|
|
|
|
|
|
|
"darkolivegreen" => [85,107,47], |
115
|
|
|
|
|
|
|
"darkorange" => [255,140,0], |
116
|
|
|
|
|
|
|
"darkorchid" => [153,50,204], |
117
|
|
|
|
|
|
|
"darkred" => [139,0,0], |
118
|
|
|
|
|
|
|
"darksalmon" => [233,150,122], |
119
|
|
|
|
|
|
|
"darkseagreen" => [143,188,143], |
120
|
|
|
|
|
|
|
"darkslateblue" => [72,61,139], |
121
|
|
|
|
|
|
|
"darkslategray" => [47,79,79], |
122
|
|
|
|
|
|
|
"darkturquoise" => [0,206,209], |
123
|
|
|
|
|
|
|
"darkviolet" => [148,0,211], |
124
|
|
|
|
|
|
|
"deeppink" => [255,20,147], |
125
|
|
|
|
|
|
|
"deepskyblue" => [0,191,255], |
126
|
|
|
|
|
|
|
"dimgray" => [105,105,105], |
127
|
|
|
|
|
|
|
"dodgerblue" => [30,144,255], |
128
|
|
|
|
|
|
|
"firebrick" => [178,34,34], |
129
|
|
|
|
|
|
|
"floralwhite" => [255,250,240], |
130
|
|
|
|
|
|
|
"forestgreen" => [34,139,34], |
131
|
|
|
|
|
|
|
"fuchsia" => [255,0,255], |
132
|
|
|
|
|
|
|
"gainsboro" => [220,220,220], |
133
|
|
|
|
|
|
|
"ghostwhite" => [248,248,255], |
134
|
|
|
|
|
|
|
"gold" => [255,215,0], |
135
|
|
|
|
|
|
|
"goldenrod" => [218,165,32], |
136
|
|
|
|
|
|
|
"gray" => [128,128,128], |
137
|
|
|
|
|
|
|
"green" => [0,255,0], # [0,128,0] |
138
|
|
|
|
|
|
|
"greenyellow" => [173,255,47], |
139
|
|
|
|
|
|
|
"honeydew" => [240,255,240], |
140
|
|
|
|
|
|
|
"hotpink" => [255,105,180], |
141
|
|
|
|
|
|
|
"indianred" => [205,92,92], |
142
|
|
|
|
|
|
|
"indigo" => [75,0,130], |
143
|
|
|
|
|
|
|
"ivory" => [255,255,240], |
144
|
|
|
|
|
|
|
"khaki" => [240,230,140], |
145
|
|
|
|
|
|
|
"lavender" => [230,230,250], |
146
|
|
|
|
|
|
|
"lavenderblush" => [255,240,245], |
147
|
|
|
|
|
|
|
"lawngreen" => [124,252,0], |
148
|
|
|
|
|
|
|
"lemonchiffon" => [255,250,205], |
149
|
|
|
|
|
|
|
"lightblue" => [173,216,230], |
150
|
|
|
|
|
|
|
"lightcoral" => [240,128,128], |
151
|
|
|
|
|
|
|
"lightcyan" => [224,255,255], |
152
|
|
|
|
|
|
|
"lightgoldenrodyellow" => [250,250,210], |
153
|
|
|
|
|
|
|
"lightgreen" => [144,238,144], |
154
|
|
|
|
|
|
|
"lightgrey" => [211,211,211], |
155
|
|
|
|
|
|
|
"lightpink" => [255,182,193], |
156
|
|
|
|
|
|
|
"lightsalmon" => [255,160,122], |
157
|
|
|
|
|
|
|
"lightseagreen" => [32,178,170], |
158
|
|
|
|
|
|
|
"lightskyblue" => [135,206,250], |
159
|
|
|
|
|
|
|
"lightslategray" => [119,136,153], |
160
|
|
|
|
|
|
|
"lightsteelblue" => [176,196,222], |
161
|
|
|
|
|
|
|
"lightyellow" => [255,255,224], |
162
|
|
|
|
|
|
|
"lime" => [0,255,0], |
163
|
|
|
|
|
|
|
"limegreen" => [50,205,50], |
164
|
|
|
|
|
|
|
"linen" => [250,240,230], |
165
|
|
|
|
|
|
|
"magenta" => [255,0,255], |
166
|
|
|
|
|
|
|
"maroon" => [128,0,0], |
167
|
|
|
|
|
|
|
"mediumaquamarine" => [102,205,170], |
168
|
|
|
|
|
|
|
"mediumblue" => [0,0,205], |
169
|
|
|
|
|
|
|
"mediumorchid" => [186,85,211], |
170
|
|
|
|
|
|
|
"mediumpurple" => [147,112,219], |
171
|
|
|
|
|
|
|
"mediumseagreen" => [60,179,113], |
172
|
|
|
|
|
|
|
"mediumslateblue" => [123,104,238], |
173
|
|
|
|
|
|
|
"mediumspringgreen" => [0,250,154], |
174
|
|
|
|
|
|
|
"mediumturquoise" => [72,209,204], |
175
|
|
|
|
|
|
|
"mediumvioletred" => [199,21,133], |
176
|
|
|
|
|
|
|
"midnightblue" => [25,25,112], |
177
|
|
|
|
|
|
|
"mintcream" => [245,255,250], |
178
|
|
|
|
|
|
|
"mistyrose" => [255,228,225], |
179
|
|
|
|
|
|
|
"moccasin" => [255,228,181], |
180
|
|
|
|
|
|
|
"navajowhite" => [255,222,173], |
181
|
|
|
|
|
|
|
"navy" => [0,0,128], |
182
|
|
|
|
|
|
|
"oldlace" => [253,245,230], |
183
|
|
|
|
|
|
|
"olive" => [128,128,0], |
184
|
|
|
|
|
|
|
"olivedrab" => [107,142,35], |
185
|
|
|
|
|
|
|
"orange" => [255,165,0], |
186
|
|
|
|
|
|
|
"orangered" => [255,69,0], |
187
|
|
|
|
|
|
|
"orchid" => [218,112,214], |
188
|
|
|
|
|
|
|
"palegoldenrod" => [238,232,170], |
189
|
|
|
|
|
|
|
"palegreen" => [152,251,152], |
190
|
|
|
|
|
|
|
"paleturquoise" => [175,238,238], |
191
|
|
|
|
|
|
|
"palevioletred" => [219,112,147], |
192
|
|
|
|
|
|
|
"papayawhip" => [255,239,213], |
193
|
|
|
|
|
|
|
"peachpuff" => [255,218,185], |
194
|
|
|
|
|
|
|
"peru" => [205,133,63], |
195
|
|
|
|
|
|
|
"pink" => [255,192,203], |
196
|
|
|
|
|
|
|
"plum" => [221,160,221], |
197
|
|
|
|
|
|
|
"powderblue" => [176,224,230], |
198
|
|
|
|
|
|
|
"purple" => [128,0,128], |
199
|
|
|
|
|
|
|
"red" => [255,0,0], |
200
|
|
|
|
|
|
|
"rosybrown" => [188,143,143], |
201
|
|
|
|
|
|
|
"royalblue" => [65,105,225], |
202
|
|
|
|
|
|
|
"saddlebrown" => [139,69,19], |
203
|
|
|
|
|
|
|
"salmon" => [250,128,114], |
204
|
|
|
|
|
|
|
"sandybrown" => [244,164,96], |
205
|
|
|
|
|
|
|
"seagreen" => [46,139,87], |
206
|
|
|
|
|
|
|
"seashell" => [255,245,238], |
207
|
|
|
|
|
|
|
"sienna" => [160,82,45], |
208
|
|
|
|
|
|
|
"silver" => [192,192,192], |
209
|
|
|
|
|
|
|
"skyblue" => [135,206,235], |
210
|
|
|
|
|
|
|
"slateblue" => [106,90,205], |
211
|
|
|
|
|
|
|
"slategray" => [112,128,144], |
212
|
|
|
|
|
|
|
"snow" => [255,250,250], |
213
|
|
|
|
|
|
|
"springgreen" => [0,255,127], |
214
|
|
|
|
|
|
|
"steelblue" => [70,130,180], |
215
|
|
|
|
|
|
|
"tan" => [210,180,140], |
216
|
|
|
|
|
|
|
"teal" => [0,128,128], |
217
|
|
|
|
|
|
|
"thistle" => [216,191,216], |
218
|
|
|
|
|
|
|
"tomato" => [255,99,71], |
219
|
|
|
|
|
|
|
"turquoise" => [64,224,208], |
220
|
|
|
|
|
|
|
"violet" => [238,130,238], |
221
|
|
|
|
|
|
|
"wheat" => [245,222,179], |
222
|
|
|
|
|
|
|
"white" => [255,255,255], |
223
|
|
|
|
|
|
|
"whitesmoke" => [245,245,245], |
224
|
|
|
|
|
|
|
"yellow" => [255,255,0], |
225
|
|
|
|
|
|
|
"yellowgreen" => [154,205,50] |
226
|
|
|
|
|
|
|
); |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
__END__ |