line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
=head1 NAME |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
PDL::Graphics::LUT - provides access to a number of look-up tables |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 SYNOPSIS |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use PDL::Graphics::PGPLOT; |
9
|
|
|
|
|
|
|
use PDL::Graphics::LUT; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# what tables are available |
12
|
|
|
|
|
|
|
my @tables = lut_names(); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# get the reversed colour table 'smooth', |
15
|
|
|
|
|
|
|
# with the gamma intensity ramp |
16
|
|
|
|
|
|
|
my ( $l, $r, $g, $b ) = lut_data( 'smooth', 1, 'gamma' ); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# use the table idl5 in ctab |
19
|
|
|
|
|
|
|
ctab( lut_data('idl5') ); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DESCRIPTION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
PDL::Graphics::LUT contains a number of colour look-up tables |
24
|
|
|
|
|
|
|
(in rgb format) and intensity ramps, and provides routines to |
25
|
|
|
|
|
|
|
access this data. |
26
|
|
|
|
|
|
|
The format of the data is suitable for use by |
27
|
|
|
|
|
|
|
L. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Unlike the initial release of the package, the data tables are |
30
|
|
|
|
|
|
|
now stored within the PDL distribution as FITS files |
31
|
|
|
|
|
|
|
(see L$tabledir> and L$rampdir>), |
32
|
|
|
|
|
|
|
rather than in the module itself. |
33
|
|
|
|
|
|
|
Changes to these directories will be picked up on the next call |
34
|
|
|
|
|
|
|
to one of the package functions. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 FUNCTIONS |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head2 lut_names() |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=for ref |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Return, as a list, the names of the available colour tables. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=for usage |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
@tables = lut_names(); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head2 lut_ramps() |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=for ref |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
Return, as a list, the names of the available intensity ramps. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=for usage |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
@ramps = lut_ramps(); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 lut_data() |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=for ref |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Load in the requested colour table and intensity ramp. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=for usage |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
my ( $l, $r, $g, $b ) = lut_data( $table, [ $reverse, [ $ramp ] ] ); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Returns the levels and r, g, b components of the colour table |
69
|
|
|
|
|
|
|
C<$table>. If C<$reverse> is 1 (defaults to B<0> |
70
|
|
|
|
|
|
|
if not supplied), |
71
|
|
|
|
|
|
|
then the r, g, and b components are reversed before being |
72
|
|
|
|
|
|
|
returned. |
73
|
|
|
|
|
|
|
If not supplied, C<$ramp> defaults to B<"ramp"> |
74
|
|
|
|
|
|
|
(this is a linear intensity ramp). |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
The returned values are piddles containing values in the range |
77
|
|
|
|
|
|
|
0 to 1 inclusive, and are floats. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 VARIABLES |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 $tabledir |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=for ref |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
The directory in which the colour tables (in rgb format) |
86
|
|
|
|
|
|
|
are stored. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head2 $rampdir |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=for ref |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
The directory in which the intensity ramps are stored. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head2 $suffix |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=for ref |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
The suffix for the data files in C<$tabledir> and |
99
|
|
|
|
|
|
|
C<$rampdir>. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 FURTHER INFORMATION |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
The colour tables were taken from the STARLINK GAIA package, |
104
|
|
|
|
|
|
|
and are provided under the GNU copyleft. |
105
|
|
|
|
|
|
|
See http://star-www.rl.ac.uk/ and |
106
|
|
|
|
|
|
|
http://star-www.dur.ac.uk/~pdraper/ for more details. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 AUTHOR |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Doug Burke (djburke@cpan.org), with thanks to |
111
|
|
|
|
|
|
|
Peter Draper/STARLINK for providing the colour-table data, |
112
|
|
|
|
|
|
|
and Christian Soeller and Karl Glazebrook for their help. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
All rights reserved. There is no warranty. You are allowed |
115
|
|
|
|
|
|
|
to redistribute this software / documentation under certain |
116
|
|
|
|
|
|
|
conditions. For details, see the file COPYING in the PDL |
117
|
|
|
|
|
|
|
distribution. If this file is separated from the PDL distribution, |
118
|
|
|
|
|
|
|
the copyright notice should be included in the file. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=cut |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
package PDL::Graphics::LUT; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
# Just a plain function exporting package |
125
|
1
|
|
|
1
|
|
608
|
use Exporter; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
43
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
# attempt to avoid Unix-specific file/directory names |
128
|
1
|
|
|
1
|
|
6
|
use File::Spec; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
19
|
|
129
|
1
|
|
|
1
|
|
5
|
use File::Basename; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
113
|
|
130
|
|
|
|
|
|
|
|
131
|
1
|
|
|
1
|
|
670
|
use autodie; |
|
1
|
|
|
|
|
17588
|
|
|
1
|
|
|
|
|
5
|
|
132
|
|
|
|
|
|
|
|
133
|
1
|
|
|
1
|
|
7039
|
use PDL::Core qw/:Func :Internal/; # Grab the Core names |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
10
|
|
134
|
1
|
|
|
1
|
|
8
|
use PDL::Basic; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
135
|
1
|
|
|
1
|
|
7
|
use PDL::Types; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
150
|
|
136
|
1
|
|
|
1
|
|
9
|
use PDL::Slices; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
137
|
1
|
|
|
1
|
|
706
|
use PDL::IO::Misc; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
138
|
1
|
|
|
1
|
|
855
|
use PDL::IO::FITS; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
14
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
# should be careful that $suffix is a valid length on non-Unix systems |
141
|
|
|
|
|
|
|
$suffix = ".fits"; |
142
|
1
|
|
|
1
|
|
9
|
use vars qw( $tabledir $rampdir $suffix ); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
92
|
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
# should really use EXPORT_OK |
145
|
|
|
|
|
|
|
@EXPORT = qw( lut_names lut_ramps lut_data ); |
146
|
|
|
|
|
|
|
@EXPORT_OK = qw( $tabledir $rampdir $suffix ); |
147
|
|
|
|
|
|
|
@ISA = qw( Exporter ); |
148
|
|
|
|
|
|
|
|
149
|
1
|
|
|
1
|
|
8
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
292
|
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
############################################################################ |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
# can we find the data? |
154
|
|
|
|
|
|
|
BEGIN { |
155
|
1
|
|
|
1
|
|
17
|
my $d = File::Spec->catdir( "PDL", "Graphics", "LUT" ); |
156
|
1
|
|
|
|
|
3
|
my $lutdir = undef; |
157
|
1
|
|
|
|
|
3
|
foreach my $path ( @INC ) { |
158
|
2
|
|
|
|
|
15
|
my $check = File::Spec->catdir( $path, $d ); |
159
|
2
|
100
|
|
|
|
60
|
if ( -d $check ) { $lutdir = $check; last; } |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
2
|
|
160
|
|
|
|
|
|
|
} |
161
|
1
|
50
|
|
|
|
3
|
barf "Unable to find directory ${d} within the perl libraries.\n" |
162
|
|
|
|
|
|
|
unless defined $lutdir; |
163
|
1
|
|
|
|
|
8
|
$tabledir = File::Spec->catdir( $lutdir, "tables" ); |
164
|
1
|
|
|
|
|
14
|
$rampdir = File::Spec->catdir( $lutdir, "ramps" ); |
165
|
1
|
50
|
|
|
|
38
|
barf "Unable to find directory ${tabledir} within the perl libraries.\n" |
166
|
|
|
|
|
|
|
unless -d $tabledir; |
167
|
1
|
50
|
|
|
|
1021
|
barf "Unable to find directory ${rampdir} within the perl libraries.\n" |
168
|
|
|
|
|
|
|
unless -d $rampdir; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
############################################################################ |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub _lsdir_basename { |
174
|
2
|
|
|
2
|
|
11
|
my ($dir, $suffix) = @_; |
175
|
2
|
|
|
|
|
14
|
opendir my $fh, $dir; |
176
|
2
|
|
|
|
|
2864
|
map basename($_, $suffix), grep /\Q$suffix\E\z/, readdir $fh; |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
# exported functions |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
# Return the list of available tables |
182
|
1
|
|
|
1
|
1
|
94
|
sub lut_names () { _lsdir_basename $tabledir, $suffix } |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
# Return the list of available ramps |
185
|
1
|
|
|
1
|
1
|
6
|
sub lut_ramps () { _lsdir_basename $rampdir, $suffix } |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
# Return the requested colour table |
188
|
|
|
|
|
|
|
sub lut_data ($;$$) { |
189
|
3
|
|
|
3
|
1
|
3480
|
my $table = shift; |
190
|
3
|
100
|
|
|
|
13
|
my $reverse = $#_ != -1 ? shift : 0; |
191
|
3
|
100
|
|
|
|
11
|
my $ramp = $#_ != -1 ? shift : "ramp"; |
192
|
|
|
|
|
|
|
|
193
|
3
|
|
|
|
|
52
|
my $lfile = File::Spec->catfile( $tabledir, "${table}${suffix}" ); |
194
|
3
|
|
|
|
|
23
|
my $rfile = File::Spec->catfile( $rampdir, "${ramp}${suffix}" ); |
195
|
3
|
50
|
|
|
|
11
|
print "Reading colour table and intensity ramp from:\n $lfile\n $rfile\n" |
196
|
|
|
|
|
|
|
if $PDL::verbose; |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
# unknown table? |
199
|
3
|
50
|
|
|
|
78
|
unless ( -e $lfile ) { |
200
|
0
|
|
|
|
|
0
|
my @names = lut_names(); |
201
|
0
|
|
|
|
|
0
|
barf <<"EOD"; |
202
|
|
|
|
|
|
|
Unknown colour table $table |
203
|
|
|
|
|
|
|
Available tables: |
204
|
|
|
|
|
|
|
@names |
205
|
|
|
|
|
|
|
EOD |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
# unknown ramp? |
209
|
3
|
50
|
|
|
|
56
|
unless ( -e $rfile ) { |
210
|
0
|
|
|
|
|
0
|
my @names = lut_ramps(); |
211
|
0
|
|
|
|
|
0
|
barf <<"EOD"; |
212
|
|
|
|
|
|
|
Unknown intensity ramp $ramp |
213
|
|
|
|
|
|
|
Available ramps: |
214
|
|
|
|
|
|
|
@names |
215
|
|
|
|
|
|
|
EOD |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
# read in rgb data |
219
|
3
|
|
|
|
|
18
|
my $rgb = rfits $lfile; |
220
|
3
|
50
|
|
|
|
17
|
$rgb = float($rgb) if $rgb->get_datatype != $PDL_F; |
221
|
3
|
|
|
|
|
11
|
my ( @ldims ) = $rgb->dims; |
222
|
3
|
50
|
33
|
|
|
16
|
barf "LUT file $lfile is not the correct format (ie n by 3)\n" |
223
|
|
|
|
|
|
|
unless $#ldims == 1 and $ldims[1] == 3; |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
# read in intensity data |
226
|
3
|
|
|
|
|
10
|
my $l = rfits $rfile; |
227
|
3
|
50
|
|
|
|
21
|
$l = float($l) if $l->get_datatype != $PDL_F; |
228
|
3
|
50
|
|
|
|
16
|
barf "Ramp file $rfile does not match the colour table size.\n" |
229
|
|
|
|
|
|
|
unless $l->nelem == $ldims[0]; |
230
|
|
|
|
|
|
|
|
231
|
3
|
100
|
|
|
|
12
|
my $s = $reverse ? "-1:0" : ""; |
232
|
3
|
|
|
|
|
15
|
return ( $l, $rgb->slice("${s},(0)"), $rgb->slice("${s},(1)"), $rgb->slice("${s},(2)") ); |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
} # sub: lut_data() |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
# Exit with OK status |
237
|
|
|
|
|
|
|
1; |
238
|
|
|
|
|
|
|
|