Skip to content

Instantly share code, notes, and snippets.

@gamefreak
Created October 4, 2011 12:48
Show Gist options
  • Save gamefreak/1261559 to your computer and use it in GitHub Desktop.
Save gamefreak/1261559 to your computer and use it in GitHub Desktop.
Pixel Magnitude function
#define SLICE(value, shift) (int16_t)((value & (0xff << shift)) >> shift)
static inline uint32_t pixel_magnitude(uint32 pixel, uint32 color) {
int16_t r = SLICE(pixel, 24) - SLICE(color, 24);
int16_t g = SLICE(pixel, 16) - SLICE(color, 16);
int16_t b = SLICE(pixel, 8) - SLICE(color, 8);
return (r*r+g*g+b*b);
}
#undef SLICE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment