DIRECTORY Buttons, Commander, CommandTool, ColorMaps, FS, FileNames, Imager, ImagerColorMap, ImagerDitherContext, ImagerTerminal, InterminalBackdoor, IO, List, MessageWindow, Rope, SymTab, Terminal, TerminalIO, UserProfile, ViewerPrivate, WindowManager; ColorMapsImpl: CEDAR MONITOR IMPORTS Buttons, Commander, CommandTool, FS, FileNames, ImagerColorMap, ImagerDitherContext, ImagerTerminal, InterminalBackdoor, IO, List, MessageWindow, Rope, SymTab, Terminal, TerminalIO, UserProfile, ViewerPrivate, WindowManager EXPORTS ColorMaps = BEGIN OPEN ColorMaps; last: Rope.ROPE _ NIL; terminal: Terminal.Virtual _ InterminalBackdoor.terminal; useMapEntries: ImagerDitherContext.MapEntries _ NIL; useCursor: Terminal.ColorCursorPresentation _ onesAreWhite; regTab: SymTab.Ref _ SymTab.Create[5]; callBackList: LIST OF PROC_NIL; ContextCreator: ViewerPrivate.ContextCreatorProc = BEGIN context: Imager.Context; SELECT screen FROM bw => context _ ImagerTerminal.BWContext[vt: terminal, pixelUnits: TRUE]; color => { context _ ImagerTerminal.ColorContext[vt: terminal, pixelUnits: TRUE]; IF useMapEntries#NIL THEN ImagerDitherContext.SetDitherMap[context, useMapEntries]; [] _ Terminal.SetColorCursorPresentation[terminal, useCursor]; } ENDCASE => ERROR; RETURN [context] END; ForceColors: PROC [mapEntries: ImagerDitherContext.MapEntries, allBitsCursor: BOOL_TRUE] = BEGIN ImagerColorMap.LoadEntries[vt: terminal, mapEntries: mapEntries, gamma: 1, shared: FALSE]; useCursor _ IF allBitsCursor THEN onesAreWhite ELSE onesAreBlack; [] _ Terminal.SetColorCursorPresentation[terminal, useCursor]; [] _ ViewerPrivate.SetCreator[ContextCreator]; END; Last: PUBLIC PROC [] RETURNS [fileName: Rope.ROPE] = BEGIN RETURN [last]; END; On8Bits: PUBLIC PROC [forceOn: BOOL_TRUE, force8bit: BOOL_TRUE] RETURNS [BOOL_FALSE] = BEGIN StartWindowManager: PROC [] = { WindowManager.StartColorViewers[ screenPos: (IF Rope.Equal["right", UserProfile.Token[key: "ColorDisplay.Side"], FALSE] THEN right ELSE left), bitsPerPixel: 8 ]; }; Is8: PROC [] RETURNS [BOOL] = { m: Terminal.ColorMode = Terminal.GetColorMode[terminal]; RETURN [~m.full AND m.bitsPerPixelChannelA=8]; }; IF terminal.hasColorDisplay THEN { IF ~WindowManager.colorDisplayOn AND forceOn THEN StartWindowManager[]; IF WindowManager.colorDisplayOn AND ~Is8[] AND force8bit THEN { WindowManager.StopColorViewers[]; StartWindowManager[]; }; RETURN [ WindowManager.colorDisplayOn AND Is8[] ]; } END; SetUpFile: PROC [fileName: Rope.ROPE, forceOn: BOOL_TRUE, force8bit: BOOL_TRUE, msgs: IO.STREAM_NIL] = BEGIN fastList: LIST OF ImagerColorMap.MapEntry_NIL; slowList: LIST OF ImagerColorMap.MapEntry_NIL; cdCursor: BOOL _ TRUE; OneLine: PROC [line: Rope.ROPE] = BEGIN Range: PROC [i: INT] RETURNS [c: [0..256)] = { i _ MAX[0, MIN[i, 255]]; c _ i }; stream: IO.STREAM _IO.RIS[line]; i, index, r, g, b: INT; mapEntrie: ImagerColorMap.MapEntry; i _ IO.GetInt[stream]; r _ IO.GetInt[stream]; g _ IO.GetInt[stream]; b _ IO.GetInt[stream]; index _ ABS[i] MOD 256; mapEntrie _ [Range[index], Range[r], Range[g], Range[b]]; fastList _ CONS[mapEntrie, fastList]; IF index=i THEN slowList _ CONS[mapEntrie, slowList]; END; IF On8Bits[forceOn, force8bit] THEN { file: IO.STREAM _ NIL; line: Rope.ROPE; IF msgs=NIL THEN msgs _ TerminalIO.TOS[]; fileName _ ExtendName[fileName]; file _ FS.StreamOpen[fileName ! FS.Error => { IO.PutF[msgs, "not done: %g\n", IO.rope[error.explanation]]; GOTO thatsIt }]; line _ IO.GetTokenRope[file ! IO.EndOfStream => GOTO thatsIt].token; IF ~Rope.Equal[line, "ColorMap", FALSE] THEN { IO.PutRope[msgs, "not a ColorMap file\n"] }; line _ IO.GetTokenRope[file ! IO.EndOfStream => GOTO thatsIt].token; IF Rope.Equal[line, "onesAreBlack", FALSE] THEN cdCursor _ FALSE; BEGIN DO line _ IO.GetLineRope[file ! IO.EndOfStream => {GOTO eof}]; IF ~Rope.IsEmpty[line] THEN OneLine[line]; ENDLOOP; EXITS eof => NULL END; useMapEntries _ slowList; ForceColors[fastList, cdCursor]; last _ fileName; IO.Close[file]; }; EXITS thatsIt => NULL END; SetUpOff: PROC [] = BEGIN last _ NIL; IF terminal.hasColorDisplay THEN WindowManager.StopColorViewers[]; END; SetUpCedar: PROC[] = BEGIN last _ NIL; IF terminal.hasColorDisplay THEN { [] _ ViewerPrivate.SetCreator[NIL]; [] _ On8Bits[]; ImagerTerminal.SetStandardColorMap[terminal]; WindowManager.RestoreCursor[]; [] _ Terminal.SetColorCursorPresentation[terminal, onesAreBlack]; }; END; SetUp: PUBLIC PROC [fileName: Rope.ROPE, forceOn: BOOL_TRUE, forceBits: BOOL_TRUE, msgs: IO.STREAM_NIL] = BEGIN WHILE Rope.Equal[fileName, "type filename", FALSE] DO fileName _ TerminalIO.RequestRope["filename for colormap file (///) >"]; ENDLOOP; IF Rope.Equal[fileName, "cedar-8-bit", FALSE] THEN SetUpCedar[] ELSE IF Rope.Equal[fileName, "off", FALSE] THEN SetUpOff[] ELSE IF Rope.Equal[fileName, "?", FALSE] THEN { msgs.PutRope["current color map from: "]; msgs.PutRope[last]; msgs.PutRope["\n"]; RETURN } ELSE IF ~Rope.IsEmpty[fileName] THEN SetUpFile[fileName, forceOn, forceBits, msgs]; CallList[]; END; ExtendName: PROC [name: Rope.ROPE] RETURNS [fn: Rope.ROPE] = BEGIN fn _ name; IF Rope.Find[fn, "."]<1 THEN fn _ Rope.Concat[fn, ".ColorMap"]; END; RegisterMenu: PUBLIC PROC [entryName: Rope.ROPE, fileName: Rope.ROPE_NIL] = BEGIN IF Rope.IsEmpty[fileName] THEN [] _ regTab.Delete[entryName] ELSE [] _ regTab.Store[entryName, fileName] END; CallBack: PUBLIC ENTRY PROC [p: PROC] = BEGIN IF p#NIL THEN callBackList _ CONS [p, callBackList]; END; CallList: PROC [] = BEGIN FOR l: LIST OF PROC _ callBackList, l.rest WHILE l#NIL DO l.first[] ENDLOOP END; Create: PUBLIC PROC [fileName: Rope.ROPE, special: REF_NIL, msgs: IO.STREAM_NIL] = BEGIN file: IO.STREAM; IF msgs=NIL THEN msgs _ TerminalIO.TOS[]; IF ~On8Bits[FALSE, FALSE] THEN { msgs.PutRope["not done; not in 8 bit mode\n"]; GOTO thatsIt }; file _ FS.StreamOpen[ExtendName[fileName], create ! FS.Error => { msgs.PutRope["not done:"]; msgs.PutRope[error.explanation]; msgs.PutRope["\n"]; GOTO thatsIt }]; IO.PutRope[file, "ColorMap\n"]; IF Terminal.GetColorCursorPresentation[terminal]=onesAreBlack THEN IO.PutRope[file, "onesAreBlack\n"] ELSE IO.PutRope[file, "onesAreWhite\n"]; FOR i: Terminal.ChannelValue IN Terminal.ChannelValue DO red, green, blue: Terminal.ColorValue; index: INT _ i; [red, green, blue] _ Terminal.GetColor[terminal, i]; IF special=$i THEN index _ -index; IO.PutF[file, " %g %g %g %g\n", IO.int[index], IO.card[red], IO.card[green], IO.card[blue]]; ENDLOOP; IO.Close[file]; EXITS thatsIt => NULL END; ButtonHit: Buttons.ButtonProc = BEGIN ENABLE TerminalIO.UserAbort => GOTO aborted; choice: INT _ 0; lor: LIST OF Rope.ROPE _ NIL; Each: SymTab.EachPairAction = { lor _ CONS[key, lor]; quit _ FALSE }; [] _ regTab.Pairs[Each]; IF lor#NIL THEN choice _ TerminalIO.RequestSelection["color", lor]; IF choice>0 THEN TRUSTED { entry: Rope.ROPE _ NARROW[List.NthElement[LOOPHOLE[lor], choice]]; name: Rope.ROPE _ NARROW[regTab.Fetch[entry].val]; SetUp[name]; }; Message[]; EXITS aborted => NULL; END; Message: PROC [] = BEGIN r: Rope.ROPE _ Last[]; IF r=NIL THEN r _ "not loaded from a file"; MessageWindow.Append[Rope.Concat["color map: ", r], TRUE]; END; ColorMapCommand: Commander.CommandProc = BEGIN argv: CommandTool.ArgumentVector _ CommandTool.Parse[cmd ! CommandTool.Failed => {msg _ errorMsg; GO TO oops}]; IF argv.argc<=1 OR argv[1].IsEmpty[] THEN GO TO oops; IF argv[1].Fetch[0]#'- THEN SetUp[argv[1], TRUE, TRUE, cmd.out] ELSE { --switches.. SELECT TRUE FROM Rope.Equal[argv[1], "-n", FALSE] => { --read without forcing display IF argv.argc<=2 THEN {msg _ "needs filename"; GO TO oops}; SetUp[argv[2], FALSE, FALSE, cmd.out]; }; Rope.Equal[argv[1], "-register", FALSE] => { --register menu command fn: Rope.ROPE; IF argv.argc<=3 THEN {msg _ "needs key and filename"; GO TO oops}; fn _ FileNames.FileWithSearchRules[root: argv[3], defaultExtension: ".ColorMap", searchRules: NIL].fullPath; IF Rope.IsEmpty[fn] THEN {msg _ "file not found"; GO TO oops}; RegisterMenu[argv[2], fn]; }; Rope.Equal[argv[1], "-create", FALSE] => {--create file IF argv.argc<=2 THEN {msg _ "needs filename"; GO TO oops}; Create[argv[2], NIL, cmd.out]; }; ENDCASE => {msg _ "only known switches: -n, -register, -create"; GO TO oops}; }; EXITS oops => result _ $Failure; END; IF terminal.hasColorDisplay THEN [] _ Buttons.Create[info: [name: "8-bit colors"], proc: ButtonHit, fork: TRUE]; RegisterMenu["cedar-8-bit", "cedar-8-bit"]; RegisterMenu["off", "off"]; Commander.Register[key: "///Commands/ColorMap", proc: ColorMapCommand, doc: "reads 8 bit colormap from file [-n, -register, -create]"]; END. vColorMapsImpl.mesa Copyright c 1985 by Xerox Corporation. All rights reserved. by Christian Jacobi, December 23, 1985 12:52:29 pm PST last edited by Christian Jacobi, February 12, 1986 10:16:42 am PST --experimenting showed that the following line was necessary.... --IF ~Rope.Equal[fileName, Last[], FALSE] THEN --bad optimiztion: disables reset after other tool Κ Ά˜codešœ™Kšœ Οmœ1™˜>K˜—Kšžœžœ˜—Kšžœ ˜Kšžœ˜—K˜šΟn œžœ=žœžœ˜ZKšž˜KšœSžœ˜ZKšœ žœžœžœ˜AKšœ>˜>Kšœ.˜.Kšžœ˜—K˜š‘œž œžœžœ˜4Kšž˜Kšžœ˜Kšžœ˜—K˜š‘œž œ žœžœ žœžœžœžœžœ˜VKšž˜š‘œžœ˜šœ ˜ Kš œ žœBžœžœžœ˜nKšœ˜Kšœ˜—Kšœ˜—š‘œžœžœžœ˜Kšœ8˜8Kšžœ žœ˜.K˜—šžœžœ˜"Kšžœžœ žœ˜Gšžœžœžœ žœ˜?Kšœ!˜!Kšœ˜K˜—Kšžœ žœ ˜2K˜—Kšžœ˜—K˜š‘ œžœžœ žœžœ žœžœžœžœžœ˜fKšž˜Kšœ žœžœžœ˜.Kšœ žœžœžœ˜.Kšœ žœžœ˜K˜š‘œžœ žœ˜!Kšž˜š‘œžœžœžœ˜.Kšœžœžœ ˜Kšœ˜Kšœ˜—Kš œžœžœžœžœ˜ Kšœžœ˜Kšœ#˜#Kšœžœ˜Kšœžœ˜Kšœžœ˜Kšœžœ˜Kšœžœžœ˜Kšœ9˜9Kšœ žœ˜%Kšžœ žœ žœ˜5Kšžœ˜—K˜šžœžœ˜%Kš œžœžœžœžœ˜(Kšžœžœžœžœ˜)Kšœ ˜ šœžœžœ ˜-Kšœ=˜=Kšžœ˜ Kšœ˜—Kšœžœžœžœ˜Dšžœžœžœ˜.Kšžœ'˜)K˜—Kšœžœžœžœ˜DKšžœ"žœžœ žœ˜Ašž˜šž˜Kš œžœΟrΠkr’ œžœ˜;Kšžœžœ˜*Kšžœ˜—Kšžœž˜Kšžœ˜—Kšœ˜Kšœ ˜ Kšœ˜Kšžœ ˜K˜—Kšžœ ž˜Kšžœ˜—K˜š‘œžœ˜Kšž˜Kšœžœ˜ Kšžœžœ"˜BKšžœ˜—K˜šΠbn œžœ˜Kšž˜Kšœžœ˜ šžœžœ˜#Kšœžœ˜#Kšœ˜Kšœ.˜.Kšœ˜KšœA˜AKšœ˜—Kšžœ˜—š‘œžœžœžœ žœžœ žœžœžœžœžœ˜jKšž˜šžœ'žœžœ˜6KšœH˜HKšžœ˜—Kšžœ%žœžœ ˜?Kšžœžœžœžœ ˜:šžœžœžœžœ˜/KšœQ˜QKšž˜K˜—šžœžœžœ˜%Kšœ/™/Kšœ2™2Kšœ.˜.—Kšœ ˜ Kšžœ˜—K˜š ‘ œžœ žœžœ žœ˜Kšœ˜K˜—šœžœ₯ ˜7Kšžœžœžœžœ˜:Kšœžœ ˜K˜—Kšžœ:žœžœ˜M—K˜—Kšžœ˜ Kšžœ˜K˜—šžœžœ˜!KšœIžœ˜O—Kšœ+˜+Kšœ˜Kšœ‡˜‡Kšžœ˜—…—!/Ό