]> git.sesse.net Git - vlc/blob - src/video_output/vout_pictures.c
Install new required files for skins2 on make install
[vlc] / src / video_output / vout_pictures.c
1 /*****************************************************************************
2  * vout_pictures.c : picture management functions
3  *****************************************************************************
4  * Copyright (C) 2000-2004 VideoLAN
5  * $Id: vout_pictures.c,v 1.47 2004/02/27 14:01:35 fenrir Exp $
6  *
7  * Authors: Vincent Seguin <seguin@via.ecp.fr>
8  *          Samuel Hocevar <sam@zoy.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <stdlib.h>                                                /* free() */
29 #include <stdio.h>                                              /* sprintf() */
30 #include <string.h>                                            /* strerror() */
31
32 #include <vlc/vlc.h>
33
34 #include "vlc_video.h"
35 #include "video_output.h"
36
37 #include "vout_pictures.h"
38
39 /*****************************************************************************
40  * Local prototypes
41  *****************************************************************************/
42 static void CopyPicture( vout_thread_t *, picture_t *, picture_t * );
43
44 /*****************************************************************************
45  * vout_DisplayPicture: display a picture
46  *****************************************************************************
47  * Remove the reservation flag of a picture, which will cause it to be ready
48  * for display. The picture won't be displayed until vout_DatePicture has been
49  * called.
50  *****************************************************************************/
51 void vout_DisplayPicture( vout_thread_t *p_vout, picture_t *p_pic )
52 {
53     vlc_mutex_lock( &p_vout->picture_lock );
54     switch( p_pic->i_status )
55     {
56     case RESERVED_PICTURE:
57         p_pic->i_status = RESERVED_DISP_PICTURE;
58         break;
59     case RESERVED_DATED_PICTURE:
60         p_pic->i_status = READY_PICTURE;
61         break;
62     default:
63         msg_Err( p_vout, "picture to display %p has invalid status %d",
64                          p_pic, p_pic->i_status );
65         break;
66     }
67
68     vlc_mutex_unlock( &p_vout->picture_lock );
69 }
70
71 /*****************************************************************************
72  * vout_DatePicture: date a picture
73  *****************************************************************************
74  * Remove the reservation flag of a picture, which will cause it to be ready
75  * for display. The picture won't be displayed until vout_DisplayPicture has
76  * been called.
77  *****************************************************************************/
78 void vout_DatePicture( vout_thread_t *p_vout,
79                        picture_t *p_pic, mtime_t date )
80 {
81     vlc_mutex_lock( &p_vout->picture_lock );
82     p_pic->date = date;
83     switch( p_pic->i_status )
84     {
85     case RESERVED_PICTURE:
86         p_pic->i_status = RESERVED_DATED_PICTURE;
87         break;
88     case RESERVED_DISP_PICTURE:
89         p_pic->i_status = READY_PICTURE;
90         break;
91     default:
92         msg_Err( p_vout, "picture to date %p has invalid status %d",
93                          p_pic, p_pic->i_status );
94         break;
95     }
96
97     vlc_mutex_unlock( &p_vout->picture_lock );
98 }
99
100 /*****************************************************************************
101  * vout_CreatePicture: allocate a picture in the video output heap.
102  *****************************************************************************
103  * This function creates a reserved image in the video output heap.
104  * A null pointer is returned if the function fails. This method provides an
105  * already allocated zone of memory in the picture data fields.
106  * It needs locking since several pictures can be created by several producers
107  * threads.
108  *****************************************************************************/
109 picture_t *vout_CreatePicture( vout_thread_t *p_vout,
110                                vlc_bool_t b_progressive,
111                                vlc_bool_t b_top_field_first,
112                                unsigned int i_nb_fields )
113 {
114     int         i_pic;                                      /* picture index */
115     picture_t * p_pic;
116     picture_t * p_freepic = NULL;                      /* first free picture */
117
118     /* Get lock */
119     vlc_mutex_lock( &p_vout->picture_lock );
120
121     /*
122      * Look for an empty place in the picture heap.
123      */
124     for( i_pic = 0; i_pic < I_RENDERPICTURES; i_pic++ )
125     {
126         p_pic = PP_RENDERPICTURE[(p_vout->render.i_last_used_pic + i_pic + 1)
127                                  % I_RENDERPICTURES];
128
129         switch( p_pic->i_status )
130         {
131             case DESTROYED_PICTURE:
132                 /* Memory will not be reallocated, and function can end
133                  * immediately - this is the best possible case, since no
134                  * memory allocation needs to be done */
135                 p_pic->i_status   = RESERVED_PICTURE;
136                 p_pic->i_refcount = 0;
137                 p_pic->b_force    = 0;
138
139                 p_pic->b_progressive        = b_progressive;
140                 p_pic->i_nb_fields          = i_nb_fields;
141                 p_pic->b_top_field_first    = b_top_field_first;
142
143                 p_vout->i_heap_size++;
144                 p_vout->render.i_last_used_pic =
145                     ( p_vout->render.i_last_used_pic + i_pic + 1 )
146                     % I_RENDERPICTURES;
147                 vlc_mutex_unlock( &p_vout->picture_lock );
148                 return( p_pic );
149
150             case FREE_PICTURE:
151                 /* Picture is empty and ready for allocation */
152                 p_vout->render.i_last_used_pic =
153                     ( p_vout->render.i_last_used_pic + i_pic + 1 )
154                     % I_RENDERPICTURES;
155                 p_freepic = p_pic;
156                 break;
157
158             default:
159                 break;
160         }
161     }
162
163     /*
164      * Prepare picture
165      */
166     if( p_freepic != NULL )
167     {
168         vout_AllocatePicture( VLC_OBJECT(p_vout),
169                               p_freepic, p_vout->render.i_chroma,
170                               p_vout->render.i_width, p_vout->render.i_height,
171                               p_vout->render.i_aspect );
172
173         if( p_freepic->i_planes )
174         {
175             /* Copy picture information, set some default values */
176             p_freepic->i_status   = RESERVED_PICTURE;
177             p_freepic->i_type     = MEMORY_PICTURE;
178
179             p_freepic->i_refcount = 0;
180             p_freepic->b_force = 0;
181
182             p_freepic->b_progressive        = b_progressive;
183             p_freepic->i_nb_fields          = i_nb_fields;
184             p_freepic->b_top_field_first    = b_top_field_first;
185
186             p_freepic->i_matrix_coefficients = 1;
187
188             p_vout->i_heap_size++;
189         }
190         else
191         {
192             /* Memory allocation failed : set picture as empty */
193             p_freepic->i_status = FREE_PICTURE;
194             p_freepic = NULL;
195
196             msg_Err( p_vout, "picture allocation failed" );
197         }
198
199         vlc_mutex_unlock( &p_vout->picture_lock );
200
201         return( p_freepic );
202     }
203
204     /* No free or destroyed picture could be found, but the decoder
205      * will try again in a while. */
206     vlc_mutex_unlock( &p_vout->picture_lock );
207
208     return( NULL );
209 }
210
211 /*****************************************************************************
212  * vout_DestroyPicture: remove a permanent or reserved picture from the heap
213  *****************************************************************************
214  * This function frees a previously reserved picture or a permanent
215  * picture. It is meant to be used when the construction of a picture aborted.
216  * Note that the picture will be destroyed even if it is linked !
217  *****************************************************************************/
218 void vout_DestroyPicture( vout_thread_t *p_vout, picture_t *p_pic )
219 {
220     vlc_mutex_lock( &p_vout->picture_lock );
221
222 #ifdef DEBUG
223     /* Check if picture status is valid */
224     if( (p_pic->i_status != RESERVED_PICTURE) &&
225         (p_pic->i_status != RESERVED_DATED_PICTURE) &&
226         (p_pic->i_status != RESERVED_DISP_PICTURE) )
227     {
228         msg_Err( p_vout, "picture to destroy %p has invalid status %d",
229                          p_pic, p_pic->i_status );
230     }
231 #endif
232
233     p_pic->i_status = DESTROYED_PICTURE;
234     p_vout->i_heap_size--;
235
236     vlc_mutex_unlock( &p_vout->picture_lock );
237 }
238
239 /*****************************************************************************
240  * vout_LinkPicture: increment reference counter of a picture
241  *****************************************************************************
242  * This function increments the reference counter of a picture in the video
243  * heap. It needs a lock since several producer threads can access the picture.
244  *****************************************************************************/
245 void vout_LinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
246 {
247     vlc_mutex_lock( &p_vout->picture_lock );
248     p_pic->i_refcount++;
249     vlc_mutex_unlock( &p_vout->picture_lock );
250 }
251
252 /*****************************************************************************
253  * vout_UnlinkPicture: decrement reference counter of a picture
254  *****************************************************************************
255  * This function decrement the reference counter of a picture in the video heap
256  *****************************************************************************/
257 void vout_UnlinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
258 {
259     vlc_mutex_lock( &p_vout->picture_lock );
260     p_pic->i_refcount--;
261
262     if( p_pic->i_refcount < 0 )
263     {
264         msg_Err( p_vout, "picture %p refcount is %i",
265                  p_pic, p_pic->i_refcount );
266         p_pic->i_refcount = 0;
267     }
268
269     if( ( p_pic->i_refcount == 0 ) &&
270         ( p_pic->i_status == DISPLAYED_PICTURE ) )
271     {
272         p_pic->i_status = DESTROYED_PICTURE;
273         p_vout->i_heap_size--;
274     }
275
276     vlc_mutex_unlock( &p_vout->picture_lock );
277 }
278
279 /*****************************************************************************
280  * vout_RenderPicture: render a picture
281  *****************************************************************************
282  * This function chooses whether the current picture needs to be copied
283  * before rendering, does the subpicture magic, and tells the video output
284  * thread which direct buffer needs to be displayed.
285  *****************************************************************************/
286 picture_t * vout_RenderPicture( vout_thread_t *p_vout, picture_t *p_pic,
287                                                        subpicture_t *p_subpic )
288 {
289     if( p_pic == NULL )
290     {
291         /* XXX: subtitles */
292
293         return NULL;
294     }
295
296     if( p_pic->i_type == DIRECT_PICTURE )
297     {
298         if( !p_vout->render.b_allow_modify_pics || p_pic->i_refcount )
299         {
300             /* Picture is in a direct buffer and is still in use,
301              * we need to copy it to another direct buffer before
302              * displaying it if there are subtitles. */
303             if( p_subpic != NULL )
304             {
305                 /* We have subtitles. First copy the picture to
306                  * the spare direct buffer, then render the
307                  * subtitles. */
308                 CopyPicture( p_vout, p_pic, PP_OUTPUTPICTURE[0] );
309
310                 vout_RenderSubPictures( p_vout, PP_OUTPUTPICTURE[0], p_subpic );
311
312                 return PP_OUTPUTPICTURE[0];
313             }
314
315             /* No subtitles, picture is in a directbuffer so
316              * we can display it directly even if it is still
317              * in use. */
318             return p_pic;
319         }
320
321         /* Picture is in a direct buffer but isn't used by the
322          * decoder. We can safely render subtitles on it and
323          * display it. */
324         vout_RenderSubPictures( p_vout, p_pic, p_subpic );
325
326         return p_pic;
327     }
328
329     /* Not a direct buffer. We either need to copy it to a direct buffer,
330      * or render it if the chroma isn't the same. */
331     if( p_vout->b_direct )
332     {
333         /* Picture is not in a direct buffer, but is exactly the
334          * same size as the direct buffers. A memcpy() is enough,
335          * then render the subtitles. */
336
337         if( PP_OUTPUTPICTURE[0]->pf_lock )
338             if( PP_OUTPUTPICTURE[0]->pf_lock( p_vout, PP_OUTPUTPICTURE[0] ) )
339             {
340                 if( PP_OUTPUTPICTURE[0]->pf_unlock )
341                 PP_OUTPUTPICTURE[0]->pf_unlock( p_vout, PP_OUTPUTPICTURE[0] );
342
343                 return NULL;
344             }
345
346         CopyPicture( p_vout, p_pic, PP_OUTPUTPICTURE[0] );
347
348         vout_RenderSubPictures( p_vout, PP_OUTPUTPICTURE[0], p_subpic );
349
350         if( PP_OUTPUTPICTURE[0]->pf_unlock )
351             PP_OUTPUTPICTURE[0]->pf_unlock( p_vout, PP_OUTPUTPICTURE[0] );
352
353         return PP_OUTPUTPICTURE[0];
354     }
355
356     /* Picture is not in a direct buffer, and needs to be converted to
357      * another size/chroma. Then the subtitles need to be rendered as
358      * well. This usually means software YUV, or hardware YUV with a
359      * different chroma. */
360
361     if( p_vout->p_picture[0].pf_lock )
362         if( p_vout->p_picture[0].pf_lock( p_vout, &p_vout->p_picture[0] ) )
363             return NULL;
364
365     /* Convert image to the first direct buffer */
366     p_vout->chroma.pf_convert( p_vout, p_pic, &p_vout->p_picture[0] );
367
368     /* Render subpictures on the first direct buffer */
369     vout_RenderSubPictures( p_vout, &p_vout->p_picture[0], p_subpic );
370
371     if( p_vout->p_picture[0].pf_unlock )
372         p_vout->p_picture[0].pf_unlock( p_vout, &p_vout->p_picture[0] );
373
374     return &p_vout->p_picture[0];
375 }
376
377 /*****************************************************************************
378  * vout_PlacePicture: calculate image window coordinates
379  *****************************************************************************
380  * This function will be accessed by plugins. It calculates the relative
381  * position of the output window and the image window.
382  *****************************************************************************/
383 void vout_PlacePicture( vout_thread_t *p_vout,
384                         unsigned int i_width, unsigned int i_height,
385                         unsigned int *pi_x, unsigned int *pi_y,
386                         unsigned int *pi_width, unsigned int *pi_height )
387 {
388     if( (i_width <= 0) || (i_height <=0) )
389     {
390         *pi_width = *pi_height = *pi_x = *pi_y = 0;
391
392         return;
393     }
394
395     if( p_vout->b_scale )
396     {
397         *pi_width = i_width;
398         *pi_height = i_height;
399     }
400     else
401     {
402         *pi_width = __MIN( i_width, p_vout->render.i_width );
403         *pi_height = __MIN( i_height, p_vout->render.i_height );
404     }
405
406     if( VOUT_ASPECT_FACTOR * *pi_width / *pi_height < p_vout->render.i_aspect )
407     {
408         *pi_width = *pi_height * p_vout->render.i_aspect / VOUT_ASPECT_FACTOR;
409     }
410     else
411     {
412         *pi_height = *pi_width * VOUT_ASPECT_FACTOR / p_vout->render.i_aspect;
413     }
414
415     if( *pi_width > i_width )
416     {
417         *pi_width = i_width;
418         *pi_height = VOUT_ASPECT_FACTOR * *pi_width / p_vout->render.i_aspect;
419     }
420
421     if( *pi_height > i_height )
422     {
423         *pi_height = i_height;
424         *pi_width = *pi_height * p_vout->render.i_aspect / VOUT_ASPECT_FACTOR;
425     }
426
427     switch( p_vout->i_alignment & VOUT_ALIGN_HMASK )
428     {
429     case VOUT_ALIGN_LEFT:
430         *pi_x = 0;
431         break;
432     case VOUT_ALIGN_RIGHT:
433         *pi_x = i_width - *pi_width;
434         break;
435     default:
436         *pi_x = ( i_width - *pi_width ) / 2;
437     }
438
439     switch( p_vout->i_alignment & VOUT_ALIGN_VMASK )
440     {
441     case VOUT_ALIGN_TOP:
442         *pi_y = 0;
443         break;
444     case VOUT_ALIGN_BOTTOM:
445         *pi_y = i_height - *pi_height;
446         break;
447     default:
448         *pi_y = ( i_height - *pi_height ) / 2;
449     }
450 }
451
452 /*****************************************************************************
453  * vout_AllocatePicture: allocate a new picture in the heap.
454  *****************************************************************************
455  * This function allocates a fake direct buffer in memory, which can be
456  * used exactly like a video buffer. The video output thread then manages
457  * how it gets displayed.
458  *****************************************************************************/
459 void vout_AllocatePicture( vlc_object_t *p_this, picture_t *p_pic,
460                            vlc_fourcc_t i_chroma,
461                            int i_width, int i_height, int i_aspect )
462 {
463     int i_bytes, i_index;
464
465     vout_InitPicture( p_this, p_pic, i_chroma,
466                       i_width, i_height, i_aspect );
467
468     /* Calculate how big the new image should be */
469     i_bytes = p_pic->format.i_bits_per_pixel *
470         p_pic->format.i_width * p_pic->format.i_height / 8;
471
472     p_pic->p_data = vlc_memalign( &p_pic->p_data_orig, 16, i_bytes );
473
474     if( p_pic->p_data == NULL )
475     {
476         p_pic->i_planes = 0;
477         return;
478     }
479
480     /* Fill the p_pixels field for each plane */
481     p_pic->p[ 0 ].p_pixels = p_pic->p_data;
482
483     for( i_index = 1; i_index < p_pic->i_planes; i_index++ )
484     {
485         p_pic->p[i_index].p_pixels = p_pic->p[i_index-1].p_pixels
486                                           + p_pic->p[i_index-1].i_lines
487                                              * p_pic->p[i_index-1].i_pitch;
488     }
489 }
490
491 /*****************************************************************************
492  * vout_InitFormat: initialise the video format fields given chroma/size.
493  *****************************************************************************
494  * This function initializes all the video_frame_format_t fields given the
495  * static properties of a picture (chroma and size).
496  *****************************************************************************/
497 void vout_InitFormat( video_frame_format_t *p_format, vlc_fourcc_t i_chroma,
498                       int i_width, int i_height, int i_aspect )
499 {
500     p_format->i_chroma   = i_chroma;
501     p_format->i_width    = p_format->i_visible_width  = i_width;
502     p_format->i_height   = p_format->i_visible_height = i_height;
503     p_format->i_x_offset = p_format->i_y_offset = 0;
504     p_format->i_aspect   = i_aspect;
505
506 #if 0
507     /* Assume we have square pixels */
508     if( i_width && i_height )
509         p_format->i_aspect = i_width * VOUT_ASPECT_FACTOR / i_height;
510     else
511         p_format->i_aspect = 0;
512 #endif
513
514     switch( i_chroma )
515     {
516         case FOURCC_I444:
517             p_format->i_bits_per_pixel = 24;
518             break;
519         case FOURCC_I422:
520         case FOURCC_YUY2:
521             p_format->i_bits_per_pixel = 16;
522             p_format->i_bits_per_pixel = 16;
523             break;
524         case FOURCC_I411:
525         case FOURCC_YV12:
526         case FOURCC_I420:
527         case FOURCC_IYUV:
528             p_format->i_bits_per_pixel = 12;
529             break;
530         case FOURCC_I410:
531         case FOURCC_YVU9:
532             p_format->i_bits_per_pixel = 9;
533             break;
534         case FOURCC_Y211:
535             p_format->i_bits_per_pixel = 8;
536             break;
537         case FOURCC_RV32:
538             p_format->i_bits_per_pixel = 32;
539             break;
540         case FOURCC_RV24:
541             /* FIXME: Should be 24 here but x11 and our chroma conversion
542              * routines assume 32. */
543 #ifdef WIN32
544             p_format->i_bits_per_pixel = 24;
545 #else
546             p_format->i_bits_per_pixel = 32;
547 #endif
548             break;
549         case FOURCC_RV15:
550         case FOURCC_RV16:
551             p_format->i_bits_per_pixel = 16;
552             break;
553         case FOURCC_RGB2:
554             p_format->i_bits_per_pixel = 8;
555             break;
556         default:
557             p_format->i_bits_per_pixel = 0;
558             break;
559     }
560 }
561
562 /*****************************************************************************
563  * vout_InitPicture: initialise the picture_t fields given chroma/size.
564  *****************************************************************************
565  * This function initializes most of the picture_t fields given a chroma and
566  * size. It makes the assumption that stride == width.
567  *****************************************************************************/
568 void vout_InitPicture( vlc_object_t *p_this, picture_t *p_pic,
569                        vlc_fourcc_t i_chroma,
570                        int i_width, int i_height, int i_aspect )
571 {
572     int i_index;
573
574     /* Store default values */
575     for( i_index = 0; i_index < VOUT_MAX_PLANES; i_index++ )
576     {
577         p_pic->p[i_index].p_pixels = NULL;
578         p_pic->p[i_index].i_pixel_pitch = 1;
579     }
580
581     vout_InitFormat( &p_pic->format, i_chroma, i_width, i_height, i_aspect );
582
583     /* Calculate coordinates */
584     switch( i_chroma )
585     {
586         case FOURCC_I411:
587             p_pic->p[ Y_PLANE ].i_lines = i_height;
588             p_pic->p[ Y_PLANE ].i_pitch = i_width;
589             p_pic->p[ Y_PLANE ].i_visible_pitch = p_pic->p[ Y_PLANE ].i_pitch;
590             p_pic->p[ U_PLANE ].i_lines = i_height;
591             p_pic->p[ U_PLANE ].i_pitch = i_width / 4;
592             p_pic->p[ U_PLANE ].i_visible_pitch = p_pic->p[ U_PLANE ].i_pitch;
593             p_pic->p[ V_PLANE ].i_lines = i_height;
594             p_pic->p[ V_PLANE ].i_pitch = i_width / 4;
595             p_pic->p[ V_PLANE ].i_visible_pitch = p_pic->p[ V_PLANE ].i_pitch;
596             p_pic->i_planes = 3;
597             break;
598
599         case FOURCC_I410:
600         case FOURCC_YVU9:
601             p_pic->p[ Y_PLANE ].i_lines = i_height;
602             p_pic->p[ Y_PLANE ].i_pitch = i_width;
603             p_pic->p[ Y_PLANE ].i_visible_pitch = p_pic->p[ Y_PLANE ].i_pitch;
604             p_pic->p[ U_PLANE ].i_lines = i_height / 4;
605             p_pic->p[ U_PLANE ].i_pitch = i_width / 4;
606             p_pic->p[ U_PLANE ].i_visible_pitch = p_pic->p[ U_PLANE ].i_pitch;
607             p_pic->p[ V_PLANE ].i_lines = i_height / 4;
608             p_pic->p[ V_PLANE ].i_pitch = i_width / 4;
609             p_pic->p[ V_PLANE ].i_visible_pitch = p_pic->p[ V_PLANE ].i_pitch;
610             p_pic->i_planes = 3;
611             break;
612
613         case FOURCC_YV12:
614         case FOURCC_I420:
615         case FOURCC_IYUV:
616             p_pic->p[ Y_PLANE ].i_lines = i_height;
617             p_pic->p[ Y_PLANE ].i_pitch = i_width;
618             p_pic->p[ Y_PLANE ].i_visible_pitch = p_pic->p[ Y_PLANE ].i_pitch;
619             p_pic->p[ U_PLANE ].i_lines = i_height / 2;
620             p_pic->p[ U_PLANE ].i_pitch = i_width / 2;
621             p_pic->p[ U_PLANE ].i_visible_pitch = p_pic->p[ U_PLANE ].i_pitch;
622             p_pic->p[ V_PLANE ].i_lines = i_height / 2;
623             p_pic->p[ V_PLANE ].i_pitch = i_width / 2;
624             p_pic->p[ V_PLANE ].i_visible_pitch = p_pic->p[ V_PLANE ].i_pitch;
625             p_pic->i_planes = 3;
626             break;
627
628         case FOURCC_I422:
629             p_pic->p[ Y_PLANE ].i_lines = i_height;
630             p_pic->p[ Y_PLANE ].i_pitch = i_width;
631             p_pic->p[ Y_PLANE ].i_visible_pitch = p_pic->p[ Y_PLANE ].i_pitch;
632             p_pic->p[ U_PLANE ].i_lines = i_height;
633             p_pic->p[ U_PLANE ].i_pitch = i_width / 2;
634             p_pic->p[ U_PLANE ].i_visible_pitch = p_pic->p[ U_PLANE ].i_pitch;
635             p_pic->p[ V_PLANE ].i_lines = i_height;
636             p_pic->p[ V_PLANE ].i_pitch = i_width / 2;
637             p_pic->p[ V_PLANE ].i_visible_pitch = p_pic->p[ V_PLANE ].i_pitch;
638             p_pic->i_planes = 3;
639             break;
640
641         case FOURCC_I444:
642             p_pic->p[ Y_PLANE ].i_lines = i_height;
643             p_pic->p[ Y_PLANE ].i_pitch = i_width;
644             p_pic->p[ Y_PLANE ].i_visible_pitch = p_pic->p[ Y_PLANE ].i_pitch;
645             p_pic->p[ U_PLANE ].i_lines = i_height;
646             p_pic->p[ U_PLANE ].i_pitch = i_width;
647             p_pic->p[ U_PLANE ].i_visible_pitch = p_pic->p[ U_PLANE ].i_pitch;
648             p_pic->p[ V_PLANE ].i_lines = i_height;
649             p_pic->p[ V_PLANE ].i_pitch = i_width;
650             p_pic->p[ V_PLANE ].i_visible_pitch = p_pic->p[ V_PLANE ].i_pitch;
651             p_pic->i_planes = 3;
652             break;
653
654         case FOURCC_Y211:
655             p_pic->p->i_lines = i_height;
656             p_pic->p->i_pitch = i_width;
657             p_pic->p->i_visible_pitch = p_pic->p->i_pitch;
658             p_pic->p->i_pixel_pitch = 4;
659             p_pic->i_planes = 1;
660             break;
661
662         case FOURCC_YUY2:
663             p_pic->p->i_lines = i_height;
664             p_pic->p->i_pitch = i_width * 2;
665             p_pic->p->i_visible_pitch = p_pic->p->i_pitch;
666             p_pic->p->i_pixel_pitch = 4;
667             p_pic->i_planes = 1;
668             break;
669
670         case FOURCC_RGB2:
671             p_pic->p->i_lines = i_height;
672             p_pic->p->i_pitch = i_width;
673             p_pic->p->i_visible_pitch = p_pic->p->i_pitch;
674             p_pic->p->i_pixel_pitch = 1;
675             p_pic->i_planes = 1;
676             break;
677
678         case FOURCC_RV15:
679             p_pic->p->i_lines = i_height;
680             p_pic->p->i_pitch = i_width * 2;
681             p_pic->p->i_visible_pitch = p_pic->p->i_pitch;
682             p_pic->p->i_pixel_pitch = 2;
683 /* FIXME: p_heap isn't always reachable
684             p_pic->p_heap->i_rmask = 0x001f;
685             p_pic->p_heap->i_gmask = 0x03e0;
686             p_pic->p_heap->i_bmask = 0x7c00; */
687             p_pic->i_planes = 1;
688             break;
689
690         case FOURCC_RV16:
691             p_pic->p->i_lines = i_height;
692             p_pic->p->i_pitch = i_width * 2;
693             p_pic->p->i_visible_pitch = p_pic->p->i_pitch;
694             p_pic->p->i_pixel_pitch = 2;
695 /* FIXME: p_heap isn't always reachable
696             p_pic->p_heap->i_rmask = 0x001f;
697             p_pic->p_heap->i_gmask = 0x07e0;
698             p_pic->p_heap->i_bmask = 0xf800; */
699             p_pic->i_planes = 1;
700             break;
701
702         case FOURCC_RV24:
703             p_pic->p->i_lines = i_height;
704
705             /* FIXME: Should be 3 here but x11 and our chroma conversion
706              * routines assume 4. */
707 #ifdef WIN32
708             p_pic->p->i_pitch = i_width * 3;
709             p_pic->p->i_pixel_pitch = 3;
710 #else
711             p_pic->p->i_pitch = i_width * 4;
712             p_pic->p->i_pixel_pitch = 4;
713 #endif
714             p_pic->p->i_visible_pitch = p_pic->p->i_pitch;
715 /* FIXME: p_heap isn't always reachable
716             p_pic->p_heap->i_rmask = 0xff0000;
717             p_pic->p_heap->i_gmask = 0x00ff00;
718             p_pic->p_heap->i_bmask = 0x0000ff; */
719             p_pic->i_planes = 1;
720             break;
721
722         case FOURCC_RV32:
723             p_pic->p->i_lines = i_height;
724             p_pic->p->i_pitch = i_width * 4;
725             p_pic->p->i_visible_pitch = p_pic->p->i_pitch;
726             p_pic->p->i_pixel_pitch = 4;
727 /* FIXME: p_heap isn't always reachable
728             p_pic->p_heap->i_rmask = 0xff0000;
729             p_pic->p_heap->i_gmask = 0x00ff00;
730             p_pic->p_heap->i_bmask = 0x0000ff; */
731             p_pic->i_planes = 1;
732             break;
733
734         default:
735             msg_Err( p_this, "unknown chroma type 0x%.8x (%4.4s)",
736                              i_chroma, (char*)&i_chroma );
737             p_pic->i_planes = 0;
738             return;
739     }
740 }
741
742 /*****************************************************************************
743  * vout_ChromaCmp: compare two chroma values
744  *****************************************************************************
745  * This function returns 1 if the two fourcc values given as argument are
746  * the same format (eg. UYVY/UYNV) or almost the same format (eg. I420/YV12)
747  *****************************************************************************/
748 int vout_ChromaCmp( vlc_fourcc_t i_chroma, vlc_fourcc_t i_amorhc )
749 {
750     /* If they are the same, they are the same ! */
751     if( i_chroma == i_amorhc )
752     {
753         return 1;
754     }
755
756     /* Check for equivalence classes */
757     switch( i_chroma )
758     {
759         case FOURCC_I420:
760         case FOURCC_IYUV:
761         case FOURCC_YV12:
762             switch( i_amorhc )
763             {
764                 case FOURCC_I420:
765                 case FOURCC_IYUV:
766                 case FOURCC_YV12:
767                     return 1;
768
769                 default:
770                     return 0;
771             }
772
773         case FOURCC_UYVY:
774         case FOURCC_UYNV:
775         case FOURCC_Y422:
776             switch( i_amorhc )
777             {
778                 case FOURCC_UYVY:
779                 case FOURCC_UYNV:
780                 case FOURCC_Y422:
781                     return 1;
782
783                 default:
784                     return 0;
785             }
786
787         case FOURCC_YUY2:
788         case FOURCC_YUNV:
789             switch( i_amorhc )
790             {
791                 case FOURCC_YUY2:
792                 case FOURCC_YUNV:
793                     return 1;
794
795                 default:
796                     return 0;
797             }
798
799         default:
800             return 0;
801     }
802 }
803
804 /* Following functions are local */
805
806 /*****************************************************************************
807  * CopyPicture: copy a picture to another one
808  *****************************************************************************
809  * This function takes advantage of the image format, and reduces the
810  * number of calls to memcpy() to the minimum. Source and destination
811  * images must have same width (hence i_visible_pitch), height, and chroma.
812  *****************************************************************************/
813 static void CopyPicture( vout_thread_t * p_vout,
814                          picture_t *p_src, picture_t *p_dest )
815 {
816     int i;
817
818     for( i = 0; i < p_src->i_planes ; i++ )
819     {
820         if( p_src->p[i].i_pitch == p_dest->p[i].i_pitch )
821         {
822             /* There are margins, but with the same width : perfect ! */
823             p_vout->p_vlc->pf_memcpy(
824                          p_dest->p[i].p_pixels, p_src->p[i].p_pixels,
825                          p_src->p[i].i_pitch * p_src->p[i].i_lines );
826         }
827         else
828         {
829             /* We need to proceed line by line */
830             uint8_t *p_in = p_src->p[i].p_pixels;
831             uint8_t *p_out = p_dest->p[i].p_pixels;
832             int i_line;
833
834             for( i_line = p_src->p[i].i_lines; i_line--; )
835             {
836                 p_vout->p_vlc->pf_memcpy( p_out, p_in,
837                                           p_src->p[i].i_visible_pitch );
838                 p_in += p_src->p[i].i_pitch;
839                 p_out += p_dest->p[i].i_pitch;
840             }
841         }
842     }
843     p_dest->date = p_src->date;
844 }