ColorTrixPixImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Bloomenthal, March 24, 1986 10:55:07 am PST
DIRECTORY ColorTrixPix, ImagerSample, ImagerPixelMap, PixelMapOps, Process, Random, Real;
ColorTrixPixImpl: CEDAR PROGRAM
IMPORTS ImagerSample, ImagerPixelMap, PixelMapOps, Process, Random, Real
EXPORTS ColorTrixPix
~ {
Color Display Modification Procedures:
Dither: PUBLIC PROC [pm: ImagerPixelMap.PixelMap, intensity: NAT] ~ {
w: ImagerPixelMap.DeviceRectangle ← ImagerPixelMap.Window[pm];
IF intensity = 0 THEN {ImagerPixelMap.Fill[pm, w, 0]; RETURN};
ImagerPixelMap.Fill[pm, w, 255];
IF intensity = 255 THEN RETURN;
FOR y: NAT IN [w.sMin..w.sMin+w.sSize) DO
Process.CheckForAbort[];
FOR x: NAT IN [w.fMin..w.fMin+w.fSize) DO
IF Random.ChooseInt[min: 0, max: 255] > intensity
THEN ImagerPixelMap.Fill[pm, [y, x, 1, 1], 0];
ENDLOOP;
ENDLOOP;
};
RampH: PUBLIC PROC [pm: ImagerPixelMap.PixelMap] ~ {
bounds: ImagerPixelMap.DeviceRectangle ~ pm.Window;
inc: REAL ← 255.0/Real.Float[bounds.fSize-1];
action: PROC [line: ImagerSample.SampleBuffer] ~ TRUSTED {
FOR y: NAT IN [bounds.sMin..bounds.sMin+bounds.sSize) DO
ival: NAT ← Real.Round[(y-bounds.sMin)*inc];
Process.CheckForAbort[];
FOR x: NAT IN [0..bounds.fSize) DO line.samples[x] ← ival; ENDLOOP;
PixelMapOps.PutF[pm, y, bounds.fMin, line, 0, 0, bounds.fSize, null, null];
ENDLOOP;
};
ImagerSample.DoWithScratchBuffer[1, pm.fSize, action];
};
RampV: PUBLIC PROC [pm: ImagerPixelMap.PixelMap] ~ {
bounds: ImagerPixelMap.DeviceRectangle ~ pm.Window;
inc: REAL ← 255.0/Real.Float[bounds.fSize-1];
action: PROC [line: ImagerSample.SampleBuffer] ~ TRUSTED {
FOR x: NAT IN [0..bounds.fSize) DO line.samples[x] ← Real.Round[x*inc]; ENDLOOP;
FOR y: NAT IN [bounds.sMin..bounds.sMin+bounds.sSize) DO
Process.CheckForAbort[];
PixelMapOps.PutF[pm, y, bounds.fMin, line, 0, 0, bounds.fSize, null, null];
ENDLOOP;
};
ImagerSample.DoWithScratchBuffer[1, pm.fSize, action];
};
Pie: PUBLIC PROC [pm: ImagerPixelMap.PixelMap] ~ {
maxVal: NAT ~ 255;
sq: ARRAY [0..512] OF INT;
threshs: ARRAY [0..maxVal+1] OF INT;
line: ImagerSample.SampleBuffer ~ ImagerSample.ObtainScratchBuffer[1, pm.fSize];
dx: NAT ~ MIN[511, (pm.fSize+1)/2-1];
dy: NAT ~ MIN[511, (pm.sSize+1)/2-1];
cx: NAT ~ pm.fMin+dx;
cy: NAT ~ pm.sMin+dy;
ratio: REAL ← Real.RoundI[dx+1]/256.0;
Init: PROC ~ {
val: INT ← 0; dval: INT ← 1; ddval: INT ~ 2;
factor: REAL ← ratio*ratio;
FOR i: NAT IN [0..512] DO sq[i] ← val; val ← val + dval; dval ← dval + ddval; ENDLOOP;
FOR i: NAT IN [0..maxVal+1] DO threshs[i] ← Real.Round[factor*sq[i]]; ENDLOOP;
};
Scan: PROC [y: NAT] ~ {
pval: CARDINAL ← Real.Round[MIN[255.0, MAX[1.0, REAL[y]/ratio]]];
thresh: INT ← threshs[pval]-sq[y];
FOR x: NAT IN [0..dx] DO
WHILE sq[x] > thresh AND pval < maxVal DO
pval ← pval+1;
thresh ← threshs[pval]-sq[y];
ENDLOOP;
IF pval = maxVal THEN {
FOR xx: NAT IN [dx+x..pm.fSize) DO line.samples[xx] ← maxVal; ENDLOOP;
FOR xx: NAT IN [0..dx-x] DO line.samples[xx] ← maxVal; ENDLOOP;
EXIT;
};
line.samples[dx+x] ← line.samples[dx-x] ← pval;
ENDLOOP;
PixelMapOps.PutF[pm, cy+y, pm.fMin, line, 0, 0, pm.fSize, null, null];
PixelMapOps.PutF[pm, cy-y, pm.fMin, line, 0, 0, pm.fSize, null, null];
};
Init[];
FOR y: NAT IN [0..dy] DO Process.CheckForAbort[]; Scan[y]; ENDLOOP;
IF pm.sSize MOD 2 = 0 THEN ImagerPixelMap.Fill[pm, [pm.sMin+pm.sSize-1, pm.fMin, 1, pm.fSize], 255];
IF pm.fSize MOD 2 = 0 THEN ImagerPixelMap.Fill[pm, [pm.sMin, pm.fMin+pm.fSize-1, pm.sSize, 1], 255];
};
}.