<> <> <> <<>> 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; <> 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; <> 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.