CtMod.mesa
Copyright Ó 1985, 1992 by Xerox Corporation. All rights reserved.
Bloomenthal, September 10, 1992 4:35 pm PDT
Heckbert, June 1, 1988 0:36:58 am PDT
Glassner, December 11, 1989 11:12:03 pm PST
DIRECTORY CtBasic, CtMap, G2dMatrix, G2dVector, ImagerColor, ImagerSample, ImagerTransformation, SF;
CtMod: CEDAR DEFINITIONS
~ BEGIN
Imported Types
IntegerPair:  TYPE ~ CtBasic.IntegerPair;
SampleMaps:  TYPE ~ CtBasic.SampleMaps;
PixelArray:  TYPE ~ CtBasic.PixelArray;
Cmap:    TYPE ~ CtMap.Cmap;
Table:    TYPE ~ CtMap.Table;
Matrix:   TYPE ~ G2dMatrix.Matrix;
PairSequence: TYPE ~ G2dVector.PairSequence;
Box:    TYPE ~ ImagerSample.Box;
SampleMap:  TYPE ~ ImagerSample.SampleMap;
Transformation: TYPE ~ ImagerTransformation.Transformation;
Vec:    TYPE ~ SF.Vec;
Raster Transformations
TransformProc: TYPE ~ PROC [p: IntegerPair] RETURNS [IntegerPair];
Points transformed beyond the original raster are clipped to the nearest raster point.
TransformMap: PROC [map: SampleMap, transformation: Transformation];
Resample the raster given the transformation.
TransformMaps: PROC [maps: SampleMaps, transformation: Transformation];
Resample the rasters given the transformation.
ArbTransformMap: PROC [map: SampleMap, proc: TransformProc];
Overwrite map such that map(x,y) ¬ map(proc(x,y)).
ArbTransformMaps: PROC [maps: SampleMaps, proc: TransformProc];
Overwrite maps such that maps(x,y) ¬ maps(proc(x,y)).
Palette Procedures
Palette: PROC [maps: SampleMaps, nRows: NAT ¬ 5, smooth: BOOL]
RETURNS [affectedRegion: Box];
Draw the color map palette in the given maps.
Color Map Indirection
Indirect: PROC [map: SampleMap, table: Table, box: Box];
Indirect all pixels within box through the table. No op if map.bpp # 8.
Lum24: PROC [maps: SampleMaps, cmap: Cmap, coeff: ImagerColor.RGB ¬ [.30, .59, .11]];
Compute luminance by indirecting through cmap and weighting by the coefficients.
No op if maps.bpp = 8.
Simple Modifying Procedures
Dif: PROC [map: SampleMap, x0, y0, x1, y1, x2, y2, w, h: NAT];
Display the difference (absolute value) of two windows in a third window, each w by h.
Up: PROC [map: SampleMap, shift: INTEGER];
Move the image up by shift amount; image will wrap-around.
Left: PROC [map: SampleMap, shift: INTEGER];
Move the image left by shift amount; image will wrap-around.
Negate: PROC [map: SampleMap];
Negate the image in the color display.
ReflectH: PROC [map: SampleMap];
Reflect the pixel map about the horizontal mid-line.
ReflectV: PROC [map: SampleMap];
Reflect the pixel map about the vertical mid-line.
MirrorH: PROC [map: SampleMap, topToBottom: BOOL ¬ TRUE];
Mirror the pixel map about the horizontal mid-line.
MirrorV: PROC [map: SampleMap, leftToRight: BOOL ¬ TRUE];
Mirror the pixel map about the vertical mid-line.
Transpose: PROC [map: SampleMap];
Transpose the pixels in the map within a square region of the map.
Rotate: PROC [map: SampleMap, degrees: REAL];
Rotate the map by the given degrees; positive rotation is counter-clockwise.
Add: PROC [dst, map: SampleMap, fbAlpha, fileAlpha: REAL];
Linear interpolation: dst ← (fileAlpha*dst)+(fbAlpha*map).
Lerp: PROC [dst, map: SampleMap, alpha: REAL];
Linear interpolation: dst ← alpha*dst+(1-alpha)*map.
PVal: PROC [map: SampleMap, new: NAT, old: LIST OF NAT];
Set any old valued pixels to the new value.
Gammatize: PROC [maps: SampleMaps, gamma: REAL, x, y, w, h: NAT];
Apply a gamma correction to maps.
Warping
CoonsControl: TYPE ~ RECORD [filter: {point, box} ¬ point, abort: BOOL ¬ FALSE];
PerspWarp: PROC [
texture:  PixelArray ¬ NIL,    -- source image
dest:   SampleMaps,      -- destination sample maps
smooth:  BOOL ¬ FALSE,     -- anti-alias or not?
points:  ARRAY [0..4) OF IntegerPair] -- warp quadrilateral
RETURNS [transform: Matrix];
Perform the perspective warping on the input texture; return the perspective transformation.
CoonsWarp: PROC [
pa1, pa2, pa3: PixelArray,      -- source (pa1 for bw or r, pa2, 3 for g, b)
curves: ARRAY [0..4) OF PairSequence,  -- outline curves
dest: SampleMaps,        -- destination sample maps
control: REF CoonsControl ¬ NIL];
Warp the region of the source image bounded by the outline curves into the rectangular destination window. The mapping is a bilinear Coons surface, (see On Coons and Other Methods for the Representation of Curved Sufaces by Forrest, CGIP 1972).
For an 8-bpp source image, pa2 and pa3 is NIL; for 24bpp, pa1, pa2, pa3 are red, green, blue.
Filter options are point sampled (fast) or bilinear (box) filtering (slow).
If control # NIL then filter can be changed or operation aborted during this call.
If control = NIL, then filter type defaults to point sampling.
Pixel Procedures
BiLerp: PROC [pa: PixelArray, x, y: REAL] RETURNS [CARDINAL];
Return the bilinearly interpolated pixel value rounded to the nearest integer.
The pixel array may be 8 or 16 bpp. Bounds fault if x or y is out of range.
BiLerpReal: PROC [pa: PixelArray, x, y: REAL] RETURNS [REAL];
Return the bilinearly interpolated pixel value. The pixel array must be 8 bpp only.
Bounds fault if x or y is out of range.
END.