comparison src/video/x11/SDL_x11window.c @ 3052:b7197d7e8566

indent
author Sam Lantinga <slouken@libsdl.org>
date Fri, 30 Jan 2009 06:38:44 +0000
parents b36579172f27
children 089a77aebb7d
comparison
equal deleted inserted replaced
3051:1a45bc89db0c 3052:b7197d7e8566
218 218
219 Status status; 219 Status status;
220 XStandardColormap cmap; 220 XStandardColormap cmap;
221 XColor *colorcells; 221 XColor *colorcells;
222 Colormap colormap; 222 Colormap colormap;
223 Sint32 pix; 223 Sint32 pix;
224 Sint32 ncolors; 224 Sint32 ncolors;
225 Sint32 nbits; 225 Sint32 nbits;
226 Sint32 rmax, gmax, bmax; 226 Sint32 rmax, gmax, bmax;
227 Sint32 rwidth, gwidth, bwidth; 227 Sint32 rwidth, gwidth, bwidth;
228 Sint32 rmask, gmask, bmask; 228 Sint32 rmask, gmask, bmask;
229 Sint32 rshift, gshift, bshift; 229 Sint32 rshift, gshift, bshift;
230 Sint32 r, g, b; 230 Sint32 r, g, b;
231 231
232 /* Is the colormap we need already registered in SDL? */ 232 /* Is the colormap we need already registered in SDL? */
233 if (colormap = 233 if (colormap =
234 X11_LookupColormap(data->display, 234 X11_LookupColormap(data->display,
235 displaydata->screen, visual->visualid)) { 235 displaydata->screen, visual->visualid)) {
257 SDL_SetError("out of memory in X11_CreateWindow"); 257 SDL_SetError("out of memory in X11_CreateWindow");
258 return -1; 258 return -1;
259 } 259 }
260 260
261 ncolors = visual->map_entries; 261 ncolors = visual->map_entries;
262 nbits = visual->bits_per_rgb; 262 nbits = visual->bits_per_rgb;
263 263
264 /* printf("ncolors = %d nbits = %d\n", ncolors, nbits); */ 264 /* printf("ncolors = %d nbits = %d\n", ncolors, nbits); */
265 265
266 /* what if ncolors != (1 << nbits)? That can happen on a 266 /* what if ncolors != (1 << nbits)? That can happen on a
267 true PseudoColor display. I'm assuming that we will 267 true PseudoColor display. I'm assuming that we will
268 always have ncolors == (1 << nbits)*/ 268 always have ncolors == (1 << nbits) */
269 269
270 /* I'm making a lot of assumptions here. */ 270 /* I'm making a lot of assumptions here. */
271 271
272 /* Compute the width of each field. If there is one extra 272 /* Compute the width of each field. If there is one extra
273 bit, give it to green. If there are two extra bits give 273 bit, give it to green. If there are two extra bits give
274 them to red and greed. We can get extra bits when the 274 them to red and greed. We can get extra bits when the
275 number of bits per pixel is not a multiple of 3. For 275 number of bits per pixel is not a multiple of 3. For
276 example when we have 16 bits per pixel and need a 5/6/5 276 example when we have 16 bits per pixel and need a 5/6/5
277 layout for the RGB fields */ 277 layout for the RGB fields */
278 278
279 rwidth = (nbits / 3) + (((nbits % 3) == 2) ? 1 : 0); 279 rwidth = (nbits / 3) + (((nbits % 3) == 2) ? 1 : 0);
280 gwidth = (nbits / 3) + (((nbits % 3) >= 1) ? 1 : 0); 280 gwidth = (nbits / 3) + (((nbits % 3) >= 1) ? 1 : 0);
281 bwidth = (nbits / 3); 281 bwidth = (nbits / 3);
282 282
283 rshift = gwidth + bwidth; 283 rshift = gwidth + bwidth;
284 gshift = bwidth; 284 gshift = bwidth;
285 bshift = 0; 285 bshift = 0;
286 286
295 /* printf("red mask = %4x shift = %4d width = %d\n", rmask, rshift, rwidth); */ 295 /* printf("red mask = %4x shift = %4d width = %d\n", rmask, rshift, rwidth); */
296 /* printf("green mask = %4x shift = %4d width = %d\n", gmask, gshift, gwidth); */ 296 /* printf("green mask = %4x shift = %4d width = %d\n", gmask, gshift, gwidth); */
297 /* printf("blue mask = %4x shift = %4d width = %d\n", bmask, bshift, bwidth); */ 297 /* printf("blue mask = %4x shift = %4d width = %d\n", bmask, bshift, bwidth); */
298 298
299 /* build the color table pixel values */ 299 /* build the color table pixel values */
300 pix = 0; 300 pix = 0;
301 for (r = 0; r < rmax; r++) { 301 for (r = 0; r < rmax; r++) {
302 for (g = 0; g < gmax; g++) { 302 for (g = 0; g < gmax; g++) {
303 for (b = 0; b < bmax; b++) { 303 for (b = 0; b < bmax; b++) {
304 colorcells[pix].pixel = (r << rshift) | (g << gshift) | (b << bshift); 304 colorcells[pix].pixel =
305 colorcells[pix].red = (0xffff * r) / rmask; 305 (r << rshift) | (g << gshift) | (b << bshift);
306 colorcells[pix].green = (0xffff * g) / gmask; 306 colorcells[pix].red = (0xffff * r) / rmask;
307 colorcells[pix].blue = (0xffff * b) / bmask; 307 colorcells[pix].green = (0xffff * g) / gmask;
308 colorcells[pix].blue = (0xffff * b) / bmask;
308 /* printf("%4x:%4x [%4x %4x %4x]\n", */ 309 /* printf("%4x:%4x [%4x %4x %4x]\n", */
309 /* pix, */ 310 /* pix, */
310 /* colorcells[pix].pixel, */ 311 /* colorcells[pix].pixel, */
311 /* colorcells[pix].red, */ 312 /* colorcells[pix].red, */
312 /* colorcells[pix].green, */ 313 /* colorcells[pix].green, */
313 /* colorcells[pix].blue); */ 314 /* colorcells[pix].blue); */
314 pix++; 315 pix++;
315 } 316 }
316 } 317 }
317 } 318 }
318 319
319 /* status = */ 320 /* status = */
320 /* XStoreColors(data->display, colormap, colorcells, ncolors); */ 321 /* XStoreColors(data->display, colormap, colorcells, ncolors); */
321 322
322 xattr.colormap = colormap; 323 xattr.colormap = colormap;