;------------------------------------------------------------- ;+ ; NAME: ; XVIEW ; PURPOSE: ; View and/or convert images (GIF, TIFF, ...). ; CATEGORY: ; CALLING SEQUENCE: ; xview ; INPUTS: ; KEYWORD PARAMETERS: ; Keywords: ; SCROLL_SIZE=[mx,my] Max size before scrolling sets in. ; DIRECTORY=dir Set initial directory. ; HOTLIST=hfile Name of directory hotlist file. ; File has list of directories of interest. For file ; format do xhotlist, /help. Default is the file named. ; xview_dir.txt in local directory first, then $HOME. ; TYPE=typ Initial image type: ; GIF=def,JPEG,TIFF,XWD,BMP,XBM,PICT,SRF ; WILD=wild Initial wildcard (def depends on TYPE). ; MAG=mag Initial magnification (def=1.0). ; ICTXT=txt Text string to execute after each image load. ; Intended to set data coordinates for data cursor. ; Image name is available in the variable called NAME at ; the point where this text is executed. If a file name ; contains coordinate info a routine which extracts that ; info may be called. Ex: for file N40W120.gif the ; routine could pick off the 40 and 120 and use that to ; set the scaling. Something like ICTXT="set_scale,name" ; READ_CUSTOM=rc Name of an optional custom image ; read routine. May also include default wild card ; as 2nd element of a string array. Routine syntax: ; img = rdcust(filename, r, g, b) where r,g,b may ; be set to scalar 0 for no new color table. ; OUTPUTS: ; COMMON BLOCKS: ; NOTES: ; MODIFICATION HISTORY: ; R. Sterner, 11 Oct, 1993 ; R. Sterner, 1994 Dec 13 --- Added JPEG. Also allowed initial ; mag factor to be given. Added more mag factors to pulldown menu. ; R. Sterner, 1994 Dec 30 --- Added XBM. ; R. Sterner, 1995 May 5 --- Added PRINT. ; R. Sterner, 1995 May 18 --- Added TRANSPARENCY. ; R. Sterner, 1995 Nov 9 --- Added SRF. ; R. Sterner, 1997 Feb 27 --- Added vivid color print option. ; R. Sterner, 1998 Jan 15 --- Dropped use of !d.n_colors. ; R. Sterner, 1999 Sep 28 --- Switched to read_tiff (from tiff_read). ; R. Sterner, 2001 Jul 19 --- Fixed to save JPEG correctly. ; R. Sterner, 2001 Jul 26 --- Fixed image resize, also called img_shape. ; ; Copyright (C) 1993, Johns Hopkins University/Applied Physics Laboratory ; This software may be used, copied, or redistributed as long as it is not ; sold and this copyright notice is reproduced on each copy made. This ; routine is provided as is without any express or implied warranties ; whatsoever. Other limitations apply as described in the file disclaimer.txt. ;- ;------------------------------------------------------------- ;======================================================== ; xview_print = Make a color print of current image. ; R. Sterner, 1995 May 5. ;======================================================== pro xview_print, fname, trans=trans, printer=pr txt = 'print' if keyword_set(trans) then txt = 'transparency' subset = 0 sub2set = 0 opt = xoption(title='Make a color '+txt,['OK','Cancel'],$ def=0, subopt=['Single Page','Two Pages','Four Pages'],$ subset=subset, /exclusive, sub2opt=['Display color',$ 'Vivid color'],sub2set=sub2set,/ex2) if opt ne 0 then return if n_elements(pr) eq 0 then begin pr = 'Paper Color' if keyword_set(trans) then pr = 'Transparency Color' endif two = 0 four = 0 if subset eq 1 then two=1 if subset eq 2 then four=1 vivid = '' if sub2set eq 1 then vivid=' vivid' prwindow, pr+vivid, comment=fname, two=two, four=four return end ;======================================================== ; udlist = Update image list. ;======================================================== pro udlist, up, noload=noload widget_control, /hour widget_control, up.dir, get_value=dir ; Get current directory. dir = dir(0) widget_control, up.file, get_value=wild ; Get current file or wild. wild = wild(0) widget_control, up.mag, get_val=mag ; Get current mag. mag = mag(0) mag = getwrd(mag,2)+0.0 smax = up.smax ; Max scroll window. tmpdir = dir ; To avoid ls arg list too cd,curr=tmp2dir ; big error if tmp2dir eq dir then tmpdir='' ; use null for local. fname = filename(tmpdir,wild,/nosym) ; Add path to file. f = findfile(fname,count=cnt) ; Look for files. if cnt eq 0 then begin ; No files. widget_control, up.list, set_value=['No files found'] widget_control, up.left, set_uval=[''] endif else begin ; Found some. for i = 0, n_elements(f)-1 do f(i)=getwrd(f(i),/last,delim='/') widget_control, up.list, set_val=f widget_control, up.left, set_uval=f if keyword_set(noload) then return ; Don't load. if cnt eq 1 then begin ; Found one. Load it. tvimg, fname, smax=smax, mag=mag, cinit=up.ictxt, imgsz=up.imgsz, $ type=up.type, custom=up.custread, rot=up.rot endif endelse return end ;======================================================== ; tvimg = image loader ; R. Sterner, 11 Oct, 1993 ; R. Sterner, 2000 Sep 26 --- Upgraded for 24-bit color. ; ; tvimg, name, smax=smax ; name = image file name. in ; smax = optional max scroll window size [mx,my] in ; mag=mag = optional image mag factor. in ;======================================================== pro tvimg, name, smax=smax, mag=mag, custom=cust, type=id_type, $ cinit=ictxt, rot=rot, imgsz=imgsz ;--------- Get file type from widget --------------- widget_control, id_type, get_val=txt type = strupcase(getwrd(txt,/last)) tt = getwrd(name,/last,delim='/') ; Window title = file name. ;--------- Read image ---------- iflag = -1 ; Indexed color? 1=yes, 0=no. order = 0 case type of 'GIF': begin read_gif, name, img, r, g, b iflag = 1 end 'SRF': begin read_srf, name, img, r, g, b iflag = 1 end 'JPG': begin read_jpeg, name, img if (size(img))(0) eq 1 then begin ; Gray scale. r = c g = c b = c iflag = 1 endif else begin ; Color. iflag = 0 endelse end 'XWD': begin img = read_xwd(name, r, g, b) end 'TIF': begin img = read_tiff(name, order=order) if order gt 1 then order=1 ; A bug? order comes back 16437. iflag = 0 end 'BMP': begin img = read_bmp(name, r, g, b) iflag = 1 end 'XBM': begin read_x11_bitmap, name, img, /expand_to_bytes img = reverse(img,2) r = bindgen(256) g = r b = r iflag = 1 end 'PICT': begin read_pict, name, img, r, g, b iflag = 1 end 'CUSTOM': begin img = call_function(cust, name, r, g, b) iflag = 1 end else: begin print,' Unkown image type: ',type return end endcase ;----------- Rotate image -------------- img = img_rotate(img,rot) ;----------- Size image ---------------- mx = smax(0) my = smax(1) img_shape, img, true=tr, nx=nx,ny=ny ttsz = ' ('+strtrim(nx,2)+', '+strtrim(ny,2)+')' tt = tt + ttsz widget_control, imgsz, set_val='Image size:'+ttsz if n_elements(mag) eq 0 then mag = 1 if mag ne 1 then begin img = img_resize(img,mag=mag) img_shape, img, nx=nx,ny=ny endif sx = nx