test/testbitmap.c
changeset 691 609543e2b3a1
parent 0 74212992fb08
child 1151 be9c9c8f6d53
     1.1 --- a/test/testbitmap.c	Sat Aug 23 23:12:19 2003 +0000
     1.2 +++ b/test/testbitmap.c	Sat Aug 23 23:18:49 2003 +0000
     1.3 @@ -50,8 +50,13 @@
     1.4  	Uint8  video_bpp;
     1.5  	Uint32 videoflags;
     1.6  	Uint8 *buffer;
     1.7 -	int i, done;
     1.8 +	int i, k, done;
     1.9  	SDL_Event event;
    1.10 +	Uint16 *buffer16;
    1.11 +        Uint16 color;
    1.12 +        Uint8  gradient;
    1.13 +	SDL_Color palette[256];
    1.14 +
    1.15  
    1.16  	/* Initialize SDL */
    1.17  	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
    1.18 @@ -91,6 +96,16 @@
    1.19  		exit(2);
    1.20  	}
    1.21  
    1.22 +	if (video_bpp==8) {
    1.23 +		/* Set a gray colormap, reverse order from white to black */
    1.24 +		for ( i=0; i<256; ++i ) {
    1.25 +			palette[i].r = 255-i;
    1.26 +			palette[i].g = 255-i;
    1.27 +			palette[i].b = 255-i;
    1.28 +		}
    1.29 +		SDL_SetColors(screen, palette, 0, 256);
    1.30 +	}
    1.31 +
    1.32  	/* Set the surface pixels and refresh! */
    1.33  	if ( SDL_LockSurface(screen) < 0 ) {
    1.34  		fprintf(stderr, "Couldn't lock the display surface: %s\n",
    1.35 @@ -98,10 +113,25 @@
    1.36  		exit(2);
    1.37  	}
    1.38  	buffer=(Uint8 *)screen->pixels;
    1.39 -	for ( i=0; i<screen->h; ++i ) {
    1.40 -		memset(buffer,(i*255)/screen->h, screen->pitch);
    1.41 -		buffer += screen->pitch;
    1.42 -	}
    1.43 +	if (screen->format->BytesPerPixel!=2) {
    1.44 +        	for ( i=0; i<screen->h; ++i ) {
    1.45 +        		memset(buffer,(i*255)/screen->h, screen->pitch);
    1.46 +        		buffer += screen->pitch;
    1.47 +        	}
    1.48 +        }
    1.49 +        else
    1.50 +        {
    1.51 +		for ( i=0; i<screen->h; ++i ) {
    1.52 +			gradient=((i*255)/screen->h);
    1.53 +                        color = SDL_MapRGB(screen->format, gradient, gradient, gradient);
    1.54 +                        buffer16=(Uint16*)buffer;
    1.55 +                        for (k=0; k<screen->w; k++)
    1.56 +                        {
    1.57 +                            *(buffer16+k)=color;
    1.58 +                        }
    1.59 +			buffer += screen->pitch;
    1.60 +		}
    1.61 +        }
    1.62  	SDL_UnlockSurface(screen);
    1.63  	SDL_UpdateRect(screen, 0, 0, 0, 0);
    1.64