CCTToolImpl.mesa
Copyright © 1984, 1985 by Xerox Corporation. All rights reserved.
Implements tool to allow user to set parameters for CCT and UCR for printing
Eric Nickell January 19, 1986 11:50:43 pm PST
DIRECTORY
CCTTool,
Atom USING [GetPropFromList, PutPropOnList],
Buttons USING [Button, ButtonProc, Create, SetDisplayStyle],
ColorTransforms USING [Transform, TRC],
ColorTransformTRC USING [ReadTRCFromAltoFile],
Commander USING [CommandProc, Register],
CommandTool USING [ArgumentVector, Parse],
Containers USING [Container, Create],
Convert USING [Error, RealFromRope, RopeFromReal],
FS USING [Error, FileInfo],
Icons USING [IconFlavor, NewIconFromFile],
Imager USING [black],
ImagerFont USING [Find, Font],
Labels USING [Create, Label],
MessageWindow USING [Append, Blink],
Rope USING [Cat, Length, ROPE],
Rules USING [Create],
VFonts USING [StringWidth],
ViewerClasses USING [Viewer],
ViewerEvents USING [EventProc, RegisterEventProc],
ViewerOps USING [OpenIcon, SetOpenHeight],
ViewerTools USING [GetContents, MakeNewTextViewer, SetContents];
CCTToolImpl: CEDAR MONITOR
IMPORTS Atom, Buttons, ColorTransformTRC, Commander, CommandTool, Containers, Convert, FS, Icons, Imager, ImagerFont, Labels, MessageWindow, Rope, Rules, VFonts, ViewerEvents, ViewerOps, ViewerTools
EXPORTS CCTTool
~ {
OPEN CCTTool;
Types and Constants
ROPE: TYPE ~ Rope.ROPE;
Viewer: TYPE ~ ViewerClasses.Viewer;
TransformCoords: TYPE ~ RECORD [from, to: NAT];
Global Data
entryVSpace: CARDINAL = 8;
entryHSpace: CARDINAL = 2;
hMargin: CARDINAL = 5; --Spacing between buttons on a line
vMargin: CARDINAL = 5; --Spacing between rows of buttons
graphInset: CARDINAL = 110;
buttonHeight: CARDINAL ← 20;
buttonWidth: CARDINAL ← 0;
trcWidth: CARDINAL ← 250;
trcHeight: CARDINAL ← trcWidth;
typicalWidth: CARDINAL ~ entryVSpace+graphInset+trcWidth;
viewer: Containers.Container ← NIL;  --The actual CCT Tool viewer
printTrcFile: ROPENIL;
printTrcNames: ARRAY [0..3) OF ROPEALL[NIL];
printTrcs: PUBLIC ARRAY [0..3) OF ColorTransforms.TRC;
transform: PUBLIC ColorTransforms.Transform ← [[1,0,0],[0,1,0],[0,0,1],[0,0,0]];
toggleButton: PUBLIC PACKED ARRAY ToggleButton OF BOOLEANALL[FALSE];
ucrGamma, ucrThreshold, ucrFraction: PUBLIC REAL ← 0;
cctToolIcon: Icons.IconFlavor ~ Icons.NewIconFromFile["CCTTool.icons", 0];
CCTTool Implementation
NoCCTTool: PROC RETURNS [BOOLEAN] ~ INLINE {
RETURN [viewer=NIL OR viewer.destroyed]
};
MakeCCTToolCommand: Commander.CommandProc = BEGIN
RETURN [msg: MakeCCTTool[]]
END;
MakeCCTTool: ENTRY PROC RETURNS [msg: ROPE] ~ {
ENABLE UNWIND => NULL;
height: CARDINAL;
IF viewer#NIL AND ~viewer.destroyed THEN {
ViewerOps.OpenIcon[viewer];
RETURN [msg: "Opened existing CCT Tool.\n"]
};
viewer ← Containers.Create[[
name: "Coronado CCT Tool",
column: right,
iconic: TRUE,
icon: cctToolIcon,
scrollable: TRUE ]];
height ← MakeCCTViewer[];
ViewerOps.SetOpenHeight[viewer, height];
};
CCTTextLosingInputFocus: ENTRY ViewerEvents.EventProc = {
[viewer: ViewerClasses.Viewer, event: ViewerEvents.ViewerEvent, before: BOOL] RETURNS [abort: BOOL ← FALSE]
GetValue: PROC RETURNS [value: REAL] ~ {
value ← Convert.RealFromRope[r: contents ! Convert.Error => {
MessageWindow.Append[message: Rope.Cat[contents, "not a legal value."], clearFirst: TRUE];
MessageWindow.Blink[];
value ← 0;
ViewerTools.SetContents[viewer: viewer, contents: "0"];
CONTINUE;
}];
};
EvaluateTRCs: PROC ~ {
IF printTrcFile=NIL THEN RETURN;
FOR from: NAT IN [0..3) DO
IF Rope.Length[printTrcNames[from]]=0 THEN printTrcs[from] ← NIL ELSE printTrcs[from] ← ColorTransformTRC.ReadTRCFromAltoFile[fileName: printTrcFile, trcName: printTrcNames[from] ! ANY => {
MessageWindow.Append[message: Rope.Cat["Could not find trc: ", printTrcNames[from]], clearFirst: TRUE];
MessageWindow.Blink[];
printTrcs[from] ← NIL;
CONTINUE
}];
ENDLOOP;
};
SetTRC: PROC [from: NAT] ~ {
printTrcNames[from] ← contents;
EvaluateTRCs[];
};
id: REF ~ Atom.GetPropFromList[propList: viewer.props, prop: $CCTTool];
contents: ROPE ~ ViewerTools.GetContents[viewer: viewer];
WITH id SELECT FROM
atom: ATOM => {
SELECT atom FROM
$File => {
printTrcFile ← FS.FileInfo[name: contents ! FS.Error => {
printTrcFile ← NIL;
MessageWindow.Append[message: Rope.Cat[r1: "TRC file (", r2: contents, r3: ") not found."], clearFirst: TRUE];
MessageWindow.Blink[];
CONTINUE
}].fullFName;
EvaluateTRCs[];
};
$Red => SetTRC[from: 0];
$Green => SetTRC[from: 1];
$Blue => SetTRC[from: 2];
$Gamma => ucrGamma ← GetValue[];
$Threshold => ucrThreshold ← GetValue[];
$Fraction => ucrFraction ← GetValue[];
ENDCASE => ERROR;
};
tCoord: REF TransformCoords => transform[tCoord.from][tCoord.to] ← GetValue[];
ENDCASE => ERROR;
};
ToggleButtonProc: Buttons.ButtonProc = {
[parent: REF ANY, clientData: REF ANY ← NIL, mouseButton: Menus.MouseButton ← red, shift: BOOL ← FALSE, control: BOOL ← FALSE]
v: Viewer ~ NARROW[parent];
button: ToggleButton ~ NARROW[clientData, REF ToggleButton]^;
Buttons.SetDisplayStyle[button: v, style: IF toggleButton[button] ← ~toggleButton[button] THEN $WhiteOnBlack ELSE $BlackOnWhite];
};
MakeCCTViewer: INTERNAL PROC [] RETURNS [height: CARDINAL] ~ {
MakeRule: PROC ~ {
[] ← Rules.Create[info: [wx: entryHSpace, wy: thisY, wh: 2, ww: typicalWidth, parent: viewer], color: Imager.black];
thisY ← thisY + entryVSpace;
};
MakeTitle: PROC [title: ROPE] ~ {
font: ImagerFont.Font ~ ImagerFont.Find["Xerox/TiogaFonts/TimesRoman14B"];
tempWidth: CARDINAL ← VFonts.StringWidth[string: title, font: font];
prev ← Labels.Create[info: [name: title, wx: (typicalWidth - tempWidth)/2, wy: thisY, parent: viewer, border: FALSE], font: font];
thisY ← thisY + 14 + entryVSpace; --The 14 comes from TimesRoman14
};
MakeTextInputViewer: PROC [id: REF ANY, title, initialContents: ROPENIL, ww: INTEGER ← trcWidth, deltaThisY: INTEGER ← entryVSpace, newLine: BOOLTRUE] ~ {
IF title#NIL THEN {
tempWidth: CARDINAL ← VFonts.StringWidth[string: title];
label: Labels.Label ← Labels.Create[ info: [name: title, wx: thisX - tempWidth - 2*hMargin, wy: thisY, parent: viewer, border: FALSE]];
};
prev ← ViewerTools.MakeNewTextViewer[info: [props: Atom.PutPropOnList[propList: NIL, prop: $CCTTool, val: id], wx: thisX, wy: thisY, ww: ww, wh: buttonHeight, parent: viewer, scrollable: FALSE, data: initialContents]];
IF newLine THEN {thisX ← entryHSpace + graphInset; thisY ← thisY + prev.wh + deltaThisY} ELSE thisX ← thisX + hMargin + prev.ww;
[] ← ViewerEvents.RegisterEventProc[proc: CCTTextLosingInputFocus, event: killInputFocus, filter: prev, before: FALSE];
};
MakeToggleButton: PROC [label: ROPE, button: ToggleButton, initialState: BOOLEAN] ~ {
prev ← Buttons.Create[info: [name: label, wx: thisX, wy: thisY, parent: viewer], proc: ToggleButtonProc, clientData: NEW[ToggleButton ← button]];
Buttons.SetDisplayStyle[button: prev, style: IF toggleButton[button] ← initialState THEN $WhiteOnBlack ELSE $BlackOnWhite];
thisX ← thisX + prev.ww + hMargin;
};
prev: ViewerClasses.Viewer;
thisX: INT ← entryHSpace+graphInset;
thisY: INT ← entryVSpace;
Color correct and under-color removal
MakeTitle["Input TRC"];
MakeTextInputViewer[$File, "TRC File Name"];
MakeTextInputViewer[$Red, "Red TRC"];
MakeTextInputViewer[$Green, "Green TRC"];
MakeTextInputViewer[$Blue, "Blue TRC"];
MakeRule[];
MakeTitle["Color Correction Transform"];
FOR each: LIST OF ROPELIST["Red", "Green", "Blue", "Constant offset"], each.rest UNTIL each=NIL DO
prev ← Labels.Create[info: [name: each.first, wx: thisX, wy: thisY, parent: viewer, border: FALSE]];
thisX ← thisX + trcWidth/4-hMargin + hMargin;
ENDLOOP;
thisX ← entryHSpace + graphInset;
thisY ← thisY + prev.wh + 2;
FOR to: NAT IN [0..3) DO
FOR from: NAT IN [0..4) DO
id: REF TransformCoords ~ NEW[TransformCoords ← [from: from, to: to]];
MakeTextInputViewer[id: id, title: IF from=0 THEN SELECT to FROM 0 => "Cyan", 1 => "Magenta", 2 => "Yellow", ENDCASE => "Error" ELSE NIL, initialContents: Convert.RopeFromReal[from: transform[from][to]], ww: trcWidth/4-hMargin, newLine: from=3, deltaThisY: IF to=2 THEN entryVSpace ELSE 2];
ENDLOOP;
ENDLOOP;
MakeToggleButton["Log Data", alreadyLog, TRUE];
MakeToggleButton["Invert in", invertIn, TRUE];
MakeToggleButton["out", invertOut, FALSE];
MakeRule[];
MakeTitle["Under Color Removal"];
thisX ← entryHSpace + graphInset;
thisY ← thisY + prev.wh + entryVSpace;
MakeTextInputViewer[id: $Gamma, title: "Gamma", initialContents: "0", ww: trcWidth/4, deltaThisY: 2];
MakeTextInputViewer[id: $Threshold, title: "Threshold", initialContents: "0", ww: trcWidth/4, deltaThisY: 2];
MakeTextInputViewer[id: $Fraction, title: "Fraction Removed", initialContents: "0", ww: trcWidth/4];
height ← thisY ← thisY + entryVSpace;
};
SetGamma: Commander.CommandProc = {
[cmd: Commander.Handle] RETURNS [result: REF ANY ← NIL, msg: ROPE ← NIL]
arg: CommandTool.ArgumentVector ~ CommandTool.Parse[cmd: cmd];
IF arg.argc#2 THEN GOTO Failure;
EXITS Failure => RETURN [msg: "Usage: Gamma <realValue>", result: $Failure];
};
Init: PROC ~ {
Commander.Register[key: "MakeCCTTool", proc: MakeCCTToolCommand, doc: "Create a CCT Tool" ];
[] ← MakeCCTTool[];
};
Init[];
}.