Mercurial > sdl-ios-xcode
diff src/video/x11/SDL_x11gamma.c @ 3044:b36579172f27
Changes to hopefully handle the creation of a colormap for 8 bit PseudoColor visuals in X11
author | Bob Pendleton <bob@pendleton.com> |
---|---|
date | Thu, 15 Jan 2009 21:35:42 +0000 |
parents | a6694a812119 |
children | b7197d7e8566 |
line wrap: on
line diff
--- a/src/video/x11/SDL_x11gamma.c Wed Jan 14 15:03:44 2009 +0000 +++ b/src/video/x11/SDL_x11gamma.c Thu Jan 15 21:35:42 2009 +0000 @@ -23,6 +23,9 @@ #include "../SDL_sysvideo.h" #include "SDL_x11video.h" + /* The size of *all* SDL gamma ramps */ +#define SDL_GammaRampSize (3 * 256 * sizeof(Uint16)) + static int numCmaps = 0; typedef struct @@ -93,20 +96,22 @@ SDL_memcpy(&cmapTable[numCmaps].visual, visual, sizeof(Visual)); cmapTable[numCmaps].ramp = NULL; - newramp = SDL_malloc(3 * 256 * sizeof(Uint16)); /* The size of *all* SDL gamma ramps */ - if (NULL == newramp) { + if (ramp != NULL) { + newramp = SDL_malloc(SDL_GammaRampSize); + if (NULL == newramp) { SDL_SetError("Out of memory in X11_TrackColormap()"); return; - } - SDL_memset(newramp, 0, sizeof(*newramp)); - cmapTable[numCmaps].ramp = newramp; + } + SDL_memset(newramp, 0, SDL_GammaRampSize); + cmapTable[numCmaps].ramp = newramp; - ncolors = cmapTable[numCmaps].visual.map_entries; + ncolors = cmapTable[numCmaps].visual.map_entries; - for (i = 0; i < ncolors; i++) { + for (i = 0; i < ncolors; i++) { newramp[(0 * 256) + i] = ramp[i].red; newramp[(1 * 256) + i] = ramp[i].green; newramp[(2 * 256) + i] = ramp[i].blue; + } } numCmaps++; @@ -144,7 +149,15 @@ return -1; } /* remember the new ramp */ - SDL_memcpy(cmapTable[j].ramp, ramp, sizeof(*cmapTable[j].ramp)); + if (cmapTable[j].ramp == NULL) { + Uint16 * newramp = SDL_malloc(SDL_GammaRampSize); + if (NULL == newramp) { + SDL_SetError("Out of memory in X11_TrackColormap()"); + return -1; + } + cmapTable[j].ramp = newramp; + } + SDL_memcpy(cmapTable[j].ramp, ramp, SDL_GammaRampSize); rshift = 0; rmask = visual->red_mask; @@ -210,7 +223,7 @@ for (i = 0; i < numCmaps; i++) { if (cmapTable[i].visual.class == DirectColor) { - SDL_memcpy(ramp, cmapTable[i].ramp, sizeof(*cmapTable[i].ramp)); + SDL_memcpy(ramp, cmapTable[i].ramp, SDL_GammaRampSize); return 0; } }