ImagerFunctionDevice.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Last edited by: Mik Lamming - November 18, 1985 10:57:24 am PST
An imager device that enables simple image processing functions to be focussed upon irregularly shaped sections of a pixelmap. The target areas are defined using Imager.Mask operations. Useful for clients who want to experiment with alpha-channels.
For each mask operation invoked through the imager interface this device applies a client supplied function to each affected pixel in the deviceMap. To mimic a conventional imager device a client function would copy appropriate pixels from the current constantColor or sampledColor into the deviceMap. More interesting behaviours may be produce if the client function uses both source pixels, e.g. the current color, and destination pixels, e.g. the deviceMap to compute the final value of the deviceMap.
Because the characteristics of the deviceMap are not fixed the device cannot understand how regular colors (e.g. colors that might be generated by ImagerColor) are to be transformed into a form that can be processed by the client function. Neither can it understand the regular color operators (available through ImagerColorOperator) that are used to specify sampled colors. To alleviate these problems the device assumes that all colors submitted to it are in a device dependent form - see MakeConstantColor. When using Imager.SetSampledColor the ColorOperator parameter will be ignored and the pixel array data will be passed to the client function unmodified.
DIRECTORY
Imager USING [Context],
ImagerColorDefs USING [ConstantColor],
ImagerDevice USING[Device],
ImagerPixelMap USING [PixelMap],
ImagerSample USING [SampleBuffer],
ImagerTransformation USING [Transformation];
ImagerFunctionDevice: CEDAR DEFINITIONS
~ BEGIN OPEN Imager, ImagerPixelMap, ImagerTransformation;
SampleBuffer: TYPE ~ ImagerSample.SampleBuffer;
ClientFunc: TYPE = PROC [fMin, fSize: NAT, colorSamples, deviceSamples: SampleBuffer] ;
Create: PROC [
samplesPerPixel:NAT,   -- colorToSampleProc will generate this many 16 bit samples per pixel
devicePms: LIST OF PixelMap, -- where this device stores the image
deviceToPixel: Transformation ← NIL, -- transformation from device space
initialScale: REAL ← 1.0,  -- 1 unit = 1 pixel
clientFunc: ClientFunc ← NIL-- devicePms ← clientFunc(devicePms, color)
]
RETURNS [Context];
Creates a context that will operate upon the list of pixelmaps. For each imager "mask" operation the clientFunc is called to combine (in whatever fashion it wants) the current color with the device pixelmaps.
Use LikeScreen to generate a surfaceToPixel of the most commonly wanted kind.
CreateFromDevice: PROC [
device: ImagerDevice.Device,
initialScale: REAL ← 1.0  -- 1 unit = 1 pixel
]
RETURNS [Context];
DeviceFromPixelMap: PROC [
samplesPerPixel:NAT,
pms: LIST OF PixelMap,
deviceToPixel: Transformation,
clientFunc: ClientFunc
] RETURNS [ImagerDevice.Device] ;
-- As above but only creates a device - useful for ambushes!
LikeScreen: PROC [sSize: NAT] RETURNS [Transformation];
Convenience for making a surfaceToPixel transformation in the favored screen orientation.
MakeConstantColor: PROC [sample: SampleBuffer]
RETURNS [color: ImagerColorDefs.ConstantColor] ;
MakePMS: PROC [n, sSize, fSize:NAT] RETURNS [LIST OF PixelMap] ;
Convenience for making n similar sized pixel maps
END.