Mercurial > sdl-ios-xcode
comparison test/common.c @ 3184:68d3b48a6002
SDL pixel format string is printed near mode number in form of SDL_PIXELFORMAT_XXXXX, when --info option is passed. It is usefull for debugging.
author | Mike Gorchak <lestat@i.com.ua> |
---|---|
date | Wed, 10 Jun 2009 05:56:36 +0000 |
parents | 9dde605c7540 |
children | 51750b7a966f |
comparison
equal
deleted
inserted
replaced
3183:d1436442215f | 3184:68d3b48a6002 |
---|---|
8 #define VIDEO_USAGE \ | 8 #define VIDEO_USAGE \ |
9 "[--video driver] [--renderer driver] [--info all|video|modes|render|event] [--display %d] [--fullscreen | --windows N] [--title title] [--center | --position X,Y] [--geometry WxH] [--depth N] [--refresh R] [--vsync] [--noframe] [--resize] [--minimize] [--maximize] [--grab]" | 9 "[--video driver] [--renderer driver] [--info all|video|modes|render|event] [--display %d] [--fullscreen | --windows N] [--title title] [--center | --position X,Y] [--geometry WxH] [--depth N] [--refresh R] [--vsync] [--noframe] [--resize] [--minimize] [--maximize] [--grab]" |
10 | 10 |
11 #define AUDIO_USAGE \ | 11 #define AUDIO_USAGE \ |
12 "[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]" | 12 "[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]" |
13 | |
14 struct pformat { | |
15 Uint32 id; | |
16 const char* idstr; | |
17 } pixel_format[]={ | |
18 {SDL_PIXELFORMAT_INDEX1LSB, "SDL_PIXELFORMAT_INDEX1LSB"}, | |
19 {SDL_PIXELFORMAT_INDEX1MSB, "SDL_PIXELFORMAT_INDEX1MSB"}, | |
20 {SDL_PIXELFORMAT_INDEX4LSB, "SDL_PIXELFORMAT_INDEX4LSB"}, | |
21 {SDL_PIXELFORMAT_INDEX4MSB, "SDL_PIXELFORMAT_INDEX4MSB"}, | |
22 {SDL_PIXELFORMAT_INDEX8, "SDL_PIXELFORMAT_INDEX8"}, | |
23 {SDL_PIXELFORMAT_RGB332, "SDL_PIXELFORMAT_RGB332"}, | |
24 {SDL_PIXELFORMAT_RGB444, "SDL_PIXELFORMAT_RGB444"}, | |
25 {SDL_PIXELFORMAT_RGB555, "SDL_PIXELFORMAT_RGB555"}, | |
26 {SDL_PIXELFORMAT_BGR555, "SDL_PIXELFORMAT_BGR555"}, | |
27 {SDL_PIXELFORMAT_ARGB4444, "SDL_PIXELFORMAT_ARGB4444"}, | |
28 {SDL_PIXELFORMAT_ABGR4444, "SDL_PIXELFORMAT_ABGR4444"}, | |
29 {SDL_PIXELFORMAT_ARGB1555, "SDL_PIXELFORMAT_ARGB1555"}, | |
30 {SDL_PIXELFORMAT_ABGR1555, "SDL_PIXELFORMAT_ABGR1555"}, | |
31 {SDL_PIXELFORMAT_RGB565, "SDL_PIXELFORMAT_RGB565"}, | |
32 {SDL_PIXELFORMAT_BGR565, "SDL_PIXELFORMAT_BGR565"}, | |
33 {SDL_PIXELFORMAT_RGB24, "SDL_PIXELFORMAT_RGB24"}, | |
34 {SDL_PIXELFORMAT_BGR24, "SDL_PIXELFORMAT_BGR24"}, | |
35 {SDL_PIXELFORMAT_RGB888, "SDL_PIXELFORMAT_RGB888"}, | |
36 {SDL_PIXELFORMAT_BGR888, "SDL_PIXELFORMAT_BGR888"}, | |
37 {SDL_PIXELFORMAT_ARGB8888, "SDL_PIXELFORMAT_ARGB8888"}, | |
38 {SDL_PIXELFORMAT_RGBA8888, "SDL_PIXELFORMAT_RGBA8888"}, | |
39 {SDL_PIXELFORMAT_ABGR8888, "SDL_PIXELFORMAT_ABGR8888"}, | |
40 {SDL_PIXELFORMAT_BGRA8888, "SDL_PIXELFORMAT_BGRA8888"}, | |
41 {SDL_PIXELFORMAT_ARGB2101010, "SDL_PIXELFORMAT_ARGB2101010"}, | |
42 {SDL_PIXELFORMAT_YV12, "SDL_PIXELFORMAT_YV12"}, | |
43 {SDL_PIXELFORMAT_IYUV, "SDL_PIXELFORMAT_IYUV"}, | |
44 {SDL_PIXELFORMAT_YUY2, "SDL_PIXELFORMAT_YUY2"}, | |
45 {SDL_PIXELFORMAT_UYVY, "SDL_PIXELFORMAT_UYVY"}, | |
46 {SDL_PIXELFORMAT_YVYU, "SDL_PIXELFORMAT_YVYU"} | |
47 }; | |
48 | |
49 const char* PixelFormatToString(Uint32 pformat) | |
50 { | |
51 Uint32 it=0; | |
52 | |
53 do { | |
54 if (pixel_format[it].idstr == NULL) { | |
55 break; | |
56 } | |
57 if (pixel_format[it].id == pformat) { | |
58 return pixel_format[it].idstr; | |
59 } | |
60 it++; | |
61 } while(1); | |
62 | |
63 return "SDL_PIXELFORMAT_UNKNOWN"; | |
64 } | |
13 | 65 |
14 CommonState * | 66 CommonState * |
15 CommonCreateState(char **argv, Uint32 flags) | 67 CommonCreateState(char **argv, Uint32 flags) |
16 { | 68 { |
17 CommonState *state = SDL_calloc(1, sizeof(*state)); | 69 CommonState *state = SDL_calloc(1, sizeof(*state)); |
397 fprintf(stderr, "RGB555"); | 449 fprintf(stderr, "RGB555"); |
398 break; | 450 break; |
399 case SDL_PIXELFORMAT_ARGB4444: | 451 case SDL_PIXELFORMAT_ARGB4444: |
400 fprintf(stderr, "ARGB4444"); | 452 fprintf(stderr, "ARGB4444"); |
401 break; | 453 break; |
454 case SDL_PIXELFORMAT_ABGR4444: | |
455 fprintf(stderr, "ABGR4444"); | |
456 break; | |
402 case SDL_PIXELFORMAT_ARGB1555: | 457 case SDL_PIXELFORMAT_ARGB1555: |
403 fprintf(stderr, "ARGB1555"); | 458 fprintf(stderr, "ARGB1555"); |
404 break; | 459 break; |
460 case SDL_PIXELFORMAT_ABGR1555: | |
461 fprintf(stderr, "ABGR1555"); | |
462 break; | |
405 case SDL_PIXELFORMAT_RGB565: | 463 case SDL_PIXELFORMAT_RGB565: |
406 fprintf(stderr, "RGB565"); | 464 fprintf(stderr, "RGB565"); |
465 break; | |
466 case SDL_PIXELFORMAT_BGR565: | |
467 fprintf(stderr, "BGR565"); | |
407 break; | 468 break; |
408 case SDL_PIXELFORMAT_RGB24: | 469 case SDL_PIXELFORMAT_RGB24: |
409 fprintf(stderr, "RGB24"); | 470 fprintf(stderr, "RGB24"); |
410 break; | 471 break; |
411 case SDL_PIXELFORMAT_BGR24: | 472 case SDL_PIXELFORMAT_BGR24: |
565 | 626 |
566 SDL_GetDesktopDisplayMode(&mode); | 627 SDL_GetDesktopDisplayMode(&mode); |
567 SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, &Gmask, | 628 SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, &Gmask, |
568 &Bmask, &Amask); | 629 &Bmask, &Amask); |
569 fprintf(stderr, | 630 fprintf(stderr, |
570 " Current mode: %dx%d@%dHz, %d bits-per-pixel\n", | 631 " Current mode: %dx%d@%dHz, %d bits-per-pixel (%s)\n", |
571 mode.w, mode.h, mode.refresh_rate, bpp); | 632 mode.w, mode.h, mode.refresh_rate, bpp, |
633 PixelFormatToString(mode.format)); | |
572 if (Rmask || Gmask || Bmask) { | 634 if (Rmask || Gmask || Bmask) { |
573 fprintf(stderr, " Red Mask = 0x%.8x\n", Rmask); | 635 fprintf(stderr, " Red Mask = 0x%.8x\n", Rmask); |
574 fprintf(stderr, " Green Mask = 0x%.8x\n", Gmask); | 636 fprintf(stderr, " Green Mask = 0x%.8x\n", Gmask); |
575 fprintf(stderr, " Blue Mask = 0x%.8x\n", Bmask); | 637 fprintf(stderr, " Blue Mask = 0x%.8x\n", Bmask); |
576 if (Amask) | 638 if (Amask) |
577 fprintf(stderr, " Alpha Mask = 0x%.8x\n", Amask); | 639 fprintf(stderr, " Alpha Mask = 0x%.8x\n", Amask); |
578 } | 640 } |
579 | 641 |
580 /* Print available fullscreen video modes */ | 642 /* Print available fullscreen video modes */ |
586 for (j = 0; j < m; ++j) { | 648 for (j = 0; j < m; ++j) { |
587 SDL_GetDisplayMode(j, &mode); | 649 SDL_GetDisplayMode(j, &mode); |
588 SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, | 650 SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, |
589 &Gmask, &Bmask, &Amask); | 651 &Gmask, &Bmask, &Amask); |
590 fprintf(stderr, | 652 fprintf(stderr, |
591 " Mode %d: %dx%d@%dHz, %d bits-per-pixel\n", | 653 " Mode %d: %dx%d@%dHz, %d bits-per-pixel (%s)\n", |
592 j, mode.w, mode.h, mode.refresh_rate, bpp); | 654 j, mode.w, mode.h, mode.refresh_rate, bpp, |
655 PixelFormatToString(mode.format)); | |
593 if (Rmask || Gmask || Bmask) { | 656 if (Rmask || Gmask || Bmask) { |
594 fprintf(stderr, " Red Mask = 0x%.8x\n", | 657 fprintf(stderr, " Red Mask = 0x%.8x\n", |
595 Rmask); | 658 Rmask); |
596 fprintf(stderr, " Green Mask = 0x%.8x\n", | 659 fprintf(stderr, " Green Mask = 0x%.8x\n", |
597 Gmask); | 660 Gmask); |
598 fprintf(stderr, " Blue Mask = 0x%.8x\n", | 661 fprintf(stderr, " Blue Mask = 0x%.8x\n", |
599 Bmask); | 662 Bmask); |
600 if (Amask) | 663 if (Amask) |
601 fprintf(stderr, | 664 fprintf(stderr, |
602 " Alpha Mask = 0x%.8x\n", | 665 " Alpha Mask = 0x%.8x\n", |
603 Amask); | 666 Amask); |
631 fullscreen_mode.format = SDL_PIXELFORMAT_RGB555; | 694 fullscreen_mode.format = SDL_PIXELFORMAT_RGB555; |
632 break; | 695 break; |
633 case 16: | 696 case 16: |
634 fullscreen_mode.format = SDL_PIXELFORMAT_RGB565; | 697 fullscreen_mode.format = SDL_PIXELFORMAT_RGB565; |
635 break; | 698 break; |
699 case 24: | |
700 fullscreen_mode.format = SDL_PIXELFORMAT_RGB24; | |
701 break; | |
636 default: | 702 default: |
637 fullscreen_mode.format = SDL_PIXELFORMAT_RGB888; | 703 fullscreen_mode.format = SDL_PIXELFORMAT_RGB888; |
638 break; | 704 break; |
639 } | 705 } |
640 fullscreen_mode.w = state->window_w; | 706 fullscreen_mode.w = state->window_w; |
641 fullscreen_mode.h = state->window_h; | 707 fullscreen_mode.h = state->window_h; |
642 fullscreen_mode.refresh_rate = state->refresh_rate; | 708 fullscreen_mode.refresh_rate = state->refresh_rate; |
643 SDL_SetFullscreenDisplayMode(&fullscreen_mode); | 709 if (SDL_SetFullscreenDisplayMode(&fullscreen_mode)<0) { |
710 fprintf(stderr, "Can't switch to fullscreen display mode: %s\n", | |
711 SDL_GetError()); | |
712 return SDL_FALSE; | |
713 } | |
644 | 714 |
645 state->windows = | 715 state->windows = |
646 (SDL_WindowID *) SDL_malloc(state->num_windows * | 716 (SDL_WindowID *) SDL_malloc(state->num_windows * |
647 sizeof(*state->windows)); | 717 sizeof(*state->windows)); |
648 if (!state->windows) { | 718 if (!state->windows) { |