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
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;
58 msg_Err( p_vout, "picture to display %p has invalid status %d",
59 p_pic, p_pic->i_status );
62 vlc_mutex_unlock( &p_vout->picture_lock );
66 * Allocate a picture in the video output heap.
68 * This function creates a reserved image in the video output heap.
69 * A null pointer is returned if the function fails. This method provides an
70 * already allocated zone of memory in the picture data fields.
71 * It needs locking since several pictures can be created by several producers
74 int vout_CountPictureAvailable( vout_thread_t *p_vout )
79 vlc_mutex_lock( &p_vout->picture_lock );
80 for( i_pic = 0; i_pic < I_RENDERPICTURES; i_pic++ )
82 picture_t *p_pic = PP_RENDERPICTURE[(p_vout->render.i_last_used_pic + i_pic + 1) % I_RENDERPICTURES];
84 switch( p_pic->i_status )
86 case DESTROYED_PICTURE:
98 vlc_mutex_unlock( &p_vout->picture_lock );
103 picture_t *vout_CreatePicture( vout_thread_t *p_vout,
105 bool b_top_field_first,
106 unsigned int i_nb_fields )
108 int i_pic; /* picture index */
110 picture_t * p_freepic = NULL; /* first free picture */
113 vlc_mutex_lock( &p_vout->picture_lock );
116 * Look for an empty place in the picture heap.
118 for( i_pic = 0; i_pic < I_RENDERPICTURES; i_pic++ )
120 p_pic = PP_RENDERPICTURE[(p_vout->render.i_last_used_pic + i_pic + 1)
123 switch( p_pic->i_status )
125 case DESTROYED_PICTURE:
126 /* Memory will not be reallocated, and function can end
127 * immediately - this is the best possible case, since no
128 * memory allocation needs to be done */
129 p_pic->i_status = RESERVED_PICTURE;
130 p_pic->i_refcount = 0;
133 p_pic->b_progressive = b_progressive;
134 p_pic->i_nb_fields = i_nb_fields;
135 p_pic->b_top_field_first = b_top_field_first;
137 p_vout->i_heap_size++;
138 p_vout->render.i_last_used_pic =
139 ( p_vout->render.i_last_used_pic + i_pic + 1 )
141 vlc_mutex_unlock( &p_vout->picture_lock );
145 /* Picture is empty and ready for allocation */
146 p_vout->render.i_last_used_pic =
147 ( p_vout->render.i_last_used_pic + i_pic + 1 )
160 if( p_freepic != NULL )
162 vout_AllocatePicture( VLC_OBJECT(p_vout),
163 p_freepic, p_vout->render.i_chroma,
164 p_vout->render.i_width, p_vout->render.i_height,
165 p_vout->render.i_aspect );
167 if( p_freepic->i_planes )
169 /* Copy picture information, set some default values */
170 p_freepic->i_status = RESERVED_PICTURE;
171 p_freepic->i_type = MEMORY_PICTURE;
172 p_freepic->b_slow = 0;
174 p_freepic->i_refcount = 0;
175 p_freepic->b_force = 0;
177 p_freepic->b_progressive = b_progressive;
178 p_freepic->i_nb_fields = i_nb_fields;
179 p_freepic->b_top_field_first = b_top_field_first;
181 p_vout->i_heap_size++;
185 /* Memory allocation failed : set picture as empty */
186 p_freepic->i_status = FREE_PICTURE;
189 msg_Err( p_vout, "picture allocation failed" );
192 vlc_mutex_unlock( &p_vout->picture_lock );
197 /* No free or destroyed picture could be found, but the decoder
198 * will try again in a while. */
199 vlc_mutex_unlock( &p_vout->picture_lock );
205 * Remove a permanent or reserved picture from the heap
207 * This function frees a previously reserved picture or a permanent
208 * picture. It is meant to be used when the construction of a picture aborted.
209 * Note that the picture will be destroyed even if it is linked !
211 void vout_DestroyPicture( vout_thread_t *p_vout, picture_t *p_pic )
213 vlc_mutex_lock( &p_vout->picture_lock );
216 /* Check if picture status is valid */
217 if( p_pic->i_status != RESERVED_PICTURE )
219 msg_Err( p_vout, "picture to destroy %p has invalid status %d",
220 p_pic, p_pic->i_status );
224 p_pic->i_status = DESTROYED_PICTURE;
225 p_vout->i_heap_size--;
226 picture_CleanupQuant( p_pic );
228 vlc_mutex_unlock( &p_vout->picture_lock );
232 void vout_DropPicture( vout_thread_t *p_vout, picture_t *p_pic )
234 vlc_mutex_lock( &p_vout->picture_lock );
236 if( p_pic->i_status == READY_PICTURE )
238 /* Grr cannot destroy ready picture by myself so be sure vout won't like it */
241 else if( p_pic->i_refcount > 0 )
243 p_pic->i_status = DISPLAYED_PICTURE;
247 p_pic->i_status = DESTROYED_PICTURE;
248 p_vout->i_heap_size--;
249 picture_CleanupQuant( p_pic );
252 vlc_mutex_unlock( &p_vout->picture_lock );
256 * Increment reference counter of a picture
258 * This function increments the reference counter of a picture in the video
259 * heap. It needs a lock since several producer threads can access the picture.
261 void vout_LinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
263 vlc_mutex_lock( &p_vout->picture_lock );
265 vlc_mutex_unlock( &p_vout->picture_lock );
269 * Decrement reference counter of a picture
271 * This function decrement the reference counter of a picture in the video heap
273 void vout_UnlinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
275 vlc_mutex_lock( &p_vout->picture_lock );
278 if( ( p_pic->i_refcount == 0 ) &&
279 ( p_pic->i_status == DISPLAYED_PICTURE ) )
281 p_pic->i_status = DESTROYED_PICTURE;
282 p_vout->i_heap_size--;
283 picture_CleanupQuant( p_pic );
286 vlc_mutex_unlock( &p_vout->picture_lock );
289 static int vout_LockPicture( vout_thread_t *p_vout, picture_t *p_picture )
291 if( p_picture->pf_lock )
292 return p_picture->pf_lock( p_vout, p_picture );
295 static void vout_UnlockPicture( vout_thread_t *p_vout, picture_t *p_picture )
297 if( p_picture->pf_unlock )
298 p_picture->pf_unlock( p_vout, p_picture );
304 * This function chooses whether the current picture needs to be copied
305 * before rendering, does the subpicture magic, and tells the video output
306 * thread which direct buffer needs to be displayed.
308 picture_t *vout_RenderPicture( vout_thread_t *p_vout, picture_t *p_pic,
309 subpicture_t *p_subpic, bool b_paused )
314 if( p_pic->i_type == DIRECT_PICTURE )
316 /* Picture is in a direct buffer. */
318 if( p_subpic != NULL )
320 /* We have subtitles. First copy the picture to
321 * the spare direct buffer, then render the
323 if( vout_LockPicture( p_vout, PP_OUTPUTPICTURE[0] ) )
326 picture_Copy( PP_OUTPUTPICTURE[0], p_pic );
328 spu_RenderSubpictures( p_vout->p_spu,
329 PP_OUTPUTPICTURE[0], &p_vout->fmt_out,
330 p_subpic, &p_vout->fmt_in, b_paused );
332 vout_UnlockPicture( p_vout, PP_OUTPUTPICTURE[0] );
334 return PP_OUTPUTPICTURE[0];
337 /* No subtitles, picture is in a directbuffer so
338 * we can display it directly (even if it is still
343 /* Not a direct buffer. We either need to copy it to a direct buffer,
344 * or render it if the chroma isn't the same. */
345 if( p_vout->p->b_direct )
347 /* Picture is not in a direct buffer, but is exactly the
348 * same size as the direct buffers. A memcpy() is enough,
349 * then render the subtitles. */
351 if( vout_LockPicture( p_vout, PP_OUTPUTPICTURE[0] ) )
354 picture_Copy( PP_OUTPUTPICTURE[0], p_pic );
355 spu_RenderSubpictures( p_vout->p_spu,
356 PP_OUTPUTPICTURE[0], &p_vout->fmt_out,
357 p_subpic, &p_vout->fmt_in, b_paused );
359 vout_UnlockPicture( p_vout, PP_OUTPUTPICTURE[0] );
361 return PP_OUTPUTPICTURE[0];
364 /* Picture is not in a direct buffer, and needs to be converted to
365 * another size/chroma. Then the subtitles need to be rendered as
366 * well. This usually means software YUV, or hardware YUV with a
367 * different chroma. */
369 if( p_subpic != NULL && p_vout->p_picture[0].b_slow )
371 /* The picture buffer is in slow memory. We'll use
372 * the "2 * VOUT_MAX_PICTURES + 1" picture as a temporary
373 * one for subpictures rendering. */
374 picture_t *p_tmp_pic = &p_vout->p_picture[2 * VOUT_MAX_PICTURES];
375 if( p_tmp_pic->i_status == FREE_PICTURE )
377 vout_AllocatePicture( VLC_OBJECT(p_vout),
378 p_tmp_pic, p_vout->fmt_out.i_chroma,
379 p_vout->fmt_out.i_width,
380 p_vout->fmt_out.i_height,
381 p_vout->fmt_out.i_aspect );
382 p_tmp_pic->i_type = MEMORY_PICTURE;
383 p_tmp_pic->i_status = RESERVED_PICTURE;
384 /* some modules (such as blend) needs to know the extra information in picture heap */
385 p_tmp_pic->p_heap = &p_vout->output;
388 /* Convert image to the first direct buffer */
389 p_vout->p->p_chroma->p_owner = (filter_owner_sys_t *)p_tmp_pic;
390 p_vout->p->p_chroma->pf_video_filter( p_vout->p->p_chroma, p_pic );
392 /* Render subpictures on the first direct buffer */
393 spu_RenderSubpictures( p_vout->p_spu,
394 p_tmp_pic, &p_vout->fmt_out,
395 p_subpic, &p_vout->fmt_in, b_paused );
397 if( vout_LockPicture( p_vout, &p_vout->p_picture[0] ) )
400 picture_Copy( &p_vout->p_picture[0], p_tmp_pic );
404 if( vout_LockPicture( p_vout, &p_vout->p_picture[0] ) )
407 /* Convert image to the first direct buffer */
408 p_vout->p->p_chroma->p_owner = (filter_owner_sys_t *)&p_vout->p_picture[0];
409 p_vout->p->p_chroma->pf_video_filter( p_vout->p->p_chroma, p_pic );
411 /* Render subpictures on the first direct buffer */
412 spu_RenderSubpictures( p_vout->p_spu,
413 &p_vout->p_picture[0], &p_vout->fmt_out,
414 p_subpic, &p_vout->fmt_in, b_paused );
417 vout_UnlockPicture( p_vout, &p_vout->p_picture[0] );
419 return &p_vout->p_picture[0];
423 * Calculate image window coordinates
425 * This function will be accessed by plugins. It calculates the relative
426 * position of the output window and the image window.
428 void vout_PlacePicture( vout_thread_t *p_vout,
429 unsigned int i_width, unsigned int i_height,
430 unsigned int *pi_x, unsigned int *pi_y,
431 unsigned int *pi_width, unsigned int *pi_height )
433 if( (i_width <= 0) || (i_height <=0) )
435 *pi_width = *pi_height = *pi_x = *pi_y = 0;
439 if( p_vout->b_scale )
442 *pi_height = i_height;
446 *pi_width = __MIN( i_width, p_vout->fmt_in.i_visible_width );
447 *pi_height = __MIN( i_height, p_vout->fmt_in.i_visible_height );
450 int64_t i_scaled_width = p_vout->fmt_in.i_visible_width * (int64_t)p_vout->fmt_in.i_sar_num *
451 *pi_height / p_vout->fmt_in.i_visible_height / p_vout->fmt_in.i_sar_den;
452 int64_t i_scaled_height = p_vout->fmt_in.i_visible_height * (int64_t)p_vout->fmt_in.i_sar_den *
453 *pi_width / p_vout->fmt_in.i_visible_width / p_vout->fmt_in.i_sar_num;
455 if( i_scaled_width <= 0 || i_scaled_height <= 0 )
457 msg_Warn( p_vout, "ignoring broken aspect ratio" );
458 i_scaled_width = *pi_width;
459 i_scaled_height = *pi_height;
462 if( i_scaled_width > *pi_width )
463 *pi_height = i_scaled_height;
465 *pi_width = i_scaled_width;
467 switch( p_vout->i_alignment & VOUT_ALIGN_HMASK )
469 case VOUT_ALIGN_LEFT:
472 case VOUT_ALIGN_RIGHT:
473 *pi_x = i_width - *pi_width;
476 *pi_x = ( i_width - *pi_width ) / 2;
479 switch( p_vout->i_alignment & VOUT_ALIGN_VMASK )
484 case VOUT_ALIGN_BOTTOM:
485 *pi_y = i_height - *pi_height;
488 *pi_y = ( i_height - *pi_height ) / 2;
493 * Allocate a new picture in the heap.
495 * This function allocates a fake direct buffer in memory, which can be
496 * used exactly like a video buffer. The video output thread then manages
497 * how it gets displayed.
499 int __vout_AllocatePicture( vlc_object_t *p_this, picture_t *p_pic,
500 vlc_fourcc_t i_chroma,
501 int i_width, int i_height, int i_aspect )
503 int i_bytes, i_index, i_width_aligned, i_height_aligned;
505 /* Make sure the real dimensions are a multiple of 16 */
506 i_width_aligned = (i_width + 15) >> 4 << 4;
507 i_height_aligned = (i_height + 15) >> 4 << 4;
509 if( vout_InitPicture( p_this, p_pic, i_chroma,
510 i_width, i_height, i_aspect ) != VLC_SUCCESS )
516 /* Calculate how big the new image should be */
517 i_bytes = p_pic->format.i_bits_per_pixel *
518 i_width_aligned * i_height_aligned / 8;
520 p_pic->p_data = vlc_memalign( &p_pic->p_data_orig, 16, i_bytes );
522 if( p_pic->p_data == NULL )
528 /* Fill the p_pixels field for each plane */
529 p_pic->p[ 0 ].p_pixels = p_pic->p_data;
531 for( i_index = 1; i_index < p_pic->i_planes; i_index++ )
533 p_pic->p[i_index].p_pixels = p_pic->p[i_index-1].p_pixels +
534 p_pic->p[i_index-1].i_lines * p_pic->p[i_index-1].i_pitch;
541 * Initialise the video format fields given chroma/size.
543 * This function initializes all the video_frame_format_t fields given the
544 * static properties of a picture (chroma and size).
545 * \param p_format Pointer to the format structure to initialize
546 * \param i_chroma Chroma to set
547 * \param i_width Width to set
548 * \param i_height Height to set
549 * \param i_aspect Aspect ratio
551 void vout_InitFormat( video_frame_format_t *p_format, vlc_fourcc_t i_chroma,
552 int i_width, int i_height, int i_aspect )
554 p_format->i_chroma = i_chroma;
555 p_format->i_width = p_format->i_visible_width = i_width;
556 p_format->i_height = p_format->i_visible_height = i_height;
557 p_format->i_x_offset = p_format->i_y_offset = 0;
558 p_format->i_aspect = i_aspect;
561 /* Assume we have square pixels */
562 if( i_width && i_height )
563 p_format->i_aspect = i_width * VOUT_ASPECT_FACTOR / i_height;
565 p_format->i_aspect = 0;
571 p_format->i_bits_per_pixel = 32;
575 p_format->i_bits_per_pixel = 24;
581 p_format->i_bits_per_pixel = 16;
585 p_format->i_bits_per_pixel = 16;
592 p_format->i_bits_per_pixel = 12;
596 p_format->i_bits_per_pixel = 9;
599 p_format->i_bits_per_pixel = 8;
602 p_format->i_bits_per_pixel = 8;
607 p_format->i_bits_per_pixel = 32;
610 p_format->i_bits_per_pixel = 24;
614 p_format->i_bits_per_pixel = 16;
617 p_format->i_bits_per_pixel = 8;
624 p_format->i_bits_per_pixel = 8;
628 p_format->i_bits_per_pixel = 0;
634 * Initialise the picture_t fields given chroma/size.
636 * This function initializes most of the picture_t fields given a chroma and
637 * size. It makes the assumption that stride == width.
638 * \param p_this The calling object
639 * \param p_pic Pointer to the picture to initialize
640 * \param i_chroma The chroma fourcc to set
641 * \param i_width The width of the picture
642 * \param i_height The height of the picture
643 * \param i_aspect The aspect ratio of the picture
645 int __vout_InitPicture( vlc_object_t *p_this, picture_t *p_pic,
646 vlc_fourcc_t i_chroma,
647 int i_width, int i_height, int i_aspect )
649 int i_index, i_width_aligned, i_height_aligned;
651 /* Store default values */
652 for( i_index = 0; i_index < VOUT_MAX_PLANES; i_index++ )
654 p_pic->p[i_index].p_pixels = NULL;
655 p_pic->p[i_index].i_pixel_pitch = 1;
658 p_pic->pf_release = NULL;
659 p_pic->pf_lock = NULL;
660 p_pic->pf_unlock = NULL;
661 p_pic->i_refcount = 0;
664 p_pic->i_qstride = 0;
667 vout_InitFormat( &p_pic->format, i_chroma, i_width, i_height, i_aspect );
669 /* Make sure the real dimensions are a multiple of 16 */
670 i_width_aligned = (i_width + 15) >> 4 << 4;
671 i_height_aligned = (i_height + 15) >> 4 << 4;
673 /* Calculate coordinates */
677 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
678 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
679 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
680 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
681 p_pic->p[ U_PLANE ].i_lines = i_height_aligned;
682 p_pic->p[ U_PLANE ].i_visible_lines = i_height;
683 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 4;
684 p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 4;
685 p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
686 p_pic->p[ V_PLANE ].i_visible_lines = i_height;
687 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 4;
688 p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 4;
694 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
695 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
696 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
697 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
698 p_pic->p[ U_PLANE ].i_lines = i_height_aligned / 4;
699 p_pic->p[ U_PLANE ].i_visible_lines = i_height / 4;
700 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 4;
701 p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 4;
702 p_pic->p[ V_PLANE ].i_lines = i_height_aligned / 4;
703 p_pic->p[ V_PLANE ].i_visible_lines = i_height / 4;
704 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 4;
705 p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 4;
713 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
714 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
715 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
716 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
717 p_pic->p[ U_PLANE ].i_lines = i_height_aligned / 2;
718 p_pic->p[ U_PLANE ].i_visible_lines = i_height / 2;
719 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 2;
720 p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 2;
721 p_pic->p[ V_PLANE ].i_lines = i_height_aligned / 2;
722 p_pic->p[ V_PLANE ].i_visible_lines = i_height / 2;
723 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 2;
724 p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 2;
730 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
731 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
732 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
733 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
734 p_pic->p[ U_PLANE ].i_lines = i_height_aligned;
735 p_pic->p[ U_PLANE ].i_visible_lines = i_height;
736 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 2;
737 p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 2;
738 p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
739 p_pic->p[ V_PLANE ].i_visible_lines = i_height;
740 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 2;
741 p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 2;
747 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
748 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
749 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
750 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
751 p_pic->p[ U_PLANE ].i_lines = i_height_aligned / 2;
752 p_pic->p[ U_PLANE ].i_visible_lines = i_height / 2;
753 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned;
754 p_pic->p[ U_PLANE ].i_visible_pitch = i_width;
755 p_pic->p[ V_PLANE ].i_lines = i_height_aligned / 2;
756 p_pic->p[ V_PLANE ].i_visible_lines = i_height / 2;
757 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned;
758 p_pic->p[ V_PLANE ].i_visible_pitch = i_width;
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;
769 p_pic->p[ U_PLANE ].i_visible_lines = i_height;
770 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned;
771 p_pic->p[ U_PLANE ].i_visible_pitch = i_width;
772 p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
773 p_pic->p[ V_PLANE ].i_visible_lines = i_height;
774 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned;
775 p_pic->p[ V_PLANE ].i_visible_pitch = i_width;
780 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
781 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
782 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
783 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
784 p_pic->p[ U_PLANE ].i_lines = i_height_aligned;
785 p_pic->p[ U_PLANE ].i_visible_lines = i_height;
786 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned;
787 p_pic->p[ U_PLANE ].i_visible_pitch = i_width;
788 p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
789 p_pic->p[ V_PLANE ].i_visible_lines = i_height;
790 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned;
791 p_pic->p[ V_PLANE ].i_visible_pitch = i_width;
792 p_pic->p[ A_PLANE ].i_lines = i_height_aligned;
793 p_pic->p[ A_PLANE ].i_visible_lines = i_height;
794 p_pic->p[ A_PLANE ].i_pitch = i_width_aligned;
795 p_pic->p[ A_PLANE ].i_visible_pitch = i_width;
800 p_pic->p->i_lines = i_height_aligned;
801 p_pic->p->i_visible_lines = i_height;
802 p_pic->p->i_pitch = i_width_aligned;
803 p_pic->p->i_visible_pitch = i_width;
804 p_pic->p->i_pixel_pitch = 8;
809 p_pic->p->i_lines = i_height_aligned;
810 p_pic->p->i_visible_lines = i_height;
811 p_pic->p->i_pitch = i_width_aligned;
812 p_pic->p->i_visible_pitch = i_width;
813 p_pic->p->i_pixel_pitch = 4;
819 p_pic->p->i_lines = i_height_aligned;
820 p_pic->p->i_visible_lines = i_height;
821 p_pic->p->i_pitch = i_width_aligned * 2;
822 p_pic->p->i_visible_pitch = i_width * 2;
823 p_pic->p->i_pixel_pitch = 4;
828 p_pic->p->i_lines = i_height_aligned;
829 p_pic->p->i_visible_lines = i_height;
830 p_pic->p->i_pitch = i_width_aligned;
831 p_pic->p->i_visible_pitch = i_width;
832 p_pic->p->i_pixel_pitch = 1;
837 p_pic->p->i_lines = i_height_aligned;
838 p_pic->p->i_visible_lines = i_height;
839 p_pic->p->i_pitch = i_width_aligned * 2;
840 p_pic->p->i_visible_pitch = i_width * 2;
841 p_pic->p->i_pixel_pitch = 2;
846 p_pic->p->i_lines = i_height_aligned;
847 p_pic->p->i_visible_lines = i_height;
848 p_pic->p->i_pitch = i_width_aligned * 2;
849 p_pic->p->i_visible_pitch = i_width * 2;
850 p_pic->p->i_pixel_pitch = 2;
855 p_pic->p->i_lines = i_height_aligned;
856 p_pic->p->i_visible_lines = i_height;
857 p_pic->p->i_pitch = i_width_aligned * 3;
858 p_pic->p->i_visible_pitch = i_width * 3;
859 p_pic->p->i_pixel_pitch = 3;
865 p_pic->p->i_lines = i_height_aligned;
866 p_pic->p->i_visible_lines = i_height;
867 p_pic->p->i_pitch = i_width_aligned * 4;
868 p_pic->p->i_visible_pitch = i_width * 4;
869 p_pic->p->i_pixel_pitch = 4;
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;
880 p_pic->p->i_visible_pitch = i_width;
881 p_pic->p->i_pixel_pitch = 1;
887 msg_Err( p_this, "unknown chroma type 0x%.8x (%4.4s)",
888 i_chroma, (char*)&i_chroma );
897 * Compare two chroma values
899 * This function returns 1 if the two fourcc values given as argument are
900 * the same format (eg. UYVY/UYNV) or almost the same format (eg. I420/YV12)
902 int vout_ChromaCmp( vlc_fourcc_t i_chroma, vlc_fourcc_t i_amorhc )
904 /* If they are the same, they are the same ! */
905 if( i_chroma == i_amorhc )
910 /* Check for equivalence classes */
972 /*****************************************************************************
974 *****************************************************************************/
975 static void PictureReleaseCallback( picture_t *p_picture )
977 if( --p_picture->i_refcount > 0 )
979 picture_Delete( p_picture );
981 /*****************************************************************************
983 *****************************************************************************/
984 picture_t *picture_New( vlc_fourcc_t i_chroma, int i_width, int i_height, int i_aspect )
986 picture_t *p_picture = malloc( sizeof(*p_picture) );
991 memset( p_picture, 0, sizeof(*p_picture) );
992 if( __vout_AllocatePicture( NULL, p_picture,
993 i_chroma, i_width, i_height, i_aspect ) )
999 p_picture->i_refcount = 1;
1000 p_picture->pf_release = PictureReleaseCallback;
1001 p_picture->i_status = RESERVED_PICTURE;
1006 /*****************************************************************************
1008 *****************************************************************************/
1009 void picture_Delete( picture_t *p_picture )
1011 assert( p_picture && p_picture->i_refcount == 0 );
1013 free( p_picture->p_q );
1014 free( p_picture->p_data_orig );
1015 free( p_picture->p_sys );
1019 /*****************************************************************************
1021 *****************************************************************************/
1022 void picture_CopyPixels( picture_t *p_dst, const picture_t *p_src )
1026 for( i = 0; i < p_src->i_planes ; i++ )
1027 plane_CopyPixels( p_dst->p+i, p_src->p+i );
1030 void plane_CopyPixels( plane_t *p_dst, const plane_t *p_src )
1032 const unsigned i_width = __MIN( p_dst->i_visible_pitch,
1033 p_src->i_visible_pitch );
1034 const unsigned i_height = __MIN( p_dst->i_visible_lines,
1035 p_src->i_visible_lines );
1037 if( p_src->i_pitch == p_dst->i_pitch )
1039 /* There are margins, but with the same width : perfect ! */
1040 vlc_memcpy( p_dst->p_pixels, p_src->p_pixels,
1041 p_src->i_pitch * i_height );
1045 /* We need to proceed line by line */
1046 uint8_t *p_in = p_src->p_pixels;
1047 uint8_t *p_out = p_dst->p_pixels;
1053 for( i_line = i_height; i_line--; )
1055 vlc_memcpy( p_out, p_in, i_width );
1056 p_in += p_src->i_pitch;
1057 p_out += p_dst->i_pitch;
1062 /*****************************************************************************
1064 *****************************************************************************/