Skip to content

Instantly share code, notes, and snippets.

@wjlafrance
Created April 22, 2012 19:25
Show Gist options
  • Save wjlafrance/2466303 to your computer and use it in GitHub Desktop.
Save wjlafrance/2466303 to your computer and use it in GitHub Desktop.
Processing pixels stored in 32-bit integers as AARRGGBB to create a negative image
//Slow:
int r = (pixels[i] & 0x00FF0000 >> 16) * -1 + 255;
int b = (pixels[i] & 0x0000FF00 >> 8) * -1 + 255;
int g = (pixels[i] & 0x000000FF) * -1 + 255;
pixels[i] = r << 16 | b << 8 | g;
//Fast:
pixels[i] ^= 0x00FFFFFF;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment