5.5 Controlling Graphics Tricks

The GC provides a flexible way to control exactly which planes are affected by graphics requests and how the source and old destination pixel values are used to compute the new destination pixel values. These features are needed only for playing certain tricks like rubber-banding, and nondestructively overlaying graphics. We will demonstrate these techniques later in the book (in Chapter 14 and Chapter 7, respectively), but describe the corresponding GC components here.

Example 5-7 shows the types of the logical operation and plane mask components of the GC.

Example 5-7. Members of XGCValues that control combining of source and destination pixels

int function;                   /* Logical function */
unsigned long plane_mask;                       /* Plane mask */

The source (result of stage 2 of the drawing process) and existing destination pixels are combined by performing a logical function on the corresponding bits for each pixel. The plane_mask restricts the operation to a subset of planes, so that some bits in the source may be excluded from the computation. The clip_mask restricts the operation to a subset of the pixels, likewise eliminating some pixels from the result.

The source, destination, and plane_mask are combined using the algorithm shown below to yield the new destination pixel values. For each bit in each pixel that has been selected and colored in the first two drawing stages, the following expression defines whether that bit is set in the destination drawable:

((src FUNC dst) ...

Get XLIB Programming Manual, Rel. 5, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.