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 );
63 vlc_mutex_unlock( &p_vout->picture_lock );
67 * Allocate a picture in the video output heap.
69 * This function creates a reserved image in the video output heap.
70 * A null pointer is returned if the function fails. This method provides an
71 * already allocated zone of memory in the picture data fields.
72 * It needs locking since several pictures can be created by several producers
75 int vout_CountPictureAvailable( vout_thread_t *p_vout )
80 vlc_mutex_lock( &p_vout->picture_lock );
81 for( i_pic = 0; i_pic < I_RENDERPICTURES; i_pic++ )
83 picture_t *p_pic = PP_RENDERPICTURE[(p_vout->render.i_last_used_pic + i_pic + 1) % I_RENDERPICTURES];
85 switch( p_pic->i_status )
87 case DESTROYED_PICTURE:
99 vlc_mutex_unlock( &p_vout->picture_lock );
104 picture_t *vout_CreatePicture( vout_thread_t *p_vout,
106 bool b_top_field_first,
107 unsigned int i_nb_fields )
109 int i_pic; /* picture index */
111 picture_t * p_freepic = NULL; /* first free picture */
114 vlc_mutex_lock( &p_vout->picture_lock );
117 * Look for an empty place in the picture heap.
119 for( i_pic = 0; i_pic < I_RENDERPICTURES; i_pic++ )
121 p_pic = PP_RENDERPICTURE[(p_vout->render.i_last_used_pic + i_pic + 1)
124 switch( p_pic->i_status )
126 case DESTROYED_PICTURE:
127 /* Memory will not be reallocated, and function can end
128 * immediately - this is the best possible case, since no
129 * memory allocation needs to be done */
130 p_pic->i_status = RESERVED_PICTURE;
131 p_pic->i_refcount = 0;
134 p_pic->b_progressive = b_progressive;
135 p_pic->i_nb_fields = i_nb_fields;
136 p_pic->b_top_field_first = b_top_field_first;
138 p_vout->i_heap_size++;
139 p_vout->render.i_last_used_pic =
140 ( p_vout->render.i_last_used_pic + i_pic + 1 )
142 vlc_mutex_unlock( &p_vout->picture_lock );
146 /* Picture is empty and ready for allocation */
147 p_vout->render.i_last_used_pic =
148 ( p_vout->render.i_last_used_pic + i_pic + 1 )
161 if( p_freepic != NULL )
163 vout_AllocatePicture( VLC_OBJECT(p_vout),
164 p_freepic, p_vout->render.i_chroma,
165 p_vout->render.i_width, p_vout->render.i_height,
166 p_vout->render.i_aspect );
168 if( p_freepic->i_planes )
170 /* Copy picture information, set some default values */
171 p_freepic->i_status = RESERVED_PICTURE;
172 p_freepic->i_type = MEMORY_PICTURE;
173 p_freepic->b_slow = 0;
175 p_freepic->i_refcount = 0;
176 p_freepic->b_force = 0;
178 p_freepic->b_progressive = b_progressive;
179 p_freepic->i_nb_fields = i_nb_fields;
180 p_freepic->b_top_field_first = b_top_field_first;
182 p_vout->i_heap_size++;
186 /* Memory allocation failed : set picture as empty */
187 p_freepic->i_status = FREE_PICTURE;
190 msg_Err( p_vout, "picture allocation failed" );
193 vlc_mutex_unlock( &p_vout->picture_lock );
198 /* No free or destroyed picture could be found, but the decoder
199 * will try again in a while. */
200 vlc_mutex_unlock( &p_vout->picture_lock );
206 static void DestroyPicture( vout_thread_t *p_vout, picture_t *p_picture )
208 vlc_assert_locked( &p_vout->picture_lock );
210 p_picture->i_status = DESTROYED_PICTURE;
211 p_vout->i_heap_size--;
212 picture_CleanupQuant( p_picture );
214 vlc_cond_signal( &p_vout->p->picture_wait );
218 * Remove a permanent or reserved picture from the heap
220 * This function frees a previously reserved picture or a permanent
221 * picture. It is meant to be used when the construction of a picture aborted.
222 * Note that the picture will be destroyed even if it is linked !
224 * TODO remove it, vout_DropPicture should be used instead
226 void vout_DestroyPicture( vout_thread_t *p_vout, picture_t *p_pic )
229 /* Check if picture status is valid */
230 vlc_mutex_lock( &p_vout->picture_lock );
231 if( p_pic->i_status != RESERVED_PICTURE )
233 msg_Err( p_vout, "picture to destroy %p has invalid status %d",
234 p_pic, p_pic->i_status );
236 vlc_mutex_unlock( &p_vout->picture_lock );
239 vout_DropPicture( p_vout, p_pic );
243 void vout_UsePictureLocked( vout_thread_t *p_vout, picture_t *p_picture )
245 vlc_assert_locked( &p_vout->picture_lock );
246 if( p_picture->i_refcount > 0 )
248 /* Pretend we displayed the picture, but don't destroy
249 * it since the decoder might still need it. */
250 p_picture->i_status = DISPLAYED_PICTURE;
254 /* Destroy the picture without displaying it */
255 DestroyPicture( p_vout, p_picture );
260 void vout_DropPicture( vout_thread_t *p_vout, picture_t *p_pic )
262 vlc_mutex_lock( &p_vout->picture_lock );
264 if( p_pic->i_status == READY_PICTURE )
266 /* Grr cannot destroy ready picture by myself so be sure vout won't like it */
268 vlc_cond_signal( &p_vout->p->picture_wait );
272 vout_UsePictureLocked( p_vout, p_pic );
275 vlc_mutex_unlock( &p_vout->picture_lock );
279 * Increment reference counter of a picture
281 * This function increments the reference counter of a picture in the video
282 * heap. It needs a lock since several producer threads can access the picture.
284 void vout_LinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
286 vlc_mutex_lock( &p_vout->picture_lock );
288 vlc_mutex_unlock( &p_vout->picture_lock );
292 * Decrement reference counter of a picture
294 * This function decrement the reference counter of a picture in the video heap
296 void vout_UnlinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
298 vlc_mutex_lock( &p_vout->picture_lock );
300 if( p_pic->i_refcount > 0 )
303 msg_Err( p_vout, "Invalid picture reference count (%p, %d)",
304 p_pic, p_pic->i_refcount );
306 if( p_pic->i_refcount == 0 && p_pic->i_status == DISPLAYED_PICTURE )
307 DestroyPicture( p_vout, p_pic );
309 vlc_mutex_unlock( &p_vout->picture_lock );
312 static int vout_LockPicture( vout_thread_t *p_vout, picture_t *p_picture )
314 if( p_picture->pf_lock )
315 return p_picture->pf_lock( p_vout, p_picture );
318 static void vout_UnlockPicture( vout_thread_t *p_vout, picture_t *p_picture )
320 if( p_picture->pf_unlock )
321 p_picture->pf_unlock( p_vout, p_picture );
327 * This function chooses whether the current picture needs to be copied
328 * before rendering, does the subpicture magic, and tells the video output
329 * thread which direct buffer needs to be displayed.
331 picture_t *vout_RenderPicture( vout_thread_t *p_vout, picture_t *p_pic,
332 subpicture_t *p_subpic, bool b_paused )
337 if( p_pic->i_type == DIRECT_PICTURE )
339 /* Picture is in a direct buffer. */
341 if( p_subpic != NULL )
343 /* We have subtitles. First copy the picture to
344 * the spare direct buffer, then render the
346 if( vout_LockPicture( p_vout, PP_OUTPUTPICTURE[0] ) )
349 picture_Copy( PP_OUTPUTPICTURE[0], p_pic );
351 spu_RenderSubpictures( p_vout->p_spu,
352 PP_OUTPUTPICTURE[0], &p_vout->fmt_out,
353 p_subpic, &p_vout->fmt_in, b_paused );
355 vout_UnlockPicture( p_vout, PP_OUTPUTPICTURE[0] );
357 return PP_OUTPUTPICTURE[0];
360 /* No subtitles, picture is in a directbuffer so
361 * we can display it directly (even if it is still
366 /* Not a direct buffer. We either need to copy it to a direct buffer,
367 * or render it if the chroma isn't the same. */
368 if( p_vout->p->b_direct )
370 /* Picture is not in a direct buffer, but is exactly the
371 * same size as the direct buffers. A memcpy() is enough,
372 * then render the subtitles. */
374 if( vout_LockPicture( p_vout, PP_OUTPUTPICTURE[0] ) )
377 picture_Copy( PP_OUTPUTPICTURE[0], p_pic );
378 spu_RenderSubpictures( p_vout->p_spu,
379 PP_OUTPUTPICTURE[0], &p_vout->fmt_out,
380 p_subpic, &p_vout->fmt_in, b_paused );
382 vout_UnlockPicture( p_vout, PP_OUTPUTPICTURE[0] );
384 return PP_OUTPUTPICTURE[0];
387 /* Picture is not in a direct buffer, and needs to be converted to
388 * another size/chroma. Then the subtitles need to be rendered as
389 * well. This usually means software YUV, or hardware YUV with a
390 * different chroma. */
392 if( p_subpic != NULL && p_vout->p_picture[0].b_slow )
394 /* The picture buffer is in slow memory. We'll use
395 * the "2 * VOUT_MAX_PICTURES + 1" picture as a temporary
396 * one for subpictures rendering. */
397 picture_t *p_tmp_pic = &p_vout->p_picture[2 * VOUT_MAX_PICTURES];
398 if( p_tmp_pic->i_status == FREE_PICTURE )
400 vout_AllocatePicture( VLC_OBJECT(p_vout),
401 p_tmp_pic, p_vout->fmt_out.i_chroma,
402 p_vout->fmt_out.i_width,
403 p_vout->fmt_out.i_height,
404 p_vout->fmt_out.i_aspect );
405 p_tmp_pic->i_type = MEMORY_PICTURE;
406 p_tmp_pic->i_status = RESERVED_PICTURE;
407 /* some modules (such as blend) needs to know the extra information in picture heap */
408 p_tmp_pic->p_heap = &p_vout->output;
411 /* Convert image to the first direct buffer */
412 p_vout->p->p_chroma->p_owner = (filter_owner_sys_t *)p_tmp_pic;
413 p_vout->p->p_chroma->pf_video_filter( p_vout->p->p_chroma, p_pic );
415 /* Render subpictures on the first direct buffer */
416 spu_RenderSubpictures( p_vout->p_spu,
417 p_tmp_pic, &p_vout->fmt_out,
418 p_subpic, &p_vout->fmt_in, b_paused );
420 if( vout_LockPicture( p_vout, &p_vout->p_picture[0] ) )
423 picture_Copy( &p_vout->p_picture[0], p_tmp_pic );
427 if( vout_LockPicture( p_vout, &p_vout->p_picture[0] ) )
430 /* Convert image to the first direct buffer */
431 p_vout->p->p_chroma->p_owner = (filter_owner_sys_t *)&p_vout->p_picture[0];
432 p_vout->p->p_chroma->pf_video_filter( p_vout->p->p_chroma, p_pic );
434 /* Render subpictures on the first direct buffer */
435 spu_RenderSubpictures( p_vout->p_spu,
436 &p_vout->p_picture[0], &p_vout->fmt_out,
437 p_subpic, &p_vout->fmt_in, b_paused );
440 vout_UnlockPicture( 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( const vout_thread_t *p_vout,
452 unsigned int i_width, unsigned int i_height,
453 unsigned int *restrict pi_x,
454 unsigned int *restrict pi_y,
455 unsigned int *restrict pi_width,
456 unsigned int *restrict pi_height )
458 if( (i_width <= 0) || (i_height <=0) )
460 *pi_width = *pi_height = *pi_x = *pi_y = 0;
464 bool b_autoscale = p_vout->b_autoscale;
465 int i_zoom = p_vout->i_zoom;
467 /* be realistic, scaling factor confined between .2 and 10. */
468 if( i_zoom > 10 * ZOOM_FP_FACTOR || i_zoom < ZOOM_FP_FACTOR / 5 )
469 i_zoom = ZOOM_FP_FACTOR;
474 *pi_height = i_height;
476 else if( i_zoom == ZOOM_FP_FACTOR ) /* original size */
478 *pi_width = __MIN( i_width, p_vout->fmt_in.i_visible_width );
479 *pi_height = __MIN( i_height, p_vout->fmt_in.i_visible_height );
484 p_vout->fmt_in.i_visible_width * i_zoom / ZOOM_FP_FACTOR;
486 p_vout->fmt_in.i_visible_height * i_zoom / ZOOM_FP_FACTOR;
489 int64_t i_scaled_width = p_vout->fmt_in.i_visible_width * (int64_t)p_vout->fmt_in.i_sar_num *
490 *pi_height / p_vout->fmt_in.i_visible_height / p_vout->fmt_in.i_sar_den;
491 int64_t i_scaled_height = p_vout->fmt_in.i_visible_height * (int64_t)p_vout->fmt_in.i_sar_den *
492 *pi_width / p_vout->fmt_in.i_visible_width / p_vout->fmt_in.i_sar_num;
494 if( i_scaled_width <= 0 || i_scaled_height <= 0 )
496 msg_Warn( p_vout, "ignoring broken aspect ratio" );
497 i_scaled_width = *pi_width;
498 i_scaled_height = *pi_height;
501 if( i_scaled_width > *pi_width )
502 *pi_height = i_scaled_height;
504 *pi_width = i_scaled_width;
506 switch( p_vout->i_alignment & VOUT_ALIGN_HMASK )
508 case VOUT_ALIGN_LEFT:
511 case VOUT_ALIGN_RIGHT:
512 *pi_x = i_width - *pi_width;
515 *pi_x = ( i_width - *pi_width ) / 2;
518 switch( p_vout->i_alignment & VOUT_ALIGN_VMASK )
523 case VOUT_ALIGN_BOTTOM:
524 *pi_y = i_height - *pi_height;
527 *pi_y = ( i_height - *pi_height ) / 2;
532 * Allocate a new picture in the heap.
534 * This function allocates a fake direct buffer in memory, which can be
535 * used exactly like a video buffer. The video output thread then manages
536 * how it gets displayed.
538 int __vout_AllocatePicture( vlc_object_t *p_this, picture_t *p_pic,
539 vlc_fourcc_t i_chroma,
540 int i_width, int i_height, int i_aspect )
542 int i_bytes, i_index, i_width_aligned, i_height_aligned;
544 /* Make sure the real dimensions are a multiple of 16 */
545 i_width_aligned = (i_width + 15) >> 4 << 4;
546 i_height_aligned = (i_height + 15) >> 4 << 4;
548 if( vout_InitPicture( p_this, p_pic, i_chroma,
549 i_width, i_height, i_aspect ) != VLC_SUCCESS )
555 /* Calculate how big the new image should be */
556 i_bytes = p_pic->format.i_bits_per_pixel *
557 i_width_aligned * i_height_aligned / 8;
559 p_pic->p_data = vlc_memalign( &p_pic->p_data_orig, 16, i_bytes );
561 if( p_pic->p_data == NULL )
567 /* Fill the p_pixels field for each plane */
568 p_pic->p[ 0 ].p_pixels = p_pic->p_data;
570 for( i_index = 1; i_index < p_pic->i_planes; i_index++ )
572 p_pic->p[i_index].p_pixels = p_pic->p[i_index-1].p_pixels +
573 p_pic->p[i_index-1].i_lines * p_pic->p[i_index-1].i_pitch;
580 * Initialise the video format fields given chroma/size.
582 * This function initializes all the video_frame_format_t fields given the
583 * static properties of a picture (chroma and size).
584 * \param p_format Pointer to the format structure to initialize
585 * \param i_chroma Chroma to set
586 * \param i_width Width to set
587 * \param i_height Height to set
588 * \param i_aspect Aspect ratio
590 void vout_InitFormat( video_frame_format_t *p_format, vlc_fourcc_t i_chroma,
591 int i_width, int i_height, int i_aspect )
593 p_format->i_chroma = i_chroma;
594 p_format->i_width = p_format->i_visible_width = i_width;
595 p_format->i_height = p_format->i_visible_height = i_height;
596 p_format->i_x_offset = p_format->i_y_offset = 0;
597 p_format->i_aspect = i_aspect;
600 /* Assume we have square pixels */
601 if( i_width && i_height )
602 p_format->i_aspect = i_width * VOUT_ASPECT_FACTOR / i_height;
604 p_format->i_aspect = 0;
610 p_format->i_bits_per_pixel = 32;
614 p_format->i_bits_per_pixel = 24;
620 p_format->i_bits_per_pixel = 16;
624 p_format->i_bits_per_pixel = 16;
631 p_format->i_bits_per_pixel = 12;
635 p_format->i_bits_per_pixel = 9;
638 p_format->i_bits_per_pixel = 8;
641 p_format->i_bits_per_pixel = 8;
646 p_format->i_bits_per_pixel = 32;
649 p_format->i_bits_per_pixel = 24;
653 p_format->i_bits_per_pixel = 16;
656 p_format->i_bits_per_pixel = 8;
663 p_format->i_bits_per_pixel = 8;
667 p_format->i_bits_per_pixel = 0;
673 * Initialise the picture_t fields given chroma/size.
675 * This function initializes most of the picture_t fields given a chroma and
676 * size. It makes the assumption that stride == width.
677 * \param p_this The calling object
678 * \param p_pic Pointer to the picture to initialize
679 * \param i_chroma The chroma fourcc to set
680 * \param i_width The width of the picture
681 * \param i_height The height of the picture
682 * \param i_aspect The aspect ratio of the picture
684 int __vout_InitPicture( vlc_object_t *p_this, picture_t *p_pic,
685 vlc_fourcc_t i_chroma,
686 int i_width, int i_height, int i_aspect )
688 int i_index, i_width_aligned, i_height_aligned;
690 /* Store default values */
691 for( i_index = 0; i_index < VOUT_MAX_PLANES; i_index++ )
693 p_pic->p[i_index].p_pixels = NULL;
694 p_pic->p[i_index].i_pixel_pitch = 1;
697 p_pic->pf_release = NULL;
698 p_pic->pf_lock = NULL;
699 p_pic->pf_unlock = NULL;
700 p_pic->i_refcount = 0;
703 p_pic->i_qstride = 0;
706 vout_InitFormat( &p_pic->format, i_chroma, i_width, i_height, i_aspect );
708 /* Make sure the real dimensions are a multiple of 16 */
709 i_width_aligned = (i_width + 15) >> 4 << 4;
710 i_height_aligned = (i_height + 15) >> 4 << 4;
712 /* Calculate coordinates */
716 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
717 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
718 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
719 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
720 p_pic->p[ U_PLANE ].i_lines = i_height_aligned;
721 p_pic->p[ U_PLANE ].i_visible_lines = i_height;
722 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 4;
723 p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 4;
724 p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
725 p_pic->p[ V_PLANE ].i_visible_lines = i_height;
726 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 4;
727 p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 4;
733 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
734 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
735 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
736 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
737 p_pic->p[ U_PLANE ].i_lines = i_height_aligned / 4;
738 p_pic->p[ U_PLANE ].i_visible_lines = i_height / 4;
739 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 4;
740 p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 4;
741 p_pic->p[ V_PLANE ].i_lines = i_height_aligned / 4;
742 p_pic->p[ V_PLANE ].i_visible_lines = i_height / 4;
743 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 4;
744 p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 4;
752 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
753 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
754 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
755 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
756 p_pic->p[ U_PLANE ].i_lines = i_height_aligned / 2;
757 p_pic->p[ U_PLANE ].i_visible_lines = i_height / 2;
758 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 2;
759 p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 2;
760 p_pic->p[ V_PLANE ].i_lines = i_height_aligned / 2;
761 p_pic->p[ V_PLANE ].i_visible_lines = i_height / 2;
762 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 2;
763 p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 2;
769 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
770 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
771 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
772 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
773 p_pic->p[ U_PLANE ].i_lines = i_height_aligned;
774 p_pic->p[ U_PLANE ].i_visible_lines = i_height;
775 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 2;
776 p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 2;
777 p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
778 p_pic->p[ V_PLANE ].i_visible_lines = i_height;
779 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 2;
780 p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 2;
786 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
787 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
788 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
789 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
790 p_pic->p[ U_PLANE ].i_lines = i_height_aligned / 2;
791 p_pic->p[ U_PLANE ].i_visible_lines = i_height / 2;
792 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned;
793 p_pic->p[ U_PLANE ].i_visible_pitch = i_width;
794 p_pic->p[ V_PLANE ].i_lines = i_height_aligned / 2;
795 p_pic->p[ V_PLANE ].i_visible_lines = i_height / 2;
796 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned;
797 p_pic->p[ V_PLANE ].i_visible_pitch = i_width;
803 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
804 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
805 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
806 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
807 p_pic->p[ U_PLANE ].i_lines = i_height_aligned;
808 p_pic->p[ U_PLANE ].i_visible_lines = i_height;
809 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned;
810 p_pic->p[ U_PLANE ].i_visible_pitch = i_width;
811 p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
812 p_pic->p[ V_PLANE ].i_visible_lines = i_height;
813 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned;
814 p_pic->p[ V_PLANE ].i_visible_pitch = i_width;
819 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
820 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
821 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
822 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
823 p_pic->p[ U_PLANE ].i_lines = i_height_aligned;
824 p_pic->p[ U_PLANE ].i_visible_lines = i_height;
825 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned;
826 p_pic->p[ U_PLANE ].i_visible_pitch = i_width;
827 p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
828 p_pic->p[ V_PLANE ].i_visible_lines = i_height;
829 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned;
830 p_pic->p[ V_PLANE ].i_visible_pitch = i_width;
831 p_pic->p[ A_PLANE ].i_lines = i_height_aligned;
832 p_pic->p[ A_PLANE ].i_visible_lines = i_height;
833 p_pic->p[ A_PLANE ].i_pitch = i_width_aligned;
834 p_pic->p[ A_PLANE ].i_visible_pitch = i_width;
839 p_pic->p->i_lines = i_height_aligned;
840 p_pic->p->i_visible_lines = i_height;
841 p_pic->p->i_pitch = i_width_aligned;
842 p_pic->p->i_visible_pitch = i_width;
843 p_pic->p->i_pixel_pitch = 8;
848 p_pic->p->i_lines = i_height_aligned;
849 p_pic->p->i_visible_lines = i_height;
850 p_pic->p->i_pitch = i_width_aligned;
851 p_pic->p->i_visible_pitch = i_width;
852 p_pic->p->i_pixel_pitch = 4;
858 p_pic->p->i_lines = i_height_aligned;
859 p_pic->p->i_visible_lines = i_height;
860 p_pic->p->i_pitch = i_width_aligned * 2;
861 p_pic->p->i_visible_pitch = i_width * 2;
862 p_pic->p->i_pixel_pitch = 4;
867 p_pic->p->i_lines = i_height_aligned;
868 p_pic->p->i_visible_lines = i_height;
869 p_pic->p->i_pitch = i_width_aligned;
870 p_pic->p->i_visible_pitch = i_width;
871 p_pic->p->i_pixel_pitch = 1;
876 p_pic->p->i_lines = i_height_aligned;
877 p_pic->p->i_visible_lines = i_height;
878 p_pic->p->i_pitch = i_width_aligned * 2;
879 p_pic->p->i_visible_pitch = i_width * 2;
880 p_pic->p->i_pixel_pitch = 2;
885 p_pic->p->i_lines = i_height_aligned;
886 p_pic->p->i_visible_lines = i_height;
887 p_pic->p->i_pitch = i_width_aligned * 2;
888 p_pic->p->i_visible_pitch = i_width * 2;
889 p_pic->p->i_pixel_pitch = 2;
894 p_pic->p->i_lines = i_height_aligned;
895 p_pic->p->i_visible_lines = i_height;
896 p_pic->p->i_pitch = i_width_aligned * 3;
897 p_pic->p->i_visible_pitch = i_width * 3;
898 p_pic->p->i_pixel_pitch = 3;
904 p_pic->p->i_lines = i_height_aligned;
905 p_pic->p->i_visible_lines = i_height;
906 p_pic->p->i_pitch = i_width_aligned * 4;
907 p_pic->p->i_visible_pitch = i_width * 4;
908 p_pic->p->i_pixel_pitch = 4;
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;
919 p_pic->p->i_visible_pitch = i_width;
920 p_pic->p->i_pixel_pitch = 1;
926 msg_Err( p_this, "unknown chroma type 0x%.8x (%4.4s)",
927 i_chroma, (char*)&i_chroma );
936 * Compare two chroma values
938 * This function returns 1 if the two fourcc values given as argument are
939 * the same format (eg. UYVY/UYNV) or almost the same format (eg. I420/YV12)
941 int vout_ChromaCmp( vlc_fourcc_t i_chroma, vlc_fourcc_t i_amorhc )
943 /* If they are the same, they are the same ! */
944 if( i_chroma == i_amorhc )
949 /* Check for equivalence classes */
1011 /*****************************************************************************
1013 *****************************************************************************/
1014 static void PictureReleaseCallback( picture_t *p_picture )
1016 if( --p_picture->i_refcount > 0 )
1018 picture_Delete( p_picture );
1020 /*****************************************************************************
1022 *****************************************************************************/
1023 picture_t *picture_New( vlc_fourcc_t i_chroma, int i_width, int i_height, int i_aspect )
1025 picture_t *p_picture = calloc( 1, sizeof(*p_picture) );
1029 if( __vout_AllocatePicture( NULL, p_picture,
1030 i_chroma, i_width, i_height, i_aspect ) )
1036 p_picture->i_refcount = 1;
1037 p_picture->pf_release = PictureReleaseCallback;
1038 p_picture->i_status = RESERVED_PICTURE;
1043 /*****************************************************************************
1045 *****************************************************************************/
1046 void picture_Delete( picture_t *p_picture )
1048 assert( p_picture && p_picture->i_refcount == 0 );
1050 free( p_picture->p_q );
1051 free( p_picture->p_data_orig );
1052 free( p_picture->p_sys );
1056 /*****************************************************************************
1058 *****************************************************************************/
1059 void picture_CopyPixels( picture_t *p_dst, const picture_t *p_src )
1063 for( i = 0; i < p_src->i_planes ; i++ )
1064 plane_CopyPixels( p_dst->p+i, p_src->p+i );
1067 void plane_CopyPixels( plane_t *p_dst, const plane_t *p_src )
1069 const unsigned i_width = __MIN( p_dst->i_visible_pitch,
1070 p_src->i_visible_pitch );
1071 const unsigned i_height = __MIN( p_dst->i_visible_lines,
1072 p_src->i_visible_lines );
1074 if( p_src->i_pitch == p_dst->i_pitch )
1076 /* There are margins, but with the same width : perfect ! */
1077 vlc_memcpy( p_dst->p_pixels, p_src->p_pixels,
1078 p_src->i_pitch * i_height );
1082 /* We need to proceed line by line */
1083 uint8_t *p_in = p_src->p_pixels;
1084 uint8_t *p_out = p_dst->p_pixels;
1090 for( i_line = i_height; i_line--; )
1092 vlc_memcpy( p_out, p_in, i_width );
1093 p_in += p_src->i_pitch;
1094 p_out += p_dst->i_pitch;
1099 /*****************************************************************************
1101 *****************************************************************************/