DIRECTORY Basics USING [bitsPerWord], SampleMapOps; SlowSampleMapOps: CEDAR DEFINITIONS ~ BEGIN SampleMap: TYPE ~ SampleMapOps.SampleMap; SubMap: TYPE ~ SampleMapOps.SubMap; bitsPerWord: NAT ~ Basics.bitsPerWord; CVEC: TYPE ~ SampleMapOps.CVEC; zeroCVEC: CVEC ~ [0, 0]; lastCVEC: CVEC ~ [CARDINAL.LAST, CARDINAL.LAST]; Function: TYPE ~ SampleMapOps.Function; nullFunction: Function ~ SampleMapOps.nullFunction; Create: PROC [sSize: CARDINAL, fSize: CARDINAL, bitsPerSample: [0..Basics.bitsPerWord]] RETURNS [s: SampleMap]; CreateZ: PROC [sSize: CARDINAL, fSize: CARDINAL, bitsPerSample: [0..Basics.bitsPerWord]] RETURNS [s: SampleMap]; Copy: PROC [subMap: SubMap] RETURNS [SampleMap]; DoubleCopy: PROC [to, slowTo, from: SampleMap, destStart: CVEC]; GetSample: PROC [sampleMap: SampleMap, index: CVEC] RETURNS [CARDINAL]; PutSample: PROC [sampleMap: SampleMap, index: CVEC, value: CARDINAL, function: Function _ nullFunction, goodDest: SampleMap]; Transfer: PROC [dest: SampleMap, destStart: CVEC _ zeroCVEC, source: SubMap, function: Function _ nullFunction, goodDest: SampleMap]; Move: PROC [sampleMap: SampleMap, destStart: CVEC _ zeroCVEC, sourceStart: CVEC _ zeroCVEC, size: CVEC _ lastCVEC, function: Function _ nullFunction, goodDest: SampleMap]; Fill: PROC [dest: SubMap, value: CARDINAL, function: Function _ nullFunction, goodDest: SubMap]; TileBox: PROC [dest: SampleMap, start: CVEC, size: CVEC, source: SampleMap, s0, f0: INTEGER, phase: NAT, function: Function _ nullFunction, goodDest: SampleMap]; Buffer: TYPE ~ SampleMapOps.Buffer; maxCount: NAT ~ LAST[NAT]; Get: PROC [buffer: Buffer, start: NAT _ 0, count: NAT _ maxCount, sampleMap: SampleMap, s, f: NAT _ 0, ds: NAT _ 0, df: NAT _ 1]; Put: PROC [buffer: Buffer, start: NAT _ 0, count: NAT _ maxCount, sampleMap: SampleMap, s, f: NAT _ 0, ds: NAT _ 0, df: NAT _ 1, function: Function _ nullFunction, goodDest: SampleMap]; END. pSlowSampleMapOps.mesa Copyright c 1985 by Xerox Corporation. All rights reserved. Michael Plass, December 4, 1985 11:31:32 am PST Willie-Sue, August 18, 1986 6:02:20 pm PDT Provides a safe set of operations on two-dimensional arrays of small unsigned integers. This interface provides most of the functionality of BitBlt, without the attendant risk of smashing the world. To avoid confusion no matter how the represented image is oriented, terms like height and width are avoided, and the coordinates are expressed in terms of s and f, for slow and fast. On a display, the s axis is normally vertical, and points down, but on a printer that scans in the long direction, the f axis will point up. Some of the operations in this interface are documented by code fragments; note that in case of unsuccessful completion (due to bounds fault, for instance), the set of samples moved by the implementation may differ from that implied by the documentation. Operations creates a SampleMap with no zero entries creates a SampleMap with all zero entries Stores modified value into the SampleMap at indexed location, dropping extra high-order bits. Bounds fault if index is out of range. size _ MIN[source.size, Size[dest]-destStart, Size[source.sampleMap]-source.start]; FOR s: CARDINAL IN [0..size.s) DO FOR f: NAT IN [0..size.f) DO sample: CARDINAL ~ GetSample[source.sampleMap, [source.start.s+s, source.start.f+f]]; PutSample[dest, [destStart.s+s, destStart.f+f], sample, function]; ENDLOOP; ENDLOOP; Transfers a rectangular region of the sampleMap, ordering it so ripple does not occur even if the rectangles overlap. Tiles the rectangle designated by (start, size) with the tile designated by (source, s0, f0, phase). start, size, s0, and f0 all work in the dest coordinate system. The DIV and MOD functions in the following take the sign of the remainder equal to the sign of the divisor, rather than of the dividend as is usual. FOR s: NAT IN [start.s..start.s+size.s) DO FOR f: NAT IN [start.f..start.f+size.f) DO sSource: CARDINAL ~ (s-s0) MOD source.sSize; fSource: CARDINAL ~ (f-f0 - ((s-s0)/source.sSize)*phase) MOD source.fSize; sample: CARDINAL ~ GetSample[source, [sSource, fSource]]; PutSample[dest, [s, f], sample, function]; ENDLOOP; ENDLOOP; Sample Buffers When performing operations on many contiguous samples, it is usually a good idea to unpack them into a one-word-per-sample buffer, work on them, and pack them up again into the output. This works well because whole-word access is typically much faster than partial word access (although byte access is not too bad). The following operations will help to do this kind of processing. FOR j: NAT IN [0..MIN[count, NAT[buffer.length-start]]) DO buffer[start+j] _ GetSample[sampleMap, [s+j*ds, f+j*df]]; ENDLOOP; FOR j: NAT IN [0..MIN[count, NAT[buffer.length-start]]) DO PutSample[sampleMap, [s+j*ds, f+j*df], buffer[start+j], function]; ENDLOOP; Ê-˜™Icodešœ Ïmœ1™˜¹š žœžœžœžœžœž™:KšœB™BKšžœ™—K˜——Kšžœ˜—…—„!