ALPHA operation in 16 bit bit mode

zhaozj2021-02-08  221

Good, 16bit alpha operations are finally sorted out, if there is something wrong, welcome everyone to criticize advice. how about it? Is it still modest? Ok, the collateral is correct, and Alpha integration in special effects is one of the applications. The hardware acceleration can be used in D3D, and Alpha integration is more than 2D. The monks have been searching for various special effects under 2D. Now they have seen the better alpha operations, share with everyone, if you have a better algorithm, don't forget to tell me. Attachment: Source, compile DX6 or above SDK, VC, DXGuide.

Here is the unlimited magnitude Alpha check table algorithm, why is it unlimited? Because you can set the alpha level. Before introducing 16-bit algorithms, we should first take a look at 8-bit check algorithms:

Create a 256 * 256 size table, each unit is a color index value;

Start with a given Alpha value;

Check the table calculation.

The table initialization is to pre-calculate the combination of all possible source points and target points, and the specific practice is to separate the R, G, B value according to the color index value of the palette and the source point and the target point. Remove the color index value of the most in line with the calculation result from the palette.

When calculating, simply use the color index value of the source point and the target point as the subscript of the lookup table, find the corresponding table unit. The algorithm is original in Tony Cox's FAQ.

The 16-bit algorithm is basically the same as 8 digits, but does not need to build 216 * 216 table, but build two? 28 * 28 table. Calculate the low byte and high byte when calculating, why can we separate our following we can prove:

Take 565 modes, the source point color value is R1G11 G12B1, R1G11 is high byte, and G12b2 is low byte. The same target point color value is set to R2G21 G22B2, the Alpha value is a, the maximum level is m, and the fusion formula is:

R = (A * R1 (M-A) * R2) / M

G1G2 = (A * G11G12 (M-A) * G21G22) / M

B = (a * b1 (m-a) * b2) / m

[RG1G2B] = 211 * R 25 * G1G2 B

= 211 * (A * R1 (M-A) * R2) / M

25 * (A * G11G12 (M-A) * G21G22) / M

(A * b1 (m-a) * b2) / m

= 28 * (A * 23 * R1 (M-A) * 23 * R2) / M

25 * (A * (23 * G11 G12) (M-A) * (23 * G21 G22)) / m

(A * b1 (m-a) * b2) / m

= 28 * (A * (23 * R1 G11) (M-A) * (23 * R2 G21)) / m

(A * (25 * g12 b1) (m-a) * (25 * g22 b2)) / m

= 28 * (A * [R1G11] (M-A) * [R2G21]) / M

(A * [g12b1] (m-a) * [G22B2]) / M

The dead top and date! Haven't seen it? what? The first half is high byte, the second half is low byte, Ha ----

So the high and low byte calculation is independent. It can be generated as N-bit arithmetic independence. Next, let's know how to build a lookup table? I still don't know? Don't ask me, think about it slowly. I never want to knock half a mark.

Followed by 32 ALPHA operation principle of this method is relatively simple, a color expansion word to a double word, with a calculated 32-bit register, for example: RRRRRGGGGGGBBBBB expanded to 00000RRRRR000000GGGGGG00000BBBBB, after their operation can be reduced to a word. Why is it 32 rather than 64? Because 2 is 52, no matter whether it is 555 or 565, the average number of colors can only expand 5 bits, 32 is the maximum number of this method. Of course, less than 32 is no problem. The key to affecting this method is the development of the word to double words. In fact, R, G, and B will not be tight after anyone, the most important thing is to quickly expand and restore. Take 565 as an example: expand: (WRGB & Brvbarwrgb << 16) & 0xf81f07e0 // 1111, 11000, 01, 1111, 0000, 0111, 1110,0000

Restore: (DWRGB >> 16) & brvbardwrgb

Compare the two methods, the first method is more suitable for the case of the Alpha value, such as the visual area of ​​the "World War II Special Forces". As for the efficiency of Alpha progressive changes, the larger the calculation area, the greater the first method advantage. The specific contrast is not done, you can do it yourself.

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

New Post(0)