function trace_jpeg_decomp, index, jpeg_stream, $ temp=temp, huffman=huffman, qt=qt, $ debug=debug, nx=nx, ny=ny, ssw=ssw, current=current ;+ ; Name: trace_jpeg_decomp ; ; Purpose: decompress a 'TRACE' jpeg stream (call RShine C routine) ; ; Input Parameters: ; index - structure defining image/stream (w/tag = dp_header) ; OR trace dp_header ; jpeg_stream - stream ; ; Keyword Parameters: ; huffman - huffman table to use (default derived from DP header) ; qt - quant. talbe default derived from DP header) ; nx - (output) NX size of decoded image ; ny - (output) NY size of decoded image ; current - (switch) if set, use copy of Shared object in current direct. ; ssw - (switch) if set, force use of SSW shared version (DEFAULT) ; debug - (switch) if set, stop before and after call_external call ; temp - (switch) if set, work on temporary copy of jpeg stream ; ; History: ; 26-Nov-1997 - S.L.Freeland / Richard Shine ; 2-dec-1997 - S.L.Freeland - add NX, NY, made temporary copy , reform within IDL ; made it SSW transportable - rename to 'trace_jpeg_decomp' ; ; 4-dec-1997 - S.L.Freeland - add /CURRENT (testing) ; review after c change - nx/ny protect ; eliminate old testing dir referces ; 15-dec-1997 - S.L.Freeland - remove some diagnostics, add /TEMP switch ; only use temporary copy on request ; 7-May-1999 - S.L.Freeland - avoid addressing 'decoded stream' if ; bad decode status is returned by shared object ; 5_Oct-1999 - R.W.Nightingale - double 'decoded_stream' array length ; 17-Jan-2000 - S.L Freeland - Made default quieter ; 10-Feb-2000 - S.L. Freeland - Added version dependent SO name ; (sgi/idl V5.3 uses different compiler options ; 15-Mar-2003 - H.P.Warren - pass IDL Release to dcompressor ; 8-Apr-2003 - S.L.Freeland - use $SSW_TRACE/binaries/.. for "new" ; decompressor (which accepts release) - attempt to make ; this backwardly compatible and independent of $SSW_BINARIES ; branch upgrade (which may occur asyncronously w/resp to trace) ; 10-Nov-2003 - S.L.Freeland - try to rationalize the OS/ARCH -and- ; RSI Release dependcies; goal is backward and forward ; compatibility, but let me know.... ; (still many OS not represented yet, such as WinXX, MacOS ; ; Method: ; Set up and call R. Shine C routine 'trace_decode_idl' via 'call_external' ; TODO - optimize ;- common trace_decode_idl_blk, shared_lib, newbin common trace_decode_idl_blk1, sharedo temp=keyword_set(temp) debug=keyword_set(debug) ssw=keyword_set(ssw) current=keyword_set(current) loud=get_logenv('read_trace_loud') ne '' release = float(!version.release) ; passed to new version (H.P.Warren) relstr='V'+ str_replace(gt_tagval(!version,/release),'.','_') routine='trace_decode_idl' ; shared object jpeg decompressor bsubdir=!version.OS + '_' + !version.ARCH ; OS/ARCH dependent subdir ; Call routine to get system dependent call_external information status=call_external_info(routine, shared, entry) ; There are many OS/ARCH -and- RSI/IDL Release dependencies on which object ; to select.... (why I wish the decompressor was written in IDL...) if n_elements(shared_lib) eq 0 then begin ; 1st call - select bin path newtop=concat_dir(concat_dir('$SSW_TRACE','binaries'),bsubdir) ; newer oldtop=concat_dir(concat_dir('$SSW_BINARIES','exe'),bsubdir) ; original binpaths=[concat_dir(newtop,relstr),newtop, $ ; 4 possibilities concat_dir(oldtop,relstr), oldtop ] newbin=file_exist(newtop) sharedos=concat_dir(binpaths,shared) ; all possible so mappings soss=where(file_exist(sharedos),scnt) ; if multiple matches, 1st match ; assumed best match... if scnt gt 0 then begin sharedo=sharedos(soss(0)) ; << selected SO full path shared_lib=binpaths(soss(0)) ; << SO "library" path endif else begin box_message,["Cannot find TRACE JPEG decompressor, non-IDL binary", $ "You need to upgrade your SSW TRACE and Binaries trees...",$ "You can upgrade via (tell your SSW/sysadmin if it's not you)",$ "IDL> ssw_upgrade,/trace,/binaries,/spawn,/loud"] return,0 endelse endif cdir=curdir() ; save "for later" if current then shared_lib=cdir else cd,shared_lib ; define default tables trace_jpeg_dbase, index, huff_tab, qual_tab if not keyword_set(huffman) then huffman=huff_tab if not keyword_set(qt) then qt=qual_tab jpeg_size=long(n_elements(jpeg_stream)) if temp then temp_stream=jpeg_stream decoded_stream=make_array(1024L*2048L,/int,/nozero) ; 1D output stream decoded_size=long(n_elements(decoded_stream)) decoded_size=0L & nx=0L & ny=0L temp_stream=jpeg_stream if loud then print,"---------- Calling JPEG shared object -----------" ; --------- decode stream --------------------- decode=0l ; define function return if newbin then $ decode = call_external( sharedo, entry, $ ; SO, entry name huffman, qt, $ ; dbase tables jpeg_stream, jpeg_size, $ ; input stream & size decoded_stream, decoded_size, $ ; output image & size nx, ny, $ ; NX and NY release) else $ ; IDL release (HPW) ; else (old call) decode = call_external( sharedo, entry, $ ; SO, entry name huffman, qt, $ ; dbase tables jpeg_stream, jpeg_size, $ ; input stream & size decoded_stream, decoded_size, $ ; output image & size nx, ny) ; NX and NY ; ------------------------------------------------ if loud then print,"-------------------------------------------------" if nx gt 1024 or ny gt 1024 then print,'*** nx or ny cannot be > 1024 ',nx,ny if temp then jpeg_stream=temporary(temp_stream) if nx lt 1 or ny lt 1 then begin box_message,"Warning - bad decode (NX/NY problem) nx=nx>1 ny=ny>1 outimage=make_array(nx,ny,/int) endif else outimage=reform(decoded_stream(0:nx*ny-1),nx,ny,/over ) ; 1D->2D if current then delvarx,shared_lib else cd,cdir return, outimage end