-
Notifications
You must be signed in to change notification settings - Fork 2
/
idl-colors.i
102 lines (94 loc) · 3.19 KB
/
idl-colors.i
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
* idl-colors.i --
*
* Routines to manipulate IDL color files.
* Provides functions:
* - loadct: load IDL color table / get names of IDL color tables.
*
* $Id: idl-colors.i,v 1.2 2007-12-13 21:15:28 frigaut Exp $
*
* Copyright (c) 1996, Eric THIEBAUT ([email protected], Centre de
* Recherche Astrophysique de Lyon, 9 avenue Charles Andre, F-69561 Saint
* Genis Laval Cedex).
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details (to receive a copy of the GNU
* General Public License, write to the Free Software Foundation, Inc., 675
* Mass Ave, Cambridge, MA 02139, USA).
*/
require,"string.i";
require,"pathfun.i";
func loadct(which, file=)
/* DOCUMENT loadct, which;
color_names= loadct();
In the first form, load IDL color table identified by WHICH (either
a number or a name). When called as a function, e.g., second form,
returns an array of names of color tables.
Keyword FILE can be used to indicate an alternate file name (default
is Y_SITE + "data/colors1.tbl").
SEE ALSO palette.
*/
{
/* Open color tables file. */
if (is_void(file)) {
file = find_in_path("../data/colors1.tbl",takefirst=1);
if (is_void(file)) error,"Can't find colors1.tbl";
}
file= open(file, "rb");
/* Get number of color tables. */
ntables= char();
if (_read(file, 0, ntables) != sizeof(ntables)) {
error, "cannot read number of color tables";
}
ntables= long(ntables);
/* Eventually, seek names of color tables. */
if (structof(which) == string || !am_subroutine()) {
buf= array(char, 32, ntables);
if (_read(file, ntables * 768 + 1, buf) != sizeof(buf)) {
error, "cannot read names of color tables";
}
names= array(string, ntables);
for (i=1; i<=ntables; i++) {
names(i)= strtrim(string(&buf(,i)));
}
if (structof(which)==string) {
i= where(strtolower(names) == strtolower(which));
if (numberof(i) == 0) {
error, "bad color table name";
}
which= i(1);
}
} else if (which < 1 || which > ntables) {
error, "bad color table number";
}
/* Read color table data. */
if (!is_void(which)) {
if (structof(which) != long || dimsof(which)(1) != 0) {
error, "color table number must be a LONG scalar";
}
local r, g, b;
lut= array(char, 256, 3);
if (_read(file, 1 + (which - 1) * 768, lut) != sizeof(lut)) {
error, "cannot read color table";
}
//lut= long(lut);
palette, r, g, b, query=1;
x= span(0., 1., 256);
xp= span(0., 1., numberof(r));
palette, int(.5+interp(lut(,1), x, xp)),
int(.5+interp(lut(,2), x, xp)),
int(.5+interp(lut(,3), x, xp));
}
/* Close file and return. */
close, file;
if (!am_subroutine()) {
return names;
}
}