ImagerPixelArray.mesa
Copyright © 1984, 1985, 1986 by Xerox Corporation. All rights reserved.
Michael Plass, August 1, 1984 9:59:33 am PDT
Doug Wyatt, March 3, 1986 3:09:37 pm PST
DIRECTORY
Atom USING [PropList],
ImagerSample USING [Function, maxVec, nullFunction, PixelBuffer, PixelMap, PixelProc, Sample, SampleMap, SampleBuffer, Vec, zeroVec],
ImagerTransformation USING [ScanMode, Transformation],
Rope USING [ROPE];
ImagerPixelArray: CEDAR DEFINITIONS
~ BEGIN
Transformation: TYPE ~ ImagerTransformation.Transformation;
ScanMode: TYPE ~ ImagerTransformation.ScanMode;
Sample: TYPE ~ ImagerSample.Sample;
SampleBuffer: TYPE ~ ImagerSample.SampleBuffer;
SampleMap: TYPE ~ ImagerSample.SampleMap;
PixelProc: TYPE ~ ImagerSample.PixelProc;
PixelBuffer: TYPE ~ ImagerSample.PixelBuffer;
PixelMap: TYPE ~ ImagerSample.PixelMap;
Vec: TYPE ~ ImagerSample.Vec;
zeroVec: Vec ~ ImagerSample.zeroVec;
maxVec: Vec ~ ImagerSample.maxVec;
Function: TYPE ~ ImagerSample.Function;
nullFunction: Function ~ ImagerSample.nullFunction;
ROPE: TYPE ~ Rope.ROPE;
maxCount: NAT ~ NAT.LAST;
Basic operations
PixelArray: TYPE ~ REF PixelArrayRep;
PixelArrayRep: TYPE ~ RECORD [
immutable: BOOL,
samplesPerPixel: NAT, -- number of samples for each pixel
sSize, fSize: INT, -- slow and fast dimensions (Interpress calls these xPixels, yPixels)
m: Transformation, -- transforms [s, f] coordinates to "upright" [x, y] coordinates
class: REF PixelArrayClassRep, -- class operations
data: REF, -- instance data
propList: Atom.PropList ← NIL
];
The pixel array contains sSize*fSize pixels, samplesPerPixel*sSize*fSize samples.
A sample is named by a triple: i IN[0..samplesPerPixel), s IN[0..sSize), f IN[0..fSize).
PixelArrayClassRep: TYPE; -- see ImagerPixelArrayPrivate
ErrorDesc: TYPE ~ RECORD [code: ATOM, explanation: ROPE];
Error: ERROR [error: ErrorDesc];
GetClass: PROC [self: PixelArray] RETURNS [ATOM];
... returns an ATOM that identifies the PixelArray's class.
MaxSampleValue: PROC [self: PixelArray, i: NAT] RETURNS [Sample];
... returns the maximum sample value for the ith sample.
For all i IN[0..self.samplesPerPixel), s IN[0..self.sSize), f IN[0..self.fSize):
self.Get[i, s, f] IN[0..self.MaxSampleValue[i]].
Get: PROC [self: PixelArray, i: NAT ← 0, s, f: INT] RETURNS [Sample];
... returns the sample value with indices [i, s, f].
! BoundsFault if i ~IN[0..self.samplesPerPixel) OR s ~IN[0..self.sSize) OR f ~IN[0..self.fSize).
GetSamples: PROC [self: PixelArray, i: NAT ← 0, s, f: INT ← 0,
samples: SampleBuffer, start: NAT ← 0, count: NAT ← maxCount];
... fetches a run of samples into a buffer. The effect is:
FOR k: NAT IN[0..MIN[samples.length-start, count]) DO
samples[start+k] ← self.Get[i, s, f+k]
ENDLOOP
! BoundsFault if any index into the pixel array is out of range
GetPixels: PROC [self: PixelArray, s, f: INT ← 0,
pixels: PixelBuffer, start: NAT ← 0, count: NAT ← maxCount];
... fetches a run of pixels into a buffer. The effect is:
FOR i: NAT IN[0..self.samplesPerPixel) DO
self.GetSamples[i, s, f, pixels[i], start, count]
ENDLOOP
! BoundsFault if any index into the pixel array is out of range
Transfer: PROC [self: PixelArray, i: NAT ← 0, s, f: INT ← 0,
dst: SampleMap, dstMin: Vec ← zeroVec, size: Vec ← maxVec,
function: Function ← nullFunction];
... like ImagerSample.Transfer, where the pixel array is the source.
! BoundsFault if any sample index is out of range
Creating pixel arrays
Copy: PROC [self: PixelArray] RETURNS [PixelArray];
... makes an immutable copy of a pixel array; returns self if self.immutable.
Extract: PROC [old: PixelArray, samplesPerPixel: NAT, select: PROC [NAT] RETURNS [NAT]]
RETURNS
[new: PixelArray];
... extracts selected sample layers from a pixel array.
new.samplesPerPixel = samplesPerPixel
new.sSize = old.sSize, new.fSize = old.fSize
ImagerTransformation.Equal[new.m, old.m]
new.MaxSampleValue[i] = old.MaxSampleValue[select[i]]
new.Get[i, s, f] = old.Get[select[i], s, f]
! BoundsFault if for any i IN[0..samplesPerPixel), select[i] ~IN[0..pa.samplesPerPixel).
Join: PROC [list: LIST OF PixelArray] RETURNS [PixelArray];
Join3: PROC [pa1, pa2, pa3: PixelArray] RETURNS [PixelArray];
... joins multiple sample planes into one PixelArray.
! Error[[$incompatibleJoin, ...]] if sizes or transformations do not match.
FromPixelMap: PROC [map: PixelMap, scanMode: ScanMode,
immutable: BOOLFALSE] RETURNS [PixelArray];
If immutable=TRUE, caller guarantees that the contents of the PixelMap will not change as long as the PixelArray is in use.
The ScanMode relates the (slow, fast) coords of the PixelMap to the client coords of the PixelArray.
FromAIS: PROC [name: ROPE] RETURNS [PixelArray];
... makes a pixel array from an AIS file with the specified name.
! FS.Error if the named file cannot be opened.
! Error[[$malformedAISFile, ...]] if the file is not a valid AIS file.
Join3AIS: PROC [name1, name2, name3: ROPE] RETURNS [PixelArray];
A convenience, equivalent to Join3[FromAIS[name1], FromAIS[name2], FromAIS[name3]].
! FS.Error or Error, as for FromAIS or Join.
END.