1 /*****************************************************************************
2 * vout_pictures.c : picture management functions
3 *****************************************************************************
4 * Copyright (C) 2000-2004 VideoLAN
7 * Authors: Vincent Seguin <seguin@via.ecp.fr>
8 * Samuel Hocevar <sam@zoy.org>
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.
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.
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 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
28 #include <stdlib.h> /* free() */
29 #include <stdio.h> /* sprintf() */
30 #include <string.h> /* strerror() */
34 #include "vlc_video.h"
35 #include "video_output.h"
37 #include "vout_pictures.h"
39 /*****************************************************************************
41 *****************************************************************************/
42 static void CopyPicture( vout_thread_t *, picture_t *, picture_t * );
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
51 void vout_DisplayPicture( vout_thread_t *p_vout, picture_t *p_pic )
53 vlc_mutex_lock( &p_vout->picture_lock );
54 switch( p_pic->i_status )
56 case RESERVED_PICTURE:
57 p_pic->i_status = RESERVED_DISP_PICTURE;
59 case RESERVED_DATED_PICTURE:
60 p_pic->i_status = READY_PICTURE;
63 msg_Err( p_vout, "picture to display %p has invalid status %d",
64 p_pic, p_pic->i_status );
68 vlc_mutex_unlock( &p_vout->picture_lock );
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
77 * \param p_vout The vout in question
78 * \param p_pic The picture to date
79 * \param date The date to display the picture
81 void vout_DatePicture( vout_thread_t *p_vout,
82 picture_t *p_pic, mtime_t date )
84 vlc_mutex_lock( &p_vout->picture_lock );
86 switch( p_pic->i_status )
88 case RESERVED_PICTURE:
89 p_pic->i_status = RESERVED_DATED_PICTURE;
91 case RESERVED_DISP_PICTURE:
92 p_pic->i_status = READY_PICTURE;
95 msg_Err( p_vout, "picture to date %p has invalid status %d",
96 p_pic, p_pic->i_status );
100 vlc_mutex_unlock( &p_vout->picture_lock );
104 * Allocate a picture in the video output heap.
106 * This function creates a reserved image in the video output heap.
107 * A null pointer is returned if the function fails. This method provides an
108 * already allocated zone of memory in the picture data fields.
109 * It needs locking since several pictures can be created by several producers
112 picture_t *vout_CreatePicture( vout_thread_t *p_vout,
113 vlc_bool_t b_progressive,
114 vlc_bool_t b_top_field_first,
115 unsigned int i_nb_fields )
117 int i_pic; /* picture index */
119 picture_t * p_freepic = NULL; /* first free picture */
122 vlc_mutex_lock( &p_vout->picture_lock );
125 * Look for an empty place in the picture heap.
127 for( i_pic = 0; i_pic < I_RENDERPICTURES; i_pic++ )
129 p_pic = PP_RENDERPICTURE[(p_vout->render.i_last_used_pic + i_pic + 1)
132 switch( p_pic->i_status )
134 case DESTROYED_PICTURE:
135 /* Memory will not be reallocated, and function can end
136 * immediately - this is the best possible case, since no
137 * memory allocation needs to be done */
138 p_pic->i_status = RESERVED_PICTURE;
139 p_pic->i_refcount = 0;
142 p_pic->b_progressive = b_progressive;
143 p_pic->i_nb_fields = i_nb_fields;
144 p_pic->b_top_field_first = b_top_field_first;
146 p_vout->i_heap_size++;
147 p_vout->render.i_last_used_pic =
148 ( p_vout->render.i_last_used_pic + i_pic + 1 )
150 vlc_mutex_unlock( &p_vout->picture_lock );
154 /* Picture is empty and ready for allocation */
155 p_vout->render.i_last_used_pic =
156 ( p_vout->render.i_last_used_pic + i_pic + 1 )
169 if( p_freepic != NULL )
171 vout_AllocatePicture( VLC_OBJECT(p_vout),
172 p_freepic, p_vout->render.i_chroma,
173 p_vout->render.i_width, p_vout->render.i_height,
174 p_vout->render.i_aspect );
176 if( p_freepic->i_planes )
178 /* Copy picture information, set some default values */
179 p_freepic->i_status = RESERVED_PICTURE;
180 p_freepic->i_type = MEMORY_PICTURE;
181 p_freepic->b_slow = 0;
183 p_freepic->i_refcount = 0;
184 p_freepic->b_force = 0;
186 p_freepic->b_progressive = b_progressive;
187 p_freepic->i_nb_fields = i_nb_fields;
188 p_freepic->b_top_field_first = b_top_field_first;
190 p_freepic->i_matrix_coefficients = 1;
192 p_vout->i_heap_size++;
196 /* Memory allocation failed : set picture as empty */
197 p_freepic->i_status = FREE_PICTURE;
200 msg_Err( p_vout, "picture allocation failed" );
203 vlc_mutex_unlock( &p_vout->picture_lock );
208 /* No free or destroyed picture could be found, but the decoder
209 * will try again in a while. */
210 vlc_mutex_unlock( &p_vout->picture_lock );
216 * Remove a permanent or reserved picture from the heap
218 * This function frees a previously reserved picture or a permanent
219 * picture. It is meant to be used when the construction of a picture aborted.
220 * Note that the picture will be destroyed even if it is linked !
222 void vout_DestroyPicture( vout_thread_t *p_vout, picture_t *p_pic )
224 vlc_mutex_lock( &p_vout->picture_lock );
227 /* Check if picture status is valid */
228 if( (p_pic->i_status != RESERVED_PICTURE) &&
229 (p_pic->i_status != RESERVED_DATED_PICTURE) &&
230 (p_pic->i_status != RESERVED_DISP_PICTURE) )
232 msg_Err( p_vout, "picture to destroy %p has invalid status %d",
233 p_pic, p_pic->i_status );
237 p_pic->i_status = DESTROYED_PICTURE;
238 p_vout->i_heap_size--;
240 vlc_mutex_unlock( &p_vout->picture_lock );
244 * Increment reference counter of a picture
246 * This function increments the reference counter of a picture in the video
247 * heap. It needs a lock since several producer threads can access the picture.
249 void vout_LinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
251 vlc_mutex_lock( &p_vout->picture_lock );
253 vlc_mutex_unlock( &p_vout->picture_lock );
257 * Decrement reference counter of a picture
259 * This function decrement the reference counter of a picture in the video heap
261 void vout_UnlinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
263 vlc_mutex_lock( &p_vout->picture_lock );
266 if( p_pic->i_refcount < 0 )
268 msg_Err( p_vout, "picture %p refcount is %i",
269 p_pic, p_pic->i_refcount );
270 p_pic->i_refcount = 0;
273 if( ( p_pic->i_refcount == 0 ) &&
274 ( p_pic->i_status == DISPLAYED_PICTURE ) )
276 p_pic->i_status = DESTROYED_PICTURE;
277 p_vout->i_heap_size--;
280 vlc_mutex_unlock( &p_vout->picture_lock );
286 * This function chooses whether the current picture needs to be copied
287 * before rendering, does the subpicture magic, and tells the video output
288 * thread which direct buffer needs to be displayed.
290 picture_t * vout_RenderPicture( vout_thread_t *p_vout, picture_t *p_pic,
291 subpicture_t *p_subpic )
300 if( p_pic->i_type == DIRECT_PICTURE )
302 if( !p_vout->render.b_allow_modify_pics || p_pic->i_refcount )
304 /* Picture is in a direct buffer and is still in use,
305 * we need to copy it to another direct buffer before
306 * displaying it if there are subtitles. */
307 if( p_subpic != NULL )
309 /* We have subtitles. First copy the picture to
310 * the spare direct buffer, then render the
312 CopyPicture( p_vout, p_pic, PP_OUTPUTPICTURE[0] );
314 vout_RenderSubPictures( p_vout, PP_OUTPUTPICTURE[0], p_subpic );
316 return PP_OUTPUTPICTURE[0];
319 /* No subtitles, picture is in a directbuffer so
320 * we can display it directly even if it is still
325 /* Picture is in a direct buffer but isn't used by the
326 * decoder. We can safely render subtitles on it and
328 vout_RenderSubPictures( p_vout, p_pic, p_subpic );
333 /* Not a direct buffer. We either need to copy it to a direct buffer,
334 * or render it if the chroma isn't the same. */
335 if( p_vout->b_direct )
337 /* Picture is not in a direct buffer, but is exactly the
338 * same size as the direct buffers. A memcpy() is enough,
339 * then render the subtitles. */
341 if( PP_OUTPUTPICTURE[0]->pf_lock )
342 if( PP_OUTPUTPICTURE[0]->pf_lock( p_vout, PP_OUTPUTPICTURE[0] ) )
344 if( PP_OUTPUTPICTURE[0]->pf_unlock )
345 PP_OUTPUTPICTURE[0]->pf_unlock( p_vout, PP_OUTPUTPICTURE[0] );
350 if( p_subpic == NULL ||
351 ( p_vout->render.b_allow_modify_pics && !p_pic->i_refcount ) )
353 vout_RenderSubPictures( p_vout, p_pic, p_subpic );
354 CopyPicture( p_vout, p_pic, PP_OUTPUTPICTURE[0] );
356 else if( PP_OUTPUTPICTURE[0]->b_slow )
358 /* The picture buffer is in slow memory. We'll use
359 * the "2 * VOUT_MAX_PICTURES + 1" picture as a temporary
360 * one for subpictures rendering. */
361 picture_t *p_tmp_pic = &p_vout->p_picture[2 * VOUT_MAX_PICTURES];
362 if( p_tmp_pic->i_status == FREE_PICTURE )
364 vout_AllocatePicture( VLC_OBJECT(p_vout),
365 p_tmp_pic, p_vout->render.i_chroma,
366 p_vout->render.i_width,
367 p_vout->render.i_height,
368 p_vout->render.i_aspect );
369 p_tmp_pic->i_type = MEMORY_PICTURE;
370 p_tmp_pic->i_status = RESERVED_PICTURE;
373 CopyPicture( p_vout, p_pic, p_tmp_pic );
375 vout_RenderSubPictures( p_vout, p_tmp_pic, p_subpic );
377 CopyPicture( p_vout, p_tmp_pic, PP_OUTPUTPICTURE[0] );
381 CopyPicture( p_vout, p_pic, PP_OUTPUTPICTURE[0] );
383 vout_RenderSubPictures( p_vout, PP_OUTPUTPICTURE[0], p_subpic );
386 if( PP_OUTPUTPICTURE[0]->pf_unlock )
387 PP_OUTPUTPICTURE[0]->pf_unlock( p_vout, PP_OUTPUTPICTURE[0] );
389 return PP_OUTPUTPICTURE[0];
392 /* Picture is not in a direct buffer, and needs to be converted to
393 * another size/chroma. Then the subtitles need to be rendered as
394 * well. This usually means software YUV, or hardware YUV with a
395 * different chroma. */
397 if( p_subpic != NULL && p_vout->p_picture[0].b_slow )
399 /* The picture buffer is in slow memory. We'll use
400 * the "2 * VOUT_MAX_PICTURES + 1" picture as a temporary
401 * one for subpictures rendering. */
402 picture_t *p_tmp_pic = &p_vout->p_picture[2 * VOUT_MAX_PICTURES];
403 if( p_tmp_pic->i_status == FREE_PICTURE )
405 vout_AllocatePicture( VLC_OBJECT(p_vout),
406 p_tmp_pic, p_vout->output.i_chroma,
407 p_vout->output.i_width,
408 p_vout->output.i_height,
409 p_vout->output.i_aspect );
410 p_tmp_pic->i_type = MEMORY_PICTURE;
411 p_tmp_pic->i_status = RESERVED_PICTURE;
414 /* Convert image to the first direct buffer */
415 p_vout->chroma.pf_convert( p_vout, p_pic, p_tmp_pic );
417 /* Render subpictures on the first direct buffer */
418 vout_RenderSubPictures( p_vout, p_tmp_pic, p_subpic );
420 if( p_vout->p_picture[0].pf_lock )
421 if( p_vout->p_picture[0].pf_lock( p_vout, &p_vout->p_picture[0] ) )
424 CopyPicture( p_vout, p_tmp_pic, &p_vout->p_picture[0] );
428 if( p_vout->p_picture[0].pf_lock )
429 if( p_vout->p_picture[0].pf_lock( p_vout, &p_vout->p_picture[0] ) )
432 /* Convert image to the first direct buffer */
433 p_vout->chroma.pf_convert( p_vout, p_pic, &p_vout->p_picture[0] );
435 /* Render subpictures on the first direct buffer */
436 vout_RenderSubPictures( p_vout, &p_vout->p_picture[0], p_subpic );
439 if( p_vout->p_picture[0].pf_unlock )
440 p_vout->p_picture[0].pf_unlock( p_vout, &p_vout->p_picture[0] );
442 return &p_vout->p_picture[0];
446 * Calculate image window coordinates
448 * This function will be accessed by plugins. It calculates the relative
449 * position of the output window and the image window.
451 void vout_PlacePicture( vout_thread_t *p_vout,
452 unsigned int i_width, unsigned int i_height,
453 unsigned int *pi_x, unsigned int *pi_y,
454 unsigned int *pi_width, unsigned int *pi_height )
456 if( (i_width <= 0) || (i_height <=0) )
458 *pi_width = *pi_height = *pi_x = *pi_y = 0;
463 if( p_vout->b_scale )
466 *pi_height = i_height;
470 *pi_width = __MIN( i_width, p_vout->render.i_width );
471 *pi_height = __MIN( i_height, p_vout->render.i_height );
474 if( VOUT_ASPECT_FACTOR * *pi_width / *pi_height < p_vout->render.i_aspect )
476 *pi_width = *pi_height * p_vout->render.i_aspect / VOUT_ASPECT_FACTOR;
480 *pi_height = *pi_width * VOUT_ASPECT_FACTOR / p_vout->render.i_aspect;
483 if( *pi_width > i_width )
486 *pi_height = VOUT_ASPECT_FACTOR * *pi_width / p_vout->render.i_aspect;
489 if( *pi_height > i_height )
491 *pi_height = i_height;
492 *pi_width = *pi_height * p_vout->render.i_aspect / VOUT_ASPECT_FACTOR;
495 switch( p_vout->i_alignment & VOUT_ALIGN_HMASK )
497 case VOUT_ALIGN_LEFT:
500 case VOUT_ALIGN_RIGHT:
501 *pi_x = i_width - *pi_width;
504 *pi_x = ( i_width - *pi_width ) / 2;
507 switch( p_vout->i_alignment & VOUT_ALIGN_VMASK )
512 case VOUT_ALIGN_BOTTOM:
513 *pi_y = i_height - *pi_height;
516 *pi_y = ( i_height - *pi_height ) / 2;
521 * Allocate a new picture in the heap.
523 * This function allocates a fake direct buffer in memory, which can be
524 * used exactly like a video buffer. The video output thread then manages
525 * how it gets displayed.
527 void vout_AllocatePicture( vlc_object_t *p_this, picture_t *p_pic,
528 vlc_fourcc_t i_chroma,
529 int i_width, int i_height, int i_aspect )
531 int i_bytes, i_index;
533 vout_InitPicture( p_this, p_pic, i_chroma,
534 i_width, i_height, i_aspect );
536 /* Calculate how big the new image should be */
537 i_bytes = p_pic->format.i_bits_per_pixel *
538 p_pic->format.i_width * p_pic->format.i_height / 8;
540 p_pic->p_data = vlc_memalign( &p_pic->p_data_orig, 16, i_bytes );
542 if( p_pic->p_data == NULL )
548 /* Fill the p_pixels field for each plane */
549 p_pic->p[ 0 ].p_pixels = p_pic->p_data;
551 for( i_index = 1; i_index < p_pic->i_planes; i_index++ )
553 p_pic->p[i_index].p_pixels = p_pic->p[i_index-1].p_pixels
554 + p_pic->p[i_index-1].i_lines
555 * p_pic->p[i_index-1].i_pitch;
560 * Initialise the video format fields given chroma/size.
562 * This function initializes all the video_frame_format_t fields given the
563 * static properties of a picture (chroma and size).
564 * \param p_format Pointer to the format structure to initialize
565 * \param i_chroma Chroma to set
566 * \param i_width Width to set
567 * \param i_height Height to set
568 * \param i_aspect Aspect ratio
570 void vout_InitFormat( video_frame_format_t *p_format, vlc_fourcc_t i_chroma,
571 int i_width, int i_height, int i_aspect )
573 p_format->i_chroma = i_chroma;
574 p_format->i_width = p_format->i_visible_width = i_width;
575 p_format->i_height = p_format->i_visible_height = i_height;
576 p_format->i_x_offset = p_format->i_y_offset = 0;
577 p_format->i_aspect = i_aspect;
580 /* Assume we have square pixels */
581 if( i_width && i_height )
582 p_format->i_aspect = i_width * VOUT_ASPECT_FACTOR / i_height;
584 p_format->i_aspect = 0;
590 p_format->i_bits_per_pixel = 32;
593 p_format->i_bits_per_pixel = 24;
598 p_format->i_bits_per_pixel = 16;
599 p_format->i_bits_per_pixel = 16;
605 p_format->i_bits_per_pixel = 12;
609 p_format->i_bits_per_pixel = 9;
612 p_format->i_bits_per_pixel = 8;
615 p_format->i_bits_per_pixel = 8;
619 p_format->i_bits_per_pixel = 32;
622 /* FIXME: Should be 24 here but x11 and our chroma conversion
623 * routines assume 32. */
625 p_format->i_bits_per_pixel = 24;
627 p_format->i_bits_per_pixel = 32;
632 p_format->i_bits_per_pixel = 16;
635 p_format->i_bits_per_pixel = 8;
638 p_format->i_bits_per_pixel = 0;
644 * Initialise the picture_t fields given chroma/size.
646 * This function initializes most of the picture_t fields given a chroma and
647 * size. It makes the assumption that stride == width.
648 * \param p_this The calling object
649 * \param p_pic Pointer to the picture to initialize
650 * \param i_chroma The chroma fourcc to set
651 * \param i_width The width of the picture
652 * \param i_height The height of the picture
653 * \param i_aspect The aspect ratio of the picture
655 void vout_InitPicture( vlc_object_t *p_this, picture_t *p_pic,
656 vlc_fourcc_t i_chroma,
657 int i_width, int i_height, int i_aspect )
661 /* Store default values */
662 for( i_index = 0; i_index < VOUT_MAX_PLANES; i_index++ )
664 p_pic->p[i_index].p_pixels = NULL;
665 p_pic->p[i_index].i_pixel_pitch = 1;
668 vout_InitFormat( &p_pic->format, i_chroma, i_width, i_height, i_aspect );
670 /* Calculate coordinates */
674 p_pic->p[ Y_PLANE ].i_lines = i_height;
675 p_pic->p[ Y_PLANE ].i_pitch = i_width;
676 p_pic->p[ Y_PLANE ].i_visible_pitch = p_pic->p[ Y_PLANE ].i_pitch;
677 p_pic->p[ U_PLANE ].i_lines = i_height;
678 p_pic->p[ U_PLANE ].i_pitch = i_width / 4;
679 p_pic->p[ U_PLANE ].i_visible_pitch = p_pic->p[ U_PLANE ].i_pitch;
680 p_pic->p[ V_PLANE ].i_lines = i_height;
681 p_pic->p[ V_PLANE ].i_pitch = i_width / 4;
682 p_pic->p[ V_PLANE ].i_visible_pitch = p_pic->p[ V_PLANE ].i_pitch;
688 p_pic->p[ Y_PLANE ].i_lines = i_height;
689 p_pic->p[ Y_PLANE ].i_pitch = i_width;
690 p_pic->p[ Y_PLANE ].i_visible_pitch = p_pic->p[ Y_PLANE ].i_pitch;
691 p_pic->p[ U_PLANE ].i_lines = i_height / 4;
692 p_pic->p[ U_PLANE ].i_pitch = i_width / 4;
693 p_pic->p[ U_PLANE ].i_visible_pitch = p_pic->p[ U_PLANE ].i_pitch;
694 p_pic->p[ V_PLANE ].i_lines = i_height / 4;
695 p_pic->p[ V_PLANE ].i_pitch = i_width / 4;
696 p_pic->p[ V_PLANE ].i_visible_pitch = p_pic->p[ V_PLANE ].i_pitch;
703 p_pic->p[ Y_PLANE ].i_lines = i_height;
704 p_pic->p[ Y_PLANE ].i_pitch = i_width;
705 p_pic->p[ Y_PLANE ].i_visible_pitch = p_pic->p[ Y_PLANE ].i_pitch;
706 p_pic->p[ U_PLANE ].i_lines = i_height / 2;
707 p_pic->p[ U_PLANE ].i_pitch = i_width / 2;
708 p_pic->p[ U_PLANE ].i_visible_pitch = p_pic->p[ U_PLANE ].i_pitch;
709 p_pic->p[ V_PLANE ].i_lines = i_height / 2;
710 p_pic->p[ V_PLANE ].i_pitch = i_width / 2;
711 p_pic->p[ V_PLANE ].i_visible_pitch = p_pic->p[ V_PLANE ].i_pitch;
716 p_pic->p[ Y_PLANE ].i_lines = i_height;
717 p_pic->p[ Y_PLANE ].i_pitch = i_width;
718 p_pic->p[ Y_PLANE ].i_visible_pitch = p_pic->p[ Y_PLANE ].i_pitch;
719 p_pic->p[ U_PLANE ].i_lines = i_height;
720 p_pic->p[ U_PLANE ].i_pitch = i_width / 2;
721 p_pic->p[ U_PLANE ].i_visible_pitch = p_pic->p[ U_PLANE ].i_pitch;
722 p_pic->p[ V_PLANE ].i_lines = i_height;
723 p_pic->p[ V_PLANE ].i_pitch = i_width / 2;
724 p_pic->p[ V_PLANE ].i_visible_pitch = p_pic->p[ V_PLANE ].i_pitch;
729 p_pic->p[ Y_PLANE ].i_lines = i_height;
730 p_pic->p[ Y_PLANE ].i_pitch = i_width;
731 p_pic->p[ Y_PLANE ].i_visible_pitch = p_pic->p[ Y_PLANE ].i_pitch;
732 p_pic->p[ U_PLANE ].i_lines = i_height;
733 p_pic->p[ U_PLANE ].i_pitch = i_width;
734 p_pic->p[ U_PLANE ].i_visible_pitch = p_pic->p[ U_PLANE ].i_pitch;
735 p_pic->p[ V_PLANE ].i_lines = i_height;
736 p_pic->p[ V_PLANE ].i_pitch = i_width;
737 p_pic->p[ V_PLANE ].i_visible_pitch = p_pic->p[ V_PLANE ].i_pitch;
742 p_pic->p[ Y_PLANE ].i_lines = i_height;
743 p_pic->p[ Y_PLANE ].i_pitch = i_width;
744 p_pic->p[ Y_PLANE ].i_visible_pitch = p_pic->p[ Y_PLANE ].i_pitch;
745 p_pic->p[ U_PLANE ].i_lines = i_height;
746 p_pic->p[ U_PLANE ].i_pitch = i_width;
747 p_pic->p[ U_PLANE ].i_visible_pitch = p_pic->p[ U_PLANE ].i_pitch;
748 p_pic->p[ V_PLANE ].i_lines = i_height;
749 p_pic->p[ V_PLANE ].i_pitch = i_width;
750 p_pic->p[ V_PLANE ].i_visible_pitch = p_pic->p[ V_PLANE ].i_pitch;
751 p_pic->p[ A_PLANE ].i_lines = i_height;
752 p_pic->p[ A_PLANE ].i_pitch = i_width;
753 p_pic->p[ A_PLANE ].i_visible_pitch = p_pic->p[ A_PLANE ].i_pitch;
758 p_pic->p->i_lines = i_height;
759 p_pic->p->i_pitch = i_width;
760 p_pic->p->i_visible_pitch = p_pic->p->i_pitch;
761 p_pic->p->i_pixel_pitch = 8;
766 p_pic->p->i_lines = i_height;
767 p_pic->p->i_pitch = i_width;
768 p_pic->p->i_visible_pitch = p_pic->p->i_pitch;
769 p_pic->p->i_pixel_pitch = 4;
775 p_pic->p->i_lines = i_height;
776 p_pic->p->i_pitch = i_width * 2;
777 p_pic->p->i_visible_pitch = p_pic->p->i_pitch;
778 p_pic->p->i_pixel_pitch = 4;
783 p_pic->p->i_lines = i_height;
784 p_pic->p->i_pitch = i_width;
785 p_pic->p->i_visible_pitch = p_pic->p->i_pitch;
786 p_pic->p->i_pixel_pitch = 1;
791 p_pic->p->i_lines = i_height;
792 p_pic->p->i_pitch = i_width * 2;
793 p_pic->p->i_visible_pitch = p_pic->p->i_pitch;
794 p_pic->p->i_pixel_pitch = 2;
795 /* FIXME: p_heap isn't always reachable
796 p_pic->p_heap->i_rmask = 0x001f;
797 p_pic->p_heap->i_gmask = 0x03e0;
798 p_pic->p_heap->i_bmask = 0x7c00; */
803 p_pic->p->i_lines = i_height;
804 p_pic->p->i_pitch = i_width * 2;
805 p_pic->p->i_visible_pitch = p_pic->p->i_pitch;
806 p_pic->p->i_pixel_pitch = 2;
807 /* FIXME: p_heap isn't always reachable
808 p_pic->p_heap->i_rmask = 0x001f;
809 p_pic->p_heap->i_gmask = 0x07e0;
810 p_pic->p_heap->i_bmask = 0xf800; */
815 p_pic->p->i_lines = i_height;
817 /* FIXME: Should be 3 here but x11 and our chroma conversion
818 * routines assume 4. */
820 p_pic->p->i_pitch = i_width * 3;
821 p_pic->p->i_pixel_pitch = 3;
823 p_pic->p->i_pitch = i_width * 4;
824 p_pic->p->i_pixel_pitch = 4;
826 p_pic->p->i_visible_pitch = p_pic->p->i_pitch;
827 /* FIXME: p_heap isn't always reachable
828 p_pic->p_heap->i_rmask = 0xff0000;
829 p_pic->p_heap->i_gmask = 0x00ff00;
830 p_pic->p_heap->i_bmask = 0x0000ff; */
835 p_pic->p->i_lines = i_height;
836 p_pic->p->i_pitch = i_width * 4;
837 p_pic->p->i_visible_pitch = p_pic->p->i_pitch;
838 p_pic->p->i_pixel_pitch = 4;
839 /* FIXME: p_heap isn't always reachable
840 p_pic->p_heap->i_rmask = 0xff0000;
841 p_pic->p_heap->i_gmask = 0x00ff00;
842 p_pic->p_heap->i_bmask = 0x0000ff; */
847 msg_Err( p_this, "unknown chroma type 0x%.8x (%4.4s)",
848 i_chroma, (char*)&i_chroma );
855 * Compare two chroma values
857 * This function returns 1 if the two fourcc values given as argument are
858 * the same format (eg. UYVY/UYNV) or almost the same format (eg. I420/YV12)
860 int vout_ChromaCmp( vlc_fourcc_t i_chroma, vlc_fourcc_t i_amorhc )
862 /* If they are the same, they are the same ! */
863 if( i_chroma == i_amorhc )
868 /* Check for equivalence classes */
916 /* Following functions are local */
918 /*****************************************************************************
919 * CopyPicture: copy a picture to another one
920 *****************************************************************************
921 * This function takes advantage of the image format, and reduces the
922 * number of calls to memcpy() to the minimum. Source and destination
923 * images must have same width (hence i_visible_pitch), height, and chroma.
924 *****************************************************************************/
925 static void CopyPicture( vout_thread_t * p_vout,
926 picture_t *p_src, picture_t *p_dest )
930 for( i = 0; i < p_src->i_planes ; i++ )
932 if( p_src->p[i].i_pitch == p_dest->p[i].i_pitch )
934 /* There are margins, but with the same width : perfect ! */
935 p_vout->p_vlc->pf_memcpy(
936 p_dest->p[i].p_pixels, p_src->p[i].p_pixels,
937 p_src->p[i].i_pitch * p_src->p[i].i_lines );
941 /* We need to proceed line by line */
942 uint8_t *p_in = p_src->p[i].p_pixels;
943 uint8_t *p_out = p_dest->p[i].p_pixels;
946 for( i_line = p_src->p[i].i_lines; i_line--; )
948 p_vout->p_vlc->pf_memcpy( p_out, p_in,
949 p_src->p[i].i_visible_pitch );
950 p_in += p_src->p[i].i_pitch;
951 p_out += p_dest->p[i].i_pitch;
955 p_dest->date = p_src->date;