ColorCorrectAISImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Eric Nickell, January 15, 1986 11:14:57 am PST
DIRECTORY
AIS, ColorCorrectAIS, Basics, ColorTransforms, Rope, SampleArrays, SampleMapOps;
ColorCorrectAISImpl: CEDAR PROGRAM
IMPORTS AIS, ColorTransforms, Rope, SampleArrays, SampleMapOps
EXPORTS ColorCorrectAIS
~ BEGIN
OPEN ColorCorrectAIS;
Buffer: TYPE ~ SampleMapOps.Buffer;
ext: ARRAY Sep OF ROPE ← ["-red.ais", "-green.ais", "-blue.ais", "-cyan.ais", "-magenta.ais", "-yellow.ais", "-black.ais"];
RootToNames: PUBLIC PROC [root: ROPE] RETURNS [names: ARRAY Sep OF ROPE] ~ {
FOR color: Sep IN Sep DO
names[color] ← Rope.Cat[root, ext[color]];
ENDLOOP;
};
NamesToSampleMaps: PUBLIC PROC [names: ARRAY Sep OF ROPE] RETURNS [sm: ARRAY Sep OF SampleMap] ~ {
sSize, fSize, bitsPerSample: CARDINAL;
sm[red] ← SampleArrays.MapFromAIS[names[red]].sm;
sSize ← sm[red].sSize;
fSize ← sm[red].fSize;
bitsPerSample ← sm[red].bitsPerSample;
FOR color: Sep IN [green .. blue] DO
sm[color] ← SampleArrays.MapFromAIS[names[color]].sm;
IF sSize#sm[color].sSize OR fSize#sm[color].fSize OR bitsPerSample#sm[color].bitsPerSample THEN ERROR;
ENDLOOP;
FOR color: Sep IN [cyan .. black] DO
sm[color] ← SampleMapOps.Create[sSize: sSize, fSize: fSize, bitsPerSample: bitsPerSample];
ENDLOOP;
};
CorrectSMs: PUBLIC PROC [sm: ARRAY Sep OF SampleMap, cct: CCT, ucr: UCR] ~ {
sSize, fSize, bitsPerSample: CARDINAL;
buffer: ARRAY Sep OF Buffer;
pointer: ARRAY Sep OF LONG POINTER TO Basics.RawWords;
sSize ← sm[red].sSize;
fSize ← sm[red].fSize;
bitsPerSample ← sm[red].bitsPerSample;
FOR color: Sep IN Sep DO
buffer[color] ← SampleMapOps.ObtainBuffer[fSize];
pointer[color] ← SampleMapOps.GetPointer[buffer: buffer[color], start: 0, count: fSize];
ENDLOOP;
Here's the work-horse
FOR s: CARDINAL IN [0..sSize) DO
FOR color: Sep IN [red .. blue] DO
SampleMapOps.Get[buffer: buffer[color], count: fSize, sampleMap: sm[color], s: s, f: 0];
ENDLOOP;
TRUSTED {
ColorTransforms.ApplyCCT[cct, pointer[red], pointer[green], pointer[blue], pointer[red], pointer[green], pointer[blue], fSize];
ColorTransforms.ApplyUCR[ucr, pointer[red], pointer[green], pointer[blue], pointer[cyan], pointer[magenta], pointer[yellow], pointer[black], fSize];
};
FOR color: Sep IN [cyan .. black] DO
SampleMapOps.Put[buffer: buffer[color], count: fSize, sampleMap: sm[color], s: s, f: 0];
ENDLOOP;
ENDLOOP;
};
SaveCMYKToDisk: PUBLIC PROC [sm: ARRAY Sep OF SampleMap, names: ARRAY Sep OF ROPE] ~ {
FOR color: Sep IN [cyan .. black] DO
SampleArrays.CreateAISFromMap[sm[color], names[color]];
ENDLOOP;
};
CorrectAIS: PUBLIC PROC [names: ARRAY Sep OF ROPE, cct: CCT, ucr: UCR] ~ TRUSTED {
sSize, fSize: CARDINAL;
raster: AIS.Raster;
wref: ARRAY Sep OF AIS.WRef;
buffer: ARRAY Sep OF Buffer;
pointer: ARRAY Sep OF LONG POINTER;
FOR color: Sep IN [red .. blue] DO
fref: AIS.FRef ~ AIS.OpenFile[name: names[color]];
wref[color] ← AIS.OpenWindow[f: fref];
raster ← wref[red].fref.raster;
IF raster^ # wref[red].fref.raster^ THEN ERROR;
ENDLOOP;
sSize ← wref[red].fref.raster.scanCount;
fSize ← wref[red].fref.raster.scanLength;
FOR color: Sep IN [cyan .. black] DO
fref: AIS.FRef ~ AIS.CreateFile[name: names[color], raster: raster];
wref[color] ← AIS.OpenWindow[f: fref];
ENDLOOP;
FOR color: Sep IN Sep DO
buffer[color] ← SampleMapOps.ObtainBuffer[fSize];
pointer[color] ← LOOPHOLE[SampleMapOps.GetPointer[buffer: buffer[color], start: 0, count: fSize], LONG POINTER];
ENDLOOP;
Here's the work-horse
FOR s: CARDINAL IN [0..sSize) DO
FOR color: Sep IN [red .. blue] DO
AIS.UnsafeReadLine[w: wref[color], buffer: [length: fSize/2, addr: pointer[color]], line: s];
ENDLOOP;
TRUSTED {
ColorTransforms.ApplyCCTToBytes[cct, pointer[red], pointer[green], pointer[blue], pointer[red], pointer[green], pointer[blue], fSize];
ColorTransforms.ApplyUCRToBytes[ucr, pointer[red], pointer[green], pointer[blue], pointer[cyan], pointer[magenta], pointer[yellow], pointer[black], fSize];
};
FOR color: Sep IN [cyan .. black] DO
AIS.UnsafeWriteLine[w: wref[color], buffer: [length: fSize/2, addr: pointer[color]], line: s];
ENDLOOP;
ENDLOOP;
FOR color: Sep IN Sep DO
fref: AIS.FRef ~ wref[color].fref;
AIS.CloseWindow[w: wref[color]];
AIS.CloseFile[f: fref];
ENDLOOP;
};
END.