Skip to content

Instantly share code, notes, and snippets.

@city41
Created January 29, 2012 03:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save city41/1697003 to your computer and use it in GitHub Desktop.
Save city41/1697003 to your computer and use it in GitHub Desktop.
Alpha compositing in JavaScript
function _composite(under, over) {
var alphaO = over[3],
alphaU = under[3],
invAlphaO = 1 - alphaO,
i,
len;
for(i = 0, len = under.length - 1; i < len; ++i) {
under[i] = Math.round((over[i] * alphaO)
+ ((under[i] * alphaU) * invAlphaO));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment