JaMIDunnImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Last edited by: Mik Lamming - April 9, 1986 12:56:29 pm PST
DIRECTORY BasicTime, Convert, CommandTool, Interpress, Interpreter, PupDefs, IO, ImagerPixelMap, Terminal, InterminalBackdoor, ImagerSmooth, ImagerOps, DicentraRS232CAsync, MessageWindow, JaM, JaMIPrivate, Imager, Rope;
JaMIDunnImpl:
CEDAR MONITOR
IMPORTS BasicTime, Convert, CommandTool, Interpreter, Interpress, IO, PupDefs, ImagerPixelMap, Rope, Terminal, InterminalBackdoor, ImagerSmooth, ImagerOps, DicentraRS232CAsync, MessageWindow, Imager, JaM, JaMIPrivate
DunnHost: Rope.ROPE ← "York";
DunnWS: Rope.ROPE ← "Reprisal";
s: IO.STREAM;
Map: TYPE = ARRAY [0..255] OF NAT;
red, grn, blu: Map;
copies: NAT ← 1;
simulate: BOOLEAN ← FALSE;
cmdCode: TYPE = MACHINE DEPENDENT {
from RS232 Interface Specs for Dunn Models 631 and 632 Color Camera Systems
videoInvertHigh (2EH),
videoInvertLow (2FH),
readyTest (3AH),
statusRequest (3BH),
expose8x5TimeReq (3CH),
exposeAuxTimeReq (3DH),
exposeAdjFactorReq (3EH),
advAuxFrameCnt (3FH),
reset8x10ExposeStat (40H),
restoreFilterWheel (41H),
recovDefaultVals (42H),
select8x10Mode (43H),
selectAuxMode (44H),
selectBW (45H),
selectColor (46H),
selectNrmSeqMode (47H),
selectSepSeqMode (48H),
exposeSeq (49H),
selectVidAndExpose (4AH),
set8x10ExposeTimes (4BH),
setAuxExposeTimes (4CH),
setExposeAdjFactors (4DH),
openAuxShutter (4EH),
closeAuxShutter (4FH),
unblankMonitor (50H),
blankMonitor (51H),
selectVideoChannel (52H),
positionFilterWheel (53H),
immExposeNoVidSw (54H),
yAxisRasterCompOn (55H),
yAxisRasterCompOff (56H),
clearYAxisOffset (57H),
stepYAxisOffset (58H),
clearXAxisOffset (59H),
stepXAxisOffset (5AH),
select35mmAuxCam (5BH),
select16mmAuxCam (5CH),
select4x5AuxCam (5DH),
selectSX70AuxCam (5EH),
setNumPadChars (5FH),
resetAuxNoFilmStats (60H),
fastOn (61H),
fastOff (62H)
};
ApplyLinearMap:
PROC [self: JaM.State] ~ {
FOR i:
NAT
IN [0..255]
DO
red[i] ← grn[i] ← blu[i] ← i;
ENDLOOP;
};
ApplyForceClose:
PROC [self: JaM.State] ~ {
IF NOT simulate THEN Close[s];
};
ApplySetCopies:
PROC [self: JaM.State] ~ {
info: JaMIPrivate.Info ← JaMIPrivate.GetInfo[self];
copies ← JaM.PopInt[self];
};
ApplyInterpret:
PROC [self: JaM.State] ~ {
info: JaMIPrivate.Info ← JaMIPrivate.GetInfo[self];
command: Rope.ROPE ← JaM.PopRope[self];
errorRope: Rope.ROPE ← NIL;
[ , errorRope, ] ← Interpreter.Evaluate[command];
JaM.PushRope[self, errorRope];
};
ApplyDate:
PROC [self: JaM.State] ~ {
info: JaMIPrivate.Info ← JaMIPrivate.GetInfo[self];
JaM.PushRope[self, Convert.RopeFromTime[from:BasicTime.Now[], start:months, end:seconds, includeDayOfWeek:TRUE, includeZone:FALSE]];
};
IpOpenFailed: ERROR[msg: Rope.ROPE] = CODE;
LogError: Interpress.LogProc ~ {
ERROR IpOpenFailed[Rope.Concat["Interpress error: ", explanation]];
};
ApplyShowIP:
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];
Interpress.DoPage[master: master, page: page, context: context]
};
info: JaMIPrivate.Info ← JaMIPrivate.GetInfo[self];
context: Imager.Context ~ GetContext[self];
file: Rope.ROPE ← JaM.PopRope[self];
page: INT ← JaM.PopInt[self];
master: Interpress.OpenMaster;
master ← Interpress.Open[file, LogError ! IpOpenFailed => {
ERROR JaM.Error[type: OpenFailed, msg: msg]
}];
page ← MAX[1, MIN[page, master.pages]];
Imager.DoSaveAll[context, Action];
};
ApplyCommand:
PROC [self: JaM.State] ~ {
info: JaMIPrivate.Info ← JaMIPrivate.GetInfo[self];
JaM.Push[self, CommandTool.DoCommand[JaM.PopRope[self], NIL]];
};
ApplyDunnSnap:
ENTRY PROC [self: JaM.State] ~ {
saveR, saveG, saveB: Map;
vt: Terminal.Virtual ← InterminalBackdoor.terminal;
{
-- extra block to make vt in scope for abort
ENABLE
UNWIND => {
FOR i:
NAT
IN [0..255]
DO
Terminal.SetColor[vt, i, 0, saveR[i], saveG[i], saveB[i]];
ENDLOOP;
IF NOT simulate THEN Close[s];
};
-- Open a stream to the Dunn camera
-- set up the color map as per user's spec.
FOR i:
NAT
IN [0..255]
DO
[saveR[i], saveG[i], saveB[i]] ← Terminal.GetColor[vt, i, 0];
ENDLOOP;
-- make three spearations.
Snap[s, vt, self];
-- Close down the Dunn channel
Close[s];
-- Reset the color maps as we found them
FOR i:
NAT
IN [0..255]
DO
Terminal.SetColor[vt, i, 0, saveR[i], saveG[i], saveB[i]];
ENDLOOP;
};
};
Open:
PROC [host: Rope.
ROPE ←
NIL]
RETURNS [stream:
IO.
STREAM] ~ {
simulate ← TRUE;
MessageWindow.Clear[];
IF PupDefs.GetMyName[].Equal[DunnWS,
FALSE]
THEN {
MessageWindow.Append[" Opening connection.."];
stream ← DicentraRS232CAsync.CreateStream[host: host !
IO.Error, IO.EndOfStream => ERROR;
DicentraRS232CAsync.CommError => ERROR;
DicentraRS232CAsync.CommBusy => ERROR;
];
MessageWindow.Append[" Open"];
simulate ← FALSE
}
ELSE
MessageWindow.Append[" Simulation"];
};
Close:
PROC [stream:
IO.
STREAM] ~ {
IF
NOT simulate
THEN {
MessageWindow.Append[" Closing"];
IO.Flush[stream];
IO.Close[stream];
};
MessageWindow.Append[" Done"];
};
Cmd:
PROC [code:
cmdCode] ~ {
IF simulate THEN RETURN [];
IO.PutChar[s, LOOPHOLE[code, CHAR]];
IO.Flush[s];
IF NOT CheckReady[s] THEN ERROR;
};
CheckReady:
PROC [s:
IO.
STREAM]
RETURNS [ok:
BOOL ←
TRUE] ~ {
IO.PutChar[s, LOOPHOLE[cmdCode[readyTest], CHAR]];
IO.Flush[s];
IF
IO.GetChar[s] # 'R
THEN
{
MessageWindow.Append[" Not Ready"];
RETURN [FALSE];
};
IF
IO.GetChar[s] # '\n
THEN
{
MessageWindow.Append[" Not OK"];
RETURN [FALSE];
};
};
Snap:
PROC [s:
IO.
STREAM, vt: Terminal.Virtual, self: JaM.State] ~ {
info: JaMIPrivate.Info ← JaMIPrivate.GetInfo[self];
x: JaM.Any ~ JaM.Pop[self];
pm: ImagerPixelMap.PixelMap ← ImagerOps.PixelMapFromFrameBuffer[Terminal.GetColorFrameBufferA[vt]];
oldScreen: ImagerPixelMap.PixelMap ← pm.Copy[];
redScreen, grnScreen, bluScreen: ImagerPixelMap.PixelMap;
action:
PROC [] ~ {
pm.Fill[[0,0,pm.sSize, pm.fSize], 255];
Imager.ScaleT[ctx, 0.0254/72];
{
ENABLE UNWIND => { info.ipenabled← FALSE };
info.ipenabled← TRUE;
info.ipdc← ctx;
JaM.Execute[self, x];
info.ipenabled← FALSE;
};
};
ctx: Imager.Context ← ImagerSmooth.Create[
pm,
$Intensity,
ImagerSmooth.LikeScreen[vt.colorHeight],
72/0.0254];
IF info = NIL THEN ERROR;
{
ENABLE
UNWIND => {
Cmd[cmdCode[selectNrmSeqMode]];
Cmd[cmdCode[exposeSeq]];
Cmd[cmdCode[restoreFilterWheel]];
MessageWindow.Append[" aborted"];
pm.Transfer[oldScreen];
pm.refRep.ref ← NIL; pm.refRep ← NIL;
IF redScreen.refRep # NIL THEN redScreen.refRep.ref ← NIL;
redScreen.refRep ← NIL;
IF grnScreen.refRep # NIL THEN grnScreen.refRep.ref ← NIL;
grnScreen.refRep ← NIL;
IF bluScreen.refRep # NIL THEN bluScreen.refRep.ref ← NIL;
bluScreen.refRep ← NIL;
};
-- set up red color map, build image and cache bits
MessageWindow.Append[" Building separations"];
FOR i:
NAT
IN [0..255]
DO
Terminal.SetColor[vt, i, 0, red[i], 0, 0];
ENDLOOP;
ImagerSmooth.SetComponent[ctx, $Red];
ctx.DoSaveAll[action];
redScreen ← pm.Copy[];
MessageWindow.Append[" R"];
-- set up green color map, build image and cache bits
FOR i:
NAT
IN [0..255]
DO
Terminal.SetColor[vt, i, 0, 0, grn[i], 0];
ENDLOOP;
ImagerSmooth.SetComponent[ctx, $Green];
ctx.DoSaveAll[action];
grnScreen ← pm.Copy[];
MessageWindow.Append["G"];
-- set up blue color map, build image and cache bits
FOR i:
NAT
IN [0..255]
DO
Terminal.SetColor[vt, i, 0, 0, 0, blu[i]];
ENDLOOP;
ImagerSmooth.SetComponent[ctx, $Blue];
ctx.DoSaveAll[action];
bluScreen ← pm.Copy[];
MessageWindow.Append["B"];
MessageWindow.Append[" Snapping "];
Cmd[cmdCode[closeAuxShutter]];
Cmd[cmdCode[restoreFilterWheel]];
Cmd[cmdCode[selectSepSeqMode]];
-- set up red color map, restore image and expose it
THROUGH [1..copies]
DO
IF JaM.GetAbort[self] THEN EXIT;
FOR i:
NAT
IN [0..255]
DO
Terminal.SetColor[vt, i, 0, red[i], 0, 0];
ENDLOOP;
pm.Transfer[redScreen];
Cmd[cmdCode[exposeSeq]];
MessageWindow.Append[" R"];
-- set up green color map, restore image and expose it
FOR i:
NAT
IN [0..255]
DO
Terminal.SetColor[vt, i, 0, 0, grn[i], 0];
ENDLOOP;
ImagerSmooth.SetComponent[ctx, $Green];
pm.Transfer[grnScreen];
Cmd[cmdCode[exposeSeq]];
MessageWindow.Append["G"];
-- set up blue color map, restore image and expose it
FOR i:
NAT
IN [0..255]
DO
Terminal.SetColor[vt, i, 0, 0, 0, blu[i]];
ENDLOOP;
ImagerSmooth.SetComponent[ctx, $Blue];
pm.Transfer[bluScreen];
Cmd[cmdCode[exposeSeq]];
MessageWindow.Append["B"];
ENDLOOP;
pm.Transfer[oldScreen];
pm.refRep.ref ← NIL; pm.refRep ← NIL;
redScreen.refRep.ref ← NIL; redScreen.refRep ← NIL;
grnScreen.refRep.ref ← NIL; grnScreen.refRep ← NIL;
bluScreen.refRep.ref ← NIL; bluScreen.refRep ← NIL;
};
};
ApplySetMap:
PROC [self: JaM.State] ~ {
info: JaMIPrivate.Info ← JaMIPrivate.GetInfo[self];
map: JaM.Array ~ JaM.PopArray[self];
length: NAT ← map.length;
nEntries:NAT ← map.length / 4;
IF nEntries > 256 THEN ERROR;
FOR i:
NAT
IN [0..255]
DO
red[i] ← grn[i] ← blu[i] ← 0;
ENDLOOP;
FOR i:
NAT
IN [0..nEntries)
DO
index: NAT ← NatFromAny[JaM.AGet[map, i*4+0]];
red[index] ← NatFromAny[JaM.AGet[map, i*4+1]];
grn[index] ← NatFromAny[JaM.AGet[map, i*4+2]];
blu[index] ← NatFromAny[JaM.AGet[map, i*4+3]];
ENDLOOP;
};
NatFromAny:
PROC [x: JaM.Any]
RETURNS [
NAT] ~ {
i:
INT ←
WITH x
SELECT
FROM
x: REF INT => x^,
ENDCASE => ERROR JaM.Error[WrongType, "color map should contain CARDINALS [0-255]"];
IF i IN [0..255]
THEN
RETURN [i]
ELSE
ERROR JaM.Error[WrongType, "color map should contain CARDINALS [0-255]"]
};
RegisterDunn:
PUBLIC
PROC [self: JaM.State] ~ {
-- called with (JaMIDunnImpl) .callinit
JaM.Register[self, ".dunnsnap", ApplyDunnSnap];
JaM.Register[self, ".preparecolormaps", ApplySetMap];
JaM.Register[self, ".linearmaps", ApplyLinearMap];
JaM.Register[self, ".forcedunnclosed", ApplyForceClose];
JaM.Register[self, ".copies", ApplySetCopies];
JaM.Register[self, ".interpret", ApplyInterpret];
JaM.Register[self, ".command", ApplyCommand];
JaM.Register[self, ".date", ApplyDate];
JaM.Register[self, ".showip", ApplyShowIP];
};
Init:
PROC []
RETURNS [] ~ {
FOR i:
NAT
IN [0..255]
DO
red[i] ← grn[i] ← blu[i] ← i;
ENDLOOP;
JaM.RegisterInit["JaMIDunnImpl", RegisterDunn];
};
Init[];