ColorizeViewPointOptimizeImpl.mesa
Copyright Ó 1989 by Xerox Corporation. All rights reserved.
Bob Coleman, May 2, 1990 4:01:53 pm PDT
DIRECTORY
ColorizeViewPointBackdoor, IPMaster, IPScan, Rope;
ColorizeViewPointOptimizeImpl: CEDAR PROGRAM
IMPORTS ColorizeViewPointBackdoor, IPMaster, IPScan, Rope
~ BEGIN
ROPE: TYPE ~ Rope.ROPE;
OptimizeViewPointIP: ColorizeViewPointBackdoor.Colorization ~ {
[ip: ROPE, palette: Profiles.Profile, checkSystemSetting: ColorizeViewPoint.CheckSystemSettingProc, mapData: MapData] RETURNS [newIP: ROPE]
RETURN ConvertSampledBlackAndEraseTransparentBoxes[ip: ip, palette: palette, checkSystemSetting: checkSystemSetting, mapData: mapData];
};
ConvertSampledBlackAndEraseTransparentBoxes: ColorizeViewPointBackdoor.Colorization ~ {
[ip: ROPE, palette: Profiles.Profile, checkSystemSetting: ColorizeViewPoint.CheckSystemSettingProc, mapData: MapData] RETURNS [newIP: ROPE]
PotentialCandidate: IPScan.ScanProc = {
[min: INT, max: INT, op: IPMaster.Op ← nil, seq: IPScan.Seq ← nil, num: INTEGER ← 0, punt: BOOL ← FALSE] (min points to the first token in the set, max points AFTER the last)
IF ignoreFSetAndGet AND (op=fset OR op=fget) THEN RETURN;
SELECT op FROM
makesampledblack --used in Basic Graphics and ProIllus-- => IF ~punt THEN SELECT TRUE FROM
ip.Substr[max-4, 4].Equal["\017\241\241\252"--1 MAKESAMPLEDBLACK=transparent--] AND ip.Substr[max-89, 64].Equal["\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"] -- empty bitArray -- => {
afterBox: INT;
SELECT TRUE FROM
ip.Substr[max+7, 1].Equal["\225" -- FSET--] => {
ignoreFSetAndGet ← FALSE;
frameNumber ← ip.Substr[max+5, 2]; --eg, 49 FSET = "\017\321\225": \017\321\ = 4049 = 49 (with Interpress's 4000 offset), \225 = FSET--
fSetPosition ← max+8; --just after FSET
afterBox ← EraseTransparentBoxes[start: fSetPosition--likely points to the first number in a rectangle-producing series--];
IF afterBox=0 THEN RETURN; --leave as is if can't find object being imaged
newIP ← newIP.Cat[ip.Substr[flushedTo, min-flushedTo], "\017\240\241\251" --0 MAKEGRAY--, ip.Substr[max --after MAKESAMPLEDBLACK--, fSetPosition-max --thru FSET--]];
newIP ← newIP.Concat[ip.Substr[flushedTo, fSetPosition-flushedTo]]; --this line keeps the MAKESAMPLEDBLACK in by flushing thru FSET. This would be better than the above, which substitutes an opaque MAKEGRAY, but some ImagerInterpress stuff seems to break on an MSB which isn't imaged
flushedTo ← afterBox; --elim. box being imaged
};
ip.Substr[max, 3].Equal["\017\255\223" --13 ISET--] => {--no frame being set; elim msb and box
afterBox ← EraseTransparentBoxes[start: max+3--likely points to the first number in a rectangle-producing series--];
IF afterBox=0 THEN RETURN; --leave as is if can't find object being imaged
newIP ← newIP.Concat[ip.Substr[flushedTo, min-flushedTo]];
flushedTo ← afterBox; --elim. box being imaged
};
ENDCASE => NULL; --leave as is if unknown construct
};
ip.Substr[max-4, 4].Equal["\017\240\241\252"--0 MAKESAMPLEDBLACK=opaque--] AND ip.Substr[max-89, 64].Equal["\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"] -- white bitArray-- => {
newIP ← newIP.Cat[ip.Substr[flushedTo, min-flushedTo], "\017\240\241\251" --0 MAKEGRAY--]; --replace MAKESAMPLEDBLACK with 0 MAKEGRAY
flushedTo ← max;
};
ip.Substr[max-4, 4].Equal["\017\240\241\252"--0 MAKESAMPLEDBLACK=opaque--] AND ip.Substr[max-89, 64].Equal["\377\377\000\000\377\377\000\000\377\377\000\000\377\377\000\000\377\377\000\000\377\377\000\000\377\377\000\000\377\377\000\000\377\377\000\000\377\377\000\000\377\377\000\000\377\377\000\000\377\377\000\000\377\377\000\000\377\377\000\000\377\377\000\000"] -- black bitArray-- => {
newIP ← newIP.Cat[ip.Substr[flushedTo, min-flushedTo], "\017\241\241\251" --1 MAKEGRAY--]; --replace MAKESAMPLEDBLACK with 1 MAKEGRAY
flushedTo ← max;
};
ENDCASE => NULL; --ignore all other MAKESAMPLEDBLACKs
setsampledblack --used in Gargoyle-- => IF ~punt THEN SELECT TRUE FROM
ip.Substr[max-4, 4].Equal["\017\241\241\254"--1 SETSAMPLEDBLACK=transparent--] AND ip.Substr[max-88, 64].Equal["\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"] --empty bitArray -- => {
afterBox: INT ← EraseTransparentBoxes[start: max--likely points to the first number in a rectangle-producing series--];
ignoreFSetAndGet ← TRUE; --Gargoyle doesn't store in the frame - it seems to regenerate the sampled black each time
IF afterBox=0 THEN RETURN; --leave as is if can't find object being imaged
newIP ← newIP.Concat[ip.Substr[flushedTo, min-flushedTo]]; --elim. SetSB
flushedTo ← afterBox; --elim. box being imaged
};
ip.Substr[max-4, 4].Equal["\017\240\241\254"--0 SETSAMPLEDBLACK=opaque --] AND ip.Substr[max-88, 64].Equal["\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"] --white bitArray -- => {
newIP ← newIP.Cat[ip.Substr[flushedTo, min-flushedTo], "\017\240\241\250" --0 SETGRAY--]; --replace SETSAMPLEDBLACK with 0 SETGRAY
flushedTo ← max;
};
ip.Substr[max-4, 4].Equal["\017\240\241\254"--0 SETSAMPLEDBLACK=opaque --] AND ip.Substr[max-88, 64].Equal["\377\377\000\000\377\377\000\000\377\377\000\000\377\377\000\000\377\377\000\000\377\377\000\000\377\377\000\000\377\377\000\000\377\377\000\000\377\377\000\000\377\377\000\000\377\377\000\000\377\377\000\000\377\377\000\000\377\377\000\000\377\377\000\000"] --black bitArray -- => {
newIP ← newIP.Cat[ip.Substr[flushedTo, min-flushedTo], "\017\241\241\250" --1 SETGRAY--]; --replace SETSAMPLEDBLACK with 1 SETGRAY
flushedTo ← max;
};
ENDCASE => NULL; --ignore all other SETSAMPLEDBLACKs
fset => IF max > fSetPosition--want FSETs after the first one-- AND ip.Substr[max-3, 3].Equal[frameNumber.Concat["\225"--FSET--]] THEN ignoreFSetAndGet ← TRUE; --if we run across the same frame being used for storage that MakeSampledBlack had used, ignore future FGET/SETs because they're not a transparent sampledblack
fget => IF ip.Substr[max-3, 3].Equal[frameNumber.Concat["\224"--FGET--]] AND ip.Substr[max, 3].Equal["\017\255\223" --13 ISET--] THEN {
afterBox: INT ← EraseTransparentBoxes[start: max+3--likely points to the first number in a rectangle-producing series--];
IF afterBox=0 THEN RETURN; --leave as is if can't find object being imaged
newIP ← newIP.Concat[ip.Substr[flushedTo, max+3-flushedTo]]; --thru ISET
flushedTo ← afterBox; --elim. box being imaged
};
ENDCASE => ERROR;
};
EraseTransparentBoxes: PROC [start: INT] RETURNS [afterBox: INT ← 0] ~ { --assumes is pointing at the first number of a MASKRECTANGLE (BasicGraphics & ProIllus) or MAKEOUTLINE (Gargoyle) series
NextToken: PROC [] ~ {
[token: token, next: tempPos] ← IPMaster.GetToken[encoding: ip, start: tempPos];
IF token.seq=sequenceInteger OR token.seq=sequenceRational THEN --Interpress represents some large numbers as sequenceIntegers
tempPos ← tempPos + token.len; --move pointer beyond sequence
};
token: IPMaster.Token;
tempPos: INT ← start;
FOR i: NAT IN [0..4] DO --get to MaskRectangle if there is one
NextToken[];
IF token.op=setxy THEN FOR j: NAT IN [0..i] DO --if a SETXY found, start again
NextToken[];
ENDLOOP;
ENDLOOP;
IF token.op=maskrectangle THEN RETURN [tempPos]; --found MaskRectangle
FOR i: NAT IN [0..8] DO --get to MASKFILL if there is one
NextToken[];
ENDLOOP;
IF token.op=maskfill THEN RETURN [tempPos]; --found MASKFILL;
SELECT IPMaster.GetToken[encoding: ip, start: start+2].token.op FROM --last resort: if there is a # setgray or # makegray directly following the MakeSampledBlack, then it is doing no imaging anyway
setgray, makegray => RETURN [start];
ENDCASE => RETURN;
};
frameNumber: ROPENIL; --the frame which holds the transparent sampled black
ignoreFSetAndGet: BOOLTRUE;
flushedTo, fSetPosition: INT ← 0;
IPScan.ScanRope[ip: ip, ops: LIST[makesampledblack, setsampledblack, fset, fget], action: PotentialCandidate];
newIP ← newIP.Concat[ip.Substr[flushedTo]];
};
ColorizeViewPointBackdoor.InstallNewColorization[colorization: OptimizeViewPointIP, setting: [key: "OptimizeInterpress", description: "For now: 1) converts most opaque SampledBlacks from ViewPoint and some from Gargoyle which are pure white or black to SetGrays. 2) For transparent SampledBlacks erases the associated rectangles (which Viewpoint puts in as text frames). More optimization later.", default: TRUE]];
END.