ColorTrixPaletteImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Plass and Bloomenthal, January 7, 1986 6:40:22 pm PST
DIRECTORY ColorTrixPalette, ImagerPixelMap, Real;
ColorTrixPaletteImpl: CEDAR PROGRAM
IMPORTS ImagerPixelMap, Real
EXPORTS ColorTrixPalette
~ {
palOn: BOOLFALSE;
botLoRes: NAT ~ 360;
botHiRes: NAT ~ 650;
palLoRes: ImagerPixelMap.PixelMap ← ImagerPixelMap.Create[3, [botLoRes, 0, 60, 640]];
palHiRes: ImagerPixelMap.PixelMap ← ImagerPixelMap.Create[3, [botHiRes, 0, 60, 1024]];
Pal: PUBLIC PROC [pm: ImagerPixelMap.PixelMap, nRows: NAT ← 5, smooth: BOOL] ~ {
hSpace: NAT ~ 2;
vSpace: NAT ~ 2;
i:   NAT ← 1;
vSize:  NAT ← 7;
vTot:  NAT ← vSize+vSpace;
nRows2: NATMAX[1, MIN[60/vTot, nRows]];
nCols:  NATIF 255 MOD nRows2 = 0 THEN 255/nRows2 ELSE 255/nRows2+1;
hSize:  NATMIN[14, (pm.fSize-2*20)/nCols-hSpace];
hTot:  NAT ← hSize+hSpace;
x:   NAT ← (pm.fSize-nCols*hTot)/2;
hiRes:  BOOL ← pm.sSize = 768;
bot:  NATIF hiRes THEN botHiRes ELSE botLoRes;
ImagerPixelMap.Transfer[IF hiRes THEN palHiRes ELSE palLoRes, pm];
IF smooth THEN FOR xx: NAT IN[x..x+hTot*nCols) DO
val: CARDINAL ← Real.RoundI[255.0*REAL[xx-x]/REAL[hTot*nCols]];
ImagerPixelMap.Fill[pm, [bot, xx, vTot*nRows2, 1], val];
ENDLOOP
ELSE FOR row: NAT IN [0..nRows2) DO
FOR col: NAT IN [0..nCols) DO
ImagerPixelMap.Fill[pm, [bot+row*vTot, x+col*hTot, vSize, hSize], i];
IF (i ← i+1) = 256 THEN EXIT;
ENDLOOP;
ENDLOOP;
palOn ← TRUE;
};
UnPal: PUBLIC PROC [pm: ImagerPixelMap.PixelMap] ~ {
IF NOT palOn THEN RETURN;
IF pm.sSize = 480
THEN ImagerPixelMap.Transfer[pm, palLoRes]
ELSE ImagerPixelMap.Transfer[pm, palHiRes];
palOn ← FALSE;
};
}.