SampleArrays.mesa
Copyright © 1984, 1985 by Xerox Corporation. All rights reserved.
Michael Plass, August 1, 1984 9:59:33 am PDT
Doug Wyatt, May 19, 1985 2:49:54 pm PDT
Eric Nickell January 6, 1986 3:34:57 pm PST
DIRECTORY
SampleMapOps,
Rope USING [ROPE];
SampleArrays: CEDAR DEFINITIONS
IMPORTS SampleMapOps
~ BEGIN
Buffer: TYPE ~ SampleMapOps.Buffer;
CVEC: TYPE ~ SampleMapOps.CVEC;
Function: TYPE ~ SampleMapOps.Function;
SampleMap: TYPE ~ SampleMapOps.SampleMap;
ROPE: TYPE ~ Rope.ROPE;
maxCount: NAT ~ SampleMapOps.maxCount;
nullFunction: Function ~ SampleMapOps.nullFunction;
Basic operations
SampleArray: TYPE ~ REF SampleArrayRep;
SampleArrayRep: TYPE ~ RECORD [
sSize, fSize: NAT,
layer: SEQUENCE n: NAT OF SampleMapEntry
];
SampleMapEntry: TYPE ~ RECORD [
sm: SampleMap ← NIL,
class: ATOMNIL,
data: REFNIL
];
The sample array contains sSize*fSize pixels, samplesPerPixel*sSize*fSize samples.
A sample is named by a triple: i IN[0..samplesPerSample), s IN[0..sSize), f IN[0..fSize).
Sample: TYPE ~ CARDINAL;
ErrorDesc: TYPE ~ RECORD [code: ATOM, explanation: ROPE];
Error: ERROR [error: ErrorDesc];
MaxSampleValue: PROC [sa: SampleArray, i: NAT] RETURNS [Sample];
... returns the maximum sample value for the ith sample.
For all i IN[0..sa.samplesPerSample), s IN[0..sa.sSize), f IN[0..sa.fSize):
sa.GetSample[i, s, f] IN[0..sa.MaxSampleValue[i]].
GetSample: PROC [sa: SampleArray, i: NAT, index: CVEC] RETURNS [Sample] ~ INLINE {
RETURN [SampleMapOps.GetSample[sampleMap: sa.layer[i].sm, index: index]];
};
... returns the sample value with indices [i, s, f].
! BoundsFault if i ~IN[0..sa.samplesPerSample) OR s ~IN[0..sa.sSize) OR f ~IN[0..sa.fSize).
PutSample: PROC [sa: SampleArray, i: NAT, index: CVEC, value: Sample, function: Function ← nullFunction] ~ INLINE {
SampleMapOps.PutSample[sampleMap: sa.layer[i].sm, index: index, value: value, function: function];
};
... returns the sample value with indices [i, s, f].
! BoundsFault if i ~IN[0..sa.samplesPerSample) OR s ~IN[0..sa.sSize) OR f ~IN[0..sa.fSize).
GetSamples: PROC [buffer: Buffer, start: NAT ← 0, count: NAT ← maxCount,
sa: SampleArray, i: NAT, s, f: NAT ← 0, ds: NAT ← 0, df: NAT ← 1];
InlineGetSamples: PROC [buffer: Buffer, start: NAT ← 0, count: NAT ← maxCount,
sa: SampleArray, i: NAT, s, f: NAT ← 0, ds: NAT ← 0, df: NAT ← 1] ~ INLINE {
SampleMapOps.Get[buffer: buffer, start: start, count: count, sampleMap: sa.layer[i].sm, s: s, f: f, ds: ds, df: df];
};
! BoundsFault if any index into sa is out of range
PutSamples: PROC [buffer: Buffer, start: NAT ← 0, count: NAT ← maxCount,
sa: SampleArray, i: NAT, s, f: NAT ← 0, ds: NAT ← 0, df: NAT ← 1, function: Function ← nullFunction];
InlinePutSamples: PROC [buffer: Buffer, start: NAT ← 0, count: NAT ← maxCount,
sa: SampleArray, i: NAT, s, f: NAT ← 0, ds: NAT ← 0, df: NAT ← 1, function: Function ← nullFunction] ~ INLINE {
SampleMapOps.Put[buffer: buffer, start: start, count: count, sampleMap: sa.layer[i].sm, s: s, f: f, ds: ds, df: df, function: function];
};
! BoundsFault if any index into sa is out of range
Save: PROC [sa: SampleArray];
Saves the sample array out to disk. The actual operation performed depends on the class.
Creating sample arrays
Extract: PROC [old: SampleArray, samplesPerSample: NAT, select: PROC [NAT] RETURNS [NAT]]
RETURNS
[new: SampleArray];
... extracts selected sample layers from a pixel array.
new.samplesPerSample = samplesPerSample
new.sSize = old.sSize, new.fSize = old.fSize
new.MaxSampleValue[i] = old.MaxSampleValue[select[i]]
new.GetSample[i, s, f] = old.GetSample[select[i], s, f]
! BoundsFault if for any i IN[0..samplesPerSample), select[i] ~IN[0..sa.samplesPerSample).
Join: PROC [list: LIST OF SampleArray] RETURNS [SampleArray];
JoinMaps: PROC [list: LIST OF SampleMapEntry] RETURNS [SampleArray];
Join3: PROC [sa1, sa2, sa3: SampleArray] RETURNS [SampleArray];
Join3Maps: PROC [sm1, sm2, sm3: SampleMapEntry] RETURNS [SampleArray];
... joins multiple sample planes into one SampleArray.
! Error[[$incompatibleJoin, ...]] if sizes do not match.
FromAIS: PROC [name: ROPE] RETURNS [SampleArray];
... 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.
MapFromAIS: PROC [name: ROPE] RETURNS [SampleMapEntry];
... 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.
CreateAISFromMap: PROC [sm: SampleMap, name: ROPE];
Puts the sample map out to an AIS file.
Join3AIS: PROC [name1, name2, name3: ROPE] RETURNS [SampleArray];
A convenience, equivalent to Join3[FromAIS[name1], FromAIS[name2], FromAIS[name3]].
! FS.Error or Error, as for FromAIS or Join.
Other operations
FileNameRoot: PROC [sa: SampleArray] RETURNS [root: ROPE];
Returns the common part of the file name.
BackingFileOf: PROC [sme: SampleMapEntry] RETURNS [backingFileName: ROPE];
Note that not all classes are guaranteed to have backing files.
END.