diff --git a/src/quadtree.cpp b/src/quadtree.cpp index edb53d2..be6bf8e 100644 --- a/src/quadtree.cpp +++ b/src/quadtree.cpp @@ -58,9 +58,31 @@ SDL_Surface * QuadTree::image(short niveau_p) { return nouvelle_image; } -SDL_Color QuadTree::calculeCouleur(SDL_Surface *) { - // Temporaire - return SDL_Color(); +SDL_Color QuadTree::calculeCouleur(SDL_Surface * s) { + int r = 0, g = 0, b = 0; + 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( + static_cast(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 *) {