Mercurial > sdl-ios-xcode
annotate src/video/windx5/SDL_dx5yuv.c @ 1338:604d73db6802
Removed uses of stdlib.h and string.h
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 07 Feb 2006 09:29:18 +0000 |
parents | 3692456e7b0f |
children | c71e05b4dc2e |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
811
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
811
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
811
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 9 |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
811
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
811
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
811
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
811
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
33
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
22 | |
23 /* This is the DirectDraw implementation of YUV video overlays */ | |
24 | |
1338
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
25 #include "SDL_stdlib.h" |
604d73db6802
Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents:
1336
diff
changeset
|
26 #include "SDL_string.h" |
0 | 27 #include "SDL_error.h" |
28 #include "SDL_video.h" | |
29 #include "SDL_dx5yuv_c.h" | |
30 #include "SDL_yuvfuncs.h" | |
31 | |
811
e06ec825242d
Don't use hardware overlay by default (seems much faster this way)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
32 //#define USE_DIRECTX_OVERLAY |
0 | 33 |
34 /* The functions used to manipulate software video overlays */ | |
35 static struct private_yuvhwfuncs dx5_yuvfuncs = { | |
36 DX5_LockYUVOverlay, | |
37 DX5_UnlockYUVOverlay, | |
38 DX5_DisplayYUVOverlay, | |
39 DX5_FreeYUVOverlay | |
40 }; | |
41 | |
42 struct private_yuvhwdata { | |
43 LPDIRECTDRAWSURFACE3 surface; | |
44 | |
45 /* These are just so we don't have to allocate them separately */ | |
46 Uint16 pitches[3]; | |
47 Uint8 *planes[3]; | |
48 }; | |
49 | |
50 | |
51 static LPDIRECTDRAWSURFACE3 CreateYUVSurface(_THIS, | |
52 int width, int height, Uint32 format) | |
53 { | |
54 HRESULT result; | |
55 LPDIRECTDRAWSURFACE dd_surface1; | |
56 LPDIRECTDRAWSURFACE3 dd_surface3; | |
57 DDSURFACEDESC ddsd; | |
58 | |
59 /* Set up the surface description */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
60 SDL_memset(&ddsd, 0, sizeof(ddsd)); |
0 | 61 ddsd.dwSize = sizeof(ddsd); |
62 ddsd.dwFlags = (DDSD_WIDTH|DDSD_HEIGHT|DDSD_CAPS|DDSD_PIXELFORMAT); | |
63 ddsd.dwWidth = width; | |
64 ddsd.dwHeight= height; | |
65 #ifdef USE_DIRECTX_OVERLAY | |
66 ddsd.ddsCaps.dwCaps = (DDSCAPS_OVERLAY|DDSCAPS_VIDEOMEMORY); | |
67 #else | |
68 ddsd.ddsCaps.dwCaps = (DDSCAPS_OFFSCREENPLAIN|DDSCAPS_VIDEOMEMORY); | |
69 #endif | |
70 ddsd.ddpfPixelFormat.dwSize = sizeof(ddsd.ddpfPixelFormat); | |
71 ddsd.ddpfPixelFormat.dwFlags = DDPF_FOURCC; | |
72 ddsd.ddpfPixelFormat.dwFourCC = format; | |
73 | |
74 /* Create the DirectDraw video surface */ | |
75 result = IDirectDraw2_CreateSurface(ddraw2, &ddsd, &dd_surface1, NULL); | |
76 if ( result != DD_OK ) { | |
77 SetDDerror("DirectDraw2::CreateSurface", result); | |
78 return(NULL); | |
79 } | |
80 result = IDirectDrawSurface_QueryInterface(dd_surface1, | |
81 &IID_IDirectDrawSurface3, (LPVOID *)&dd_surface3); | |
82 IDirectDrawSurface_Release(dd_surface1); | |
83 if ( result != DD_OK ) { | |
84 SetDDerror("DirectDrawSurface::QueryInterface", result); | |
85 return(NULL); | |
86 } | |
87 | |
88 /* Make sure the surface format was set properly */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
89 SDL_memset(&ddsd, 0, sizeof(ddsd)); |
0 | 90 ddsd.dwSize = sizeof(ddsd); |
91 result = IDirectDrawSurface3_Lock(dd_surface3, NULL, | |
92 &ddsd, DDLOCK_NOSYSLOCK, NULL); | |
93 if ( result != DD_OK ) { | |
94 SetDDerror("DirectDrawSurface3::Lock", result); | |
95 IDirectDrawSurface_Release(dd_surface3); | |
96 return(NULL); | |
97 } | |
98 IDirectDrawSurface3_Unlock(dd_surface3, NULL); | |
99 | |
100 if ( !(ddsd.ddpfPixelFormat.dwFlags & DDPF_FOURCC) || | |
101 (ddsd.ddpfPixelFormat.dwFourCC != format) ) { | |
102 SDL_SetError("DDraw didn't use requested FourCC format"); | |
103 IDirectDrawSurface_Release(dd_surface3); | |
104 return(NULL); | |
105 } | |
106 | |
107 /* We're ready to go! */ | |
108 return(dd_surface3); | |
109 } | |
110 | |
111 #ifdef DEBUG_YUV | |
112 static char *PrintFOURCC(Uint32 code) | |
113 { | |
114 static char buf[5]; | |
115 | |
116 buf[3] = code >> 24; | |
117 buf[2] = (code >> 16) & 0xFF; | |
118 buf[1] = (code >> 8) & 0xFF; | |
119 buf[0] = (code & 0xFF); | |
120 return(buf); | |
121 } | |
122 #endif | |
123 | |
124 SDL_Overlay *DX5_CreateYUVOverlay(_THIS, int width, int height, Uint32 format, SDL_Surface *display) | |
125 { | |
126 SDL_Overlay *overlay; | |
127 struct private_yuvhwdata *hwdata; | |
128 | |
129 #ifdef DEBUG_YUV | |
130 DWORD numcodes; | |
131 DWORD *codes; | |
132 | |
133 printf("FOURCC format requested: 0x%x\n", PrintFOURCC(format)); | |
134 IDirectDraw2_GetFourCCCodes(ddraw2, &numcodes, NULL); | |
135 if ( numcodes ) { | |
136 DWORD i; | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
137 codes = SDL_malloc(numcodes*sizeof(*codes)); |
0 | 138 if ( codes ) { |
139 IDirectDraw2_GetFourCCCodes(ddraw2, &numcodes, codes); | |
140 for ( i=0; i<numcodes; ++i ) { | |
141 fprintf(stderr, "Code %d: 0x%x\n", i, PrintFOURCC(codes[i])); | |
142 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
143 SDL_free(codes); |
0 | 144 } |
145 } else { | |
146 fprintf(stderr, "No FOURCC codes supported\n"); | |
147 } | |
148 #endif | |
149 | |
150 /* Create the overlay structure */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
151 overlay = (SDL_Overlay *)SDL_malloc(sizeof *overlay); |
0 | 152 if ( overlay == NULL ) { |
153 SDL_OutOfMemory(); | |
154 return(NULL); | |
155 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
156 SDL_memset(overlay, 0, (sizeof *overlay)); |
0 | 157 |
158 /* Fill in the basic members */ | |
159 overlay->format = format; | |
160 overlay->w = width; | |
161 overlay->h = height; | |
162 | |
163 /* Set up the YUV surface function structure */ | |
164 overlay->hwfuncs = &dx5_yuvfuncs; | |
165 | |
166 /* Create the pixel data and lookup tables */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
167 hwdata = (struct private_yuvhwdata *)SDL_malloc(sizeof *hwdata); |
0 | 168 overlay->hwdata = hwdata; |
169 if ( hwdata == NULL ) { | |
170 SDL_OutOfMemory(); | |
171 SDL_FreeYUVOverlay(overlay); | |
172 return(NULL); | |
173 } | |
174 hwdata->surface = CreateYUVSurface(this, width, height, format); | |
175 if ( hwdata->surface == NULL ) { | |
176 SDL_FreeYUVOverlay(overlay); | |
177 return(NULL); | |
178 } | |
179 overlay->hw_overlay = 1; | |
180 | |
181 /* Set up the plane pointers */ | |
182 overlay->pitches = hwdata->pitches; | |
183 overlay->pixels = hwdata->planes; | |
184 switch (format) { | |
185 case SDL_YV12_OVERLAY: | |
186 case SDL_IYUV_OVERLAY: | |
187 overlay->planes = 3; | |
33
81a7158fa836
Silly bug fix from Billy Biggs
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
188 break; |
0 | 189 default: |
190 overlay->planes = 1; | |
191 break; | |
192 } | |
193 | |
194 /* We're all done.. */ | |
195 return(overlay); | |
196 } | |
197 | |
198 int DX5_LockYUVOverlay(_THIS, SDL_Overlay *overlay) | |
199 { | |
200 HRESULT result; | |
201 LPDIRECTDRAWSURFACE3 surface; | |
202 DDSURFACEDESC ddsd; | |
203 | |
204 surface = overlay->hwdata->surface; | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
205 SDL_memset(&ddsd, 0, sizeof(ddsd)); |
0 | 206 ddsd.dwSize = sizeof(ddsd); |
207 result = IDirectDrawSurface3_Lock(surface, NULL, | |
208 &ddsd, DDLOCK_NOSYSLOCK, NULL); | |
209 if ( result == DDERR_SURFACELOST ) { | |
210 result = IDirectDrawSurface3_Restore(surface); | |
211 result = IDirectDrawSurface3_Lock(surface, NULL, &ddsd, | |
212 (DDLOCK_NOSYSLOCK|DDLOCK_WAIT), NULL); | |
213 } | |
214 if ( result != DD_OK ) { | |
215 SetDDerror("DirectDrawSurface3::Lock", result); | |
216 return(-1); | |
217 } | |
218 | |
219 /* Find the pitch and offset values for the overlay */ | |
220 #if defined(NONAMELESSUNION) | |
221 overlay->pitches[0] = (Uint16)ddsd.u1.lPitch; | |
222 #else | |
223 overlay->pitches[0] = (Uint16)ddsd.lPitch; | |
224 #endif | |
225 overlay->pixels[0] = (Uint8 *)ddsd.lpSurface; | |
226 switch (overlay->format) { | |
227 case SDL_YV12_OVERLAY: | |
228 case SDL_IYUV_OVERLAY: | |
229 /* Add the two extra planes */ | |
230 overlay->pitches[1] = overlay->pitches[0] / 2; | |
231 overlay->pitches[2] = overlay->pitches[0] / 2; | |
232 overlay->pixels[1] = overlay->pixels[0] + | |
233 overlay->pitches[0] * overlay->h; | |
234 overlay->pixels[2] = overlay->pixels[1] + | |
235 overlay->pitches[1] * overlay->h / 2; | |
236 break; | |
237 default: | |
238 /* Only one plane, no worries */ | |
239 break; | |
240 } | |
241 return(0); | |
242 } | |
243 | |
244 void DX5_UnlockYUVOverlay(_THIS, SDL_Overlay *overlay) | |
245 { | |
246 LPDIRECTDRAWSURFACE3 surface; | |
247 | |
248 surface = overlay->hwdata->surface; | |
249 IDirectDrawSurface3_Unlock(surface, NULL); | |
250 } | |
251 | |
252 int DX5_DisplayYUVOverlay(_THIS, SDL_Overlay *overlay, SDL_Rect *dstrect) | |
253 { | |
254 HRESULT result; | |
255 LPDIRECTDRAWSURFACE3 surface; | |
256 RECT src, dst; | |
257 | |
258 surface = overlay->hwdata->surface; | |
259 src.top = 0; | |
260 src.bottom = overlay->h; | |
261 src.left = 0; | |
262 src.right = overlay->w; | |
263 dst.top = SDL_bounds.top+dstrect->y; | |
264 dst.left = SDL_bounds.left+dstrect->x; | |
265 dst.bottom = dst.top+dstrect->h; | |
266 dst.right = dst.left+dstrect->w; | |
267 #ifdef USE_DIRECTX_OVERLAY | |
268 result = IDirectDrawSurface3_UpdateOverlay(surface, &src, | |
269 SDL_primary, &dst, DDOVER_SHOW, NULL); | |
270 if ( result != DD_OK ) { | |
271 SetDDerror("DirectDrawSurface3::UpdateOverlay", result); | |
272 return(-1); | |
273 } | |
274 #else | |
275 result = IDirectDrawSurface3_Blt(SDL_primary, &dst, surface, &src, | |
276 DDBLT_WAIT, NULL); | |
277 if ( result != DD_OK ) { | |
278 SetDDerror("DirectDrawSurface3::Blt", result); | |
279 return(-1); | |
280 } | |
281 #endif | |
282 return(0); | |
283 } | |
284 | |
285 void DX5_FreeYUVOverlay(_THIS, SDL_Overlay *overlay) | |
286 { | |
287 struct private_yuvhwdata *hwdata; | |
288 | |
289 hwdata = overlay->hwdata; | |
290 if ( hwdata ) { | |
291 if ( hwdata->surface ) { | |
292 IDirectDrawSurface_Release(hwdata->surface); | |
293 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1330
diff
changeset
|
294 SDL_free(hwdata); |
0 | 295 } |
296 } | |
297 |