[SDL] Possible bug in FillRect?

Rob Probin rob at lightsoft.co.uk
Sun Jul 17 12:28:38 PDT 2011

  Anyone else see this? Am I just going a bit mad - entirely possible :-)

If you are doing this:
SDL_MapRGB(new_surface->format,r,g,b)); // (I know the second parameter 
could be NULL here)

On a 24 bit pixel surface (e.g. SDL_PIXELFORMAT_BGR24 or 

You get down to this routine (v1.3.0 build 5557 I think):

    static void
    SDL_FillRect3(Uint8 * pixels, int pitch, Uint32 color, int w, int h)
    Uint8 r = (Uint8) ((color >> 16) & 0xFF);
    Uint8 g = (Uint8) ((color >> 8) & 0xFF);
    Uint8 b = (Uint8) (color & 0xFF);

    while (h--) {
    int n = w;
    Uint8 *p = pixels;

    while (n--) {
    *p++ = r;
    *p++ = g;
    *p++ = b;
    pixels += pitch;

A Note from the comments for SDL_FillRect in the header ...
* The color should be a pixel of the format used by the surface, and
* can be generated by the SDL_MapRGB() function.

Ironically, due to the SDL_MapRGB, the decode of r g b in SDL_FillRect3 
is wrong for both BGR24 and RGB24!!!


P.S. I was using the just as a temporary working surface in order to 
modify one colour of the image to another. The work around I've used is 
to move to SDL_PIXELFORMAT_BGR888. However, I think a SDL_LoadBMP() will 
return one of these surfaces so it's not impossible to hit this by 
accident (which is how I ended up there...).

The alternative - swap b and r in the SDL_MapRGB() - looks like it would 
break once this (possible) bug is fixed.

P.P.S. [Apologies if this is a duplicate post ... different email 
accounts, and all that]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20110717/b516fc28/attachment-0007.htm>

More information about the SDL mailing list