ImagerPixelArrayImpl.mesa
Copyright © 1984, Xerox Corporation. All rights reserved.
Doug Wyatt, November 5, 1984 3:09:07 pm PST
DIRECTORY
ImagerPixelArray,
RuntimeError USING [BoundsFault];
ImagerPixelArrayImpl: CEDAR PROGRAM
IMPORTS RuntimeError
EXPORTS ImagerPixelArray
~ BEGIN OPEN ImagerPixelArray;
MaxSampleValue: PUBLIC PROC[pa: PixelArray, i: NAT] RETURNS[Val] ~ {
RETURN pa.class.MaxSampleValue[pa, i];
};
GetSample: PUBLIC PROC[pa: PixelArray, s, f, i: NAT] RETURNS[Val] ~ {
RETURN pa.class.GetSample[pa, s, f, i];
};
GetRow: PUBLIC PROC[pa: PixelArray, row: Row, s, f, i: NAT] ~ {
pa.class.GetRow[pa, row, s, f, i];
};
EqTransformations: PROC[m, n: Transformation] RETURNS[BOOL] ~ {
RETURN[m.a=n.a AND m.b=n.b AND m.c=n.c AND m.d=n.d AND m.e=n.e AND m.f=n.f];
};
JoinPixelArrays: PUBLIC PROC[pixelArrays: LIST OF PixelArray] RETURNS[PixelArray] ~ {
sSize, fSize, samplesPerPixel: NAT ← 0;
m: Transformation ← NIL;
first: BOOLTRUE;
FOR each: LIST OF PixelArray ← pixelArrays, each.rest UNTIL each=NIL DO
pa: PixelArray ~ each.first;
IF first THEN { sSize ← pa.sSize; fSize ← pa.fSize; m ← pa.m; first ← FALSE }
ELSE IF pa.sSize=sSize AND pa.fSize=fSize AND EqTransformations[pa.m, m] THEN NULL
ELSE ERROR; -- incompatible
samplesPerPixel ← samplesPerPixel+pa.samplesPerPixel;
ENDLOOP;
RETURN[NEW[PixelArrayRep ← [class: joinedClass, data: pixelArrays,
sSize: sSize, fSize: fSize, samplesPerPixel: samplesPerPixel, m: m]]];
};
joinedClass: Class ~ NEW[ClassRep ← [
type: $Joined,
MaxSampleValue: JoinedMaxSampleValue,
GetSample: JoinedGetSample,
GetRow: JoinedGetRow
]];
JoinedMaxSampleValue: PROC[pa: PixelArray, i: NAT] RETURNS[Val] ~ {
list: LIST OF PixelArray ~ NARROW[pa.data];
IF i IN[0..pa.samplesPerPixel) THEN {
k: NAT ← i;
FOR each: LIST OF PixelArray ← list, each.rest UNTIL each=NIL DO
slice: PixelArray ~ each.first;
IF k<slice.samplesPerPixel THEN RETURN[MaxSampleValue[slice, k]]
ELSE k ← k-slice.samplesPerPixel;
ENDLOOP;
ERROR;
}
ELSE ERROR RuntimeError.BoundsFault;
};
JoinedGetSample: PROC[pa: PixelArray, s, f, i: NAT ← 0] RETURNS[Val] ~ {
list: LIST OF PixelArray ~ NARROW[pa.data];
IF s IN[0..pa.sSize) AND f IN[0..pa.fSize) AND i IN[0..pa.samplesPerPixel) THEN {
k: NAT ← i;
FOR each: LIST OF PixelArray ← list, each.rest UNTIL each=NIL DO
slice: PixelArray ~ each.first;
IF k<slice.samplesPerPixel THEN RETURN[GetSample[slice, s, f, k]]
ELSE k ← k-slice.samplesPerPixel;
ENDLOOP;
ERROR;
}
ELSE ERROR RuntimeError.BoundsFault;
};
JoinedGetRow: PROC[pa: PixelArray, row: Row, s, f, i: NAT ← 0] ~ {
list: LIST OF PixelArray ~ NARROW[pa.data];
IF s IN[0..pa.sSize) AND f IN[0..pa.fSize) AND i IN[0..pa.samplesPerPixel) THEN {
k: NAT ← i;
FOR each: LIST OF PixelArray ← list, each.rest UNTIL each=NIL DO
slice: PixelArray ~ each.first;
IF k<slice.samplesPerPixel THEN { GetRow[slice, row, s, f, k]; RETURN }
ELSE k ← k-slice.samplesPerPixel;
ENDLOOP;
ERROR;
}
ELSE ERROR RuntimeError.BoundsFault;
};
END.