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

Last change on this file since 136 was 136, checked in by pinsard, 18 years ago

some improvements and corrections in some .pro file according to
aspell and idldoc log file

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