In the game, we can often see some translucent images, how is these images generated? Is it a simple attachment? Of course, it is not, it is not kind. This is actually the effect of mixing two images after mixing two images, that is, the alpha mixture of graphics, to get a mixed picture, you must process each point. Let's take a look at how Alpha mixed. Here is a 16-bit color bit example: 16-bit color, each pixel is used in a word, there is 16 binary. This 16-bit, divided into three segments respectively represents the R, G, and B value of the pixel. There are two current display cards: 555 format RGB each accounts for 5 highlights, and the value of 565 format G occupies 6 digits, and the other two components each account for 5. So first, we have to get the pixel RGB.
N
R
R
R
R
R
G
G
G
G
G
B
B
B
B
B
Figure 1 555 RGB component
R
R
R
R
R
G
G
G
G
G
G
B
B
B
B
B
Figure 2 565 RGB component
Under DirectDraw, you can get the surface of the surface to get the pixels of the surface to a Word * variable. When we get the pixels of the resource surface and the surface of the target, we can start alpha mixing. The 16bit Alpha mixed first must distinct the pixel of the original and purpose surface. This can be realized by a bit operation, and the extra other colors are removed with the operation with the specific value corresponding to the RGB, respectively, and finally removed by shift. Here you should pay attention to the difference between the 555 display card and 565 display card. After the color, the mixing is officially started, and the differences of R, G, and B, which will be mixed, each mixed separately. Let's take a formula first: a = destination color, b = resource color, alpha = mixed color depth (0 Color after mixing = a * alpha b * (1-alpha) When alpha = 0, the color after mixing = a. When Alpha = 1, the color after mixing = b. When Alpha is between 0 and 1, the mixed colors contain two colors of resources and destination surfaces. Adjust the value of Alpha, the color after mixing will follow regular changes. However, the color is an integer, so we have to make a simple change in the formula: Color after mixing = (a * alpha b * (32-alpha)) / 32 1 <32 All elements after such an equivalent change becomes an integer, the number of adjustment grades of the mixed color is 32 (more orally, it is also possible to replace 32 in the formula to other numbers, but also changes in the ALPHA region), but Computer processing multiplication and division are very slow, and Alpha hybrid is calculated on many points. The above formula is obviously unsuitable, and we will change again: Color after mixing = ((a-b) * alpha) >> 5 B In addition to 32 equal to right, this is the reason for adjusting the number of 32. Computer processing shift is very fast. As for the one multiplying alpha, I don't know what simple approach to change the efficiency algorithm. After mixing the colors of R, G, B, and finally need to synthesize them, this is a simple step, opposite the difference, and then three color value is bitten or operated. After processing all the pixels that need to be mixed, remember to unlock the surface.