<> <> <> <> <<>> DIRECTORY Atom, CD, CDColors, CDPrivate, Imager, ImagerColor, ImagerDitherContext, Rope; <<-- ChipNDale interface defining low layer color handling. >> <<-- (semi-public) >> CDColorsImpl: CEDAR PROGRAM IMPORTS Atom, CD, Imager, ImagerDitherContext, Rope EXPORTS CDColors = BEGIN DisplayType: TYPE = CDColors.DisplayType; <<-- {bw, bit1, bit2, bit4, bit8, bit9}; >> DisplayMode: TYPE = CDColors.DisplayMode; <<-- {normal, pushedOut}; >> Brick: TYPE = CDColors.Brick; -- ARRAY [0..4) OF CARDINAL; ColorTable: TYPE = CDColors.ColorTable; <<-- RECORD; >> <<-- bricks: ARRAY CD.Layer OF REF Brick; >> <<-- cols: ARRAY CD.Layer OF Imager.Color; >> ColorTableSet: TYPE = CDColors.ColorTableSet; <<-- ARRAY DisplayMode OF REF ColorTable;>> ColorDefinition: TYPE = CDColors.ColorDefinition; <<-- ARRAY DisplayType OF REF ColorTableSet;>> globalColors: PUBLIC REF ColorDefinition _ NEW[ColorDefinition_ALL[NIL]]; emptyBrick: REF Brick = NEW[Brick_ALL[0]]; fullBrick: REF Brick = NEW[Brick_ALL[LAST[CARDINAL]]]; NewColorTab: PROC [] RETURNS [ct: REF ColorTable] = { ct _ NEW[ColorTable _ [ bricks: NEW[ARRAY CD.Layer OF REF Brick _ ALL[fullBrick]], filter: NEW[CD.ContextFilter _ ALL[TRUE]], cols: NEW[ARRAY CD.Layer OF Imager.Color _ ALL[Imager.black]] ]]; ct.filter[CD.backgroundLayer] _ FALSE; }; GetCTS: PROC [table: REF ColorDefinition, display: DisplayType] RETURNS [cts: REF ColorTableSet] = { IF table=NIL THEN table _ globalColors; IF table[display]=NIL THEN { IF table=globalColors THEN { IF display=bit1 THEN display _ bw --color 1 bit/pixel gets same stipples as bw ELSE IF display=bit9 THEN display _ bit8; --9 bit/pixel uses same stipples as 8 bit/pixel }; IF table[display]=NIL THEN { table[display] _ NEW[ColorTableSet _ ALL[NIL]]; table[display][normal] _ NewColorTab[]; table[display][pushedOut] _ NewColorTab[]; }; }; cts _ table[display]; }; DefineColor: PUBLIC PROC[ layer: CD.Layer, brick: REF Brick _ NIL, -- do no more change the values display: DisplayType _ bw, mode: DisplayMode _ normal, table: REF ColorDefinition _ NIL --NIL uses the global table ] = BEGIN cts: REF ColorTableSet _ GetCTS[table, display]; IF brick=NIL THEN brick _ fullBrick ELSE IF brick^=fullBrick^ THEN brick _ fullBrick -- reuse fullbrick; reduce swapping ELSE IF brick^=emptyBrick^ THEN brick _ emptyBrick; cts[mode].bricks[layer] _ brick; IF mode=normal THEN cts[pushedOut].bricks[layer] _ brick; END; DefineIColor: PUBLIC PROC[ layer: CD.Layer, col: Imager.Color _ NIL, display: DisplayType _ bw, mode: DisplayMode _ normal, table: REF ColorDefinition _ NIL --NIL uses the global table ] = BEGIN cts: REF ColorTableSet _ GetCTS[table, display]; <<--check special case>> IF col#NIL AND display=bit8 AND ISTYPE[col, ImagerColor.OpConstantColor] THEN { b: REF Brick _ cts[mode].bricks[layer]; IF b#NIL AND b[0]=b[1] AND b[0]=b[1] AND b[0]=b[3] THEN { n: CARDINAL _ b[0] MOD 256; IF n=(b[0] / 256) THEN { tech: CD.Technology _ CD.LayerTechnology[layer]; col _ ImagerDitherContext.MakeSpecialColor[ ordinaryColor: NARROW[col], specialPixel: [n, or], name: Rope.Cat["Xerox/Research/ChipNDale/", (IF tech=NIL THEN "CD" ELSE tech.name), "/", Atom.GetPName[CD.LayerKey[layer]]] ]; } } }; <<--always>> cts[mode].cols[layer] _ col; cts[mode].filter[layer] _ col#NIL; IF mode=normal THEN { cts[pushedOut].cols[layer] _ col; cts[pushedOut].filter[layer] _ col#NIL; } END; globalColors[bw] _ globalColors[bit1] _ NEW[ColorTableSet]; globalColors[bw][normal] _ NewColorTab[]; globalColors[bw][pushedOut] _ NewColorTab[]; globalColors[bit8] _ globalColors[bit4] _ globalColors[bit2] _ globalColors[bit9] _ NEW[ColorTableSet]; globalColors[bit8][normal] _ NewColorTab[]; globalColors[bit8][pushedOut] _ NewColorTab[]; END.