Home   Index   About
Ultimate Pack


Custom Search
Binary Raster Operations

This section lists the binary raster-operation codes used by the GetROP2 and SetROP2 functions. Raster-operation codes define how GDI combines the bits from the selected pen with the bits in the destination bitmap.

Each raster-operation code represents a Boolean operation in which the values of the pixels in the selected pen and the destination bitmap are combined. Following are the two operands used in these operations:

Operand
Meaning
P
Selected pen
D
Destination bitmap

The Boolean operators used in these operations follow:

Operator
Meaning
a
Bitwise AND
n
Bitwise NOT (inverse)
o
Bitwise OR
x
Bitwise exclusive OR (XOR)

All Boolean operations are presented in reverse Polish notation. For example, the following operation replaces the values of the pixels in the destination bitmap with a combination of the pixel values of the pen and the selected brush:

DPo

Each raster-operation code is a 32-bit integer whose high-order word is a Boolean operation index and whose low-order word is the operation code. The 16-bit operation index is a zero-extended 8-bit value that represents all possible outcomes resulting from the Boolean operation on two parameters (in this case, the pen and destination values). For example, the operation indexes for the DPo and DPan operations are shown in the following list:

P
D
DPo
DPan
0
0
0

0




0





0

The following list outlines the drawing modes and the Boolean operations that they represent:

Raster operation
Boolean operation
R2_BLACK
0
R2_COPYPEN
P
R2_MASKNOTPEN
DPna
R2_MASKPEN
DPa
R2_MASKPENNOT
PDna
R2_MERGENOTPEN
DPno
R2_MERGEPEN
DPo
R2_MERGEPENNOT
PDno
R2_NOP
D
R2_NOT
Dn
R2_NOTCOPYPEN
Pn
R2_NOTMASKPEN
DPan
R2_NOTMERGEPEN
DPon
R2_NOTXORPEN
DPxn
R2_WHITE

R2_XORPEN
DPx

For a monochrome device, GDI maps the value zero to black and the value 1 to white. If an application attempts to draw with a black pen on a white destination by using the available binary raster operations, the following results occur:

Raster operation
Result
R2_BLACK
Visible black line
R2_COPYPEN
Visible black line
R2_MASKNOTPEN
No visible line
R2_MASKPEN
Visible black line
R2_MASKPENNOT
Visible black line
R2_MERGENOTPEN
No visible line
R2_MERGEPEN
Visible black line
R2_MERGEPENNOT
Visible black line
R2_NOP
No visible line
R2_NOT
Visible black line
R2_NOTCOPYPEN
No visible line
R2_NOTMASKPEN
No visible line
R2_NOTMERGEPEN
Visible black line
R2_NOTXORPEN
Visible black line
R2_WHITE
No visible line
R2_XORPEN
No visible line

For a color device, GDI uses RGB values to represent the colors of the pen and the destination. An RGB color value is a long integer that contains a red, a green, and a blue color field, each specifying the intensity of the given color. Intensities range from 0 through 255. The values are packed in the three low-order bytes of the long integer. The color of a pen is always a solid color, but the color of the destination may be a mixture of any two or three colors. If an application attempts to draw with a white pen on a blue destination by using the available binary raster operations, the following results occur:

Raster operation
Result
R2_BLACK
Visible black line
R2_COPYPEN
Visible white line
R2_MASKNOTPEN
Visible black line
R2_MASKPEN
Invisible blue line
R2_MASKPENNOT
Visible red/green line
R2_MERGENOTPEN
Invisible blue line
R2_MERGEPEN
Visible white line
R2_MERGEPENNOT
Visible white line
R2_NOP
Invisible blue line
R2_NOT
Visible red/green line
R2_NOTCOPYPEN
Visible black line
R2_NOTMASKPEN
Visible red/green line
R2_NOTMERGEPEN
Visible black line
R2_NOTXORPEN
Invisible blue line
R2_WHITE
Visible white line
R2_XORPEN
Visible red/green line


Last news from Greatis Software

Nostalgia .Net     Nostalgia .Net     .Net is powerful, but not all-powerful, so sometimes we need to use Win32 API for our .Net applications. It's simple enough with Platform Invoke if you have Win32 skill, but we do not always have time to dig the ancient documentation, declare the special types that are compatible with Win32, find the values of the Win32's constants and so on. Nostalgia .Net offers several simple-to-use classes, and components that will allow you to forget about the headache of Win32 and just use the power of Win32 in your application the same way as you use the native. Net classes.  More »

Recommended software for developers

Ultimate Pack for Delphi and C++ Builder     Ultimate Pack     Component pack for Delphi and C++ Builder that contains runtime form designer, runtime object inspector, print suite and much more for the very special price.  More »

Form Designer .Net     Form Designer .Net     Unique runtime form design solution that allows to edit any form in .Net WinForms application at runtime with full source codes for only 300 euro!  More »

Print Suite .Net     Print Suite .Net     Print Suite .Net is a set of components for easy printing texts, images and grids from your WinForms applications. Full C# source codes are available  More »

Gradient Controls .Net     Gradient Controls .Net     Gradient Controls .Net offers controls with gradient background feature. Labels, panels and so on... Full C# source codes are available  More »

iGrid     Greatis iGrid     iGrid plots drawing grid right over your desktop, so you can use it everywhere, with any drawing application without any special plugins for different graphic editors.  More »


All the contacts and projects

Dmitry Vasiliev (just.dmitry)

Related Links

Software for Visual Studio .NET developers
Software for Delphi and C++ Builder developers
Software for Visual Basic 6 developers
Delphi Tips&Tricks
MegaDetailed.NET

More Online Helps

Win32 Programmer's Reference
Win32 Multimedia Programmer's Reference
OLE Programmer's Reference
Microsoft Windows Pen API Programmer's Reference
Microsoft Windows Sockets 2 Reference
Microsoft Windows Telephony API (TAPI) Programmer's Reference
Unix Manual Pages

Free Tech Secrets ;) Copyright © 2008-2012 Free Tech Secrets ;) greatis just4fun network just4fun