<> <> <> 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: BOOL _ TRUE; 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