<> <> <> DIRECTORY ColorTrixPalette, ImagerPixelMap, Real; ColorTrixPaletteImpl: CEDAR PROGRAM IMPORTS ImagerPixelMap, Real EXPORTS ColorTrixPalette ~ { palOn: BOOL _ FALSE; 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: NAT _ MAX[1, MIN[60/vTot, nRows]]; nCols: NAT _ IF 255 MOD nRows2 = 0 THEN 255/nRows2 ELSE 255/nRows2+1; hSize: NAT _ MIN[14, (pm.fSize-2*20)/nCols-hSpace]; hTot: NAT _ hSize+hSpace; x: NAT _ (pm.fSize-nCols*hTot)/2; hiRes: BOOL _ pm.sSize = 768; bot: NAT _ IF 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; }; }. <<>>