Specifying Mix Values

When you draw a graphics primitive into a presentation space, it is affected by the current foreground-mix value, and possibly by the current background-mix value, in that presentation space. However, when you copy a bit map into a target presentation space, the current foreground- and background-mix values in the target presentation space are ignored. Instead, you specify a mix-mode value, also known as the raster-operation (ROP) value. This value determines:

Each pel in the bit map of the target presentation space has, potentially, three color settings:

The (boolean) values of each of these settings can be combined using boolean operations to produce the final value of each pel in the target presentation space. For a color target, the target must be regarded as consisting of multiple one-bit per pel planes, with the mixing applied to each plane separately to produce the final color index into the physical color table. Because the final color index is an index into the physical palette, the results of any color mixing are therefore unpredictable. For example, if you ORed together two numeric index values, the color indexed by the result is unlikely to have any direct relation to the colors indexed by the two values you ORed together. It depends on the order of the colors in the physical table.

As input to the functions, you supply an actual mix value. The ROP mix value required to achieve any given result can be determined from the following table. The final value of each bit in every pel depends on the values of the corresponding bits in the pattern (P), source (S), and the original target value (T initial). Each row of the table shows one of the eight possible combinations of these values. For each combination, mark the desired final target value in the last column. The eight bits in this column then show the value of the least significant byte of the ROP value required to achieve this mixing function. For example, if the required mixing function is to copy the source to the target, then the target (final) column will be the same as the S column, and the ROP value will have the binary value 11001100, or the hexadecimal value 00CC.

Possible Settings for the Index Bits

┌───────┬───────┬────────────────┬──────────────┬────────────────┐│Pattern│Source │Target (initial)│              │Target (final)  │
├───────┼───────┼────────────────┼──────────────┼────────────────┤
│0      │0      │0               │              │Index bit 0     │
├───────┼───────┼────────────────┼──────────────┼────────────────┤
│0      │0      │1               │              │Index bit 1     │
├───────┼───────┼────────────────┼──────────────┼────────────────┤
│0      │1      │0               │              │Index bit 2     │
├───────┼───────┼────────────────┼──────────────┼────────────────┤
│0      │1      │1               │              │Index bit 3     │
├───────┼───────┼────────────────┼──────────────┼────────────────┤
│1      │0      │0               │              │Index bit 4     │
├───────┼───────┼────────────────┼──────────────┼────────────────┤
│1      │0      │1               │              │Index bit 5     │
├───────┼───────┼────────────────┼──────────────┼────────────────┤
│1      │1      │0               │              │Index bit 6     │
├───────┼───────┼────────────────┼──────────────┼────────────────┤
│1      │1      │1               │              │Index bit 7     │
└───────┴───────┴────────────────┴──────────────┴────────────────┘

If you want the pattern to have no effect on the target rectangle, the four low-order bits of the index must be the same as the four high-order bits.

A monochrome bit map consists only of source settings of 1s and 0s, where a 1 or 0 represents each pel. It also has a two-entry color table with index 0 specifying what color a 0 pel represents and index 1 representing what color a 1 pel represents. In a monochrome bit map, this color table is not used during BitBlt operations (but is used when drawing to the bit map and moving the bit map between devices). The preceding table defines how any combination of pattern, source and target original (1 and 0) values define the target final (1 or 0) value. A color bit map has an index (in the case of four bits, 0-15) for each pel which, serves as index into the bit map color table (16 entries for four bits per pel) to define the color of each pel. Unlike monochrome bit maps, this table is used during BitBlt operations (instead of target image bundle attributes) to provide the color of the target output.

The following table represents a selection of the most commonly used mixes with predefined symbolic names and their effects. (There are many other possible mixes).

Mix Value Names

┌──────────────────┬──────────────────────────────────────────┐
│Mix Name          │Effect                                    │
├──────────────────┼──────────────────────────────────────────┤
│ROP_SRCCOPY       │Source                                    │
├──────────────────┼──────────────────────────────────────────┤
│ROP_SRCPAINT      │Source OR Target                          │
├──────────────────┼──────────────────────────────────────────┤
│ROP_SRCAND        │Source AND Target                         │
├──────────────────┼──────────────────────────────────────────┤
│ROP_SRCINVERT     │Source XOR Target                         │
├──────────────────┼──────────────────────────────────────────┤
│ROP_SRCERASE      │Source AND NOT (Target)                   │
├──────────────────┼──────────────────────────────────────────┤
│ROP_NOTSRCCOPY    │NOT (Source)                              │
├──────────────────┼──────────────────────────────────────────┤
│ROP_NOTSRCERASE   │NOT (Source) AND NOT (Target)             │
├──────────────────┼──────────────────────────────────────────┤
│ROP_MERGECOPY     │Source AND Pattern                        │
├──────────────────┼──────────────────────────────────────────┤
│ROP_MERGEPAINT    │NOT (Source) OR Target                    │
├──────────────────┼──────────────────────────────────────────┤
│ROP_PATCOPY       │Pattern                                   │
├──────────────────┼──────────────────────────────────────────┤
│ROP_PATPAINT      │NOT (Source) OR Pattern OR Target         │
├──────────────────┼──────────────────────────────────────────┤
│ROP_PATINVERT     │Target XOR Pattern                        │
├──────────────────┼──────────────────────────────────────────┤
│ROP_DSTINVERT     │NOT (Target)                              │
├──────────────────┼──────────────────────────────────────────┤
│ROP_ZERO          │0                                         │
├──────────────────┼──────────────────────────────────────────┤
│ROP_ONE           │1                                         │
├──────────────────┼──────────────────────────────────────────┤
│ROP_GRAY          │Gray pattern background                   │
└──────────────────┴──────────────────────────────────────────┘

ROP_SRCCOPY is the most often used value. It simply copies the bit map to the target presentation space without performing any color mixing. Because most of the remaining mixes involve some degree of color mixing, they result in an image that is quite different from the original.


[Back: Changing the Size of the Bit Map]
[Next: Converting between Monochrome and Color Data Bit Maps]