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

Last change on this file since 230 was 230, checked in by pinsard, 17 years ago

improvements/corrections of some *.pro headers

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