Mercurial > sdl-ios-xcode
comparison test/testoverlay.c @ 1668:4da1ee79c9af SDL-1.3
more tweaking indent options
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 29 May 2006 04:04:35 +0000 |
parents | 782fd950bd46 |
children |
comparison
equal
deleted
inserted
replaced
1667:1fddae038bc8 | 1668:4da1ee79c9af |
---|---|
21 int luminance; | 21 int luminance; |
22 int w, h; | 22 int w, h; |
23 | 23 |
24 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ | 24 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ |
25 static void | 25 static void |
26 quit (int rc) | 26 quit(int rc) |
27 { | 27 { |
28 SDL_Quit (); | 28 SDL_Quit(); |
29 exit (rc); | 29 exit(rc); |
30 } | 30 } |
31 | 31 |
32 /* NOTE: These RGB conversion functions are not intended for speed, | 32 /* NOTE: These RGB conversion functions are not intended for speed, |
33 only as examples. | 33 only as examples. |
34 */ | 34 */ |
35 | 35 |
36 void | 36 void |
37 RGBtoYUV (Uint8 * rgb, int *yuv, int monochrome, int luminance) | 37 RGBtoYUV(Uint8 * rgb, int *yuv, int monochrome, int luminance) |
38 { | 38 { |
39 if (monochrome) { | 39 if (monochrome) { |
40 #if 1 /* these are the two formulas that I found on the FourCC site... */ | 40 #if 1 /* these are the two formulas that I found on the FourCC site... */ |
41 yuv[0] = 0.299 * rgb[0] + 0.587 * rgb[1] + 0.114 * rgb[2]; | 41 yuv[0] = 0.299 * rgb[0] + 0.587 * rgb[1] + 0.114 * rgb[2]; |
42 yuv[1] = 128; | 42 yuv[1] = 128; |
75 } | 75 } |
76 */ | 76 */ |
77 } | 77 } |
78 | 78 |
79 void | 79 void |
80 ConvertRGBtoYV12 (SDL_Surface * s, SDL_Overlay * o, int monochrome, | 80 ConvertRGBtoYV12(SDL_Surface * s, SDL_Overlay * o, int monochrome, |
81 int luminance) | 81 int luminance) |
82 { | 82 { |
83 int x, y; | 83 int x, y; |
84 int yuv[3]; | 84 int yuv[3]; |
85 Uint8 *p, *op[3]; | 85 Uint8 *p, *op[3]; |
86 | 86 |
87 SDL_LockSurface (s); | 87 SDL_LockSurface(s); |
88 SDL_LockYUVOverlay (o); | 88 SDL_LockYUVOverlay(o); |
89 | 89 |
90 /* Black initialization */ | 90 /* Black initialization */ |
91 /* | 91 /* |
92 memset(o->pixels[0],0,o->pitches[0]*o->h); | 92 memset(o->pixels[0],0,o->pitches[0]*o->h); |
93 memset(o->pixels[1],128,o->pitches[1]*((o->h+1)/2)); | 93 memset(o->pixels[1],128,o->pitches[1]*((o->h+1)/2)); |
99 p = ((Uint8 *) s->pixels) + s->pitch * y; | 99 p = ((Uint8 *) s->pixels) + s->pitch * y; |
100 op[0] = o->pixels[0] + o->pitches[0] * y; | 100 op[0] = o->pixels[0] + o->pitches[0] * y; |
101 op[1] = o->pixels[1] + o->pitches[1] * (y / 2); | 101 op[1] = o->pixels[1] + o->pitches[1] * (y / 2); |
102 op[2] = o->pixels[2] + o->pitches[2] * (y / 2); | 102 op[2] = o->pixels[2] + o->pitches[2] * (y / 2); |
103 for (x = 0; x < s->w && x < o->w; x++) { | 103 for (x = 0; x < s->w && x < o->w; x++) { |
104 RGBtoYUV (p, yuv, monochrome, luminance); | 104 RGBtoYUV(p, yuv, monochrome, luminance); |
105 *(op[0]++) = yuv[0]; | 105 *(op[0]++) = yuv[0]; |
106 if (x % 2 == 0 && y % 2 == 0) { | 106 if (x % 2 == 0 && y % 2 == 0) { |
107 *(op[1]++) = yuv[2]; | 107 *(op[1]++) = yuv[2]; |
108 *(op[2]++) = yuv[1]; | 108 *(op[2]++) = yuv[1]; |
109 } | 109 } |
110 p += s->format->BytesPerPixel; | 110 p += s->format->BytesPerPixel; |
111 } | 111 } |
112 } | 112 } |
113 | 113 |
114 SDL_UnlockYUVOverlay (o); | 114 SDL_UnlockYUVOverlay(o); |
115 SDL_UnlockSurface (s); | 115 SDL_UnlockSurface(s); |
116 } | 116 } |
117 | 117 |
118 void | 118 void |
119 ConvertRGBtoIYUV (SDL_Surface * s, SDL_Overlay * o, int monochrome, | 119 ConvertRGBtoIYUV(SDL_Surface * s, SDL_Overlay * o, int monochrome, |
120 int luminance) | 120 int luminance) |
121 { | 121 { |
122 int x, y; | 122 int x, y; |
123 int yuv[3]; | 123 int yuv[3]; |
124 Uint8 *p, *op[3]; | 124 Uint8 *p, *op[3]; |
125 | 125 |
126 SDL_LockSurface (s); | 126 SDL_LockSurface(s); |
127 SDL_LockYUVOverlay (o); | 127 SDL_LockYUVOverlay(o); |
128 | 128 |
129 /* Black initialization */ | 129 /* Black initialization */ |
130 /* | 130 /* |
131 memset(o->pixels[0],0,o->pitches[0]*o->h); | 131 memset(o->pixels[0],0,o->pitches[0]*o->h); |
132 memset(o->pixels[1],128,o->pitches[1]*((o->h+1)/2)); | 132 memset(o->pixels[1],128,o->pitches[1]*((o->h+1)/2)); |
138 p = ((Uint8 *) s->pixels) + s->pitch * y; | 138 p = ((Uint8 *) s->pixels) + s->pitch * y; |
139 op[0] = o->pixels[0] + o->pitches[0] * y; | 139 op[0] = o->pixels[0] + o->pitches[0] * y; |
140 op[1] = o->pixels[1] + o->pitches[1] * (y / 2); | 140 op[1] = o->pixels[1] + o->pitches[1] * (y / 2); |
141 op[2] = o->pixels[2] + o->pitches[2] * (y / 2); | 141 op[2] = o->pixels[2] + o->pitches[2] * (y / 2); |
142 for (x = 0; x < s->w && x < o->w; x++) { | 142 for (x = 0; x < s->w && x < o->w; x++) { |
143 RGBtoYUV (p, yuv, monochrome, luminance); | 143 RGBtoYUV(p, yuv, monochrome, luminance); |
144 *(op[0]++) = yuv[0]; | 144 *(op[0]++) = yuv[0]; |
145 if (x % 2 == 0 && y % 2 == 0) { | 145 if (x % 2 == 0 && y % 2 == 0) { |
146 *(op[1]++) = yuv[1]; | 146 *(op[1]++) = yuv[1]; |
147 *(op[2]++) = yuv[2]; | 147 *(op[2]++) = yuv[2]; |
148 } | 148 } |
149 p += s->format->BytesPerPixel; | 149 p += s->format->BytesPerPixel; |
150 } | 150 } |
151 } | 151 } |
152 | 152 |
153 SDL_UnlockYUVOverlay (o); | 153 SDL_UnlockYUVOverlay(o); |
154 SDL_UnlockSurface (s); | 154 SDL_UnlockSurface(s); |
155 } | 155 } |
156 | 156 |
157 void | 157 void |
158 ConvertRGBtoUYVY (SDL_Surface * s, SDL_Overlay * o, int monochrome, | 158 ConvertRGBtoUYVY(SDL_Surface * s, SDL_Overlay * o, int monochrome, |
159 int luminance) | 159 int luminance) |
160 { | 160 { |
161 int x, y; | 161 int x, y; |
162 int yuv[3]; | 162 int yuv[3]; |
163 Uint8 *p, *op; | 163 Uint8 *p, *op; |
164 | 164 |
165 SDL_LockSurface (s); | 165 SDL_LockSurface(s); |
166 SDL_LockYUVOverlay (o); | 166 SDL_LockYUVOverlay(o); |
167 | 167 |
168 for (y = 0; y < s->h && y < o->h; y++) { | 168 for (y = 0; y < s->h && y < o->h; y++) { |
169 p = ((Uint8 *) s->pixels) + s->pitch * y; | 169 p = ((Uint8 *) s->pixels) + s->pitch * y; |
170 op = o->pixels[0] + o->pitches[0] * y; | 170 op = o->pixels[0] + o->pitches[0] * y; |
171 for (x = 0; x < s->w && x < o->w; x++) { | 171 for (x = 0; x < s->w && x < o->w; x++) { |
172 RGBtoYUV (p, yuv, monochrome, luminance); | 172 RGBtoYUV(p, yuv, monochrome, luminance); |
173 if (x % 2 == 0) { | 173 if (x % 2 == 0) { |
174 *(op++) = yuv[1]; | 174 *(op++) = yuv[1]; |
175 *(op++) = yuv[0]; | 175 *(op++) = yuv[0]; |
176 *(op++) = yuv[2]; | 176 *(op++) = yuv[2]; |
177 } else | 177 } else |
179 | 179 |
180 p += s->format->BytesPerPixel; | 180 p += s->format->BytesPerPixel; |
181 } | 181 } |
182 } | 182 } |
183 | 183 |
184 SDL_UnlockYUVOverlay (o); | 184 SDL_UnlockYUVOverlay(o); |
185 SDL_UnlockSurface (s); | 185 SDL_UnlockSurface(s); |
186 } | 186 } |
187 | 187 |
188 void | 188 void |
189 ConvertRGBtoYVYU (SDL_Surface * s, SDL_Overlay * o, int monochrome, | 189 ConvertRGBtoYVYU(SDL_Surface * s, SDL_Overlay * o, int monochrome, |
190 int luminance) | 190 int luminance) |
191 { | 191 { |
192 int x, y; | 192 int x, y; |
193 int yuv[3]; | 193 int yuv[3]; |
194 Uint8 *p, *op; | 194 Uint8 *p, *op; |
195 | 195 |
196 SDL_LockSurface (s); | 196 SDL_LockSurface(s); |
197 SDL_LockYUVOverlay (o); | 197 SDL_LockYUVOverlay(o); |
198 | 198 |
199 for (y = 0; y < s->h && y < o->h; y++) { | 199 for (y = 0; y < s->h && y < o->h; y++) { |
200 p = ((Uint8 *) s->pixels) + s->pitch * y; | 200 p = ((Uint8 *) s->pixels) + s->pitch * y; |
201 op = o->pixels[0] + o->pitches[0] * y; | 201 op = o->pixels[0] + o->pitches[0] * y; |
202 for (x = 0; x < s->w && x < o->w; x++) { | 202 for (x = 0; x < s->w && x < o->w; x++) { |
203 RGBtoYUV (p, yuv, monochrome, luminance); | 203 RGBtoYUV(p, yuv, monochrome, luminance); |
204 if (x % 2 == 0) { | 204 if (x % 2 == 0) { |
205 *(op++) = yuv[0]; | 205 *(op++) = yuv[0]; |
206 *(op++) = yuv[2]; | 206 *(op++) = yuv[2]; |
207 op[1] = yuv[1]; | 207 op[1] = yuv[1]; |
208 } else { | 208 } else { |
212 | 212 |
213 p += s->format->BytesPerPixel; | 213 p += s->format->BytesPerPixel; |
214 } | 214 } |
215 } | 215 } |
216 | 216 |
217 SDL_UnlockYUVOverlay (o); | 217 SDL_UnlockYUVOverlay(o); |
218 SDL_UnlockSurface (s); | 218 SDL_UnlockSurface(s); |
219 } | 219 } |
220 | 220 |
221 void | 221 void |
222 ConvertRGBtoYUY2 (SDL_Surface * s, SDL_Overlay * o, int monochrome, | 222 ConvertRGBtoYUY2(SDL_Surface * s, SDL_Overlay * o, int monochrome, |
223 int luminance) | 223 int luminance) |
224 { | 224 { |
225 int x, y; | 225 int x, y; |
226 int yuv[3]; | 226 int yuv[3]; |
227 Uint8 *p, *op; | 227 Uint8 *p, *op; |
228 | 228 |
229 SDL_LockSurface (s); | 229 SDL_LockSurface(s); |
230 SDL_LockYUVOverlay (o); | 230 SDL_LockYUVOverlay(o); |
231 | 231 |
232 for (y = 0; y < s->h && y < o->h; y++) { | 232 for (y = 0; y < s->h && y < o->h; y++) { |
233 p = ((Uint8 *) s->pixels) + s->pitch * y; | 233 p = ((Uint8 *) s->pixels) + s->pitch * y; |
234 op = o->pixels[0] + o->pitches[0] * y; | 234 op = o->pixels[0] + o->pitches[0] * y; |
235 for (x = 0; x < s->w && x < o->w; x++) { | 235 for (x = 0; x < s->w && x < o->w; x++) { |
236 RGBtoYUV (p, yuv, monochrome, luminance); | 236 RGBtoYUV(p, yuv, monochrome, luminance); |
237 if (x % 2 == 0) { | 237 if (x % 2 == 0) { |
238 *(op++) = yuv[0]; | 238 *(op++) = yuv[0]; |
239 *(op++) = yuv[1]; | 239 *(op++) = yuv[1]; |
240 op[1] = yuv[2]; | 240 op[1] = yuv[2]; |
241 } else { | 241 } else { |
245 | 245 |
246 p += s->format->BytesPerPixel; | 246 p += s->format->BytesPerPixel; |
247 } | 247 } |
248 } | 248 } |
249 | 249 |
250 SDL_UnlockYUVOverlay (o); | 250 SDL_UnlockYUVOverlay(o); |
251 SDL_UnlockSurface (s); | 251 SDL_UnlockSurface(s); |
252 } | 252 } |
253 | 253 |
254 void | 254 void |
255 Draw () | 255 Draw() |
256 { | 256 { |
257 SDL_Rect rect; | 257 SDL_Rect rect; |
258 int i; | 258 int i; |
259 int disp; | 259 int disp; |
260 | 260 |
262 rect.w = overlay->w; | 262 rect.w = overlay->w; |
263 rect.h = overlay->h; | 263 rect.h = overlay->h; |
264 for (i = 0; i < h - rect.h && i < w - rect.w; i++) { | 264 for (i = 0; i < h - rect.h && i < w - rect.w; i++) { |
265 rect.x = i; | 265 rect.x = i; |
266 rect.y = i; | 266 rect.y = i; |
267 SDL_DisplayYUVOverlay (overlay, &rect); | 267 SDL_DisplayYUVOverlay(overlay, &rect); |
268 } | 268 } |
269 } else { | 269 } else { |
270 rect.w = overlay->w / 2; | 270 rect.w = overlay->w / 2; |
271 rect.h = overlay->h / 2; | 271 rect.h = overlay->h / 2; |
272 rect.x = (w - rect.w) / 2; | 272 rect.x = (w - rect.w) / 2; |
275 for (i = 0; i < disp; i++) { | 275 for (i = 0; i < disp; i++) { |
276 rect.w += 2; | 276 rect.w += 2; |
277 rect.h += 2; | 277 rect.h += 2; |
278 rect.x--; | 278 rect.x--; |
279 rect.y--; | 279 rect.y--; |
280 SDL_DisplayYUVOverlay (overlay, &rect); | 280 SDL_DisplayYUVOverlay(overlay, &rect); |
281 } | 281 } |
282 } | 282 } |
283 printf ("Displayed %d times.\n", i); | 283 printf("Displayed %d times.\n", i); |
284 } | 284 } |
285 | 285 |
286 static void | 286 static void |
287 PrintUsage (char *argv0) | 287 PrintUsage(char *argv0) |
288 { | 288 { |
289 fprintf (stderr, "Usage: %s [arg] [arg] [arg] ...\n", argv0); | 289 fprintf(stderr, "Usage: %s [arg] [arg] [arg] ...\n", argv0); |
290 fprintf (stderr, "Where 'arg' is one of:\n"); | 290 fprintf(stderr, "Where 'arg' is one of:\n"); |
291 fprintf (stderr, " -delay <seconds>\n"); | 291 fprintf(stderr, " -delay <seconds>\n"); |
292 fprintf (stderr, " -width <pixels>\n"); | 292 fprintf(stderr, " -width <pixels>\n"); |
293 fprintf (stderr, " -height <pixels>\n"); | 293 fprintf(stderr, " -height <pixels>\n"); |
294 fprintf (stderr, " -bpp <bits>\n"); | 294 fprintf(stderr, " -bpp <bits>\n"); |
295 fprintf (stderr, | 295 fprintf(stderr, |
296 " -format <fmt> (one of the: YV12, IYUV, YUY2, UYVY, YVYU)\n"); | 296 " -format <fmt> (one of the: YV12, IYUV, YUY2, UYVY, YVYU)\n"); |
297 fprintf (stderr, " -hw\n"); | 297 fprintf(stderr, " -hw\n"); |
298 fprintf (stderr, " -flip\n"); | 298 fprintf(stderr, " -flip\n"); |
299 fprintf (stderr, | 299 fprintf(stderr, |
300 " -scale (test scaling features, from 50%% upto window size)\n"); | 300 " -scale (test scaling features, from 50%% upto window size)\n"); |
301 fprintf (stderr, " -mono (use monochromatic RGB2YUV conversion)\n"); | 301 fprintf(stderr, " -mono (use monochromatic RGB2YUV conversion)\n"); |
302 fprintf (stderr, | 302 fprintf(stderr, |
303 " -lum <perc> (use luminance correction during RGB2YUV conversion,\n"); | 303 " -lum <perc> (use luminance correction during RGB2YUV conversion,\n"); |
304 fprintf (stderr, | 304 fprintf(stderr, |
305 " from 0%% to unlimited, normal is 100%%)\n"); | 305 " from 0%% to unlimited, normal is 100%%)\n"); |
306 fprintf (stderr, " -help (shows this help)\n"); | 306 fprintf(stderr, " -help (shows this help)\n"); |
307 fprintf (stderr, " -fullscreen (test overlay in fullscreen mode)\n"); | 307 fprintf(stderr, " -fullscreen (test overlay in fullscreen mode)\n"); |
308 } | 308 } |
309 | 309 |
310 int | 310 int |
311 main (int argc, char **argv) | 311 main(int argc, char **argv) |
312 { | 312 { |
313 char *argv0 = argv[0]; | 313 char *argv0 = argv[0]; |
314 int flip; | 314 int flip; |
315 int delay; | 315 int delay; |
316 int desired_bpp; | 316 int desired_bpp; |
332 desired_bpp = 0; | 332 desired_bpp = 0; |
333 video_flags = 0; | 333 video_flags = 0; |
334 overlay_format = SDL_YV12_OVERLAY; | 334 overlay_format = SDL_YV12_OVERLAY; |
335 | 335 |
336 while (argc > 1) { | 336 while (argc > 1) { |
337 if (strcmp (argv[1], "-delay") == 0) { | 337 if (strcmp(argv[1], "-delay") == 0) { |
338 if (argv[2]) { | 338 if (argv[2]) { |
339 delay = atoi (argv[2]); | 339 delay = atoi(argv[2]); |
340 argv += 2; | 340 argv += 2; |
341 argc -= 2; | 341 argc -= 2; |
342 } else { | 342 } else { |
343 fprintf (stderr, "The -delay option requires an argument\n"); | 343 fprintf(stderr, "The -delay option requires an argument\n"); |
344 return (1); | 344 return (1); |
345 } | 345 } |
346 } else if (strcmp (argv[1], "-width") == 0) { | 346 } else if (strcmp(argv[1], "-width") == 0) { |
347 if (argv[2] && ((w = atoi (argv[2])) > 0)) { | 347 if (argv[2] && ((w = atoi(argv[2])) > 0)) { |
348 argv += 2; | 348 argv += 2; |
349 argc -= 2; | 349 argc -= 2; |
350 } else { | 350 } else { |
351 fprintf (stderr, "The -width option requires an argument\n"); | 351 fprintf(stderr, "The -width option requires an argument\n"); |
352 return (1); | 352 return (1); |
353 } | 353 } |
354 } else if (strcmp (argv[1], "-height") == 0) { | 354 } else if (strcmp(argv[1], "-height") == 0) { |
355 if (argv[2] && ((h = atoi (argv[2])) > 0)) { | 355 if (argv[2] && ((h = atoi(argv[2])) > 0)) { |
356 argv += 2; | 356 argv += 2; |
357 argc -= 2; | 357 argc -= 2; |
358 } else { | 358 } else { |
359 fprintf (stderr, "The -height option requires an argument\n"); | 359 fprintf(stderr, "The -height option requires an argument\n"); |
360 return (1); | 360 return (1); |
361 } | 361 } |
362 } else if (strcmp (argv[1], "-bpp") == 0) { | 362 } else if (strcmp(argv[1], "-bpp") == 0) { |
363 if (argv[2]) { | 363 if (argv[2]) { |
364 desired_bpp = atoi (argv[2]); | 364 desired_bpp = atoi(argv[2]); |
365 argv += 2; | 365 argv += 2; |
366 argc -= 2; | 366 argc -= 2; |
367 } else { | 367 } else { |
368 fprintf (stderr, "The -bpp option requires an argument\n"); | 368 fprintf(stderr, "The -bpp option requires an argument\n"); |
369 return (1); | 369 return (1); |
370 } | 370 } |
371 } else if (strcmp (argv[1], "-lum") == 0) { | 371 } else if (strcmp(argv[1], "-lum") == 0) { |
372 if (argv[2]) { | 372 if (argv[2]) { |
373 luminance = atoi (argv[2]); | 373 luminance = atoi(argv[2]); |
374 argv += 2; | 374 argv += 2; |
375 argc -= 2; | 375 argc -= 2; |
376 } else { | 376 } else { |
377 fprintf (stderr, "The -lum option requires an argument\n"); | 377 fprintf(stderr, "The -lum option requires an argument\n"); |
378 return (1); | 378 return (1); |
379 } | 379 } |
380 } else if (strcmp (argv[1], "-format") == 0) { | 380 } else if (strcmp(argv[1], "-format") == 0) { |
381 if (argv[2]) { | 381 if (argv[2]) { |
382 if (!strcmp (argv[2], "YV12")) | 382 if (!strcmp(argv[2], "YV12")) |
383 overlay_format = SDL_YV12_OVERLAY; | 383 overlay_format = SDL_YV12_OVERLAY; |
384 else if (!strcmp (argv[2], "IYUV")) | 384 else if (!strcmp(argv[2], "IYUV")) |
385 overlay_format = SDL_IYUV_OVERLAY; | 385 overlay_format = SDL_IYUV_OVERLAY; |
386 else if (!strcmp (argv[2], "YUY2")) | 386 else if (!strcmp(argv[2], "YUY2")) |
387 overlay_format = SDL_YUY2_OVERLAY; | 387 overlay_format = SDL_YUY2_OVERLAY; |
388 else if (!strcmp (argv[2], "UYVY")) | 388 else if (!strcmp(argv[2], "UYVY")) |
389 overlay_format = SDL_UYVY_OVERLAY; | 389 overlay_format = SDL_UYVY_OVERLAY; |
390 else if (!strcmp (argv[2], "YVYU")) | 390 else if (!strcmp(argv[2], "YVYU")) |
391 overlay_format = SDL_YVYU_OVERLAY; | 391 overlay_format = SDL_YVYU_OVERLAY; |
392 else { | 392 else { |
393 fprintf (stderr, | 393 fprintf(stderr, |
394 "The -format option %s is not recognized\n", | 394 "The -format option %s is not recognized\n", |
395 argv[2]); | 395 argv[2]); |
396 return (1); | 396 return (1); |
397 } | 397 } |
398 argv += 2; | 398 argv += 2; |
399 argc -= 2; | 399 argc -= 2; |
400 } else { | 400 } else { |
401 fprintf (stderr, "The -format option requires an argument\n"); | 401 fprintf(stderr, "The -format option requires an argument\n"); |
402 return (1); | 402 return (1); |
403 } | 403 } |
404 } else if (strcmp (argv[1], "-hw") == 0) { | 404 } else if (strcmp(argv[1], "-hw") == 0) { |
405 video_flags |= SDL_HWSURFACE; | 405 video_flags |= SDL_HWSURFACE; |
406 argv += 1; | 406 argv += 1; |
407 argc -= 1; | 407 argc -= 1; |
408 } else if (strcmp (argv[1], "-flip") == 0) { | 408 } else if (strcmp(argv[1], "-flip") == 0) { |
409 video_flags |= SDL_DOUBLEBUF; | 409 video_flags |= SDL_DOUBLEBUF; |
410 argv += 1; | 410 argv += 1; |
411 argc -= 1; | 411 argc -= 1; |
412 } else if (strcmp (argv[1], "-scale") == 0) { | 412 } else if (strcmp(argv[1], "-scale") == 0) { |
413 scale = 1; | 413 scale = 1; |
414 argv += 1; | 414 argv += 1; |
415 argc -= 1; | 415 argc -= 1; |
416 } else if (strcmp (argv[1], "-mono") == 0) { | 416 } else if (strcmp(argv[1], "-mono") == 0) { |
417 monochrome = 1; | 417 monochrome = 1; |
418 argv += 1; | 418 argv += 1; |
419 argc -= 1; | 419 argc -= 1; |
420 } else if ((strcmp (argv[1], "-help") == 0) | 420 } else if ((strcmp(argv[1], "-help") == 0) |
421 || (strcmp (argv[1], "-h") == 0)) { | 421 || (strcmp(argv[1], "-h") == 0)) { |
422 PrintUsage (argv0); | 422 PrintUsage(argv0); |
423 return (1); | 423 return (1); |
424 } else if (strcmp (argv[1], "-fullscreen") == 0) { | 424 } else if (strcmp(argv[1], "-fullscreen") == 0) { |
425 video_flags |= SDL_FULLSCREEN; | 425 video_flags |= SDL_FULLSCREEN; |
426 argv += 1; | 426 argv += 1; |
427 argc -= 1; | 427 argc -= 1; |
428 } else | 428 } else |
429 break; | 429 break; |
430 } | 430 } |
431 if (SDL_Init (SDL_INIT_VIDEO) < 0) { | 431 if (SDL_Init(SDL_INIT_VIDEO) < 0) { |
432 fprintf (stderr, "Couldn't initialize SDL: %s\n", SDL_GetError ()); | 432 fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); |
433 return (1); | 433 return (1); |
434 } | 434 } |
435 | 435 |
436 /* Initialize the display */ | 436 /* Initialize the display */ |
437 screen = SDL_SetVideoMode (w, h, desired_bpp, video_flags); | 437 screen = SDL_SetVideoMode(w, h, desired_bpp, video_flags); |
438 if (screen == NULL) { | 438 if (screen == NULL) { |
439 fprintf (stderr, "Couldn't set %dx%dx%d video mode: %s\n", | 439 fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n", |
440 w, h, desired_bpp, SDL_GetError ()); | 440 w, h, desired_bpp, SDL_GetError()); |
441 quit (1); | 441 quit(1); |
442 } | 442 } |
443 printf ("Set%s %dx%dx%d mode\n", | 443 printf("Set%s %dx%dx%d mode\n", |
444 screen->flags & SDL_FULLSCREEN ? " fullscreen" : "", | 444 screen->flags & SDL_FULLSCREEN ? " fullscreen" : "", |
445 screen->w, screen->h, screen->format->BitsPerPixel); | 445 screen->w, screen->h, screen->format->BitsPerPixel); |
446 printf ("(video surface located in %s memory)\n", | 446 printf("(video surface located in %s memory)\n", |
447 (screen->flags & SDL_HWSURFACE) ? "video" : "system"); | 447 (screen->flags & SDL_HWSURFACE) ? "video" : "system"); |
448 if (screen->flags & SDL_DOUBLEBUF) { | 448 if (screen->flags & SDL_DOUBLEBUF) { |
449 printf ("Double-buffering enabled\n"); | 449 printf("Double-buffering enabled\n"); |
450 flip = 1; | 450 flip = 1; |
451 } | 451 } |
452 | 452 |
453 /* Set the window manager title bar */ | 453 /* Set the window manager title bar */ |
454 SDL_WM_SetCaption ("SDL test overlay", "testoverlay"); | 454 SDL_WM_SetCaption("SDL test overlay", "testoverlay"); |
455 | 455 |
456 /* Load picture */ | 456 /* Load picture */ |
457 bmpfile = (argv[1] ? argv[1] : "sample.bmp"); | 457 bmpfile = (argv[1] ? argv[1] : "sample.bmp"); |
458 pic = SDL_LoadBMP (bmpfile); | 458 pic = SDL_LoadBMP(bmpfile); |
459 if (pic == NULL) { | 459 if (pic == NULL) { |
460 fprintf (stderr, "Couldn't load %s: %s\n", bmpfile, SDL_GetError ()); | 460 fprintf(stderr, "Couldn't load %s: %s\n", bmpfile, SDL_GetError()); |
461 quit (1); | 461 quit(1); |
462 } | 462 } |
463 | 463 |
464 /* Convert the picture to 32bits, for easy conversion */ | 464 /* Convert the picture to 32bits, for easy conversion */ |
465 { | 465 { |
466 SDL_Surface *newsurf; | 466 SDL_Surface *newsurf; |
488 format.Bloss = 0; | 488 format.Bloss = 0; |
489 format.Aloss = 8; | 489 format.Aloss = 8; |
490 format.colorkey = 0; | 490 format.colorkey = 0; |
491 format.alpha = 0; | 491 format.alpha = 0; |
492 | 492 |
493 newsurf = SDL_ConvertSurface (pic, &format, SDL_SWSURFACE); | 493 newsurf = SDL_ConvertSurface(pic, &format, SDL_SWSURFACE); |
494 if (!newsurf) { | 494 if (!newsurf) { |
495 fprintf (stderr, "Couldn't convert picture to 32bits RGB: %s\n", | 495 fprintf(stderr, "Couldn't convert picture to 32bits RGB: %s\n", |
496 SDL_GetError ()); | 496 SDL_GetError()); |
497 quit (1); | 497 quit(1); |
498 } | 498 } |
499 SDL_FreeSurface (pic); | 499 SDL_FreeSurface(pic); |
500 pic = newsurf; | 500 pic = newsurf; |
501 } | 501 } |
502 | 502 |
503 /* Create the overlay */ | 503 /* Create the overlay */ |
504 overlay = SDL_CreateYUVOverlay (pic->w, pic->h, overlay_format, screen); | 504 overlay = SDL_CreateYUVOverlay(pic->w, pic->h, overlay_format, screen); |
505 if (overlay == NULL) { | 505 if (overlay == NULL) { |
506 fprintf (stderr, "Couldn't create overlay: %s\n", SDL_GetError ()); | 506 fprintf(stderr, "Couldn't create overlay: %s\n", SDL_GetError()); |
507 quit (1); | 507 quit(1); |
508 } | 508 } |
509 printf ("Created %dx%dx%d %s %s overlay\n", overlay->w, overlay->h, | 509 printf("Created %dx%dx%d %s %s overlay\n", overlay->w, overlay->h, |
510 overlay->planes, overlay->hw_overlay ? "hardware" : "software", | 510 overlay->planes, overlay->hw_overlay ? "hardware" : "software", |
511 overlay->format == SDL_YV12_OVERLAY ? "YV12" : overlay->format == | 511 overlay->format == SDL_YV12_OVERLAY ? "YV12" : overlay->format == |
512 SDL_IYUV_OVERLAY ? "IYUV" : overlay->format == | 512 SDL_IYUV_OVERLAY ? "IYUV" : overlay->format == |
513 SDL_YUY2_OVERLAY ? "YUY2" : overlay->format == | 513 SDL_YUY2_OVERLAY ? "YUY2" : overlay->format == |
514 SDL_UYVY_OVERLAY ? "UYVY" : overlay->format == | 514 SDL_UYVY_OVERLAY ? "UYVY" : overlay->format == |
515 SDL_YVYU_OVERLAY ? "YVYU" : "Unknown"); | 515 SDL_YVYU_OVERLAY ? "YVYU" : "Unknown"); |
516 for (i = 0; i < overlay->planes; i++) { | 516 for (i = 0; i < overlay->planes; i++) { |
517 printf (" plane %d: pitch=%d\n", i, overlay->pitches[i]); | 517 printf(" plane %d: pitch=%d\n", i, overlay->pitches[i]); |
518 } | 518 } |
519 | 519 |
520 /* Convert to YUV, and draw to the overlay */ | 520 /* Convert to YUV, and draw to the overlay */ |
521 #ifdef BENCHMARK_SDL | 521 #ifdef BENCHMARK_SDL |
522 then = SDL_GetTicks (); | 522 then = SDL_GetTicks(); |
523 #endif | 523 #endif |
524 switch (overlay->format) { | 524 switch (overlay->format) { |
525 case SDL_YV12_OVERLAY: | 525 case SDL_YV12_OVERLAY: |
526 ConvertRGBtoYV12 (pic, overlay, monochrome, luminance); | 526 ConvertRGBtoYV12(pic, overlay, monochrome, luminance); |
527 break; | 527 break; |
528 case SDL_UYVY_OVERLAY: | 528 case SDL_UYVY_OVERLAY: |
529 ConvertRGBtoUYVY (pic, overlay, monochrome, luminance); | 529 ConvertRGBtoUYVY(pic, overlay, monochrome, luminance); |
530 break; | 530 break; |
531 case SDL_YVYU_OVERLAY: | 531 case SDL_YVYU_OVERLAY: |
532 ConvertRGBtoYVYU (pic, overlay, monochrome, luminance); | 532 ConvertRGBtoYVYU(pic, overlay, monochrome, luminance); |
533 break; | 533 break; |
534 case SDL_YUY2_OVERLAY: | 534 case SDL_YUY2_OVERLAY: |
535 ConvertRGBtoYUY2 (pic, overlay, monochrome, luminance); | 535 ConvertRGBtoYUY2(pic, overlay, monochrome, luminance); |
536 break; | 536 break; |
537 case SDL_IYUV_OVERLAY: | 537 case SDL_IYUV_OVERLAY: |
538 ConvertRGBtoIYUV (pic, overlay, monochrome, luminance); | 538 ConvertRGBtoIYUV(pic, overlay, monochrome, luminance); |
539 break; | 539 break; |
540 default: | 540 default: |
541 printf ("cannot convert RGB picture to obtained YUV format!\n"); | 541 printf("cannot convert RGB picture to obtained YUV format!\n"); |
542 quit (1); | 542 quit(1); |
543 break; | 543 break; |
544 } | 544 } |
545 #ifdef BENCHMARK_SDL | 545 #ifdef BENCHMARK_SDL |
546 now = SDL_GetTicks (); | 546 now = SDL_GetTicks(); |
547 printf ("Conversion Time: %d milliseconds\n", now - then); | 547 printf("Conversion Time: %d milliseconds\n", now - then); |
548 #endif | 548 #endif |
549 | 549 |
550 /* Do all the drawing work */ | 550 /* Do all the drawing work */ |
551 #ifdef BENCHMARK_SDL | 551 #ifdef BENCHMARK_SDL |
552 then = SDL_GetTicks (); | 552 then = SDL_GetTicks(); |
553 #endif | 553 #endif |
554 Draw (); | 554 Draw(); |
555 #ifdef BENCHMARK_SDL | 555 #ifdef BENCHMARK_SDL |
556 now = SDL_GetTicks (); | 556 now = SDL_GetTicks(); |
557 printf ("Time: %d milliseconds\n", now - then); | 557 printf("Time: %d milliseconds\n", now - then); |
558 #endif | 558 #endif |
559 SDL_Delay (delay * 1000); | 559 SDL_Delay(delay * 1000); |
560 SDL_Quit (); | 560 SDL_Quit(); |
561 return (0); | 561 return (0); |
562 } | 562 } |