The pixel channel structure of an Image is determined when the image is allocated (including the image allocated by the system to represent a physical display). This structure is described externally by a channel format string, described in colour (6), and internally by a value of the Chans adt, which is used when allocating new images in the calls below. Draw defines a set of constants of type Chans for common channel types: GREY1 , GREY2 and GREY8 for greyscale (depths 1, 2 and 8); CMAP8 for 8-bit rgbv (8) colour-mapped images; RGB16 for 16-bit r5g6b5 colour images; RGB24 for 24-bit colour; and RGBA32 for 24-bit colour with alpha channel. Chans has the following operations:
10 Chans.mk( s ) Return the Chans value corresponding to the channel format string s (see image (6) for the syntax of s ).
10 c .depth() Return the depth in bits of c . The result is 0 if c is invalid; in particular, Chans.mk( s ).depth() is zero if s is invalid.
c .text() Return the format string corresponding to c .
c .eq( d ) Return true if d has the same channel structure as c ; return false otherwise.
Colours in the calls below are specified as 32-bit integers (`32-bit RGBA format') containing red, green, blue and alpha components as 8-bit values, in order from most to least significant byte. The 8-bit colour component values express illumination, ranging from 0 (no colour) to 255 (saturated). For the alpha component, 0 is fully transparent, and 255 is fully opaque.
Display itself has the following components:
10 image The visible contents of the display; draw on image to change the display.
white ", " black Replicated images of a single pixel, either all ones (white) or all zeroes (black).
opaque ", " transparent Replicated images of a single pixel, either all ones (fully opaque) or all zeroes (fully transparent). Used as mattes for basic graphical operations.
allocate( dev ) Attach to a new display, represented by the draw (3) device mounted in the specified dev directory. If dev is the empty string, /dev is used. The return value is nil if the allocation fails.
d .startrefresh() After allocating a Display object, the application should spawn a process to call startrefresh ; this thread will receive and process window refresh events from the device.
d .publicscreen( id ) Create a locally addressable pointer to a public Screen ; see \f2display-screen(2).
d .newimage( r, chans, repl, rgba ) Allocate an off-screen Image . The arguments supply values for the Image 's r , chans , and repl , and an initial pixel value rgba in 32-bit RGBA format, used to paint the image when created. It can be Draw->Transparent to create a fully transparent image to draw on to form an arbitrarily-shaped image or matte. If it is Draw->Nofill , the image is not initialised. The image's clipr is initialized to r .
d .color( rgba ) Creates a single-pixel, replicated off-screen image of the specified colour, expressed in 32-bit RGBA format. The Draw module defines constants for several dozen colours:
.EX Opaque: con int 16rFFFFFFFF; Transparent: con int 16r00000000; Black: con int 16r000000FF; White: con int 16rFFFFFFFF; Red: con int 16rFF0000FF; Green: con int 16r00FF00FF; Blue: con int 16r0000FFFF; Cyan: con int 16r00FFFFFF; Magenta: con int 16rFF00FFFF; Yellow: con int 16rFFFF00FF; Grey: con int 16rEEEEEEFF; Paleyellow: con int 16rFFFFAAFF; Darkyellow: con int 16rEEEE9EFF; Darkgreen: con int 16r448844FF; Palegreen: con int 16rAAFFAAFF; Medgreen: con int 16r88CC88FF; Darkblue: con int 16r000055FF; Palebluegreen: con int 16rAAFFFFFF; Paleblue: con int 16r0000BBFF; Bluegreen: con int 16r008888FF; Greygreen: con int 16r55AAAAFF; Palegreygreen: con int 16r9EEEEEFF; Yellowgreen: con int 16r99994CFF; Medblue: con int 16r000099FF; Greyblue: con int 16r005DBBFF; Palegreyblue: con int 16r4993DDFF; Purpleblue: con int 16r8888CCFF; Notacolor: con int 16rFFFFFF00; Nofill: con Notacolor;
The special values Draw->Opaque (fully opaque) and Draw->Transparent (fully transparent) are useful as the pixel values for Display.newimage when forming a matte. The special value Draw->Nofill tells Display.newimage not to paint a new image with any colour, leaving it uninitialised.
d .colormix( one, three ) Allocate background colours. On true color displays, it returns a 1×1 replicated image whose pixel is the result of mixing the two colours in a one to three ratio; both colours are expressed in 32-bit RGBA format. On 8-bit color-mapped displays, it returns a 2×2 replicated image with one pixel coloured one and the other three with three (after translation through the colour map). This simulates a wider range of tones than can be represented by a single pixel value on a colour-mapped display.
d .rgb( red, green, blue ) Uses the values of red, green, and blue to create a single-pixel replicated image of that colour. The values are intensities that range from 0 (no colour) to 255 (saturated). The alpha component is always 255 (fully opaque).
d .namedimage ( name ) Returns a reference to the image published as name on display d by Image.name (see draw-image (2)). This allows unrelated processes to share the image (eg, a window manager and client).
d .open( name ) Read an image description from the named file and return an Image holding the picture. See image (6) for more information about image files.
d .readimage( fd ) Analogous to open , but from an open file descriptor rather than a named file.
d .writeimage( fd, i ) Complement of readimage : write an image file representing i to the open file descriptor.
d .rgb2cmap( red, green, blue ) Return the rgbv colour map index (see colour (6)) of the colour that best matches the given colour triple. The values of the components range from 0 (no colour) to 255 (saturated).
d .cmap2rgb( c ) Return the colour triple (red, blue, green) corresponding to colour map index c .
d .cmap2rgba( c ) Return the 32-bit RGBA representation of the colour corresponding to colour map index c . The alpha component is always 255 (fully opaque).
d .cursor(i, p) Set the current cursor. If i is the image of the current display, then the graphics cursor will be set to its default value, otherwise i must be an image with ldepth 0 and the following rules apply: the size of the cursor will be half the horizontal height of i (subject to system-dependent restrictions on cursor size). The top half and the bottom half of the image are treated as two independent masks. When the cursor is drawn, pixels congruent with non-zero bits in the top half are cleared and then pixels congruent with non-zero bits in the bottom half are set. P gives the offset added to the mouse position when drawing the cursor image.
d .cursorset(p) Set the position of the mouse cursor to p .