diff -r eaafb42daa70 include/SDL_surface.h --- a/include/SDL_surface.h Sat Mar 21 22:42:53 2015 +0100 +++ b/include/SDL_surface.h Sun Mar 22 02:56:23 2015 +0100 @@ -118,6 +118,8 @@ extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurface (Uint32 flags, int width, int height, int depth, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask); +extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceWithFormat + (Uint32 flags, int width, int height, int depth, Uint32 format); extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceFrom(void *pixels, int width, int height, @@ -127,6 +129,8 @@ Uint32 Gmask, Uint32 Bmask, Uint32 Amask); +extern DECLSPEC SDL_Surface *SDLCALL SDL_CreateRGBSurfaceWithFormatFrom + (void *pixels, int width, int height, int depth, int pitch, Uint32 format); extern DECLSPEC void SDLCALL SDL_FreeSurface(SDL_Surface * surface); /** diff -r eaafb42daa70 src/dynapi/SDL_dynapi_overrides.h --- a/src/dynapi/SDL_dynapi_overrides.h Sat Mar 21 22:42:53 2015 +0100 +++ b/src/dynapi/SDL_dynapi_overrides.h Sun Mar 22 02:56:23 2015 +0100 @@ -445,6 +445,8 @@ #define SDL_iconv_close SDL_iconv_close_REAL #define SDL_iconv SDL_iconv_REAL #define SDL_iconv_string SDL_iconv_string_REAL +#define SDL_CreateRGBSurfaceWithFormat SDL_CreateRGBSurfaceWithFormat_REAL +#define SDL_CreateRGBSurfaceWithFormatFrom SDL_CreateRGBSurfaceWithFormatFrom_REAL #define SDL_CreateRGBSurface SDL_CreateRGBSurface_REAL #define SDL_CreateRGBSurfaceFrom SDL_CreateRGBSurfaceFrom_REAL #define SDL_FreeSurface SDL_FreeSurface_REAL @@ -591,3 +593,5 @@ #define SDL_QueueAudio SDL_QueueAudio_REAL #define SDL_GetQueuedAudioSize SDL_GetQueuedAudioSize_REAL #define SDL_ClearQueuedAudio SDL_ClearQueuedAudio_REAL +#define SDL_CreateRGBSurfaceWithFormat SDL_CreateRGBSurfaceWithFormat_REAL +#define SDL_CreateRGBSurfaceWithFormatFrom SDL_CreateRGBSurfaceWithFormatFrom_REAL diff -r eaafb42daa70 src/dynapi/SDL_dynapi_procs.h --- a/src/dynapi/SDL_dynapi_procs.h Sat Mar 21 22:42:53 2015 +0100 +++ b/src/dynapi/SDL_dynapi_procs.h Sun Mar 22 02:56:23 2015 +0100 @@ -623,3 +623,5 @@ SDL_DYNAPI_PROC(int,SDL_QueueAudio,(SDL_AudioDeviceID a, const void *b, Uint32 c),(a,b,c),return) SDL_DYNAPI_PROC(Uint32,SDL_GetQueuedAudioSize,(SDL_AudioDeviceID a),(a),return) SDL_DYNAPI_PROC(void,SDL_ClearQueuedAudio,(SDL_AudioDeviceID a),(a),) +SDL_DYNAPI_PROC(SDL_Surface*,SDL_CreateRGBSurfaceWithFormat,(Uint32 a, int b, int c, int d, Uint32 e),(a,b,c,d,e),return) +SDL_DYNAPI_PROC(SDL_Surface*,SDL_CreateRGBSurfaceWithFormatFrom,(void *a, int b, int c, int d, int e, Uint32 f),(a,b,c,d,e,f),return) diff -r eaafb42daa70 src/video/SDL_surface.c --- a/src/video/SDL_surface.c Sat Mar 21 22:42:53 2015 +0100 +++ b/src/video/SDL_surface.c Sun Mar 22 02:56:23 2015 +0100 @@ -27,27 +27,16 @@ #include "SDL_pixels_c.h" /* Public routines */ + /* - * Create an empty RGB surface of the appropriate depth + * Create an empty RGB surface of the appropriate depth using the given given + * enum SDL_PIXELFORMAT_* format */ SDL_Surface * -SDL_CreateRGBSurface(Uint32 flags, - int width, int height, int depth, - Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) +SDL_CreateRGBSurfaceWithFormat(Uint32 flags, int width, int height, int depth, + Uint32 format) { SDL_Surface *surface; - Uint32 format; - - /* The flags are no longer used, make the compiler happy */ - (void)flags; - - /* Get the pixel format */ - format = SDL_MasksToPixelFormatEnum(depth, Rmask, Gmask, Bmask, Amask); - if (format == SDL_PIXELFORMAT_UNKNOWN) { - SDL_SetError("Unknown pixel format"); - return NULL; - } - /* Allocate the surface */ surface = (SDL_Surface *) SDL_calloc(1, sizeof(*surface)); if (surface == NULL) { @@ -105,7 +94,7 @@ } /* By default surface with an alpha mask are set up for blending */ - if (Amask) { + if (surface->format->Amask) { SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND); } @@ -115,6 +104,30 @@ } /* + * Create an empty RGB surface of the appropriate depth + */ +SDL_Surface * +SDL_CreateRGBSurface(Uint32 flags, + int width, int height, int depth, + Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask) +{ + SDL_Surface *surface; + Uint32 format; + + /* The flags are no longer used, make the compiler happy */ + (void)flags; + + /* 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(flags, width, height, depth, format); +} + +/* * Create an RGB surface from an existing memory buffer */ SDL_Surface * @@ -138,6 +151,29 @@ 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 depth, int pitch, + Uint32 format) +{ + SDL_Surface *surface; + + surface = SDL_CreateRGBSurfaceWithFormat(0, 0, 0, depth, 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; +} + int SDL_SetSurfacePalette(SDL_Surface * surface, SDL_Palette * palette) {