I am implementing an alpha blending, and one of the examples I came across used this format. I am confused why the division by 256
and why isn't there inv_alpha
in red and blue channels
int pixel,vga_pixel;
int alpha, blue, green, red, pixel;
int height = 1296;
int width = 968;
int x, y;
for (y = 0; y <= height; y++){
for (x = 0; x <= width; x++){
pixel = *(img.memloc + x + y);
//0xff gets the first 8 bits, in this case red
red = pixel & 0xff;
//shift by 8 to get rid of red then AND to get first 8, here green
green = pixel >> 8 & 0xff;
blue = pixel >> 16 & 0xff;
alpha = pixel >> 24 & 0xff;
int inv_alpha = 0xff - alpha; // 1-alpha
int vga_red = (red*(int)alpha);
int vga_green = (green*(int)alpha + inv_alpha/256);
int vga_blue = (blue*(int)alpha);
int vga_alpha = 0xff;
int vga_pixel = vga_alpha << 24 | vga_blue << 16 | vga_green << 8 | vga_red;
}
}
Can anyone clarify if this is a valid method, and why?