DIRECTORY Basics USING[BYTE], Terminal USING[Virtual], Atom USING[PropList], Rope USING[ROPE], Imager USING[Context, Rectangle], SampleMapOps USING[SubMap, Buffer]; Pixels: CEDAR DEFINITIONS ~ BEGIN BYTE: TYPE ~ Basics.BYTE; -- parts of a pixel will not exceed 8 bits in the forseeable future Extent: TYPE ~ RECORD[x, y, w, h: NAT]; SampleSet: TYPE ~ SampleMapOps.Buffer; SampleSetSequence: TYPE ~ RECORD[SEQUENCE length: NAT OF SampleSet]; SubMap: TYPE ~ RECORD[ subMap: SampleMapOps.SubMap, df: NAT _ 1]; SubMapSequence: TYPE ~ RECORD[SEQUENCE length: NAT OF SubMap]; PixelBuffer: TYPE ~ RECORD[ width: NAT _ 0, -- width, in pixels, of pixel grid height: NAT _ 0, -- height, in pixels, of pixel grid samplesPerPixel: NAT _ 0, -- number of samples representing each pixel (eg. RGB) pixels: REF SubMapSequence _ NIL, -- The bits. Each SubMap represents one sample from a pixel. Where an alpha buffer or depth buffer is used, its location is stored in the props under $Alpha or $Depth. props: Atom.PropList _ NIL ]; PixelsError: SIGNAL [reason: ErrorDesc]; ErrorDesc: TYPE ~ RECORD [code: ATOM, explanation: Rope.ROPE]; XfmMapPlace: PROC [ map: SubMap, x, y: INTEGER ] RETURNS [newX, newY: INTEGER]; ByteAvrgWgtd: PROC[ b1, b2, wgt: BYTE ] RETURNS[ bOut: BYTE ]; SumLessProd: PROC[ b1, b2: BYTE ] RETURNS[ bOut: BYTE ]; GetSampleSet: PROC[size: NAT] RETURNS[SampleSet]; Create: PROC [width, height: NAT, pixelSizes: SampleSet] RETURNS[PixelBuffer]; GetFromImagerContext: PROC [context: Imager.Context, alpha, depth: BOOLEAN] RETURNS[PixelBuffer, Imager.Rectangle]; GetFromTerminal: PROC [vt: Terminal.Virtual, alpha, depth: BOOLEAN] RETURNS[PixelBuffer]; TerminalFromBuffer: PROC [buf: PixelBuffer] RETURNS[vt: Terminal.Virtual]; ImagerContextFromBuffer: PROC [buf: PixelBuffer, type: ATOM _ NIL] RETURNS[ctx: Imager.Context]; Fill: PROC [buf: PixelBuffer, pixel: SampleSet _ NIL]; Transfer: PROC [dstBuf, srcBuf: PixelBuffer]; Copy: PROC [ destination, source: PixelBuffer, destArea, srcArea: Extent, op: ATOM _ $Write ]; ShowOnImagerContext: PROC [context: Imager.Context, buf: PixelBuffer]; GetPixel: PROC [buf: PixelBuffer, x, y: NAT, pixel: SampleSet _ NIL] RETURNS[ SampleSet ]; PutPixel: PROC [ buf: PixelBuffer, x, y: NAT, pixel: SampleSet ]; GetScanSeg: PROC [buf: PixelBuffer, x, y, length: NAT, pixels: REF SampleSetSequence _ NIL] RETURNS[ REF SampleSetSequence ]; PutScanSeg: PROC [ buf: PixelBuffer, x, y, length: NAT, pixels: REF SampleSetSequence ]; PixelOp: PROC [ buf: PixelBuffer, area: Extent, pixel: SampleSet, op: ATOM _ $Write ]; GetValue: PROC [buf: PixelBuffer, x, y: NAT, map: NAT _ 0] RETURNS[ value: CARDINAL ]; PutValue: PROC [ buf: PixelBuffer, x, y: NAT, value: CARDINAL, map: NAT _ 0 ]; ValueOp: PROC [ buf: PixelBuffer, area: Extent, value: CARDINAL, map: NAT _ 0, op: ATOM _ $Write ]; END. ΚPixels.mesa Copyright c 1985 by Xerox Corporation. All rights reserved. Frank Crow, May 13, 1986 12:18:38 pm PDT Basic operations on two-dimensional arrays of pixels. A pixel consists of an arbitrary number of values (samples) addressed at the same position. A pixel is supposed to represent the information behind a displayed spot, not all of which is necessarily visible to the viewer. One typical pixel format consists of 4 samples, one each for alpha, red, green, and blue. Type Definitions REF RECORD [length: NAT, samples: SEQUENCE maxLength: NAT OF CARDINAL];; extended SubMap, df is distance (in samples) between samples Utility Procedures Creation Operations Allocates bits and builds PixelBuffer record with default procedures. PixelSizes allows arbitrary collections of bits to be used as pixels Forces pixel buffer onto Imager context in those circumstances where it is possible, stores REF to imager context on PixelBuffer.props Makes pixel buffer out of terminal color display, if there is one PixelBuffer Operations For getting terminal when needed for locking, etc. Allows imager calls to act on your pixels understood types are: $Dithered, $Mapped, $Grey, $Dorado24 Fill pixels with specified pixel value, default pixel value (pixel = NIL) clears to zero Copies one PixelBuffer into another, doing the "right thing" about non-visible buffers Copies using the specified source and destination rectangles Puts pixels from displayMemory onto supplied context using Imager calls Pixel operations In the following, a SampleSet is assumed to map one byte into one SubMap. Those in a hurry can avoid allocates by caching "pixel" (the 4th argument) Standard ops include: $AND = bitwise AND $OR = bitwise OR $XOR = bitwise XOR $Write = replace previous contents with new pixel (default) $WriteUnder = blend behind previously written pixels (using alpha buffer) $WriteOver = blend in front of previously written pixels (using alpha buffer) Visible value operations In the following, the Client specifies which submap is targeted, and gains speed thereby. Standard ops are: $AND = bitwise AND $OR = bitwise OR $XOR = bitwise XOR $Write = replace previous contents with new pixel (default) ΚV˜head2šœ ™ Jšœ Οmœ1™J˜—™Lš Οn œžœžœžœžœ˜OIdefaultš ‘ œžœžœžœžœ˜@Mš ‘ œžœ žœžœžœ˜8Mš‘ œžœžœžœ ˜1—šœ™unitš‘œžœžœžœ˜PMšœ‹™‹—š‘œžœ)žœ žœ ˜|Mšœ†™†—š‘œžœ&žœ žœ˜bM™A—M™—šœ™š‘œžœžœ˜JM™2—š ‘œžœžœžœžœ˜lMšœd™d—š‘œžœ'žœ˜6MšœEžœ™X—š‘œžœ˜-M™W—š‘œžœIžœ ˜dL™<—š‘œžœ-˜FM™G——™LšœI™Iš ‘œžœžœžœžœ˜`LšœJ™J—Lš‘œžœžœ˜ALš‘ œžœ"žœ žœžœžœžœ˜ƒLš‘ œžœ#žœ žœ˜Xš‘œžœ>žœ ˜[™L™L™L™L™>L™KL™O——M˜—™LšœY™YLš ‘œžœžœžœžœ žœ˜VLš ‘œžœžœ žœžœ˜Nš ‘œžœ*žœžœžœ ˜j™L™L™L™L™>——M˜—Jšžœ˜—…— r’