diff --git a/src/quadtree.cpp b/src/quadtree.cpp index dc0ed97..ae00da1 100644 --- a/src/quadtree.cpp +++ b/src/quadtree.cpp @@ -31,7 +31,7 @@ SDL_Surface * QuadTree::image(short niveau_p) { SDL_Surface * couleur_unie = SDL_CreateRGBSurface(0, dimensions.first, dimensions.second, 32, r_mask, g_mask, b_mask, a_mask); if(SDL_LockSurface(couleur_unie) == 0) { SDL_memset(couleur_unie->pixels, static_cast( - SDL_MapRGB(couleur_unie->format, couleur.r, couleur.g, couleur.b) + SDL_MapRGBA(couleur_unie->format, couleur.r, couleur.g, couleur.b, 255) ), static_cast(couleur_unie->h * couleur_unie->pitch)); SDL_UnlockSurface(couleur_unie); @@ -51,30 +51,31 @@ SDL_Surface * QuadTree::image(short niveau_p) { } SDL_Color QuadTree::calculeCouleur(SDL_Surface * s) { - int r = 0, g = 0, b = 0; + int r = 0, g = 0, b = 0, a = 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( + Uint8 r_temp, g_temp, b_temp, a_temp; + SDL_GetRGBA(*reinterpret_cast( static_cast(s->pixels) + y * s->pitch + x * s->format->BytesPerPixel - ), s->format, &r_temp, &g_temp, &b_temp); + ), s->format, &r_temp, &g_temp, &b_temp, &a_temp); r += r_temp; g += g_temp; b += b_temp; + a += a_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; + return SDL_Color{ + static_cast(r / diviseur), + static_cast(g / diviseur), + static_cast(b / diviseur), + static_cast(a / diviseur), + }; } bool QuadTree::verificationEgalitee(SDL_Surface * s) {