Mercurial > sdl-ios-xcode
comparison 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 |
comparison
equal
deleted
inserted
replaced
3043:9a20287aaed1 | 3044:b36579172f27 |
---|---|
20 slouken@libsdl.org | 20 slouken@libsdl.org |
21 */ | 21 */ |
22 #include "SDL_config.h" | 22 #include "SDL_config.h" |
23 #include "../SDL_sysvideo.h" | 23 #include "../SDL_sysvideo.h" |
24 #include "SDL_x11video.h" | 24 #include "SDL_x11video.h" |
25 | |
26 /* The size of *all* SDL gamma ramps */ | |
27 #define SDL_GammaRampSize (3 * 256 * sizeof(Uint16)) | |
25 | 28 |
26 static int numCmaps = 0; | 29 static int numCmaps = 0; |
27 | 30 |
28 typedef struct | 31 typedef struct |
29 { | 32 { |
91 cmapTable[numCmaps].scrNum = scrNum; | 94 cmapTable[numCmaps].scrNum = scrNum; |
92 cmapTable[numCmaps].colormap = colormap; | 95 cmapTable[numCmaps].colormap = colormap; |
93 SDL_memcpy(&cmapTable[numCmaps].visual, visual, sizeof(Visual)); | 96 SDL_memcpy(&cmapTable[numCmaps].visual, visual, sizeof(Visual)); |
94 cmapTable[numCmaps].ramp = NULL; | 97 cmapTable[numCmaps].ramp = NULL; |
95 | 98 |
96 newramp = SDL_malloc(3 * 256 * sizeof(Uint16)); /* The size of *all* SDL gamma ramps */ | 99 if (ramp != NULL) { |
97 if (NULL == newramp) { | 100 newramp = SDL_malloc(SDL_GammaRampSize); |
101 if (NULL == newramp) { | |
98 SDL_SetError("Out of memory in X11_TrackColormap()"); | 102 SDL_SetError("Out of memory in X11_TrackColormap()"); |
99 return; | 103 return; |
100 } | 104 } |
101 SDL_memset(newramp, 0, sizeof(*newramp)); | 105 SDL_memset(newramp, 0, SDL_GammaRampSize); |
102 cmapTable[numCmaps].ramp = newramp; | 106 cmapTable[numCmaps].ramp = newramp; |
103 | 107 |
104 ncolors = cmapTable[numCmaps].visual.map_entries; | 108 ncolors = cmapTable[numCmaps].visual.map_entries; |
105 | 109 |
106 for (i = 0; i < ncolors; i++) { | 110 for (i = 0; i < ncolors; i++) { |
107 newramp[(0 * 256) + i] = ramp[i].red; | 111 newramp[(0 * 256) + i] = ramp[i].red; |
108 newramp[(1 * 256) + i] = ramp[i].green; | 112 newramp[(1 * 256) + i] = ramp[i].green; |
109 newramp[(2 * 256) + i] = ramp[i].blue; | 113 newramp[(2 * 256) + i] = ramp[i].blue; |
114 } | |
110 } | 115 } |
111 | 116 |
112 numCmaps++; | 117 numCmaps++; |
113 } | 118 } |
114 | 119 |
142 if (NULL == colorcells) { | 147 if (NULL == colorcells) { |
143 SDL_SetError("out of memory in X11_SetDisplayGammaRamp"); | 148 SDL_SetError("out of memory in X11_SetDisplayGammaRamp"); |
144 return -1; | 149 return -1; |
145 } | 150 } |
146 /* remember the new ramp */ | 151 /* remember the new ramp */ |
147 SDL_memcpy(cmapTable[j].ramp, ramp, sizeof(*cmapTable[j].ramp)); | 152 if (cmapTable[j].ramp == NULL) { |
153 Uint16 * newramp = SDL_malloc(SDL_GammaRampSize); | |
154 if (NULL == newramp) { | |
155 SDL_SetError("Out of memory in X11_TrackColormap()"); | |
156 return -1; | |
157 } | |
158 cmapTable[j].ramp = newramp; | |
159 } | |
160 SDL_memcpy(cmapTable[j].ramp, ramp, SDL_GammaRampSize); | |
148 | 161 |
149 rshift = 0; | 162 rshift = 0; |
150 rmask = visual->red_mask; | 163 rmask = visual->red_mask; |
151 while (0 == (rmask & 1)) { | 164 while (0 == (rmask & 1)) { |
152 rshift++; | 165 rshift++; |
208 /* find the first DirectColor colormap and use it to get the gamma | 221 /* find the first DirectColor colormap and use it to get the gamma |
209 ramp */ | 222 ramp */ |
210 | 223 |
211 for (i = 0; i < numCmaps; i++) { | 224 for (i = 0; i < numCmaps; i++) { |
212 if (cmapTable[i].visual.class == DirectColor) { | 225 if (cmapTable[i].visual.class == DirectColor) { |
213 SDL_memcpy(ramp, cmapTable[i].ramp, sizeof(*cmapTable[i].ramp)); | 226 SDL_memcpy(ramp, cmapTable[i].ramp, SDL_GammaRampSize); |
214 return 0; | 227 return 0; |
215 } | 228 } |
216 } | 229 } |
217 | 230 |
218 return -1; | 231 return -1; |