This paper is taught in the TC in the 256-color tone panel mode of VGA, how to make Alpha hybrids. This is written in my VGA13H Graphics Lib for TC 2.0, basically achieves Alpha hybrid. The disadvantage is that the speed is too slow, and the division operations are used in both ARGB and GETRGB, and the speed is impossible to get up. And also made an error, which is meaningless in the 256-color mode of the alpha mix, and it is impossible to implement, and only 4 levels can be reached. In short, there are still many errors, recently repeatedly study Alpha mixed and palette, and new gains, new algorithms are sufficient to use real-time Alpha hybrids, and then write in the art. The 256 color video mode is due to the palette, the pixel value stored in the memory is actually the index number of the palette, and the 256-color BMP file is similar, and the data field is stored in the data field. The index number, this situation gives our alpha mixers to bring great inconvenience.
In actual applications, a fixed palette is typically selected, and then drawing operations under this palette. This is because a pair image has different display effects under different palettes, and two bitmaps using different palettes are in general, and they cannot be displayed on the same screen. So the usual situation is to select a universal palette, which is the problem of using this universal palette to use this generic palette to use this generic palette. In this way, how to choose a universal palette is the key.
Everyone knows that VGA / SVGA's palette register is usually 6 bits. Each register stores a color component, and a RGB color vector requires three registers to store, so you can represent 2 ^ 6 * 2 ^ 6 * 2 ^ 6 = 256K color, this color range is very large. The VGA / SVGA has only 256 sets of tones registers, so in such a vector space in (0, 0, 0) - (63, 63, 63), 256 color vectors are selected. This is similar to the base (very unrelated group) of the vector space in the linear algebra. Our task is similar to finding a base in this color space to be (0, 0, 0) - (63, 63, 63). Simply put to find 256 color vectors, form a color palette, and make this 256 colors evenly distributed in (0, 0, 0) - (63, 63, 63) this space, and also To ensure its independence. Detailed approach is no longer discussed, but only gives a relatively universal palette. R (i) = (i / 32% 8) * 9; g (i) = (i / 4% 8) * 9; B (i) = (i% 4) * 21; where i is the register group number, R (i), g (i), b (i) is the RGB color component value of the register, which is a transform type from I to R (I), G (I), B (I). Thereby, its inverse transform: i = r / 9 * 32 g / 9 * 4 b / 21;
Do it, you can do a multiplication and division operation, you can get the following: R (i) = (((i >> 5)% 8) << 3) ((i >> 5)% 8); g (i) = (((i >> 2) 4% 8) << 3) ((I >> 2) 4% 8); B (i) = ((i% 4) << 4) ( (i% 4) << 2) (i% 4);
I = ((R / 9) << 5) ((g / 9) << 2) B / 21;
According to these two transformations, we can write two macros for obtaining color number I, and (R, g, b) values corresponding to color number I, and color number I. #define RGB (((((((((((((((((((((((g) / 9) << 2) (b) / 21) #define argb (r, g , b) RGB (R 4, G 4, B 10) #define getRGB (I, PR, PG, PB) {* (PR) = (((i >> 5)% 8) << 3) ((i >> 5)% 8); * (pg) = (((i >> 2) 4% 8) << 3) ((i >> 2) 4% 8); (* PB) = ((i% 4) << 4) ((i% 4) << 2) (I% 4);} where the Argb (Adjusted RGB) macro is corrected to the RGB macro because the RGB macro is in error.
In this way, we have established the correspondence between I and (R, G, B), which I have paved the road for our alpha.