PDInterpBitmap.mesa
Michael Plass, November 9, 1983 10:39 am
Basic operations on two-dimensional arrays of pixels.
DIRECTORY BitBlt, Inline;
PDInterpBitmap: DEFINITIONS IMPORTS Inline = BEGIN
This interface provides most of the functionality of BitBlt. To avoid confusion no matter how the map is physically laid out, terms like height and width are avoided, and the coordinates are expressed in terms of s and f, for slow and fast. On a display, the s axis is normally vertical, and points down, but on a printer that scans in the long direction, the f axis will point up. The diagram below takes the latter point of view.
--   ^
--f |
--   |
--   |    +----------------------------+
--   |    |        |
--   |    |rast * bitsPerWord / bitsPerPixel  |
--   |    |        |
--   |    |   +------------+  |
--   |    |   |    |  |
--   |    |   |    |  |
--   |    |   |fSize   |  |
--   |    |   |    |  |
--   |    | sMin  |  sSize  |  |
--   |    |<-- -->+------------+  |
--   |    |   ^      |
--   |    |   |fMin     |
--   | sOrigin  |   v   lines  |
--   |<---- ---->+----------------------------+
--   |    ^origin of buffer
--   |    |
--   |    |fOrigin
--   |    |
--   |    |
--   |    v
--   +-------------------------------------------->
-- Device space origin       s
A BitmapDesc describes a window into a buffer, and the buffer itself may be positioned anywhere in a global device space. The windowing information is stored in the BitmapDesc record, so that it may be easily changed to accomplish translation and clipping by rectangles. The translation feature may be used for destination maps to conveniently implement band buffers.
BitmapDesc: TYPE = RECORD [
These parameters define a window within the buffer, as well as where the buffer is positioned in device space.
sOrigin, fOrigin: INTEGER ← 0,
sMin, fMin: INTEGER ← 0,
sSize, fSize: NAT ← 0,
pointer: LONG POINTERNIL,
rast, lines: CARDINAL ← 0
Stored contiguously, with each line padded to a word boundary, rast words per line. The long pointer points to the actual bits.
];
Rectangle: TYPE = RECORD [sMin, fMin: INTEGER, sSize, fSize: NAT];
RasterWords: PROC [bitmapDesc: BitmapDesc] RETURNS [INT] = INLINE {
RETURN [Inline.LongMult[bitmapDesc.rast, bitmapDesc.lines]];
};
Reshape: PROC [pointer: LONG POINTER, words: INT, bounds: Rectangle] RETURNS [BitmapDesc];
Makes a PixelMap from the storage provided.
InsufficientSpace: ERROR;
Intersect: PROC [a, b: Rectangle] RETURNS [Rectangle];
Computes the intersection of device rectangles.
Clear: PROC [bitmapDesc: BitmapDesc];
A fast way to clear a buffer.
ShiftMap: PROC [p: BitmapDesc, s, f: INTEGER] RETURNS [BitmapDesc];
Translates the bitmapDesc in device space.
ShiftWindow: PROC [p: BitmapDesc, s, f: INTEGER] RETURNS [BitmapDesc];
Translates the window in device space.
Clip: PROC [p: BitmapDesc, bounds: Rectangle] RETURNS [BitmapDesc];
Further restricts the window
SetWindow: PROC [p: BitmapDesc, bounds: Rectangle] RETURNS [BitmapDesc];
Changes the window
Window: PROC [p: BitmapDesc] RETURNS [Rectangle];
BufferBounds: PROC [p: BitmapDesc] RETURNS [Rectangle];
Returns a rectangle describing the actual bounds of the buffer
BoundedWindow: PROC [p: BitmapDesc] RETURNS [Rectangle];
p.Window.Intersect[p.BufferBounds]
Fill: PROC [dest: BitmapDesc, area: Rectangle, value: CARDINAL, function: Function ← [null, null]];
Function: TYPE = RECORD [dstFunc: BitBlt.DstFunc, srcFunc: BitBlt.SrcFunc];
[null, null] makes zero bits white, one bits black
[or, null] makes zero bits transparent, one bits black
[and, null] makes zero bits white, one bits black
[and, complement] makes zero bits transparent, one bits white
[xor, null] makes zero bits transparent, one bits inverted
etcetera.
Transfer: PROC [dest, source: BitmapDesc, function: Function ← [null, null]];
Does a BITBLT from the source to the dest, through the intersection of the two windows. Does the right thing if the source and dest overlap in the same buffer.
Tile: TYPE = RECORD [
sOrigin, fOrigin: INTEGER,
sSize, fSize: NAT,
phase: INTEGER,
pointer: LONG POINTER,
rast, lines: CARDINAL
];
A tile is similar to a BitmapDesc, but the window specifications are more primitive, and there is an additional phase specification. A tile is replicated to fill the plane, with tile shifted by phase pixels in the f direction every source.sSize lines.
CreateTile: PROC [rectangle: Rectangle, phase: INTEGER ← 0, rasterPointer: LONG POINTER, scratchPointer: LONG POINTERNIL, scratchWords: INT ← 0] RETURNS [tile: Tile];
The scratchPointer and scratchWords parameters describe the space for the results. The raster is turned into a tile. This may involve replicating the pattern to make a larger tile that will speed the coloring operation, so the size of the result will not in general be the same as the source. However, the raster may not always be copied.
TransferTile: PROC [dest: BitmapDesc, tile: Tile, function: Function ← [null, null]];
Transfers from the tiled plane to dest.
END.