Again, map the color with the alpha channel filled in.
authorSam Lantinga <slouken@libsdl.org>
Fri, 28 Nov 2008 20:09:32 +0000
changeset 2799bbf3aac2672a
parent 2798 5f3831f1c3ea
child 2800 8969da2ef606
Again, map the color with the alpha channel filled in.
test/testalpha.c
     1.1 --- a/test/testalpha.c	Fri Nov 28 19:59:46 2008 +0000
     1.2 +++ b/test/testalpha.c	Fri Nov 28 20:09:32 2008 +0000
     1.3 @@ -25,8 +25,6 @@
     1.4  FillBackground(SDL_Surface * screen)
     1.5  {
     1.6      Uint8 *buffer;
     1.7 -    Uint16 *buffer16;
     1.8 -    Uint16 color;
     1.9      Uint8 gradient;
    1.10      int i, k;
    1.11  
    1.12 @@ -37,24 +35,45 @@
    1.13          quit(2);
    1.14      }
    1.15      buffer = (Uint8 *) screen->pixels;
    1.16 -    if (screen->format->BytesPerPixel != 2) {
    1.17 -        for (i = 0; i < screen->h; ++i) {
    1.18 -            memset(buffer, (i * 255) / screen->h,
    1.19 -                   screen->w * screen->format->BytesPerPixel);
    1.20 -            buffer += screen->pitch;
    1.21 -        }
    1.22 -    } else {
    1.23 -        for (i = 0; i < screen->h; ++i) {
    1.24 -            gradient = ((i * 255) / screen->h);
    1.25 -            color =
    1.26 -                (Uint16) SDL_MapRGB(screen->format, gradient, gradient,
    1.27 -                                    gradient);
    1.28 -            buffer16 = (Uint16 *) buffer;
    1.29 -            for (k = 0; k < screen->w; k++) {
    1.30 -                *(buffer16 + k) = color;
    1.31 +    switch (screen->format->BytesPerPixel) {
    1.32 +        case 1:
    1.33 +        case 3:
    1.34 +            for (i = 0; i < screen->h; ++i) {
    1.35 +                memset(buffer, (i * 255) / screen->h,
    1.36 +                       screen->w * screen->format->BytesPerPixel);
    1.37 +                buffer += screen->pitch;
    1.38              }
    1.39 -            buffer += screen->pitch;
    1.40 -        }
    1.41 +            break;
    1.42 +        case 2:
    1.43 +            for (i = 0; i < screen->h; ++i) {
    1.44 +                Uint16 *buffer16;
    1.45 +                Uint16 color;
    1.46 +
    1.47 +                gradient = ((i * 255) / screen->h);
    1.48 +                color = (Uint16) SDL_MapRGB(screen->format,
    1.49 +                                            gradient, gradient, gradient);
    1.50 +                buffer16 = (Uint16 *) buffer;
    1.51 +                for (k = 0; k < screen->w; k++) {
    1.52 +                    *buffer16++ = color;
    1.53 +                }
    1.54 +                buffer += screen->pitch;
    1.55 +            }
    1.56 +            break;
    1.57 +        case 4:
    1.58 +            for (i = 0; i < screen->h; ++i) {
    1.59 +                Uint32 *buffer32;
    1.60 +                Uint32 color;
    1.61 +
    1.62 +                gradient = ((i * 255) / screen->h);
    1.63 +                color = SDL_MapRGB(screen->format,
    1.64 +                                   gradient, gradient, gradient);
    1.65 +                buffer32 = (Uint32 *) buffer;
    1.66 +                for (k = 0; k < screen->w; k++) {
    1.67 +                    *buffer32++ = color;
    1.68 +                }
    1.69 +                buffer += screen->pitch;
    1.70 +            }
    1.71 +            break;
    1.72      }
    1.73  
    1.74      SDL_UnlockSurface(screen);