I found this code buried under some rocks:
var divAlpha = 0xff00/color.A;
var r = (byte) (color.R*divAlpha >> 8);
var g = (byte) (color.G*divAlpha >> 8);
var b = (byte) (color.B*divAlpha >> 8);
The fields on color
are bytes, of course. My guess would be it's avoiding using floating point operations to handle premultiplied alpha, but is it converting from or to? How does this work out?
Example output:
0x44112233 -> a: 0x44, r: 0x3f, g: 0x7f, b: 0xbf