Mercurial > sdl-ios-xcode
comparison src/video/x11/SDL_x11window.c @ 2214:e7164a4dac62
Added gamma table support to X11. Also now supports DirectColor visuals.
author | Bob Pendleton <bob@pendleton.com> |
---|---|
date | Wed, 25 Jul 2007 21:22:55 +0000 |
parents | 59a667370c57 |
children | c5feceb0395e |
comparison
equal
deleted
inserted
replaced
2213:59a667370c57 | 2214:e7164a4dac62 |
---|---|
179 } else { | 179 } else { |
180 xattr.override_redirect = False; | 180 xattr.override_redirect = False; |
181 } | 181 } |
182 xattr.background_pixel = 0; | 182 xattr.background_pixel = 0; |
183 xattr.border_pixel = 0; | 183 xattr.border_pixel = 0; |
184 | |
184 if (visual->class == DirectColor || visual->class == PseudoColor) { | 185 if (visual->class == DirectColor || visual->class == PseudoColor) { |
185 int nmaps; | 186 int nmaps; |
187 XStandardColormap cmap; | |
186 XStandardColormap *stdmaps; | 188 XStandardColormap *stdmaps; |
189 XColor *colorcells; | |
190 Colormap colormap; | |
187 Bool found = False; | 191 Bool found = False; |
188 | 192 int i; |
189 /* check to see if the colormap we need already exists */ | 193 int ncolors; |
190 if (0 != XGetRGBColormaps(data->display, | 194 int rmax, gmax, bmax; |
191 RootWindow(data->display, | 195 int rmul, gmul, bmul; |
192 displaydata->screen), &stdmaps, | 196 |
193 &nmaps, XA_RGB_BEST_MAP)) { | 197 if (colormap = |
194 int i; | 198 X11_LookupColormap(data->display, displaydata->screen, |
195 for (i = 0; i < nmaps; i++) { | 199 visual->visualid)) { |
196 if (stdmaps[i].visualid == visual->visualid) { | 200 xattr.colormap = colormap; |
197 xattr.colormap = stdmaps[i].colormap; | 201 } else { |
198 X11_TrackColormap(data->display, displaydata->screen, | 202 /* check to see if the colormap we need already exists */ |
199 &stdmaps[i], visual); | 203 if (0 != XGetRGBColormaps(data->display, |
200 found = True; | 204 RootWindow(data->display, |
201 break; | 205 displaydata->screen), |
206 &stdmaps, &nmaps, XA_RGB_BEST_MAP)) { | |
207 for (i = 0; i < nmaps; i++) { | |
208 if (stdmaps[i].visualid == visual->visualid) { | |
209 SDL_memcpy(&cmap, &stdmaps[i], | |
210 sizeof(XStandardColormap)); | |
211 found = True; | |
212 break; | |
213 } | |
202 } | 214 } |
215 XFree(stdmaps); | |
203 } | 216 } |
204 XFree(stdmaps); | 217 |
205 } | 218 /* it doesn't exist, so create it */ |
206 | 219 if (!found) { |
207 /* it doesn't exist, so create it */ | 220 int max = visual->map_entries - 1; |
208 if (!found) { | 221 stdmaps = |
209 int max = visual->map_entries - 1; | 222 XmuStandardColormap(data->display, displaydata->screen, |
210 XStandardColormap *cmap = | 223 visual->visualid, depth, |
211 XmuStandardColormap(data->display, displaydata->screen, | 224 XA_RGB_BEST_MAP, None, max, max, max); |
212 visual->visualid, depth, | 225 if (NULL == stdmaps || stdmaps->visualid != visual->visualid) { |
213 XA_RGB_BEST_MAP, None, | 226 SDL_SetError |
214 max, max, max); | 227 ("Couldn't create window:XA_RGB_BEST_MAP not found and could not be created"); |
215 if (NULL != cmap && cmap->visualid == visual->visualid) { | 228 return -1; |
216 xattr.colormap = cmap->colormap; | 229 } |
217 X11_TrackColormap(data->display, displaydata->screen, cmap, | 230 SDL_memcpy(&cmap, stdmaps, sizeof(XStandardColormap)); |
218 visual); | 231 } |
219 } else { | 232 |
220 SDL_SetError | 233 /* OK, we have the best color map, now copy it for use by the |
221 ("Couldn't create window:XA_RGB_BEST_MAP not found"); | 234 program */ |
235 | |
236 colorcells = SDL_malloc(visual->map_entries * sizeof(XColor)); | |
237 if (NULL == colorcells) { | |
238 SDL_SetError("out of memory in X11_CreateWindow"); | |
222 return -1; | 239 return -1; |
223 } | 240 } |
241 ncolors = visual->map_entries; | |
242 rmax = cmap.red_max + 1; | |
243 gmax = cmap.blue_max + 1; | |
244 bmax = cmap.green_max + 1; | |
245 | |
246 rmul = cmap.red_mult; | |
247 gmul = cmap.blue_mult; | |
248 bmul = cmap.green_mult; | |
249 | |
250 /* build the color table pixel values */ | |
251 for (i = 0; i < ncolors; i++) { | |
252 Uint32 red = (rmax * i) / ncolors; | |
253 Uint32 green = (gmax * i) / ncolors; | |
254 Uint32 blue = (bmax * i) / ncolors; | |
255 | |
256 colorcells[i].pixel = | |
257 (red * rmul) | (green * gmul) | (blue * bmul); | |
258 } | |
259 XQueryColors(data->display, cmap.colormap, colorcells, ncolors); | |
260 colormap = XCreateColormap(data->display, | |
261 RootWindow(data->display, | |
262 displaydata->screen), | |
263 visual, AllocAll); | |
264 XStoreColors(data->display, colormap, colorcells, ncolors); | |
265 SDL_free(colorcells); | |
266 | |
267 xattr.colormap = colormap; | |
268 X11_TrackColormap(data->display, displaydata->screen, colormap, | |
269 &cmap, visual); | |
224 } | 270 } |
225 } else { | 271 } else { |
226 xattr.colormap = | 272 xattr.colormap = |
227 XCreateColormap(data->display, | 273 XCreateColormap(data->display, |
228 RootWindow(data->display, displaydata->screen), | 274 RootWindow(data->display, displaydata->screen), |