<<>> <> <> <> <> DIRECTORY Basics USING [bitsPerWord, RawWords, UnsafeBlock], RasterBasics USING [BitAddress, DstFunc, SrcFunc], Scaled USING [Value], SF USING [Box, BoxAction, BoxGenerator, maxVec, minVec, Vec, zeroVec]; ImagerSample: CEDAR DEFINITIONS ~ BEGIN Vec: TYPE ~ SF.Vec; minVec: Vec ~ SF.minVec; zeroVec: Vec ~ SF.zeroVec; maxVec: Vec ~ SF.maxVec; Box: TYPE ~ SF.Box; maxBox: Box ~ [min: minVec, max: maxVec]; BoxAction: TYPE ~ SF.BoxAction; BoxGenerator: TYPE ~ SF.BoxGenerator; maxCount: NAT ~ NAT.LAST; MultipleReleaseOfScratch: ERROR; <> Sample: TYPE ~ WORD; maxSample: Sample ~ Sample.LAST; RawSamples: TYPE ~ Basics.RawWords; maxBitsPerSample: NAT ~ Basics.bitsPerWord; BitsPerSample: TYPE ~ NAT[0..maxBitsPerSample]; SampleBuffer: TYPE ~ REF SampleBufferRep; SampleBufferRep: TYPE ~ RECORD [ length: NAT, samples: SEQUENCE maxLength: NAT OF Sample ]; BitAddress: TYPE ~ RasterBasics.BitAddress; NewSamples: PROC [length: NAT, scratch: SampleBuffer ¬ NIL] RETURNS [SampleBuffer]; ObtainScratchSamples: PROC [length: NAT] RETURNS [SampleBuffer]; <<>> ReleaseScratchSamples: PROC [buffer: SampleBuffer]; DoWithScratchSamples: PROC [length: NAT, action: PROC [SampleBuffer]]; PointerToSamples: PROC [buffer: SampleBuffer, start, count: NAT] RETURNS [LONG POINTER TO RawSamples]; FlipSamples: PROC [buffer: SampleBuffer, start: NAT ¬ 0, count: NAT ¬ maxCount]; <> FillSamples: PROC [buffer: SampleBuffer, value: Sample, start: NAT ¬ 0, count: NAT ¬ maxCount]; CopySamples: PROC [dst, src: SampleBuffer, dstStart, srcStart: NAT ¬ 0, count: NAT ¬ maxCount]; ClearSamples: PROC [buffer: SampleBuffer, start: NAT ¬ 0, count: NAT ¬ maxCount]; <> SampleMap: TYPE ~ REF SampleMapRep; SampleMapRep: TYPE ~ PRIVATE RECORD [ <<-- It is UNSAFE to alter these fields. -->> box: Box, -- lower and upper bounds in each direction immutable: BOOL, bitsPerSample: [0..BITS[Sample]], -- number of bits per sample v: SELECT tag: * FROM raster => [ bitsPerLine: CARD, -- bits per scan line base: BitAddress, -- starting bit address ref: REF -- for retaining the underlying storage ], object => [class: SampleMapClass, data: REF], ENDCASE ]; <> SampleMapClass: TYPE ~ REF SampleMapClassRep; SampleMapClassRep: TYPE; -- Opaque to allow more flexibility ObjectGetProc: TYPE ~ PROC [self: ObjectSampleMap, initIndex: SF.Vec, buffer: SampleBuffer, start, count: NAT]; ObjectPutProc: TYPE ~ PROC [self: ObjectSampleMap, initIndex: SF.Vec, buffer: SampleBuffer, start, count: NAT, function: Function]; RasterSampleMap: TYPE ~ REF SampleMapRep.raster; ObjectSampleMap: TYPE ~ REF SampleMapRep.object; UnsafeNewSampleMap: UNSAFE PROC [box: Box, bitsPerSample: BitsPerSample, bitsPerLine: INT, base: BitAddress, ref: REF, words: INT, scratchDescriptor: SampleMap ¬ NIL] RETURNS [RasterSampleMap]; <> BitsForSamples: PROC [fSize: NAT, bitsPerSample: NAT] RETURNS [INT]; <> WordsForLines: PROC [sSize: NAT, bitsPerLine: INT] RETURNS [INT]; <> WordsForMap: PROC [size: Vec, bitsPerSample: BitsPerSample ¬ 1, bitsPerLine: INT ¬ 0] RETURNS [INT]; <> <> <<>> NewSampleMap: PROC [box: Box, bitsPerSample: BitsPerSample ¬ 1, bitsPerLine: INT ¬ 0] RETURNS [RasterSampleMap]; <> <> NewObjectSampleMap: PROC [box: Box, bitsPerSample: BitsPerSample, getSamples: ObjectGetProc, putSamples: ObjectPutProc, data: REF] RETURNS [ObjectSampleMap]; <> Copy: PROC [map: SampleMap, delta: Vec ¬ zeroVec, box: Box ¬ maxBox] RETURNS [RasterSampleMap]; <> <> <> ObtainScratchMap: PROC [box: Box, bitsPerSample: BitsPerSample ¬ 1, bitsPerLine: INT ¬ 0] RETURNS [RasterSampleMap]; ReleaseScratchMap: PROC [map: SampleMap]; DoWithScratchMap: PROC [box: Box, bitsPerSample: BitsPerSample ¬ 1, action: PROC [RasterSampleMap]]; <> ObtainUnsafeDescriptor: UNSAFE PROC [size: Vec, bitsPerSample: BitsPerSample, bitsPerLine: INT, base: BitAddress, ref: REF, words: INT, rawMin, delta: Vec ¬ zeroVec] RETURNS [RasterSampleMap]; <> <> <> <> <> ReIndex: PROC [map: SampleMap, delta: Vec ¬ zeroVec, box: Box ¬ maxBox] RETURNS [SampleMap]; <> <> <> <> Clip: PROC [map: SampleMap, box: Box ¬ maxBox] RETURNS [SampleMap]; <> Shift: PROC [map: SampleMap, delta: Vec ¬ zeroVec] RETURNS [SampleMap]; <> ZeroOrigin: PROC [map: SampleMap] RETURNS [SampleMap]; <> ReleaseDescriptor: UNSAFE PROC [map: SampleMap]; <> <> <> GetBox: PROC [map: SampleMap] RETURNS [Box] ~ INLINE {RETURN [map.box]}; GetSize: PROC [map: SampleMap] RETURNS [Vec] ~ INLINE {b: Box ~ map.box; RETURN [[s: b.max.s-b.min.s, f: b.max.f-b.min.f]]}; GetImmutable: PROC [map: SampleMap] RETURNS [BOOL] ~ INLINE {RETURN [map.immutable]}; MakeImmutable: PROC [map: SampleMap] ~ INLINE {map.immutable ¬ TRUE}; GetBitsPerSample: PROC [map: SampleMap] RETURNS [BitsPerSample] ~ INLINE {RETURN [map.bitsPerSample]}; GetBitsPerLine: PROC [map: RasterSampleMap] RETURNS [INT] ~ INLINE {RETURN [map.bitsPerLine]}; GetBase: PROC [map: RasterSampleMap] RETURNS [BitAddress] ~ INLINE {RETURN [map.base]}; GetUnsafeBlock: PROC [map: RasterSampleMap] RETURNS [Basics.UnsafeBlock]; <> <> GetRef: PROC [map: RasterSampleMap] RETURNS [REF] ~ INLINE {RETURN [map.ref]}; GetData: PROC [map: ObjectSampleMap] RETURNS [REF] ~ INLINE {RETURN [map.data]}; <> SrcFunc: TYPE ~ RasterBasics.SrcFunc; DstFunc: TYPE ~ RasterBasics.DstFunc; Function: TYPE ~ MACHINE DEPENDENT RECORD [dstFunc: DstFunc, srcFunc: SrcFunc]; nullFunction: Function ~ [dstFunc: null, srcFunc: null]; <<[null, null] dst _ src>> <<[or, null] dst _ BITOR[dst, src]>> <<[and, null] dst _ BITAND[dst, src]>> <<[and, complement] dst _ BITAND[dst, BITNOT[src]]>> <<[xor, null] dst _ BITXOR[dst, src]>> <> <<>> ApplyFunction: PROC [function: Function, dstVal, srcVal: Sample] RETURNS [Sample]; <> Get: PROC [map: SampleMap, index: Vec] RETURNS [Sample]; <> <> Put: PROC [map: SampleMap, index: Vec, value: Sample, function: Function ¬ nullFunction]; <> <> GetSamples: PROC [map: SampleMap, initIndex: Vec ¬ zeroVec, delta: Vec ¬ [s: 0, f: 1], buffer: SampleBuffer, start: NAT ¬ 0, count: NAT ¬ maxCount]; <> <> <> <> <> <> GetTileSamples: PROC [tile: SampleMap, phase: NAT ¬ 0, initIndex: SF.Vec ¬ zeroVec, buffer: SampleBuffer]; <> <> <> <> Halftone: PROC [map: SampleMap, min: SF.Vec, sampleBuffer, thresholdBuffer: SampleBuffer, function: Function]; <> < thresholdBuffer[j] THEN 0 ELSE 1;>> <> <> PutSamples: PROC [map: SampleMap, initIndex: Vec ¬ zeroVec, delta: Vec ¬ [s: 0, f: 1], buffer: SampleBuffer, start: NAT ¬ 0, count: NAT ¬ maxCount, function: Function ¬ nullFunction]; <> <> <> <> <> <> <> Clear: PROC [map: SampleMap]; <> <> <> <<>> BasicTransfer: PROC [dst: SampleMap, src: SampleMap, dstMin: Vec ¬ zeroVec, srcMin: Vec ¬ zeroVec, size: Vec, function: Function ¬ nullFunction]; <> <> <> <> <> <> <> <> <> <<>> Transfer: PROC [dst: SampleMap, src: SampleMap, delta: Vec ¬ zeroVec, function: Function ¬ nullFunction]; <> <> <> Move: PROC [map: SampleMap, dstMin: Vec ¬ zeroVec, srcMin: Vec ¬ zeroVec, size: Vec ¬ maxVec, function: Function ¬ nullFunction]; <> <> <<(avoids ripple if the source and destination overlap)>> Fill: PROC [map: SampleMap, box: Box ¬ maxBox, value: Sample ¬ maxSample, function: Function ¬ nullFunction]; <> <> <> <> <> <> <> <> RawDescriptor: TYPE ~ RECORD [box: Box, bitsPerLine: NAT, basePointer: LONG POINTER, ref: REF]; <> RawListTransfer: PROC [dst: RasterSampleMap, src: LIST OF RawDescriptor, function: Function ¬ nullFunction]; <> TileFromStipple: PROC [stipple: WORD, bitsPerSample: BitsPerSample ¬ 1, value0: Sample ¬ 0, value1: Sample ¬ maxSample, scratch: SampleMap ¬ NIL] RETURNS [SampleMap]; <> Tile: PROC [map: SampleMap, box: Box ¬ maxBox, tile: SampleMap, phase: NAT ¬ 0, function: Function ¬ nullFunction]; <> <> <> <> <> <> <> <> <> <> <> <> <> <> TileBoxes: PROC [map: SampleMap, boxes: BoxGenerator, tile: SampleMap, phase: NAT ¬ 0, function: Function ¬ nullFunction]; <> <> <> <> <<};>> <> <<>> <> TransferBoxes: PROC [dst: SampleMap, src: SampleMap, delta: Vec ¬ zeroVec, boxes: BoxGenerator, function: Function ¬ nullFunction]; <> <> <> <<};>> <> <> FillBoxes: PROC [map: SampleMap, boxes: BoxGenerator, value: Sample ¬ maxSample, function: Function ¬ nullFunction]; <> <> <> <> <<};>> <> EdgeAction: TYPE ~ PROC [ which: [0..1], -- Which side this specifies sMin: INTEGER, -- First scan line touched sCount: NAT, -- Number of scan lines touched f0: Scaled.Value, -- Initial value of f, offset by 1/2 pixel df: Scaled.Value -- df/ds ]; RegionFill: PROC [dst: RasterSampleMap, edgeGenerator: PROC [EdgeAction], value: Sample ¬ maxSample, function: Function ¬ nullFunction]; <> <<>> BoxesFromBitmap: PROC [map: SampleMap, boxAction: BoxAction]; <> <<>> <> Trim: PROC [map: SampleMap, box: Box ¬ maxBox, background: Sample ¬ 0] RETURNS [Box]; <> <> IsAll: PROC [map: SampleMap, box: Box ¬ maxBox, value: Sample ¬ 0] RETURNS [BOOL]; <> <<>> Equal: PROC [s1, s2: SampleMap] RETURNS [BOOL]; <> <<>> END.