comparison test/testalpha.c @ 2799:bbf3aac2672a

Again, map the color with the alpha channel filled in.
author Sam Lantinga <slouken@libsdl.org>
date Fri, 28 Nov 2008 20:09:32 +0000
parents c81150fedf6f
children 938aa47f903a
comparison
equal deleted inserted replaced
2798:5f3831f1c3ea 2799:bbf3aac2672a
23 /* Fill the screen with a gradient */ 23 /* Fill the screen with a gradient */
24 static void 24 static void
25 FillBackground(SDL_Surface * screen) 25 FillBackground(SDL_Surface * screen)
26 { 26 {
27 Uint8 *buffer; 27 Uint8 *buffer;
28 Uint16 *buffer16;
29 Uint16 color;
30 Uint8 gradient; 28 Uint8 gradient;
31 int i, k; 29 int i, k;
32 30
33 /* Set the surface pixels and refresh! */ 31 /* Set the surface pixels and refresh! */
34 if (SDL_LockSurface(screen) < 0) { 32 if (SDL_LockSurface(screen) < 0) {
35 fprintf(stderr, "Couldn't lock the display surface: %s\n", 33 fprintf(stderr, "Couldn't lock the display surface: %s\n",
36 SDL_GetError()); 34 SDL_GetError());
37 quit(2); 35 quit(2);
38 } 36 }
39 buffer = (Uint8 *) screen->pixels; 37 buffer = (Uint8 *) screen->pixels;
40 if (screen->format->BytesPerPixel != 2) { 38 switch (screen->format->BytesPerPixel) {
41 for (i = 0; i < screen->h; ++i) { 39 case 1:
42 memset(buffer, (i * 255) / screen->h, 40 case 3:
43 screen->w * screen->format->BytesPerPixel); 41 for (i = 0; i < screen->h; ++i) {
44 buffer += screen->pitch; 42 memset(buffer, (i * 255) / screen->h,
45 } 43 screen->w * screen->format->BytesPerPixel);
46 } else { 44 buffer += screen->pitch;
47 for (i = 0; i < screen->h; ++i) {
48 gradient = ((i * 255) / screen->h);
49 color =
50 (Uint16) SDL_MapRGB(screen->format, gradient, gradient,
51 gradient);
52 buffer16 = (Uint16 *) buffer;
53 for (k = 0; k < screen->w; k++) {
54 *(buffer16 + k) = color;
55 } 45 }
56 buffer += screen->pitch; 46 break;
57 } 47 case 2:
48 for (i = 0; i < screen->h; ++i) {
49 Uint16 *buffer16;
50 Uint16 color;
51
52 gradient = ((i * 255) / screen->h);
53 color = (Uint16) SDL_MapRGB(screen->format,
54 gradient, gradient, gradient);
55 buffer16 = (Uint16 *) buffer;
56 for (k = 0; k < screen->w; k++) {
57 *buffer16++ = color;
58 }
59 buffer += screen->pitch;
60 }
61 break;
62 case 4:
63 for (i = 0; i < screen->h; ++i) {
64 Uint32 *buffer32;
65 Uint32 color;
66
67 gradient = ((i * 255) / screen->h);
68 color = SDL_MapRGB(screen->format,
69 gradient, gradient, gradient);
70 buffer32 = (Uint32 *) buffer;
71 for (k = 0; k < screen->w; k++) {
72 *buffer32++ = color;
73 }
74 buffer += screen->pitch;
75 }
76 break;
58 } 77 }
59 78
60 SDL_UnlockSurface(screen); 79 SDL_UnlockSurface(screen);
61 SDL_UpdateRect(screen, 0, 0, 0, 0); 80 SDL_UpdateRect(screen, 0, 0, 0, 0);
62 } 81 }