ImagerSample.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Doug Wyatt, May 28, 1985 11:47:19 am PDT
Michael Plass, June 3, 1985 11:11:41 am PDT
DIRECTORY
Basics USING [bitsPerWord, LongNumber, RawWords],
ImagerTransformation USING [Transformation],
PrincOps USING [SrcFunc, DstFunc]
;
ImagerSample: CEDAR DEFINITIONS
~ BEGIN
Transformation: TYPE ~ ImagerTransformation.Transformation;
Sample buffers
Sample: TYPE ~ WORD;
maxBitsPerSample: NAT ~ Basics.bitsPerWord;
RawSamples: TYPE ~ Basics.RawWords;
UnsafeSamples: TYPE ~ LONG POINTER TO RawSamples;
SampleBuffer: TYPE ~ REF SampleBufferRep;
SampleBufferRep: TYPE ~ RECORD [
iSize, jSize: NAT,
samples: SEQUENCE size: NAT OF Sample
];
NewBuffer: PROC [iSize, jSize: NAT, scratch: SampleBuffer ← NIL] RETURNS [SampleBuffer];
ObtainScratchBuffer: PROC [iSize, jSize: NAT] RETURNS [SampleBuffer];
ReleaseScratchBuffer: PROC [buffer: SampleBuffer];
DoWithScratchBuffer: PROC [iSize, jSize: NAT, action: PROC [SampleBuffer]];
GetSample: PROC [buffer: SampleBuffer, i, j: NAT] RETURNS [Sample];
PutSample: PROC [buffer: SampleBuffer, i, j: NAT, sample: Sample];
GetPointer: PROC [buffer: SampleBuffer, i, j, count: NAT] RETURNS [UnsafeSamples];
SampleBuffer operations
UnsafeAdd: UNSAFE PROC [src1, src2, dst: UnsafeSamples, count: NAT];
FOR k: NAT IN[0..count) DO dst[k] ← src1[k]+src2[k] ENDLOOP;
UnsafeSub: UNSAFE PROC [src1, src2, dst: UnsafeSamples, count: NAT];
FOR k: NAT IN[0..count) DO dst[k] ← src1[k]-src2[k] ENDLOOP;
UnsafeLookup: UNSAFE PROC [tbl, src, dst: UnsafeSamples, count: NAT];
FOR k: NAT IN[0..count) DO dst[k] ← tbl[src[k]] ENDLOOP;
AddSamples: PROC [samples: SampleBuffer, si, sj: NAT ← 0,
buffer: SampleBuffer, bi, bj: NAT ← 0, count: NAT];
FOR k: NAT IN[0..count) DO
buffer.PutSample[bi, bj+k, buffer.GetSample[bi, bj+k]+samples.GetSample[si, sj+k]]
ENDLOOP;
SubSamples: PROC [samples: SampleBuffer, si, sj: NAT ← 0,
buffer: SampleBuffer, bi, bj: NAT ← 0, count: NAT];
FOR k: NAT IN[0..count) DO
buffer.PutSample[bi, bj+k, buffer.GetSample[bi, bj+k]-samples.GetSample[si, sj+k]]
ENDLOOP;
LookupSamples: PROC [table: SampleBuffer, samples: SampleBuffer, si, sj: NAT ← 0,
buffer: SampleBuffer, bi, bj: NAT ← 0, count: NAT];
FOR k: NAT IN[0..count) DO
buffer.PutSample[bi, bj+k, table.GetSample[0, samples.GetSample[si, sj+k]]]
ENDLOOP;
LookupPixels: PROC [tables: SampleBuffer, pixels: SampleBuffer, pj: NAT ← 0,
buffer: SampleBuffer, bi, bj: NAT ← 0, count: NAT];
FOR k: NAT IN[0..count) DO
sum: Sample ← 0;
FOR i: NAT IN[0..tables.iSize) DO
sum ← sum+tables.GetSample[i, pixels.GetSample[i, pj+k]];
ENDLOOP;
buffer.PutSample[bi, bj+k, sum];
ENDLOOP;
Packing and unpacking
BitsPerSample: TYPE ~ [0..maxBitsPerSample];
UnsafeGetF: UNSAFE PROC [samples: UnsafeSamples, count: NAT, s, f: NAT ← 0,
base: LONG POINTER, wordsPerLine: NAT, bitsPerSample: BitsPerSample];
samples[k] ← array[s, f+k], for k IN[0..count)
UnsafePutF: UNSAFE PROC [samples: UnsafeSamples, count: NAT, s, f: NAT ← 0,
base: LONG POINTER, wordsPerLine: NAT, bitsPerSample: BitsPerSample, srcFunc: PrincOps.SrcFunc ← null, dstFunc: PrincOps.DstFunc ← null];
array[s, f+k] ← Func[array[s, f+k], samples[k]], for k IN[0..count)
UnsafePutFSign: UNSAFE PROC [samples: UnsafeSamples, count: NAT, s, f: NAT ← 0,
base: LONG POINTER, wordsPerLine: NAT];
bitArray[s, f+k] ← SignBit[samples[k]], for k IN[0..count). Useful for halftoning.
UnsafeGetS: UNSAFE PROC [samples: UnsafeSamples, count: NAT, s, f: NAT ← 0,
base: LONG POINTER, wordsPerLine: NAT, bitsPerSample: BitsPerSample];
samples[k] ← array[s+k, f], for k IN[0..count)
UnsafePutS: UNSAFE PROC [samples: UnsafeSamples, count: NAT, s, f: NAT ← 0,
base: LONG POINTER, wordsPerLine: NAT, bitsPerSample: BitsPerSample, srcFunc: PrincOps.SrcFunc ← null, dstFunc: PrincOps.DstFunc ← null];
array[s+k, f] ← Func[array[s+k, f], samples[k]], for k IN[0..count)
Sampling
Sampler: TYPE ~ REF SamplerRep;
SamplerRep: TYPE ~ RECORD [
base: LONG POINTERNIL, -- source base address
wordsPerLine: CARDINAL ← 0, -- source words per scan line
bitsPerSample: BitsPerSample ← 0, -- source bits per sample
sSize: CARDINAL ← 0, -- source size in slow (scan line) direction
fSize: CARDINAL ← 0, -- source size in fast (pixel) direction
sMin: CARDINAL ← 0, -- source origin in slow (scan line) direction
fMin: CARDINAL ← 0, -- source origin in fast (pixel) direction
sfDelta: Basics.LongNumber ← [lc[0]], -- source delta s for destination f increment
ffDelta: Basics.LongNumber ← [lc[0]], -- source delta f for destination f increment
ssDelta: Basics.LongNumber ← [lc[0]], -- source delta s for destination s increment
fsDelta: Basics.LongNumber ← [lc[0]], -- source delta f for destination s increment
sSource: Basics.LongNumber ← [lc[0]], -- initial source s (corresponding to sDest, fDest)
fSource: Basics.LongNumber ← [lc[0]], -- initial source f (corresponding to sDest, fDest)
sDest: CARDINAL ← 0, -- initial destination s
fDest: CARDINAL ← 0 -- initial destination f
];
SetSamplerIncrements: PROC [sampler: Sampler, m: Transformation];
Sets sfDelta, ffDelta, ssDelta, fsDelta.
SetSamplerPosition: PROC [sampler: Sampler, m: Transformation, s, f: CARDINAL];
Sets initial destination position.
GetPointSamples: PROC [sampler: Sampler, s, f: CARDINAL,
buffer: SampleBuffer, bi, bj: NAT ← 0, count: NAT];
buffer[bi, bj+k] ← <sample for destination>[s, f+k], for k IN[0..count)
GetInterpolatedSamples: PROC [sampler: Sampler, s, f: CARDINAL,
buffer: SampleBuffer, i, j: NAT ← 0, count: NAT];
Similar to GetPointSamples, but interpolates four surrounding samples to get result.
END.