Determine the average color of the image
This commit is contained in:
parent
0ddb373b3d
commit
cdf531131e
1 changed files with 25 additions and 3 deletions
|
@ -58,9 +58,31 @@ SDL_Surface * QuadTree::image(short niveau_p) {
|
||||||
return nouvelle_image;
|
return nouvelle_image;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Color QuadTree::calculeCouleur(SDL_Surface *) {
|
SDL_Color QuadTree::calculeCouleur(SDL_Surface * s) {
|
||||||
// Temporaire
|
int r = 0, g = 0, b = 0;
|
||||||
return SDL_Color();
|
if(SDL_LockSurface(s) == 0) {
|
||||||
|
for(int x = 0; x < s->w; ++x) {
|
||||||
|
for(int y = 0; y < s->h; ++y) {
|
||||||
|
Uint8 r_temp, g_temp, b_temp;
|
||||||
|
SDL_GetRGB(*reinterpret_cast<Uint32 *>(
|
||||||
|
static_cast<Uint8 *>(s->pixels) + y * s->pitch + x * s->format->BytesPerPixel
|
||||||
|
), s->format, &r_temp, &g_temp, &b_temp);
|
||||||
|
r += r_temp;
|
||||||
|
g += g_temp;
|
||||||
|
b += b_temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_UnlockSurface(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_Color color;
|
||||||
|
int diviseur = s->w * s->h;
|
||||||
|
color.r = floor(r / diviseur);
|
||||||
|
color.g = floor(g / diviseur);
|
||||||
|
color.b = floor(b / diviseur);
|
||||||
|
|
||||||
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QuadTree::verificationEgalitee(SDL_Surface *) {
|
bool QuadTree::verificationEgalitee(SDL_Surface *) {
|
||||||
|
|
Reference in a new issue