Modifications
- Remove destructor - Remove temporary code - Fix crash when saving quadtree, better readability
This commit is contained in:
parent
9e89f0f943
commit
00fc4df7ca
2 changed files with 15 additions and 38 deletions
|
@ -40,8 +40,6 @@ class QuadTree {
|
|||
public:
|
||||
QuadTree(SDL_Surface *, short = 0);
|
||||
|
||||
~QuadTree(void);
|
||||
|
||||
// Renvoie l'image avec un certain niveau de compression
|
||||
SDL_Surface * image(short);
|
||||
};
|
||||
|
|
|
@ -26,21 +26,6 @@ QuadTree::QuadTree(SDL_Surface * image, short niveau_p): niveau(niveau_p), coule
|
|||
}
|
||||
}
|
||||
|
||||
QuadTree::~QuadTree(void) {
|
||||
/* if(nord_ouest != nullptr) {
|
||||
delete nord_ouest;
|
||||
}
|
||||
if(nord_est != nullptr) {
|
||||
delete nord_est;
|
||||
}
|
||||
if(sud_ouest != nullptr) {
|
||||
delete sud_ouest;
|
||||
}
|
||||
if(sud_est != nullptr) {
|
||||
delete sud_est;
|
||||
} */
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -154,30 +139,31 @@ std::array<SDL_Surface *, 4> QuadTree::coupeEnQuatre(SDL_Surface * s) {
|
|||
return resultat;
|
||||
}
|
||||
|
||||
#include <string>
|
||||
SDL_Surface * QuadTree::colleQuatreImages(std::array<SDL_Surface *, 4> morceaux) {
|
||||
// Récupère la hauteur/largeur de l'image qui est composé des 4 sous-images
|
||||
// Double les dimensions des morceaux en diagonale (ici NO et SE)
|
||||
int largeur = (morceaux[0]->w * 2 == morceaux[3]->w * 2) ? morceaux[0]->w * 2 : -1;
|
||||
int hauteur = (morceaux[0]->h * 2 == morceaux[3]->h * 2) ? morceaux[0]->w * 2 : -1;
|
||||
// Double les dimensions des morceaux en diagonale (ici NO et SE) si identique
|
||||
int double_NO_w = morceaux[0]->w * 2;
|
||||
int double_SE_w = morceaux[3]->w * 2;
|
||||
|
||||
int double_NO_h = morceaux[0]->h * 2;
|
||||
int double_SE_h = morceaux[3]->h * 2;
|
||||
|
||||
int largeur = (double_NO_w == double_SE_w) ? double_NO_w : -1;
|
||||
int hauteur = (double_NO_h == double_SE_h) ? double_NO_h : -1;
|
||||
|
||||
// Si dimensions différente alors on prend l'entre-deux
|
||||
if(largeur == -1) {
|
||||
int double_NO = morceaux[0]->w * 2;
|
||||
int double_SE = morceaux[3]->w * 2;
|
||||
if(double_NO > double_SE) {
|
||||
largeur = double_NO - 1;
|
||||
if(double_NO_w > double_SE_w) {
|
||||
largeur = double_NO_w - 1;
|
||||
} else {
|
||||
largeur = double_SE- 1;
|
||||
largeur = double_SE_w - 1;
|
||||
}
|
||||
}
|
||||
if(hauteur == -1) {
|
||||
int double_NO = morceaux[0]->h * 2;
|
||||
int double_SE = morceaux[3]->h * 2;
|
||||
if(double_NO > double_SE) {
|
||||
hauteur = double_NO - 1;
|
||||
if(double_NO_h > double_SE_h) {
|
||||
hauteur = double_NO_h - 1;
|
||||
} else {
|
||||
hauteur = double_SE - 1;
|
||||
hauteur = double_SE_h - 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -215,13 +201,6 @@ SDL_Surface * QuadTree::colleQuatreImages(std::array<SDL_Surface *, 4> morceaux)
|
|||
SDL_UnlockSurface(nouvelle_image);
|
||||
}
|
||||
|
||||
// Temporaire
|
||||
for(Uint32 i = 0; i < morceaux.size(); ++i) {
|
||||
std::string chemin = std::to_string(i) + ".png";
|
||||
IMG_SavePNG(morceaux[i], chemin.c_str());
|
||||
}
|
||||
IMG_SavePNG(nouvelle_image, "4.png");
|
||||
|
||||
for(auto it: morceaux) {
|
||||
SDL_FreeSurface(it);
|
||||
}
|
||||
|
|
Reference in a new issue