diff --git a/includes/quadtree.hpp b/includes/quadtree.hpp index fc3321b..6e026b9 100644 --- a/includes/quadtree.hpp +++ b/includes/quadtree.hpp @@ -25,6 +25,9 @@ class QuadTree { // Est vrai si l'on ne doit pas diviser la surface bool final; + // Format de l'image (SDL_PixelFormatEnum) + Uint32 format; + // Calcule la couleur qui apparaît majoritairement dans la surface SDL_Color calculeCouleur(SDL_Surface *); diff --git a/src/quadtree.cpp b/src/quadtree.cpp index ae00da1..a661ca5 100644 --- a/src/quadtree.cpp +++ b/src/quadtree.cpp @@ -1,20 +1,10 @@ #include "../includes/quadtree.hpp" -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - Uint32 r_mask = 0xff000000; - Uint32 g_mask = 0x00ff0000; - Uint32 b_mask = 0x0000ff00; - Uint32 a_mask = 0x000000ff; -#else - Uint32 r_mask = 0x000000ff; - Uint32 g_mask = 0x0000ff00; - Uint32 b_mask = 0x00ff0000; - Uint32 a_mask = 0xff000000; -#endif - QuadTree::QuadTree(SDL_Surface * image, short niveau_p): niveau(niveau_p), couleur(calculeCouleur(image)), dimensions(image->w, image->h), nord_ouest(nullptr), nord_est(nullptr), sud_ouest(nullptr), sud_est(nullptr), - final(true) { + final(true), format(SDL_PIXELFORMAT_RGB888) { + // *reinterpret_cast(image->format) + // SDL_PIXELFORMAT_RGB888 -> noir et blanc if(!verificationEgalitee(image)) { std::array image_coupe = coupeEnQuatre(image); @@ -28,7 +18,7 @@ QuadTree::QuadTree(SDL_Surface * image, short niveau_p): niveau(niveau_p), coule SDL_Surface * QuadTree::image(short niveau_p) { if(final || niveau == niveau_p) { - SDL_Surface * couleur_unie = SDL_CreateRGBSurface(0, dimensions.first, dimensions.second, 32, r_mask, g_mask, b_mask, a_mask); + SDL_Surface * couleur_unie = SDL_CreateRGBSurfaceWithFormat(0, dimensions.first, dimensions.second, 32, format); if(SDL_LockSurface(couleur_unie) == 0) { SDL_memset(couleur_unie->pixels, static_cast( SDL_MapRGBA(couleur_unie->format, couleur.r, couleur.g, couleur.b, 255) @@ -116,10 +106,10 @@ std::array QuadTree::coupeEnQuatre(SDL_Surface * s) { // Création d'une nouvelle surface // Copie pixel par pixel de la surface mère vers la surface fille // Stockage de la nouvelle surface dans l'array `resultat` - SDL_Surface * nouvelle_image = SDL_CreateRGBSurface(0, + SDL_Surface * nouvelle_image = SDL_CreateRGBSurfaceWithFormat(0, coordonnes_quadrants[i][2] - coordonnes_quadrants[i][0], coordonnes_quadrants[i][3] - coordonnes_quadrants[i][1], - 32, r_mask, g_mask, b_mask, a_mask); + 32, format); if(SDL_LockSurface(nouvelle_image) == 0) { for(int x = 0; x < nouvelle_image->w; ++x) { @@ -168,7 +158,7 @@ SDL_Surface * QuadTree::colleQuatreImages(std::array morceaux) } } - SDL_Surface * nouvelle_image = SDL_CreateRGBSurface(0, largeur, hauteur, 32, r_mask, g_mask, b_mask, a_mask); + SDL_Surface * nouvelle_image = SDL_CreateRGBSurfaceWithFormat(0, largeur, hauteur, 32, format); // Copie chacun son tour les morceaux d'image dans l'image if(SDL_LockSurface(nouvelle_image) == 0) {