Validate that pixel formats have the correct attributes

Also added a test to save and load as BMP format to make sure pixel transformations are working correctly.

Fixes https://github.com/libsdl-org/SDL/issues/11483
This commit is contained in:
Sam Lantinga
2024-11-17 08:53:20 -08:00
parent bd57cfdb55
commit e027b85cc4
4 changed files with 677 additions and 91 deletions

View File

@@ -664,17 +664,8 @@ bool SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio)
SDL_BITSPERPIXEL(surface->format));
goto done;
}
} else if ((SDL_BITSPERPIXEL(surface->format) == 24) && !save32bit &&
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
(surface->fmt->Rmask == 0x00FF0000) &&
(surface->fmt->Gmask == 0x0000FF00) &&
(surface->fmt->Bmask == 0x000000FF)
#else
(surface->fmt->Rmask == 0x000000FF) &&
(surface->fmt->Gmask == 0x0000FF00) &&
(surface->fmt->Bmask == 0x00FF0000)
#endif
) {
} else if ((surface->format == SDL_PIXELFORMAT_BGR24 && !save32bit) ||
(surface->format == SDL_PIXELFORMAT_BGRA32 && save32bit)) {
intermediate_surface = surface;
} else {
SDL_PixelFormat pixel_format;

View File

@@ -2597,6 +2597,7 @@ bool SDL_ClearSurface(SDL_Surface *surface, float r, float g, float b, float a)
goto done;
}
SDL_SetSurfaceColorspace(tmp, surface->colorspace);
SDL_SetSurfaceBlendMode(tmp, SDL_BLENDMODE_NONE);
float *pixels = (float *)tmp->pixels;
pixels[0] = r;