SnapshotImpl.mesa
Copyright © 1985, 1986 by Xerox Corporation. All rights reserved.
Michael Plass, July 23, 1985 5:26:12 pm PDT
Doug Wyatt, June 6, 1986 2:41:31 pm PDT
DIRECTORY Atom, Commander,
FS, Imager, ImagerTransformation, ImagerPixelMap, ImagerPixelArrayDefs, ImagerPixelArray, ImagerInterpress,
IO, Rope, ImagerColorMap, ImagerColorOperator, ImagerColorDefs, ImagerOps, Terminal, ImagerColor, InterminalBackdoor;
~
BEGIN
ROPE: TYPE ~ Rope.ROPE;
PixelMap: TYPE ~ ImagerPixelMap.PixelMap;
Transformation: TYPE ~ ImagerTransformation.Transformation;
PixelArray: TYPE ~ ImagerPixelArrayDefs.PixelArray;
ColorOperator: TYPE ~ ImagerColorDefs.ColorOperator;
ConstantColor: TYPE ~ ImagerColorDefs.ConstantColor;
ColorSnapshot:
PROC [context: Imager.Context, vt: Terminal.Virtual, s0, f0:
NAT ← 0, s1, f1:
NAT ←
NAT.
LAST] ~ {
w: ImagerPixelMap.DeviceRectangle ~ [sMin: MIN[s0, s1], fMin: MIN[f0, f1], sSize: ABS[s1-s0], fSize: ABS[f1-f0]];
IF Terminal.GetColorBitmapState[vt]#none
THEN {
mode: Terminal.ColorMode ~ Terminal.GetColorMode[vt];
IF mode.full
THEN {
frameA: Terminal.FrameBuffer ~ Terminal.GetColorFrameBufferA[vt];
frameB: Terminal.FrameBuffer ~ Terminal.GetColorFrameBufferB[vt];
ERROR;
}
ELSE {
frame: Terminal.FrameBuffer ~ Terminal.GetColorFrameBufferA[vt];
pm: PixelMap ~ ImagerOps.PixelMapFromFrameBuffer[frame].Clip[w].ShiftMap[-w.sMin, -w.fMin];
um: Transformation ~ ImagerTransformation.Rotate[-90].PostTranslate[[0, -pm.sSize]];
pa: PixelArray ~ ImagerOps.PixelArrayFromPixelMaps[LIST[pm], um];
maxSample: NAT ~ ImagerPixelArray.MaxSampleValue[pa, 0];
gamma: REAL ~ ImagerColorMap.GetGamma[vt];
Map:
PROC [s:
CARDINAL]
RETURNS [ImagerColorDefs.ConstantColor] ~ {
r, g, b: NAT;
[r, g, b] ← Terminal.GetColor[vt: vt, aChannelValue: s, bChannelValue: 0];
RETURN [ImagerColor.ColorFromRGB[[
R: ImagerColorMap.ApplyGammaInverse[r, gamma],
G: ImagerColorMap.ApplyGammaInverse[g, gamma],
B: ImagerColorMap.ApplyGammaInverse[b, gamma]
]]]
};
op: ColorOperator ~ ImagerColorOperator.MapColorModel[maxSample, Map];
Imager.SetSampledColor[context: context, pa: pa, m: NIL, colorOperator: op];
Imager.MaskRectangleI[context, 0, 0, pm.fSize, pm.sSize];
Imager.SetGray[context, 1];
};
};
};
BWSnapshot:
PROC [context: Imager.Context, vt: Terminal.Virtual, s0, f0:
NAT ← 0, s1, f1:
NAT ←
NAT.
LAST] ~ {
w: ImagerPixelMap.DeviceRectangle ~ [sMin: MIN[s0, s1], fMin: MIN[f0, f1], sSize: ABS[s1-s0], fSize: ABS[f1-f0]];
IF Terminal.GetBWBitmapState[vt]#none
THEN {
frame: Terminal.FrameBuffer ~ Terminal.GetBWFrameBuffer[vt];
pm: PixelMap ~ ImagerOps.PixelMapFromFrameBuffer[frame].Clip[w].ShiftMap[-w.sMin, -w.fMin];
um: Transformation ~ ImagerTransformation.Rotate[-90].PostTranslate[[0, -pm.sSize]];
pa: PixelArray ~ ImagerOps.PixelArrayFromPixelMaps[LIST[pm], um];
Imager.SetSampledBlack[context: context, pa: pa, m: NIL, clear: FALSE];
Imager.MaskRectangleI[context, 0, 0, pm.fSize, pm.sSize];
Imager.SetGray[context, 1];
};
};
SnapshotIP:
PROC [fileName:
ROPE, color:
BOOL] ~ {
interpress: ImagerInterpress.Ref ← ImagerInterpress.Create[fileName];
Paint:
PROC [context: Imager.Context] ~ {
Imager.SetPriorityImportant[context, TRUE];
IF color THEN ColorSnapshot[context, InterminalBackdoor.terminal]
ELSE BWSnapshot[context, InterminalBackdoor.terminal];
};
ImagerInterpress.DoPage[self: interpress, action: Paint, scale: 0.0254/72];
ImagerInterpress.Close[interpress];
};
FindFullName:
PROC [inputName:
ROPE]
RETURNS [
ROPE] ~ {
fullFName: ROPE ← NIL;
fullFName ← FS.FileInfo[inputName].fullFName;
RETURN [fullFName]
};
CmdTokenBreak:
PROC [char:
CHAR]
RETURNS [
IO.CharClass] = {
IF char = '← THEN RETURN [break];
IF char = ' OR char = '\t OR char = ', OR char = '; OR char = '\n THEN RETURN [sepr];
RETURN [other];
};
GetCmdToken:
PROC [stream:
IO.
STREAM]
RETURNS [rope:
ROPE] = {
rope ← NIL;
rope ← stream.GetTokenRope[CmdTokenBreak ! IO.EndOfStream => CONTINUE].token;
};
SnapshotCommand: Commander.CommandProc ~ {
stream: IO.STREAM ← IO.RIS[cmd.commandLine];
outputName: ROPE ← GetCmdToken[stream];
gets: ROPE ← GetCmdToken[stream];
input: ROPE ← GetCmdToken[stream];
IF outputName = NIL THEN {cmd.out.PutRope[cmd.procData.doc]; RETURN};
IF NOT gets.Equal["←"] OR input = NIL THEN {cmd.out.PutRope["Specify output ← (color | bw), please\n"]; RETURN};
SELECT
TRUE
FROM
input.Equal["color", FALSE] => SnapshotIP[outputName, TRUE];
input.Equal["bw", FALSE] => SnapshotIP[outputName, FALSE];
ENDCASE => {cmd.out.PutRope["Specify output ← (color | bw), please\n"]; RETURN};
outputName ← FindFullName[outputName];
cmd.out.PutRope[outputName];
cmd.out.PutRope[" written.\n"];
};
Commander.Register["Snapshot", SnapshotCommand, "Make an Interpress master from the screen (ouput ← (color | bw))\n"];