ColorizeViewPointDeInterleaveImpl.mesa
Copyright Ó 1989 by Xerox Corporation. All rights reserved.
Bob Coleman, February 16, 1990 2:56:40 pm PST
DIRECTORY
ColorizeViewPointBackdoor, IPScan, Rope;
ColorizeViewPointDeInterleaveImpl: CEDAR PROGRAM
IMPORTS ColorizeViewPointBackdoor, IPScan, Rope
~ BEGIN
ROPE: TYPE ~ Rope.ROPE;
DeInterleaveSamples: PUBLIC ColorizeViewPointBackdoor.Colorization ~ {
[ip: ROPE, palette: Profiles.Profile, checkSystemSetting: ColorizeViewPoint.CheckSystemSettingProc] RETURNS [newIP: ROPE]
InterleavedSamplesAction: 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)
xPixels, yPixels, samplesPerPixel: NAT;
startPA, totalPixels: INT;
IF ~(ip.Substr[max-2, 2].Equal["\241\302"]) --MAKEPIXELARRAY-- THEN ERROR; --System error
IF ip.Substr[min+8, 2].Equal["\017\240" --0=non-interleaved--] OR (samplesPerPixel ← ORD[ip.Fetch[min+4]]*256 + ORD[ip.Fetch[min+5]] - 4000)=1 --ie, bitmap-- THEN { --flush and leave
newIP ← newIP.Concat[ip.Substr[flushedTo, max-flushedTo]];
flushedTo ← max;
RETURN;
};
Gather more Pixel Array info:
xPixels ← ORD[ip.Fetch[min]]*256 + ORD[ip.Fetch[min+1]] - 4000;
yPixels ← ORD[ip.Fetch[min+2]]*256 + ORD[ip.Fetch[min+3]] - 4000;
totalPixels ← xPixels*yPixels;
FOR startPA ← min+10, startPA+1 WHILE startPA<=ip.Size DO
SELECT TRUE FROM
ip.Fetch[startPA]='\350 AND ip.Fetch[startPA+4]='\001 --header to Long sequenceLargeVector-- => { startPA ← startPA+5; EXIT };
ip.Fetch[startPA]='\310 AND ip.Fetch[startPA+2]='\001 --header to Short sequenceLargeVector-- => { startPA ← startPA+3; EXIT };
ENDCASE => NULL;
ENDLOOP;
At this point, startPA points to start of actual pixel array data
newIP ← newIP.Cat[ip.Substr[flushedTo, (min+8)-flushedTo], "\017\240" --change to non-interleaved samples--, ip.Substr[min+10, startPA-(min+10)]]; --flush through PA data
FOR i: NAT IN [0..samplesPerPixel) DO
tLen: NATMIN[totalPixels, NAT.LAST];
processedTo: INT ← startPA+i;
DO
scratchText: REF TEXTNEW[TEXT[tLen]];
scratchText.length ← tLen;
The following in brackets is simply a faster way to do this loop:
FOR j: NAT IN [0..tLEN) DO
scratchText[j] ← ip.Fetch[processedTo+(j*samplesPerPixel)];
ENDLOOP;
{
ipIndex: INT ← 0;
textIndex: NAT ← 0;
s1: NAT ~ samplesPerPixel;
s2: NAT ~ s1+s1; s3: NAT ~ s2+s1; s4: NAT ~ s3+s1;
s5: NAT ~ s4+s1; s6: NAT ~ s5+s1; s7: NAT ~ s6+s1;
s8: NAT ~ s7+s1;
THROUGH [0 .. tLen/8) DO
scratchText[textIndex] ← ip.Fetch[processedTo+ipIndex];
scratchText[textIndex+1] ← ip.Fetch[processedTo+ipIndex+s1];
scratchText[textIndex+2] ← ip.Fetch[processedTo+ipIndex+s2];
scratchText[textIndex+3] ← ip.Fetch[processedTo+ipIndex+s3];
scratchText[textIndex+4] ← ip.Fetch[processedTo+ipIndex+s4];
scratchText[textIndex+5] ← ip.Fetch[processedTo+ipIndex+s5];
scratchText[textIndex+6] ← ip.Fetch[processedTo+ipIndex+s6];
scratchText[textIndex+7] ← ip.Fetch[processedTo+ipIndex+s7];
textIndex ← textIndex+8;
ipIndex ← ipIndex+s8;
ENDLOOP;
FOR k: NAT IN [textIndex .. tLen) DO
scratchText[k] ← ip.Fetch[processedTo+ipIndex];
ipIndex ← ipIndex+s1;
ENDLOOP;
};
newIP ← newIP.Concat[Rope.FromRefText[scratchText]];
IF (processedTo ← processedTo+tLen)<totalPixels THEN tLen ← MIN[totalPixels-processedTo, NAT.LAST] ELSE EXIT;
ENDLOOP;
ENDLOOP;
flushedTo ← startPA+totalPixels*samplesPerPixel; --skip over previous PixelArray data
};
flushedTo: INT ← 0;
IPScan.ScanRope[ip: ip, ops: LIST[makepixelarray], action: InterleavedSamplesAction];
newIP ← newIP.Concat[ip.Substr[flushedTo]];
};
ColorizeViewPointBackdoor.InstallNewColorization[colorization: DeInterleaveSamples, setting: [key: "DeInterleave", description: "For now, gets rid of interleaved samples from Sweeps.", default: FALSE]];
END.