<> <> <<>> DIRECTORY FS, IO, DisplayMap, Real, Rope; DisplayMapImpl: CEDAR PROGRAM IMPORTS FS, IO, DisplayMap, Real EXPORTS DisplayMap = BEGIN OPEN DisplayMap; ListToTable: PUBLIC PROCEDURE [list: ColorList, error: ErrorFunc _ Vector3D] RETURNS [colorTable: ColorTable, pal:PalTable]= { redRange: TYPE = [0..16); greenRange: TYPE = [0..16); blueRange: TYPE = [0..16); tableIndex: TYPE = [0..(LAST[redRange]+1)*(LAST[greenRange]+1)*(LAST[blueRange]+1)); Nearest: PROCEDURE [pal:PalTable, error: ErrorFunc, lr,lg,lb:REAL] RETURNS [palix:ColorMapSize] = { newError:REAL; bestError:REAL _ Real.LargestNumber; lr _ lr / (LAST[redRange]); lg _lg / (LAST[greenRange]); lb _ lb / (LAST[blueRange]); FOR this:CARDINAL IN [0..pal.size) DO OPEN pal[this]; newError _ error[lr,lg,lb, r,g,b]; IF newError GOTO QUIT]; REPEAT QUIT => ERROR; -- unexpected eof ENDLOOP; pal _ ReadPal[in]; IO.Close[in]; }; ReadPal: PROCEDURE [in:IO.STREAM] RETURNS [pal:PalTable _ NIL] = { length:CARDINAL _ IO.GetCard[in]; pal _ NEW[PalTableRec[length]]; pal.size _ length; FOR i:CARDINAL IN [0..length) DO OPEN pal[i]; r _ IO.GetReal[in ! IO.EndOfStream => GOTO QUIT]; g _ IO.GetReal[in ! IO.EndOfStream => GOTO QUIT]; b _ IO.GetReal[in ! IO.EndOfStream => GOTO QUIT]; REPEAT QUIT => ERROR; -- unexpected eof ENDLOOP; }; WritePal: PROCEDURE [out:IO.STREAM, pal:PalTable] = { IO.PutF[out, "\n%g\n", IO.card[pal.size]]; FOR palix:CARDINAL IN [0..pal.size) DO OPEN pal[palix]; IO.PutF[out, "%g %g %g\n", IO.real[r], IO.real[g], IO.real[b]]; ENDLOOP; }; END.