source: trunk/SRC/Picture/imdisp.pro @ 134

Last change on this file since 134 was 134, checked in by navarro, 18 years ago

change *.pro file properties (del eof-style, del executable, set keywords Id

  • Property svn:keywords set to Id
File size: 28.9 KB
Line 
1;-------------------------------------------------------------------------------
2;+
3; @hidden
4;-
5FUNCTION IMDISP_GETPOS, ASPECT, POSITION=POSITION, MARGIN=MARGIN
6;
7  compile_opt idl2, strictarrsubs
8;
9
10;- Compute a position vector given an aspect ratio (called by IMDISP_IMSIZE)
11
12;- Check arguments
13if (n_params() ne 1) then message, 'Usage: RESULT = IMDISP_GETPOS(ASPECT)'
14if (n_elements(aspect) eq 0) then message, 'ASPECT is undefined'
15
16;- Check keywords
17if (n_elements(position) eq 0) then position = [0.0, 0.0, 1.0, 1.0]
18if (n_elements(margin) eq 0) then margin = 0.1
19
20;- Get range limited aspect ratio and margin input values
21aspect_val = (float(aspect[0]) > 0.01) < 100.0
22margin_val = (float(margin[0]) > 0.0) < 0.495
23
24;- Compute aspect ratio of position vector in this window
25xsize = (position[2] - position[0]) * !d.x_vsize
26ysize = (position[3] - position[1]) * !d.y_vsize
27cur_aspect = ysize / xsize
28
29;- Compute aspect ratio of this window
30win_aspect = float(!d.y_vsize) / float(!d.x_vsize)
31
32;- Compute height and width in normalized units
33if (aspect_val ge cur_aspect) then begin
34  height = (position[3] - position[1]) - 2.0 * margin
35  width  = height * (win_aspect / aspect_val)
36endif else begin
37  width  = (position[2] - position[0]) - 2.0 * margin
38  height = width * (aspect_val / win_aspect)
39endelse
40
41;- Compute and return position vector
42xcenter = 0.5 * (position[0] + position[2])
43ycenter = 0.5 * (position[1] + position[3])
44x0 = xcenter - 0.5 * width
45y0 = ycenter - 0.5 * height
46x1 = xcenter + 0.5 * width
47y1 = ycenter + 0.5 * height
48return, [x0, y0, x1, y1]
49
50END
51;-------------------------------------------------------------------------------
52;+
53; @hidden
54;-
55FUNCTION IMDISP_IMSCALE, IMAGE, RANGE=RANGE, BOTTOM=BOTTOM, NCOLORS=NCOLORS, $
56  NEGATIVE=NEGATIVE
57;
58  compile_opt idl2, strictarrsubs
59;
60
61;- Byte-scale an image (called by IMDISP)
62
63;- Check arguments
64if (n_params() ne 1) then message, 'Usage: RESULT = IMDISP_IMSCALE(IMAGE)'
65if (n_elements(image) eq 0) then message, 'Argument IMAGE is undefined'
66
67;- Check keywords
68if (n_elements(range) eq 0) then begin
69  min_value = min(image, max=max_value)
70  range = [min_value, max_value]
71endif
72if (n_elements(bottom) eq 0) then bottom = 0B
73if (n_elements(ncolors) eq 0) then ncolors = !d.table_size - bottom
74
75;- Compute the scaled image
76scaled = bytscl(image, min=range[0], max=range[1], top=(ncolors - 1))
77
78;- Create a negative image if required
79if keyword_set(negative) then scaled = byte(ncolors - 1) - scaled
80
81;- Return the scaled image in the correct color range
82return, scaled + byte(bottom)
83
84END
85;-------------------------------------------------------------------------------
86;+
87; @hidden
88;-
89FUNCTION IMDISP_IMREGRID, DATA, NX, NY, INTERP=INTERP
90;
91  compile_opt idl2, strictarrsubs
92;
93
94;- Regrid a 2D array (called by IMDISP)
95
96;- Check arguments
97if (n_params() ne 3) then $
98  message, 'Usage: RESULT = IMDISP_IMREGRID(DATA, NX, NY)'
99if (n_elements(data) eq 0) then message, 'Argument DATA is undefined'
100result = size(data)
101ndims = result[0]
102dims = result[1:ndims]
103if (ndims ne 2) then message, 'Argument DATA must have 2 dimensions'
104if (n_elements(nx) eq 0) then message, 'Argument NX is undefined'
105if (n_elements(ny) eq 0) then message, 'Argument NY is undefined'
106if (nx lt 1) then message, 'NX must be 1 or greater'
107if (ny lt 1) then message, 'NY must be 1 or greater'
108
109;- Copy the array if the requested size is the same as the current size
110if (nx eq dims[0]) and (ny eq dims[1]) then begin
111  new = data
112  return, new
113endif
114
115;- Compute index arrays for bilinear interpolation
116xindex = (findgen(nx) + 0.5) * (dims[0] / float(nx)) - 0.5
117yindex = (findgen(ny) + 0.5) * (dims[1] / float(ny)) - 0.5
118
119;- Round the index arrays if nearest neighbor sampling is required
120if (keyword_set(interp) eq 0) then begin
121  xindex = round(xindex)
122  yindex = round(yindex)
123endif
124
125;- Return regridded array
126return, interpolate(data, xindex, yindex, /grid)
127
128END
129;-------------------------------------------------------------------------------
130;+
131; @hidden
132;-
133PRO IMDISP_IMSIZE, IMAGE, X0, Y0, XSIZE, YSIZE, ASPECT=ASPECT, $
134  POSITION=POSITION, MARGIN=MARGIN
135;
136  compile_opt idl2, strictarrsubs
137;
138
139;- Compute the size and offset for an image (called by IMDISP)
140
141;- Check arguments
142if (n_params() ne 5) then $
143  message, 'Usage: IMDISP_IMSIZE, IMAGE, X0, Y0, XSIZE, YSIZE'
144if (n_elements(image) eq 0) then $
145  message, 'Argument IMAGE is undefined'
146if (n_elements(position) eq 0) then position = [0.0, 0.0, 1.0, 1.0]
147if (n_elements(position) ne 4) then $
148  message, 'POSITION must be a 4 element vector'
149if (n_elements(margin) eq 0) then margin = 0.1
150if (n_elements(margin) ne 1) then $
151  message, 'MARGIN must be a scalar'
152
153;- Get image dimensions
154result = size(image)
155ndims = result[0]
156if (ndims ne 2) then message, 'IMAGE must be a 2D array'
157dims = result[1 : ndims]
158
159;- Get aspect ratio for image
160if (n_elements(aspect) eq 0) then $
161  aspect = float(dims[1]) / float(dims[0])
162if (n_elements(aspect) ne 1) then $
163  message, 'ASPECT must be a scalar'
164
165;- Check output parameters
166if (arg_present(x0) ne 1) then message, 'Argument XO cannot be set'
167if (arg_present(y0) ne 1) then message, 'Argument YO cannot be set'
168if (arg_present(xsize) ne 1) then message, 'Argument XSIZE cannot be set'
169if (arg_present(ysize) ne 1) then message, 'Argument YSIZE cannot be set'
170
171;- Get approximate image position
172position = imdisp_getpos(aspect, position=position, margin=margin)
173
174;- Compute lower left position of image (device units)
175x0 = round(position[0] * !d.x_vsize) > 0L
176y0 = round(position[1] * !d.y_vsize) > 0L
177
178;- Compute size of image (device units)
179xsize = round((position[2] - position[0]) * !d.x_vsize) > 2L
180ysize = round((position[3] - position[1]) * !d.y_vsize) > 2L
181
182;- Recompute the image position based on actual image size
183position = fltarr(4)
184position[0] = x0 / float(!d.x_vsize)
185position[1] = y0 / float(!d.y_vsize)
186position[2] = (x0 + xsize) / float(!d.x_vsize)
187position[3] = (y0 + ysize) / float(!d.y_vsize)
188
189END
190;*******************************************************************************
191;+
192;
193; @file_comments
194;    Display an image on the current graphics device.
195;    IMDISP is an advanced replacement for TV and TVSCL.
196;
197;    - Supports WIN, MAC, X, CGM, PCL, PRINTER, PS, and Z graphics devices,
198;    - Image is automatically byte-scaled (can be disabled),
199;    - Custom byte-scaling of Pseudo color images via the RANGE keyword,
200;    - Pseudo (indexed) color and True color images are handled automatically,
201;    - 8-bit and 24-bit graphics devices  are handled automatically,
202;    - Decomposed color settings are handled automatically,
203;    - Image is automatically sized to fit the display (can be disabled),
204;    - The !P.MULTI system variable is honored for multiple image display,
205;    - Image can be positioned via the POSITION keyword,
206;    - Color table splitting via the BOTTOM and NCOLORS keywords,
207;    - Image aspect ratio customization via the ASPECT keyword,
208;    - Resized images can be resampled (default) or interpolated,
209;    - Top down image display via the ORDER keyword (!ORDER is ignored),
210;    - Selectable display channel (R/G/B) via the CHANNEL keyword,
211;    - Background can be set to a specified color via the BACKGROUND keyword,
212;    - Screen can be erased prior to image display via the ERASE keyword,
213;    - Plot axes can be drawn on the image via the AXIS keyword,
214;    - Photographic negative images can be displayed via the NEGATIVE keyword.
215;
216; @categories Image display
217;
218; @param IMAGE {in}{required} Array containing image data.
219;                Pseudo (indexed) color images must have 2 dimensions.
220;                True color images must have 3 dimensions, in either
221;                [3, NX, NY], [NX, 3, NY], or [NX, NY, 3] form.
222;
223; @keyword RANGE For Pseudo Color images only, a vector with two elements
224;                specifying the minimum and maximum values of the image
225;                array to be considered when the image is byte-scaled
226;                (default is minimum and maximum array values).
227;                This keyword is ignored for True Color images,
228;                or if the NOSCALE keyword is set.
229;
230; @keyword BOTTOM Bottom value in the color table to be used
231;                for the byte-scaled image
232;                (default is 0).
233;                This keyword is ignored if the NOSCALE keyword is set.
234;
235; @keyword NCOLORS Number of colors in the color table to be used
236;                for the byte-scaled image
237;                (default is !D.TABLE_SIZE - BOTTOM).
238;                This keyword is ignored if the NOSCALE keyword is set.
239;
240; @keyword MARGIN A scalar value specifying the margin to be maintained
241;                around the image in normal coordinates
242;                (default is 0.1, or 0.025 if !P.MULTI is set to display
243;                multiple images).
244;
245; @keyword INTERP If set, the resized image will be interpolated using
246;                bilinear interpolation
247;                (default is nearest neighbor sampling).
248;
249; @keyword DITHER If set, true color images will be dithered when displayed
250;                on an 8-bit graphics device
251;                (default is no dithering).
252;
253; @keyword ASPECT A scalar value specifying the aspect ratio (height/width)
254;                for the displayed image
255;                (default is to maintain native aspect ratio).
256;
257; @keyword POSITION On input, a 4-element vector specifying the position
258;                of the displayed image in the form [X0,Y0,X1,Y1] in
259;                in normal coordinates
260;                (default is [0.0,0.0,1.0,1.0]).
261;                See the examples below to display an image where only the
262;                offset and size are known (e.g. MAP_IMAGE output).
263;
264; @keyword OUT_POS On output, a 4-element vector specifying the position
265;                actually used to display the image.
266;
267; @keyword NOSCALE If set, the image will not be byte-scaled
268;                (default is to byte-scale the image).
269;
270; @keyword NORESIZE If set, the image will not be resized.
271;                (default is to resize the image to fit the display).
272;
273; @keyword ORDER If set, the image is displayed from the top down
274;                (default is to display the image from the bottom up).
275;                Note that the system variable !ORDER is always ignored.
276;
277; @keyword USEPOS If set, the image will be sized to exactly fit a supplied
278;                POSITION vector, over-riding ASPECT and MARGIN
279;                (default is to honor ASPECT and MARGIN when a POSITION
280;                vector is supplied).
281;
282; @keyword CHANNEL Display channel (Red, Green, or Blue) to be written.
283;                0 => All channels (the default)
284;                1 => Red channel
285;                2 => Green channel
286;                3 => Blue channel
287;                This keyword is only recognized by graphics devices which
288;                support 24-bit decomposed color (WIN, MAC, X). It is ignored
289;                by all other graphics devices. However True color (RGB)
290;                images can be displayed on any device supported by IMDISP.
291;
292; @keyword BACKGROUND If set to a positive integer, the background will be filled
293;                with the color defined by BACKGROUND.
294;
295; @keyword ERASE If set, the screen contents will be erased. Note that if
296;                !P.MULTI is set to display multiple images, the screen is
297;                always erased when the first image is displayed.
298;
299; @keyword AXIS If set, plot axes will be drawn on the image. The default
300;                x and y axis ranges are determined by the size of the image.
301;                When the AXIS keyword is set, IMDISP accepts any keywords
302;                supported by PLOT (e.g. TITLE, COLOR, CHARSIZE etc.).
303;
304; @keyword NEGATIVE If set, a photographic negative of the image is displayed.
305;                The values of BOTTOM and NCOLORS are honored. This keyword
306;                allows True color images scanned from color negatives to be
307;                displayed. It also allows Pseudo color images to be displayed
308;                as negatives without reversing the color table. This keyword
309;                is ignored if the NOSCALE keyword is set.
310;
311; @restrictions The image is displayed on the current graphics device.
312;
313; @restrictions Requires IDL 5.0 or higher (square bracket array syntax).
314;
315; @examples
316;
317;;- Load test data
318;
319;openr, lun, filepath('ctscan.dat', subdir='examples/data'), /get_lun
320;ctscan = bytarr(256, 256)
321;readu, lun, ctscan
322;free_lun, lun
323;openr, lun, filepath('hurric.dat', subdir='examples/data'), /get_lun
324;hurric = bytarr(440, 330)
325;readu, lun, hurric
326;free_lun, lun
327;read_jpeg, filepath('rose.jpg', subdir='examples/data'), rose
328;help, ctscan, hurric, rose
329;
330;;- Display single images
331;
332;!p.multi = 0
333;loadct, 0
334;imdisp, hurric, /erase
335;wait, 3.0
336;imdisp, rose, /interp, /erase
337;wait, 3.0
338;
339;;- Display multiple images without color table splitting
340;;- (works on 24-bit displays only; top 2 images are garbled on 8-bit displays)
341;
342;!p.multi = [0, 1, 3, 0, 0]
343;loadct, 0
344;imdisp, ctscan, margin=0.02
345;loadct, 13
346;imdisp, hurric, margin=0.02
347;imdisp, rose, margin=0.02
348;wait, 3.0
349;
350;;- Display multiple images with color table splitting
351;;- (works on 8-bit or 24-bit displays)
352;
353;!p.multi = [0, 1, 3, 0, 0]
354;loadct, 0, ncolors=64, bottom=0
355;imdisp, ctscan, margin=0.02, ncolors=64, bottom=0
356;loadct, 13, ncolors=64, bottom=64
357;imdisp, hurric, margin=0.02, ncolors=64, bottom=64
358;imdisp, rose, margin=0.02, ncolors=64, bottom=128
359;wait, 3.0
360;
361;;- Display an image at a specific position, over-riding aspect and margin
362;
363;!p.multi = 0
364;loadct, 0
365;imdisp, hurric, position=[0.0, 0.0, 1.0, 0.5], /usepos, /erase
366;wait, 3.0
367;
368;;- Display an image with axis overlay
369;
370;!p.multi = 0
371;loadct, 0
372;imdisp, rose, /axis, /erase
373;wait, 3.0
374;
375;;- Display an image with contour plot overlay
376;
377;!p.multi = 0
378;loadct, 0
379;imdisp, hurric, out_pos=out_pos, /erase
380;contour, smooth(hurric, 10, /edge), /noerase, position=out_pos, $
381;  xstyle=1, ystyle=1, levels=findgen(5)*40.0, /follow
382;wait, 3.0
383;
384;;- Display a small image with correct resizing
385;
386;!p.multi = 0
387;loadct, 0
388;data = (dist(8))[1:7, 1:7]
389;imdisp, data, /erase
390;wait, 3.0
391;imdisp, data, /interp
392;wait, 3.0
393;
394;;- Display a true color image without and with interpolation
395;
396;!p.multi = 0
397;imdisp, rose, /erase
398;wait, 3.0
399;imdisp, rose, /interp
400;wait, 3.0
401;
402;;- Display a true color image as a photographic negative
403;
404;imdisp, rose, /negative, /erase
405;wait, 3.0
406;
407;;- Display a true color image on PostScript output
408;;- (note that color table is handled automatically)
409;
410;current_device = !d.name
411;set_plot, 'PS'
412;device, /color, bits_per_pixel=8, filename='imdisp_true.ps'
413;imdisp, rose, /axis, title='PostScript True Color Output'
414;device, /close
415;set_plot, current_device
416;
417;;- Display a pseudo color image on PostScript output
418;
419;current_device = !d.name
420;set_plot, 'PS'
421;device, /color, bits_per_pixel=8, filename='imdisp_pseudo.ps'
422;loadct, 0
423;imdisp, hurric, /axis, title='PostScript Pseudo Color Output'
424;device, /close
425;set_plot, current_device
426;
427;;- Display an image where only the offset and size are known
428;
429;;- Read world elevation data
430;file = filepath('worldelv.dat', subdir='examples/data')
431;openr, lun, file, /get_lun
432;data = bytarr(360, 360)
433;readu, lun, data
434;free_lun, lun
435;;- Reorganize array so it spans 180W to 180E
436;world = data
437;world[0:179, *] = data[180:*, *]
438;world[180:*, *] = data[0:179, *]
439;;- Create remapped image
440;map_set, /orthographic, /isotropic, /noborder
441;remap = map_image(world, x0, y0, xsize, ysize, compress=1)
442;;- Convert offset and size to position vector
443;pos = fltarr(4)
444;pos[0] = x0 / float(!d.x_vsize)
445;pos[1] = y0 / float(!d.y_vsize)
446;pos[2] = (x0 + xsize) / float(!d.x_vsize)
447;pos[3] = (y0 + ysize) / float(!d.y_vsize)
448;;- Display the image
449;loadct, 0
450;imdisp, remap, pos=pos, /usepos
451;map_continents
452;map_grid
453;
454; @history Liam.Gumley@ssec.wisc.edu
455; http://cimss.ssec.wisc.edu/~gumley
456;
457; Copyright (C) 1999, 2000 Liam E. Gumley
458;
459; This program is free software; you can redistribute it and/or
460; modify it under the terms of the GNU General Public License
461; as published by the Free Software Foundation; either version 2
462; of the License, or (at your option) any later version.
463;
464; This program is distributed in the hope that it will be useful,
465; but WITHOUT ANY WARRANTY; without even the implied warranty of
466; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
467; GNU General Public License for more details.
468;
469; You should have received a copy of the GNU General Public License
470; along with this program; if not, write to the Free Software
471; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
472;
473; @version $Id: imdisp.pro,v 1.47 2002/06/05 16:31:07 gumley Exp $
474;
475;-
476;-------------------------------------------------------------------------------
477PRO IMDISP, IMAGE, RANGE=RANGE, BOTTOM=BOTTOM, NCOLORS=NCOLORS, $
478  MARGIN=MARGIN, INTERP=INTERP, DITHER=DITHER, ASPECT=ASPECT, $
479  POSITION=POSITION, OUT_POS=OUT_POS, NOSCALE=NOSCALE, NORESIZE=NORESIZE, $
480  ORDER=ORDER, USEPOS=USEPOS, CHANNEL=CHANNEL, $
481  BACKGROUND=BACKGROUND, ERASE=ERASE, $
482  AXIS=AXIS, NEGATIVE=NEGATIVE, _EXTRA=EXTRA_KEYWORDS
483;
484  compile_opt idl2, strictarrsubs
485;
486
487rcs_id = '$Id: imdisp.pro,v 1.47 2002/06/05 16:31:07 gumley Exp $'
488
489;-------------------------------------------------------------------------------
490;- CHECK INPUT
491;-------------------------------------------------------------------------------
492
493;- Check arguments
494if (n_params() ne 1) then message, 'Usage: IMDISP, IMAGE'
495if (n_elements(image) eq 0) then message, 'Argument IMAGE is undefined'
496if (max(!p.multi) eq 0) then begin
497  if (n_elements(margin) eq 0) then begin
498    if (n_elements(position) eq 4) then margin = 0.0 else margin = 0.1
499  endif
500endif else begin
501  if (n_elements(margin) eq 0) then margin = 0.025
502endelse
503if (n_elements(order) eq 0) then order = 0
504if (n_elements(channel) eq 0) then channel = 0
505
506;- Check position vector
507if (n_elements(position) gt 0) then begin
508  if (n_elements(position) ne 4) then $
509    message, 'POSITION must be a 4 element vector of the form [X0, Y0, X1, Y1]'
510  if (position[0] lt 0.0) then message, 'POSITION[0] must be GE 0.0'
511  if (position[1] lt 0.0) then message, 'POSITION[1] must be GE 0.0'
512  if (position[2] gt 1.0) then message, 'POSITION[2] must be LE 1.0'
513  if (position[3] gt 1.0) then message, 'POSITION[3] must be LE 1.0'
514  if (position[0] ge position[2]) then $
515    message, 'POSITION[0] must be LT POSITION[2]'
516  if (position[1] ge position[3]) then $
517    message, 'POSITION[1] must be LT POSITION[3]'
518endif
519
520;- Check the image dimensions
521result = size(image)
522ndims = result[0]
523if (ndims lt 2) or (ndims gt 3) then $
524  message, 'IMAGE must be a Pseudo Color (2D) or True Color (3D) image array'
525dims = result[1:ndims]
526
527;- Check that 3D image array is in valid true color format
528true = 0
529if (ndims eq 3) then begin
530  index = where(dims eq 3L, count)
531  if (count eq 0) then $
532    message, 'True Color dimensions must be [3,NX,NY], [NX,3,NY], or [NX,NY,3]'
533  true = 1
534  truedim = index[0]
535endif
536
537;- Check scaling range for pseudo color images
538if (true eq 0) then begin
539  if (n_elements(range) eq 0) then begin
540    min_value = min(image, max=max_value)
541    range = [min_value, max_value]
542  endif
543  if (n_elements(range) ne 2) then $
544    message, 'RANGE keyword must be a 2-element vector'
545endif else begin
546  if (n_elements(range) gt 0) then $
547    message, 'RANGE keyword is not used for True Color images', /continue
548endelse
549
550;- Check for supported graphics devices
551names = ['WIN', 'MAC', 'X', 'CGM', 'PCL', 'PRINTER', 'PS', 'Z']
552result = where((!d.name eq names), count)
553if (count eq 0) then message, 'Graphics device is not supported'
554
555;- Get color table information
556if ((!d.flags and 256) ne 0) and (!d.window lt 0) then begin
557  window, /free, /pixmap
558  wdelete, !d.window
559endif
560if (n_elements(bottom) eq 0) then bottom = 0
561if (n_elements(ncolors) eq 0) then ncolors = !d.table_size - bottom
562
563;- Get IDL version number
564version = float(!version.release)
565
566;- Check for IDL 5.2 or higher if printer device is selected
567if (version lt 5.2) and (!d.name eq 'PRINTER') then $
568  message, 'IDL 5.2 or higher is required for PRINTER device support'
569
570;-------------------------------------------------------------------------------
571;- GET RED, GREEN, AND BLUE COMPONENTS OF TRUE COLOR IMAGE
572;-------------------------------------------------------------------------------
573
574if (true eq 1) then begin
575    case truedim of
576      0 : begin
577            red = image[0, *, *]
578            grn = image[1, *, *]
579            blu = image[2, *, *]
580      end
581      1 : begin
582            red = image[*, 0, *]
583            grn = image[*, 1, *]
584            blu = image[*, 2, *]
585      end
586      2 : begin
587            red = image[*, *, 0]
588            grn = image[*, *, 1]
589            blu = image[*, *, 2]
590      end
591  endcase
592  red = reform(red, /overwrite)
593  grn = reform(grn, /overwrite)
594  blu = reform(blu, /overwrite)
595endif
596
597;-------------------------------------------------------------------------------
598;- COMPUTE POSITION FOR IMAGE
599;-------------------------------------------------------------------------------
600
601;- Save first element of !p.multi
602multi_first = !p.multi[0]
603
604;- Establish image position if not defined
605if (n_elements(position) eq 0) then begin
606  if (max(!p.multi) eq 0) then begin
607    position = [0.0, 0.0, 1.0, 1.0]
608  endif else begin
609    plot, [0], /nodata, xstyle=4, ystyle=4, xmargin=[0, 0], ymargin=[0, 0]
610    position = [!x.window[0], !y.window[0], !x.window[1], !y.window[1]]
611  endelse
612endif
613
614;- Erase and fill the background if required
615if (multi_first eq 0) then begin
616  if keyword_set(erase) then erase
617  if (n_elements(background) gt 0) then begin
618    polyfill, [-0.01,  1.01,  1.01, -0.01, -0.01], $
619      [-0.01, -0.01,  1.01,  1.01, -0.01], /normal, color=background[0]
620  endif
621endif
622
623;- Compute image aspect ratio if not defined
624if (n_elements(aspect) eq 0) then begin
625  case true of
626    0 : result = size(image)
627    1 : result = size(red)
628  endcase
629  dims = result[1:2]
630  aspect = float(dims[1]) / float(dims[0])
631endif
632
633;- Save image xrange and yrange for axis overlays
634xrange = [0, dims[0]]
635yrange = [0, dims[1]]
636if (order eq 1) then yrange = reverse(yrange)
637
638;- Set the aspect ratio and margin to fill the position window if requested
639if keyword_set(usepos) then begin
640  xpos_size = float(!d.x_vsize) * (position[2] - position[0])
641  ypos_size = float(!d.y_vsize) * (position[3] - position[1])
642  aspect_value = ypos_size / xpos_size
643  margin_value = 0.0
644endif else begin
645  aspect_value = aspect
646  margin_value = margin
647endelse
648
649;- Compute size of displayed image and save output position
650pos = position
651case true of
652  0 : imdisp_imsize, image, x0, y0, xsize, ysize, position=pos, $
653        aspect=aspect_value, margin=margin_value
654  1 : imdisp_imsize,   red, x0, y0, xsize, ysize, position=pos, $
655        aspect=aspect_value, margin=margin_value
656endcase
657out_pos = pos
658
659;-------------------------------------------------------------------------------
660;- BYTE-SCALE THE IMAGE IF REQUIRED
661;-------------------------------------------------------------------------------
662
663;- Choose whether to scale the image or not
664if (keyword_set(noscale) eq 0) then begin
665
666  ;- Scale the image
667  case true of
668    0 : scaled = imdisp_imscale(image, bottom=bottom, ncolors=ncolors, $
669          range=range, negative=keyword_set(negative))
670    1 : begin
671          scaled_dims = (size(red))[1:2]
672          scaled = bytarr(scaled_dims[0], scaled_dims[1], 3)
673          scaled[0, 0, 0] = imdisp_imscale(red, bottom=0, ncolors=256, $
674            negative=keyword_set(negative))
675          scaled[0, 0, 1] = imdisp_imscale(grn, bottom=0, ncolors=256, $
676            negative=keyword_set(negative))
677          scaled[0, 0, 2] = imdisp_imscale(blu, bottom=0, ncolors=256, $
678            negative=keyword_set(negative))
679        end
680  endcase
681
682endif else begin
683
684  ;- Don't scale the image
685  case true of
686    0 : scaled = image
687    1 : begin
688          scaled_dims = (size(red))[1:2]
689          scaled = replicate(red[0], scaled_dims[0], scaled_dims[1], 3)
690          scaled[0, 0, 0] = red
691          scaled[0, 0, 1] = grn
692          scaled[0, 0, 2] = blu
693        end
694  endcase
695
696endelse
697
698;-------------------------------------------------------------------------------
699;- DISPLAY IMAGE ON PRINTER DEVICE
700;-------------------------------------------------------------------------------
701
702if (!d.name eq 'PRINTER') then begin
703
704  ;- Display the image
705  case true of
706    0 : begin
707          device, /index_color
708          tv, scaled, x0, y0, xsize=xsize, ysize=ysize, order=order
709        end
710    1 : begin
711          device, /true_color
712          tv, scaled, x0, y0, xsize=xsize, ysize=ysize, order=order, true=3
713        end
714  endcase
715
716  ;- Draw axes if required
717  if keyword_set(axis) then $
718    plot, [0], /nodata, /noerase, position=out_pos, $
719      xrange=xrange, xstyle=1, yrange=yrange, ystyle=1, $
720      _extra=extra_keywords
721
722  ;- Return to caller
723  return
724
725endif
726
727;-------------------------------------------------------------------------------
728;- DISPLAY IMAGE ON GRAPHICS DEVICES WHICH HAVE SCALEABLE PIXELS
729;-------------------------------------------------------------------------------
730
731if ((!d.flags and 1) ne 0) then begin
732
733  ;- Display the image
734  case true of
735    0 : tv, scaled, x0, y0, xsize=xsize, ysize=ysize, order=order
736    1 : begin
737          tvlct, r, g, b, /get
738          loadct, 0, /silent
739          tv, scaled, x0, y0, xsize=xsize, ysize=ysize, order=order, true=3
740          tvlct, r, g, b
741        end
742  endcase
743
744  ;- Draw axes if required
745  if keyword_set(axis) then $
746    plot, [0], /nodata, /noerase, position=out_pos, $
747      xrange=xrange, xstyle=1, yrange=yrange, ystyle=1, $
748      _extra=extra_keywords
749
750  ;- Return to caller
751  return
752
753endif
754
755;-------------------------------------------------------------------------------
756;- RESIZE THE IMAGE
757;-------------------------------------------------------------------------------
758
759;- Resize the image
760if (keyword_set(noresize) eq 0) then begin
761  if (true eq 0) then begin
762    resized = imdisp_imregrid(scaled, xsize, ysize, interp=keyword_set(interp))
763  endif else begin
764    resized = replicate(scaled[0], xsize, ysize, 3)
765    resized[0, 0, 0] = imdisp_imregrid(reform(scaled[*, *, 0]), xsize, ysize, $
766      interp=keyword_set(interp))
767    resized[0, 0, 1] = imdisp_imregrid(reform(scaled[*, *, 1]), xsize, ysize, $
768      interp=keyword_set(interp))
769    resized[0, 0, 2] = imdisp_imregrid(reform(scaled[*, *, 2]), xsize, ysize, $
770      interp=keyword_set(interp))
771  endelse
772endif else begin
773  resized = temporary(scaled)
774  x0 = 0
775  y0 = 0
776endelse
777
778;-------------------------------------------------------------------------------
779;- GET BIT DEPTH FOR THIS DISPLAY
780;-------------------------------------------------------------------------------
781
782;- If this device supports windows, make sure a window has been opened
783if (!d.flags and 256) ne 0 then begin
784  if (!d.window lt 0) then begin
785    window, /free, /pixmap
786    wdelete, !d.window
787  endif
788endif
789
790;- Set default display depth
791depth = 8
792
793;- Get actual bit depth on supported displays
794if (!d.name eq 'WIN') or (!d.name eq 'MAC') or (!d.name eq 'X') then begin
795  if (version ge 5.1) then begin
796    device, get_visual_depth=depth
797  endif else begin
798    if (!d.n_colors gt 256) then depth = 24
799  endelse
800endif
801
802;-------------------------------------------------------------------------------
803;- SELECT DECOMPOSED COLOR MODE (ON OR OFF) FOR 24-BIT DISPLAYS
804;-------------------------------------------------------------------------------
805
806if (!d.name eq 'WIN') or (!d.name eq 'MAC') or (!d.name eq 'X') then begin
807  if (depth gt 8) then begin
808    if (version ge 5.2) then device, get_decomposed=entry_decomposed else $
809      entry_decomposed = 0
810    if (true eq 1) or (channel gt 0) then device, decomposed=1 else $
811      device, decomposed=0
812  endif
813endif
814
815;-------------------------------------------------------------------------------
816;- DISPLAY THE IMAGE
817;-------------------------------------------------------------------------------
818
819;- If the display is 8-bit and the image is true color,
820;- convert image from true color to indexed color
821if (depth le 8) and (true eq 1) then begin
822  resized = color_quan(temporary(resized), 3, r, g, b, $
823    colors=ncolors, dither=keyword_set(dither)) + byte(bottom)
824  tvlct, r, g, b, bottom
825  true = 0
826endif
827
828;- Set channel value for supported devices
829if (!d.name eq 'WIN') or (!d.name eq 'MAC') or (!d.name eq 'X') then begin
830  channel_value = channel
831endif else begin
832  channel_value = 0
833endelse
834
835;- Display the image
836case true of
837  0 : tv, resized, x0, y0, order=order, channel=channel_value
838  1 : tv, resized, x0, y0, order=order, true=3
839endcase
840
841;-------------------------------------------------------------------------------
842;- RESTORE THE DECOMPOSED COLOR MODE FOR 24-BIT DISPLAYS
843;-------------------------------------------------------------------------------
844
845if ((!d.name eq 'WIN') or (!d.name eq 'MAC') or (!d.name eq 'X')) and $
846  (depth gt 8) then begin
847  device, decomposed=entry_decomposed
848  if (!d.name eq 'MAC') then tv, [0], -1, -1
849endif
850
851;-------------------------------------------------------------------------------
852;- DRAW AXES IF REQUIRED
853;-------------------------------------------------------------------------------
854
855if keyword_set(axis) then $
856  plot, [0], /nodata, /noerase, position=out_pos, $
857    xrange=xrange, xstyle=1, yrange=yrange, ystyle=1, $
858    _extra=extra_keywords
859
860END
Note: See TracBrowser for help on using the repository browser.