Skip to content

Instantly share code, notes, and snippets.

Created December 5, 2011 21:30
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 anonymous/1435459 to your computer and use it in GitHub Desktop.
Save anonymous/1435459 to your computer and use it in GitHub Desktop.
8-Bit node.js Buffer Mix
var length = chA.length, // A & B must be the same length
out = new Buffer(length) // faster if you just overwrite one mix channel
for (i=0; i<length; i++) {
if (chA[i] < 128 && chB[i] < 128) {
out[i] = chA[i] * chB[i] / 128;
}
else {
out[i] = 2 * (chA[i]+chB[i]) – chA[i] * chB[i] / 128 – 256;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment