Skip to content

Instantly share code, notes, and snippets.

@natxopedreira
Created May 16, 2014 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natxopedreira/309d8cfd3a3f71617256 to your computer and use it in GitHub Desktop.
Save natxopedreira/309d8cfd3a3f71617256 to your computer and use it in GitHub Desktop.
average color from ofPixels
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