JaMMickeyMouseImpl.mesa
Copyright © 1985, 1986 by Xerox Corporation. All rights reserved.
Last edited by: Mik Lamming - April 25, 1986 3:51:20 pm PST
Michael Plass, September 9, 1986 1:57:05 pm PDT
DIRECTORY Basics, Imager, ImagerBackdoor, ImagerColorOperator, ImagerSmooth, ImagerTerminal, InterminalBackdoor, ImagerPixelMap, JaM, JaMIPrivate, MickeyMouse, PrincOps, PrincOpsUtils, Real, Rope, Terminal;
JaMMickeyMouseImpl: CEDAR MONITOR
IMPORTS Imager, ImagerBackdoor, ImagerColorOperator, ImagerSmooth, ImagerTerminal, InterminalBackdoor, ImagerPixelMap, JaM, JaMIPrivate, MickeyMouse, PrincOpsUtils, Real, Terminal
~ BEGIN
ApplyCreate: PROC [self: JaM.State] ~ {
file: Rope.ROPE ← JaM.PopRope[self];
ref: MickeyMouse.Ref ← MickeyMouse.Create[file];
JaM.Push[self, ref];
};
ApplyDrawFrame: PROC [self: JaM.State] ~ {
GetContext: PROC [self: JaM.State] RETURNS [Imager.Context] ~ {
info: JaMIPrivate.Info ← JaMIPrivate.GetInfo[self];
IF info = NIL THEN ERROR;
IF info.ipenabled THEN RETURN [info.ipdc];
RETURN[info.vdc];
};
Action: PROC ~ {
Imager.ScaleT[context, 1.0/Imager.metersPerPoint];
MickeyMouse.DrawFrame[ref, context]
};
ref: MickeyMouse.Ref ← NARROW[JaM.Pop[self]];
info: JaMIPrivate.Info ← JaMIPrivate.GetInfo[self];
context: Imager.Context ~ GetContext[self];
Imager.DoSaveAll[context, Action];
};
ApplyDrawSmoothFrame: PROC [self: JaM.State] ~ {
ref: MickeyMouse.Ref ~ NARROW[JaM.Pop[self]];
colorContext: Imager.Context ← ImagerTerminal.ColorContext[InterminalBackdoor.terminal, TRUE];
IF colorContext # NIL THEN {
Action: PROC [context: Imager.Context] ~ {
Imager.ScaleT[context, 1.0/Imager.metersPerPoint];
MickeyMouse.DrawFrame[ref, context]
};
r: Imager.Rectangle ~ ImagerBackdoor.GetBounds[colorContext];
width: NAT ~ Real.Round[r.w];
height: NAT ~ Real.Round[r.h];
pa: Imager.PixelArray ← ImagerSmooth.MakePixelArray[action: Action, sSize: height, fSize: width, components: LIST[$Red, $Green, $Blue], viewToPixel: ImagerSmooth.LikeScreen[height]];
Imager.SetSampledColor[context: colorContext, pa: pa, m: NIL, colorOperator: ImagerColorOperator.RGBLinearColorModel[255]];
Imager.MaskRectangle[colorContext, r];
};
};
GetByteMap: PROC [f: Terminal.FrameBuffer] RETURNS [ImagerPixelMap.PixelMap] ~ TRUSTED {
RETURN [ImagerPixelMap.CreateFrameBuffer[pointer: f.base, words: f.vm.words, lgBitsPerPixel: 3, rast: f.wordsPerLine, lines: f.height, ref: f]]
};
scratchRep: REF ImagerPixelMap.PixelMapRep ← NIL;
FreeScratchRep: ENTRY PROC [t: REF ImagerPixelMap.PixelMapRep] ~ { scratchRep ← t };
GetScratchRep: ENTRY PROC RETURNS [t: REF ImagerPixelMap.PixelMapRep] ~ {
t ← scratchRep;
scratchRep ← NIL;
};
GetScratchPM: PROC [sSize, fSize: NAT] RETURNS [ImagerPixelMap.PixelMap] ~ {
RETURN [ImagerPixelMap.Reshape[refRep: GetScratchRep[], lgBitsPerPixel: 3, bounds: [0, 0, sSize, fSize]]]
};
blink: BOOLTRUE;
ApplyDrawFullFrame: PROC [self: JaM.State] ~ {
ref: MickeyMouse.Ref ~ NARROW[JaM.Pop[self]];
vt: Terminal.Virtual ~ InterminalBackdoor.terminal;
IF Terminal.GetColorMode[vt].full THEN {
rg: Terminal.FrameBuffer ~ Terminal.GetColorFrameBufferA[vt];
b: ImagerPixelMap.PixelMap ~ GetByteMap[Terminal.GetColorFrameBufferB[vt]];
t: ImagerPixelMap.PixelMap ~ GetScratchPM[sSize: b.sSize, fSize: b.fSize];
context: Imager.Context ~ ImagerSmooth.Create[pixelMap: t, component: $Blue, viewToPixel: ImagerSmooth.LikeScreen[b.sSize], initialScale: 1, change: NIL, changeData: NIL];
Proc: PROC ~ {
Imager.ScaleT[context, 1.0/Imager.metersPerPoint];
MickeyMouse.DrawFrame[ref, context]
};
UnpackToRG: PROC [which: [0..1]] ~ TRUSTED {
bbTableSpace: PrincOps.BBTableSpace;
bb: PrincOps.BBptr ~ PrincOpsUtils.AlignedBBTable[@bbTableSpace];
bb^ ← [
dstBpl: rg.wordsPerLine*Basics.bitsPerWord,
srcDesc: [srcBpl[t.refRep.rast*Basics.bitsPerWord]],
height: rg.height,
width: 8,
flags: [direction: forward, disjoint: TRUE, disjointItems: TRUE, gray: FALSE, srcFunc: null, dstFunc: null]
];
FOR j: NAT IN [0..rg.width) DO
bb^.src ← [word: t.refRep.pointer+j/Basics.bytesPerWord, bit: 8*(j MOD Basics.bytesPerWord)];
bb^.dst ← [word: rg.base+j, bit: which*8];
PrincOpsUtils.BITBLT[bb];
ENDLOOP;
};
ImagerPixelMap.Fill[t, [0, 0, t.sSize, t.fSize], CARDINAL.LAST];
ImagerSmooth.SetComponent[context, $Red];
Imager.DoSaveAll[context, Proc];
IF blink THEN Terminal.SetVisibility[vt, none];
UnpackToRG[0];
ImagerPixelMap.Fill[t, [0, 0, t.sSize, t.fSize], CARDINAL.LAST];
ImagerSmooth.SetComponent[context, $Green];
Imager.DoSaveAll[context, Proc];
UnpackToRG[1];
ImagerPixelMap.Fill[t, [0, 0, t.sSize, t.fSize], CARDINAL.LAST];
ImagerSmooth.SetComponent[context, $Blue];
Imager.DoSaveAll[context, Proc];
ImagerPixelMap.Transfer[dest: b, source: t];
IF blink THEN Terminal.SetVisibility[vt, all];
FreeScratchRep[t.refRep];
};
};
ApplyNextFrame: PROC [self: JaM.State] ~ {
ref: MickeyMouse.Ref ← NARROW[JaM.Pop[self]];
MickeyMouse.NextFrame[ref];
};
RegisterMickeyMouse: PUBLIC PROC [self: JaM.State] ~ {
-- called with (JaMMickeyMouseImpl) .callinit
JaM.Register[self, ".mickeymousemakehandle", ApplyCreate];
JaM.Register[self, ".mickeymousedrawframe", ApplyDrawFrame];
JaM.Register[self, ".mickeymousedrawsmoothframe", ApplyDrawSmoothFrame];
JaM.Register[self, ".mickeymousedrawfullframe", ApplyDrawFullFrame];
JaM.Register[self, ".mickeymousenextframe", ApplyNextFrame];
};
Init: PROC [] RETURNS [] ~ {
JaM.RegisterInit["JaMMickeyMouseImpl", RegisterMickeyMouse];
};
Init[];
END.