comparison test/testbitmap.c @ 691:609543e2b3a1

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.
author Sam Lantinga <slouken@libsdl.org>
date Sat, 23 Aug 2003 23:18:49 +0000
parents 74212992fb08
children be9c9c8f6d53
comparison
equal deleted inserted replaced
690:b87d8d4c205d 691:609543e2b3a1
48 SDL_Surface *screen; 48 SDL_Surface *screen;
49 SDL_Surface *bitmap; 49 SDL_Surface *bitmap;
50 Uint8 video_bpp; 50 Uint8 video_bpp;
51 Uint32 videoflags; 51 Uint32 videoflags;
52 Uint8 *buffer; 52 Uint8 *buffer;
53 int i, done; 53 int i, k, done;
54 SDL_Event event; 54 SDL_Event event;
55 Uint16 *buffer16;
56 Uint16 color;
57 Uint8 gradient;
58 SDL_Color palette[256];
59
55 60
56 /* Initialize SDL */ 61 /* Initialize SDL */
57 if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { 62 if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
58 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); 63 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
59 exit(1); 64 exit(1);
89 fprintf(stderr, "Couldn't set 640x480x%d video mode: %s\n", 94 fprintf(stderr, "Couldn't set 640x480x%d video mode: %s\n",
90 video_bpp, SDL_GetError()); 95 video_bpp, SDL_GetError());
91 exit(2); 96 exit(2);
92 } 97 }
93 98
99 if (video_bpp==8) {
100 /* Set a gray colormap, reverse order from white to black */
101 for ( i=0; i<256; ++i ) {
102 palette[i].r = 255-i;
103 palette[i].g = 255-i;
104 palette[i].b = 255-i;
105 }
106 SDL_SetColors(screen, palette, 0, 256);
107 }
108
94 /* Set the surface pixels and refresh! */ 109 /* Set the surface pixels and refresh! */
95 if ( SDL_LockSurface(screen) < 0 ) { 110 if ( SDL_LockSurface(screen) < 0 ) {
96 fprintf(stderr, "Couldn't lock the display surface: %s\n", 111 fprintf(stderr, "Couldn't lock the display surface: %s\n",
97 SDL_GetError()); 112 SDL_GetError());
98 exit(2); 113 exit(2);
99 } 114 }
100 buffer=(Uint8 *)screen->pixels; 115 buffer=(Uint8 *)screen->pixels;
101 for ( i=0; i<screen->h; ++i ) { 116 if (screen->format->BytesPerPixel!=2) {
102 memset(buffer,(i*255)/screen->h, screen->pitch); 117 for ( i=0; i<screen->h; ++i ) {
103 buffer += screen->pitch; 118 memset(buffer,(i*255)/screen->h, screen->pitch);
104 } 119 buffer += screen->pitch;
120 }
121 }
122 else
123 {
124 for ( i=0; i<screen->h; ++i ) {
125 gradient=((i*255)/screen->h);
126 color = SDL_MapRGB(screen->format, gradient, gradient, gradient);
127 buffer16=(Uint16*)buffer;
128 for (k=0; k<screen->w; k++)
129 {
130 *(buffer16+k)=color;
131 }
132 buffer += screen->pitch;
133 }
134 }
105 SDL_UnlockSurface(screen); 135 SDL_UnlockSurface(screen);
106 SDL_UpdateRect(screen, 0, 0, 0, 0); 136 SDL_UpdateRect(screen, 0, 0, 0, 0);
107 137
108 /* Load the bitmap */ 138 /* Load the bitmap */
109 bitmap = LoadXBM(screen, picture_width, picture_height, 139 bitmap = LoadXBM(screen, picture_width, picture_height,