1 | |
---|
2 | ; $Id$ |
---|
3 | ; |
---|
4 | ; Copyright (c) 1982-2009, ITT Visual Information Solutions. All |
---|
5 | ; rights reserved. Unauthorized reproduction is prohibited. |
---|
6 | |
---|
7 | ;+ |
---|
8 | ; NAME: |
---|
9 | ; LOADCT |
---|
10 | ; |
---|
11 | ; PURPOSE: |
---|
12 | ; Load predefined color tables. |
---|
13 | ; |
---|
14 | ; CATEGORY: |
---|
15 | ; Image display. |
---|
16 | ; |
---|
17 | ; CALLING SEQUENCE: |
---|
18 | ; LOADCT [, Table] |
---|
19 | ; |
---|
20 | ; OPTIONAL INPUTS: |
---|
21 | ; Table: The number of the pre-defined color table to load, from 0 |
---|
22 | ; to 15. If this value is omitted, a menu of the available |
---|
23 | ; tables is printed and the user is prompted to enter a table |
---|
24 | ; number. |
---|
25 | ; |
---|
26 | ; KEYWORD PARAMETERS: |
---|
27 | ; FILE: If this keyword is set, the file by the given name is used |
---|
28 | ; instead of the file colors1.tbl in the IDL directory. This |
---|
29 | ; allows multiple IDL users to have their own color table file. |
---|
30 | ; The specified file must exist. |
---|
31 | ; GET_NAMES: If this keyword is present AND DEFINED, the names |
---|
32 | ; of the color tables are returned as a string array. |
---|
33 | ; No changes are made to the color table. |
---|
34 | ; NCOLORS = number of colors to use. Use color indices from 0 |
---|
35 | ; to the smaller of !D.TABLE_SIZE-1 and NCOLORS-1. |
---|
36 | ; Default = !D.TABLE_SIZE = all available colors. |
---|
37 | ; SILENT: If this keyword is set, the Color Table message is suppressed. |
---|
38 | ; BOTTOM = first color index to use. Use color indices from BOTTOM to |
---|
39 | ; BOTTOM+NCOLORS-1. Default = 0. |
---|
40 | ; RGB_TABLE: Set this keyword to a named variable in which to return |
---|
41 | ; the desired color table as an [NCOLORS, 3] array. |
---|
42 | ; If this keyword is set, then the color table is not loaded into |
---|
43 | ; the display, but is simply returned to the user. In addition, |
---|
44 | ; if RGB_TABLE is set then SILENT is also set to true. |
---|
45 | ; |
---|
46 | ; OUTPUTS: |
---|
47 | ; No explicit outputs. |
---|
48 | ; |
---|
49 | ; COMMON BLOCKS: |
---|
50 | ; COLORS: The IDL color common block. |
---|
51 | ; |
---|
52 | ; SIDE EFFECTS: |
---|
53 | ; The color tables of the currently-selected device are modified. |
---|
54 | ; |
---|
55 | ; RESTRICTIONS: |
---|
56 | ; Works from the file: $IDL_DIR/resource/colors/colors1.tbl or the file specified |
---|
57 | ; with the FILE keyword. |
---|
58 | ; |
---|
59 | ; PROCEDURE: |
---|
60 | ; The file "colors1.tbl" or the user-supplied file is read. If |
---|
61 | ; the currently selected device doesn't have 256 colors, the color |
---|
62 | ; data is interpolated from 256 colors to the number of colors |
---|
63 | ; available. |
---|
64 | ; |
---|
65 | ; The colors loaded into the display are saved in the common |
---|
66 | ; block COLORS, as both the current and original color vectors. |
---|
67 | ; |
---|
68 | ; Interpolation: If the current device has less than 256 colors, |
---|
69 | ; the color table data is interpolated to cover the number of |
---|
70 | ; colors in the device. |
---|
71 | ; |
---|
72 | ; MODIFICATION HISTORY: |
---|
73 | ; Old. For a widgetized version of this routine, see XLOADCT in the IDL |
---|
74 | ; widget library. |
---|
75 | ; DMS, 7/92, Added new color table format providing for more than |
---|
76 | ; 16 tables. Now uses file colors1.tbl. Old LOADCT procedure |
---|
77 | ; is now OLD_LOADCT. |
---|
78 | ; ACY, 9/92, Make a pixmap if no windows exist for X windows to |
---|
79 | ; determine properly the number of available colors. |
---|
80 | ; Add FILE keyword. |
---|
81 | ; WSO, 1/95, Updated for new directory structure |
---|
82 | ; AB, 10/3/95, The number of entries in the COLORS common block is |
---|
83 | ; now always !D.TABLE_SIZE instead of NCOLORS + BOTTOM as |
---|
84 | ; before. This better reflects the true state of the device and |
---|
85 | ; works with other color manipulations routines. |
---|
86 | ; DLD, 09/98, Avoid repeating a color table name in the printed list. |
---|
87 | ; CT, Nov 2006: Added RGB_TABLE keyword. |
---|
88 | ; |
---|
89 | ;- |
---|
90 | PRO loadct_i3, table_number, SILENT = silent, GET_NAMES = names, FILE=file, $ |
---|
91 | NCOLORS = nc1, BOTTOM=bottom, RGB_TABLE=rgbTable |
---|
92 | |
---|
93 | compile_opt idl2 |
---|
94 | |
---|
95 | common colors, r_orig, g_orig, b_orig, r_curr, g_curr, b_curr |
---|
96 | |
---|
97 | |
---|
98 | on_ioerror, bad |
---|
99 | on_error, 2 ;Return to caller if error |
---|
100 | get_lun, lun |
---|
101 | |
---|
102 | rgbTable = Arg_Present(rgbTable) |
---|
103 | silent = N_Elements(silent) ? silent : rgbTable |
---|
104 | |
---|
105 | if !d.name eq 'X' and !d.window eq -1 then begin ;Uninitialized? |
---|
106 | ; If so, make a dummy window to determine the # of colors available. |
---|
107 | window,/free,/pixmap,xs=4, ys=4 |
---|
108 | wdelete, !d.window |
---|
109 | endif |
---|
110 | |
---|
111 | if n_elements(bottom) gt 0 then cbot = bottom > 0 < (!D.TABLE_SIZE-1) $ |
---|
112 | else cbot = 0 |
---|
113 | nc = !d.table_size - cbot |
---|
114 | if n_elements(nc1) gt 0 then nc = nc < nc1 |
---|
115 | |
---|
116 | if nc eq 0 then message, 'Device has static color tables. Can''t load.' |
---|
117 | |
---|
118 | if (n_elements(file) GT 0) then filename = file $ |
---|
119 | else filename = filepath('colors1.tbl', subdir=['resource', 'colors']) |
---|
120 | |
---|
121 | openr,lun, filename, /block |
---|
122 | |
---|
123 | ntables = 0b |
---|
124 | readu, lun, ntables |
---|
125 | |
---|
126 | ; Read names? |
---|
127 | IF (n_params() eq 0 || arg_present(names) || ~silent) then begin |
---|
128 | names = bytarr(32, ntables) |
---|
129 | point_lun, lun, ntables * 768L + 1 ;Read table names |
---|
130 | readu, lun, names |
---|
131 | names = strtrim(names, 2) |
---|
132 | IF arg_present(names) THEN goto, close_file ;Return names? |
---|
133 | ENDIF |
---|
134 | |
---|
135 | if n_params() lt 1 then begin ;Summarize table? |
---|
136 | nlines = (ntables + 2) / 3 ;# of lines to print |
---|
137 | nend = nlines - ((nlines*3) - ntables) |
---|
138 | for i=0, nend-1 do $ ;Print each line |
---|
139 | print, format="(i3,'- ',a17, 3x, i3,'- ',a17, 3x, i3,'- ',a17)", $ |
---|
140 | i, names[i], i+nlines, names[i+nlines], i+2*nlines < (ntables-1), $ |
---|
141 | names[i+2*nlines < (ntables-1)] |
---|
142 | if (nend lt nlines) then begin |
---|
143 | for i=nend, nlines-1 do $ |
---|
144 | print, format="(i3,'- ',a17, 3x, i3,'- ',a17)", $ |
---|
145 | i, names[i], i+nlines, names[i+nlines] |
---|
146 | endif |
---|
147 | |
---|
148 | table_number = 0 |
---|
149 | read, table_number, PROMPT='Enter table number: ' |
---|
150 | endif |
---|
151 | |
---|
152 | if (table_number ge ntables) or (table_number lt 0) then begin |
---|
153 | message, 'Table number must be from 0 to ' + strtrim(ntables-1, 2) |
---|
154 | endif |
---|
155 | |
---|
156 | ;Tables defined? |
---|
157 | if (~rgbTable && n_elements(r_orig) lt !d.table_size) then begin |
---|
158 | r_orig = BYTSCL(indgen(!d.table_size)) |
---|
159 | g_orig = r_orig |
---|
160 | b_orig = r_orig |
---|
161 | endif |
---|
162 | |
---|
163 | |
---|
164 | if keyword_set(silent) eq 0 then $ |
---|
165 | message,'Loading table ' + names[table_number],/INFO |
---|
166 | aa=assoc(lun, bytarr(256),1) ;Read 256 long ints |
---|
167 | r = aa[table_number*3] |
---|
168 | g = aa[table_number*3+1] |
---|
169 | b = aa[table_number*3+2] |
---|
170 | |
---|
171 | if nc ne 256 then begin ;Interpolate |
---|
172 | p = (lindgen(nc) * 255) / (nc-1) |
---|
173 | r = r[p] |
---|
174 | g = g[p] |
---|
175 | b = b[p] |
---|
176 | endif |
---|
177 | |
---|
178 | if (rgbTable) then begin |
---|
179 | rgbTable = [[r], [g], [b]] |
---|
180 | endif else begin |
---|
181 | r_orig[cbot] = r |
---|
182 | g_orig[cbot] = g |
---|
183 | b_orig[cbot] = b |
---|
184 | r_curr = r_orig |
---|
185 | g_curr = g_orig |
---|
186 | b_curr = b_orig |
---|
187 | tvlct,r, g, b, cbot |
---|
188 | endelse |
---|
189 | goto, close_file |
---|
190 | |
---|
191 | bad: |
---|
192 | message, /CONTINUE, 'Error reading file: ' + filename + ', ' + !error_state.msg |
---|
193 | |
---|
194 | close_file: |
---|
195 | free_lun,lun |
---|
196 | |
---|
197 | end |
---|
198 | ;+ |
---|
199 | ; |
---|
200 | ; @file_comments |
---|
201 | ; Fastest than type loadct, file = 'palette.tbl' |
---|
202 | ; |
---|
203 | ; @categories |
---|
204 | ; Graphics, Color |
---|
205 | ; |
---|
206 | ; @param numpal {in}{optional} |
---|
207 | ; number of the color palette we want to select in the file palette.tbl |
---|
208 | ; |
---|
209 | ; @keyword LIGHTNESS |
---|
210 | ; a scalar used to change the Lightness of the color |
---|
211 | ; palette to be able to adjust according to the printer we use, |
---|
212 | ; the media (paper or slide)... |
---|
213 | ; lightness < 1 to get lighter colors |
---|
214 | ; > 1 to get darker colors |
---|
215 | ; |
---|
216 | ; @keyword FILE {default='palette.tbl'} |
---|
217 | ; The file containing the color palette. It can be in any directory of the !path |
---|
218 | ; |
---|
219 | ; @keyword GET_NAME |
---|
220 | ; Set this keyword to a named variable in which the names of the color tables |
---|
221 | ; are returned as a string array. No changes are made to the color table. |
---|
222 | ; |
---|
223 | ; @keyword _EXTRA |
---|
224 | ; Used to pass keywords to <proidl>LOADCT</proidl> |
---|
225 | ; |
---|
226 | ; @history |
---|
227 | ; |
---|
228 | ; - pinsardf 20120814T142936Z curie51.c-curie.tgcc.ccc.cea.fr (Linux) |
---|
229 | ; |
---|
230 | ; * not anymore set_plot, 'x' when !d.name = 'z' |
---|
231 | ; |
---|
232 | ; Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
233 | ; 30/3/1999: add extra |
---|
234 | ; 6/7/1999: mac/windows compatibility |
---|
235 | ; |
---|
236 | ; @version |
---|
237 | ; $Id$ |
---|
238 | ; |
---|
239 | ;- |
---|
240 | PRO lct, numpal, FILE=file, GET_NAME=get_name, LIGHTNESS=lightness, _EXTRA=ex |
---|
241 | ; |
---|
242 | compile_opt idl2, strictarrsubs |
---|
243 | ; |
---|
244 | ; definition of the name of the file containing colors palettes. |
---|
245 | if keyword_set(file) then nametbl = file ELSE nametbl = 'palette.tbl' |
---|
246 | ; look for nametbl file |
---|
247 | nametbl = find(nametbl, /firstfound, /nopro) |
---|
248 | if nametbl NE 'NOT FOUND' then BEGIN |
---|
249 | if n_elements(ex) NE 0 then $ |
---|
250 | if (where(tag_names(ex) EQ 'FILE'))[0] NE -1 then ex.FILE = nametbl |
---|
251 | ; |
---|
252 | if arg_present(get_name) then begin |
---|
253 | if n_elements(numpal) EQ 0 then $ |
---|
254 | loadct_i3, file = nametbl, GET_NAME = get_name, _EXTRA = ex $ |
---|
255 | ELSE loadct_i3, numpal, file = nametbl, /silent, GET_NAME = get_name, _EXTRA = ex |
---|
256 | ENDIF ELSE BEGIN |
---|
257 | if n_elements(numpal) EQ 0 then loadct_i3, file = nametbl, _EXTRA = ex $ |
---|
258 | ELSE loadct_i3, numpal, file = nametbl, /silent, _EXTRA = ex |
---|
259 | ENDELSE |
---|
260 | ; |
---|
261 | if !d.name EQ 'PS' AND keyword_set(lightness) then palit, lightness |
---|
262 | ; |
---|
263 | ENDIF ELSE ras = report('The file containing the color palettes doesn''t exist...') |
---|
264 | |
---|
265 | return |
---|
266 | end |
---|