;+
; NAME:
; 	RESTORE_LOW8
; PURPOSE:
;       Restore a low-8 image by using a similar compressed image to 
;	  guess the upper four bits of information.
; CALLING SEQUENCE:
;	img = restore_ffi(low8,comp) returns a corrected image that uses
;	  a compressed image (comp) to reference the low-8 image (low8).
;         The user has to define which image is which. 'comp' can be a
;	  raw compressed image if desired. 
; WRITTEN:
;	HSH, March 25, 1992 
;	HSH, March 28, 1992, modified to permit decompressed image input
;	MDM, March 23, 1995, Modified how to recognize decompressed images
;-
function restore_low8, low8, comp
;
;;de_comp = comp
;;if (max(comp) lt 256) then de_comp = sxt_decomp(comp)
if (data_type(comp) eq 1) then de_comp = sxt_decomp(comp) $
			else de_comp = comp
gain = de_comp/256
rest = gain*256 + low8 
;
; find the discrepancies and correct them
;
diff = rest - de_comp
highs = where(diff gt 128, n_highs)
lows  = where(diff lt -128, n_lows)
if n_highs ne 0 then rest(highs) = rest(highs) - 256
if n_lows ne 0 then rest(lows)  = rest(lows)  + 256
return, rest
end
