<<>> <> <> <> <<>> 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--]]; <> 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: ROPE _ NIL; --the frame which holds the transparent sampled black ignoreFSetAndGet: BOOL _ TRUE; 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.