line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tempest; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
334595
|
use strict; |
|
6
|
|
|
|
|
19
|
|
|
6
|
|
|
|
|
736
|
|
4
|
6
|
|
|
6
|
|
34
|
use warnings; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
278
|
|
5
|
6
|
|
|
6
|
|
7508
|
use version; |
|
6
|
|
|
|
|
27953
|
|
|
6
|
|
|
|
|
47
|
|
6
|
|
|
|
|
|
|
|
7
|
6
|
|
|
6
|
|
616
|
use Carp; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
926
|
|
8
|
6
|
|
|
6
|
|
99
|
use File::Basename; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
1197
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Tempest - Flexible temperature-map/heat-map generator |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 DESCRIPTION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Tempest is implemented natively in multiple programming languages, including |
17
|
|
|
|
|
|
|
Perl 5. This implementation is "pure" Perl, meaning that there is no |
18
|
|
|
|
|
|
|
C or XS code to configure or compile. Installation entails the steps for any |
19
|
|
|
|
|
|
|
modern CPAN module: |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
perl Makefile.PL |
22
|
|
|
|
|
|
|
make |
23
|
|
|
|
|
|
|
make test |
24
|
|
|
|
|
|
|
make install |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 VERSION |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Version 2010.09.26 |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Tempest API Version 2009.07.15 |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=cut |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
our $VERSION = qv('2010.09.26'); |
35
|
|
|
|
|
|
|
our $API_VERSION = qv('2009.07.15'); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 SYNOPSIS |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
This module exposes the Tempest API through class instantiation: |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
use Tempest; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Create new instance |
44
|
|
|
|
|
|
|
$heatmap = new Tempest( |
45
|
|
|
|
|
|
|
'input_file' => 'screenshot.png', |
46
|
|
|
|
|
|
|
'output_file' => 'heatmap.png', |
47
|
|
|
|
|
|
|
'coordinates' => [ [0,10], [2,14], [2,14] ], |
48
|
|
|
|
|
|
|
)); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# Configure as needed |
51
|
|
|
|
|
|
|
$heatmap->set_image_lib( Tempest::LIB_GD ); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Generate and write heatmap image |
54
|
|
|
|
|
|
|
$heatmap->render(); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 CONSTANTS |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
These constants can be assigned to the C property to specify use |
59
|
|
|
|
|
|
|
of a given image library for all image manipulations. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head3 C |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
For forcing use of L support. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head3 C |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
For forcing use of L support. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head3 C |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
For forcing use of L support. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |
74
|
|
|
|
|
|
|
|
75
|
6
|
|
|
6
|
|
40
|
use constant LIB_MAGICK => 'Image::Magick'; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
666
|
|
76
|
6
|
|
|
6
|
|
34
|
use constant LIB_GMAGICK => 'Graphics::Magick'; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
290
|
|
77
|
6
|
|
|
6
|
|
30
|
use constant LIB_GD => 'GD'; |
|
6
|
|
|
|
|
84
|
|
|
6
|
|
|
|
|
28038
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 PROPERTIES |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 Required Properties |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head3 C |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
The generated heatmap will share the same dimensions as this image, |
86
|
|
|
|
|
|
|
and - if indicated - will be overlaid onto this image with a given |
87
|
|
|
|
|
|
|
opacity. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=cut |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my %input_file; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head3 C |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
The generated heatmap will be written to this path, replacing any |
96
|
|
|
|
|
|
|
existing file without warning. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=cut |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
my %output_file; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head3 C |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
The contained x,y coordinates will mark the center of all plotted data |
105
|
|
|
|
|
|
|
points in the heatmap. Coordinates can - and in many cases are |
106
|
|
|
|
|
|
|
expected to - be repeated. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
my %coordinates; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 Optional Properties |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head3 C |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
This image, expected to be greyscale, is used to plot data points for |
117
|
|
|
|
|
|
|
each of the given coordinates. Defaults to a bundled image, if none |
118
|
|
|
|
|
|
|
is provided. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
my %plot_file; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head3 C |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
This image, expected to be a true color vertical gradient, is used as a |
127
|
|
|
|
|
|
|
color lookup table and is applied to the generated heatmap. Defaults |
128
|
|
|
|
|
|
|
to a bundled image, if none is provided. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
my %color_file; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head3 C |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
If true, the heatmap is overlaid onto the input image with a given |
137
|
|
|
|
|
|
|
opacity before being written to the filesystem. Defaults to B. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=cut |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
my %overlay; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head3 C |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Indicates with what percentage of opaqueness to overlay the heatmap |
146
|
|
|
|
|
|
|
onto the input image. If 0, the heatmap will not be visible; if 100, |
147
|
|
|
|
|
|
|
the input image will not be visible. Defaults to b<50>. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=cut |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
my %opacity; |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head3 C |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Indicates which supported image manipulation library should be used |
156
|
|
|
|
|
|
|
for rendering operations. Defaults to the first available from the |
157
|
|
|
|
|
|
|
following: |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=cut |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
my %image_lib; |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
my @_required = ('input_file', 'output_file', 'coordinates'); |
164
|
|
|
|
|
|
|
my @_optional = ('plot_file', 'color_file', 'overlay', 'opacity', 'image_lib'); |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 METHODS |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head2 C |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Class constructor, accepts a hash of named arguments corresponding to |
171
|
|
|
|
|
|
|
the class' own getter and setter methods. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
$heatmap = new Tempest( |
174
|
|
|
|
|
|
|
'input_file' => 'screenshot.png', |
175
|
|
|
|
|
|
|
'output_file' => 'heatmap.png', |
176
|
|
|
|
|
|
|
'coordinates' => [ [0,10], [2,14], [2,14] ], |
177
|
|
|
|
|
|
|
); |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=cut |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub new { |
182
|
1
|
|
|
1
|
1
|
114
|
my $class = shift; |
183
|
|
|
|
|
|
|
|
184
|
1
|
50
|
|
|
|
7
|
croak('Bad parameter list, should be a hash') if @_ % 2; |
185
|
1
|
|
|
|
|
8
|
my %params = @_; |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
# inside-out object model |
188
|
1
|
|
|
|
|
4
|
my $self = bless \(my $dummy), $class; |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
# set defaults |
191
|
1
|
|
|
|
|
40
|
$plot_file{$self} = dirname(__FILE__) . '/Tempest/data/plot.png'; |
192
|
1
|
|
|
|
|
33
|
$color_file{$self} = dirname(__FILE__) . '/Tempest/data/clut.png'; |
193
|
1
|
|
|
|
|
4
|
$overlay{$self} = 1; |
194
|
1
|
|
|
|
|
3
|
$opacity{$self} = 50; |
195
|
1
|
|
|
|
|
7
|
$image_lib{$self} = $self->_calc_image_lib(); |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
# for all required parameters.. |
198
|
0
|
|
|
|
|
0
|
for my $param_name (@_required) { |
199
|
|
|
|
|
|
|
# ..ensure they were provided |
200
|
0
|
0
|
|
|
|
0
|
if(!exists $params{$param_name}) { |
201
|
0
|
|
|
|
|
0
|
croak("Missing required parameter '$param_name'"); |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
# ..and call each of their setters |
205
|
0
|
|
|
|
|
0
|
eval('$self->set_' . $param_name . '($params{$param_name})'); |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
# for all optional parameters.. |
209
|
0
|
|
|
|
|
0
|
for my $param_name (@_optional) { |
210
|
|
|
|
|
|
|
# ..if they were provided.. |
211
|
0
|
0
|
|
|
|
0
|
if(exists $params{$param_name}) { |
212
|
|
|
|
|
|
|
# ..call their setters |
213
|
0
|
|
|
|
|
0
|
eval('$self->set_' . $param_name . '($params{$param_name})'); |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
0
|
|
|
|
|
0
|
return $self; |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head2 C |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
Initiates processing of provided arguments, and writes a heatmap image |
223
|
|
|
|
|
|
|
to the filesystem. Returns B on success. |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
die('Rendering failed') if ! $heatmap->render(); |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=cut |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
sub render { |
230
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
231
|
|
|
|
|
|
|
|
232
|
0
|
|
|
|
|
0
|
my $lib_name = ucfirst(lc($image_lib{$self})); |
233
|
0
|
|
|
|
|
0
|
$lib_name =~ s/\W//g; |
234
|
|
|
|
|
|
|
|
235
|
0
|
|
|
|
|
0
|
my $result = eval('require Tempest::'.$lib_name.'; return Tempest::'.$lib_name.'::render($self);'); |
236
|
0
|
0
|
|
|
|
0
|
croak($@) if $@; |
237
|
0
|
|
|
|
|
0
|
return $result; |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=head2 C |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
Returns the version number of the current release. |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
die('Outdated') if $heatmap->version() lt '2009.06.15'; |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=cut |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
sub version { |
249
|
0
|
|
|
0
|
1
|
0
|
return $VERSION; |
250
|
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=head2 C |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
Returns the version number of the currently supported Tempest API. |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
die('API is outdated') if $heatmap->api_version() lt '2009.06.15'; |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=cut |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
sub api_version { |
261
|
0
|
|
|
0
|
1
|
0
|
return $API_VERSION; |
262
|
|
|
|
|
|
|
} |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=head2 Setters |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
Each setter method assigns a new value to its respective property. |
267
|
|
|
|
|
|
|
The setters also return the current class instance, so they can be 'chained'. |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
For example, if we wanted to change the C used for image processing, |
270
|
|
|
|
|
|
|
and immediately render the resulting heatmap: |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
# render heatmap with Image::Magick support |
273
|
|
|
|
|
|
|
$heatmap ->set_image_lib( Tempest::LIB_MAGICK ) ->render(); |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=head2 Getters |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
Each getter method returns the current value of its respective property. |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
For example, if we wanted to retrieve the C to be rendered and |
280
|
|
|
|
|
|
|
immediately output them with the L module: |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
use Data::Dumper; |
283
|
|
|
|
|
|
|
print Dumper( $heatmap->get_coordinates() ); |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
=cut |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
sub set_input_file { |
288
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
289
|
0
|
|
|
|
|
0
|
my $input_file = shift; |
290
|
|
|
|
|
|
|
|
291
|
0
|
0
|
|
|
|
0
|
if(-r $input_file) { |
292
|
0
|
|
|
|
|
0
|
$input_file{$self} = $input_file; |
293
|
|
|
|
|
|
|
} |
294
|
|
|
|
|
|
|
else { |
295
|
0
|
|
|
|
|
0
|
croak("Image '$input_file' is not readable"); |
296
|
|
|
|
|
|
|
} |
297
|
|
|
|
|
|
|
|
298
|
0
|
|
|
|
|
0
|
return $self; |
299
|
|
|
|
|
|
|
} |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
sub get_input_file { |
302
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
303
|
0
|
|
|
|
|
0
|
return $input_file{$self}; |
304
|
|
|
|
|
|
|
} |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
sub set_output_file { |
308
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
309
|
0
|
|
|
|
|
0
|
my $output_file = shift; |
310
|
|
|
|
|
|
|
|
311
|
0
|
0
|
0
|
|
|
0
|
if((! -e $output_file) || -w $output_file) { |
312
|
0
|
|
|
|
|
0
|
$output_file{$self} = $output_file; |
313
|
|
|
|
|
|
|
} |
314
|
|
|
|
|
|
|
else { |
315
|
0
|
|
|
|
|
0
|
croak("Image '$output_file' is not writable"); |
316
|
|
|
|
|
|
|
} |
317
|
|
|
|
|
|
|
|
318
|
0
|
|
|
|
|
0
|
return $self; |
319
|
|
|
|
|
|
|
} |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
sub get_output_file { |
322
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
323
|
0
|
|
|
|
|
0
|
return $output_file{$self}; |
324
|
|
|
|
|
|
|
} |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
sub set_coordinates { |
328
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
329
|
0
|
|
|
|
|
0
|
my $coordinates = shift; |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
# verify an array of 2-element arrays |
332
|
0
|
0
|
|
|
|
0
|
if(ref($coordinates) ne 'ARRAY') { |
333
|
0
|
|
|
|
|
0
|
croak('Bad coordinates: not an array reference'); |
334
|
|
|
|
|
|
|
} |
335
|
|
|
|
|
|
|
|
336
|
0
|
|
|
|
|
0
|
for my $pair (@{$coordinates}) { |
|
0
|
|
|
|
|
0
|
|
337
|
0
|
0
|
0
|
|
|
0
|
if(ref($pair) ne 'ARRAY' || scalar(@{$pair}) != 2) { |
|
0
|
|
|
|
|
0
|
|
338
|
0
|
|
|
|
|
0
|
croak('Bad coordinate pair: ' . join(',', @{$pair})); |
|
0
|
|
|
|
|
0
|
|
339
|
|
|
|
|
|
|
} |
340
|
|
|
|
|
|
|
} |
341
|
|
|
|
|
|
|
|
342
|
0
|
|
|
|
|
0
|
$coordinates{$self} = $coordinates; |
343
|
0
|
|
|
|
|
0
|
return $self; |
344
|
|
|
|
|
|
|
} |
345
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
sub get_coordinates { |
347
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
348
|
0
|
|
|
|
|
0
|
return $coordinates{$self}; |
349
|
|
|
|
|
|
|
} |
350
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
sub set_plot_file { |
353
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
354
|
0
|
|
|
|
|
0
|
my $plot_file = shift; |
355
|
|
|
|
|
|
|
|
356
|
0
|
0
|
|
|
|
0
|
if(-r $plot_file) { |
357
|
0
|
|
|
|
|
0
|
$plot_file{$self} = $plot_file; |
358
|
|
|
|
|
|
|
} |
359
|
|
|
|
|
|
|
else { |
360
|
0
|
|
|
|
|
0
|
croak("Image '$plot_file' is not readable"); |
361
|
|
|
|
|
|
|
} |
362
|
|
|
|
|
|
|
|
363
|
0
|
|
|
|
|
0
|
return $self; |
364
|
|
|
|
|
|
|
} |
365
|
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
sub get_plot_file { |
367
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
368
|
0
|
|
|
|
|
0
|
return $plot_file{$self}; |
369
|
|
|
|
|
|
|
} |
370
|
|
|
|
|
|
|
|
371
|
|
|
|
|
|
|
|
372
|
|
|
|
|
|
|
sub set_color_file { |
373
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
374
|
0
|
|
|
|
|
0
|
my $color_file = shift; |
375
|
|
|
|
|
|
|
|
376
|
0
|
0
|
|
|
|
0
|
if(-r $color_file) { |
377
|
0
|
|
|
|
|
0
|
$color_file{$self} = $color_file; |
378
|
|
|
|
|
|
|
} |
379
|
|
|
|
|
|
|
else { |
380
|
0
|
|
|
|
|
0
|
croak("Image '$color_file' is not readable"); |
381
|
|
|
|
|
|
|
} |
382
|
|
|
|
|
|
|
|
383
|
0
|
|
|
|
|
0
|
return $self; |
384
|
|
|
|
|
|
|
} |
385
|
|
|
|
|
|
|
|
386
|
|
|
|
|
|
|
sub get_color_file { |
387
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
388
|
0
|
|
|
|
|
0
|
return $color_file{$self}; |
389
|
|
|
|
|
|
|
} |
390
|
|
|
|
|
|
|
|
391
|
|
|
|
|
|
|
|
392
|
|
|
|
|
|
|
sub set_overlay { |
393
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
394
|
0
|
|
|
|
|
0
|
my $overlay = shift; |
395
|
|
|
|
|
|
|
|
396
|
0
|
0
|
|
|
|
0
|
$overlay{$self} = $overlay ? 1 : 0; |
397
|
0
|
|
|
|
|
0
|
return $self; |
398
|
|
|
|
|
|
|
} |
399
|
|
|
|
|
|
|
|
400
|
|
|
|
|
|
|
sub get_overlay { |
401
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
402
|
0
|
|
|
|
|
0
|
return $overlay{$self}; |
403
|
|
|
|
|
|
|
} |
404
|
|
|
|
|
|
|
|
405
|
|
|
|
|
|
|
|
406
|
|
|
|
|
|
|
sub set_opacity { |
407
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
408
|
0
|
|
|
|
|
0
|
my $opacity = shift; |
409
|
|
|
|
|
|
|
|
410
|
0
|
0
|
0
|
|
|
0
|
if($opacity >=0 && $opacity <= 100) { |
411
|
0
|
|
|
|
|
0
|
$opacity{$self} = $opacity; |
412
|
|
|
|
|
|
|
} |
413
|
|
|
|
|
|
|
else { |
414
|
0
|
|
|
|
|
0
|
croak("'$opacity' is not a valid percentage (integer from 0 to 100)"); |
415
|
|
|
|
|
|
|
} |
416
|
|
|
|
|
|
|
|
417
|
0
|
|
|
|
|
0
|
return $self; |
418
|
|
|
|
|
|
|
} |
419
|
|
|
|
|
|
|
|
420
|
|
|
|
|
|
|
sub get_opacity { |
421
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
422
|
0
|
|
|
|
|
0
|
return $opacity{$self}; |
423
|
|
|
|
|
|
|
} |
424
|
|
|
|
|
|
|
|
425
|
|
|
|
|
|
|
|
426
|
|
|
|
|
|
|
sub set_image_lib { |
427
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
428
|
0
|
|
|
|
|
0
|
my $image_lib = shift; |
429
|
|
|
|
|
|
|
|
430
|
0
|
0
|
|
|
|
0
|
if($self->has_image_lib($image_lib)) { |
431
|
0
|
|
|
|
|
0
|
$image_lib{$self} = $image_lib; |
432
|
|
|
|
|
|
|
} |
433
|
|
|
|
|
|
|
else { |
434
|
0
|
|
|
|
|
0
|
croak("Image library '$image_lib' could not be found"); |
435
|
|
|
|
|
|
|
} |
436
|
|
|
|
|
|
|
|
437
|
0
|
|
|
|
|
0
|
return $self; |
438
|
|
|
|
|
|
|
} |
439
|
|
|
|
|
|
|
|
440
|
|
|
|
|
|
|
sub get_image_lib { |
441
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
442
|
0
|
|
|
|
|
0
|
return $image_lib{$self}; |
443
|
|
|
|
|
|
|
} |
444
|
|
|
|
|
|
|
|
445
|
|
|
|
|
|
|
=head2 C |
446
|
|
|
|
|
|
|
|
447
|
|
|
|
|
|
|
Returns true value if the given image library is available. |
448
|
|
|
|
|
|
|
|
449
|
|
|
|
|
|
|
die('GD is unavailable') if ! $heatmap->has_image_lib(Tempest::LIB_GD); |
450
|
|
|
|
|
|
|
|
451
|
|
|
|
|
|
|
=cut |
452
|
|
|
|
|
|
|
|
453
|
|
|
|
|
|
|
sub has_image_lib { |
454
|
3
|
|
|
3
|
1
|
6
|
my $self = shift; |
455
|
3
|
|
|
|
|
4
|
my $image_lib = shift; |
456
|
|
|
|
|
|
|
|
457
|
|
|
|
|
|
|
# work as instance method or static method |
458
|
3
|
50
|
|
|
|
18
|
if(ref($self) ne 'Tempest') { |
459
|
3
|
|
|
|
|
4
|
$image_lib = $self; |
460
|
3
|
|
|
|
|
8
|
undef $self; |
461
|
|
|
|
|
|
|
} |
462
|
|
|
|
|
|
|
|
463
|
3
|
50
|
100
|
|
|
30
|
if($image_lib eq LIB_MAGICK || $image_lib eq LIB_GMAGICK || $image_lib eq LIB_GD) { |
|
|
|
66
|
|
|
|
|
464
|
3
|
|
|
1
|
|
262
|
eval("no warnings 'all'; require $image_lib;"); |
|
1
|
|
|
1
|
|
9
|
|
|
1
|
|
|
1
|
|
2
|
|
|
1
|
|
|
|
|
53
|
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
18
|
|
|
1
|
|
|
|
|
35
|
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
465
|
3
|
50
|
|
|
|
15
|
if(!$@) { |
466
|
0
|
|
|
|
|
0
|
return 1; |
467
|
|
|
|
|
|
|
} |
468
|
|
|
|
|
|
|
else { |
469
|
3
|
|
|
|
|
19
|
return 0; |
470
|
|
|
|
|
|
|
} |
471
|
|
|
|
|
|
|
} |
472
|
|
|
|
|
|
|
else { |
473
|
0
|
|
|
|
|
0
|
croak("Image library '$image_lib' is not supported"); |
474
|
|
|
|
|
|
|
} |
475
|
|
|
|
|
|
|
} |
476
|
|
|
|
|
|
|
|
477
|
|
|
|
|
|
|
# Determine optimal supported (and available) image library to use |
478
|
|
|
|
|
|
|
# not intended to be public, so no need to document it |
479
|
|
|
|
|
|
|
sub _calc_image_lib { |
480
|
1
|
|
|
1
|
|
4
|
for my $image_lib (LIB_MAGICK, LIB_GMAGICK, LIB_GD) { |
481
|
3
|
50
|
|
|
|
10
|
if(Tempest::has_image_lib($image_lib)) { |
482
|
0
|
|
|
|
|
0
|
return $image_lib; |
483
|
|
|
|
|
|
|
} |
484
|
|
|
|
|
|
|
} |
485
|
|
|
|
|
|
|
|
486
|
1
|
|
|
|
|
4464
|
croak('No supported image library could be found'); |
487
|
|
|
|
|
|
|
} |
488
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
=head2 C |
490
|
|
|
|
|
|
|
|
491
|
|
|
|
|
|
|
Class destructor, destroys the class instance. Normally not invoked directly. |
492
|
|
|
|
|
|
|
|
493
|
|
|
|
|
|
|
# free up resources |
494
|
|
|
|
|
|
|
$heatmap->DESTROY(); |
495
|
|
|
|
|
|
|
|
496
|
|
|
|
|
|
|
=cut |
497
|
|
|
|
|
|
|
|
498
|
|
|
|
|
|
|
sub DESTROY { |
499
|
1
|
|
|
1
|
|
52
|
my $self = shift; |
500
|
|
|
|
|
|
|
|
501
|
1
|
|
|
|
|
4
|
for my $param_name (@_required, @_optional) { |
502
|
|
|
|
|
|
|
{ |
503
|
6
|
|
|
6
|
|
58
|
no strict 'refs'; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
653
|
|
|
8
|
|
|
|
|
9
|
|
504
|
8
|
|
|
|
|
10
|
delete ${$param_name}{$self}; |
|
8
|
|
|
|
|
57
|
|
505
|
|
|
|
|
|
|
}; |
506
|
|
|
|
|
|
|
} |
507
|
|
|
|
|
|
|
} |
508
|
|
|
|
|
|
|
|
509
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
510
|
|
|
|
|
|
|
|
511
|
|
|
|
|
|
|
Copyright 2010 Evan Kaufman, all rights reserved. |
512
|
|
|
|
|
|
|
|
513
|
|
|
|
|
|
|
This program is released under the MIT license. |
514
|
|
|
|
|
|
|
|
515
|
|
|
|
|
|
|
L |
516
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
=head1 ADDITIONAL LINKS |
518
|
|
|
|
|
|
|
|
519
|
|
|
|
|
|
|
=over |
520
|
|
|
|
|
|
|
|
521
|
|
|
|
|
|
|
=item Tempest on Google Code: |
522
|
|
|
|
|
|
|
|
523
|
|
|
|
|
|
|
L |
524
|
|
|
|
|
|
|
|
525
|
|
|
|
|
|
|
=back |
526
|
|
|
|
|
|
|
|
527
|
|
|
|
|
|
|
=cut |
528
|
|
|
|
|
|
|
|
529
|
|
|
|
|
|
|
1; |