Fast 24-bit RGB addition without overflow checks


(c1 & 0xfefeff) + (c2 & 0xfefeff) + (c3 & 0xfefeff) + (c4 & 0xfefeff);

While working on fast bilinear filtering, I found that this adds up 4 colors without checking for overflow. It works perfectly with bilinear texture filtering because overflow shouldn’t occur anyways.

(there’s error in the blue, i’ll edit this once i figure it out)

EDIT:

fixed version:


int sum = (c1 & 0xfefeff) + (c2 & 0xfefeff) + (c3 & 0xfefeff) + (c4 & 0xfefeff);
return sum | (-(sum & 0x100) >>> 24)

If you can simplify this more, please share haha