Mercurial > sdl-ios-xcode
comparison src/video/bwindow/SDL_sysyuv.cc @ 1668:4da1ee79c9af SDL-1.3
more tweaking indent options
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 29 May 2006 04:04:35 +0000 |
parents | 782fd950bd46 |
children |
comparison
equal
deleted
inserted
replaced
1667:1fddae038bc8 | 1668:4da1ee79c9af |
---|---|
36 BE_UnlockYUVOverlay, | 36 BE_UnlockYUVOverlay, |
37 BE_DisplayYUVOverlay, | 37 BE_DisplayYUVOverlay, |
38 BE_FreeYUVOverlay | 38 BE_FreeYUVOverlay |
39 }; | 39 }; |
40 | 40 |
41 BBitmap *BE_GetOverlayBitmap (BRect bounds, color_space cs) | 41 BBitmap *BE_GetOverlayBitmap(BRect bounds, color_space cs) |
42 { | 42 { |
43 BBitmap *bbitmap; | 43 BBitmap *bbitmap; |
44 bbitmap = new BBitmap (bounds, B_BITMAP_WILL_OVERLAY, cs); | 44 bbitmap = new BBitmap(bounds, B_BITMAP_WILL_OVERLAY, cs); |
45 if (!bbitmap || bbitmap->InitCheck () != B_OK) { | 45 if (!bbitmap || bbitmap->InitCheck() != B_OK) { |
46 delete bbitmap; | 46 delete bbitmap; |
47 return 0; | 47 return 0; |
48 } | 48 } |
49 overlay_restrictions r; | 49 overlay_restrictions r; |
50 bbitmap->GetOverlayRestrictions (&r); | 50 bbitmap->GetOverlayRestrictions(&r); |
51 uint32 width = bounds.IntegerWidth () + 1; | 51 uint32 width = bounds.IntegerWidth() + 1; |
52 uint32 height = bounds.IntegerHeight () + 1; | 52 uint32 height = bounds.IntegerHeight() + 1; |
53 uint32 width_padding = 0; | 53 uint32 width_padding = 0; |
54 uint32 height_padding = 0; | 54 uint32 height_padding = 0; |
55 if ((r.source.horizontal_alignment != 0) || | 55 if ((r.source.horizontal_alignment != 0) || |
56 (r.source.vertical_alignment != 0)) { | 56 (r.source.vertical_alignment != 0)) { |
57 delete bbitmap; | 57 delete bbitmap; |
64 } | 64 } |
65 } | 65 } |
66 if (r.source.height_alignment != 0) { | 66 if (r.source.height_alignment != 0) { |
67 uint32 aligned_height = r.source.height_alignment + 1; | 67 uint32 aligned_height = r.source.height_alignment + 1; |
68 if (height % aligned_height > 0) { | 68 if (height % aligned_height > 0) { |
69 fprintf (stderr, | 69 fprintf(stderr, "GetOverlayBitmap failed height alignment\n"); |
70 "GetOverlayBitmap failed height alignment\n"); | 70 fprintf(stderr, "- height = %lu, aligned_height = %lu\n", |
71 fprintf (stderr, "- height = %lu, aligned_height = %lu\n", | 71 height, aligned_height); |
72 height, aligned_height); | |
73 delete bbitmap; | 72 delete bbitmap; |
74 return 0; | 73 return 0; |
75 } | 74 } |
76 } | 75 } |
77 if ((r.source.min_width > width) || | 76 if ((r.source.min_width > width) || |
78 (r.source.min_height > height) || | 77 (r.source.min_height > height) || |
79 (r.source.max_width < width) || (r.source.max_height < height)) { | 78 (r.source.max_width < width) || (r.source.max_height < height)) { |
80 fprintf (stderr, "GetOverlayBitmap failed bounds tests\n"); | 79 fprintf(stderr, "GetOverlayBitmap failed bounds tests\n"); |
81 delete bbitmap; | 80 delete bbitmap; |
82 return 0; | 81 return 0; |
83 } | 82 } |
84 if ((width_padding != 0) || (height_padding != 0)) { | 83 if ((width_padding != 0) || (height_padding != 0)) { |
85 delete bbitmap; | 84 delete bbitmap; |
86 bounds.Set (bounds.left, bounds.top, | 85 bounds.Set(bounds.left, bounds.top, |
87 bounds.right + width_padding, | 86 bounds.right + width_padding, |
88 bounds.bottom + height_padding); | 87 bounds.bottom + height_padding); |
89 bbitmap = new BBitmap (bounds, B_BITMAP_WILL_OVERLAY, cs); | 88 bbitmap = new BBitmap(bounds, B_BITMAP_WILL_OVERLAY, cs); |
90 if (!bbitmap || bbitmap->InitCheck () != B_OK) { | 89 if (!bbitmap || bbitmap->InitCheck() != B_OK) { |
91 fprintf (stderr, "GetOverlayBitmap failed late\n"); | 90 fprintf(stderr, "GetOverlayBitmap failed late\n"); |
92 delete bbitmap; | 91 delete bbitmap; |
93 return 0; | 92 return 0; |
94 } | 93 } |
95 } | 94 } |
96 return bbitmap; | 95 return bbitmap; |
97 } | 96 } |
98 | 97 |
99 // See <GraphicsDefs.h> [btw: Cb=U, Cr=V] | 98 // See <GraphicsDefs.h> [btw: Cb=U, Cr=V] |
100 // See also http://www.fourcc.org/indexyuv.htm | 99 // See also http://www.fourcc.org/indexyuv.htm |
101 enum color_space convert_color_space (Uint32 format) | 100 enum color_space convert_color_space(Uint32 format) |
102 { | 101 { |
103 switch (format) { | 102 switch (format) { |
104 case SDL_YV12_OVERLAY: | 103 case SDL_YV12_OVERLAY: |
105 return B_YUV9; | 104 return B_YUV9; |
106 case SDL_IYUV_OVERLAY: | 105 case SDL_IYUV_OVERLAY: |
115 return B_NO_COLOR_SPACE; | 114 return B_NO_COLOR_SPACE; |
116 } | 115 } |
117 } | 116 } |
118 | 117 |
119 // See SDL_video.h | 118 // See SDL_video.h |
120 int count_planes (Uint32 format) | 119 int count_planes(Uint32 format) |
121 { | 120 { |
122 switch (format) { | 121 switch (format) { |
123 case SDL_YV12_OVERLAY: | 122 case SDL_YV12_OVERLAY: |
124 case SDL_IYUV_OVERLAY: | 123 case SDL_IYUV_OVERLAY: |
125 return 3; | 124 return 3; |
130 default: | 129 default: |
131 return 0; | 130 return 0; |
132 } | 131 } |
133 } | 132 } |
134 | 133 |
135 SDL_Overlay *BE_CreateYUVOverlay (_THIS, int width, int height, | 134 SDL_Overlay *BE_CreateYUVOverlay(_THIS, int width, int height, |
136 Uint32 format, SDL_Surface * display) | 135 Uint32 format, SDL_Surface * display) |
137 { | 136 { |
138 SDL_Overlay *overlay; | 137 SDL_Overlay *overlay; |
139 struct private_yuvhwdata *hwdata; | 138 struct private_yuvhwdata *hwdata; |
140 BBitmap *bbitmap; | 139 BBitmap *bbitmap; |
141 int planes; | 140 int planes; |
142 BRect bounds; | 141 BRect bounds; |
143 color_space cs; | 142 color_space cs; |
144 | 143 |
145 /* find the appropriate BeOS colorspace descriptor */ | 144 /* find the appropriate BeOS colorspace descriptor */ |
146 cs = convert_color_space (format); | 145 cs = convert_color_space(format); |
147 if (cs == B_NO_COLOR_SPACE) { | 146 if (cs == B_NO_COLOR_SPACE) { |
148 return NULL; | 147 return NULL; |
149 } | 148 } |
150 | 149 |
151 /* count planes */ | 150 /* count planes */ |
152 planes = count_planes (format); | 151 planes = count_planes(format); |
153 if (planes == 0) { | 152 if (planes == 0) { |
154 return NULL; | 153 return NULL; |
155 } | 154 } |
156 /* TODO: figure out planar modes, if anyone cares */ | 155 /* TODO: figure out planar modes, if anyone cares */ |
157 if (planes == 3) { | 156 if (planes == 3) { |
158 return NULL; | 157 return NULL; |
159 } | 158 } |
160 | 159 |
161 /* Create the overlay structure */ | 160 /* Create the overlay structure */ |
162 overlay = (SDL_Overlay *) SDL_calloc (1, sizeof (SDL_Overlay)); | 161 overlay = (SDL_Overlay *) SDL_calloc(1, sizeof(SDL_Overlay)); |
163 | 162 |
164 if (overlay == NULL) { | 163 if (overlay == NULL) { |
165 SDL_OutOfMemory (); | 164 SDL_OutOfMemory(); |
166 return NULL; | 165 return NULL; |
167 } | 166 } |
168 | 167 |
169 /* Fill in the basic members */ | 168 /* Fill in the basic members */ |
170 overlay->format = format; | 169 overlay->format = format; |
175 /* Set up the YUV surface function structure */ | 174 /* Set up the YUV surface function structure */ |
176 overlay->hwfuncs = &be_yuvfuncs; | 175 overlay->hwfuncs = &be_yuvfuncs; |
177 | 176 |
178 /* Create the pixel data and lookup tables */ | 177 /* Create the pixel data and lookup tables */ |
179 hwdata = | 178 hwdata = |
180 (struct private_yuvhwdata *) SDL_calloc (1, | 179 (struct private_yuvhwdata *) SDL_calloc(1, |
181 sizeof (struct | 180 sizeof(struct |
182 private_yuvhwdata)); | 181 private_yuvhwdata)); |
183 | 182 |
184 if (hwdata == NULL) { | 183 if (hwdata == NULL) { |
185 SDL_OutOfMemory (); | 184 SDL_OutOfMemory(); |
186 SDL_FreeYUVOverlay (overlay); | 185 SDL_FreeYUVOverlay(overlay); |
187 return NULL; | 186 return NULL; |
188 } | 187 } |
189 | 188 |
190 overlay->hwdata = hwdata; | 189 overlay->hwdata = hwdata; |
191 overlay->hwdata->display = display; | 190 overlay->hwdata->display = display; |
198 bounds.left = 0; | 197 bounds.left = 0; |
199 bounds.right = width - 1; | 198 bounds.right = width - 1; |
200 bounds.bottom = height - 1; | 199 bounds.bottom = height - 1; |
201 | 200 |
202 BView *bview = | 201 BView *bview = |
203 new BView (bounds, "overlay", B_FOLLOW_NONE, B_WILL_DRAW); | 202 new BView(bounds, "overlay", B_FOLLOW_NONE, B_WILL_DRAW); |
204 if (!bview) { | 203 if (!bview) { |
205 SDL_OutOfMemory (); | 204 SDL_OutOfMemory(); |
206 SDL_FreeYUVOverlay (overlay); | 205 SDL_FreeYUVOverlay(overlay); |
207 return NULL; | 206 return NULL; |
208 } | 207 } |
209 overlay->hwdata->bview = bview; | 208 overlay->hwdata->bview = bview; |
210 overlay->hwdata->first_display = true; | 209 overlay->hwdata->first_display = true; |
211 bview->Hide (); | 210 bview->Hide(); |
212 | 211 |
213 bbitmap = BE_GetOverlayBitmap (bounds, cs); | 212 bbitmap = BE_GetOverlayBitmap(bounds, cs); |
214 if (!bbitmap) { | 213 if (!bbitmap) { |
215 overlay->hwdata->bbitmap = NULL; | 214 overlay->hwdata->bbitmap = NULL; |
216 SDL_FreeYUVOverlay (overlay); | 215 SDL_FreeYUVOverlay(overlay); |
217 return NULL; | 216 return NULL; |
218 } | 217 } |
219 overlay->hwdata->bbitmap = bbitmap; | 218 overlay->hwdata->bbitmap = bbitmap; |
220 | 219 |
221 overlay->planes = planes; | 220 overlay->planes = planes; |
222 overlay->pitches = | 221 overlay->pitches = |
223 (Uint16 *) SDL_calloc (overlay->planes, sizeof (Uint16)); | 222 (Uint16 *) SDL_calloc(overlay->planes, sizeof(Uint16)); |
224 overlay->pixels = | 223 overlay->pixels = |
225 (Uint8 **) SDL_calloc (overlay->planes, sizeof (Uint8 *)); | 224 (Uint8 **) SDL_calloc(overlay->planes, sizeof(Uint8 *)); |
226 if (!overlay->pitches || !overlay->pixels) { | 225 if (!overlay->pitches || !overlay->pixels) { |
227 SDL_OutOfMemory (); | 226 SDL_OutOfMemory(); |
228 SDL_FreeYUVOverlay (overlay); | 227 SDL_FreeYUVOverlay(overlay); |
229 return (NULL); | 228 return (NULL); |
230 } | 229 } |
231 | 230 |
232 overlay->pitches[0] = bbitmap->BytesPerRow (); | 231 overlay->pitches[0] = bbitmap->BytesPerRow(); |
233 overlay->pixels[0] = (Uint8 *) bbitmap->Bits (); | 232 overlay->pixels[0] = (Uint8 *) bbitmap->Bits(); |
234 overlay->hw_overlay = 1; | 233 overlay->hw_overlay = 1; |
235 | 234 |
236 if (SDL_Win->LockWithTimeout (1000000) != B_OK) { | 235 if (SDL_Win->LockWithTimeout(1000000) != B_OK) { |
237 SDL_FreeYUVOverlay (overlay); | 236 SDL_FreeYUVOverlay(overlay); |
238 return (NULL); | 237 return (NULL); |
239 } | 238 } |
240 BView *view = SDL_Win->View (); | 239 BView *view = SDL_Win->View(); |
241 view->AddChild (bview); | 240 view->AddChild(bview); |
242 rgb_color key; | 241 rgb_color key; |
243 bview->SetViewOverlay (bbitmap, bounds, bview->Bounds (), &key, | 242 bview->SetViewOverlay(bbitmap, bounds, bview->Bounds(), &key, |
244 B_FOLLOW_ALL, | 243 B_FOLLOW_ALL, |
245 B_OVERLAY_FILTER_HORIZONTAL | | 244 B_OVERLAY_FILTER_HORIZONTAL | |
246 B_OVERLAY_FILTER_VERTICAL); | 245 B_OVERLAY_FILTER_VERTICAL); |
247 bview->SetViewColor (key); | 246 bview->SetViewColor(key); |
248 bview->Flush (); | 247 bview->Flush(); |
249 SDL_Win->Unlock (); | 248 SDL_Win->Unlock(); |
250 | 249 |
251 current_overlay = overlay; | 250 current_overlay = overlay; |
252 | 251 |
253 return overlay; | 252 return overlay; |
254 } | 253 } |
255 | 254 |
256 int BE_LockYUVOverlay (_THIS, SDL_Overlay * overlay) | 255 int BE_LockYUVOverlay(_THIS, SDL_Overlay * overlay) |
257 { | 256 { |
258 if (overlay == NULL) { | 257 if (overlay == NULL) { |
259 return 0; | 258 return 0; |
260 } | 259 } |
261 | 260 |
262 overlay->hwdata->locked = 1; | 261 overlay->hwdata->locked = 1; |
263 return 0; | 262 return 0; |
264 } | 263 } |
265 | 264 |
266 void BE_UnlockYUVOverlay (_THIS, SDL_Overlay * overlay) | 265 void BE_UnlockYUVOverlay(_THIS, SDL_Overlay * overlay) |
267 { | 266 { |
268 if (overlay == NULL) { | 267 if (overlay == NULL) { |
269 return; | 268 return; |
270 } | 269 } |
271 | 270 |
272 overlay->hwdata->locked = 0; | 271 overlay->hwdata->locked = 0; |
273 } | 272 } |
274 | 273 |
275 int BE_DisplayYUVOverlay (_THIS, SDL_Overlay * overlay, SDL_Rect * src, | 274 int BE_DisplayYUVOverlay(_THIS, SDL_Overlay * overlay, SDL_Rect * src, |
276 SDL_Rect * dst) | 275 SDL_Rect * dst) |
277 { | 276 { |
278 if ((overlay == NULL) || (overlay->hwdata == NULL) | 277 if ((overlay == NULL) || (overlay->hwdata == NULL) |
279 || (overlay->hwdata->bview == NULL) || (SDL_Win->View () == NULL)) { | 278 || (overlay->hwdata->bview == NULL) || (SDL_Win->View() == NULL)) { |
280 return -1; | 279 return -1; |
281 } | 280 } |
282 if (SDL_Win->LockWithTimeout (50000) != B_OK) { | 281 if (SDL_Win->LockWithTimeout(50000) != B_OK) { |
283 return 0; | 282 return 0; |
284 } | 283 } |
285 BView *bview = overlay->hwdata->bview; | 284 BView *bview = overlay->hwdata->bview; |
286 if (SDL_Win->IsFullScreen ()) { | 285 if (SDL_Win->IsFullScreen()) { |
287 int left, top; | 286 int left, top; |
288 SDL_Win->GetXYOffset (left, top); | 287 SDL_Win->GetXYOffset(left, top); |
289 bview->MoveTo (left + dst->x, top + dst->y); | 288 bview->MoveTo(left + dst->x, top + dst->y); |
290 } else { | 289 } else { |
291 bview->MoveTo (dst->x, dst->y); | 290 bview->MoveTo(dst->x, dst->y); |
292 } | 291 } |
293 bview->ResizeTo (dst->w, dst->h); | 292 bview->ResizeTo(dst->w, dst->h); |
294 bview->Flush (); | 293 bview->Flush(); |
295 if (overlay->hwdata->first_display) { | 294 if (overlay->hwdata->first_display) { |
296 bview->Show (); | 295 bview->Show(); |
297 overlay->hwdata->first_display = false; | 296 overlay->hwdata->first_display = false; |
298 } | 297 } |
299 SDL_Win->Unlock (); | 298 SDL_Win->Unlock(); |
300 | 299 |
301 return 0; | 300 return 0; |
302 } | 301 } |
303 | 302 |
304 void BE_FreeYUVOverlay (_THIS, SDL_Overlay * overlay) | 303 void BE_FreeYUVOverlay(_THIS, SDL_Overlay * overlay) |
305 { | 304 { |
306 if (overlay == NULL) { | 305 if (overlay == NULL) { |
307 return; | 306 return; |
308 } | 307 } |
309 | 308 |
313 | 312 |
314 current_overlay = NULL; | 313 current_overlay = NULL; |
315 | 314 |
316 delete overlay->hwdata->bbitmap; | 315 delete overlay->hwdata->bbitmap; |
317 | 316 |
318 SDL_free (overlay->hwdata); | 317 SDL_free(overlay->hwdata); |
319 } | 318 } |
320 | 319 |
321 }; // extern "C" | 320 }; // extern "C" |
322 | 321 |
323 /* vi: set ts=4 sw=4 expandtab: */ | 322 /* vi: set ts=4 sw=4 expandtab: */ |