Created
October 4, 2011 12:48
-
-
Save gamefreak/1261559 to your computer and use it in GitHub Desktop.
Pixel Magnitude function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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