include include procedure t_fixicm () # "Fix" (kludge) an image to be sent to the Celco so the scale doesn't # stretch and the pixels match the color map. Force the minimum pixel to # 0 and the max pixel to 255. Replace the first and last colormap entry # by the corresponding mapped values of the old min and max pixel. (!) # Note that this is done in-place on both the image and colormap files. # This kludges a bug in the Celco code that causes the # image to stretch, resulting in a mismatch between the image and the # color map. # 9/2/92 ZGL pointer sp pointer image # Output image file name pointer cmap # Output colormap file name short dmin, dmax int pmin[2], pmax[2] begin call smark (sp) call salloc (image, SZ_FNAME, TY_CHAR) call salloc (cmap, SZ_FNAME, TY_CHAR) # Get task parameters call clgstr ("image", Memc[image], SZ_FNAME) call clgstr ("cmap", Memc[cmap], SZ_FNAME) # Write the pixel image call mnmximg (Memc[image], dmin, dmax, pmin, pmax) call fiximc (Memc[image], Memc[cmap], dmin, dmax, pmin, pmax) call sfree (sp) end procedure mnmximg (image, dmin, dmax, pmin, pmax) # Find the min and max pixel in the image char image[ARB] short dmin, dmax int pmin[2], pmax[2] pointer om # Output image descriptor pointer lp # Image line buffer int line # Image line int width, height pointer imgl2s(), immap() begin # Open the output pixel image om = immap (image, READ_ONLY, 0) width = IM_LEN(om,1) height = IM_LEN(om,2) dmin = MAX_SHORT dmax = -MAX_SHORT # Open the image so we can get the min, max om = immap (image, READ_WRITE, 0) do line = 1, height { # Each image line lp = imgl2s (om, line) call mnmxln (Mems[lp], width, line, dmin, dmax, pmin, pmax) call eprintf ("# Line %4d/%d %3d\r") call pargi (line) call pargi (height) call pargi (int (100.0 * real (line) / real(height))) call flush (STDERR) } call eprintf ("\n") # Close the image call imunmap (om) end procedure mnmxln (dline, npix, ln, dmin, dmax, pmin, pmax) short dline[ARB] # Data line int npix # Number of pixels in line int ln # Line number short dmin, dmax # Data min and max int pmin[2], pmax[2] # Coordinates of min and max int pix short val begin do pix = 1, npix { val = dline[pix] if (val < dmin) { dmin = val pmin[1] = pix pmin[2] = ln } if (val > dmax) { dmax = val pmax[1] = pix pmax[2] = ln } } end procedure fiximc (image, cmap, dmin, dmax, pmin, pmax) char image[ARB] # Output pixel image name char cmap[ARB] # Output colormap file name pointer om # Image descriptor pointer cm # Colormap descriptor pointer icp, ocp pointer ip short dmin, dmax int pmin[2], pmax[2] long clktime() pointer immap(), imps2s(), imgs2r(), imps2r() begin # Map the image om = immap (image, READ_WRITE, 0) # Map the colormap cm = immap (cmap, READ_WRITE, 0) # Update the header IM_LIMTIME(om) = clktime (long(0)) # Force the data range 0:255 call imputr (om, "i_minpixval", 0.0) call imputr (om, "i_maxpixval", 255.0) call imaddr (om, "datamin", 0.0) call imaddr (om, "datamax", 255.0) IM_MIN(om) = 0.0 IM_MAX(om) = 255.0 # Force the min and max pixel to 0:255 icp = imgs2r (cm, 1, 256, 1, 3) ocp = imps2r (cm, 1, 256, 1, 3) call fixcm (Memr[icp], Memr[ocp], 256, 3, dmin, dmax) ip = imps2s (om, pmin[1], pmin[1], pmin[2], pmin[2]) Mems[ip] = 0 ip = imps2s (om, pmax[1], pmax[1], pmax[2], pmax[2]) Mems[ip] = 255 call eprintf ("# Min: %d [%d,%d] --> 0, Max: %d [%d,%d] --> 255\n") call pargs (dmin) call pargi (pmin[1]) call pargi (pmin[2]) call pargs (dmax) call pargi (pmax[1]) call pargi (pmax[2]) # Close the images call imunmap (om) call imunmap (cm) end procedure fixcm (icmap, ocmap, np, nc, dmin, dmax) real icmap[np,nc] real ocmap[np,nc] int np, nc short dmin, dmax begin call eprintf ("# Min\tMax\n") call eprintf ("# In: %d %d %d\t%d %d %d\n") call pargi (int (ocmap[1,1] * 255.0)) call pargi (int (ocmap[1,2] * 255.0)) call pargi (int (ocmap[1,3] * 255.0)) call pargi (int (ocmap[256,1] * 255.0)) call pargi (int (ocmap[256,2] * 255.0)) call pargi (int (ocmap[256,3] * 255.0)) call amovr (icmap, ocmap, np*nc) ocmap[1,1] = icmap[dmin+1,1] ocmap[1,2] = icmap[dmin+1,2] ocmap[1,3] = icmap[dmin+1,3] ocmap[256,1] = icmap[dmax+1,1] ocmap[256,2] = icmap[dmax+1,2] ocmap[256,3] = icmap[dmax+1,3] call eprintf ("# Out: %d %d %d\t%d %d %d\n") call pargi (int (ocmap[1,1] * 255.0)) call pargi (int (ocmap[1,2] * 255.0)) call pargi (int (ocmap[1,3] * 255.0)) call pargi (int (ocmap[256,1] * 255.0)) call pargi (int (ocmap[256,2] * 255.0)) call pargi (int (ocmap[256,3] * 255.0)) end