How to make ARGB transparency using bitwise operators.

Posted by Smejda on Stack Overflow See other posts from Stack Overflow or by Smejda
Published on 2011-03-17T08:04:36Z Indexed on 2011/03/17 8:10 UTC
Read the original article Hit count: 437

I need to make transparency, having 2 pixels:

pixel1: {A, R, G, B} - foreground pixel
pixel2: {A, R, G, B} - background pixel

A,R,G,B are Byte values

each color is represented by byte value

now I'm calculating transparency as:

newR = pixel2_R * alpha / 255 + pixel1_R * (255 - alpha) / 255
newG = pixel2_G * alpha / 255 + pixel1_G * (255 - alpha) / 255
newB = pixel2_B * alpha / 255 + pixel1_B * (255 - alpha) / 255

but it is too slow I need to do it with bitwise operators (AND,OR,XOR, NEGATION, BIT MOVE)

© Stack Overflow or respective owner

Related posts about algorithm

Related posts about math