Mercurial > sdl-ios-xcode
annotate test/testoverlay.c @ 421:195dd37b3d86
Bugfix from Corona688: don't reference a string before we've initialized it.
Fixes crashbug on WinCE (PocketPC).
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Tue, 02 Jul 2002 04:07:01 +0000 |
parents | 255c7ee077cb |
children | e8063c656626 |
rev | line source |
---|---|
277
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
2 /* Bring up a window and play with it */ |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
3 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 #include <stdlib.h> |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
5 #include <stdio.h> |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
6 #include <string.h> |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
7 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 #define BENCHMARK_SDL |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 #define NOTICE(X) printf("%s", X); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 #include "SDL.h" |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
13 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 SDL_Surface *screen, *pic; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
15 SDL_Overlay *overlay; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
16 int scale; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
17 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
18 /* NOTE: These RGB conversion functions are not intended for speed, |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 only as examples. |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 */ |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 void RGBtoYUV(Uint8 *rgb, int *yuv) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
23 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 int i; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 #if 1 /* these are the two formulas that I found on the FourCC site... */ |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 yuv[0] = 0.299*rgb[0] + 0.587*rgb[1] + 0.114*rgb[2]; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 yuv[1] = (rgb[2]-yuv[0])*0.565 + 128; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 yuv[2] = (rgb[0]-yuv[0])*0.713 + 128; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 #else |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
30 yuv[0] = (0.257 * rgb[0]) + (0.504 * rgb[1]) + (0.098 * rgb[2]) + 16; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
31 yuv[1] = 128 - (0.148 * rgb[0]) - (0.291 * rgb[1]) + (0.439 * rgb[2]); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
32 yuv[2] = 128 + (0.439 * rgb[0]) - (0.368 * rgb[1]) - (0.071 * rgb[2]); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 #endif |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
34 /* clamp values...if you need to, we don't seem to have a need */ |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
35 /* |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
36 for(i=0;i<3;i++) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
37 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
38 if(yuv[i]<0) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
39 yuv[i]=0; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
40 if(yuv[i]>255) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
41 yuv[i]=255; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
42 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
43 */ |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
46 ConvertRGBtoYV12(SDL_Surface *s, SDL_Overlay *o) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
47 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
48 int x,y; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
49 int yuv[3]; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
50 Uint8 *p,*op[3]; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
51 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
52 SDL_LockSurface(s); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
53 SDL_LockYUVOverlay(o); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
55 /* Black initialization */ |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
56 /* |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
57 memset(o->pixels[0],0,o->pitches[0]*o->h); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
58 memset(o->pixels[1],128,o->pitches[1]*((o->h+1)/2)); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 memset(o->pixels[2],128,o->pitches[2]*((o->h+1)/2)); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
60 */ |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
61 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 /* Convert */ |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
63 for(y=0; y<s->h && y<o->h; y++) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
64 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
65 p=s->pixels+s->pitch*y; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
66 op[0]=o->pixels[0]+o->pitches[0]*y; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
67 op[1]=o->pixels[1]+o->pitches[1]*(y/2); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
68 op[2]=o->pixels[2]+o->pitches[2]*(y/2); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
69 for(x=0; x<s->w && x<o->w; x++) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
70 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
71 RGBtoYUV(p,yuv); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
72 *(op[0]++)=yuv[0]; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
73 if(x%2==0 && y%2==0) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
74 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
75 *(op[1]++)=yuv[2]; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
76 *(op[2]++)=yuv[1]; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
77 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
78 p+=s->format->BytesPerPixel; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
79 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
80 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
81 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
82 SDL_UnlockYUVOverlay(o); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
83 SDL_UnlockSurface(s); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
84 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
85 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
86 ConvertRGBtoIYUV(SDL_Surface *s, SDL_Overlay *o) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
87 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
88 int x,y; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
89 int yuv[3]; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
90 Uint8 *p,*op[3]; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
91 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
92 SDL_LockSurface(s); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
93 SDL_LockYUVOverlay(o); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
94 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
95 /* Black initialization */ |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
96 /* |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
97 memset(o->pixels[0],0,o->pitches[0]*o->h); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
98 memset(o->pixels[1],128,o->pitches[1]*((o->h+1)/2)); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
99 memset(o->pixels[2],128,o->pitches[2]*((o->h+1)/2)); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
100 */ |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
101 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
102 /* Convert */ |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
103 for(y=0; y<s->h && y<o->h; y++) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
104 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
105 p=s->pixels+s->pitch*y; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
106 op[0]=o->pixels[0]+o->pitches[0]*y; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
107 op[1]=o->pixels[1]+o->pitches[1]*(y/2); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
108 op[2]=o->pixels[2]+o->pitches[2]*(y/2); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
109 for(x=0; x<s->w && x<o->w; x++) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
110 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
111 RGBtoYUV(p,yuv); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
112 *(op[0]++)=yuv[0]; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
113 if(x%2==0 && y%2==0) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
114 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
115 *(op[1]++)=yuv[1]; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
116 *(op[2]++)=yuv[2]; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
117 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
118 p+=s->format->BytesPerPixel; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
119 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
120 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
121 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
122 SDL_UnlockYUVOverlay(o); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
123 SDL_UnlockSurface(s); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
124 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
125 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
126 ConvertRGBtoUYVY(SDL_Surface *s, SDL_Overlay *o) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
127 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
128 int x,y; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
129 int yuv[3]; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
130 Uint8 *p,*op; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
131 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
132 SDL_LockSurface(s); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
133 SDL_LockYUVOverlay(o); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
134 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
135 for(y=0; y<s->h && y<o->h; y++) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
136 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
137 p=s->pixels+s->pitch*y; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
138 op=o->pixels[0]+o->pitches[0]*y; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
139 for(x=0; x<s->w && x<o->w; x++) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
140 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
141 RGBtoYUV(p,yuv); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
142 if(x%2==0) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
143 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
144 *(op++)=yuv[1]; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
145 *(op++)=yuv[0]; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
146 *(op++)=yuv[2]; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
147 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
148 else |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
149 *(op++)=yuv[0]; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
150 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
151 p+=s->format->BytesPerPixel; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
152 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
153 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
154 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
155 SDL_UnlockYUVOverlay(o); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
156 SDL_UnlockSurface(s); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
157 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
158 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
159 ConvertRGBtoYVYU(SDL_Surface *s, SDL_Overlay *o) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
160 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
161 int x,y; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
162 int yuv[3]; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
163 Uint8 *p,*op; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
164 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
165 SDL_LockSurface(s); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
166 SDL_LockYUVOverlay(o); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
167 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
168 for(y=0; y<s->h && y<o->h; y++) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
169 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
170 p=s->pixels+s->pitch*y; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
171 op=o->pixels[0]+o->pitches[0]*y; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
172 for(x=0; x<s->w && x<o->w; x++) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
173 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
174 RGBtoYUV(p,yuv); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
175 if(x%2==0) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
176 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
177 *(op++)=yuv[0]; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
178 *(op++)=yuv[2]; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
179 op[1]=yuv[1]; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
180 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
181 else |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
182 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
183 *op=yuv[0]; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
184 op+=2; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
185 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
186 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
187 p+=s->format->BytesPerPixel; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
188 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
189 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
190 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
191 SDL_UnlockYUVOverlay(o); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
192 SDL_UnlockSurface(s); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
193 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
194 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
195 ConvertRGBtoYUY2(SDL_Surface *s, SDL_Overlay *o) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
196 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
197 int x,y; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
198 int yuv[3]; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
199 Uint8 *p,*op; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
200 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
201 SDL_LockSurface(s); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
202 SDL_LockYUVOverlay(o); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
203 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
204 for(y=0; y<s->h && y<o->h; y++) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
205 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
206 p=s->pixels+s->pitch*y; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
207 op=o->pixels[0]+o->pitches[0]*y; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
208 for(x=0; x<s->w && x<o->w; x++) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
209 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
210 RGBtoYUV(p,yuv); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
211 if(x%2==0) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
212 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
213 *(op++)=yuv[0]; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
214 *(op++)=yuv[1]; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
215 op[1]=yuv[2]; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
216 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
217 else |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
218 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
219 *op=yuv[0]; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
220 op+=2; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
221 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
222 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
223 p+=s->format->BytesPerPixel; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
224 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
225 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
226 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
227 SDL_UnlockYUVOverlay(o); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
228 SDL_UnlockSurface(s); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
229 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
230 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
231 void Draw() |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
232 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
233 SDL_Rect rect; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
234 int i; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
235 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
236 if(!scale) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
237 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
238 rect.w=overlay->w; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
239 rect.h=overlay->h; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
240 for(i=0; i<200; i++) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
241 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
242 rect.x=i; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
243 rect.y=i; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
244 SDL_DisplayYUVOverlay(overlay,&rect); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
245 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
246 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
247 else |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
248 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
249 rect.w=screen->w; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
250 rect.h=screen->h; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
251 for(i=0; i<200; i++) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
252 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
253 rect.x=i-199; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
254 rect.y=i-199; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
255 SDL_DisplayYUVOverlay(overlay,&rect); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
256 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
257 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
258 printf("Displayed %d times.\n",i); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
259 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
260 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
261 int main(int argc, char **argv) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
262 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
263 int flip; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
264 int w, h; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
265 int delay; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
266 int desired_bpp; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
267 Uint32 video_flags, overlay_format; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
268 char *bmpfile; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
269 #ifdef BENCHMARK_SDL |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
270 Uint32 then, now; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
271 #endif |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
272 int i; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
273 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
274 /* Set default options and check command-line */ |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
275 flip = 0; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
276 scale=0; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
277 delay = 1; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
278 w = 640; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
279 h = 480; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
280 desired_bpp = 0; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
281 video_flags = 0; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
282 overlay_format = SDL_YV12_OVERLAY; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
283 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
284 while ( argc > 1 ) { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
285 if ( strcmp(argv[1], "-delay") == 0 ) { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
286 if ( argv[2] ) { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
287 delay = atoi(argv[2]); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
288 argv += 2; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
289 argc -= 2; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
290 } else { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
291 fprintf(stderr, |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
292 "The -delay option requires an argument\n"); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
293 exit(1); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
294 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
295 } else |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
296 if ( strcmp(argv[1], "-width") == 0 ) { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
297 if ( argv[2] && ((w = atoi(argv[2])) > 0) ) { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
298 argv += 2; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
299 argc -= 2; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
300 } else { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
301 fprintf(stderr, |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
302 "The -width option requires an argument\n"); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
303 exit(1); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
304 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
305 } else |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
306 if ( strcmp(argv[1], "-height") == 0 ) { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
307 if ( argv[2] && ((h = atoi(argv[2])) > 0) ) { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
308 argv += 2; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
309 argc -= 2; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
310 } else { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
311 fprintf(stderr, |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
312 "The -height option requires an argument\n"); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
313 exit(1); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
314 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
315 } else |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
316 if ( strcmp(argv[1], "-bpp") == 0 ) { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
317 if ( argv[2] ) { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
318 desired_bpp = atoi(argv[2]); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
319 argv += 2; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
320 argc -= 2; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
321 } else { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
322 fprintf(stderr, |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
323 "The -bpp option requires an argument\n"); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
324 exit(1); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
325 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
326 } else |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
327 if ( strcmp(argv[1], "-format") == 0 ) { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
328 if ( argv[2] ) { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
329 if(!strcmp(argv[2],"YV12")) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
330 overlay_format = SDL_YV12_OVERLAY; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
331 else if(!strcmp(argv[2],"IYUV")) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
332 overlay_format = SDL_IYUV_OVERLAY; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
333 else if(!strcmp(argv[2],"YUY2")) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
334 overlay_format = SDL_YUY2_OVERLAY; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
335 else if(!strcmp(argv[2],"UYVY")) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
336 overlay_format = SDL_UYVY_OVERLAY; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
337 else if(!strcmp(argv[2],"YVYU")) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
338 overlay_format = SDL_YVYU_OVERLAY; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
339 else |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
340 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
341 fprintf(stderr, "The -format option %s is not recognized\n",argv[2]); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
342 exit(1); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
343 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
344 argv += 2; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
345 argc -= 2; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
346 } else { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
347 fprintf(stderr, |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
348 "The -format option requires an argument\n"); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
349 exit(1); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
350 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
351 } else |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
352 if ( strcmp(argv[1], "-hw") == 0 ) { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
353 video_flags |= SDL_HWSURFACE; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
354 argv += 1; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
355 argc -= 1; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
356 } else |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
357 if ( strcmp(argv[1], "-flip") == 0 ) { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
358 video_flags |= SDL_DOUBLEBUF; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
359 argv += 1; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
360 argc -= 1; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
361 } else |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
362 if ( strcmp(argv[1], "-scale") == 0 ) { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
363 scale = 1; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
364 argv += 1; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
365 argc -= 1; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
366 } else |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
367 if ( strcmp(argv[1], "-fullscreen") == 0 ) { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
368 video_flags |= SDL_FULLSCREEN; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
369 argv += 1; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
370 argc -= 1; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
371 } else |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
372 break; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
373 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
374 if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
375 fprintf(stderr, |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
376 "Couldn't initialize SDL: %s\n", SDL_GetError()); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
377 exit(1); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
378 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
379 atexit(SDL_Quit); /* Clean up on exit */ |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
380 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
381 /* Initialize the display */ |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
382 screen = SDL_SetVideoMode(w, h, desired_bpp, video_flags); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
383 if ( screen == NULL ) { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
384 fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n", |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
385 w, h, desired_bpp, SDL_GetError()); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
386 exit(1); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
387 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
388 printf("Set%s %dx%dx%d mode\n", |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
389 screen->flags & SDL_FULLSCREEN ? " fullscreen" : "", |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
390 screen->w, screen->h, screen->format->BitsPerPixel); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
391 printf("(video surface located in %s memory)\n", |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
392 (screen->flags&SDL_HWSURFACE) ? "video" : "system"); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
393 if ( screen->flags & SDL_DOUBLEBUF ) { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
394 printf("Double-buffering enabled\n"); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
395 flip = 1; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
396 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
397 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
398 /* Set the window manager title bar */ |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
399 SDL_WM_SetCaption("SDL test overlay", "testoverlay"); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
400 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
401 /* Load picture */ |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
402 bmpfile=(argv[1]?argv[1]:"sample.bmp"); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
403 pic = SDL_LoadBMP(bmpfile); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
404 if ( pic == NULL ) { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
405 fprintf(stderr, "Couldn't load %s: %s\n", bmpfile, |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
406 SDL_GetError()); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
407 exit(1); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
408 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
409 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
410 /* Convert the picture to 32bits, for easy conversion */ |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
411 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
412 SDL_Surface *newsurf; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
413 SDL_PixelFormat format; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
414 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
415 format.palette=NULL; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
416 format.BitsPerPixel=32; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
417 format.BytesPerPixel=4; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
418 #if SDL_BYTEORDER == SDL_LIL_ENDIAN |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
419 format.Rshift=0; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
420 format.Gshift=8; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
421 format.Bshift=16; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
422 #else |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
423 format.Rshift=24; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
424 format.Gshift=16; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
425 format.Bshift=8; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
426 #endif |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
427 format.Ashift=0; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
428 format.Rmask=0xff<<format.Rshift; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
429 format.Gmask=0xff<<format.Gshift; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
430 format.Bmask=0xff<<format.Bshift; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
431 format.Amask=0; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
432 format.Rloss=0; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
433 format.Gloss=0; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
434 format.Bloss=0; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
435 format.Aloss=8; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
436 format.colorkey=0; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
437 format.alpha=0; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
438 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
439 newsurf=SDL_ConvertSurface(pic, &format, SDL_SWSURFACE); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
440 if(!newsurf) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
441 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
442 fprintf(stderr, "Couldn't convert picture to 32bits RGB: %s\n", |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
443 SDL_GetError()); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
444 exit(1); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
445 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
446 SDL_FreeSurface(pic); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
447 pic=newsurf; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
448 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
449 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
450 /* Create the overlay */ |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
451 overlay = SDL_CreateYUVOverlay(pic->w, pic->h, overlay_format, screen); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
452 if ( overlay == NULL ) { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
453 fprintf(stderr, "Couldn't create overlay: %s\n", SDL_GetError()); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
454 exit(1); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
455 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
456 printf("Created %dx%dx%d %s %s overlay\n",overlay->w,overlay->h,overlay->planes, |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
457 overlay->hw_overlay?"hardware":"software", |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
458 overlay->format==SDL_YV12_OVERLAY?"YV12": |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
459 overlay->format==SDL_IYUV_OVERLAY?"IYUV": |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
460 overlay->format==SDL_YUY2_OVERLAY?"YUY2": |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
461 overlay->format==SDL_UYVY_OVERLAY?"UYVY": |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
462 overlay->format==SDL_YVYU_OVERLAY?"YVYU": |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
463 "Unknown"); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
464 for(i=0; i<overlay->planes; i++) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
465 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
466 printf(" plane %d: pitch=%d\n", i, overlay->pitches[i]); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
467 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
468 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
469 /* Convert to YUV, and draw to the overlay */ |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
470 #ifdef BENCHMARK_SDL |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
471 then = SDL_GetTicks(); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
472 #endif |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
473 switch(overlay->format) |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
474 { |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
475 case SDL_YV12_OVERLAY: |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
476 ConvertRGBtoYV12(pic,overlay); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
477 break; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
478 case SDL_UYVY_OVERLAY: |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
479 ConvertRGBtoUYVY(pic,overlay); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
480 break; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
481 case SDL_YVYU_OVERLAY: |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
482 ConvertRGBtoYVYU(pic,overlay); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
483 break; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
484 case SDL_YUY2_OVERLAY: |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
485 ConvertRGBtoYUY2(pic,overlay); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
486 break; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
487 case SDL_IYUV_OVERLAY: |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
488 ConvertRGBtoIYUV(pic,overlay); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
489 break; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
490 default: |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
491 printf("cannot convert RGB picture to obtained YUV format!\n"); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
492 exit(1); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
493 break; |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
494 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
495 #ifdef BENCHMARK_SDL |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
496 now = SDL_GetTicks(); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
497 printf("Conversion Time: %d milliseconds\n", now-then); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
498 #endif |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
499 |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
500 /* Do all the drawing work */ |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
501 #ifdef BENCHMARK_SDL |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
502 then = SDL_GetTicks(); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
503 #endif |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
504 Draw(); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
505 #ifdef BENCHMARK_SDL |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
506 now = SDL_GetTicks(); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
507 printf("Time: %d milliseconds\n", now-then); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
508 #endif |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
509 SDL_Delay(delay*1000); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
510 return(0); |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
511 } |
255c7ee077cb
Added a YUV overlay test program (thanks Jon!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
512 |