DIRECTORY Inline USING [BITAND, BITSHIFT], Rope USING [ROPE]; Map: DEFINITIONS IMPORTS Inline = BEGIN ColorMapSize: TYPE = [0..256); ColorRange: TYPE = REAL; ColorList: TYPE = LIST OF Triplet; Triplet: TYPE = REF TripletRec; TripletRec: TYPE = RECORD [r, g, b: ColorRange]; PalTable: TYPE = REF PalTableRec; PalTableRec: TYPE = RECORD [ size:CARDINAL, data:SEQUENCE ix:CARDINAL OF TripletRec]; ColorTable: TYPE = REF ColorTableRec; ColorTableRec: TYPE = RECORD [ size:CARDINAL, data:SEQUENCE ix:CARDINAL OF ColorMapSize]; ErrorFunc: TYPE = PROCEDURE [r1,g1,b1,r2,g2,b2: ColorRange] RETURNS [error:REAL] ; GetIndex: PUBLIC PROC [r, g, b:INTEGER, table:ColorTable] RETURNS [palix:CARDINAL] = INLINE { r _ MAX[0, MIN[r+7,255]]; g _ MAX[0, MIN[g+7,255]]; b _ MAX[0, MIN[b+7,255]]; palix _ table[Inline.BITSHIFT[Inline.BITAND[r, 360B], 4] + Inline.BITSHIFT[Inline.BITAND[g, 360B],0] + Inline.BITSHIFT[Inline.BITAND[b, 360B],-4]]; }; InsertColor: PUBLIC PROCEDURE [r,g,b: ColorRange, list: ColorList _ NIL] RETURNS [ColorList] = INLINE {RETURN [CONS[NEW[TripletRec _ [r, g, b]], list]]}; NullList: SIGNAL []; ListToTable: PUBLIC PROCEDURE [list: ColorList, error: ErrorFunc _ Vector3D] RETURNS [colorTable: ColorTable, pal:PalTable] ; MakeStandardList: PUBLIC PROCEDURE [redMax, greenMax, blueMax, grayMax:CARDINAL] RETURNS [l:ColorList] ; Restore: PUBLIC PROCEDURE [fileName:Rope.ROPE] RETURNS [table:ColorTable, pal:PalTable] ; Save: PUBLIC PROCEDURE [fileName:Rope.ROPE, table:ColorTable_NIL, pal:PalTable] ; Vector3D: PUBLIC ErrorFunc; END. φMap.Mesa Mik Lamming - September 30, 1982 11:37 am This module provides a mechanism for reducing a 24 bit color to an 8 bit index into a color palette. The goal is to allow a user to fill up a device's color palette (hardware) with any small subset of 24-bit colors. Given this set of colors, this module will generate a mapping table from the complete set of colors (16777216) to the subset contained in the color palette. 24 bit colors are mapped down to 8 bit indexes by separating the 24 bit color into 8 bit R,G,B and truncating each of these to 4 bits then combining the result to give a 12 bit index into a 4096 element table - the ColorTable. Each element in the color table contains the index of the 'nearest' color in the palette. During creation of the color map determination the 'nearest' color is the responsibility of a client procedure 'ErrorFunc'. The module also provides facilities for storing and retrieving [table, palette] pairs and a function for doing the actual mapping using the ColorTable. A user supplied routine used by ListToTable to determine hte 'difference' between two colours Returns the index of the 'nearest' color in the color palette to [r,g,b]. r,g and b are supposed to lie in the range [0..256) and will be rounded if they don't Generates a list of colors, later to be used by ListToTable to create the colormap and palette tables A signal raised by ListToTable if it doesnt have anything sensible to work on Creates a PalTable and a 4096 element ColorTable of indexes into a PalTable. The PalTable is a tabular version of the ColorList. Generates a list of colors containing: a) every combination of colors that can be generated using redMax equally spaced reds, greenMax equally spaced greens, and blueMax equally spaced blues. b) grayMax equally spaced grays excluding black and white Restore a color table and palette from given file Saves a color table and palette on a file A default error function which uses Cartesian distance to determine the nearness of two colors Κ―– "Mesa" style˜J™J™)J™šΟk ˜ Jšœ œœ˜"Jšœœœ˜—J™šΟnœ ˜Jšœ ˜Jšœœ ˜Jšœ œœ˜Jšœ œœœ ˜"Jšœ œœ ˜Jšœ œœ˜0Jšœ œœ ˜!šœ œœ˜Jšœœ˜Jšœœœœ ˜)—Jšœ œœ˜%šœœœ˜Jšœœ˜Jšœœœœ˜+—J™Jšœ£ž œš™ΖJ˜Jš ž œœ œ!œœ˜RJ™]J™šžœœœ  œœœœ˜]J™ŸJš œœœœœœœ ˜MJš œœœœœœœ˜–J˜J˜—J™Jšž œœ'œœœœœœ"˜™J™eJ™Jšžœœ˜J™MJ™Jšž œœ0œ)˜}Jšœ™J™Jšžœœ%œœ˜h™'J™˜J™:J™—Jšžœœœœ#˜YJ™1J™Jšžœœœœ˜QJ™)J™Jšžœœ ˜J™^Iproc˜Jšœ˜——…—³