SnapshotImpl.mesa
Copyright Ó 1985, 1986, 1987, 1992 by Xerox Corporation. All rights reserved.
Michael Plass, January 22, 1988 5:37:14 pm PST
Doug Wyatt, June 6, 1986 2:41:31 pm PDT
Maureen Stone, April 22, 1987 2:47:48 pm PDT
Kenneth A. Pier, September 3, 1992 11:31 am PDT. Ported to Cedar10.
DIRECTORY Imager, Commander, FS, IO, ImagerBackdoor, ImagerInterpress, ImagerPixelArray, Rope, SF, ViewerPrivate, ViewersWorld, ViewersWorldInstance, Snapshot;
SnapshotImpl: CEDAR PROGRAM
IMPORTS Imager, Commander, FS, IO, ImagerBackdoor, ImagerInterpress, ImagerPixelArray, ViewerPrivate, ViewersWorld, ViewersWorldInstance
EXPORTS Snapshot ~ BEGIN
ROPE: TYPE ~ Rope.ROPE;
<<ColorOperator: TYPE ~ ImagerColor.ColorOperator;
ConstantColor: TYPE ~ ImagerColor.ConstantColor;>>
<<ColorSnapshot: PUBLIC PROC [context: Imager.Context, vt: Terminal.Virtual, f0, s0: NAT ¬ 0, f1, s1: NAT ¬ NAT.LAST] ~ {
box: SF.Box ~ [[MIN[s0, s1], MIN[f0, f1]], [MAX[s0, s1], MAX[f0, f1]]];
S: PROC [s: ImagerSample.SampleMap] RETURNS [ImagerSample.SampleMap] ~ {
RETURN [s.Clip[box].ZeroOrigin[].Copy[]]
};
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];
pixelMap: ImagerPixel.PixelMap ~ ImagerFullColorContext.PixelMapFromFrameBuffers[frameA, frameB];
pm: ImagerPixel.PixelMap ~ ImagerPixel.MakePixelMap[S[pixelMap[0]], S[pixelMap[1]], S[pixelMap[2]]];
op: ColorOperator ~ ImagerColor.NewColorOperatorRGB[maxIn: 255];
pa: ImagerPixelArray.PixelArray ~ ImagerPixelArray.FromPixelMap[pixelMap: pm, box: pm.box, scanMode: [slow: down, fast: right], immutable: TRUE];
Imager.DrawSampledColor[context: context, pa: pa, colorOperator: op];
}
ELSE {
frame: Terminal.FrameBuffer ~ Terminal.GetColorFrameBufferA[vt];
sm: ImagerSample.SampleMap ~ S[ImagerSample.MapFromFrameBuffer[frame]];
pm: ImagerPixel.PixelMap ¬ ImagerPixel.MakePixelMap[sm];
maxSample: NAT ~ Basics.BITSHIFT[1, sm.GetBitsPerSample[]]-1;
gamma: REAL ~ ImagerColorMap.GetGamma[vt];
Map: PROC [s: ImagerSample.Sample] RETURNS [ImagerColor.ConstantColor] ~ {
r, g, b: NAT ¬ 0;
[r, g, b] ¬ Terminal.GetColor[vt: vt, aChannelValue: s, bChannelValue: 0];
RETURN [ImagerColor.ColorFromRGB[[
ImagerColorMap.ApplyGammaInverse[r, gamma],
ImagerColorMap.ApplyGammaInverse[g, gamma],
ImagerColorMap.ApplyGammaInverse[b, gamma]]]];
};
op: ColorOperator ~ ImagerColor.NewColorOperatorMap[maxSampleValue: maxSample, map: Map];
pa: ImagerPixelArray.PixelArray ~ ImagerPixelArray.FromPixelMap[pixelMap: pm, box: pm.box, scanMode: [slow: down, fast: right], immutable: TRUE];
Imager.DrawSampledColor[context: context, pa: pa, colorOperator: op];
};
};
};
>>
Snapshot: PUBLIC PROC [context: Imager.Context, screen: ViewerPrivate.Screen, f0, s0: NAT ¬ 0, f1, s1: NAT ¬ NAT.LAST] ~ {
action: PROC [pixelMap: Imager.PixelMap] = {
pa: Imager.PixelArray ¬ ImagerPixelArray.FromPixelMap[pixelMap: pixelMap, box: box, scanMode: [slow: down, fast: right], immutable: TRUE];
Imager.DrawSampledColor[context: context, pa: pa, colorOperator: op];
};
box: SF.Box ~ [[MIN[s0, s1], MIN[f0, f1]], [MAX[s0, s1], MAX[f0, f1]]];
screenContext: Imager.Context ¬ ViewerPrivate.CreateContext[screen];
op: Imager.ColorOperator ¬ ImagerBackdoor.GetBufferColorOperator[screenContext];
ImagerBackdoor.AccessBufferRectangle[screenContext, action, [f0, s0, f1, s1] ];
};
SnapshotIP: PROC [fileName: ROPE] ~ {
interpress: ImagerInterpress.Ref ¬ ImagerInterpress.Create[fileName];
Paint: PROC [context: Imager.Context] ~ {
width, height: NAT ← 0;
[width, height] ← ViewersWorld.GetSize[ViewersWorldInstance.GetWorld[]];
Imager.SetPriorityImportant[context, TRUE];
Snapshot[context: context, screen: main, s0: 0, f0: 0, s1: height, f1: width];
};
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];
IF outputName = NIL THEN {cmd.out.PutRope[cmd.procData.doc]; RETURN};
SnapshotIP[outputName];
outputName ¬ FindFullName[outputName];
cmd.out.PutRope[outputName];
cmd.out.PutRope[" written.\n"];
};
Commander.Register["Snapshot", SnapshotCommand, "Make an Interpress master from the screen. Specify output IP file name.\n"];
END.