Bit map of raster operation and ROP code analysis

xiaoxiao2021-03-06  22

Bit map of raster operation and ROP code analysis

(SnowStart on March 22, 2005)

The bitmap is a very important aspect of Windows graphics programming. In a normal bitmap operation, such as GDI functions Bitblt, StretchBLT, StretchDibits will be used to use a raster operation code, a ROP code, like SRCCopy, PatPaint, Srcand, etc., due to the recent development graphics drive, involving many ROP2 , ROP3 and ROP

4 yards operation, the ROP code has been in-depth research, and the following detailed introduction is shared with you.

Binary raster operation: When we use the GDI line and the padding area, GDI uses a binary raster operand ROP2 to combine brush or brush pixels and target pixels to obtain new target pixels. For example, the setrop2 function and the getrop2 function support 16 binary raster operations, such as: (see Wingdi.h)

#define r2_not 6 // DN

#define r2_xorpen 7 // DPX

Trimata Grating: For the same gratual operation for the image to generate various special effects, three pixels, source image pixels, target image pixels and painted brush pixels (template image pixels), called three yuan Raster operation, use ROP

3 yards, such as: (see Wingdi.h)

#define srcpaint (dword) 0x00EE0086 // DEST = Source Or Dest

#define srcand (DWORD) 0X

008800C6 // DEST = Source and Dest

Four-dimensional grating operation: It is mixed for the source image pixel, the target image pixel and the template brush pixel, but also adds a mask bitmap, and four variables form a four-dimensional grating operation, corresponding to ROP

4 yards, the Maskblt function in the GDI function is ROP

4 yards, the only API function that accepts four-dimensional raster operation

Code of the raster operation:

One byte can encode 256 gratings, assuming P is the bit of the brush or the bit, S is the bit of the source image, and D is the target image. If the result of the operation is, the encoded is 0xF0, if the result of the operation is, the encoding is 0xcc, and if the result of the operation is, 0xAA is encoded.

Const byte rop_p = 0xf0; // 1 1 1 1 0 0 0 0

Const byte rop_s = 0xcc; // 1 1 0 0 1 1 0 0

Const byte rop_d = 0xAA; // 1 0 1 0 1 0 1 0

All other grating operations can operate based on the Boolean operation of the three constants, such as the logic of defining the source image S and the painting P, calculating ROP_S & ROP_P = 0xc0

The grating operation in GDI actually uses 32-bit DWORD encoding, not simple 0-255 single byte encoding, double byte high 8 bits indicate one of the above-mentioned 256 single-byte grating coding, low byte 16 bits define the calculation of the calculation of the raster operation.

The low byte 16 bits are divided into two parts: operators and operands, as follows:

Low byte high 11 bits indicate operator

Two digits represent a logical operation (00-Not, 01-xor, 10-or, 11-and), a total of 5 logical operations, the remaining one indicates whether the last operation is not operation

Low byte low 5 digits

The first 3 specified analysis string, the latter 2-bit specified the offset of the string (8 kinds of analysis strings are as follows) 000: SPDDDDDD

001: SPDSPDSP

010: SDPSDPSD

011: DDDDDDDD

100: DDDDDDDD

101: S SP-DSS

110: S SP-PDS

111: S SD-PDS

The " " and "-" in the string are called special operands. There are 16 complex operations in 256 raster operations that cannot be represented by a single accumulator, and the temporary storage operand is required, " " indicates that the press stack is pressed, "-" indicates the stack, and it is paired,

Note: The analysis of the skewers to read, and move forward when they are shifted.

OP5OP4OP3OP2OP1NOT analysis string offset

Figure 1. Code grating calculation (16 bits of raster encoding)

For example: If the grating operation is encoded is 0x00e20746, the low byte is 0x0746, the binary is 0000 0111 0100 0110

Obviously OP5 = NOT, OP4 = NOT, OP3 = XOR, OP2 = AND, OP1 = XOR, and NOT = 0 means that there is no additional NOT;

Analytical string = 001 shift = 2, the actual string is the SPDSPDSP left shift 2 symbols, which is DSPDSPSP, OP1-OP3 is a binary operator, and the OP4-OP5 is a one-dollar operator, so only 4 operands, so that the string The suffix of the raster operation is the same as DSPDXAXNM is simplified to DSPDXAXNM D ^ (S & (P ^ D))) is the same as DSPDXAXNM.

This coding of 16 bits is actually an encoding designed in the early days, and the new GDI implementation is no longer used in this case, so in general, in the case of throwing three yuan. The low order of the raster operation is secure, but it is difficult to say whether there will be a graphics device driver to check each bit matching of the 32-bit raster operand, for security, when used to the new raster operation code, it should Check and use the entire grating operation code.

The three-dimensional raster operand only uses 24 bits of the 32-bit grating code. The high 8 bits of the raster operation code are usually all bit 0. Windows2000 and above, two new flags are introduced to control bitmap transfer operations CaptureBLT and NomirrorBitmap.

NomirrorBitmap flag (0x80000000) prevents bitmaps from being vertically or horizontally mirrored, as the direction or other aspect of the axis of the source and target rectangle is different.

The CaptureBLT flag (0x40000000) is used to overlap the window operation.

Four yuan raster encoding:

The fourth participant in the four-dimensional raster operation is a monochrome shielding bitmap, and the quadritical grating code consists of a foreground three-dimensional raster code and a background ternary grating code. When the mask pixel is 1, when the foreground grating operation code is used, when the mask pixel is 0, the background grating operation code is used, and the GDI defines the macro MakeroP4 to combine 2 24-bit three-dimensional grating code into 32-bit four. The Yuan Grating Operation Code ROP4. Defined as follows:

#define makerop4 (more, back) ((((back << 8) & 0xff000000) | (Fore))

Background ROP Index (8-bit) Prospect ROP Index (8-bit) Prospects of the Foreground ROP Formula (Low 16 Bits of ROP)

The macroblift is a high 8-bit raster operating index of the background raster operation code, the left shifts 8 bits, and then the 24-bit foreground grating operation code consists of 32-bit ROP4.

Note that the position of the mask in the four-dimensional raster operation is not equal, it is limited to two values:

1

(White) and

0

转载请注明原文地址:https://www.9cbs.com/read-44135.html

New Post(0)