Skip to content

Instantly share code, notes, and snippets.

@XProger
Created October 14, 2014 20:33
Show Gist options
  • Save XProger/96253e93baccfbf338de to your computer and use it in GitHub Desktop.
Save XProger/96253e93baccfbf338de to your computer and use it in GitHub Desktop.
Fast integer alpha blending
uint32 blend(uint32 color1, uint32 color2, uint8 alpha) {
uint32 rb = color1 & 0xff00ff;
uint32 g = color1 & 0x00ff00;
rb += ((color2 & 0xff00ff) - rb) * alpha >> 8;
g += ((color2 & 0x00ff00) - g) * alpha >> 8;
return (rb & 0xff00ff) | (g & 0xff00);
}
@lili2012
Copy link

lili2012 commented Jun 11, 2020

Since you are dividing 256 not 255 so in your case return (rb & 0xff00ff) | (g & 0xff00); cant change to return rb | g;
Anyway, I like this code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment