Windows provides a number of functions that use the brush currently selected into a device context to perform bitmap operations. An example of two of these are the PatBlt and FloodFill functions.The first function, PatBlt replicates the brush in a rectangular region within a window; the second function FloodFill replicates the brush inside an area in a window that is bounded by the specified color (unlike PatBlt, FloodFill will fill non-rectangular shapes).
The PatBlt function-name is actually an abbreviation for Pattern-Block-transfer. Although the name implies that the function simply replicates the brush (or pattern) until it fills a specified rectangle, the function is actually much more powerful: prior to replicating the brush, this function combines the color data for the pattern with the color data for the existing pixels on the display using a Raster Operation or ROP. A ROP is a bitwise operation that is applied to the bits of color data for the replicated brush and the bits of color data for the target rectangle on the display. There are 256 ROPs in Windows; however, the PatBlt function recognizes those that require a pattern and a destination (it does not recognize those that require a source). The following list identifies the five most common ROPs:
ROP | Description |
PATCOPY | Copies pattern to destination bitmap. |
PATINVERT | Combines destination bitmap with pattern using the Boolean OR operator. |
DSTINVERT | Inverts the destination bitmap. |
BLACKNESS | Turns all output to binary 0s. |
WHITENESS | Turns all output to binary 1s. |
The FloodFill function replicates the brush within a region bounded by a specified color. However, unlike the PatBlt function, FloodFill does not combine the color data for the brush with the color data for the pixels on the display—it simply sets the color of all pixels within the enclosed region on the display to the color of the brush that is currently selected into the device context.
The following illustration shows the result of calling the FloodFill function in the Windows Paintbrush application to paint the interior of a non-rectangular region. The window on the left shows the region prior to calling FloodFill; the window on the right shows the region after the call was made:
Painting a Region with FloodFill