SampleArrayIconsImpl.mesa
Copyright © 1984 by Xerox Corporation. All rights reserved.
Created Thursday, August 2, 1984 9:41 pm PDT
Last edited by Eric Nickell, December 14, 1985 11:01:08 pm PST
DIRECTORY
SampleArrayIcons,
Icons USING [iconH, IconRef, IconRep, iconW, NewIcon],
SampleArrays USING [FromAIS, GetSample, SampleArray],
Real USING [FixC];
SampleArrayIconsImpl: CEDAR PROGRAM
IMPORTS Icons, SampleArrays, Real
EXPORTS SampleArrayIcons
= BEGIN
OPEN SampleArrayIcons;
iconH: INTEGER ~ Icons.iconH;
iconW: INTEGER ~ Icons.iconW;
NewIconFromFilename: PUBLIC PROC [file: ROPE] RETURNS [newFlavor: IconFlavor] ~ {
sa: SampleArrays.SampleArray ~ SampleArrays.FromAIS[name: file];
newFlavor ← NewIcon[sa];
};
NewIcon: PUBLIC PROC [sa: SampleArrays.SampleArray, layer: NAT ← 0] RETURNS [newFlavor: IconFlavor] ~ {
iconRef: Icons.IconRef ← NEW[Icons.IconRep];
bits: ARRAY [0 .. iconH) OF PACKED ARRAY [0 .. iconW) OF [0..1];
buffer: ARRAY [-1 .. iconW] OF INTEGERALL[0];
this, next, d, dr: INTEGER ← 0;
scale: REAL;
PAScan: PROC [iconScan: CARDINAL] RETURNS [aisScan: CARDINAL] ~ INLINE {
RETURN[Real.FixC[iconScan*scale]];
};
PAPixel: PROC [iconPixel: CARDINAL] RETURNS [aisPixel: CARDINAL] ~ INLINE {
RETURN[Real.FixC[iconPixel*scale]];
};
scale ← MIN[(sa.fSize)/(iconW - 1.0), (sa.sSize)/(iconH - 1.0)];
FOR scan: CARDINAL IN [0 .. iconH) DO
s: CARDINALMIN[sa.sSize-1, Real.FixC[scan*scale]];
FOR pixel: CARDINAL IN [0 .. iconW) DO
f: CARDINALMIN[sa.fSize-1, Real.FixC[pixel*scale]];
this ← SampleArrays.GetSample[sa: sa, i: layer, index: [s: s, f: f]] + buffer[pixel] + next;
IF this < 128
THEN bits[scan][pixel] ← 1
ELSE {bits[scan][pixel] ← 0; this ← this-255};
[buffer[pixel-1], d, dr, next] ← Propagate[this, d, dr];
ENDLOOP;
ENDLOOP;
FOR scan: CARDINAL IN [0 .. iconH) DO
bits[scan][0] ← bits[scan][1] ← bits[scan][iconW-2] ← bits[scan][iconW-1] ← 1;
ENDLOOP;
FOR pixel: CARDINAL IN [0 .. iconH) DO
bits[0][pixel] ← bits[1][pixel] ← bits[iconH-2][pixel] ← bits[iconH-1][pixel] ← 1;
ENDLOOP;
iconRef.bits ← LOOPHOLE[bits];
RETURN[Icons.NewIcon[iconRef]];
};
Propagate: PROC [this, oldd, olddr: INTEGER] RETURNS [dl, d, dr, next: INTEGER] ~ INLINE {
RETURN [
dl: ThreeParts[this]+oldd,
d: olddr + FiveParts[this],
dr: OnePart[this],
next: SevenParts[this]
]
};
UnsignedDivideBy16: PROC [INTEGER] RETURNS [INTEGER] ~ TRUSTED MACHINE CODE {
PO.zLIB, 16; PO.zDIV
};
SixteenthOf: PROC [i: INTEGER] RETURNS [INTEGER] ~ TRUSTED INLINE {
RETURN[UnsignedDivideBy16[i+1024]-1024/16];
};
SixteenthOf: PROC [i: INTEGER] RETURNS [INTEGER] ~ TRUSTED INLINE {RETURN[i/16]};
OnePart: PROC [i: INTEGER] RETURNS [INTEGER] ~ INLINE {RETURN[SixteenthOf[i]]};
ThreeParts: PROC [i: INTEGER] RETURNS [INTEGER] ~ INLINE {RETURN[SixteenthOf[(i*3)]]};
FiveParts: PROC [i: INTEGER] RETURNS [INTEGER] ~ INLINE {RETURN[SixteenthOf[(i*5)]]};
SevenParts: PROC [i: INTEGER] RETURNS [INTEGER] ~ INLINE {RETURN[SixteenthOf[(i*7)]]};
END.