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 *****************************************************************************/
33 #include <vlc_common.h>
36 #include <vlc_filter.h>
37 #include "vout_pictures.h"
38 #include "vout_internal.h"
45 * Remove the reservation flag of a picture, which will cause it to be ready
46 * for display. The picture won't be displayed until vout_DatePicture has been
49 void vout_DisplayPicture( vout_thread_t *p_vout, picture_t *p_pic )
51 vlc_mutex_lock( &p_vout->picture_lock );
52 switch( p_pic->i_status )
54 case RESERVED_PICTURE:
55 p_pic->i_status = RESERVED_DISP_PICTURE;
57 case RESERVED_DATED_PICTURE:
58 p_pic->i_status = READY_PICTURE;
61 msg_Err( p_vout, "picture to display %p has invalid status %d",
62 p_pic, p_pic->i_status );
66 vlc_mutex_unlock( &p_vout->picture_lock );
72 * Remove the reservation flag of a picture, which will cause it to be ready
73 * for display. The picture won't be displayed until vout_DisplayPicture has
75 * \param p_vout The vout in question
76 * \param p_pic The picture to date
77 * \param date The date to display the picture
79 void vout_DatePicture( vout_thread_t *p_vout,
80 picture_t *p_pic, mtime_t date )
82 vlc_mutex_lock( &p_vout->picture_lock );
84 switch( p_pic->i_status )
86 case RESERVED_PICTURE:
87 p_pic->i_status = RESERVED_DATED_PICTURE;
89 case RESERVED_DISP_PICTURE:
90 p_pic->i_status = READY_PICTURE;
93 msg_Err( p_vout, "picture to date %p has invalid status %d",
94 p_pic, p_pic->i_status );
98 vlc_mutex_unlock( &p_vout->picture_lock );
102 * Allocate a picture in the video output heap.
104 * This function creates a reserved image in the video output heap.
105 * A null pointer is returned if the function fails. This method provides an
106 * already allocated zone of memory in the picture data fields.
107 * It needs locking since several pictures can be created by several producers
110 int vout_CountPictureAvailable( vout_thread_t *p_vout )
115 vlc_mutex_lock( &p_vout->picture_lock );
116 for( i_pic = 0; i_pic < I_RENDERPICTURES; i_pic++ )
118 picture_t *p_pic = PP_RENDERPICTURE[(p_vout->render.i_last_used_pic + i_pic + 1) % I_RENDERPICTURES];
120 switch( p_pic->i_status )
122 case DESTROYED_PICTURE:
134 vlc_mutex_unlock( &p_vout->picture_lock );
139 picture_t *vout_CreatePicture( vout_thread_t *p_vout,
141 bool b_top_field_first,
142 unsigned int i_nb_fields )
144 int i_pic; /* picture index */
146 picture_t * p_freepic = NULL; /* first free picture */
149 vlc_mutex_lock( &p_vout->picture_lock );
152 * Look for an empty place in the picture heap.
154 for( i_pic = 0; i_pic < I_RENDERPICTURES; i_pic++ )
156 p_pic = PP_RENDERPICTURE[(p_vout->render.i_last_used_pic + i_pic + 1)
159 switch( p_pic->i_status )
161 case DESTROYED_PICTURE:
162 /* Memory will not be reallocated, and function can end
163 * immediately - this is the best possible case, since no
164 * memory allocation needs to be done */
165 p_pic->i_status = RESERVED_PICTURE;
166 p_pic->i_refcount = 0;
169 p_pic->b_progressive = b_progressive;
170 p_pic->i_nb_fields = i_nb_fields;
171 p_pic->b_top_field_first = b_top_field_first;
173 p_vout->i_heap_size++;
174 p_vout->render.i_last_used_pic =
175 ( p_vout->render.i_last_used_pic + i_pic + 1 )
177 vlc_mutex_unlock( &p_vout->picture_lock );
181 /* Picture is empty and ready for allocation */
182 p_vout->render.i_last_used_pic =
183 ( p_vout->render.i_last_used_pic + i_pic + 1 )
196 if( p_freepic != NULL )
198 vout_AllocatePicture( VLC_OBJECT(p_vout),
199 p_freepic, p_vout->render.i_chroma,
200 p_vout->render.i_width, p_vout->render.i_height,
201 p_vout->render.i_aspect );
203 if( p_freepic->i_planes )
205 /* Copy picture information, set some default values */
206 p_freepic->i_status = RESERVED_PICTURE;
207 p_freepic->i_type = MEMORY_PICTURE;
208 p_freepic->b_slow = 0;
210 p_freepic->i_refcount = 0;
211 p_freepic->b_force = 0;
213 p_freepic->b_progressive = b_progressive;
214 p_freepic->i_nb_fields = i_nb_fields;
215 p_freepic->b_top_field_first = b_top_field_first;
217 p_freepic->i_matrix_coefficients = 1;
219 p_vout->i_heap_size++;
223 /* Memory allocation failed : set picture as empty */
224 p_freepic->i_status = FREE_PICTURE;
227 msg_Err( p_vout, "picture allocation failed" );
230 vlc_mutex_unlock( &p_vout->picture_lock );
235 /* No free or destroyed picture could be found, but the decoder
236 * will try again in a while. */
237 vlc_mutex_unlock( &p_vout->picture_lock );
243 * Remove a permanent or reserved picture from the heap
245 * This function frees a previously reserved picture or a permanent
246 * picture. It is meant to be used when the construction of a picture aborted.
247 * Note that the picture will be destroyed even if it is linked !
249 void vout_DestroyPicture( vout_thread_t *p_vout, picture_t *p_pic )
251 vlc_mutex_lock( &p_vout->picture_lock );
254 /* Check if picture status is valid */
255 if( (p_pic->i_status != RESERVED_PICTURE) &&
256 (p_pic->i_status != RESERVED_DATED_PICTURE) &&
257 (p_pic->i_status != RESERVED_DISP_PICTURE) )
259 msg_Err( p_vout, "picture to destroy %p has invalid status %d",
260 p_pic, p_pic->i_status );
264 p_pic->i_status = DESTROYED_PICTURE;
265 p_vout->i_heap_size--;
266 picture_CleanupQuant( p_pic );
268 vlc_mutex_unlock( &p_vout->picture_lock );
272 void vout_DropPicture( vout_thread_t *p_vout, picture_t *p_pic )
274 vlc_mutex_lock( &p_vout->picture_lock );
276 if( p_pic->i_status == READY_PICTURE )
278 /* Grr cannot destroy ready picture by myself so be sure vout won't like it */
281 else if( p_pic->i_refcount > 0 )
283 p_pic->i_status = DISPLAYED_PICTURE;
287 p_pic->i_status = DESTROYED_PICTURE;
288 p_vout->i_heap_size--;
289 picture_CleanupQuant( p_pic );
292 vlc_mutex_unlock( &p_vout->picture_lock );
296 * Increment reference counter of a picture
298 * This function increments the reference counter of a picture in the video
299 * heap. It needs a lock since several producer threads can access the picture.
301 void vout_LinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
303 vlc_mutex_lock( &p_vout->picture_lock );
305 vlc_mutex_unlock( &p_vout->picture_lock );
309 * Decrement reference counter of a picture
311 * This function decrement the reference counter of a picture in the video heap
313 void vout_UnlinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
315 vlc_mutex_lock( &p_vout->picture_lock );
318 if( ( p_pic->i_refcount == 0 ) &&
319 ( p_pic->i_status == DISPLAYED_PICTURE ) )
321 p_pic->i_status = DESTROYED_PICTURE;
322 p_vout->i_heap_size--;
323 picture_CleanupQuant( p_pic );
326 vlc_mutex_unlock( &p_vout->picture_lock );
329 static int vout_LockPicture( vout_thread_t *p_vout, picture_t *p_picture )
331 if( p_picture->pf_lock )
332 return p_picture->pf_lock( p_vout, p_picture );
335 static void vout_UnlockPicture( vout_thread_t *p_vout, picture_t *p_picture )
337 if( p_picture->pf_unlock )
338 p_picture->pf_unlock( p_vout, p_picture );
344 * This function chooses whether the current picture needs to be copied
345 * before rendering, does the subpicture magic, and tells the video output
346 * thread which direct buffer needs to be displayed.
348 picture_t *vout_RenderPicture( vout_thread_t *p_vout, picture_t *p_pic,
349 subpicture_t *p_subpic, bool b_paused )
354 if( p_pic->i_type == DIRECT_PICTURE )
356 /* Picture is in a direct buffer. */
358 if( p_subpic != NULL )
360 /* We have subtitles. First copy the picture to
361 * the spare direct buffer, then render the
363 if( vout_LockPicture( p_vout, PP_OUTPUTPICTURE[0] ) )
366 picture_Copy( PP_OUTPUTPICTURE[0], p_pic );
368 spu_RenderSubpictures( p_vout->p_spu,
369 PP_OUTPUTPICTURE[0], &p_vout->fmt_out,
370 p_subpic, &p_vout->fmt_in, b_paused );
372 vout_UnlockPicture( p_vout, PP_OUTPUTPICTURE[0] );
374 return PP_OUTPUTPICTURE[0];
377 /* No subtitles, picture is in a directbuffer so
378 * we can display it directly (even if it is still
383 /* Not a direct buffer. We either need to copy it to a direct buffer,
384 * or render it if the chroma isn't the same. */
385 if( p_vout->p->b_direct )
387 /* Picture is not in a direct buffer, but is exactly the
388 * same size as the direct buffers. A memcpy() is enough,
389 * then render the subtitles. */
391 if( vout_LockPicture( p_vout, PP_OUTPUTPICTURE[0] ) )
394 picture_Copy( PP_OUTPUTPICTURE[0], p_pic );
395 spu_RenderSubpictures( p_vout->p_spu,
396 PP_OUTPUTPICTURE[0], &p_vout->fmt_out,
397 p_subpic, &p_vout->fmt_in, b_paused );
399 vout_UnlockPicture( p_vout, PP_OUTPUTPICTURE[0] );
401 return PP_OUTPUTPICTURE[0];
404 /* Picture is not in a direct buffer, and needs to be converted to
405 * another size/chroma. Then the subtitles need to be rendered as
406 * well. This usually means software YUV, or hardware YUV with a
407 * different chroma. */
409 if( p_subpic != NULL && p_vout->p_picture[0].b_slow )
411 /* The picture buffer is in slow memory. We'll use
412 * the "2 * VOUT_MAX_PICTURES + 1" picture as a temporary
413 * one for subpictures rendering. */
414 picture_t *p_tmp_pic = &p_vout->p_picture[2 * VOUT_MAX_PICTURES];
415 if( p_tmp_pic->i_status == FREE_PICTURE )
417 vout_AllocatePicture( VLC_OBJECT(p_vout),
418 p_tmp_pic, p_vout->fmt_out.i_chroma,
419 p_vout->fmt_out.i_width,
420 p_vout->fmt_out.i_height,
421 p_vout->fmt_out.i_aspect );
422 p_tmp_pic->i_type = MEMORY_PICTURE;
423 p_tmp_pic->i_status = RESERVED_PICTURE;
424 /* some modules (such as blend) needs to know the extra information in picture heap */
425 p_tmp_pic->p_heap = &p_vout->output;
428 /* Convert image to the first direct buffer */
429 p_vout->p->p_chroma->p_owner = (filter_owner_sys_t *)p_tmp_pic;
430 p_vout->p->p_chroma->pf_video_filter( p_vout->p->p_chroma, p_pic );
432 /* Render subpictures on the first direct buffer */
433 spu_RenderSubpictures( p_vout->p_spu,
434 p_tmp_pic, &p_vout->fmt_out,
435 p_subpic, &p_vout->fmt_in, b_paused );
437 if( vout_LockPicture( p_vout, &p_vout->p_picture[0] ) )
440 picture_Copy( &p_vout->p_picture[0], p_tmp_pic );
444 if( vout_LockPicture( p_vout, &p_vout->p_picture[0] ) )
447 /* Convert image to the first direct buffer */
448 p_vout->p->p_chroma->p_owner = (filter_owner_sys_t *)&p_vout->p_picture[0];
449 p_vout->p->p_chroma->pf_video_filter( p_vout->p->p_chroma, p_pic );
451 /* Render subpictures on the first direct buffer */
452 spu_RenderSubpictures( p_vout->p_spu,
453 &p_vout->p_picture[0], &p_vout->fmt_out,
454 p_subpic, &p_vout->fmt_in, b_paused );
457 vout_UnlockPicture( p_vout, &p_vout->p_picture[0] );
459 return &p_vout->p_picture[0];
463 * Calculate image window coordinates
465 * This function will be accessed by plugins. It calculates the relative
466 * position of the output window and the image window.
468 void vout_PlacePicture( vout_thread_t *p_vout,
469 unsigned int i_width, unsigned int i_height,
470 unsigned int *pi_x, unsigned int *pi_y,
471 unsigned int *pi_width, unsigned int *pi_height )
473 if( (i_width <= 0) || (i_height <=0) )
475 *pi_width = *pi_height = *pi_x = *pi_y = 0;
479 if( p_vout->b_scale )
482 *pi_height = i_height;
486 *pi_width = __MIN( i_width, p_vout->fmt_in.i_visible_width );
487 *pi_height = __MIN( i_height, p_vout->fmt_in.i_visible_height );
490 int64_t i_scaled_width = p_vout->fmt_in.i_visible_width * (int64_t)p_vout->fmt_in.i_sar_num *
491 *pi_height / p_vout->fmt_in.i_visible_height / p_vout->fmt_in.i_sar_den;
492 int64_t i_scaled_height = p_vout->fmt_in.i_visible_height * (int64_t)p_vout->fmt_in.i_sar_den *
493 *pi_width / p_vout->fmt_in.i_visible_width / p_vout->fmt_in.i_sar_num;
495 if( i_scaled_width <= 0 || i_scaled_height <= 0 )
497 msg_Warn( p_vout, "ignoring broken aspect ratio" );
498 i_scaled_width = *pi_width;
499 i_scaled_height = *pi_height;
502 if( i_scaled_width > *pi_width )
503 *pi_height = i_scaled_height;
505 *pi_width = i_scaled_width;
507 switch( p_vout->i_alignment & VOUT_ALIGN_HMASK )
509 case VOUT_ALIGN_LEFT:
512 case VOUT_ALIGN_RIGHT:
513 *pi_x = i_width - *pi_width;
516 *pi_x = ( i_width - *pi_width ) / 2;
519 switch( p_vout->i_alignment & VOUT_ALIGN_VMASK )
524 case VOUT_ALIGN_BOTTOM:
525 *pi_y = i_height - *pi_height;
528 *pi_y = ( i_height - *pi_height ) / 2;
533 * Allocate a new picture in the heap.
535 * This function allocates a fake direct buffer in memory, which can be
536 * used exactly like a video buffer. The video output thread then manages
537 * how it gets displayed.
539 int __vout_AllocatePicture( vlc_object_t *p_this, picture_t *p_pic,
540 vlc_fourcc_t i_chroma,
541 int i_width, int i_height, int i_aspect )
543 int i_bytes, i_index, i_width_aligned, i_height_aligned;
545 /* Make sure the real dimensions are a multiple of 16 */
546 i_width_aligned = (i_width + 15) >> 4 << 4;
547 i_height_aligned = (i_height + 15) >> 4 << 4;
549 if( vout_InitPicture( p_this, p_pic, i_chroma,
550 i_width, i_height, i_aspect ) != VLC_SUCCESS )
556 /* Calculate how big the new image should be */
557 i_bytes = p_pic->format.i_bits_per_pixel *
558 i_width_aligned * i_height_aligned / 8;
560 p_pic->p_data = vlc_memalign( &p_pic->p_data_orig, 16, i_bytes );
562 if( p_pic->p_data == NULL )
568 /* Fill the p_pixels field for each plane */
569 p_pic->p[ 0 ].p_pixels = p_pic->p_data;
571 for( i_index = 1; i_index < p_pic->i_planes; i_index++ )
573 p_pic->p[i_index].p_pixels = p_pic->p[i_index-1].p_pixels +
574 p_pic->p[i_index-1].i_lines * p_pic->p[i_index-1].i_pitch;
581 * Initialise the video format fields given chroma/size.
583 * This function initializes all the video_frame_format_t fields given the
584 * static properties of a picture (chroma and size).
585 * \param p_format Pointer to the format structure to initialize
586 * \param i_chroma Chroma to set
587 * \param i_width Width to set
588 * \param i_height Height to set
589 * \param i_aspect Aspect ratio
591 void vout_InitFormat( video_frame_format_t *p_format, vlc_fourcc_t i_chroma,
592 int i_width, int i_height, int i_aspect )
594 p_format->i_chroma = i_chroma;
595 p_format->i_width = p_format->i_visible_width = i_width;
596 p_format->i_height = p_format->i_visible_height = i_height;
597 p_format->i_x_offset = p_format->i_y_offset = 0;
598 p_format->i_aspect = i_aspect;
601 /* Assume we have square pixels */
602 if( i_width && i_height )
603 p_format->i_aspect = i_width * VOUT_ASPECT_FACTOR / i_height;
605 p_format->i_aspect = 0;
611 p_format->i_bits_per_pixel = 32;
615 p_format->i_bits_per_pixel = 24;
621 p_format->i_bits_per_pixel = 16;
625 p_format->i_bits_per_pixel = 16;
632 p_format->i_bits_per_pixel = 12;
636 p_format->i_bits_per_pixel = 9;
639 p_format->i_bits_per_pixel = 8;
642 p_format->i_bits_per_pixel = 8;
647 p_format->i_bits_per_pixel = 32;
650 p_format->i_bits_per_pixel = 24;
654 p_format->i_bits_per_pixel = 16;
657 p_format->i_bits_per_pixel = 8;
664 p_format->i_bits_per_pixel = 8;
668 p_format->i_bits_per_pixel = 0;
674 * Initialise the picture_t fields given chroma/size.
676 * This function initializes most of the picture_t fields given a chroma and
677 * size. It makes the assumption that stride == width.
678 * \param p_this The calling object
679 * \param p_pic Pointer to the picture to initialize
680 * \param i_chroma The chroma fourcc to set
681 * \param i_width The width of the picture
682 * \param i_height The height of the picture
683 * \param i_aspect The aspect ratio of the picture
685 int __vout_InitPicture( vlc_object_t *p_this, picture_t *p_pic,
686 vlc_fourcc_t i_chroma,
687 int i_width, int i_height, int i_aspect )
689 int i_index, i_width_aligned, i_height_aligned;
691 /* Store default values */
692 for( i_index = 0; i_index < VOUT_MAX_PLANES; i_index++ )
694 p_pic->p[i_index].p_pixels = NULL;
695 p_pic->p[i_index].i_pixel_pitch = 1;
698 p_pic->pf_release = NULL;
699 p_pic->pf_lock = NULL;
700 p_pic->pf_unlock = NULL;
701 p_pic->i_refcount = 0;
704 p_pic->i_qstride = 0;
707 vout_InitFormat( &p_pic->format, i_chroma, i_width, i_height, i_aspect );
709 /* Make sure the real dimensions are a multiple of 16 */
710 i_width_aligned = (i_width + 15) >> 4 << 4;
711 i_height_aligned = (i_height + 15) >> 4 << 4;
713 /* Calculate coordinates */
717 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
718 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
719 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
720 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
721 p_pic->p[ U_PLANE ].i_lines = i_height_aligned;
722 p_pic->p[ U_PLANE ].i_visible_lines = i_height;
723 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 4;
724 p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 4;
725 p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
726 p_pic->p[ V_PLANE ].i_visible_lines = i_height;
727 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 4;
728 p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 4;
734 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
735 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
736 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
737 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
738 p_pic->p[ U_PLANE ].i_lines = i_height_aligned / 4;
739 p_pic->p[ U_PLANE ].i_visible_lines = i_height / 4;
740 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 4;
741 p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 4;
742 p_pic->p[ V_PLANE ].i_lines = i_height_aligned / 4;
743 p_pic->p[ V_PLANE ].i_visible_lines = i_height / 4;
744 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 4;
745 p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 4;
753 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
754 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
755 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
756 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
757 p_pic->p[ U_PLANE ].i_lines = i_height_aligned / 2;
758 p_pic->p[ U_PLANE ].i_visible_lines = i_height / 2;
759 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 2;
760 p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 2;
761 p_pic->p[ V_PLANE ].i_lines = i_height_aligned / 2;
762 p_pic->p[ V_PLANE ].i_visible_lines = i_height / 2;
763 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 2;
764 p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 2;
770 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
771 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
772 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
773 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
774 p_pic->p[ U_PLANE ].i_lines = i_height_aligned;
775 p_pic->p[ U_PLANE ].i_visible_lines = i_height;
776 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 2;
777 p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 2;
778 p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
779 p_pic->p[ V_PLANE ].i_visible_lines = i_height;
780 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 2;
781 p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 2;
787 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
788 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
789 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
790 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
791 p_pic->p[ U_PLANE ].i_lines = i_height_aligned / 2;
792 p_pic->p[ U_PLANE ].i_visible_lines = i_height / 2;
793 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned;
794 p_pic->p[ U_PLANE ].i_visible_pitch = i_width;
795 p_pic->p[ V_PLANE ].i_lines = i_height_aligned / 2;
796 p_pic->p[ V_PLANE ].i_visible_lines = i_height / 2;
797 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned;
798 p_pic->p[ V_PLANE ].i_visible_pitch = i_width;
804 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
805 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
806 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
807 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
808 p_pic->p[ U_PLANE ].i_lines = i_height_aligned;
809 p_pic->p[ U_PLANE ].i_visible_lines = i_height;
810 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned;
811 p_pic->p[ U_PLANE ].i_visible_pitch = i_width;
812 p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
813 p_pic->p[ V_PLANE ].i_visible_lines = i_height;
814 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned;
815 p_pic->p[ V_PLANE ].i_visible_pitch = i_width;
820 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
821 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
822 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
823 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
824 p_pic->p[ U_PLANE ].i_lines = i_height_aligned;
825 p_pic->p[ U_PLANE ].i_visible_lines = i_height;
826 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned;
827 p_pic->p[ U_PLANE ].i_visible_pitch = i_width;
828 p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
829 p_pic->p[ V_PLANE ].i_visible_lines = i_height;
830 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned;
831 p_pic->p[ V_PLANE ].i_visible_pitch = i_width;
832 p_pic->p[ A_PLANE ].i_lines = i_height_aligned;
833 p_pic->p[ A_PLANE ].i_visible_lines = i_height;
834 p_pic->p[ A_PLANE ].i_pitch = i_width_aligned;
835 p_pic->p[ A_PLANE ].i_visible_pitch = i_width;
840 p_pic->p->i_lines = i_height_aligned;
841 p_pic->p->i_visible_lines = i_height;
842 p_pic->p->i_pitch = i_width_aligned;
843 p_pic->p->i_visible_pitch = i_width;
844 p_pic->p->i_pixel_pitch = 8;
849 p_pic->p->i_lines = i_height_aligned;
850 p_pic->p->i_visible_lines = i_height;
851 p_pic->p->i_pitch = i_width_aligned;
852 p_pic->p->i_visible_pitch = i_width;
853 p_pic->p->i_pixel_pitch = 4;
859 p_pic->p->i_lines = i_height_aligned;
860 p_pic->p->i_visible_lines = i_height;
861 p_pic->p->i_pitch = i_width_aligned * 2;
862 p_pic->p->i_visible_pitch = i_width * 2;
863 p_pic->p->i_pixel_pitch = 4;
868 p_pic->p->i_lines = i_height_aligned;
869 p_pic->p->i_visible_lines = i_height;
870 p_pic->p->i_pitch = i_width_aligned;
871 p_pic->p->i_visible_pitch = i_width;
872 p_pic->p->i_pixel_pitch = 1;
877 p_pic->p->i_lines = i_height_aligned;
878 p_pic->p->i_visible_lines = i_height;
879 p_pic->p->i_pitch = i_width_aligned * 2;
880 p_pic->p->i_visible_pitch = i_width * 2;
881 p_pic->p->i_pixel_pitch = 2;
886 p_pic->p->i_lines = i_height_aligned;
887 p_pic->p->i_visible_lines = i_height;
888 p_pic->p->i_pitch = i_width_aligned * 2;
889 p_pic->p->i_visible_pitch = i_width * 2;
890 p_pic->p->i_pixel_pitch = 2;
895 p_pic->p->i_lines = i_height_aligned;
896 p_pic->p->i_visible_lines = i_height;
897 p_pic->p->i_pitch = i_width_aligned * 3;
898 p_pic->p->i_visible_pitch = i_width * 3;
899 p_pic->p->i_pixel_pitch = 3;
905 p_pic->p->i_lines = i_height_aligned;
906 p_pic->p->i_visible_lines = i_height;
907 p_pic->p->i_pitch = i_width_aligned * 4;
908 p_pic->p->i_visible_pitch = i_width * 4;
909 p_pic->p->i_pixel_pitch = 4;
917 p_pic->p->i_lines = i_height_aligned;
918 p_pic->p->i_visible_lines = i_height;
919 p_pic->p->i_pitch = i_width_aligned;
920 p_pic->p->i_visible_pitch = i_width;
921 p_pic->p->i_pixel_pitch = 1;
927 msg_Err( p_this, "unknown chroma type 0x%.8x (%4.4s)",
928 i_chroma, (char*)&i_chroma );
937 * Compare two chroma values
939 * This function returns 1 if the two fourcc values given as argument are
940 * the same format (eg. UYVY/UYNV) or almost the same format (eg. I420/YV12)
942 int vout_ChromaCmp( vlc_fourcc_t i_chroma, vlc_fourcc_t i_amorhc )
944 /* If they are the same, they are the same ! */
945 if( i_chroma == i_amorhc )
950 /* Check for equivalence classes */
1012 /*****************************************************************************
1014 *****************************************************************************/
1015 static void PictureReleaseCallback( picture_t *p_picture )
1017 if( --p_picture->i_refcount > 0 )
1019 picture_Delete( p_picture );
1021 /*****************************************************************************
1023 *****************************************************************************/
1024 picture_t *picture_New( vlc_fourcc_t i_chroma, int i_width, int i_height, int i_aspect )
1026 picture_t *p_picture = malloc( sizeof(*p_picture) );
1031 memset( p_picture, 0, sizeof(*p_picture) );
1032 if( __vout_AllocatePicture( NULL, p_picture,
1033 i_chroma, i_width, i_height, i_aspect ) )
1039 p_picture->i_refcount = 1;
1040 p_picture->pf_release = PictureReleaseCallback;
1041 p_picture->i_status = RESERVED_PICTURE;
1046 /*****************************************************************************
1048 *****************************************************************************/
1049 void picture_Delete( picture_t *p_picture )
1051 assert( p_picture && p_picture->i_refcount == 0 );
1053 free( p_picture->p_q );
1054 free( p_picture->p_data_orig );
1055 free( p_picture->p_sys );
1059 /*****************************************************************************
1061 *****************************************************************************/
1062 void picture_CopyPixels( picture_t *p_dst, const picture_t *p_src )
1066 for( i = 0; i < p_src->i_planes ; i++ )
1067 plane_CopyPixels( p_dst->p+i, p_src->p+i );
1070 void plane_CopyPixels( plane_t *p_dst, const plane_t *p_src )
1072 const unsigned i_width = __MIN( p_dst->i_visible_pitch,
1073 p_src->i_visible_pitch );
1074 const unsigned i_height = __MIN( p_dst->i_visible_lines,
1075 p_src->i_visible_lines );
1077 if( p_src->i_pitch == p_dst->i_pitch )
1079 /* There are margins, but with the same width : perfect ! */
1080 vlc_memcpy( p_dst->p_pixels, p_src->p_pixels,
1081 p_src->i_pitch * i_height );
1085 /* We need to proceed line by line */
1086 uint8_t *p_in = p_src->p_pixels;
1087 uint8_t *p_out = p_dst->p_pixels;
1093 for( i_line = i_height; i_line--; )
1095 vlc_memcpy( p_out, p_in, i_width );
1096 p_in += p_src->i_pitch;
1097 p_out += p_dst->i_pitch;
1102 /*****************************************************************************
1104 *****************************************************************************/