Fixed bug 2441 - SDL_DuplicateSurface
authorSam Lantinga <slouken@libsdl.org>
Mon, 14 Aug 2017 13:37:14 -0700
changeset 11289ca3c2c98f2e1
parent 11288 47a5a4999180
child 11290 ef96b05151c5
Fixed bug 2441 - SDL_DuplicateSurface


Rainer Deyke

I've written a small patch that adds a small SDL_DuplicateSurface function to SDL. I've written the function as part of a larger (as yet unfinished) patch, but I think this function is useful enough that it merits inclusion in SDL on its own.
include/SDL_surface.h
src/dynapi/SDL_dynapi_overrides.h
src/dynapi/SDL_dynapi_procs.h
src/video/SDL_surface.c
     1.1 --- a/include/SDL_surface.h	Mon Aug 14 10:28:47 2017 -0700
     1.2 +++ b/include/SDL_surface.h	Mon Aug 14 13:37:14 2017 -0700
     1.3 @@ -359,6 +359,11 @@
     1.4  extern DECLSPEC void SDLCALL SDL_GetClipRect(SDL_Surface * surface,
     1.5                                               SDL_Rect * rect);
     1.6  
     1.7 +/*
     1.8 + * Creates a new surface identical to the existing surface
     1.9 + */
    1.10 +extern DECLSPEC SDL_Surface *SDLCALL SDL_DuplicateSurface(SDL_Surface * surface);
    1.11 +
    1.12  /**
    1.13   *  Creates a new surface of the specified format, and then copies and maps
    1.14   *  the given surface to it so the blit of the converted surface will be as
     2.1 --- a/src/dynapi/SDL_dynapi_overrides.h	Mon Aug 14 10:28:47 2017 -0700
     2.2 +++ b/src/dynapi/SDL_dynapi_overrides.h	Mon Aug 14 13:37:14 2017 -0700
     2.3 @@ -628,3 +628,4 @@
     2.4  #define SDL_LoadFile_RW SDL_LoadFile_RW_REAL
     2.5  #define SDL_wcscmp SDL_wcscmp_REAL
     2.6  #define SDL_ComposeCustomBlendMode SDL_ComposeCustomBlendMode_REAL
     2.7 +#define SDL_DuplicateSurface SDL_DuplicateSurface_REAL
     3.1 --- a/src/dynapi/SDL_dynapi_procs.h	Mon Aug 14 10:28:47 2017 -0700
     3.2 +++ b/src/dynapi/SDL_dynapi_procs.h	Mon Aug 14 13:37:14 2017 -0700
     3.3 @@ -660,3 +660,4 @@
     3.4  SDL_DYNAPI_PROC(void*,SDL_LoadFile_RW,(SDL_RWops *a, size_t *b, int c),(a,b,c),return)
     3.5  SDL_DYNAPI_PROC(int,SDL_wcscmp,(const wchar_t *a, const wchar_t *b),(a,b),return)
     3.6  SDL_DYNAPI_PROC(SDL_BlendMode,SDL_ComposeCustomBlendMode,(SDL_BlendFactor a, SDL_BlendFactor b, SDL_BlendOperation c, SDL_BlendFactor d, SDL_BlendFactor e, SDL_BlendOperation f),(a,b,c,d,e,f),return)
     3.7 +SDL_DYNAPI_PROC(SDL_Surface*,SDL_DuplicateSurface,(SDL_Surface *a),(a),return)
     4.1 --- a/src/video/SDL_surface.c	Mon Aug 14 10:28:47 2017 -0700
     4.2 +++ b/src/video/SDL_surface.c	Mon Aug 14 13:37:14 2017 -0700
     4.3 @@ -871,6 +871,15 @@
     4.4  }
     4.5  
     4.6  /*
     4.7 + * Creates a new surface identical to the existing surface
     4.8 + */
     4.9 +SDL_Surface *
    4.10 +SDL_DuplicateSurface(SDL_Surface * surface)
    4.11 +{
    4.12 +    return SDL_ConvertSurface(surface, surface->format, surface->flags);
    4.13 +}
    4.14 +
    4.15 +/*
    4.16   * Convert a surface into the specified pixel format.
    4.17   */
    4.18  SDL_Surface *
    4.19 @@ -882,6 +891,15 @@
    4.20      SDL_Color copy_color;
    4.21      SDL_Rect bounds;
    4.22  
    4.23 +    if (!surface) {
    4.24 +        SDL_InvalidParamError("surface");
    4.25 +        return NULL;
    4.26 +    }
    4.27 +    if (!format) {
    4.28 +        SDL_InvalidParamError("format");
    4.29 +        return NULL;
    4.30 +    }
    4.31 +
    4.32      /* Check for empty destination palette! (results in empty image) */
    4.33      if (format->palette != NULL) {
    4.34          int i;