Relative Content

Tag Archive for c++cgraphicsfixed-point

Alpha compositing in fixed point (0xff is not 1.0)

I’m writing some C code that does alpha compositing using integer math (fixed point), and I’m coming across the problem that 0xff isn’t quite 1.0. This is particularly problematic in the alpha channel. For example (0xff * 0xff) >> 8 equals 0xfe. So if you have a white pixel with alpha 0xff and RGB 0xff, and you try to premultiply your alpha channel into the color channels, you end up with 0xfe in the RGB channels, so you no longer really have white.