;------------------------------------------------------------- ;+ ; 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. ; ; 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 txt = 'print' if keyword_set(trans) then txt = 'transparency' subset = 0 opt = xoption(title='Make a color '+txt,['OK','Cancel'],$ def=0, subopt=['Single Page','Two Pages','Four Pages'],$ subset=subset, /exclusive) if opt ne 0 then return pr = 'Paper Color' if keyword_set(trans) then pr = 'Transparency Color' two = 0 four = 0 if subset eq 1 then two=1 if subset eq 2 then four=1 prwindow, pr, 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. fname = filename(dir,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 ; ; 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 ---------- case type of 'GIF': read_gif, name, img, r, g, b 'SRF': read_srf, name, img, r, g, b 'JPG': begin read_jpeg, name, img, c, colors=256,/dither,/two_pass if (size(c))(0) eq 1 then begin ; Gray scale. r = c g = c b = c endif else begin ; Color. r = c(*,0) g = c(*,1) b = c(*,2) endelse end 'XWD': img = read_xwd(name, r, g, b) 'TIF': begin img = tiff_read(name, r, g, b, order=order) sz = size(img) if sz(0) eq 3 then begin xmess,'Loading 24 bit image . . .',wid=wid,/nowait rr = img(0,*,*) gg = img(1,*,*) bb = img(2,*,*) img = color_quan(rr,gg,bb,r,g,b) img = reform(img) widget_control,wid,/dest endif if order eq 1 then img = reverse(img,2) if n_elements(r) eq 0 then begin r = bindgen(256) g = r b = r endif end 'BMP': img = read_bmp(name, r, g, b) 'XBM': begin read_x11_bitmap, name, img, /expand_to_bytes img = reverse(img,2) r = bindgen(256) g = r b = r endif 'PICT': read_pict, name, img, r, g, b 'CUSTOM': img = call_function(cust, name, r, g, b) else: begin print,' Unkown image type: ',type return end endcase ;----------- Rotate image -------------- img = rotate(img,rot) ;----------- Size image ---------------- if n_elements(smax) eq 0 then smax = [1100,950] mx = smax(0) my = smax(1) sz = size(img) nx = sz(1) ny = sz(2) 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 = congrid(img,nx*mag,ny*mag) sz = size(img) nx = sz(1) ny = sz(2) endif sx = nx