IPImageImpl.mesa
Last edited by:
Doug Wyatt, March 9, 1984 2:43:16 pm PST
DIRECTORY
Imager -- USING most everything --,
ImagerBasic USING [State],
ImagerExtras USING [MakeSampledBlack, MakeSampledColor, MaskTrapezoidX, MaskTrapezoidY, Show, ShowAndXRel],
IP USING [Any, AppearanceWarning, Apply, CheckInteger, Color, DoWithMarkProtection, FGet, GetIndex, ImagerVariable, Index, Integer, MasterError, Operator, Outline, Pair, PixelArray, PopBool, PopColor, PopInteger, PopOperator, PopOutline, PopPair, PopPixelArray, PopReal, PopTrajectory, PopTransformation, PopVector, PushColor, PushInteger, PushOutline, PushPair, PushPixelArray, PushReal, PushTrajectory, PushTransformation, PushVector, SetIndex, State, Trajectory, Transformation, Vector, VectorFromAny],
IPFont USING [FindFont, FindFontVec, FontFromVector, ModifyFont, VectorFromFont],
IPImage USING [];
IPImageImpl: CEDAR PROGRAM
IMPORTS Imager, ImagerExtras, IP, IPFont
EXPORTS IPImage
~ BEGIN OPEN IP;
PopImagerVariable: PROC[self: State] RETURNS[ImagerVariable] ~ {
ImagerVariableValue: TYPE ~ [ImagerVariable.FIRST.ORD..ImagerVariable.LAST.ORD];
i: Integer ~ PopInteger[self];
IF i IN ImagerVariableValue THEN RETURN[LOOPHOLE[ImagerVariableValue[i]]]
ELSE { MasterError[$boundsFault, "Imager variable index out of bounds."]; ERROR };
};
ApplyIGET: PUBLIC PROC[self: State] ~ {
var: ImagerVariable ~ PopImagerVariable[self];
state: ImagerBasic.State ~ self.imager.state;
SELECT var FROM
DCScpx => PushReal[self, state.cpx];
DCScpy => PushReal[self, state.cpy];
correctMX => PushReal[self, state.correctMX];
correctMY => PushReal[self, state.correctMY];
T => PushTransformation[self, state.T];
priorityImportant => PushInteger[self, CheckInteger[state.priorityImportant]];
mediumXSize => PushReal[self, state.mediumXSize];
mediumYSize => PushReal[self, state.mediumYSize];
fieldXMin => PushReal[self, state.fieldXMin];
fieldYMin => PushReal[self, state.fieldYMin];
fieldXMax => PushReal[self, state.fieldXMax];
fieldYMax => PushReal[self, state.fieldYMax];
showVec => PushVector[self, IPFont.VectorFromFont[NARROW[state.showVec]]];
color => PushColor[self, state.color];
noImage => PushInteger[self, CheckInteger[state.noImage]];
strokeWidth => PushReal[self, state.strokeWidth];
strokeEnd => PushInteger[self, CheckInteger[state.strokeEnd]];
underlineStart => PushReal[self, state.underlineStart];
amplifySpace => PushReal[self, state.amplifySpace];
correctPass => PushInteger[self, CheckInteger[state.correctPass]];
correctShrink => PushReal[self, state.correctShrink];
correctTX => PushReal[self, state.correctTX];
correctTY => PushReal[self, state.correctTY];
clipOutline => Push[self, state.clipOutline];
ENDCASE => ERROR;
};
ApplyISET: PUBLIC PROC[self: State] ~ {
var: ImagerVariable ~ PopImagerVariable[self];
state: ImagerBasic.State ~ self.imager.state;
SELECT var FROM
DCScpx => state.cpx ← PopReal[self];
DCScpy => state.cpy ← PopReal[self];
correctMX => state.correctMX ← PopReal[self];
correctMY => state.correctMY ← PopReal[self];
T => state.T ← PopTransformation[self];
priorityImportant => state.priorityImportant ← PopInteger[self];
mediumXSize => state.mediumXSize ← PopReal[self];
mediumYSize => state.mediumYSize ← PopReal[self];
fieldXMin => state.fieldXMin ← PopReal[self];
fieldYMin => state.fieldYMin ← PopReal[self];
fieldXMax => state.fieldXMax ← PopReal[self];
fieldYMax => state.fieldYMax ← PopReal[self];
showVec => state.showVec ← IPFont.FontFromVector[PopVector[self]];
color => state.color ← PopColor[self];
noImage => state.noImage ← PopInteger[self];
strokeWidth => state.strokeWidth ← PopReal[self];
strokeEnd => state.strokeEnd ← PopInteger[self];
underlineStart => state.underlineStart ← PopReal[self];
amplifySpace => state.amplifySpace ← PopReal[self];
correctPass => state.correctPass ← PopInteger[self];
correctShrink => state.correctShrink ← PopReal[self];
correctTX => state.correctTX ← PopReal[self];
correctTY => state.correctTY ← PopReal[self];
clipOutline => state.clipOutline ← Pop[self];
ENDCASE => ERROR;
};
ApplyDROUND: PUBLIC PROC[self: State] ~ {
p: Pair ~ PopPair[self];
PushPair[self, Imager.DRound[p]];
};
ApplyMAKET: PUBLIC PROC[self: State] ~ {
f: REAL ~ PopReal[self];
e: REAL ~ PopReal[self];
d: REAL ~ PopReal[self];
c: REAL ~ PopReal[self];
b: REAL ~ PopReal[self];
a: REAL ~ PopReal[self];
PushTransformation[self, Imager.MakeT[a, b, c, d, e, f]];
};
ApplyOPENT: PUBLIC PROC[self: State] ~ {
m: Transformation ~ PopTransformation[self];
a, b, c, d, e, f: REAL;
[a, b, c, d, e, f] ← Imager.OpenT[m];
PushReal[self, a]; PushReal[self, b]; PushReal[self, c];
PushReal[self, d]; PushReal[self, e]; PushReal[self, f];
};
ApplyTRANSLATE: PUBLIC PROC[self: State] ~ {
y: REAL ~ PopReal[self]; x: REAL ~ PopReal[self];
PushTransformation[self, Imager.Translate[x, y]];
};
ApplyROTATE: PUBLIC PROC[self: State] ~ {
a: REAL ~ PopReal[self];
PushTransformation[self, Imager.Rotate[a]];
};
ApplySCALE: PUBLIC PROC[self: State] ~ {
s: REAL ~ PopReal[self];
PushTransformation[self, Imager.Scale[s]];
};
ApplySCALE2: PUBLIC PROC[self: State] ~ {
sy: REAL ~ PopReal[self]; sx: REAL ~ PopReal[self];
PushTransformation[self, Imager.Scale2[sx, sy]];
};
ApplyCONCAT: PUBLIC PROC[self: State] ~ {
n: Transformation ~ PopTransformation[self];
m: Transformation ~ PopTransformation[self];
PushTransformation[self, Imager.Concat[m, n]];
};
ApplyINVERT: PUBLIC PROC[self: State] ~ {
m: Transformation ~ PopTransformation[self];
PushTransformation[self, Imager.Invert[m]];
};
ApplyTRANSFORM: PUBLIC PROC[self: State] ~ {
m: Transformation ~ PopTransformation[self];
p: Pair ~ PopPair[self];
PushPair[self, Imager.Transform[m, p]];
};
ApplyTRANSFORMVEC: PUBLIC PROC[self: State] ~ {
m: Transformation ~ PopTransformation[self];
v: Pair ~ PopPair[self];
PushPair[self, Imager.TransformVec[m, v]];
};
ApplyROUNDXY: PUBLIC PROC[self: State] ~ {
m: Transformation ~ PopTransformation[self];
p: Pair ~ PopPair[self];
PushPair[self, Imager.RoundXY[m, p]];
};
ApplyROUNDXYVEC: PUBLIC PROC[self: State] ~ {
m: Transformation ~ PopTransformation[self];
v: Pair ~ PopPair[self];
PushPair[self, Imager.RoundXYVec[m, v]];
};
ApplyCONCATT: PUBLIC PROC[self: State] ~ {
m: Transformation ~ PopTransformation[self];
Imager.ConcatT[self.imager, m];
};
ApplyMOVE: PUBLIC PROC[self: State] ~ {
Imager.Move[self.imager];
};
ApplyTRANS: PUBLIC PROC[self: State] ~ {
Imager.Trans[self.imager];
};
StringFromVector: PROC[v: Vector] RETURNS[REF TEXT] ~ {
IF v.class=$String THEN WITH v.data SELECT FROM
text: REF TEXT => RETURN[text]; ENDCASE;
RETURN[NIL];
};
ApplySHOW: PUBLIC PROC[self: State] ~ {
ImagerExtras.Show[self.imager, StringFromVector[PopVector[self]]];
};
ApplySHOWANDXREL: PUBLIC PROC[self: State] ~ {
ImagerExtras.ShowAndXRel[self.imager, StringFromVector[PopVector[self]]];
};
ApplySETXY: PUBLIC PROC[self: State] ~ {
Imager.SetXY[self.imager, PopPair[self]];
};
ApplySETXYREL: PUBLIC PROC[self: State] ~ {
Imager.SetXYRel[self.imager, PopPair[self]];
};
ApplySETXREL: PUBLIC PROC[self: State] ~ {
Imager.SetXRel[self.imager, PopReal[self]];
};
ApplySETYREL: PUBLIC PROC[self: State] ~ {
Imager.SetYRel[self.imager, PopReal[self]];
};
ApplyGETCP: PUBLIC PROC[self: State] ~ {
PushPair[self, Imager.GetCP[self.imager]];
};
ApplyGETCPROUNDED: PUBLIC PROC[self: State] ~ {
PushPair[self, Imager.GetCPRounded[self.imager]];
};
ApplyMAKEPIXELARRAY: PUBLIC PROC[self: State] ~ {
samples: Vector ~ PopVector[self];
m: Transformation ~ PopTransformation[self];
samplesInterleaved: BOOL ~ PopBool[self];
maxSampleValue: Integer ~ PopInteger[self];
samplesPerPixel: Integer ~ PopInteger[self];
yPixels: Integer ~ PopInteger[self];
xPixels: Integer ~ PopInteger[self];
PushPixelArray[self, Imager.MakePixelArray[xPixels: xPixels, yPixels: yPixels,
samplesPerPixel: samplesPerPixel, maxSampleValue: maxSampleValue,
samplesInterleaved: samplesInterleaved, m: m, samples: samples]];
MasterError[$unimplemented, "MAKEPIXELARRAY is not implemented."];
};
ApplyEXTRACTPIXELARRAY: PUBLIC PROC[self: State] ~ {
select: Vector ~ PopVector[self];
pa: PixelArray ~ PopPixelArray[self];
MasterError[$unimplemented, "EXTRACTPIXELARRAY is not implemented."];
PushPixelArray[self, pa];
};
ApplyFINDDECOMPRESSOR: PUBLIC PROC[self: State] ~ {
v: Vector ~ PopVector[self];
PushOperator[self, FindDecompressor[self, v]];
MasterError[$unimplemented, "FINDDECOMPRESSOR is not implemented."];
};
ApplyFINDCOLOR: PUBLIC PROC[self: State] ~ {
v: Vector ~ PopVector[self];
PushColor[self, FindColor[self, v]];
MasterError[$unimplemented, "FINDCOLOR is not implemented."];
};
ApplyFINDCOLOROPERATOR: PUBLIC PROC[self: State] ~ {
v: Vector ~ PopVector[self];
PushOperator[self, FindColorOperator[self, v]];
MasterError[$unimplemented, "FINDCOLOROPERATOR is not implemented."];
};
ApplyFINDCOLORMODELOPERATOR: PUBLIC PROC[self: State] ~ {
v: Vector ~ PopVector[self];
PushOperator[self, FindColorModelOperator[self, v]];
MasterError[$unimplemented, "FINDCOLORMODELOPERATOR is not implemented."];
};
ApplyMAKEGRAY: PUBLIC PROC[self: State] ~ {
f: REAL ~ PopReal[self];
PushColor[self, Imager.MakeGray[f]];
};
ApplyMAKESAMPLEDCOLOR: PUBLIC PROC[self: State] ~ {
colorOperator: Operator ~ PopOperator[self];
um: Transformation ~ PopTransformation[self];
pa: PixelArray ~ PopPixelArray[self];
PushColor[self, ImagerExtras.MakeSampledColor[pa, um, colorOperator]];
};
ApplyMAKESAMPLEDBLACK: PUBLIC PROC[self: State] ~ {
clear: BOOL ~ PopBool[self];
um: Transformation ~ PopTransformation[self];
pa: PixelArray ~ PopPixelArray[self];
PushColor[self, ImagerExtras.MakeSampledBlack[pa, um, clear]];
};
ApplySETGRAY: PUBLIC PROC[self: State] ~ {
f: REAL ~ PopReal[self];
Imager.SetColor[self.imager, Imager.MakeGray[f]];
};
ApplyMOVETO: PUBLIC PROC[self: State] ~ {
p: Pair ~ PopPair[self];
PushTrajectory[self, Imager.MoveTo[p]];
};
ApplyLINETO: PUBLIC PROC[self: State] ~ {
p: Pair ~ PopPair[self];
t: Trajectory ~ PopTrajectory[self];
PushTrajectory[self, Imager.LineTo[t, p]];
};
ApplyLINETOX: PUBLIC PROC[self: State] ~ {
x: REAL ~ PopReal[self];
t: Trajectory ~ PopTrajectory[self];
PushTrajectory[self, Imager.LineToX[t, x]];
};
ApplyLINETOY: PUBLIC PROC[self: State] ~ {
y: REAL ~ PopReal[self];
t: Trajectory ~ PopTrajectory[self];
PushTrajectory[self, Imager.LineToY[t, y]];
};
ApplyCURVETO: PUBLIC PROC[self: State] ~ {
p3: Pair ~ PopPair[self];
p2: Pair ~ PopPair[self];
p1: Pair ~ PopPair[self];
t: Trajectory ~ PopTrajectory[self];
PushTrajectory[self, Imager.CurveTo[t, p1, p2, p3]];
};
ApplyARCTO: PUBLIC PROC[self: State] ~ {
p2: Pair ~ PopPair[self];
p1: Pair ~ PopPair[self];
t: Trajectory ~ PopTrajectory[self];
PushTrajectory[self, Imager.ArcTo[t, p1, p2]];
};
ApplyCONICTO: PUBLIC PROC[self: State] ~ {
e: REAL ~ PopReal[self];
p2: Pair ~ PopPair[self];
p1: Pair ~ PopPair[self];
t: Trajectory ~ PopTrajectory[self];
PushTrajectory[self, Imager.ConicTo[t, p1, p2, e]];
};
ApplyMAKEOUTLINE: PUBLIC PROC[self: State] ~ {
n: Integer ~ PopInteger[self];
list: LIST OF Trajectory ← NIL;
THROUGH [0..n) DO list ← CONS[PopTrajectory[self], list] ENDLOOP;
PushOutline[self, Imager.MakeOutline[list]];
};
ApplyMASKFILL: PUBLIC PROC[self: State] ~ {
o: Outline ~ PopOutline[self];
Imager.MaskFill[self.imager, o];
};
ApplyMASKSTROKE: PUBLIC PROC[self: State] ~ {
t: Trajectory ~ PopTrajectory[self];
Imager.MaskStroke[self.imager, t];
};
ApplyMASKSTROKECLOSED: PUBLIC PROC[self: State] ~ {
t: Trajectory ~ PopTrajectory[self];
Imager.MaskStrokeClosed[self.imager, t];
};
ApplyMASKRECTANGLE: PUBLIC PROC[self: State] ~ {
h: REAL ~ PopReal[self]; w: REAL ~ PopReal[self];
y: REAL ~ PopReal[self]; x: REAL ~ PopReal[self];
Imager.MaskRectangle[self.imager, x, y, w, h];
};
ApplyMASKVECTOR: PUBLIC PROC[self: State] ~ {
p2: Pair ~ PopPair[self];
p1: Pair ~ PopPair[self];
Imager.MaskVector[self.imager, p1, p2];
};
ApplySTARTUNDERLINE: PUBLIC PROC[self: State] ~ {
Imager.StartUnderline[self.imager];
};
ApplyMASKUNDERLINE: PUBLIC PROC[self: State] ~ {
h: REAL ~ PopReal[self]; dy: REAL ~ PopReal[self];
Imager.MaskUnderline[self.imager, dy, h];
};
ApplyMASKTRAPEZOIDX: PUBLIC PROC[self: State] ~ {
x4: REAL ~ PopReal[self]; y3: REAL ~ PopReal[self]; x3: REAL ~ PopReal[self];
x2: REAL ~ PopReal[self]; y1: REAL ~ PopReal[self]; x1: REAL ~ PopReal[self];
ImagerExtras.MaskTrapezoidX[self.imager, x1, y1, x2, x3, y3, x4];
};
ApplyMASKTRAPEZOIDY: PUBLIC PROC[self: State] ~ {
y4: REAL ~ PopReal[self]; y3: REAL ~ PopReal[self]; x3: REAL ~ PopReal[self];
y2: REAL ~ PopReal[self]; y1: REAL ~ PopReal[self]; x1: REAL ~ PopReal[self];
ImagerExtras.MaskTrapezoidY[self.imager, x1, y1, y2, x3, y3, y4];
};
ApplyMASKPIXEL: PUBLIC PROC[self: State] ~ {
pa: PixelArray ~ PopPixelArray[self];
Imager.MaskPixel[self.imager, pa];
};
ApplyCLIPOUTLINE: PUBLIC PROC[self: State] ~ {
o: Outline ~ PopOutline[self];
Imager.ClipOutline[self.imager, o];
};
ApplyCLIPRECTANGLE: PUBLIC PROC[self: State] ~ {
h: REAL ~ PopReal[self]; w: REAL ~ PopReal[self];
y: REAL ~ PopReal[self]; x: REAL ~ PopReal[self];
Imager.ClipRectangle[self.imager, x, y, w, h];
};
ApplyFINDFONT: PUBLIC PROC[self: State] ~ {
v: Vector ~ PopVector[self];
PushVector[self, IPFont.FindFont[self, v]];
};
ApplyFINDFONTVEC: PUBLIC PROC[self: State] ~ {
v: Vector ~ PopVector[self];
PushVector[self, IPFont.FindFontVec[self, v]];
};
ApplyMODIFYFONT: PUBLIC PROC[self: State] ~ {
m: Transformation ~ PopTransformation[self];
v: Vector ~ PopVector[self];
PushVector[self, IPFont.ModifyFont[v, m]];
};
ApplySETFONT: PUBLIC PROC[self: State] ~ {
state: ImagerBasic.State ~ self.imager.state;
n: Integer ~ PopInteger[self];
state.showVec ← IPFont.FontFromVector[VectorFromAny[FGet[self, n]]];
};
ApplyCORRECTMASK: PUBLIC PROC[self: State] ~ {
Imager.CorrectMask[self.imager];
};
ApplyCORRECTSPACE: PUBLIC PROC[self: State] ~ {
Imager.CorrectSpace[self.imager, PopPair[self]];
};
ApplyCORRECT: PUBLIC PROC[self: State] ~ {
b: Index ~ GetIndex[self];
innerBody: PROC[self: State] ~ { SetIndex[self, b]; Apply[self, $dosavesimplebody] };
body: PROC ~ { [] ← DoWithMarkProtection[self, innerBody] };
Imager.Correct[self.imager, body
! Imager.Error =>
IF errorCode=$UnableToProperlyAdjustMaskPositions THEN {
AppearanceWarning[$correctFailed,
"CORRECT failed to achieve target position within tolerance."];
CONTINUE;
};
];
};
ApplySETCORRECTMEASURE: PUBLIC PROC[self: State] ~ {
Imager.SetCorrectMeasure[self.imager, PopPair[self]];
};
ApplySETCORRECTTOLERANCE: PUBLIC PROC[self: State] ~ {
Imager.SetCorrectTolerance[self.imager, PopPair[self]];
};
ApplySPACE: PUBLIC PROC[self: State] ~ {
Imager.Space[self.imager, PopReal[self]];
};
END.