MebesBitsCedar.mesa - June 8, 1982 9:09 PM
last modified by McCreight, November 7, 1984 9:47:54 am PST
for Cedar
last modified by McCreight, November 28, 1983 8:59 AM
to reduce the height of a rectangle by one MEBES pixel, increase the width of a rectangle by one Versatec pixel.
DIRECTORY
Commander,
FS,
Imager,
ImagerBasic,
ImagerPDExtras,
IO,
Rope;
MebesBitsCedar: CEDAR PROGRAM IMPORTS Commander, FS, Imager, ImagerPDExtras, IO =
BEGIN
NotMEBESFormat: ERROR = CODE;
NewCVContext: PROC [ fileName: Rope.ROPENIL ] RETURNS [ context: Imager.Context ] =
BEGIN
IF fileName = NIL THEN fileName ← "///temp/plot0.pd";
context ← Imager.Create[$PD, ImagerPDExtras.ColorVersatec[fileName: fileName]];
END;
NewDisplayContext: PROC RETURNS [ context: Imager.Context ] =
BEGIN
context ← Imager.Create[$LFDisplay];
context.ClipView[[0,0,600,808], FALSE];
END;
scale: REAL ← 1.0;
center: Imager.Pair ← [x: 4.0*4000 -- mm --, y: 4.0*4000 -- mm --];
ResetContext: PROC [ context: Imager.Context ] =
BEGIN
surface: Imager.IntRectangle;
context.Reset[];
surface ← context.GetViewBox[];
context.state.T ← Imager.Scale[1.0];
context.SetColor[Imager.white];
context.MaskRectangle[0, 0, LAST[INTEGER], LAST[INTEGER]];
context.SetColor[Imager.black];
context.TranslateT[x: surface.x+surface.w/2, y: surface.y+surface.h/2];
context.ScaleT[scale];
context.TranslateT[x: -center.x, y: -center.y];
END;
CloseCVContext: PROC [ context: Imager.Context ] = {[] ← context.SpecialOp[$Close, NIL]};
ReadMebesPatternFile: PROCEDURE [ fileName: Rope.ROPE, data: REFNIL ] =
BEGIN
s: IO.STREAM = FS.StreamOpen[fileName];
ReadMebesPatternStream[s, data ! UNWIND => s.Close[]];
s.Close[];
END;
stripeHeight: INT = 255;
ReadMebesPatternStream: PROCEDURE [ s: IO.STREAM, data: REFNIL ] =
BEGIN
blockSize: INT = 2048;
block: REF TEXT = NEW[TEXT[blockSize]];
index: INT ← 0;
Byte: TYPE = [0..256);
ReadMebesWord: PROC RETURNS [ w: INT ] =
BEGIN
IF index MOD blockSize = 0 THEN
BEGIN
IF s.GetBlock[block, 0, blockSize] # blockSize THEN ERROR;
index ← 0;
END;
w ← 256*LOOPHOLE[block[index], Byte]+LOOPHOLE[block[index+1], Byte];
index ← index+2;
END;
stripe: INT;
stripeVisible: BOOLTRUE;
header: ARRAY [0..15] OF INT;
FOR i: INT IN [0..16) DO header[i] ← ReadMebesWord[]; ENDLOOP;
IF (header[0] # 1003B) AND (header[0] # 1006B) OR header[6] # 6
OR header[13] # 2 THEN ERROR NotMEBESFormat;
DO
t1: INT ← ReadMebesWord[];
SELECT t1 MOD 100B FROM
16 =>
BEGIN -- Manhattan Rectangle
IF stripeVisible THEN
BEGIN
x, width, y, height: INT;
height ← t1/100B + 1;
width ← 256*LOOPHOLE[block[index], Byte]+LOOPHOLE[block[index+1], Byte];
x ← 256*LOOPHOLE[block[index+2], Byte]+LOOPHOLE[block[index+3], Byte];
y ← 256*LOOPHOLE[block[index+4], Byte]+LOOPHOLE[block[index+5], Byte];
InsertRectangle[x, width, stripe*stripeHeight+y, height, data];
END;
index ← index+6;
END;
17 =>
BEGIN -- Parallelogram
x, width, leftEdge: INT;
y, height, tmp1: INT;
height ← t1/100B + 1;
width ← ReadMebesWord[];
x ← ReadMebesWord[];
y ← ReadMebesWord[];
leftEdge ← ReadMebesWord[];
tmp1 ← ReadMebesWord[];
width ← width + (tmp1 MOD 40B)*200000B;
tmp1 ← tmp1/40B;
x ← x + (tmp1 MOD 40B)*200000B;
tmp1 ← tmp1/40B;
leftEdge ←
leftEdge + (tmp1 MOD 100B)*200000B +
(IF tmp1/40B # 0 THEN 37760000000B ELSE 0);
InsertTrapezoid[x, width, stripe*stripeHeight+y, height, leftEdge, leftEdge, data];
END;
18 =>
BEGIN -- Trapezoid 1
x, width, leftEdge: INT;
y, height, tmp1: INT;
height ← t1/100B + 1;
width ← ReadMebesWord[];
x ← ReadMebesWord[];
y ← ReadMebesWord[];
leftEdge ← ReadMebesWord[];
tmp1 ← ReadMebesWord[];
width ← width + (tmp1 MOD 40B)*200000B;
tmp1 ← tmp1/40B;
x ← x + (tmp1 MOD 40B)*200000B;
tmp1 ← tmp1/40B;
leftEdge ←
leftEdge + (tmp1 MOD 100B)*200000B +
(IF tmp1/40B # 0 THEN 37760000000B ELSE 0);
InsertTrapezoid[x, width, stripe*stripeHeight+y, height, leftEdge, 0, data];
END;
19 =>
BEGIN -- Trapezoid 2
x, width, rightEdge: INT;
y, height, tmp1: INT;
height ← t1/100B + 1;
width ← ReadMebesWord[];
x ← ReadMebesWord[];
y ← ReadMebesWord[];
rightEdge ← ReadMebesWord[];
tmp1 ← ReadMebesWord[];
width ← width + (tmp1 MOD 40B)*200000B;
tmp1 ← tmp1/40B;
x ← x + (tmp1 MOD 40B)*200000B;
tmp1 ← tmp1/40B;
rightEdge ←
rightEdge + (tmp1 MOD 100B)*200000B +
(IF tmp1/40B # 0 THEN 37760000000B ELSE 0);
InsertTrapezoid[x, width, stripe*stripeHeight+y, height, 0, rightEdge, data];
END;
20 =>
BEGIN -- Trapezoid 3
x, width, leftEdge, rightEdge: INT;
y, height, tmp1: INT;
height ← t1/100B + 1;
width ← ReadMebesWord[];
x ← ReadMebesWord[];
y ← ReadMebesWord[];
leftEdge ← ReadMebesWord[];
rightEdge ← ReadMebesWord[];
tmp1 ← ReadMebesWord[];
width ← width + (tmp1 MOD 40B)*200000B;
tmp1 ← tmp1/40B;
x ← x + (tmp1 MOD 40B)*200000B;
tmp1 ← tmp1/40B;
leftEdge ←
leftEdge + (tmp1 MOD 100B)*200000B +
(IF tmp1/40B # 0 THEN 37760000000B ELSE 0);
tmp1 ← y/2000B;
y ← y MOD 2000B;
rightEdge ←
rightEdge + (tmp1 MOD 100B)*200000B +
(IF tmp1/40B # 0 THEN 37760000000B ELSE 0);
InsertTrapezoid[x, width, stripe*stripeHeight+y, height, leftEdge, rightEdge, data];
END;
9 => index ← blockSize; -- end of buffer
4 => RETURN; -- end of drawing
7 =>
BEGIN -- start of stripe
stripe ← t1/256;
stripeVisible ← StripeVisible[stripe, data];
END;
8 => NULL; -- end of stripe
3, 6 => FOR i: INT IN [1..16) DO [] ← ReadMebesWord[]; ENDLOOP; -- header
ENDCASE => ERROR NotMEBESFormat;
ENDLOOP;
END;
seeEverything: BOOLFALSE;
StripeVisible: PROC [ stripe: INT, data: REFNIL ] RETURNS [ visible: BOOL ] =
BEGIN
SELECT TRUE FROM
seeEverything => visible ← TRUE;
data = NIL => visible ← FALSE;
ENDCASE =>
BEGIN
context: Imager.Context = NARROW[data];
visible ← context.TestRectangle[x: 0, y: stripe*stripeHeight, w: LAST[INTEGER], h: stripeHeight] # invisible;
END;
END;
InsertTrapezoid: PROCEDURE [ x, width, y, height, leftEdge, rightEdge: INT, data: REFNIL] =
BEGIN
FOR pos: INT IN [0..height) DO
le: INT = x + (pos*leftEdge)/height;
re: INT = x + (pos*rightEdge)/height + width - 1;
left: INT = (le + 8)/16;
right: INT = (re + 7)/16;
IF right < left THEN LOOP;
InsertRectangle[left, right - left + 1, y + pos, 1, data];
ENDLOOP;
END;
InsertRectangle: PROCEDURE [x, width, y, height: INT, data: REFNIL] =
BEGIN
IF width # 0 AND height # 0 AND data # NIL THEN
BEGIN
context: Imager.Context = NARROW[data];
context.IntegerMaskRectangle[x: x, y: y, w: width, h: height];
END;
END;
DoNothing: PROC [ cmd: Commander.Handle ] RETURNS [ result: REFNIL, msg: Rope.ROPENIL ] -- Commander.CommandProc -- = {NULL};
Commander.Register["MebesBitsCedar", DoNothing, "Plots .mebes files with the Imager. User interface through Cedar interpreter."];
END.