Mercurial > hg > dmlib
changeset 1154:494fa5998b65
Move RGBA mask definitions to static global variables that are
chosen at compile time based on endianess.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 05 Mar 2015 05:23:19 +0200 |
parents | 782516a8e3dd |
children | d46966ad3b08 |
files | src/dmimage.c |
diffstat | 1 files changed, 22 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/src/dmimage.c Thu Mar 05 05:21:42 2015 +0200 +++ b/src/dmimage.c Thu Mar 05 05:23:19 2015 +0200 @@ -29,31 +29,35 @@ #include "stb_image.c" -SDL_Surface *dmCreateRGBSurfaceFrom(void *data, const int width, const int height, const int depth, const int pitch, const int rmask, const int gmask, const int bmask, const int amask) +static Uint32 +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + dmXrmask = 0xff000000, + dmXgmask = 0x00ff0000, + dmXbmask = 0x0000ff00, + dmXamask = 0x000000ff; +#else + dmXrmask = 0x000000ff, + dmXgmask = 0x0000ff00, + dmXbmask = 0x00ff0000, + dmXamask = 0xff000000; +#endif + + +SDL_Surface *dmCreateRGBSurfaceFrom(void *data, + const int width, const int height, + const int depth, const int pitch, + const int rmask, const int gmask, const int bmask, const int amask) { // Create source surface from given data SDL_Surface *tmp = SDL_CreateRGBSurfaceFrom(data, width, height, depth, pitch, bmask, gmask, rmask, amask); - // Result surface component orders as masks -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - Uint32 - Xrmask = 0xff000000, - Xgmask = 0x00ff0000, - Xbmask = 0x0000ff00, - Xamask = 0x000000ff; -#else - Uint32 - Xrmask = 0x000000ff, - Xgmask = 0x0000ff00, - Xbmask = 0x00ff0000, - Xamask = 0xff000000; -#endif - // Create result conversion surface SDL_Surface *result = NULL, *pixtmp = SDL_CreateRGBSurface( - SDL_SWSURFACE | SDL_SRCALPHA, 16, 16, 32, Xrmask, Xgmask, Xbmask, Xamask); + SDL_SWSURFACE | SDL_SRCALPHA, + 16, 16, 32, + dmXrmask, dmXgmask, dmXbmask, dmXamask); if (tmp != NULL && pixtmp != NULL) { @@ -139,19 +143,8 @@ switch (comp) { case 4: -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - rmask = 0xff000000; - gmask = 0x00ff0000; - bmask = 0x0000ff00; - amask = 0x000000ff; -#else - rmask = 0x000000ff; - gmask = 0x0000ff00; - bmask = 0x00ff0000; - amask = 0xff000000; -#endif result = dmCreateRGBSurfaceFrom(data, width, height, comp * 8, - width * comp, rmask, gmask, bmask, amask); + width * comp, dmXrmask, dmXgmask, dmXbmask, dmXamask); break; case 3: