diff --git a/WhatsNew.txt b/WhatsNew.txt index 833e28bd4..44fc5ef13 100644 --- a/WhatsNew.txt +++ b/WhatsNew.txt @@ -19,13 +19,19 @@ General: * SDL_RWFromFP() * SDL_SetWindowBrightness() * SDL_SetWindowGammaRamp() + * SDL_CreateRGBSurface() + * SDL_CreateRGBSurfaceWithFormat() + * SDL_CreateRGBSurfaceFrom() + * SDL_CreateRGBSurfaceWithFormatFrom() * Removed the following hints from the API, see docs/README-migration.md for details: * SDL_HINT_IDLE_TIMER_DISABLED * SDL_HINT_VIDEO_X11_FORCE_EGL * SDL_HINT_VIDEO_X11_XINERAMA * SDL_HINT_VIDEO_X11_XVIDMODE * SDL_stdinc.h no longer includes stdio.h, stdlib.h, etc., it only provides the SDL C runtime functionality -* Removed unused 'depth' parameter from SDL_CreateRGBSurfaceWithFormat and SDL_CreateRGBSurfaceWithFormatFrom -* Removed unused 'flags' parameter from SDL_CreateRGBSurface and SDL_CreateRGBSurfaceWithFormat * Removed unused 'flags' parameter from SDL_ConvertSurface and SDL_ConvertSurfaceFormat +* Added SDL_CreateSurface() and SDL_CreateSurfaceFrom() which take a format. SDL_CreateRGBSurface*() are removed. + + + diff --git a/Xcode-iOS/Demos/src/fireworks.c b/Xcode-iOS/Demos/src/fireworks.c index dbb86f392..43427b49e 100644 --- a/Xcode-iOS/Demos/src/fireworks.c +++ b/Xcode-iOS/Demos/src/fireworks.c @@ -327,8 +327,6 @@ void initializeTexture() { - int bpp; /* texture bits per pixel */ - Uint32 Rmask, Gmask, Bmask, Amask; /* masks for pixel format passed into OpenGL */ SDL_Surface *bmp_surface; /* the bmp is loaded here */ SDL_Surface *bmp_surface_rgba8888; /* this serves as a destination to convert the BMP to format passed into OpenGL */ @@ -338,13 +336,9 @@ initializeTexture() fatalError("could not load stroke.bmp"); } - /* Grab info about format that will be passed into OpenGL */ - SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_ABGR8888, &bpp, &Rmask, &Gmask, - &Bmask, &Amask); /* Create surface that will hold pixels passed into OpenGL */ - bmp_surface_rgba8888 = - SDL_CreateRGBSurface(bmp_surface->w, bmp_surface->h, bpp, Rmask, - Gmask, Bmask, Amask); + bmp_surface_rgba8888 = SDL_CreateSurface(bmp_surface->w, bmp_surface->h, SDL_PIXELFORMAT_ABGR8888); + /* Blit to this surface, effectively converting the format */ SDL_BlitSurface(bmp_surface, NULL, bmp_surface_rgba8888, NULL); diff --git a/Xcode-iOS/Demos/src/keyboard.c b/Xcode-iOS/Demos/src/keyboard.c index e9896977d..2d0ae841c 100644 --- a/Xcode-iOS/Demos/src/keyboard.c +++ b/Xcode-iOS/Demos/src/keyboard.c @@ -173,13 +173,9 @@ loadFont(void) SDL_SetColorKey(surface, 1, SDL_MapRGB(surface->format, 238, 0, 252)); /* now we convert the surface to our desired pixel format */ int format = SDL_PIXELFORMAT_ABGR8888; /* desired texture format */ - Uint32 Rmask, Gmask, Bmask, Amask; /* masks for desired format */ - int bpp; /* bits per pixel for desired format */ - SDL_PixelFormatEnumToMasks(format, &bpp, &Rmask, &Gmask, &Bmask, - &Amask); - SDL_Surface *converted = - SDL_CreateRGBSurface(surface->w, surface->h, bpp, Rmask, Gmask, - Bmask, Amask); + + SDL_Surface *converted = SDL_CreateSurface(surface->w, surface->h, format); + SDL_BlitSurface(surface, NULL, converted, NULL); /* create our texture */ texture = SDL_CreateTextureFromSurface(renderer, converted); diff --git a/docs/README-migration.md b/docs/README-migration.md index d7aeb5c08..1016004c3 100644 --- a/docs/README-migration.md +++ b/docs/README-migration.md @@ -162,9 +162,38 @@ M_PI is no longer defined in SDL_stdinc.h, you can use the new symbols SDL_PI_D ## SDL_surface.h -Removed unused 'depth' parameter from SDL_CreateRGBSurfaceWithFormat() and SDL_CreateRGBSurfaceWithFormatFrom() -Removed unused 'flags' parameter from SDL_CreateRGBSurface() and SDL_CreateRGBSurfaceWithFormat() -Removed unused 'flags' parameter from SDL_ConvertSurface and SDL_ConvertSurfaceFormat +Removed unused 'flags' parameter from SDL_ConvertSurface and SDL_ConvertSurfaceFormat. + + +Added SDL_CreateSurface() and SDL_CreateSurfaceFrom() which take a format. +SDL_CreateRGBSurface(), SDL_CreateRGBSurfaceFrom(), SDL_CreateRGBSurfaceWithFormat() and SDL_CreateRGBSurfaceWithFormatFrom() are removed. + +This code: + +```c +SDL_Surface *surface = SDL_CreateRGBSurface(0, width, height, 0, Rmask, Gmask, Bmask, Amask); +``` + +can be replaced with this: + +```c +Uint32 format = SDL_MasksToPixelFormatEnum(0, Rmask, Gmask, Bmask, Amask); +SDL_Surface *surface = SDL_CreateSurface(width, height, format); +``` + +but in general, you probably have a format that you know you're using, possibly one of these: + + +```c +// Various mask (R, G, B, A) in little endian and their corresponding format: +0xFF000000 0x00FF0000 0x0000FF00 0x000000FF => SDL_PIXELFORMAT_RGBA8888 +0x000000FF 0x0000FF00 0x00FF0000 0xFF000000 => SDL_PIXELFORMAT_ABGR8888 +0x00FF0000 0x0000FF00 0x000000FF 0xFF000000 => SDL_PIXELFORMAT_ARGB8888 +0x00FF0000 0x0000FF00 0x000000FF 0x00000000 => SDL_PIXELFORMAT_BGR24 +0x000000FF 0x0000FF00 0x000000FF 0x00000000 => SDL_PIXELFORMAT_RGB24 +0x00007C00 00000x03E0 00000x001F 0x00000000 => SDL_PIXELFORMAT_RGB555 +0x00007C00 00000x03E0 00000x001F 0x00008000 => SDL_PIXELFORMAT_ARGB1555 +``` ## SDL_syswm.h diff --git a/include/SDL3/SDL_pixels.h b/include/SDL3/SDL_pixels.h index 0f041e846..39045094f 100644 --- a/include/SDL3/SDL_pixels.h +++ b/include/SDL3/SDL_pixels.h @@ -468,7 +468,7 @@ extern DECLSPEC int SDLCALL SDL_SetPixelFormatPalette(SDL_PixelFormat * format, * \since This function is available since SDL 3.0.0. * * \sa SDL_AllocPalette - * \sa SDL_CreateRGBSurface + * \sa SDL_CreateSurface */ extern DECLSPEC int SDLCALL SDL_SetPaletteColors(SDL_Palette * palette, const SDL_Color * colors, diff --git a/include/SDL3/SDL_surface.h b/include/SDL3/SDL_surface.h index c2d832b49..32d833137 100644 --- a/include/SDL3/SDL_surface.h +++ b/include/SDL3/SDL_surface.h @@ -113,61 +113,9 @@ typedef enum SDL_YUV_CONVERSION_AUTOMATIC /**< BT.601 for SD content, BT.709 for HD content */ } SDL_YUV_CONVERSION_MODE; -/** - * Allocate a new RGB surface. - * - * If `depth` is 4 or 8 bits, an empty palette is allocated for the surface. - * If `depth` is greater than 8 bits, the pixel format is set using the - * [RGBA]mask parameters. - * - * The [RGBA]mask parameters are the bitmasks used to extract that color from - * a pixel. For instance, `Rmask` being 0xFF000000 means the red data is - * stored in the most significant byte. Using zeros for the RGB masks sets a - * default value, based on the depth. For example: - * - * ```c++ - * SDL_CreateRGBSurface(0,w,h,32,0,0,0,0); - * ``` - * - * However, using zero for the Amask results in an Amask of 0. - * - * By default surfaces with an alpha mask are set up for blending as with: - * - * ```c++ - * SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND) - * ``` - * - * You can change this by calling SDL_SetSurfaceBlendMode() and selecting a - * different `blendMode`. - * - * \param width the width of the surface - * \param height the height of the surface - * \param depth the depth of the surface in bits - * \param Rmask the red mask for the pixels - * \param Gmask the green mask for the pixels - * \param Bmask the blue mask for the pixels - * \param Amask the alpha mask for the pixels - * \returns the new SDL_Surface structure that is created or NULL if it fails; - * call SDL_GetError() for more information. - * - * \since This function is available since SDL 3.0.0. - * - * \sa SDL_CreateRGBSurfaceFrom - * \sa SDL_CreateRGBSurfaceWithFormat - * \sa SDL_FreeSurface - */ -extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurface - (int width, int height, int depth, - Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask); - - /** * Allocate a new RGB surface with a specific pixel format. * - * This function operates mostly like SDL_CreateRGBSurface(), except instead - * of providing pixel color masks, you provide it with a predefined format - * from SDL_PixelFormatEnum. - * * \param width the width of the surface * \param height the height of the surface * \param format the SDL_PixelFormatEnum for the new surface's pixel format. @@ -176,59 +124,16 @@ extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurface * * \since This function is available since SDL 3.0.0. * - * \sa SDL_CreateRGBSurface - * \sa SDL_CreateRGBSurfaceFrom + * \sa SDL_CreateSurfaceFrom * \sa SDL_FreeSurface */ -extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceWithFormat +extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateSurface (int width, int height, Uint32 format); -/** - * Allocate a new RGB surface with existing pixel data. - * - * This function operates mostly like SDL_CreateRGBSurface(), except it does - * not allocate memory for the pixel data, instead the caller provides an - * existing buffer of data for the surface to use. - * - * No copy is made of the pixel data. Pixel data is not managed automatically; - * you must free the surface before you free the pixel data. - * - * \param pixels a pointer to existing pixel data - * \param width the width of the surface - * \param height the height of the surface - * \param depth the depth of the surface in bits - * \param pitch the pitch of the surface in bytes - * \param Rmask the red mask for the pixels - * \param Gmask the green mask for the pixels - * \param Bmask the blue mask for the pixels - * \param Amask the alpha mask for the pixels - * \returns the new SDL_Surface structure that is created or NULL if it fails; - * call SDL_GetError() for more information. - * - * \since This function is available since SDL 3.0.0. - * - * \sa SDL_CreateRGBSurface - * \sa SDL_CreateRGBSurfaceWithFormat - * \sa SDL_FreeSurface - */ -extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceFrom(void *pixels, - int width, - int height, - int depth, - int pitch, - Uint32 Rmask, - Uint32 Gmask, - Uint32 Bmask, - Uint32 Amask); - /** * Allocate a new RGB surface with with a specific pixel format and existing * pixel data. * - * This function operates mostly like SDL_CreateRGBSurfaceFrom(), except - * instead of providing pixel color masks, you provide it with a predefined - * format from SDL_PixelFormatEnum. - * * No copy is made of the pixel data. Pixel data is not managed automatically; * you must free the surface before you free the pixel data. * @@ -242,11 +147,10 @@ extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceFrom(void *pixels, * * \since This function is available since SDL 3.0.0. * - * \sa SDL_CreateRGBSurfaceFrom - * \sa SDL_CreateRGBSurfaceWithFormat + * \sa SDL_CreateSurface * \sa SDL_FreeSurface */ -extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceWithFormatFrom +extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateSurfaceFrom (void *pixels, int width, int height, int pitch, Uint32 format); /** @@ -258,8 +162,8 @@ extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceWithFormatFrom * * \since This function is available since SDL 3.0.0. * - * \sa SDL_CreateRGBSurface - * \sa SDL_CreateRGBSurfaceFrom + * \sa SDL_CreateSurface + * \sa SDL_CreateSurfaceFrom * \sa SDL_LoadBMP * \sa SDL_LoadBMP_RW */ @@ -660,7 +564,7 @@ extern DECLSPEC SDL_Surface *SDLCALL SDL_DuplicateSurface(SDL_Surface * surface) * * \sa SDL_AllocFormat * \sa SDL_ConvertSurfaceFormat - * \sa SDL_CreateRGBSurface + * \sa SDL_CreateSurface */ extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurface (SDL_Surface * src, const SDL_PixelFormat * fmt); @@ -683,7 +587,7 @@ extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurface * * \sa SDL_AllocFormat * \sa SDL_ConvertSurface - * \sa SDL_CreateRGBSurface + * \sa SDL_CreateSurface */ extern DECLSPEC SDL_Surface *SDLCALL SDL_ConvertSurfaceFormat (SDL_Surface * src, Uint32 pixel_format); diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h index f2c4d0c54..a021787a6 100644 --- a/src/dynapi/SDL_dynapi_overrides.h +++ b/src/dynapi/SDL_dynapi_overrides.h @@ -437,8 +437,6 @@ #define SDL_iconv_close SDL_iconv_close_REAL #define SDL_iconv SDL_iconv_REAL #define SDL_iconv_string SDL_iconv_string_REAL -#define SDL_CreateRGBSurface SDL_CreateRGBSurface_REAL -#define SDL_CreateRGBSurfaceFrom SDL_CreateRGBSurfaceFrom_REAL #define SDL_FreeSurface SDL_FreeSurface_REAL #define SDL_SetSurfacePalette SDL_SetSurfacePalette_REAL #define SDL_LockSurface SDL_LockSurface_REAL @@ -592,8 +590,8 @@ #define SDL_RenderGetIntegerScale SDL_RenderGetIntegerScale_REAL #define SDL_DequeueAudio SDL_DequeueAudio_REAL #define SDL_SetWindowResizable SDL_SetWindowResizable_REAL -#define SDL_CreateRGBSurfaceWithFormat SDL_CreateRGBSurfaceWithFormat_REAL -#define SDL_CreateRGBSurfaceWithFormatFrom SDL_CreateRGBSurfaceWithFormatFrom_REAL +#define SDL_CreateSurface SDL_CreateSurface_REAL +#define SDL_CreateSurfaceFrom SDL_CreateSurfaceFrom_REAL #define SDL_GetHintBoolean SDL_GetHintBoolean_REAL #define SDL_JoystickGetDeviceVendor SDL_JoystickGetDeviceVendor_REAL #define SDL_JoystickGetDeviceProduct SDL_JoystickGetDeviceProduct_REAL diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h index 2e704ebfb..389c3b35d 100644 --- a/src/dynapi/SDL_dynapi_procs.h +++ b/src/dynapi/SDL_dynapi_procs.h @@ -464,8 +464,6 @@ SDL_DYNAPI_PROC(SDL_iconv_t,SDL_iconv_open,(const char *a, const char *b),(a,b), SDL_DYNAPI_PROC(int,SDL_iconv_close,(SDL_iconv_t a),(a),return) SDL_DYNAPI_PROC(size_t,SDL_iconv,(SDL_iconv_t a, const char **b, size_t *c, char **d, size_t *e),(a,b,c,d,e),return) SDL_DYNAPI_PROC(char*,SDL_iconv_string,(const char *a, const char *b, const char *c, size_t d),(a,b,c,d),return) -SDL_DYNAPI_PROC(SDL_Surface*,SDL_CreateRGBSurface,(int a, int b, int c, Uint32 d, Uint32 e, Uint32 f, Uint32 g),(a,b,c,d,e,f,g),return) -SDL_DYNAPI_PROC(SDL_Surface*,SDL_CreateRGBSurfaceFrom,(void *a, int b, int c, int d, int e, Uint32 f, Uint32 g, Uint32 h, Uint32 i),(a,b,c,d,e,f,g,h,i),return) SDL_DYNAPI_PROC(void,SDL_FreeSurface,(SDL_Surface *a),(a),) SDL_DYNAPI_PROC(int,SDL_SetSurfacePalette,(SDL_Surface *a, SDL_Palette *b),(a,b),return) SDL_DYNAPI_PROC(int,SDL_LockSurface,(SDL_Surface *a),(a),return) @@ -625,8 +623,8 @@ SDL_DYNAPI_PROC(int,SDL_RenderSetIntegerScale,(SDL_Renderer *a, SDL_bool b),(a,b SDL_DYNAPI_PROC(SDL_bool,SDL_RenderGetIntegerScale,(SDL_Renderer *a),(a),return) SDL_DYNAPI_PROC(Uint32,SDL_DequeueAudio,(SDL_AudioDeviceID a, void *b, Uint32 c),(a,b,c),return) SDL_DYNAPI_PROC(void,SDL_SetWindowResizable,(SDL_Window *a, SDL_bool b),(a,b),) -SDL_DYNAPI_PROC(SDL_Surface*,SDL_CreateRGBSurfaceWithFormat,(int a, int b, Uint32 c),(a,b,c),return) -SDL_DYNAPI_PROC(SDL_Surface*,SDL_CreateRGBSurfaceWithFormatFrom,(void *a, int b, int c, int d, Uint32 e),(a,b,c,d,e),return) +SDL_DYNAPI_PROC(SDL_Surface*,SDL_CreateSurface,(int a, int b, Uint32 c),(a,b,c),return) +SDL_DYNAPI_PROC(SDL_Surface*,SDL_CreateSurfaceFrom,(void *a, int b, int c, int d, Uint32 e),(a,b,c,d,e),return) SDL_DYNAPI_PROC(SDL_bool,SDL_GetHintBoolean,(const char *a, SDL_bool b),(a,b),return) SDL_DYNAPI_PROC(Uint16,SDL_JoystickGetDeviceVendor,(int a),(a),return) SDL_DYNAPI_PROC(Uint16,SDL_JoystickGetDeviceProduct,(int a),(a),return) diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c index cded60d04..b9d7bf02e 100644 --- a/src/events/SDL_mouse.c +++ b/src/events/SDL_mouse.c @@ -1221,11 +1221,7 @@ SDL_CreateCursor(const Uint8 *data, const Uint8 *mask, w = ((w + 7) & ~7); /* Create the surface from a bitmap */ - surface = SDL_CreateRGBSurface(w, h, 32, - 0x00FF0000, - 0x0000FF00, - 0x000000FF, - 0xFF000000); + surface = SDL_CreateSurface(w, h, SDL_PIXELFORMAT_ARGB8888); if (surface == NULL) { return NULL; } diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c index 0962bbe38..21b51f6c0 100644 --- a/src/render/SDL_render.c +++ b/src/render/SDL_render.c @@ -2077,7 +2077,7 @@ int SDL_LockTextureToSurface(SDL_Texture *texture, const SDL_Rect *rect, return ret; } - texture->locked_surface = SDL_CreateRGBSurfaceWithFormatFrom(pixels, real_rect.w, real_rect.h, pitch, texture->format); + texture->locked_surface = SDL_CreateSurfaceFrom(pixels, real_rect.w, real_rect.h, pitch, texture->format); if (texture->locked_surface == NULL) { SDL_UnlockTexture(texture); return -1; diff --git a/src/render/SDL_yuv_sw.c b/src/render/SDL_yuv_sw.c index d5a3f46dd..403bed504 100644 --- a/src/render/SDL_yuv_sw.c +++ b/src/render/SDL_yuv_sw.c @@ -377,32 +377,19 @@ int SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture *swdata, const SDL_Rect *srcrect, stretch = 1; } if (stretch) { - int bpp; - Uint32 Rmask, Gmask, Bmask, Amask; - if (swdata->display) { swdata->display->w = w; swdata->display->h = h; swdata->display->pixels = pixels; swdata->display->pitch = pitch; } else { - /* This must have succeeded in SDL_SW_SetupYUVDisplay() earlier */ - SDL_PixelFormatEnumToMasks(target_format, &bpp, &Rmask, &Gmask, - &Bmask, &Amask); - swdata->display = - SDL_CreateRGBSurfaceFrom(pixels, w, h, bpp, pitch, Rmask, - Gmask, Bmask, Amask); + swdata->display = SDL_CreateSurfaceFrom(pixels, w, h, pitch, target_format); if (!swdata->display) { return -1; } } if (!swdata->stretch) { - /* This must have succeeded in SDL_SW_SetupYUVDisplay() earlier */ - SDL_PixelFormatEnumToMasks(target_format, &bpp, &Rmask, &Gmask, - &Bmask, &Amask); - swdata->stretch = - SDL_CreateRGBSurface(swdata->w, swdata->h, bpp, Rmask, - Gmask, Bmask, Amask); + swdata->stretch = SDL_CreateSurface(swdata->w, swdata->h, target_format); if (!swdata->stretch) { return -1; } diff --git a/src/render/software/SDL_render_sw.c b/src/render/software/SDL_render_sw.c index 973674363..1241683ba 100644 --- a/src/render/software/SDL_render_sw.c +++ b/src/render/software/SDL_render_sw.c @@ -99,16 +99,12 @@ static int SW_GetOutputSize(SDL_Renderer *renderer, int *w, int *h) static int SW_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture) { - int bpp; - Uint32 Rmask, Gmask, Bmask, Amask; + SDL_Surface *surface = SDL_CreateSurface(texture->w, texture->h, texture->format); - if (!SDL_PixelFormatEnumToMasks(texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { - return SDL_SetError("Unknown texture format"); + if (surface == NULL) { + return SDL_SetError("Cannot create surface"); } - - texture->driverdata = - SDL_CreateRGBSurface(texture->w, texture->h, bpp, Rmask, Gmask, - Bmask, Amask); + texture->driverdata = surface; SDL_SetSurfaceColorMod(texture->driverdata, texture->color.r, texture->color.g, texture->color.b); SDL_SetSurfaceAlphaMod(texture->driverdata, texture->color.a); SDL_SetSurfaceBlendMode(texture->driverdata, texture->blendMode); @@ -116,7 +112,7 @@ static int SW_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture) /* Only RLE encode textures without an alpha channel since the RLE coder * discards the color values of pixels with an alpha value of zero. */ - if (texture->access == SDL_TEXTUREACCESS_STATIC && !Amask) { + if (texture->access == SDL_TEXTUREACCESS_STATIC && !surface->format->Amask) { SDL_SetSurfaceRLE(texture->driverdata, 1); } @@ -342,9 +338,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex /* Clone the source surface but use its pixel buffer directly. * The original source surface must be treated as read-only. */ - src_clone = SDL_CreateRGBSurfaceFrom(src->pixels, src->w, src->h, src->format->BitsPerPixel, src->pitch, - src->format->Rmask, src->format->Gmask, - src->format->Bmask, src->format->Amask); + src_clone = SDL_CreateSurfaceFrom(src->pixels, src->w, src->h, src->pitch, src->format->format); if (src_clone == NULL) { if (SDL_MUSTLOCK(src)) { SDL_UnlockSurface(src); @@ -387,8 +381,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex * to clear the pixels in the destination surface. The other steps are explained below. */ if (blendmode == SDL_BLENDMODE_NONE && !isOpaque) { - mask = SDL_CreateRGBSurface(final_rect->w, final_rect->h, 32, - 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); + mask = SDL_CreateSurface(final_rect->w, final_rect->h, SDL_PIXELFORMAT_ARGB8888); if (mask == NULL) { retval = -1; } else { @@ -401,8 +394,7 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex */ if (!retval && (blitRequired || applyModulation)) { SDL_Rect scale_rect = tmp_rect; - src_scaled = SDL_CreateRGBSurface(final_rect->w, final_rect->h, 32, - 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000); + src_scaled = SDL_CreateSurface(final_rect->w, final_rect->h, SDL_PIXELFORMAT_ARGB8888); if (src_scaled == NULL) { retval = -1; } else { @@ -482,10 +474,14 @@ static int SW_RenderCopyEx(SDL_Renderer *renderer, SDL_Surface *surface, SDL_Tex * to be created. This makes all source pixels opaque and the colors get copied correctly. */ SDL_Surface *src_rotated_rgb; - src_rotated_rgb = SDL_CreateRGBSurfaceFrom(src_rotated->pixels, src_rotated->w, src_rotated->h, - src_rotated->format->BitsPerPixel, src_rotated->pitch, - src_rotated->format->Rmask, src_rotated->format->Gmask, - src_rotated->format->Bmask, 0); + int f = SDL_MasksToPixelFormatEnum(src_rotated->format->BitsPerPixel, + src_rotated->format->Rmask, + src_rotated->format->Gmask, + src_rotated->format->Bmask, + 0); + + src_rotated_rgb = SDL_CreateSurfaceFrom(src_rotated->pixels, src_rotated->w, src_rotated->h, + src_rotated->pitch, f); if (src_rotated_rgb == NULL) { retval = -1; } else { @@ -816,7 +812,7 @@ static int SW_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, vo /* Prevent to do scaling + clipping on viewport boundaries as it may lose proportion */ if (dstrect->x < 0 || dstrect->y < 0 || dstrect->x + dstrect->w > surface->w || dstrect->y + dstrect->h > surface->h) { - SDL_Surface *tmp = SDL_CreateRGBSurfaceWithFormat(dstrect->w, dstrect->h, src->format->format); + SDL_Surface *tmp = SDL_CreateSurface(dstrect->w, dstrect->h, src->format->format); /* Scale to an intermediate surface, then blit */ if (tmp) { SDL_Rect r; diff --git a/src/render/software/SDL_rotate.c b/src/render/software/SDL_rotate.c index 77786ba04..9b80292d4 100644 --- a/src/render/software/SDL_rotate.c +++ b/src/render/software/SDL_rotate.c @@ -523,7 +523,7 @@ SDLgfx_rotateSurface(SDL_Surface *src, double angle, int smooth, int flipx, int rz_dst = NULL; if (is8bit) { /* Target surface is 8 bit */ - rz_dst = SDL_CreateRGBSurfaceWithFormat(rect_dest->w, rect_dest->h + GUARD_ROWS, src->format->format); + rz_dst = SDL_CreateSurface(rect_dest->w, rect_dest->h + GUARD_ROWS, src->format->format); if (rz_dst != NULL) { if (src->format->palette) { for (i = 0; i < src->format->palette->ncolors; i++) { @@ -534,9 +534,7 @@ SDLgfx_rotateSurface(SDL_Surface *src, double angle, int smooth, int flipx, int } } else { /* Target surface is 32 bit with source RGBA ordering */ - rz_dst = SDL_CreateRGBSurface(rect_dest->w, rect_dest->h + GUARD_ROWS, 32, - src->format->Rmask, src->format->Gmask, - src->format->Bmask, src->format->Amask); + rz_dst = SDL_CreateSurface(rect_dest->w, rect_dest->h + GUARD_ROWS, src->format->format); } /* Check target */ diff --git a/src/render/software/SDL_triangle.c b/src/render/software/SDL_triangle.c index 5d2a70f6f..093d27740 100644 --- a/src/render/software/SDL_triangle.c +++ b/src/render/software/SDL_triangle.c @@ -270,7 +270,7 @@ int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Poin } /* Use an intermediate surface */ - tmp = SDL_CreateRGBSurfaceWithFormat(dstrect.w, dstrect.h, format); + tmp = SDL_CreateSurface(dstrect.w, dstrect.h, format); if (tmp == NULL) { ret = -1; goto end; diff --git a/src/test/SDL_test_common.c b/src/test/SDL_test_common.c index e75be2bf6..e7753595d 100644 --- a/src/test/SDL_test_common.c +++ b/src/test/SDL_test_common.c @@ -1749,13 +1749,9 @@ static void SDLTest_ScreenShot(SDL_Renderer *renderer) } SDL_RenderGetViewport(renderer, &viewport); - surface = SDL_CreateRGBSurface(viewport.w, viewport.h, 24, -#if SDL_BYTEORDER == SDL_LIL_ENDIAN - 0x00FF0000, 0x0000FF00, 0x000000FF, -#else - 0x000000FF, 0x0000FF00, 0x00FF0000, -#endif - 0x00000000); + + surface = SDL_CreateSurface(viewport.w, viewport.h, SDL_PIXELFORMAT_BGR24); + if (surface == NULL) { SDL_Log("Couldn't create surface: %s\n", SDL_GetError()); return; diff --git a/src/test/SDL_test_font.c b/src/test/SDL_test_font.c index 6840cbc0d..b6cd5b9b2 100644 --- a/src/test/SDL_test_font.c +++ b/src/test/SDL_test_font.c @@ -3185,8 +3185,7 @@ int SDLTest_DrawCharacter(SDL_Renderer *renderer, int x, int y, Uint32 c) /* * Redraw character into surface */ - character = SDL_CreateRGBSurface(charWidth, charHeight, 32, - 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF); + character = SDL_CreateSurface(charWidth, charHeight, SDL_PIXELFORMAT_RGBA8888); if (character == NULL) { return -1; } diff --git a/src/test/SDL_test_imageBlit.c b/src/test/SDL_test_imageBlit.c index 7a226e636..e5a9ce861 100644 --- a/src/test/SDL_test_imageBlit.c +++ b/src/test/SDL_test_imageBlit.c @@ -540,24 +540,11 @@ static const SDLTest_SurfaceImage_t SDLTest_imageBlit = { */ SDL_Surface *SDLTest_ImageBlit() { - SDL_Surface *surface = SDL_CreateRGBSurfaceFrom( + SDL_Surface *surface = SDL_CreateSurfaceFrom( (void *)SDLTest_imageBlit.pixel_data, SDLTest_imageBlit.width, SDLTest_imageBlit.height, - SDLTest_imageBlit.bytes_per_pixel * 8, - SDLTest_imageBlit.width * SDLTest_imageBlit.bytes_per_pixel, -#if (SDL_BYTEORDER == SDL_BIG_ENDIAN) - 0xff000000, /* Red bit mask. */ - 0x00ff0000, /* Green bit mask. */ - 0x0000ff00, /* Blue bit mask. */ - 0x000000ff /* Alpha bit mask. */ -#else - 0x000000ff, /* Red bit mask. */ - 0x0000ff00, /* Green bit mask. */ - 0x00ff0000, /* Blue bit mask. */ - 0xff000000 /* Alpha bit mask. */ -#endif - ); + SDLTest_imageBlit.width * SDLTest_imageBlit.bytes_per_pixel, SDL_PIXELFORMAT_RGB24); return surface; } @@ -1025,24 +1012,11 @@ static const SDLTest_SurfaceImage_t SDLTest_imageBlitColor = { */ SDL_Surface *SDLTest_ImageBlitColor() { - SDL_Surface *surface = SDL_CreateRGBSurfaceFrom( + SDL_Surface *surface = SDL_CreateSurfaceFrom( (void *)SDLTest_imageBlitColor.pixel_data, SDLTest_imageBlitColor.width, SDLTest_imageBlitColor.height, - SDLTest_imageBlitColor.bytes_per_pixel * 8, - SDLTest_imageBlitColor.width * SDLTest_imageBlitColor.bytes_per_pixel, -#if (SDL_BYTEORDER == SDL_BIG_ENDIAN) - 0xff000000, /* Red bit mask. */ - 0x00ff0000, /* Green bit mask. */ - 0x0000ff00, /* Blue bit mask. */ - 0x000000ff /* Alpha bit mask. */ -#else - 0x000000ff, /* Red bit mask. */ - 0x0000ff00, /* Green bit mask. */ - 0x00ff0000, /* Blue bit mask. */ - 0xff000000 /* Alpha bit mask. */ -#endif - ); + SDLTest_imageBlitColor.width * SDLTest_imageBlitColor.bytes_per_pixel, SDL_PIXELFORMAT_RGB24); return surface; } @@ -1673,24 +1647,11 @@ static const SDLTest_SurfaceImage_t SDLTest_imageBlitAlpha = { */ SDL_Surface *SDLTest_ImageBlitAlpha() { - SDL_Surface *surface = SDL_CreateRGBSurfaceFrom( + SDL_Surface *surface = SDL_CreateSurfaceFrom( (void *)SDLTest_imageBlitAlpha.pixel_data, SDLTest_imageBlitAlpha.width, SDLTest_imageBlitAlpha.height, - SDLTest_imageBlitAlpha.bytes_per_pixel * 8, - SDLTest_imageBlitAlpha.width * SDLTest_imageBlitAlpha.bytes_per_pixel, -#if (SDL_BYTEORDER == SDL_BIG_ENDIAN) - 0xff000000, /* Red bit mask. */ - 0x00ff0000, /* Green bit mask. */ - 0x0000ff00, /* Blue bit mask. */ - 0x000000ff /* Alpha bit mask. */ -#else - 0x000000ff, /* Red bit mask. */ - 0x0000ff00, /* Green bit mask. */ - 0x00ff0000, /* Blue bit mask. */ - 0xff000000 /* Alpha bit mask. */ -#endif - ); + SDLTest_imageBlitAlpha.width * SDLTest_imageBlitAlpha.bytes_per_pixel, SDL_PIXELFORMAT_RGB24); return surface; } diff --git a/src/test/SDL_test_imageBlitBlend.c b/src/test/SDL_test_imageBlitBlend.c index a50929da8..3dbf418c0 100644 --- a/src/test/SDL_test_imageBlitBlend.c +++ b/src/test/SDL_test_imageBlitBlend.c @@ -580,24 +580,11 @@ static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendAdd = { */ SDL_Surface *SDLTest_ImageBlitBlendAdd() { - SDL_Surface *surface = SDL_CreateRGBSurfaceFrom( + SDL_Surface *surface = SDL_CreateSurfaceFrom( (void *)SDLTest_imageBlitBlendAdd.pixel_data, SDLTest_imageBlitBlendAdd.width, SDLTest_imageBlitBlendAdd.height, - SDLTest_imageBlitBlendAdd.bytes_per_pixel * 8, - SDLTest_imageBlitBlendAdd.width * SDLTest_imageBlitBlendAdd.bytes_per_pixel, -#if (SDL_BYTEORDER == SDL_BIG_ENDIAN) - 0xff000000, /* Red bit mask. */ - 0x00ff0000, /* Green bit mask. */ - 0x0000ff00, /* Blue bit mask. */ - 0x000000ff /* Alpha bit mask. */ -#else - 0x000000ff, /* Red bit mask. */ - 0x0000ff00, /* Green bit mask. */ - 0x00ff0000, /* Blue bit mask. */ - 0xff000000 /* Alpha bit mask. */ -#endif - ); + SDLTest_imageBlitBlendAdd.width * SDLTest_imageBlitBlendAdd.bytes_per_pixel, SDL_PIXELFORMAT_RGB24); return surface; } @@ -1182,24 +1169,11 @@ static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlend = { */ SDL_Surface *SDLTest_ImageBlitBlend() { - SDL_Surface *surface = SDL_CreateRGBSurfaceFrom( + SDL_Surface *surface = SDL_CreateSurfaceFrom( (void *)SDLTest_imageBlitBlend.pixel_data, SDLTest_imageBlitBlend.width, SDLTest_imageBlitBlend.height, - SDLTest_imageBlitBlend.bytes_per_pixel * 8, - SDLTest_imageBlitBlend.width * SDLTest_imageBlitBlend.bytes_per_pixel, -#if (SDL_BYTEORDER == SDL_BIG_ENDIAN) - 0xff000000, /* Red bit mask. */ - 0x00ff0000, /* Green bit mask. */ - 0x0000ff00, /* Blue bit mask. */ - 0x000000ff /* Alpha bit mask. */ -#else - 0x000000ff, /* Red bit mask. */ - 0x0000ff00, /* Green bit mask. */ - 0x00ff0000, /* Blue bit mask. */ - 0xff000000 /* Alpha bit mask. */ -#endif - ); + SDLTest_imageBlitBlend.width * SDLTest_imageBlitBlend.bytes_per_pixel, SDL_PIXELFORMAT_RGB24); return surface; } @@ -1614,24 +1588,11 @@ static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendMod = { */ SDL_Surface *SDLTest_ImageBlitBlendMod() { - SDL_Surface *surface = SDL_CreateRGBSurfaceFrom( + SDL_Surface *surface = SDL_CreateSurfaceFrom( (void *)SDLTest_imageBlitBlendMod.pixel_data, SDLTest_imageBlitBlendMod.width, SDLTest_imageBlitBlendMod.height, - SDLTest_imageBlitBlendMod.bytes_per_pixel * 8, - SDLTest_imageBlitBlendMod.width * SDLTest_imageBlitBlendMod.bytes_per_pixel, -#if (SDL_BYTEORDER == SDL_BIG_ENDIAN) - 0xff000000, /* Red bit mask. */ - 0x00ff0000, /* Green bit mask. */ - 0x0000ff00, /* Blue bit mask. */ - 0x000000ff /* Alpha bit mask. */ -#else - 0x000000ff, /* Red bit mask. */ - 0x0000ff00, /* Green bit mask. */ - 0x00ff0000, /* Blue bit mask. */ - 0xff000000 /* Alpha bit mask. */ -#endif - ); + SDLTest_imageBlitBlendMod.width * SDLTest_imageBlitBlendMod.bytes_per_pixel, SDL_PIXELFORMAT_RGB24); return surface; } @@ -2429,24 +2390,11 @@ static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendNone = { */ SDL_Surface *SDLTest_ImageBlitBlendNone() { - SDL_Surface *surface = SDL_CreateRGBSurfaceFrom( + SDL_Surface *surface = SDL_CreateSurfaceFrom( (void *)SDLTest_imageBlitBlendNone.pixel_data, SDLTest_imageBlitBlendNone.width, SDLTest_imageBlitBlendNone.height, - SDLTest_imageBlitBlendNone.bytes_per_pixel * 8, - SDLTest_imageBlitBlendNone.width * SDLTest_imageBlitBlendNone.bytes_per_pixel, -#if (SDL_BYTEORDER == SDL_BIG_ENDIAN) - 0xff000000, /* Red bit mask. */ - 0x00ff0000, /* Green bit mask. */ - 0x0000ff00, /* Blue bit mask. */ - 0x000000ff /* Alpha bit mask. */ -#else - 0x000000ff, /* Red bit mask. */ - 0x0000ff00, /* Green bit mask. */ - 0x00ff0000, /* Blue bit mask. */ - 0xff000000 /* Alpha bit mask. */ -#endif - ); + SDLTest_imageBlitBlendNone.width * SDLTest_imageBlitBlendNone.bytes_per_pixel, SDL_PIXELFORMAT_RGB24); return surface; } @@ -2976,24 +2924,11 @@ static const SDLTest_SurfaceImage_t SDLTest_imageBlitBlendAll = { */ SDL_Surface *SDLTest_ImageBlitBlendAll() { - SDL_Surface *surface = SDL_CreateRGBSurfaceFrom( + SDL_Surface *surface = SDL_CreateSurfaceFrom( (void *)SDLTest_imageBlitBlendAll.pixel_data, SDLTest_imageBlitBlendAll.width, SDLTest_imageBlitBlendAll.height, - SDLTest_imageBlitBlendAll.bytes_per_pixel * 8, - SDLTest_imageBlitBlendAll.width * SDLTest_imageBlitBlendAll.bytes_per_pixel, -#if (SDL_BYTEORDER == SDL_BIG_ENDIAN) - 0xff000000, /* Red bit mask. */ - 0x00ff0000, /* Green bit mask. */ - 0x0000ff00, /* Blue bit mask. */ - 0x000000ff /* Alpha bit mask. */ -#else - 0x000000ff, /* Red bit mask. */ - 0x0000ff00, /* Green bit mask. */ - 0x00ff0000, /* Blue bit mask. */ - 0xff000000 /* Alpha bit mask. */ -#endif - ); + SDLTest_imageBlitBlendAll.width * SDLTest_imageBlitBlendAll.bytes_per_pixel, SDL_PIXELFORMAT_RGB24); return surface; } diff --git a/src/test/SDL_test_imageFace.c b/src/test/SDL_test_imageFace.c index 8795d50d7..92ab6a01b 100644 --- a/src/test/SDL_test_imageFace.c +++ b/src/test/SDL_test_imageFace.c @@ -223,24 +223,12 @@ static const SDLTest_SurfaceImage_t SDLTest_imageFace = { */ SDL_Surface *SDLTest_ImageFace() { - SDL_Surface *surface = SDL_CreateRGBSurfaceFrom( + SDL_Surface *surface = SDL_CreateSurfaceFrom( (void *)SDLTest_imageFace.pixel_data, SDLTest_imageFace.width, SDLTest_imageFace.height, - SDLTest_imageFace.bytes_per_pixel * 8, SDLTest_imageFace.width * SDLTest_imageFace.bytes_per_pixel, -#if (SDL_BYTEORDER == SDL_BIG_ENDIAN) - 0xff000000, /* Red bit mask. */ - 0x00ff0000, /* Green bit mask. */ - 0x0000ff00, /* Blue bit mask. */ - 0x000000ff /* Alpha bit mask. */ -#else - 0x000000ff, /* Red bit mask. */ - 0x0000ff00, /* Green bit mask. */ - 0x00ff0000, /* Blue bit mask. */ - 0xff000000 /* Alpha bit mask. */ -#endif - ); + SDL_PIXELFORMAT_RGBA32); return surface; } diff --git a/src/test/SDL_test_imagePrimitives.c b/src/test/SDL_test_imagePrimitives.c index 644cbc874..e60706453 100644 --- a/src/test/SDL_test_imagePrimitives.c +++ b/src/test/SDL_test_imagePrimitives.c @@ -504,24 +504,11 @@ static const SDLTest_SurfaceImage_t SDLTest_imagePrimitives = { */ SDL_Surface *SDLTest_ImagePrimitives() { - SDL_Surface *surface = SDL_CreateRGBSurfaceFrom( + SDL_Surface *surface = SDL_CreateSurfaceFrom( (void *)SDLTest_imagePrimitives.pixel_data, SDLTest_imagePrimitives.width, SDLTest_imagePrimitives.height, - SDLTest_imagePrimitives.bytes_per_pixel * 8, - SDLTest_imagePrimitives.width * SDLTest_imagePrimitives.bytes_per_pixel, -#if (SDL_BYTEORDER == SDL_BIG_ENDIAN) - 0xff000000, /* Red bit mask. */ - 0x00ff0000, /* Green bit mask. */ - 0x0000ff00, /* Blue bit mask. */ - 0x000000ff /* Alpha bit mask. */ -#else - 0x000000ff, /* Red bit mask. */ - 0x0000ff00, /* Green bit mask. */ - 0x00ff0000, /* Blue bit mask. */ - 0xff000000 /* Alpha bit mask. */ -#endif - ); + SDLTest_imagePrimitives.width * SDLTest_imagePrimitives.bytes_per_pixel, SDL_PIXELFORMAT_RGB24); return surface; } diff --git a/src/test/SDL_test_imagePrimitivesBlend.c b/src/test/SDL_test_imagePrimitivesBlend.c index 0cf7b01f6..6dedd2baa 100644 --- a/src/test/SDL_test_imagePrimitivesBlend.c +++ b/src/test/SDL_test_imagePrimitivesBlend.c @@ -677,24 +677,11 @@ static const SDLTest_SurfaceImage_t SDLTest_imagePrimitivesBlend = { */ SDL_Surface *SDLTest_ImagePrimitivesBlend() { - SDL_Surface *surface = SDL_CreateRGBSurfaceFrom( + SDL_Surface *surface = SDL_CreateSurfaceFrom( (void *)SDLTest_imagePrimitivesBlend.pixel_data, SDLTest_imagePrimitivesBlend.width, SDLTest_imagePrimitivesBlend.height, - SDLTest_imagePrimitivesBlend.bytes_per_pixel * 8, - SDLTest_imagePrimitivesBlend.width * SDLTest_imagePrimitivesBlend.bytes_per_pixel, -#if (SDL_BYTEORDER == SDL_BIG_ENDIAN) - 0xff000000, /* Red bit mask. */ - 0x00ff0000, /* Green bit mask. */ - 0x0000ff00, /* Blue bit mask. */ - 0x000000ff /* Alpha bit mask. */ -#else - 0x000000ff, /* Red bit mask. */ - 0x0000ff00, /* Green bit mask. */ - 0x00ff0000, /* Blue bit mask. */ - 0xff000000 /* Alpha bit mask. */ -#endif - ); + SDLTest_imagePrimitivesBlend.width * SDLTest_imagePrimitivesBlend.bytes_per_pixel, SDL_PIXELFORMAT_RGB24); return surface; } diff --git a/src/video/SDL_bmp.c b/src/video/SDL_bmp.c index fe6ba3261..64fcb528e 100644 --- a/src/video/SDL_bmp.c +++ b/src/video/SDL_bmp.c @@ -383,16 +383,19 @@ SDL_LoadBMP_RW(SDL_RWops *src, int freesrc) switch (biBitCount) { case 15: case 16: + /* SDL_PIXELFORMAT_RGB555 or SDL_PIXELFORMAT_ARGB1555 if Amask */ Rmask = 0x7C00; Gmask = 0x03E0; Bmask = 0x001F; break; case 24: #if SDL_BYTEORDER == SDL_BIG_ENDIAN + /* SDL_PIXELFORMAT_RGB24 */ Rmask = 0x000000FF; Gmask = 0x0000FF00; Bmask = 0x00FF0000; #else + /* SDL_PIXELFORMAT_BGR24 */ Rmask = 0x00FF0000; Gmask = 0x0000FF00; Bmask = 0x000000FF; @@ -401,6 +404,7 @@ SDL_LoadBMP_RW(SDL_RWops *src, int freesrc) case 32: /* We don't know if this has alpha channel or not */ correctAlpha = SDL_TRUE; + /* SDL_PIXELFORMAT_RGBA8888 */ Amask = 0xFF000000; Rmask = 0x00FF0000; Gmask = 0x0000FF00; @@ -419,12 +423,17 @@ SDL_LoadBMP_RW(SDL_RWops *src, int freesrc) } /* Create a compatible surface, note that the colors are RGB ordered */ - surface = - SDL_CreateRGBSurface(biWidth, biHeight, biBitCount, Rmask, Gmask, - Bmask, Amask); - if (surface == NULL) { - was_error = SDL_TRUE; - goto done; + { + Uint32 format; + + /* Get the pixel format */ + format = SDL_MasksToPixelFormatEnum(biBitCount, Rmask, Gmask, Bmask, Amask); + surface = SDL_CreateSurface(biWidth, biHeight, format); + + if (surface == NULL) { + was_error = SDL_TRUE; + goto done; + } } /* Load the palette, if any */ diff --git a/src/video/SDL_surface.c b/src/video/SDL_surface.c index e1bbae4a8..5162d9a62 100644 --- a/src/video/SDL_surface.c +++ b/src/video/SDL_surface.c @@ -72,7 +72,7 @@ SDL_CalculatePitch(Uint32 format, size_t width, SDL_bool minimal) * enum SDL_PIXELFORMAT_* format */ SDL_Surface * -SDL_CreateRGBSurfaceWithFormat(int width, int height, Uint32 format) +SDL_CreateSurface(int width, int height, Uint32 format) { size_t pitch; SDL_Surface *surface; @@ -170,82 +170,14 @@ SDL_CreateRGBSurfaceWithFormat(int width, int height, Uint32 format) return surface; } -/* - * Create an empty RGB surface of the appropriate depth - */ -SDL_Surface * -SDL_CreateRGBSurface(int width, int height, int depth, - Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) -{ - Uint32 format; - - /* Get the pixel format */ - format = SDL_MasksToPixelFormatEnum(depth, Rmask, Gmask, Bmask, Amask); - if (format == SDL_PIXELFORMAT_UNKNOWN) { - SDL_SetError("Unknown pixel format"); - return NULL; - } - - return SDL_CreateRGBSurfaceWithFormat(width, height, format); -} - -/* - * Create an RGB surface from an existing memory buffer - */ -SDL_Surface * -SDL_CreateRGBSurfaceFrom(void *pixels, - int width, int height, int depth, int pitch, - Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, - Uint32 Amask) -{ - SDL_Surface *surface; - Uint32 format; - size_t minimalPitch; - - if (width < 0) { - SDL_InvalidParamError("width"); - return NULL; - } - - if (height < 0) { - SDL_InvalidParamError("height"); - return NULL; - } - - format = SDL_MasksToPixelFormatEnum(depth, Rmask, Gmask, Bmask, Amask); - - if (format == SDL_PIXELFORMAT_UNKNOWN) { - SDL_SetError("Unknown pixel format"); - return NULL; - } - - minimalPitch = SDL_CalculatePitch(format, width, SDL_TRUE); - - if (pitch < 0 || (pitch > 0 && ((size_t)pitch) < minimalPitch)) { - SDL_InvalidParamError("pitch"); - return NULL; - } - - surface = SDL_CreateRGBSurfaceWithFormat(0, 0, format); - if (surface != NULL) { - surface->flags |= SDL_PREALLOC; - surface->pixels = pixels; - surface->w = width; - surface->h = height; - surface->pitch = pitch; - SDL_SetClipRect(surface, NULL); - } - return surface; -} - /* * Create an RGB surface from an existing memory buffer using the given given * enum SDL_PIXELFORMAT_* format */ SDL_Surface * -SDL_CreateRGBSurfaceWithFormatFrom(void *pixels, - int width, int height, int pitch, - Uint32 format) +SDL_CreateSurfaceFrom(void *pixels, + int width, int height, int pitch, + Uint32 format) { SDL_Surface *surface; size_t minimalPitch; @@ -267,7 +199,7 @@ SDL_CreateRGBSurfaceWithFormatFrom(void *pixels, return NULL; } - surface = SDL_CreateRGBSurfaceWithFormat(0, 0, format); + surface = SDL_CreateSurface(0, 0, format); if (surface != NULL) { surface->flags |= SDL_PREALLOC; surface->pixels = pixels; @@ -1027,7 +959,7 @@ int SDL_PrivateLowerBlitScaled(SDL_Surface *src, SDL_Rect *srcrect, } else { fmt = SDL_PIXELFORMAT_ARGB8888; } - tmp1 = SDL_CreateRGBSurfaceWithFormat(src->w, src->h, fmt); + tmp1 = SDL_CreateSurface(src->w, src->h, fmt); SDL_LowerBlit(src, srcrect, tmp1, &tmprect); srcrect2.x = 0; @@ -1042,7 +974,7 @@ int SDL_PrivateLowerBlitScaled(SDL_Surface *src, SDL_Rect *srcrect, /* Intermediate scaling */ if (is_complex_copy_flags || src->format->format != dst->format->format) { SDL_Rect tmprect; - SDL_Surface *tmp2 = SDL_CreateRGBSurfaceWithFormat(dstrect->w, dstrect->h, src->format->format); + SDL_Surface *tmp2 = SDL_CreateSurface(dstrect->w, dstrect->h, src->format->format); SDL_SoftStretchLinear(src, &srcrect2, tmp2, NULL); SDL_SetSurfaceColorMod(tmp2, r, g, b); @@ -1156,10 +1088,7 @@ SDL_ConvertSurface(SDL_Surface *surface, const SDL_PixelFormat *format) } /* Create a new surface with the desired format */ - convert = SDL_CreateRGBSurface(surface->w, surface->h, - format->BitsPerPixel, format->Rmask, - format->Gmask, format->Bmask, - format->Amask); + convert = SDL_CreateSurface(surface->w, surface->h, format->format); if (convert == NULL) { return NULL; } @@ -1300,10 +1229,7 @@ SDL_ConvertSurface(SDL_Surface *surface, const SDL_PixelFormat *format) int converted_colorkey = 0; /* Create a dummy surface to get the colorkey converted */ - tmp = SDL_CreateRGBSurface(1, 1, - surface->format->BitsPerPixel, surface->format->Rmask, - surface->format->Gmask, surface->format->Bmask, - surface->format->Amask); + tmp = SDL_CreateSurface(1, 1, surface->format->format); /* Share the palette, if any */ if (surface->format->palette) { diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 0c90a2d16..df1eb3423 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -2556,8 +2556,6 @@ static SDL_Surface *SDL_CreateWindowFramebuffer(SDL_Window *window) Uint32 format = 0; void *pixels = NULL; int pitch = 0; - int bpp; - Uint32 Rmask, Gmask, Bmask, Amask; SDL_bool created_framebuffer = SDL_FALSE; /* This will switch the video backend from using a software surface to @@ -2633,11 +2631,7 @@ static SDL_Surface *SDL_CreateWindowFramebuffer(SDL_Window *window) return window->surface; } - if (!SDL_PixelFormatEnumToMasks(format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) { - return NULL; - } - - return SDL_CreateRGBSurfaceFrom(pixels, window->w, window->h, bpp, pitch, Rmask, Gmask, Bmask, Amask); + return SDL_CreateSurfaceFrom(pixels, window->w, window->h, pitch, format); } SDL_Surface * diff --git a/src/video/android/SDL_androidmouse.c b/src/video/android/SDL_androidmouse.c index d4d022f3c..aba1e5cc0 100644 --- a/src/video/android/SDL_androidmouse.c +++ b/src/video/android/SDL_androidmouse.c @@ -118,7 +118,7 @@ static void Android_FreeCursor(SDL_Cursor *cursor) static SDL_Cursor *Android_CreateEmptyCursor() { if (empty_cursor == NULL) { - SDL_Surface *empty_surface = SDL_CreateRGBSurfaceWithFormat(1, 1, SDL_PIXELFORMAT_ARGB8888); + SDL_Surface *empty_surface = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_ARGB8888); if (empty_surface) { SDL_memset(empty_surface->pixels, 0, empty_surface->h * empty_surface->pitch); empty_cursor = Android_CreateCursor(empty_surface, 0, 0); diff --git a/src/video/dummy/SDL_nullframebuffer.c b/src/video/dummy/SDL_nullframebuffer.c index 79bf41f8b..d6a38e322 100644 --- a/src/video/dummy/SDL_nullframebuffer.c +++ b/src/video/dummy/SDL_nullframebuffer.c @@ -38,7 +38,7 @@ int SDL_DUMMY_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, /* Create a new one */ SDL_GetWindowSize(window, &w, &h); - surface = SDL_CreateRGBSurfaceWithFormat(w, h, surface_format); + surface = SDL_CreateSurface(w, h, surface_format); if (surface == NULL) { return -1; } diff --git a/src/video/emscripten/SDL_emscriptenframebuffer.c b/src/video/emscripten/SDL_emscriptenframebuffer.c index 6be95750c..520bd7600 100644 --- a/src/video/emscripten/SDL_emscriptenframebuffer.c +++ b/src/video/emscripten/SDL_emscriptenframebuffer.c @@ -32,8 +32,6 @@ int Emscripten_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format SDL_Surface *surface; const Uint32 surface_format = SDL_PIXELFORMAT_BGR888; int w, h; - int bpp; - Uint32 Rmask, Gmask, Bmask, Amask; /* Free the old framebuffer surface */ SDL_WindowData *data = (SDL_WindowData *)window->driverdata; @@ -41,10 +39,9 @@ int Emscripten_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format SDL_FreeSurface(surface); /* Create a new one */ - SDL_PixelFormatEnumToMasks(surface_format, &bpp, &Rmask, &Gmask, &Bmask, &Amask); SDL_GetWindowSize(window, &w, &h); - surface = SDL_CreateRGBSurface(w, h, bpp, Rmask, Gmask, Bmask, Amask); + surface = SDL_CreateSurface(w, h, surface_format); if (surface == NULL) { return -1; } diff --git a/src/video/n3ds/SDL_n3dsframebuffer.c b/src/video/n3ds/SDL_n3dsframebuffer.c index 3d7ed8685..7e49f5261 100644 --- a/src/video/n3ds/SDL_n3dsframebuffer.c +++ b/src/video/n3ds/SDL_n3dsframebuffer.c @@ -68,11 +68,9 @@ FreePreviousWindowFramebuffer(SDL_Window *window) SDL_FORCE_INLINE SDL_Surface * CreateNewWindowFramebuffer(SDL_Window *window) { - int w, h, bpp; - Uint32 Rmask, Gmask, Bmask, Amask; - SDL_PixelFormatEnumToMasks(FRAMEBUFFER_FORMAT, &bpp, &Rmask, &Gmask, &Bmask, &Amask); + int w, h; SDL_GetWindowSize(window, &w, &h); - return SDL_CreateRGBSurface(w, h, bpp, Rmask, Gmask, Bmask, Amask); + return SDL_CreateSurface(w, h, FRAMEBUFFER_FORMAT); } int SDL_N3DS_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect *rects, int numrects) diff --git a/src/video/ngage/SDL_ngageframebuffer.cpp b/src/video/ngage/SDL_ngageframebuffer.cpp index c8915ff12..ed403a851 100644 --- a/src/video/ngage/SDL_ngageframebuffer.cpp +++ b/src/video/ngage/SDL_ngageframebuffer.cpp @@ -56,7 +56,7 @@ int SDL_NGAGE_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, /* Create a new one */ SDL_GetWindowSize(window, &w, &h); - surface = SDL_CreateRGBSurfaceWithFormat(0, w, h, 0, surface_format); + surface = SDL_CreateSurface(w, h, surface_format); if (surface == NULL) { return -1; } diff --git a/src/video/offscreen/SDL_offscreenframebuffer.c b/src/video/offscreen/SDL_offscreenframebuffer.c index 893df0ab8..7afef1ae0 100644 --- a/src/video/offscreen/SDL_offscreenframebuffer.c +++ b/src/video/offscreen/SDL_offscreenframebuffer.c @@ -38,7 +38,7 @@ int SDL_OFFSCREEN_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *for /* Create a new one */ SDL_GetWindowSize(window, &w, &h); - surface = SDL_CreateRGBSurfaceWithFormat(w, h, surface_format); + surface = SDL_CreateSurface(w, h, surface_format); if (surface == NULL) { return -1; } diff --git a/src/video/windows/SDL_windowsmouse.c b/src/video/windows/SDL_windowsmouse.c index 05cb05fe5..fe0577a45 100644 --- a/src/video/windows/SDL_windowsmouse.c +++ b/src/video/windows/SDL_windowsmouse.c @@ -170,7 +170,7 @@ static SDL_Cursor *WIN_CreateCursor(SDL_Surface *surface, int hot_x, int hot_y) static SDL_Cursor *WIN_CreateBlankCursor() { SDL_Cursor *cursor = NULL; - SDL_Surface *surface = SDL_CreateRGBSurfaceWithFormat(32, 32, SDL_PIXELFORMAT_ARGB8888); + SDL_Surface *surface = SDL_CreateSurface(32, 32, SDL_PIXELFORMAT_ARGB8888); if (surface) { cursor = WIN_CreateCursor(surface, 0, 0); SDL_FreeSurface(surface); diff --git a/test/testautomation_render.c b/test/testautomation_render.c index 97937818d..516af0675 100644 --- a/test/testautomation_render.c +++ b/test/testautomation_render.c @@ -10,11 +10,8 @@ #define TESTRENDER_SCREEN_W 80 #define TESTRENDER_SCREEN_H 60 + #define RENDER_COMPARE_FORMAT SDL_PIXELFORMAT_ARGB8888 -#define RENDER_COMPARE_AMASK 0xff000000 /**< Alpha bit mask. */ -#define RENDER_COMPARE_RMASK 0x00ff0000 /**< Red bit mask. */ -#define RENDER_COMPARE_GMASK 0x0000ff00 /**< Green bit mask. */ -#define RENDER_COMPARE_BMASK 0x000000ff /**< Blue bit mask. */ #define ALLOWABLE_ERROR_OPAQUE 0 #define ALLOWABLE_ERROR_BLENDED 64 @@ -1044,44 +1041,43 @@ _hasTexAlpha(void) * * \sa * http://wiki.libsdl.org/SDL_RenderReadPixels - * http://wiki.libsdl.org/SDL_CreateRGBSurfaceFrom + * http://wiki.libsdl.org/SDL_CreateSurfaceFrom * http://wiki.libsdl.org/SDL_FreeSurface */ static void _compare(SDL_Surface *referenceSurface, int allowable_error) { - int result; - SDL_Rect rect; - Uint8 *pixels; - SDL_Surface *testSurface; + int result; + SDL_Rect rect; + Uint8 *pixels; + SDL_Surface *testSurface; - /* Read pixels. */ - pixels = (Uint8 *)SDL_malloc(4 * TESTRENDER_SCREEN_W * TESTRENDER_SCREEN_H); - SDLTest_AssertCheck(pixels != NULL, "Validate allocated temp pixel buffer"); - if (pixels == NULL) { - return; - } + /* Read pixels. */ + pixels = (Uint8 *)SDL_malloc(4*TESTRENDER_SCREEN_W*TESTRENDER_SCREEN_H); + SDLTest_AssertCheck(pixels != NULL, "Validate allocated temp pixel buffer"); + if (pixels == NULL) { + return; + } - /* Explicitly specify the rect in case the window isn't the expected size... */ - rect.x = 0; - rect.y = 0; - rect.w = TESTRENDER_SCREEN_W; - rect.h = TESTRENDER_SCREEN_H; - result = SDL_RenderReadPixels(renderer, &rect, RENDER_COMPARE_FORMAT, pixels, 80 * 4); - SDLTest_AssertCheck(result == 0, "Validate result from SDL_RenderReadPixels, expected: 0, got: %i", result); + /* Explicitly specify the rect in case the window isn't the expected size... */ + rect.x = 0; + rect.y = 0; + rect.w = TESTRENDER_SCREEN_W; + rect.h = TESTRENDER_SCREEN_H; + result = SDL_RenderReadPixels(renderer, &rect, RENDER_COMPARE_FORMAT, pixels, 80*4 ); + SDLTest_AssertCheck(result == 0, "Validate result from SDL_RenderReadPixels, expected: 0, got: %i", result); - /* Create surface. */ - testSurface = SDL_CreateRGBSurfaceFrom(pixels, TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, 32, TESTRENDER_SCREEN_W * 4, - RENDER_COMPARE_RMASK, RENDER_COMPARE_GMASK, RENDER_COMPARE_BMASK, RENDER_COMPARE_AMASK); - SDLTest_AssertCheck(testSurface != NULL, "Verify result from SDL_CreateRGBSurfaceFrom is not NULL"); + /* Create surface. */ + testSurface = SDL_CreateSurfaceFrom(pixels, TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, TESTRENDER_SCREEN_W*4, RENDER_COMPARE_FORMAT); + SDLTest_AssertCheck(testSurface != NULL, "Verify result from SDL_CreateSurfaceFrom is not NULL"); - /* Compare surface. */ - result = SDLTest_CompareSurfaces(testSurface, referenceSurface, allowable_error); - SDLTest_AssertCheck(result == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", result); + /* Compare surface. */ + result = SDLTest_CompareSurfaces( testSurface, referenceSurface, allowable_error ); + SDLTest_AssertCheck(result == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", result); - /* Clean up. */ - SDL_free(pixels); - SDL_FreeSurface(testSurface); + /* Clean up. */ + SDL_free(pixels); + SDL_FreeSurface(testSurface); } /** diff --git a/test/testautomation_surface.c b/test/testautomation_surface.c index e4fb02053..06ef095c8 100644 --- a/test/testautomation_surface.c +++ b/test/testautomation_surface.c @@ -40,21 +40,9 @@ void _surfaceSetUp(void *arg) int result; SDL_BlendMode blendMode = SDL_BLENDMODE_NONE; SDL_BlendMode currentBlendMode; - Uint32 rmask, gmask, bmask, amask; -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - rmask = 0xff000000; - gmask = 0x00ff0000; - bmask = 0x0000ff00; - amask = 0x000000ff; -#else - rmask = 0x000000ff; - gmask = 0x0000ff00; - bmask = 0x00ff0000; - amask = 0xff000000; -#endif - + referenceSurface = SDLTest_ImageBlit(); /* For size info */ - testSurface = SDL_CreateRGBSurface(referenceSurface->w, referenceSurface->h, 32, rmask, gmask, bmask, amask); + testSurface = SDL_CreateSurface(referenceSurface->w, referenceSurface->h, SDL_PIXELFORMAT_RGBA32); SDLTest_AssertCheck(testSurface != NULL, "Check that testSurface is not NULL"); if (testSurface != NULL) { /* Disable blend mode for target surface */ @@ -597,116 +585,116 @@ int surface_testOverflow(void *arg) SDL_memset(buf, '\0', sizeof(buf)); expectedError = "Parameter 'width' is invalid"; - surface = SDL_CreateRGBSurfaceWithFormat(-3, 100, SDL_PIXELFORMAT_INDEX8); + surface = SDL_CreateSurface(-3, 100, SDL_PIXELFORMAT_INDEX8); SDLTest_AssertCheck(surface == NULL, "Should detect negative width"); SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); - surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, -1, 1, 4, SDL_PIXELFORMAT_INDEX8); + surface = SDL_CreateSurfaceFrom(buf, -1, 1, 4, SDL_PIXELFORMAT_INDEX8); SDLTest_AssertCheck(surface == NULL, "Should detect negative width"); SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); - surface = SDL_CreateRGBSurfaceFrom(buf, -1, 1, 32, 4, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF); + surface = SDL_CreateSurfaceFrom(buf, -1, 1, 4, SDL_PIXELFORMAT_RGBA8888); SDLTest_AssertCheck(surface == NULL, "Should detect negative width"); SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); expectedError = "Parameter 'height' is invalid"; - surface = SDL_CreateRGBSurfaceWithFormat(100, -3, SDL_PIXELFORMAT_INDEX8); + surface = SDL_CreateSurface(100, -3, SDL_PIXELFORMAT_INDEX8); SDLTest_AssertCheck(surface == NULL, "Should detect negative height"); SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); - surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 1, -1, 4, SDL_PIXELFORMAT_INDEX8); + surface = SDL_CreateSurfaceFrom(buf, 1, -1, 4, SDL_PIXELFORMAT_INDEX8); SDLTest_AssertCheck(surface == NULL, "Should detect negative height"); SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); - surface = SDL_CreateRGBSurfaceFrom(buf, 1, -1, 32, 4, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF); + surface = SDL_CreateSurfaceFrom(buf, 1, -1, 4, SDL_PIXELFORMAT_RGBA8888); SDLTest_AssertCheck(surface == NULL, "Should detect negative height"); SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); expectedError = "Parameter 'pitch' is invalid"; - surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 4, 1, -1, SDL_PIXELFORMAT_INDEX8); + surface = SDL_CreateSurfaceFrom(buf, 4, 1, -1, SDL_PIXELFORMAT_INDEX8); SDLTest_AssertCheck(surface == NULL, "Should detect negative pitch"); SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); - surface = SDL_CreateRGBSurfaceFrom(buf, 1, 1, 32, -1, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF); + surface = SDL_CreateSurfaceFrom(buf, 1, 1, -1, SDL_PIXELFORMAT_RGBA8888); SDLTest_AssertCheck(surface == NULL, "Should detect negative pitch"); SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); /* Less than 1 byte per pixel: the pitch can legitimately be less than * the width, but it must be enough to hold the appropriate number of - * bits per pixel. SDL_PIXELFORMAT_INDEX4* needs 1 byte per 2 pixels. */ - surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 6, 1, 3, SDL_PIXELFORMAT_INDEX4LSB); + * bits per pixel. SDL_PIXELFORMAT_INDEX4LSB* needs 1 byte per 2 pixels. */ + surface = SDL_CreateSurfaceFrom(buf, 6, 1, 3, SDL_PIXELFORMAT_INDEX4LSB); SDLTest_AssertCheck(surface != NULL, "6px * 4 bits per px fits in 3 bytes: %s", surface != NULL ? "(success)" : SDL_GetError()); SDL_FreeSurface(surface); - surface = SDL_CreateRGBSurfaceFrom(buf, 6, 1, 4, 3, 0, 0, 0, 0); + surface = SDL_CreateSurfaceFrom(buf, 6, 1, 3, SDL_PIXELFORMAT_INDEX4LSB); SDLTest_AssertCheck(surface != NULL, "6px * 4 bits per px fits in 3 bytes: %s", surface != NULL ? "(success)" : SDL_GetError()); SDL_FreeSurface(surface); - surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 7, 1, 3, SDL_PIXELFORMAT_INDEX4LSB); + surface = SDL_CreateSurfaceFrom(buf, 7, 1, 3, SDL_PIXELFORMAT_INDEX4LSB); SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp"); SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); - surface = SDL_CreateRGBSurfaceFrom(buf, 7, 1, 4, 3, 0, 0, 0, 0); + surface = SDL_CreateSurfaceFrom(buf, 7, 1, 3, SDL_PIXELFORMAT_INDEX4LSB); SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp"); SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); - surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 7, 1, 4, SDL_PIXELFORMAT_INDEX4LSB); + surface = SDL_CreateSurfaceFrom(buf, 7, 1, 4, SDL_PIXELFORMAT_INDEX4LSB); SDLTest_AssertCheck(surface != NULL, "7px * 4 bits per px fits in 4 bytes: %s", surface != NULL ? "(success)" : SDL_GetError()); SDL_FreeSurface(surface); - surface = SDL_CreateRGBSurfaceFrom(buf, 7, 1, 4, 4, 0, 0, 0, 0); + surface = SDL_CreateSurfaceFrom(buf, 7, 1, 4, SDL_PIXELFORMAT_INDEX4LSB); SDLTest_AssertCheck(surface != NULL, "7px * 4 bits per px fits in 4 bytes: %s", surface != NULL ? "(success)" : SDL_GetError()); SDL_FreeSurface(surface); /* SDL_PIXELFORMAT_INDEX1* needs 1 byte per 8 pixels. */ - surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 16, 1, 2, SDL_PIXELFORMAT_INDEX1LSB); + surface = SDL_CreateSurfaceFrom(buf, 16, 1, 2, SDL_PIXELFORMAT_INDEX1LSB); SDLTest_AssertCheck(surface != NULL, "16px * 1 bit per px fits in 2 bytes: %s", surface != NULL ? "(success)" : SDL_GetError()); SDL_FreeSurface(surface); - surface = SDL_CreateRGBSurfaceFrom(buf, 16, 1, 1, 2, 0, 0, 0, 0); + surface = SDL_CreateSurfaceFrom(buf, 16, 1, 2, SDL_PIXELFORMAT_INDEX1LSB); SDLTest_AssertCheck(surface != NULL, "16px * 1 bit per px fits in 2 bytes: %s", surface != NULL ? "(success)" : SDL_GetError()); SDL_FreeSurface(surface); - surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 17, 1, 2, SDL_PIXELFORMAT_INDEX1LSB); + surface = SDL_CreateSurfaceFrom(buf, 17, 1, 2, SDL_PIXELFORMAT_INDEX1LSB); SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp"); SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); - surface = SDL_CreateRGBSurfaceFrom(buf, 17, 1, 1, 2, 0, 0, 0, 0); + surface = SDL_CreateSurfaceFrom(buf, 17, 1, 2, SDL_PIXELFORMAT_INDEX1LSB); SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp"); SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); - surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 17, 1, 3, SDL_PIXELFORMAT_INDEX1LSB); + surface = SDL_CreateSurfaceFrom(buf, 17, 1, 3, SDL_PIXELFORMAT_INDEX1LSB); SDLTest_AssertCheck(surface != NULL, "17px * 1 bit per px fits in 3 bytes: %s", surface != NULL ? "(success)" : SDL_GetError()); SDL_FreeSurface(surface); - surface = SDL_CreateRGBSurfaceFrom(buf, 17, 1, 1, 3, 0, 0, 0, 0); + surface = SDL_CreateSurfaceFrom(buf, 17, 1, 3, SDL_PIXELFORMAT_INDEX1LSB); SDLTest_AssertCheck(surface != NULL, "17px * 1 bit per px fits in 3 bytes: %s", surface != NULL ? "(success)" : SDL_GetError()); SDL_FreeSurface(surface); /* SDL_PIXELFORMAT_INDEX8 and SDL_PIXELFORMAT_RGB332 require 1 byte per pixel. */ - surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 5, 1, 5, SDL_PIXELFORMAT_RGB332); + surface = SDL_CreateSurfaceFrom(buf, 5, 1, 5, SDL_PIXELFORMAT_RGB332); SDLTest_AssertCheck(surface != NULL, "5px * 8 bits per px fits in 5 bytes: %s", surface != NULL ? "(success)" : SDL_GetError()); SDL_FreeSurface(surface); - surface = SDL_CreateRGBSurfaceFrom(buf, 5, 1, 8, 5, 0, 0, 0, 0); + surface = SDL_CreateSurfaceFrom(buf, 5, 1, 5, SDL_PIXELFORMAT_INDEX8); SDLTest_AssertCheck(surface != NULL, "5px * 8 bits per px fits in 5 bytes: %s", surface != NULL ? "(success)" : SDL_GetError()); SDL_FreeSurface(surface); - surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 6, 1, 5, SDL_PIXELFORMAT_RGB332); + surface = SDL_CreateSurfaceFrom(buf, 6, 1, 5, SDL_PIXELFORMAT_RGB332); SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp"); SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); - surface = SDL_CreateRGBSurfaceFrom(buf, 6, 1, 8, 5, 0, 0, 0, 0); + surface = SDL_CreateSurfaceFrom(buf, 6, 1, 5, SDL_PIXELFORMAT_INDEX8); SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp"); SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); @@ -714,39 +702,39 @@ int surface_testOverflow(void *arg) /* Everything else requires more than 1 byte per pixel, and rounds up * each pixel to an integer number of bytes (e.g. RGB555 is really * XRGB1555, with 1 bit per pixel wasted). */ - surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 3, 1, 6, SDL_PIXELFORMAT_RGB555); + surface = SDL_CreateSurfaceFrom(buf, 3, 1, 6, SDL_PIXELFORMAT_RGB555); SDLTest_AssertCheck(surface != NULL, "3px * 15 (really 16) bits per px fits in 6 bytes: %s", surface != NULL ? "(success)" : SDL_GetError()); SDL_FreeSurface(surface); - surface = SDL_CreateRGBSurfaceFrom(buf, 3, 1, 15, 6, 0, 0, 0, 0); + surface = SDL_CreateSurfaceFrom(buf, 3, 1, 6, SDL_PIXELFORMAT_RGB555); SDLTest_AssertCheck(surface != NULL, "5px * 15 (really 16) bits per px fits in 6 bytes: %s", surface != NULL ? "(success)" : SDL_GetError()); SDL_FreeSurface(surface); - surface = SDL_CreateRGBSurfaceWithFormatFrom(buf, 4, 1, 6, SDL_PIXELFORMAT_RGB555); + surface = SDL_CreateSurfaceFrom(buf, 4, 1, 6, SDL_PIXELFORMAT_RGB555); SDLTest_AssertCheck(surface == NULL, "4px * 15 (really 16) bits per px doesn't fit in 6 bytes"); SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); - surface = SDL_CreateRGBSurfaceFrom(buf, 4, 1, 15, 6, 0, 0, 0, 0); + surface = SDL_CreateSurfaceFrom(buf, 4, 1, 6, SDL_PIXELFORMAT_XRGB1555); SDLTest_AssertCheck(surface == NULL, "4px * 15 (really 16) bits per px doesn't fit in 6 bytes"); SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); if (sizeof(size_t) == 4 && sizeof(int) >= 4) { expectedError = "Out of memory"; - surface = SDL_CreateRGBSurfaceWithFormat(SDL_MAX_SINT32, 1, SDL_PIXELFORMAT_INDEX8); + surface = SDL_CreateSurface(SDL_MAX_SINT32, 1, SDL_PIXELFORMAT_INDEX8); SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width + alignment"); SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); - surface = SDL_CreateRGBSurfaceWithFormat(SDL_MAX_SINT32 / 2, 1, SDL_PIXELFORMAT_ARGB8888); + surface = SDL_CreateSurface(SDL_MAX_SINT32 / 2, 1, SDL_PIXELFORMAT_ARGB8888); SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width * bytes per pixel"); SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); - surface = SDL_CreateRGBSurfaceWithFormat((1 << 29) - 1, (1 << 29) - 1, SDL_PIXELFORMAT_INDEX8); + surface = SDL_CreateSurface((1 << 29) - 1, (1 << 29) - 1, SDL_PIXELFORMAT_INDEX8); SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width * height"); SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); - surface = SDL_CreateRGBSurfaceWithFormat((1 << 15) + 1, (1 << 15) + 1, SDL_PIXELFORMAT_ARGB8888); + surface = SDL_CreateSurface((1 << 15) + 1, (1 << 15) + 1, SDL_PIXELFORMAT_ARGB8888); SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width * height * bytes per pixel"); SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0, "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError()); diff --git a/test/testoffscreen.c b/test/testoffscreen.c index 12c24b796..4b77a6d73 100644 --- a/test/testoffscreen.c +++ b/test/testoffscreen.c @@ -50,17 +50,16 @@ void draw() void save_surface_to_bmp() { - SDL_Surface *surface; - Uint32 r_mask, g_mask, b_mask, a_mask; + SDL_Surface* surface; Uint32 pixel_format; char file[128]; - int bbp; pixel_format = SDL_GetWindowPixelFormat(window); - SDL_PixelFormatEnumToMasks(pixel_format, &bbp, &r_mask, &g_mask, &b_mask, &a_mask); - surface = SDL_CreateRGBSurface(width, height, bbp, r_mask, g_mask, b_mask, a_mask); - SDL_RenderReadPixels(renderer, NULL, pixel_format, (void *)surface->pixels, surface->pitch); + surface = SDL_CreateSurface(width, height, pixel_format); + + SDL_RenderReadPixels(renderer, NULL, pixel_format, (void*)surface->pixels, surface->pitch); + SDL_snprintf(file, sizeof(file), "SDL_window%" SDL_PRIs32 "-%8.8d.bmp", SDL_GetWindowID(window), ++frame_number); diff --git a/test/testshader.c b/test/testshader.c index 1cc40c5db..13a7dd961 100644 --- a/test/testshader.c +++ b/test/testshader.c @@ -322,15 +322,7 @@ SDL_GL_LoadTexture(SDL_Surface *surface, GLfloat *texcoord) texcoord[2] = (GLfloat)surface->w / w; /* Max X */ texcoord[3] = (GLfloat)surface->h / h; /* Max Y */ - image = SDL_CreateRGBSurface(w, h, 32, -#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */ - 0x000000FF, - 0x0000FF00, 0x00FF0000, 0xFF000000 -#else - 0xFF000000, - 0x00FF0000, 0x0000FF00, 0x000000FF -#endif - ); + image = SDL_CreateSurface(w, h, SDL_PIXELFORMAT_RGBA32); if (image == NULL) { return 0; } diff --git a/test/testyuv.c b/test/testyuv.c index 63d4b4377..a3e70fcf5 100644 --- a/test/testyuv.c +++ b/test/testyuv.c @@ -25,7 +25,7 @@ static SDL_bool is_packed_yuv_format(Uint32 format) /* Create a surface with a good pattern for verifying YUV conversion */ static SDL_Surface *generate_test_pattern(int pattern_size) { - SDL_Surface *pattern = SDL_CreateRGBSurfaceWithFormat(pattern_size, pattern_size, SDL_PIXELFORMAT_RGB24); + SDL_Surface *pattern = SDL_CreateSurface(pattern_size, pattern_size, SDL_PIXELFORMAT_RGB24); if (pattern) { int i, x, y; @@ -334,7 +334,7 @@ int main(int argc, char **argv) 0, 100); pitch = CalculateYUVPitch(yuv_format, original->w); - converted = SDL_CreateRGBSurfaceWithFormat(original->w, original->h, rgb_format); + converted = SDL_CreateSurface(original->w, original->h, rgb_format); if (converted == NULL) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create converted surface: %s\n", SDL_GetError()); return 3;