transparency support (WIP)
This commit is contained in:
parent
94d34336ae
commit
0f56b3386d
1 changed files with 12 additions and 11 deletions
|
@ -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<int>(
|
||||
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<size_t>(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<Uint32 *>(
|
||||
Uint8 r_temp, g_temp, b_temp, a_temp;
|
||||
SDL_GetRGBA(*reinterpret_cast<Uint32 *>(
|
||||
static_cast<Uint8 *>(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<Uint8>(r / diviseur),
|
||||
static_cast<Uint8>(g / diviseur),
|
||||
static_cast<Uint8>(b / diviseur),
|
||||
static_cast<Uint8>(a / diviseur),
|
||||
};
|
||||
}
|
||||
|
||||
bool QuadTree::verificationEgalitee(SDL_Surface * s) {
|
||||
|
|
Reference in a new issue