ImagerPrivateImpl.mesa
Copyright Ó 1986, 1987, 1989, 1991 by Xerox Corporation. All rights reserved.
Michael Plass, September 1, 1989 9:53:57 am PDT
Doug Wyatt, January 19, 1987 6:02:53 pm PST
DIRECTORY
Imager USING [ClassRep, ClipRectangle, ClipRectangleI, Color, ColorOperator, ConcatT, Context, DoSave, DoSaveAll, DrawSampledColor, Error, GetProp, MaskBitmap, MaskPixel, MaskRectangleI, Move, Object, PathProc, PutProp, ROPE, SetColor, SetGray, SetXY, Trans],
ImagerBackdoor USING [AccessBuffer, AccessBufferRectangle, CoordSys, GetBounds, GetTransformation, Visibility],
ImagerBox USING [Box, BoxFromRectangle, IntersectBox, Rectangle],
ImagerFont USING [MapText, XChar, XStringProc],
ImagerPixel USING [MakePixelMap, PixelMap, PixelMapRep],
ImagerPixelArray USING [FromPixelMap, PixelArray],
ImagerPrivate USING [Class, ClassRep],
ImagerSample USING [Copy, GetBox, SampleMap, Transfer],
ImagerStroke USING [Dashes],
ImagerSys USING [CheckForAbort],
ImagerTransformation USING [ApplyPreTranslate, ApplySFToXY, Destroy, ScanMode, Transform, Transformation, TransformVec, Translate],
Prop USING [Get, Put, Rem, PropList],
SF USING [Box, SizeF, SizeS, Vec],
Vector2 USING [VEC];
ImagerPrivateImpl: CEDAR PROGRAM
IMPORTS Imager, ImagerBackdoor, ImagerBox, ImagerFont, ImagerPixel, ImagerPixelArray, ImagerSample, ImagerStroke, ImagerSys, ImagerTransformation, Prop, SF
EXPORTS ImagerPrivate, Imager
~ BEGIN
Class: TYPE ~ ImagerPrivate.Class;
ClassRep: PUBLIC TYPE ~ ImagerPrivate.ClassRep; -- export to Imager.ClassRep
Context: TYPE ~ Imager.Context;
Transformation: TYPE ~ ImagerTransformation.Transformation;
PixelArray: TYPE ~ ImagerPixelArray.PixelArray;
CoordSys: TYPE ~ ImagerBackdoor.CoordSys;
Visibility: TYPE ~ ImagerBackdoor.Visibility;
ColorOperator: TYPE ~ Imager.ColorOperator;
PixelMap: TYPE ~ ImagerPixel.PixelMap;
PathProc: TYPE ~ Imager.PathProc;
noViewOps: Imager.ROPE ~ "View operations not implemented for this context";
DefaultShowAndFixedXRel: PUBLIC PROC [context: Context, string: ImagerFont.XStringProc, x: REAL] ~ {
class: Class ~ context.class;
first: BOOL ¬ TRUE;
eachChar: PROC [char: ImagerFont.XChar] ~ {
thisChar: ImagerFont.XStringProc ~ { charAction[char] };
IF first THEN first ¬ FALSE ELSE class.SetXYRel[context, [x, 0]];
class.Show[context: context, string: thisChar, xrel: FALSE];
};
string[eachChar];
};
DefaultShowText: PUBLIC PROC [context: Context, text: REF READONLY TEXT,
start: NAT ¬ 0, len: NAT ¬ NAT.LAST, xrel: BOOL ¬ FALSE] ~ {
class: Class ~ context.class;
string: ImagerFont.XStringProc ~ { ImagerFont.MapText[text, start, len, charAction] };
ImagerSys.CheckForAbort[];
class.Show[context, string, xrel];
};
DefaultMaskRectangleI: PUBLIC PROC [context: Context, x, y, w, h: INTEGER] ~ {
class: Class ~ context.class;
class.MaskRectangle[context, [x: x, y: y, w: w, h: h]];
};
DefaultMaskVector: PUBLIC PROC [context: Context, p1, p2: Vector2.VEC] ~ {
class: Class ~ context.class;
vectorPath: Imager.PathProc ~ { moveTo[p1]; lineTo[p2] };
class.MaskStroke[context: context, path: vectorPath, closed: FALSE];
};
DefaultMaskDashedStroke: PUBLIC PROC [context: Context, path: Imager.PathProc, patternLen: NAT, pattern: PROC [NAT] RETURNS [REAL], offset, length: REAL] ~ {
class: Class ~ context.class;
dashedPath: Imager.PathProc ~ { ImagerStroke.Dashes[path: path, patternLen: patternLen, pattern: pattern, offset: offset, length: length, moveTo: moveTo, lineTo: lineTo, conicTo: conicTo, curveTo: curveTo] };
class.MaskStroke[context: context, path: dashedPath, closed: FALSE];
};
DefaultMaskBitmap: PUBLIC PROC [context: Context, bitmap: ImagerSample.SampleMap, referencePoint: SF.Vec,
scanMode: ImagerTransformation.ScanMode, position: Vector2.VEC] ~ {
box: SF.Box ~ ImagerSample.GetBox[bitmap];
pa: PixelArray ~ ImagerPixelArray.FromPixelMap[pixelMap: ImagerPixel.MakePixelMap[bitmap], box: box, scanMode: [slow: right, fast: up], immutable: FALSE];
ImagerTransformation.ApplyPreTranslate[pa.m, position];
ImagerTransformation.ApplySFToXY[pa.m, scanMode, 0, 0];
ImagerTransformation.ApplyPreTranslate[pa.m, [box.min.s-referencePoint.s, box.min.f-referencePoint.f]];
Imager.MaskPixel[context, pa];
};
DefaultDrawBitmap: PUBLIC PROC [context: Context, bitmap: ImagerSample.SampleMap, referencePoint: SF.Vec,
scanMode: ImagerTransformation.ScanMode, position: Vector2.VEC] ~ {
proc: PROC ~ {
box: SF.Box ~ ImagerSample.GetBox[bitmap];
m: Transformation ¬ ImagerTransformation.Translate[position];
ImagerTransformation.ApplySFToXY[m, scanMode, 0, 0];
ImagerTransformation.ApplyPreTranslate[m, [-referencePoint.s, -referencePoint.f]];
Imager.ConcatT[context, m];
Imager.SetGray[context, 0];
Imager.MaskRectangleI[context: context, x: box.min.s, y: box.min.f, w: SF.SizeS[box], h: SF.SizeF[box]];
Imager.SetGray[context, 1];
Imager.MaskBitmap[context: context, bitmap: bitmap, referencePoint: [0, 0], scanMode: [slow: right, fast: up], position: [0, 0]];
};
Imager.DoSave[context, proc];
};
DefaultDrawPixels: PUBLIC PROC [context: Context, pixelMap: ImagerPixel.PixelMap, colorOperator: Imager.ColorOperator, referencePoint: SF.Vec, scanMode: ImagerTransformation.ScanMode, position: Vector2.VEC] ~ {
pa: PixelArray ~ ImagerPixelArray.FromPixelMap[pixelMap: pixelMap, box: pixelMap.box, scanMode: [slow: right, fast: up], immutable: FALSE];
ImagerTransformation.ApplySFToXY[pa.m, scanMode, 0, 0];
ImagerTransformation.ApplyPreTranslate[pa.m, [pixelMap.box.min.s-referencePoint.s, pixelMap.box.min.f-referencePoint.f]];
Imager.DrawSampledColor[context: context, pa: pa, colorOperator: colorOperator, m: NIL, position: position];
};
DefaultViewReset: PUBLIC PROC [context: Context] ~ {
Imager.Error[[$unimplemented, noViewOps]];
};
DefaultViewTranslateI: PUBLIC PROC [context: Context, x, y: INTEGER] ~ {
Imager.Error[[$unimplemented, noViewOps]];
};
DefaultViewClip: PUBLIC PROC [context: Context, path: Imager.PathProc, oddWrap: BOOL, exclude: BOOL] ~ {
Imager.Error[[$unimplemented, noViewOps]];
};
DefaultViewClipRectangleI: PUBLIC PROC [context: Context, x, y, w, h: INTEGER, exclude: BOOL] ~ {
Imager.Error[[$unimplemented, noViewOps]];
};
DefaultGetTransformation: PUBLIC PROC [context: Context, from, to: CoordSys] RETURNS [Transformation] ~ {
Imager.Error[[$unimplemented, noViewOps]];
};
DefaultTransform: PUBLIC PROC [context: Context, v: Vector2.VEC, from, to: CoordSys, vec: BOOL] RETURNS [Vector2.VEC] ~ {
M: Transformation ~ ImagerBackdoor.GetTransformation[context: context, from: from, to: to];
vM: Vector2.VEC ~ (IF vec THEN ImagerTransformation.TransformVec ELSE ImagerTransformation.Transform)[M, v];
ImagerTransformation.Destroy[M];
RETURN [vM];
};
DefaultMoveViewRectangle: PUBLIC PROC [context: Context, width, height, fromX, fromY, toX, toY: INTEGER] ~ {
Imager.Error[[$unimplemented, noViewOps]];
};
DefaultTestViewRectangle: PUBLIC PROC [context: Context, x, y, w, h: INTEGER] RETURNS [Visibility] ~ { RETURN [part] };
DefaultGetBounds: PUBLIC PROC [context: Context] RETURNS [ImagerBox.Rectangle] ~ {
Imager.Error[[$unimplemented, "GetBounds not implemented for this context"]];
};
DefaultDoIfVisible: PUBLIC PROC [context: Context, r: ImagerBox.Rectangle, action: PROC] ~ {
class: Class ~ context.class;
br: ImagerBox.Rectangle ¬ r;
IF class.GetBounds # DefaultGetBounds THEN {
br ¬ class.GetBounds[context ! Imager.Error => CONTINUE];
};
{ bb: ImagerBox.Box ~ ImagerBox.BoxFromRectangle[br];
cb: ImagerBox.Box ~ ImagerBox.BoxFromRectangle[r];
ib: ImagerBox.Box ~ ImagerBox.IntersectBox[bb, cb];
IF ib.xmin < ib.xmax AND ib.ymin < ib.ymax THEN action[];
};
};
DefaultDoWithBuffer: PUBLIC PROC [context: Context, action: PROC, x, y, w, h: INTEGER, backgroundColor: Imager.Color ¬ NIL] ~ {
paintBack: PROC ~ {
Imager.SetColor[context, backgroundColor];
Imager.MaskRectangleI[context, x, y, w, h];
};
clippedAction: PROC ~ {
Imager.ClipRectangleI[context, x, y, w, h];
IF backgroundColor # NIL THEN Imager.DoSave[context, paintBack];
action[];
};
Imager.DoSave[context, clippedAction];
};
DefaultDrawObject: PUBLIC PROC [context: Context, object: Imager.Object, position: Vector2.VEC, interactive: BOOL] ~ {
proc: PROC ~ {
Imager.SetXY[context, position];
IF interactive THEN Imager.Trans[context] ELSE Imager.Move[context];
Imager.ClipRectangle[context, object.clip];
object.draw[object, context]
};
Imager.DoSaveAll[context, proc];
};
DefaultGetBufferColorOperator: PUBLIC PROC [context: Context] RETURNS [ColorOperator] ~ { RETURN [NIL] };
DefaultAccessBuffer: PUBLIC PROC [context: Context, action: PROC [pixelMap: PixelMap], path: PathProc, oddWrap: BOOL] ~ {
Imager.Error[[$unimplemented, "Buffer access not implemented for this context"]];
};
DefaultSaveBuffer: PUBLIC PROC [context: Context, id: ATOM, path: PathProc, oddWrap: BOOL] ~ {
pixelMaps: LIST OF PixelMap ¬ NIL;
action: PROC [pixelMap: PixelMap] ~ {
copy: PixelMap ~ NEW[ImagerPixel.PixelMapRep[pixelMap.samplesPerPixel]];
copy.box ¬ pixelMap.box;
FOR i: NAT IN [0..pixelMap.samplesPerPixel) DO
copy[i] ¬ ImagerSample.Copy[pixelMap[i]];
ENDLOOP;
pixelMaps ¬ CONS[copy, pixelMaps];
};
savedBuffers: Prop.PropList ¬ NARROW[Imager.GetProp[context, $SavedBuffers]];
ImagerBackdoor.AccessBuffer[context: context, action: action, path: path, oddWrap: oddWrap];
savedBuffers ¬ Prop.Put[savedBuffers, id, pixelMaps];
Imager.PutProp[context, $SavedBuffers, savedBuffers];
};
DefaultRestoreBuffer: PUBLIC PROC [context: Context, id: ATOM] ~ {
savedBuffers: Prop.PropList ~ NARROW[Imager.GetProp[context, $SavedBuffers]];
pixelMaps: LIST OF PixelMap ¬ NARROW[Prop.Get[savedBuffers, id]];
action: PROC [pixelMap: PixelMap] ~ {
FOR each: LIST OF PixelMap ¬ pixelMaps, each.rest UNTIL each = NIL DO
src: PixelMap ~ each.first;
FOR i: NAT IN [0..src.samplesPerPixel) DO
ImagerSample.Transfer[dst: pixelMap[i], src: src[i]];
ENDLOOP;
ENDLOOP;
};
ImagerBackdoor.AccessBufferRectangle[context: context, action: action, rectangle: ImagerBackdoor.GetBounds[context]];
};
DefaultDiscardBuffer: PUBLIC PROC [context: Context, id: ATOM] ~ {
savedBuffers: Prop.PropList ¬ NARROW[Imager.GetProp[context, $SavedBuffers]];
savedBuffers ¬ Prop.Rem[savedBuffers, id];
Imager.PutProp[context, $SavedBuffers, savedBuffers];
Rely of garbage collection to reclaim storage.
};
END.