1 /*****************************************************************************
2 * vout_pictures.c : picture management functions
3 *****************************************************************************
4 * Copyright (C) 2000-2004 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
34 #include <vlc_common.h>
38 #include <vlc_filter.h>
39 #include "vout_pictures.h"
40 #include "vout_internal.h"
45 * Remove the reservation flag of a picture, which will cause it to be ready
48 void vout_DisplayPicture( vout_thread_t *p_vout, picture_t *p_pic )
50 vlc_mutex_lock( &p_vout->picture_lock );
52 if( p_pic->i_status == RESERVED_PICTURE )
54 p_pic->i_status = READY_PICTURE;
55 vlc_cond_signal( &p_vout->p->picture_wait );
59 msg_Err( p_vout, "picture to display %p has invalid status %d",
60 p_pic, p_pic->i_status );
62 p_vout->p->i_picture_qtype = p_pic->i_qtype;
64 vlc_mutex_unlock( &p_vout->picture_lock );
68 * Allocate a picture in the video output heap.
70 * This function creates a reserved image in the video output heap.
71 * A null pointer is returned if the function fails. This method provides an
72 * already allocated zone of memory in the picture data fields.
73 * It needs locking since several pictures can be created by several producers
76 int vout_CountPictureAvailable( vout_thread_t *p_vout )
81 vlc_mutex_lock( &p_vout->picture_lock );
82 for( i_pic = 0; i_pic < I_RENDERPICTURES; i_pic++ )
84 picture_t *p_pic = PP_RENDERPICTURE[(p_vout->render.i_last_used_pic + i_pic + 1) % I_RENDERPICTURES];
86 switch( p_pic->i_status )
88 case DESTROYED_PICTURE:
100 vlc_mutex_unlock( &p_vout->picture_lock );
105 picture_t *vout_CreatePicture( vout_thread_t *p_vout,
107 bool b_top_field_first,
108 unsigned int i_nb_fields )
110 int i_pic; /* picture index */
112 picture_t * p_freepic = NULL; /* first free picture */
115 vlc_mutex_lock( &p_vout->picture_lock );
118 * Look for an empty place in the picture heap.
120 for( i_pic = 0; i_pic < I_RENDERPICTURES; i_pic++ )
122 p_pic = PP_RENDERPICTURE[(p_vout->render.i_last_used_pic + i_pic + 1)
125 switch( p_pic->i_status )
127 case DESTROYED_PICTURE:
128 /* Memory will not be reallocated, and function can end
129 * immediately - this is the best possible case, since no
130 * memory allocation needs to be done */
131 p_pic->i_status = RESERVED_PICTURE;
132 p_pic->i_refcount = 0;
135 p_pic->b_progressive = b_progressive;
136 p_pic->i_nb_fields = i_nb_fields;
137 p_pic->b_top_field_first = b_top_field_first;
139 p_vout->i_heap_size++;
140 p_vout->render.i_last_used_pic =
141 ( p_vout->render.i_last_used_pic + i_pic + 1 )
143 vlc_mutex_unlock( &p_vout->picture_lock );
147 /* Picture is empty and ready for allocation */
148 p_vout->render.i_last_used_pic =
149 ( p_vout->render.i_last_used_pic + i_pic + 1 )
162 if( p_freepic != NULL )
164 vout_AllocatePicture( VLC_OBJECT(p_vout),
165 p_freepic, p_vout->render.i_chroma,
166 p_vout->render.i_width, p_vout->render.i_height,
167 p_vout->render.i_aspect );
169 if( p_freepic->i_planes )
171 /* Copy picture information, set some default values */
172 p_freepic->i_status = RESERVED_PICTURE;
173 p_freepic->i_type = MEMORY_PICTURE;
174 p_freepic->b_slow = 0;
176 p_freepic->i_refcount = 0;
177 p_freepic->b_force = 0;
179 p_freepic->b_progressive = b_progressive;
180 p_freepic->i_nb_fields = i_nb_fields;
181 p_freepic->b_top_field_first = b_top_field_first;
183 p_vout->i_heap_size++;
187 /* Memory allocation failed : set picture as empty */
188 p_freepic->i_status = FREE_PICTURE;
191 msg_Err( p_vout, "picture allocation failed" );
194 vlc_mutex_unlock( &p_vout->picture_lock );
199 /* No free or destroyed picture could be found, but the decoder
200 * will try again in a while. */
201 vlc_mutex_unlock( &p_vout->picture_lock );
207 static void DestroyPicture( vout_thread_t *p_vout, picture_t *p_picture )
209 vlc_assert_locked( &p_vout->picture_lock );
211 p_picture->i_status = DESTROYED_PICTURE;
212 p_vout->i_heap_size--;
213 picture_CleanupQuant( p_picture );
215 vlc_cond_signal( &p_vout->p->picture_wait );
219 * Remove a permanent or reserved picture from the heap
221 * This function frees a previously reserved picture or a permanent
222 * picture. It is meant to be used when the construction of a picture aborted.
223 * Note that the picture will be destroyed even if it is linked !
225 * TODO remove it, vout_DropPicture should be used instead
227 void vout_DestroyPicture( vout_thread_t *p_vout, picture_t *p_pic )
230 /* Check if picture status is valid */
231 vlc_mutex_lock( &p_vout->picture_lock );
232 if( p_pic->i_status != RESERVED_PICTURE )
234 msg_Err( p_vout, "picture to destroy %p has invalid status %d",
235 p_pic, p_pic->i_status );
237 vlc_mutex_unlock( &p_vout->picture_lock );
240 vout_DropPicture( p_vout, p_pic );
244 void vout_UsePictureLocked( vout_thread_t *p_vout, picture_t *p_picture )
246 vlc_assert_locked( &p_vout->picture_lock );
247 if( p_picture->i_refcount > 0 )
249 /* Pretend we displayed the picture, but don't destroy
250 * it since the decoder might still need it. */
251 p_picture->i_status = DISPLAYED_PICTURE;
255 /* Destroy the picture without displaying it */
256 DestroyPicture( p_vout, p_picture );
261 void vout_DropPicture( vout_thread_t *p_vout, picture_t *p_pic )
263 vlc_mutex_lock( &p_vout->picture_lock );
265 if( p_pic->i_status == READY_PICTURE )
267 /* Grr cannot destroy ready picture by myself so be sure vout won't like it */
269 vlc_cond_signal( &p_vout->p->picture_wait );
273 vout_UsePictureLocked( p_vout, p_pic );
276 vlc_mutex_unlock( &p_vout->picture_lock );
280 * Increment reference counter of a picture
282 * This function increments the reference counter of a picture in the video
283 * heap. It needs a lock since several producer threads can access the picture.
285 void vout_LinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
287 vlc_mutex_lock( &p_vout->picture_lock );
289 vlc_mutex_unlock( &p_vout->picture_lock );
293 * Decrement reference counter of a picture
295 * This function decrement the reference counter of a picture in the video heap
297 void vout_UnlinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
299 vlc_mutex_lock( &p_vout->picture_lock );
301 if( p_pic->i_refcount > 0 )
304 msg_Err( p_vout, "Invalid picture reference count (%p, %d)",
305 p_pic, p_pic->i_refcount );
307 if( p_pic->i_refcount == 0 && p_pic->i_status == DISPLAYED_PICTURE )
308 DestroyPicture( p_vout, p_pic );
310 vlc_mutex_unlock( &p_vout->picture_lock );
313 static int vout_LockPicture( vout_thread_t *p_vout, picture_t *p_picture )
315 if( p_picture->pf_lock )
316 return p_picture->pf_lock( p_vout, p_picture );
319 static void vout_UnlockPicture( vout_thread_t *p_vout, picture_t *p_picture )
321 if( p_picture->pf_unlock )
322 p_picture->pf_unlock( p_vout, p_picture );
328 * This function chooses whether the current picture needs to be copied
329 * before rendering, does the subpicture magic, and tells the video output
330 * thread which direct buffer needs to be displayed.
332 picture_t *vout_RenderPicture( vout_thread_t *p_vout, picture_t *p_pic,
333 subpicture_t *p_subpic, bool b_paused )
338 if( p_pic->i_type == DIRECT_PICTURE )
340 /* Picture is in a direct buffer. */
342 if( p_subpic != NULL )
344 /* We have subtitles. First copy the picture to
345 * the spare direct buffer, then render the
347 if( vout_LockPicture( p_vout, PP_OUTPUTPICTURE[0] ) )
350 picture_Copy( PP_OUTPUTPICTURE[0], p_pic );
352 spu_RenderSubpictures( p_vout->p_spu,
353 PP_OUTPUTPICTURE[0], &p_vout->fmt_out,
354 p_subpic, &p_vout->fmt_in, b_paused );
356 vout_UnlockPicture( p_vout, PP_OUTPUTPICTURE[0] );
358 return PP_OUTPUTPICTURE[0];
361 /* No subtitles, picture is in a directbuffer so
362 * we can display it directly (even if it is still
367 /* Not a direct buffer. We either need to copy it to a direct buffer,
368 * or render it if the chroma isn't the same. */
369 if( p_vout->p->b_direct )
371 /* Picture is not in a direct buffer, but is exactly the
372 * same size as the direct buffers. A memcpy() is enough,
373 * then render the subtitles. */
375 if( vout_LockPicture( p_vout, PP_OUTPUTPICTURE[0] ) )
378 picture_Copy( PP_OUTPUTPICTURE[0], p_pic );
379 spu_RenderSubpictures( p_vout->p_spu,
380 PP_OUTPUTPICTURE[0], &p_vout->fmt_out,
381 p_subpic, &p_vout->fmt_in, b_paused );
383 vout_UnlockPicture( p_vout, PP_OUTPUTPICTURE[0] );
385 return PP_OUTPUTPICTURE[0];
388 /* Picture is not in a direct buffer, and needs to be converted to
389 * another size/chroma. Then the subtitles need to be rendered as
390 * well. This usually means software YUV, or hardware YUV with a
391 * different chroma. */
393 if( p_subpic != NULL && p_vout->p_picture[0].b_slow )
395 /* The picture buffer is in slow memory. We'll use
396 * the "2 * VOUT_MAX_PICTURES + 1" picture as a temporary
397 * one for subpictures rendering. */
398 picture_t *p_tmp_pic = &p_vout->p_picture[2 * VOUT_MAX_PICTURES];
399 if( p_tmp_pic->i_status == FREE_PICTURE )
401 vout_AllocatePicture( VLC_OBJECT(p_vout),
402 p_tmp_pic, p_vout->fmt_out.i_chroma,
403 p_vout->fmt_out.i_width,
404 p_vout->fmt_out.i_height,
405 p_vout->fmt_out.i_aspect );
406 p_tmp_pic->i_type = MEMORY_PICTURE;
407 p_tmp_pic->i_status = RESERVED_PICTURE;
408 /* some modules (such as blend) needs to know the extra information in picture heap */
409 p_tmp_pic->p_heap = &p_vout->output;
412 /* Convert image to the first direct buffer */
413 p_vout->p->p_chroma->p_owner = (filter_owner_sys_t *)p_tmp_pic;
414 p_vout->p->p_chroma->pf_video_filter( p_vout->p->p_chroma, p_pic );
416 /* Render subpictures on the first direct buffer */
417 spu_RenderSubpictures( p_vout->p_spu,
418 p_tmp_pic, &p_vout->fmt_out,
419 p_subpic, &p_vout->fmt_in, b_paused );
421 if( vout_LockPicture( p_vout, &p_vout->p_picture[0] ) )
424 picture_Copy( &p_vout->p_picture[0], p_tmp_pic );
428 if( vout_LockPicture( p_vout, &p_vout->p_picture[0] ) )
431 /* Convert image to the first direct buffer */
432 p_vout->p->p_chroma->p_owner = (filter_owner_sys_t *)&p_vout->p_picture[0];
433 p_vout->p->p_chroma->pf_video_filter( p_vout->p->p_chroma, p_pic );
435 /* Render subpictures on the first direct buffer */
436 spu_RenderSubpictures( p_vout->p_spu,
437 &p_vout->p_picture[0], &p_vout->fmt_out,
438 p_subpic, &p_vout->fmt_in, b_paused );
441 vout_UnlockPicture( p_vout, &p_vout->p_picture[0] );
443 return &p_vout->p_picture[0];
447 * Calculate image window coordinates
449 * This function will be accessed by plugins. It calculates the relative
450 * position of the output window and the image window.
452 void vout_PlacePicture( const vout_thread_t *p_vout,
453 unsigned int i_width, unsigned int i_height,
454 unsigned int *restrict pi_x,
455 unsigned int *restrict pi_y,
456 unsigned int *restrict pi_width,
457 unsigned int *restrict pi_height )
459 if( i_width <= 0 || i_height <= 0 )
461 *pi_width = *pi_height = *pi_x = *pi_y = 0;
465 if( p_vout->b_autoscale )
468 *pi_height = i_height;
472 int i_zoom = p_vout->i_zoom;
473 /* be realistic, scaling factor confined between .2 and 10. */
474 if( i_zoom > 10 * ZOOM_FP_FACTOR ) i_zoom = 10 * ZOOM_FP_FACTOR;
475 else if( i_zoom < ZOOM_FP_FACTOR / 5 ) i_zoom = ZOOM_FP_FACTOR / 5;
477 unsigned int i_original_width, i_original_height;
479 if( p_vout->fmt_in.i_sar_num >= p_vout->fmt_in.i_sar_den )
481 i_original_width = p_vout->fmt_in.i_visible_width *
482 p_vout->fmt_in.i_sar_num / p_vout->fmt_in.i_sar_den;
483 i_original_height = p_vout->fmt_in.i_visible_height;
487 i_original_width = p_vout->fmt_in.i_visible_width;
488 i_original_height = p_vout->fmt_in.i_visible_height *
489 p_vout->fmt_in.i_sar_den / p_vout->fmt_in.i_sar_num;
492 /* On windows, inner video window exceeding container leads to black screen */
493 *pi_width = __MIN( i_width, i_original_width * i_zoom / ZOOM_FP_FACTOR );
494 *pi_height = __MIN( i_height, i_original_height * i_zoom / ZOOM_FP_FACTOR );
496 *pi_width = i_original_width * i_zoom / ZOOM_FP_FACTOR ;
497 *pi_height = i_original_height * i_zoom / ZOOM_FP_FACTOR ;
501 int64_t i_scaled_width = p_vout->fmt_in.i_visible_width * (int64_t)p_vout->fmt_in.i_sar_num *
502 *pi_height / p_vout->fmt_in.i_visible_height / p_vout->fmt_in.i_sar_den;
503 int64_t i_scaled_height = p_vout->fmt_in.i_visible_height * (int64_t)p_vout->fmt_in.i_sar_den *
504 *pi_width / p_vout->fmt_in.i_visible_width / p_vout->fmt_in.i_sar_num;
506 if( i_scaled_width <= 0 || i_scaled_height <= 0 )
508 msg_Warn( p_vout, "ignoring broken aspect ratio" );
509 i_scaled_width = *pi_width;
510 i_scaled_height = *pi_height;
513 if( i_scaled_width > *pi_width )
514 *pi_height = i_scaled_height;
516 *pi_width = i_scaled_width;
518 switch( p_vout->i_alignment & VOUT_ALIGN_HMASK )
520 case VOUT_ALIGN_LEFT:
523 case VOUT_ALIGN_RIGHT:
524 *pi_x = i_width - *pi_width;
527 *pi_x = ( i_width - *pi_width ) / 2;
530 switch( p_vout->i_alignment & VOUT_ALIGN_VMASK )
535 case VOUT_ALIGN_BOTTOM:
536 *pi_y = i_height - *pi_height;
539 *pi_y = ( i_height - *pi_height ) / 2;
544 * Allocate a new picture in the heap.
546 * This function allocates a fake direct buffer in memory, which can be
547 * used exactly like a video buffer. The video output thread then manages
548 * how it gets displayed.
550 int __vout_AllocatePicture( vlc_object_t *p_this, picture_t *p_pic,
551 vlc_fourcc_t i_chroma,
552 int i_width, int i_height, int i_aspect )
554 int i_bytes, i_index, i_width_aligned, i_height_aligned;
556 /* Make sure the real dimensions are a multiple of 16 */
557 i_width_aligned = (i_width + 15) >> 4 << 4;
558 i_height_aligned = (i_height + 15) >> 4 << 4;
560 if( vout_InitPicture( p_this, p_pic, i_chroma,
561 i_width, i_height, i_aspect ) != VLC_SUCCESS )
567 /* Calculate how big the new image should be */
568 i_bytes = p_pic->format.i_bits_per_pixel *
569 i_width_aligned * i_height_aligned / 8;
571 p_pic->p_data = vlc_memalign( &p_pic->p_data_orig, 16, i_bytes );
573 if( p_pic->p_data == NULL )
579 /* Fill the p_pixels field for each plane */
580 p_pic->p[ 0 ].p_pixels = p_pic->p_data;
582 for( i_index = 1; i_index < p_pic->i_planes; i_index++ )
584 p_pic->p[i_index].p_pixels = p_pic->p[i_index-1].p_pixels +
585 p_pic->p[i_index-1].i_lines * p_pic->p[i_index-1].i_pitch;
592 * Initialise the video format fields given chroma/size.
594 * This function initializes all the video_frame_format_t fields given the
595 * static properties of a picture (chroma and size).
596 * \param p_format Pointer to the format structure to initialize
597 * \param i_chroma Chroma to set
598 * \param i_width Width to set
599 * \param i_height Height to set
600 * \param i_aspect Aspect ratio
602 void vout_InitFormat( video_frame_format_t *p_format, vlc_fourcc_t i_chroma,
603 int i_width, int i_height, int i_aspect )
605 p_format->i_chroma = i_chroma;
606 p_format->i_width = p_format->i_visible_width = i_width;
607 p_format->i_height = p_format->i_visible_height = i_height;
608 p_format->i_x_offset = p_format->i_y_offset = 0;
609 p_format->i_aspect = i_aspect;
612 /* Assume we have square pixels */
613 if( i_width && i_height )
614 p_format->i_aspect = i_width * VOUT_ASPECT_FACTOR / i_height;
616 p_format->i_aspect = 0;
622 p_format->i_bits_per_pixel = 32;
626 p_format->i_bits_per_pixel = 24;
632 p_format->i_bits_per_pixel = 16;
636 p_format->i_bits_per_pixel = 16;
643 p_format->i_bits_per_pixel = 12;
647 p_format->i_bits_per_pixel = 9;
650 p_format->i_bits_per_pixel = 8;
653 p_format->i_bits_per_pixel = 8;
658 p_format->i_bits_per_pixel = 32;
661 p_format->i_bits_per_pixel = 24;
665 p_format->i_bits_per_pixel = 16;
668 p_format->i_bits_per_pixel = 8;
675 p_format->i_bits_per_pixel = 8;
679 p_format->i_bits_per_pixel = 0;
685 * Initialise the picture_t fields given chroma/size.
687 * This function initializes most of the picture_t fields given a chroma and
688 * size. It makes the assumption that stride == width.
689 * \param p_this The calling object
690 * \param p_pic Pointer to the picture to initialize
691 * \param i_chroma The chroma fourcc to set
692 * \param i_width The width of the picture
693 * \param i_height The height of the picture
694 * \param i_aspect The aspect ratio of the picture
696 int __vout_InitPicture( vlc_object_t *p_this, picture_t *p_pic,
697 vlc_fourcc_t i_chroma,
698 int i_width, int i_height, int i_aspect )
700 int i_index, i_width_aligned, i_height_aligned;
702 /* Store default values */
703 for( i_index = 0; i_index < VOUT_MAX_PLANES; i_index++ )
705 p_pic->p[i_index].p_pixels = NULL;
706 p_pic->p[i_index].i_pixel_pitch = 1;
709 p_pic->pf_release = NULL;
710 p_pic->pf_lock = NULL;
711 p_pic->pf_unlock = NULL;
712 p_pic->i_refcount = 0;
714 p_pic->i_qtype = QTYPE_NONE;
715 p_pic->i_qstride = 0;
718 vout_InitFormat( &p_pic->format, i_chroma, i_width, i_height, i_aspect );
720 /* Make sure the real dimensions are a multiple of 16 */
721 i_width_aligned = (i_width + 15) >> 4 << 4;
722 i_height_aligned = (i_height + 15) >> 4 << 4;
724 /* Calculate coordinates */
728 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
729 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
730 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
731 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
732 p_pic->p[ U_PLANE ].i_lines = i_height_aligned;
733 p_pic->p[ U_PLANE ].i_visible_lines = i_height;
734 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 4;
735 p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 4;
736 p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
737 p_pic->p[ V_PLANE ].i_visible_lines = i_height;
738 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 4;
739 p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 4;
745 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
746 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
747 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
748 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
749 p_pic->p[ U_PLANE ].i_lines = i_height_aligned / 4;
750 p_pic->p[ U_PLANE ].i_visible_lines = i_height / 4;
751 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 4;
752 p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 4;
753 p_pic->p[ V_PLANE ].i_lines = i_height_aligned / 4;
754 p_pic->p[ V_PLANE ].i_visible_lines = i_height / 4;
755 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 4;
756 p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 4;
764 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
765 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
766 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
767 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
768 p_pic->p[ U_PLANE ].i_lines = i_height_aligned / 2;
769 p_pic->p[ U_PLANE ].i_visible_lines = i_height / 2;
770 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 2;
771 p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 2;
772 p_pic->p[ V_PLANE ].i_lines = i_height_aligned / 2;
773 p_pic->p[ V_PLANE ].i_visible_lines = i_height / 2;
774 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 2;
775 p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 2;
781 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
782 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
783 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
784 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
785 p_pic->p[ U_PLANE ].i_lines = i_height_aligned;
786 p_pic->p[ U_PLANE ].i_visible_lines = i_height;
787 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 2;
788 p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 2;
789 p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
790 p_pic->p[ V_PLANE ].i_visible_lines = i_height;
791 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 2;
792 p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 2;
798 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
799 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
800 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
801 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
802 p_pic->p[ U_PLANE ].i_lines = i_height_aligned / 2;
803 p_pic->p[ U_PLANE ].i_visible_lines = i_height / 2;
804 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned;
805 p_pic->p[ U_PLANE ].i_visible_pitch = i_width;
806 p_pic->p[ V_PLANE ].i_lines = i_height_aligned / 2;
807 p_pic->p[ V_PLANE ].i_visible_lines = i_height / 2;
808 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned;
809 p_pic->p[ V_PLANE ].i_visible_pitch = i_width;
815 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
816 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
817 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
818 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
819 p_pic->p[ U_PLANE ].i_lines = i_height_aligned;
820 p_pic->p[ U_PLANE ].i_visible_lines = i_height;
821 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned;
822 p_pic->p[ U_PLANE ].i_visible_pitch = i_width;
823 p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
824 p_pic->p[ V_PLANE ].i_visible_lines = i_height;
825 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned;
826 p_pic->p[ V_PLANE ].i_visible_pitch = i_width;
831 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
832 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
833 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
834 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
835 p_pic->p[ U_PLANE ].i_lines = i_height_aligned;
836 p_pic->p[ U_PLANE ].i_visible_lines = i_height;
837 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned;
838 p_pic->p[ U_PLANE ].i_visible_pitch = i_width;
839 p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
840 p_pic->p[ V_PLANE ].i_visible_lines = i_height;
841 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned;
842 p_pic->p[ V_PLANE ].i_visible_pitch = i_width;
843 p_pic->p[ A_PLANE ].i_lines = i_height_aligned;
844 p_pic->p[ A_PLANE ].i_visible_lines = i_height;
845 p_pic->p[ A_PLANE ].i_pitch = i_width_aligned;
846 p_pic->p[ A_PLANE ].i_visible_pitch = i_width;
851 p_pic->p->i_lines = i_height_aligned;
852 p_pic->p->i_visible_lines = i_height;
853 p_pic->p->i_pitch = i_width_aligned;
854 p_pic->p->i_visible_pitch = i_width;
855 p_pic->p->i_pixel_pitch = 8;
860 p_pic->p->i_lines = i_height_aligned;
861 p_pic->p->i_visible_lines = i_height;
862 p_pic->p->i_pitch = i_width_aligned;
863 p_pic->p->i_visible_pitch = i_width;
864 p_pic->p->i_pixel_pitch = 4;
870 p_pic->p->i_lines = i_height_aligned;
871 p_pic->p->i_visible_lines = i_height;
872 p_pic->p->i_pitch = i_width_aligned * 2;
873 p_pic->p->i_visible_pitch = i_width * 2;
874 p_pic->p->i_pixel_pitch = 4;
879 p_pic->p->i_lines = i_height_aligned;
880 p_pic->p->i_visible_lines = i_height;
881 p_pic->p->i_pitch = i_width_aligned;
882 p_pic->p->i_visible_pitch = i_width;
883 p_pic->p->i_pixel_pitch = 1;
888 p_pic->p->i_lines = i_height_aligned;
889 p_pic->p->i_visible_lines = i_height;
890 p_pic->p->i_pitch = i_width_aligned * 2;
891 p_pic->p->i_visible_pitch = i_width * 2;
892 p_pic->p->i_pixel_pitch = 2;
897 p_pic->p->i_lines = i_height_aligned;
898 p_pic->p->i_visible_lines = i_height;
899 p_pic->p->i_pitch = i_width_aligned * 2;
900 p_pic->p->i_visible_pitch = i_width * 2;
901 p_pic->p->i_pixel_pitch = 2;
906 p_pic->p->i_lines = i_height_aligned;
907 p_pic->p->i_visible_lines = i_height;
908 p_pic->p->i_pitch = i_width_aligned * 3;
909 p_pic->p->i_visible_pitch = i_width * 3;
910 p_pic->p->i_pixel_pitch = 3;
916 p_pic->p->i_lines = i_height_aligned;
917 p_pic->p->i_visible_lines = i_height;
918 p_pic->p->i_pitch = i_width_aligned * 4;
919 p_pic->p->i_visible_pitch = i_width * 4;
920 p_pic->p->i_pixel_pitch = 4;
928 p_pic->p->i_lines = i_height_aligned;
929 p_pic->p->i_visible_lines = i_height;
930 p_pic->p->i_pitch = i_width_aligned;
931 p_pic->p->i_visible_pitch = i_width;
932 p_pic->p->i_pixel_pitch = 1;
938 msg_Err( p_this, "unknown chroma type 0x%.8x (%4.4s)",
939 i_chroma, (char*)&i_chroma );
948 * Compare two chroma values
950 * This function returns 1 if the two fourcc values given as argument are
951 * the same format (eg. UYVY/UYNV) or almost the same format (eg. I420/YV12)
953 int vout_ChromaCmp( vlc_fourcc_t i_chroma, vlc_fourcc_t i_amorhc )
955 /* If they are the same, they are the same ! */
956 if( i_chroma == i_amorhc )
961 /* Check for equivalence classes */
1023 /*****************************************************************************
1025 *****************************************************************************/
1026 static void PictureReleaseCallback( picture_t *p_picture )
1028 if( --p_picture->i_refcount > 0 )
1030 picture_Delete( p_picture );
1032 /*****************************************************************************
1034 *****************************************************************************/
1035 picture_t *picture_New( vlc_fourcc_t i_chroma, int i_width, int i_height, int i_aspect )
1037 picture_t *p_picture = calloc( 1, sizeof(*p_picture) );
1041 if( __vout_AllocatePicture( NULL, p_picture,
1042 i_chroma, i_width, i_height, i_aspect ) )
1048 p_picture->i_refcount = 1;
1049 p_picture->pf_release = PictureReleaseCallback;
1050 p_picture->i_status = RESERVED_PICTURE;
1055 /*****************************************************************************
1057 *****************************************************************************/
1058 void picture_Delete( picture_t *p_picture )
1060 assert( p_picture && p_picture->i_refcount == 0 );
1062 free( p_picture->p_q );
1063 free( p_picture->p_data_orig );
1064 free( p_picture->p_sys );
1068 /*****************************************************************************
1070 *****************************************************************************/
1071 void picture_CopyPixels( picture_t *p_dst, const picture_t *p_src )
1075 for( i = 0; i < p_src->i_planes ; i++ )
1076 plane_CopyPixels( p_dst->p+i, p_src->p+i );
1079 void plane_CopyPixels( plane_t *p_dst, const plane_t *p_src )
1081 const unsigned i_width = __MIN( p_dst->i_visible_pitch,
1082 p_src->i_visible_pitch );
1083 const unsigned i_height = __MIN( p_dst->i_visible_lines,
1084 p_src->i_visible_lines );
1086 if( p_src->i_pitch == p_dst->i_pitch )
1088 /* There are margins, but with the same width : perfect ! */
1089 vlc_memcpy( p_dst->p_pixels, p_src->p_pixels,
1090 p_src->i_pitch * i_height );
1094 /* We need to proceed line by line */
1095 uint8_t *p_in = p_src->p_pixels;
1096 uint8_t *p_out = p_dst->p_pixels;
1102 for( i_line = i_height; i_line--; )
1104 vlc_memcpy( p_out, p_in, i_width );
1105 p_in += p_src->i_pitch;
1106 p_out += p_dst->i_pitch;
1111 /*****************************************************************************
1113 *****************************************************************************/