CDColorsImpl.mesa (Viewer definitions for ChipNDale)
Copyright © 1984, 1987 by Xerox Corporation. All rights reserved.
Created by Christian Jacobi, September 19, 1984 6:00:17 pm PDT
Last edited by: Christian Jacobi, March 12, 1987 5:12:03 pm PST
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.