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_freepic->i_matrix_coefficients = 1;
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 * Remove a permanent or reserved picture from the heap
209 * This function frees a previously reserved picture or a permanent
210 * picture. It is meant to be used when the construction of a picture aborted.
211 * Note that the picture will be destroyed even if it is linked !
213 void vout_DestroyPicture( vout_thread_t *p_vout, picture_t *p_pic )
215 vlc_mutex_lock( &p_vout->picture_lock );
218 /* Check if picture status is valid */
219 if( p_pic->i_status != RESERVED_PICTURE )
221 msg_Err( p_vout, "picture to destroy %p has invalid status %d",
222 p_pic, p_pic->i_status );
226 p_pic->i_status = DESTROYED_PICTURE;
227 p_vout->i_heap_size--;
228 picture_CleanupQuant( p_pic );
230 vlc_mutex_unlock( &p_vout->picture_lock );
234 void vout_DropPicture( vout_thread_t *p_vout, picture_t *p_pic )
236 vlc_mutex_lock( &p_vout->picture_lock );
238 if( p_pic->i_status == READY_PICTURE )
240 /* Grr cannot destroy ready picture by myself so be sure vout won't like it */
243 else if( p_pic->i_refcount > 0 )
245 p_pic->i_status = DISPLAYED_PICTURE;
249 p_pic->i_status = DESTROYED_PICTURE;
250 p_vout->i_heap_size--;
251 picture_CleanupQuant( p_pic );
254 vlc_mutex_unlock( &p_vout->picture_lock );
258 * Increment reference counter of a picture
260 * This function increments the reference counter of a picture in the video
261 * heap. It needs a lock since several producer threads can access the picture.
263 void vout_LinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
265 vlc_mutex_lock( &p_vout->picture_lock );
267 vlc_mutex_unlock( &p_vout->picture_lock );
271 * Decrement reference counter of a picture
273 * This function decrement the reference counter of a picture in the video heap
275 void vout_UnlinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
277 vlc_mutex_lock( &p_vout->picture_lock );
280 if( ( p_pic->i_refcount == 0 ) &&
281 ( p_pic->i_status == DISPLAYED_PICTURE ) )
283 p_pic->i_status = DESTROYED_PICTURE;
284 p_vout->i_heap_size--;
285 picture_CleanupQuant( p_pic );
288 vlc_mutex_unlock( &p_vout->picture_lock );
291 static int vout_LockPicture( vout_thread_t *p_vout, picture_t *p_picture )
293 if( p_picture->pf_lock )
294 return p_picture->pf_lock( p_vout, p_picture );
297 static void vout_UnlockPicture( vout_thread_t *p_vout, picture_t *p_picture )
299 if( p_picture->pf_unlock )
300 p_picture->pf_unlock( p_vout, p_picture );
306 * This function chooses whether the current picture needs to be copied
307 * before rendering, does the subpicture magic, and tells the video output
308 * thread which direct buffer needs to be displayed.
310 picture_t *vout_RenderPicture( vout_thread_t *p_vout, picture_t *p_pic,
311 subpicture_t *p_subpic, bool b_paused )
316 if( p_pic->i_type == DIRECT_PICTURE )
318 /* Picture is in a direct buffer. */
320 if( p_subpic != NULL )
322 /* We have subtitles. First copy the picture to
323 * the spare direct buffer, then render the
325 if( vout_LockPicture( p_vout, PP_OUTPUTPICTURE[0] ) )
328 picture_Copy( PP_OUTPUTPICTURE[0], p_pic );
330 spu_RenderSubpictures( p_vout->p_spu,
331 PP_OUTPUTPICTURE[0], &p_vout->fmt_out,
332 p_subpic, &p_vout->fmt_in, b_paused );
334 vout_UnlockPicture( p_vout, PP_OUTPUTPICTURE[0] );
336 return PP_OUTPUTPICTURE[0];
339 /* No subtitles, picture is in a directbuffer so
340 * we can display it directly (even if it is still
345 /* Not a direct buffer. We either need to copy it to a direct buffer,
346 * or render it if the chroma isn't the same. */
347 if( p_vout->p->b_direct )
349 /* Picture is not in a direct buffer, but is exactly the
350 * same size as the direct buffers. A memcpy() is enough,
351 * then render the subtitles. */
353 if( vout_LockPicture( p_vout, PP_OUTPUTPICTURE[0] ) )
356 picture_Copy( PP_OUTPUTPICTURE[0], p_pic );
357 spu_RenderSubpictures( p_vout->p_spu,
358 PP_OUTPUTPICTURE[0], &p_vout->fmt_out,
359 p_subpic, &p_vout->fmt_in, b_paused );
361 vout_UnlockPicture( p_vout, PP_OUTPUTPICTURE[0] );
363 return PP_OUTPUTPICTURE[0];
366 /* Picture is not in a direct buffer, and needs to be converted to
367 * another size/chroma. Then the subtitles need to be rendered as
368 * well. This usually means software YUV, or hardware YUV with a
369 * different chroma. */
371 if( p_subpic != NULL && p_vout->p_picture[0].b_slow )
373 /* The picture buffer is in slow memory. We'll use
374 * the "2 * VOUT_MAX_PICTURES + 1" picture as a temporary
375 * one for subpictures rendering. */
376 picture_t *p_tmp_pic = &p_vout->p_picture[2 * VOUT_MAX_PICTURES];
377 if( p_tmp_pic->i_status == FREE_PICTURE )
379 vout_AllocatePicture( VLC_OBJECT(p_vout),
380 p_tmp_pic, p_vout->fmt_out.i_chroma,
381 p_vout->fmt_out.i_width,
382 p_vout->fmt_out.i_height,
383 p_vout->fmt_out.i_aspect );
384 p_tmp_pic->i_type = MEMORY_PICTURE;
385 p_tmp_pic->i_status = RESERVED_PICTURE;
386 /* some modules (such as blend) needs to know the extra information in picture heap */
387 p_tmp_pic->p_heap = &p_vout->output;
390 /* Convert image to the first direct buffer */
391 p_vout->p->p_chroma->p_owner = (filter_owner_sys_t *)p_tmp_pic;
392 p_vout->p->p_chroma->pf_video_filter( p_vout->p->p_chroma, p_pic );
394 /* Render subpictures on the first direct buffer */
395 spu_RenderSubpictures( p_vout->p_spu,
396 p_tmp_pic, &p_vout->fmt_out,
397 p_subpic, &p_vout->fmt_in, b_paused );
399 if( vout_LockPicture( p_vout, &p_vout->p_picture[0] ) )
402 picture_Copy( &p_vout->p_picture[0], p_tmp_pic );
406 if( vout_LockPicture( p_vout, &p_vout->p_picture[0] ) )
409 /* Convert image to the first direct buffer */
410 p_vout->p->p_chroma->p_owner = (filter_owner_sys_t *)&p_vout->p_picture[0];
411 p_vout->p->p_chroma->pf_video_filter( p_vout->p->p_chroma, p_pic );
413 /* Render subpictures on the first direct buffer */
414 spu_RenderSubpictures( p_vout->p_spu,
415 &p_vout->p_picture[0], &p_vout->fmt_out,
416 p_subpic, &p_vout->fmt_in, b_paused );
419 vout_UnlockPicture( p_vout, &p_vout->p_picture[0] );
421 return &p_vout->p_picture[0];
425 * Calculate image window coordinates
427 * This function will be accessed by plugins. It calculates the relative
428 * position of the output window and the image window.
430 void vout_PlacePicture( vout_thread_t *p_vout,
431 unsigned int i_width, unsigned int i_height,
432 unsigned int *pi_x, unsigned int *pi_y,
433 unsigned int *pi_width, unsigned int *pi_height )
435 if( (i_width <= 0) || (i_height <=0) )
437 *pi_width = *pi_height = *pi_x = *pi_y = 0;
441 if( p_vout->b_scale )
444 *pi_height = i_height;
448 *pi_width = __MIN( i_width, p_vout->fmt_in.i_visible_width );
449 *pi_height = __MIN( i_height, p_vout->fmt_in.i_visible_height );
452 int64_t i_scaled_width = p_vout->fmt_in.i_visible_width * (int64_t)p_vout->fmt_in.i_sar_num *
453 *pi_height / p_vout->fmt_in.i_visible_height / p_vout->fmt_in.i_sar_den;
454 int64_t i_scaled_height = p_vout->fmt_in.i_visible_height * (int64_t)p_vout->fmt_in.i_sar_den *
455 *pi_width / p_vout->fmt_in.i_visible_width / p_vout->fmt_in.i_sar_num;
457 if( i_scaled_width <= 0 || i_scaled_height <= 0 )
459 msg_Warn( p_vout, "ignoring broken aspect ratio" );
460 i_scaled_width = *pi_width;
461 i_scaled_height = *pi_height;
464 if( i_scaled_width > *pi_width )
465 *pi_height = i_scaled_height;
467 *pi_width = i_scaled_width;
469 switch( p_vout->i_alignment & VOUT_ALIGN_HMASK )
471 case VOUT_ALIGN_LEFT:
474 case VOUT_ALIGN_RIGHT:
475 *pi_x = i_width - *pi_width;
478 *pi_x = ( i_width - *pi_width ) / 2;
481 switch( p_vout->i_alignment & VOUT_ALIGN_VMASK )
486 case VOUT_ALIGN_BOTTOM:
487 *pi_y = i_height - *pi_height;
490 *pi_y = ( i_height - *pi_height ) / 2;
495 * Allocate a new picture in the heap.
497 * This function allocates a fake direct buffer in memory, which can be
498 * used exactly like a video buffer. The video output thread then manages
499 * how it gets displayed.
501 int __vout_AllocatePicture( vlc_object_t *p_this, picture_t *p_pic,
502 vlc_fourcc_t i_chroma,
503 int i_width, int i_height, int i_aspect )
505 int i_bytes, i_index, i_width_aligned, i_height_aligned;
507 /* Make sure the real dimensions are a multiple of 16 */
508 i_width_aligned = (i_width + 15) >> 4 << 4;
509 i_height_aligned = (i_height + 15) >> 4 << 4;
511 if( vout_InitPicture( p_this, p_pic, i_chroma,
512 i_width, i_height, i_aspect ) != VLC_SUCCESS )
518 /* Calculate how big the new image should be */
519 i_bytes = p_pic->format.i_bits_per_pixel *
520 i_width_aligned * i_height_aligned / 8;
522 p_pic->p_data = vlc_memalign( &p_pic->p_data_orig, 16, i_bytes );
524 if( p_pic->p_data == NULL )
530 /* Fill the p_pixels field for each plane */
531 p_pic->p[ 0 ].p_pixels = p_pic->p_data;
533 for( i_index = 1; i_index < p_pic->i_planes; i_index++ )
535 p_pic->p[i_index].p_pixels = p_pic->p[i_index-1].p_pixels +
536 p_pic->p[i_index-1].i_lines * p_pic->p[i_index-1].i_pitch;
543 * Initialise the video format fields given chroma/size.
545 * This function initializes all the video_frame_format_t fields given the
546 * static properties of a picture (chroma and size).
547 * \param p_format Pointer to the format structure to initialize
548 * \param i_chroma Chroma to set
549 * \param i_width Width to set
550 * \param i_height Height to set
551 * \param i_aspect Aspect ratio
553 void vout_InitFormat( video_frame_format_t *p_format, vlc_fourcc_t i_chroma,
554 int i_width, int i_height, int i_aspect )
556 p_format->i_chroma = i_chroma;
557 p_format->i_width = p_format->i_visible_width = i_width;
558 p_format->i_height = p_format->i_visible_height = i_height;
559 p_format->i_x_offset = p_format->i_y_offset = 0;
560 p_format->i_aspect = i_aspect;
563 /* Assume we have square pixels */
564 if( i_width && i_height )
565 p_format->i_aspect = i_width * VOUT_ASPECT_FACTOR / i_height;
567 p_format->i_aspect = 0;
573 p_format->i_bits_per_pixel = 32;
577 p_format->i_bits_per_pixel = 24;
583 p_format->i_bits_per_pixel = 16;
587 p_format->i_bits_per_pixel = 16;
594 p_format->i_bits_per_pixel = 12;
598 p_format->i_bits_per_pixel = 9;
601 p_format->i_bits_per_pixel = 8;
604 p_format->i_bits_per_pixel = 8;
609 p_format->i_bits_per_pixel = 32;
612 p_format->i_bits_per_pixel = 24;
616 p_format->i_bits_per_pixel = 16;
619 p_format->i_bits_per_pixel = 8;
626 p_format->i_bits_per_pixel = 8;
630 p_format->i_bits_per_pixel = 0;
636 * Initialise the picture_t fields given chroma/size.
638 * This function initializes most of the picture_t fields given a chroma and
639 * size. It makes the assumption that stride == width.
640 * \param p_this The calling object
641 * \param p_pic Pointer to the picture to initialize
642 * \param i_chroma The chroma fourcc to set
643 * \param i_width The width of the picture
644 * \param i_height The height of the picture
645 * \param i_aspect The aspect ratio of the picture
647 int __vout_InitPicture( vlc_object_t *p_this, picture_t *p_pic,
648 vlc_fourcc_t i_chroma,
649 int i_width, int i_height, int i_aspect )
651 int i_index, i_width_aligned, i_height_aligned;
653 /* Store default values */
654 for( i_index = 0; i_index < VOUT_MAX_PLANES; i_index++ )
656 p_pic->p[i_index].p_pixels = NULL;
657 p_pic->p[i_index].i_pixel_pitch = 1;
660 p_pic->pf_release = NULL;
661 p_pic->pf_lock = NULL;
662 p_pic->pf_unlock = NULL;
663 p_pic->i_refcount = 0;
666 p_pic->i_qstride = 0;
669 vout_InitFormat( &p_pic->format, i_chroma, i_width, i_height, i_aspect );
671 /* Make sure the real dimensions are a multiple of 16 */
672 i_width_aligned = (i_width + 15) >> 4 << 4;
673 i_height_aligned = (i_height + 15) >> 4 << 4;
675 /* Calculate coordinates */
679 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
680 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
681 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
682 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
683 p_pic->p[ U_PLANE ].i_lines = i_height_aligned;
684 p_pic->p[ U_PLANE ].i_visible_lines = i_height;
685 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 4;
686 p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 4;
687 p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
688 p_pic->p[ V_PLANE ].i_visible_lines = i_height;
689 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 4;
690 p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 4;
696 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
697 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
698 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
699 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
700 p_pic->p[ U_PLANE ].i_lines = i_height_aligned / 4;
701 p_pic->p[ U_PLANE ].i_visible_lines = i_height / 4;
702 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 4;
703 p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 4;
704 p_pic->p[ V_PLANE ].i_lines = i_height_aligned / 4;
705 p_pic->p[ V_PLANE ].i_visible_lines = i_height / 4;
706 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 4;
707 p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 4;
715 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
716 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
717 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
718 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
719 p_pic->p[ U_PLANE ].i_lines = i_height_aligned / 2;
720 p_pic->p[ U_PLANE ].i_visible_lines = i_height / 2;
721 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 2;
722 p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 2;
723 p_pic->p[ V_PLANE ].i_lines = i_height_aligned / 2;
724 p_pic->p[ V_PLANE ].i_visible_lines = i_height / 2;
725 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 2;
726 p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 2;
732 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
733 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
734 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
735 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
736 p_pic->p[ U_PLANE ].i_lines = i_height_aligned;
737 p_pic->p[ U_PLANE ].i_visible_lines = i_height;
738 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 2;
739 p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 2;
740 p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
741 p_pic->p[ V_PLANE ].i_visible_lines = i_height;
742 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 2;
743 p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 2;
749 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
750 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
751 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
752 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
753 p_pic->p[ U_PLANE ].i_lines = i_height_aligned / 2;
754 p_pic->p[ U_PLANE ].i_visible_lines = i_height / 2;
755 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned;
756 p_pic->p[ U_PLANE ].i_visible_pitch = i_width;
757 p_pic->p[ V_PLANE ].i_lines = i_height_aligned / 2;
758 p_pic->p[ V_PLANE ].i_visible_lines = i_height / 2;
759 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned;
760 p_pic->p[ V_PLANE ].i_visible_pitch = i_width;
766 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
767 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
768 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
769 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
770 p_pic->p[ U_PLANE ].i_lines = i_height_aligned;
771 p_pic->p[ U_PLANE ].i_visible_lines = i_height;
772 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned;
773 p_pic->p[ U_PLANE ].i_visible_pitch = i_width;
774 p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
775 p_pic->p[ V_PLANE ].i_visible_lines = i_height;
776 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned;
777 p_pic->p[ V_PLANE ].i_visible_pitch = i_width;
782 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
783 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
784 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
785 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
786 p_pic->p[ U_PLANE ].i_lines = i_height_aligned;
787 p_pic->p[ U_PLANE ].i_visible_lines = i_height;
788 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned;
789 p_pic->p[ U_PLANE ].i_visible_pitch = i_width;
790 p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
791 p_pic->p[ V_PLANE ].i_visible_lines = i_height;
792 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned;
793 p_pic->p[ V_PLANE ].i_visible_pitch = i_width;
794 p_pic->p[ A_PLANE ].i_lines = i_height_aligned;
795 p_pic->p[ A_PLANE ].i_visible_lines = i_height;
796 p_pic->p[ A_PLANE ].i_pitch = i_width_aligned;
797 p_pic->p[ A_PLANE ].i_visible_pitch = i_width;
802 p_pic->p->i_lines = i_height_aligned;
803 p_pic->p->i_visible_lines = i_height;
804 p_pic->p->i_pitch = i_width_aligned;
805 p_pic->p->i_visible_pitch = i_width;
806 p_pic->p->i_pixel_pitch = 8;
811 p_pic->p->i_lines = i_height_aligned;
812 p_pic->p->i_visible_lines = i_height;
813 p_pic->p->i_pitch = i_width_aligned;
814 p_pic->p->i_visible_pitch = i_width;
815 p_pic->p->i_pixel_pitch = 4;
821 p_pic->p->i_lines = i_height_aligned;
822 p_pic->p->i_visible_lines = i_height;
823 p_pic->p->i_pitch = i_width_aligned * 2;
824 p_pic->p->i_visible_pitch = i_width * 2;
825 p_pic->p->i_pixel_pitch = 4;
830 p_pic->p->i_lines = i_height_aligned;
831 p_pic->p->i_visible_lines = i_height;
832 p_pic->p->i_pitch = i_width_aligned;
833 p_pic->p->i_visible_pitch = i_width;
834 p_pic->p->i_pixel_pitch = 1;
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 * 2;
842 p_pic->p->i_visible_pitch = i_width * 2;
843 p_pic->p->i_pixel_pitch = 2;
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 * 2;
851 p_pic->p->i_visible_pitch = i_width * 2;
852 p_pic->p->i_pixel_pitch = 2;
857 p_pic->p->i_lines = i_height_aligned;
858 p_pic->p->i_visible_lines = i_height;
859 p_pic->p->i_pitch = i_width_aligned * 3;
860 p_pic->p->i_visible_pitch = i_width * 3;
861 p_pic->p->i_pixel_pitch = 3;
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 * 4;
870 p_pic->p->i_visible_pitch = i_width * 4;
871 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;
889 msg_Err( p_this, "unknown chroma type 0x%.8x (%4.4s)",
890 i_chroma, (char*)&i_chroma );
899 * Compare two chroma values
901 * This function returns 1 if the two fourcc values given as argument are
902 * the same format (eg. UYVY/UYNV) or almost the same format (eg. I420/YV12)
904 int vout_ChromaCmp( vlc_fourcc_t i_chroma, vlc_fourcc_t i_amorhc )
906 /* If they are the same, they are the same ! */
907 if( i_chroma == i_amorhc )
912 /* Check for equivalence classes */
974 /*****************************************************************************
976 *****************************************************************************/
977 static void PictureReleaseCallback( picture_t *p_picture )
979 if( --p_picture->i_refcount > 0 )
981 picture_Delete( p_picture );
983 /*****************************************************************************
985 *****************************************************************************/
986 picture_t *picture_New( vlc_fourcc_t i_chroma, int i_width, int i_height, int i_aspect )
988 picture_t *p_picture = malloc( sizeof(*p_picture) );
993 memset( p_picture, 0, sizeof(*p_picture) );
994 if( __vout_AllocatePicture( NULL, p_picture,
995 i_chroma, i_width, i_height, i_aspect ) )
1001 p_picture->i_refcount = 1;
1002 p_picture->pf_release = PictureReleaseCallback;
1003 p_picture->i_status = RESERVED_PICTURE;
1008 /*****************************************************************************
1010 *****************************************************************************/
1011 void picture_Delete( picture_t *p_picture )
1013 assert( p_picture && p_picture->i_refcount == 0 );
1015 free( p_picture->p_q );
1016 free( p_picture->p_data_orig );
1017 free( p_picture->p_sys );
1021 /*****************************************************************************
1023 *****************************************************************************/
1024 void picture_CopyPixels( picture_t *p_dst, const picture_t *p_src )
1028 for( i = 0; i < p_src->i_planes ; i++ )
1029 plane_CopyPixels( p_dst->p+i, p_src->p+i );
1032 void plane_CopyPixels( plane_t *p_dst, const plane_t *p_src )
1034 const unsigned i_width = __MIN( p_dst->i_visible_pitch,
1035 p_src->i_visible_pitch );
1036 const unsigned i_height = __MIN( p_dst->i_visible_lines,
1037 p_src->i_visible_lines );
1039 if( p_src->i_pitch == p_dst->i_pitch )
1041 /* There are margins, but with the same width : perfect ! */
1042 vlc_memcpy( p_dst->p_pixels, p_src->p_pixels,
1043 p_src->i_pitch * i_height );
1047 /* We need to proceed line by line */
1048 uint8_t *p_in = p_src->p_pixels;
1049 uint8_t *p_out = p_dst->p_pixels;
1055 for( i_line = i_height; i_line--; )
1057 vlc_memcpy( p_out, p_in, i_width );
1058 p_in += p_src->i_pitch;
1059 p_out += p_dst->i_pitch;
1064 /*****************************************************************************
1066 *****************************************************************************/