Date: Fri, 15 Aug 2003 09:13:59 +0300
authorSam Lantinga <slouken@libsdl.org>
Sat, 23 Aug 2003 23:18:49 +0000
changeset 691609543e2b3a1
parent 690 b87d8d4c205d
child 692 04dd6c6d7c30
Date: Fri, 15 Aug 2003 09:13:59 +0300
From: "Mike Gorchak"
Subject: Patches for tests and QNX6

1) graywin - added support for the gray gradient in the 15/16 bpp modes. Added SDL_VIDEOEXPOSE event handling.
2) testalpha - added support for the gray gradient in the 15/16 bpp modes.
3) testbitmap - added support for the gray gradient in the 8/15/16 bpp modes.
test/graywin.c
test/testalpha.c
test/testbitmap.c
     1.1 --- a/test/graywin.c	Sat Aug 23 23:12:19 2003 +0000
     1.2 +++ b/test/graywin.c	Sat Aug 23 23:18:49 2003 +0000
     1.3 @@ -20,6 +20,7 @@
     1.4  	static unsigned int seeded = 0;
     1.5  	SDL_Rect area;
     1.6  	Uint32 color;
     1.7 +        Uint32 randc;
     1.8  
     1.9  	/* Seed the random number generator */
    1.10  	if ( seeded == 0 ) {
    1.11 @@ -32,7 +33,16 @@
    1.12  	area.h = (rand()%height);
    1.13  	area.x = X-(area.w/2);
    1.14  	area.y = Y-(area.h/2);
    1.15 -	color = (rand()%NUM_COLORS);
    1.16 +        randc = (rand()%NUM_COLORS);
    1.17 +
    1.18 +        if (screen->format->BytesPerPixel==1)
    1.19 +        {
    1.20 +            color = randc;
    1.21 +        }
    1.22 +        else
    1.23 +        {
    1.24 +            color = SDL_MapRGB(screen->format, randc, randc, randc);
    1.25 +        }
    1.26  
    1.27  	/* Do it! */
    1.28  	SDL_FillRect(screen, &area, color);
    1.29 @@ -43,12 +53,60 @@
    1.30  	}
    1.31  }
    1.32  
    1.33 +void DrawBackground(SDL_Surface *screen)
    1.34 +{
    1.35 +	int i, j, k;
    1.36 +	Uint8  *buffer;
    1.37 +	Uint16 *buffer16;
    1.38 +        Uint16 color;
    1.39 +        Uint8  gradient;
    1.40 +
    1.41 +	/* Set the surface pixels and refresh! */
    1.42 +	/* Use two loops in case the surface is double-buffered (both sides) */
    1.43 +
    1.44 +	for ( j=0; j<2; ++j ) {
    1.45 +		if ( SDL_LockSurface(screen) < 0 ) {
    1.46 +			fprintf(stderr, "Couldn't lock display surface: %s\n",
    1.47 +								SDL_GetError());
    1.48 +			return;
    1.49 +		}
    1.50 +		buffer = (Uint8 *)screen->pixels;
    1.51 +
    1.52 +		if (screen->format->BytesPerPixel!=2) {
    1.53 +			for ( i=0; i<screen->h; ++i ) {
    1.54 +				memset(buffer,(i*(NUM_COLORS-1))/screen->h, screen->w * screen->format->BytesPerPixel);
    1.55 +				buffer += screen->pitch;
    1.56 +			}
    1.57 +		}
    1.58 +                else
    1.59 +                {
    1.60 +			for ( i=0; i<screen->h; ++i ) {
    1.61 +				gradient=((i*(NUM_COLORS-1))/screen->h);
    1.62 +                                color = SDL_MapRGB(screen->format, gradient, gradient, gradient);
    1.63 +                                buffer16=(Uint16*)buffer;
    1.64 +                                for (k=0; k<screen->w; k++)
    1.65 +                                {
    1.66 +                                   *(buffer16+k)=color;
    1.67 +                                }
    1.68 +				buffer += screen->pitch;
    1.69 +			}
    1.70 +                }
    1.71 +
    1.72 +		SDL_UnlockSurface(screen);
    1.73 +		if ( screen->flags & SDL_DOUBLEBUF ) {
    1.74 +			SDL_Flip(screen);
    1.75 +		} else {
    1.76 +			SDL_UpdateRect(screen, 0, 0, 0, 0);
    1.77 +                        break;
    1.78 +		}
    1.79 +	}
    1.80 +}
    1.81 +
    1.82  SDL_Surface *CreateScreen(Uint16 w, Uint16 h, Uint8 bpp, Uint32 flags)
    1.83  {
    1.84  	SDL_Surface *screen;
    1.85  	int i;
    1.86  	SDL_Color palette[NUM_COLORS];
    1.87 -	Uint8 *buffer;
    1.88  
    1.89  	/* Set the video mode */
    1.90  	screen = SDL_SetVideoMode(w, h, bpp, flags);
    1.91 @@ -60,33 +118,14 @@
    1.92  	fprintf(stderr, "Screen is in %s mode\n",
    1.93  		(screen->flags & SDL_FULLSCREEN) ? "fullscreen" : "windowed");
    1.94  
    1.95 -	/* Set a gray colormap, reverse order from white to black */
    1.96 -	for ( i=0; i<NUM_COLORS; ++i ) {
    1.97 -		palette[i].r = (NUM_COLORS-1)-i * (256 / NUM_COLORS);
    1.98 -		palette[i].g = (NUM_COLORS-1)-i * (256 / NUM_COLORS);
    1.99 -		palette[i].b = (NUM_COLORS-1)-i * (256 / NUM_COLORS);
   1.100 -	}
   1.101 -	SDL_SetColors(screen, palette, 0, NUM_COLORS);
   1.102 -
   1.103 -	/* Set the surface pixels and refresh! */
   1.104 -	/* Use two loops in case the surface is double-buffered (both sides) */
   1.105 -	for ( i=0; i<2; ++i ) {
   1.106 -		if ( SDL_LockSurface(screen) < 0 ) {
   1.107 -			fprintf(stderr, "Couldn't lock display surface: %s\n",
   1.108 -								SDL_GetError());
   1.109 -			return(NULL);
   1.110 +	if (bpp==8) {
   1.111 +		/* Set a gray colormap, reverse order from white to black */
   1.112 +		for ( i=0; i<NUM_COLORS; ++i ) {
   1.113 +			palette[i].r = (NUM_COLORS-1)-i * (256 / NUM_COLORS);
   1.114 +			palette[i].g = (NUM_COLORS-1)-i * (256 / NUM_COLORS);
   1.115 +			palette[i].b = (NUM_COLORS-1)-i * (256 / NUM_COLORS);
   1.116  		}
   1.117 -		buffer = (Uint8 *)screen->pixels;
   1.118 -		for ( i=0; i<screen->h; ++i ) {
   1.119 -			memset(buffer,(i*(NUM_COLORS-1))/screen->h, screen->w * screen->format->BytesPerPixel);
   1.120 -			buffer += screen->pitch;
   1.121 -		}
   1.122 -		SDL_UnlockSurface(screen);
   1.123 -		if ( screen->flags & SDL_DOUBLEBUF ) {
   1.124 -			SDL_Flip(screen);
   1.125 -		} else {
   1.126 -			SDL_UpdateRect(screen, 0, 0, 0, 0);
   1.127 -		}
   1.128 +		SDL_SetColors(screen, palette, 0, NUM_COLORS);
   1.129  	}
   1.130  
   1.131  	return(screen);
   1.132 @@ -151,6 +190,8 @@
   1.133  	if ( screen == NULL ) {
   1.134  		exit(2);
   1.135  	}
   1.136 +        
   1.137 +        DrawBackground(screen);
   1.138  		
   1.139  	/* Wait for a keystroke */
   1.140  	done = 0;
   1.141 @@ -182,12 +223,16 @@
   1.142  					"Couldn't toggle fullscreen mode\n");
   1.143  						done = 1;
   1.144  					}
   1.145 +                                        DrawBackground(screen);
   1.146  					break;
   1.147  				}
   1.148  				/* Any other key quits the application... */
   1.149  			case SDL_QUIT:
   1.150  				done = 1;
   1.151  				break;
   1.152 +			case SDL_VIDEOEXPOSE:
   1.153 +				DrawBackground(screen);
   1.154 +				break;
   1.155  			default:
   1.156  				break;
   1.157  		}
     2.1 --- a/test/testalpha.c	Sat Aug 23 23:12:19 2003 +0000
     2.2 +++ b/test/testalpha.c	Sat Aug 23 23:18:49 2003 +0000
     2.3 @@ -279,11 +279,15 @@
     2.4  	Uint8  video_bpp;
     2.5  	Uint32 videoflags;
     2.6  	Uint8 *buffer;
     2.7 -	int    i, done;
     2.8 +	int    i, k, done;
     2.9  	SDL_Event event;
    2.10  	SDL_Surface *light;
    2.11  	int mouse_pressed;
    2.12  	Uint32 ticks, lastticks;
    2.13 +	Uint16 *buffer16;
    2.14 +        Uint16 color;
    2.15 +        Uint8  gradient;
    2.16 +
    2.17  
    2.18  	/* Initialize SDL */
    2.19  	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
    2.20 @@ -298,12 +302,17 @@
    2.21  		video_bpp = info->vfmt->BitsPerPixel;
    2.22  	} else {
    2.23  		video_bpp = 16;
    2.24 +                fprintf(stderr, "forced 16 bpp mode\n");
    2.25  	}
    2.26  	videoflags = SDL_SWSURFACE;
    2.27  	while ( argc > 1 ) {
    2.28  		--argc;
    2.29  		if ( strcmp(argv[argc-1], "-bpp") == 0 ) {
    2.30  			video_bpp = atoi(argv[argc]);
    2.31 +                        if (video_bpp<=8) {
    2.32 +                            video_bpp=16;
    2.33 +                            fprintf(stderr, "forced 16 bpp mode\n");
    2.34 +                        }
    2.35  			--argc;
    2.36  		} else
    2.37  		if ( strcmp(argv[argc], "-hw") == 0 ) {
    2.38 @@ -336,10 +345,26 @@
    2.39  		exit(2);
    2.40  	}
    2.41  	buffer=(Uint8 *)screen->pixels;
    2.42 -	for ( i=0; i<screen->h; ++i ) {
    2.43 -		memset(buffer,(i*255)/screen->h, screen->pitch);
    2.44 -		buffer += screen->pitch;
    2.45 +	if (screen->format->BytesPerPixel!=2) {
    2.46 +		for ( i=0; i<screen->h; ++i ) {
    2.47 +			memset(buffer,(i*255)/screen->h, screen->pitch);
    2.48 +			buffer += screen->pitch;
    2.49 +		}
    2.50  	}
    2.51 +        else
    2.52 +        {
    2.53 +		for ( i=0; i<screen->h; ++i ) {
    2.54 +			gradient=((i*255)/screen->h);
    2.55 +                        color = SDL_MapRGB(screen->format, gradient, gradient, gradient);
    2.56 +                        buffer16=(Uint16*)buffer;
    2.57 +                        for (k=0; k<screen->w; k++)
    2.58 +                        {
    2.59 +                            *(buffer16+k)=color;
    2.60 +                        }
    2.61 +			buffer += screen->pitch;
    2.62 +		}
    2.63 +        }
    2.64 +
    2.65  	SDL_UnlockSurface(screen);
    2.66  	SDL_UpdateRect(screen, 0, 0, 0, 0);
    2.67  
     3.1 --- a/test/testbitmap.c	Sat Aug 23 23:12:19 2003 +0000
     3.2 +++ b/test/testbitmap.c	Sat Aug 23 23:18:49 2003 +0000
     3.3 @@ -50,8 +50,13 @@
     3.4  	Uint8  video_bpp;
     3.5  	Uint32 videoflags;
     3.6  	Uint8 *buffer;
     3.7 -	int i, done;
     3.8 +	int i, k, done;
     3.9  	SDL_Event event;
    3.10 +	Uint16 *buffer16;
    3.11 +        Uint16 color;
    3.12 +        Uint8  gradient;
    3.13 +	SDL_Color palette[256];
    3.14 +
    3.15  
    3.16  	/* Initialize SDL */
    3.17  	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
    3.18 @@ -91,6 +96,16 @@
    3.19  		exit(2);
    3.20  	}
    3.21  
    3.22 +	if (video_bpp==8) {
    3.23 +		/* Set a gray colormap, reverse order from white to black */
    3.24 +		for ( i=0; i<256; ++i ) {
    3.25 +			palette[i].r = 255-i;
    3.26 +			palette[i].g = 255-i;
    3.27 +			palette[i].b = 255-i;
    3.28 +		}
    3.29 +		SDL_SetColors(screen, palette, 0, 256);
    3.30 +	}
    3.31 +
    3.32  	/* Set the surface pixels and refresh! */
    3.33  	if ( SDL_LockSurface(screen) < 0 ) {
    3.34  		fprintf(stderr, "Couldn't lock the display surface: %s\n",
    3.35 @@ -98,10 +113,25 @@
    3.36  		exit(2);
    3.37  	}
    3.38  	buffer=(Uint8 *)screen->pixels;
    3.39 -	for ( i=0; i<screen->h; ++i ) {
    3.40 -		memset(buffer,(i*255)/screen->h, screen->pitch);
    3.41 -		buffer += screen->pitch;
    3.42 -	}
    3.43 +	if (screen->format->BytesPerPixel!=2) {
    3.44 +        	for ( i=0; i<screen->h; ++i ) {
    3.45 +        		memset(buffer,(i*255)/screen->h, screen->pitch);
    3.46 +        		buffer += screen->pitch;
    3.47 +        	}
    3.48 +        }
    3.49 +        else
    3.50 +        {
    3.51 +		for ( i=0; i<screen->h; ++i ) {
    3.52 +			gradient=((i*255)/screen->h);
    3.53 +                        color = SDL_MapRGB(screen->format, gradient, gradient, gradient);
    3.54 +                        buffer16=(Uint16*)buffer;
    3.55 +                        for (k=0; k<screen->w; k++)
    3.56 +                        {
    3.57 +                            *(buffer16+k)=color;
    3.58 +                        }
    3.59 +			buffer += screen->pitch;
    3.60 +		}
    3.61 +        }
    3.62  	SDL_UnlockSurface(screen);
    3.63  	SDL_UpdateRect(screen, 0, 0, 0, 0);
    3.64