1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| /**
* @brief écrit la couleur au position (x,y) d'une surface SDL
*
* @param surface la surface SDL
* @param x la position horizontale
* @param y la position verticale
* @param pixel la nouvelle couleur au format Uint32
*/
void SDL_EcrireCouleurAux(SDL_Surface* surface, int x, int y, Uint32 pixel)
{
int bpp = surface->format->BytesPerPixel;
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;
}
}
/**
* @brief écrit la couleur au position (x,y) d'une surface SDL
*
* @param surface la surface SDL
* @param x la position horizontale
* @param y la position verticale
* @param r la composante rouge du pixel
* @param g la composante verte du pixel
* @param b la composante bleu du pixel
*/
void SDL_EcrireCouleur(SDL_Surface* surface, int x, int y, int r, int g, int b)
{
SDL_EcrireCouleurAux(surface, x, y,
SDL_MapRGB(surface->format, r, g, b));
} |
Partager