diff --git a/includes/quadtree.hpp b/includes/quadtree.hpp index e78c87f..2fd7119 100644 --- a/includes/quadtree.hpp +++ b/includes/quadtree.hpp @@ -28,7 +28,7 @@ class QuadTree { // Calcule la couleur qui apparaît majoritairement dans l'image SDL_Color calculeCouleur(SDL_Surface *); - // Vérifie si l'ont doit encore diviser l'image + // Vrai si tout les pixels de l'images sont identiques bool verificationEgalitee(SDL_Surface *); // Coupe l'image en 4 diff --git a/src/quadtree.cpp b/src/quadtree.cpp index be6bf8e..0d6de13 100644 --- a/src/quadtree.cpp +++ b/src/quadtree.cpp @@ -85,8 +85,28 @@ SDL_Color QuadTree::calculeCouleur(SDL_Surface * s) { return color; } -bool QuadTree::verificationEgalitee(SDL_Surface *) { - // Temporaire +bool QuadTree::verificationEgalitee(SDL_Surface * s) { + if(SDL_LockSurface(s) == 0) { + SDL_Color dernier; + for(int x = 0; x < s->w; ++x) { + for(int y = 0; y < s->h; ++y) { + SDL_Color actuel; + SDL_GetRGB(*reinterpret_cast( + static_cast(s->pixels) + y * s->pitch + x * s->format->BytesPerPixel + ), s->format, &actuel.r, &actuel.g, &actuel.b); + + if(x != 0 && y != 0) { + if(dernier.r != actuel.r && dernier.g != actuel.g && dernier.b != actuel.b) { + return false; + } + } + dernier = actuel; + } + } + + SDL_UnlockSurface(s); + } + return true; }