AISTRCViewersImpl.mesa
Copyright © 1984 by Xerox Corporation. All rights reserved.
Implements the viewer for displaying a Tone Reproduction Curve. Hacked at to assume that high bit of sampled data is used as a mask plane — ergo, [0..127] and [128..255] of a TRC are actually two different curves.
Created Tuesday, July 31, 1984 3:32:45 pm PDT
Last edited by Eric Nickell, December 17, 1985 1:51:02 pm PST
DIRECTORY
AISTRCViewers,
Imager, --USING Lots of stuff!
ImagerPath USING [LineTo, MoveTo],
ViewerClasses,
ViewerOps USING [CreateViewer, RegisterViewerClass];
AISTRCViewersImpl:
CEDAR
PROGRAM
IMPORTS Imager, ImagerPath, ViewerOps
EXPORTS AISTRCViewers
~ {
OPEN AISTRCViewers, I: Imager, IP: ImagerPath, V: ViewerClasses;
AISTRCData: TYPE ~ REF AISTRCDataRec;
AISTRCDataRec:
TYPE ~
RECORD [
trc: REF TRC ← NIL, --TRC to display
marks: LIST OF Mark ← NIL, --x's on the field
clientData: REF ANY --Client's own data
];
Create:
PUBLIC
PROC [info:
V.ViewerRec ← [], paint:
BOOL ←
TRUE, clientData:
REF
ANY ←
NIL]
RETURNS [aisTRCViewer: AISTRCViewer] ~ {
Creates a new AISTRCViewer.
aisTRCData: AISTRCData ←
NEW[AISTRCDataRec ← [
clientData: clientData
]];
info.data ← aisTRCData;
RETURN[ViewerOps.CreateViewer[$AISTRC, info, paint]];
};
IllegalOp: PUBLIC ERROR ~ CODE;
Set:
V.SetProc ~ {
aisTRCData: AISTRCData ← NARROW[self.data];
IF aisTRCData = NIL THEN RETURN;
SELECT op
FROM
$TRC => aisTRCData.trc ← NARROW[data];
$Marks => aisTRCData.marks ← NARROW[data];
ENDCASE => ERROR IllegalOp[];
};
Get:
V.GetProc ~ {
aisTRCData: AISTRCData ← NARROW[data];
IF aisTRCData = NIL THEN RETURN[NIL];
SELECT op
FROM
$TRC => RETURN[aisTRCData.trc];
$Marks => RETURN[aisTRCData.marks];
ENDCASE => ERROR IllegalOp[];
};
black: I.ConstantColor ~ I.MakeGray[1];
grey: I.ConstantColor ~ I.MakeGray[0.5];
white:
I.ConstantColor ~
I.MakeGray[0];
length: CARDINAL ~ 256;
offset: CARDINAL ← 1;
AISTRCPaint:
PRIVATE
V.PaintProc ~ {
data: AISTRCData ← NARROW[self.data];
traj: I.Trajectory;
trc: REF TRC;
IF data=NIL OR data.trc=NIL THEN RETURN;
trc ← data.trc; --For efficiency only
Paint the TRC
I.Scale2T[context, [REAL[self.cw]/length, REAL[self.ch]/256.0]];
traj ← IP.MoveTo[[0, trc[0]]]; --Move to first point
FOR index:
NAT ← offset, index+offset
WHILE index<length
DO
traj ← IP.LineTo[traj, [index, trc[index]]];
ENDLOOP;
I.SetStrokeWidth[context, 3.0];
I.SetColor[context, black]; --Draw foreground TRC
I.MaskStrokeTrajectory[context, traj];
Paint the extra marks
I.SetColor[context, black];
FOR marks:
LIST
OF Mark ← data.marks, marks.rest
UNTIL marks=
NIL
DO
I.MaskRectangleI[context, marks.first.range, marks.first.domain, 2, 2];
ENDLOOP;
};
AISTRCInit:
PRIVATE
V.InitProc ~ {
data: AISTRCData ← NARROW[self.data];
};
aisTRCClass:
V.ViewerClass ←
NEW[
V.ViewerClassRec ← [
init: AISTRCInit,
paint: AISTRCPaint,
set: Set,
get: Get,
icon: tool
]];
ViewerOps.RegisterViewerClass[$AISTRC, aisTRCClass]; -- plug in to Viewers
}.