Created
May 16, 2014 09:11
-
-
Save natxopedreira/309d8cfd3a3f71617256 to your computer and use it in GitHub Desktop.
average color from ofPixels
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
ofColor getAverageColor(const ofPixels & pix) { | |
int pixelSize = pix.size(); | |
int r = 0, g = 0, b = 0; | |
for (int i=0; i<pixelSize; i++) { | |
ofColor c = pix[i]; | |
r += (c >> 16) & 0xFF; | |
g += (c >> 8) & 0xFF; | |
b += c & 0xFF; | |
} | |
r /= pixelSize; | |
g /= pixelSize; | |
b /= pixelSize; | |
return ofColor(r, g, b); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment