#include <cassert> #include <stdlib.h> #include <stdio.h> #include <SDL/SDL.h> #include "SDL_image.h" Uint32 getpixel(const SDL_Surface* surface, int x, int y) { const int bpp = surface->format->BytesPerPixel; /* Here p is the address to the pixel we want to retrieve */ const Uint8* p = (Uint8*)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: return *p; case 2: return *(Uint16*)p; case 3: if(SDL_BYTEORDER == SDL_BIG_ENDIAN) return p[0] << 16 | p[1] << 8 | p[2]; return p[0] | p[1] << 8 | p[2] << 16; case 4: return *(Uint32*)p; default: assert(false && "Shouldn't be reached!"); return 0; } return 0; } int main (void) { int i, j; SDL_Surface* img = NULL; Uint32 couleur, echantillon; img = IMG_Load("images/rond.bmp"); echantillon = getpixel(img, 80, 80); couleur = SDL_MapRGB(img->format, 0, 255, 9); for (i = 0; i < img->h; ++i) for (j = 0; j < img->w; ++j) if (echantillon == getpixel(img, j, i)) *((Uint32*)img->pixels + (img->h * i) + j) = couleur; SDL_SaveBMP(img, "image.bmp"); //SDL_SavePNG(img, "image.png"); cf fonction que je te propose ci-dessus. return 0; }
j'ai trouvé ma réponse finalement
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionvoid putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel) { int bpp = surface->format->BytesPerPixel; /* Here p is the address to the pixel we want to set */ Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch(bpp) { case 1: *p = pixel; break; case 2: *(Uint16 *)p = pixel; break; case 3: if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break; case 4: *(Uint32 *)p = pixel; break; } }