Determine the average color of the image

This commit is contained in:
Mylloon 2022-05-09 10:54:54 +02:00
parent 0ddb373b3d
commit cdf531131e
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -58,9 +58,31 @@ SDL_Surface * QuadTree::image(short niveau_p) {
return nouvelle_image; return nouvelle_image;
} }
SDL_Color QuadTree::calculeCouleur(SDL_Surface *) { SDL_Color QuadTree::calculeCouleur(SDL_Surface * s) {
// Temporaire int r = 0, g = 0, b = 0;
return SDL_Color(); 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 *>(
static_cast<Uint8 *>(s->pixels) + y * s->pitch + x * s->format->BytesPerPixel
), s->format, &r_temp, &g_temp, &b_temp);
r += r_temp;
g += g_temp;
b += b_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;
} }
bool QuadTree::verificationEgalitee(SDL_Surface *) { bool QuadTree::verificationEgalitee(SDL_Surface *) {