ColorTransformTRCImpl.mesa
Copyright © 1986 by Xerox Corporation. All rights reserved.
Eric Nickell, January 15, 1986 3:26:12 pm PST
DIRECTORY
ColorTransformTRC,
FS USING [Error, StreamOpen],
IO USING [GetCard, GetLineRope, EndOfStream, Error, STREAM],
ColorTransforms USING [TRC, TRCRep],
Rope USING [Find, ROPE];
ColorTransformTRCImpl: CEDAR PROGRAM
IMPORTS FS, IO, Rope
EXPORTS ColorTransformTRC
~ BEGIN
OPEN ColorTransformTRC;
ROPE: TYPE ~ Rope.ROPE;
TRC: TYPE ~ ColorTransforms.TRC;
TRCRep: TYPE ~ ColorTransforms.TRCRep;
ReadTRCFromAltoFile: PUBLIC PROC [fileName, trcName: ROPE] RETURNS [trc: TRC] ~ {
Pair: TYPE ~ RECORD [x, y: CARDINAL];
list: LIST OF Pair ← NIL;
max: CARDINAL ← 0;
stream: IO.STREAM ~ FS.StreamOpen[fileName: fileName ! FS.Error => GOTO NotFound];
UNTIL Rope.Find[s1: IO.GetLineRope[stream: stream], s2: "[TRC]", case: FALSE ! IO.EndOfStream => GOTO NotFound]~<0 DO ENDLOOP;
UNTIL Rope.Find[s1: IO.GetLineRope[stream], s2: trcName, case: FALSE ! IO.EndOfStream => GOTO NotFound]=0 DO ENDLOOP;
DO
{
x: CARDINAL ~ IO.GetCard[stream: stream ! IO.EndOfStream, IO.Error => GOTO Exit];
y: CARDINAL ~ IO.GetCard[stream: stream];
list ← CONS[[x, y], list];
max ← MAX[x, max];
EXITS Exit => EXIT;
};
ENDLOOP;
trc ← NEW[TRCRep[max+1]];
FOR each: LIST OF Pair ← list, each.rest UNTIL each.rest=NIL DO
from: Pair ← each.rest.first;
to: Pair ← each.first;
m: REAL ~ (REAL[to.y]-REAL[from.y])/(REAL[to.x]-REAL[from.x]);
FOR x: CARDINAL IN [from.x .. to.x] DO
trc[x] ← m*(x-from.x) + from.y;
ENDLOOP;
ENDLOOP;
EXITS NotFound => RETURN [NIL];
};
PreInvertTransform: PUBLIC PROC [t: Transform, maxValue: CARDINAL ← 255] RETURNS [out: Transform] ~ {
FOR from: NAT IN [0..3) DO
FOR to: NAT IN [0..3) DO
out[from][to] ← -t[from][to];
ENDLOOP;
ENDLOOP;
FOR to: NAT IN [0..3) DO
out[3][to] ← (t[0][to]+t[1][to]+t[2][to])*maxValue + t[3][to];
ENDLOOP;
};
END.