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 * Increment reference counter of a picture
274 * This function increments the reference counter of a picture in the video
275 * heap. It needs a lock since several producer threads can access the picture.
277 void vout_LinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
279 vlc_mutex_lock( &p_vout->picture_lock );
281 vlc_mutex_unlock( &p_vout->picture_lock );
285 * Decrement reference counter of a picture
287 * This function decrement the reference counter of a picture in the video heap
289 void vout_UnlinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
291 vlc_mutex_lock( &p_vout->picture_lock );
294 if( ( p_pic->i_refcount == 0 ) &&
295 ( p_pic->i_status == DISPLAYED_PICTURE ) )
297 p_pic->i_status = DESTROYED_PICTURE;
298 p_vout->i_heap_size--;
299 picture_CleanupQuant( p_pic );
302 vlc_mutex_unlock( &p_vout->picture_lock );
305 static int vout_LockPicture( vout_thread_t *p_vout, picture_t *p_picture )
307 if( p_picture->pf_lock )
308 return p_picture->pf_lock( p_vout, p_picture );
311 static void vout_UnlockPicture( vout_thread_t *p_vout, picture_t *p_picture )
313 if( p_picture->pf_unlock )
314 p_picture->pf_unlock( p_vout, p_picture );
320 * This function chooses whether the current picture needs to be copied
321 * before rendering, does the subpicture magic, and tells the video output
322 * thread which direct buffer needs to be displayed.
324 picture_t *vout_RenderPicture( vout_thread_t *p_vout, picture_t *p_pic,
325 subpicture_t *p_subpic, bool b_paused )
330 if( p_pic->i_type == DIRECT_PICTURE )
332 /* Picture is in a direct buffer. */
334 if( p_subpic != NULL )
336 /* We have subtitles. First copy the picture to
337 * the spare direct buffer, then render the
339 if( vout_LockPicture( p_vout, PP_OUTPUTPICTURE[0] ) )
342 picture_Copy( PP_OUTPUTPICTURE[0], p_pic );
344 spu_RenderSubpictures( p_vout->p_spu,
345 PP_OUTPUTPICTURE[0], &p_vout->fmt_out,
346 p_subpic, &p_vout->fmt_in, b_paused );
348 vout_UnlockPicture( p_vout, PP_OUTPUTPICTURE[0] );
350 return PP_OUTPUTPICTURE[0];
353 /* No subtitles, picture is in a directbuffer so
354 * we can display it directly (even if it is still
359 /* Not a direct buffer. We either need to copy it to a direct buffer,
360 * or render it if the chroma isn't the same. */
361 if( p_vout->p->b_direct )
363 /* Picture is not in a direct buffer, but is exactly the
364 * same size as the direct buffers. A memcpy() is enough,
365 * then render the subtitles. */
367 if( vout_LockPicture( p_vout, PP_OUTPUTPICTURE[0] ) )
370 picture_Copy( PP_OUTPUTPICTURE[0], p_pic );
371 spu_RenderSubpictures( p_vout->p_spu,
372 PP_OUTPUTPICTURE[0], &p_vout->fmt_out,
373 p_subpic, &p_vout->fmt_in, b_paused );
375 vout_UnlockPicture( p_vout, PP_OUTPUTPICTURE[0] );
377 return PP_OUTPUTPICTURE[0];
380 /* Picture is not in a direct buffer, and needs to be converted to
381 * another size/chroma. Then the subtitles need to be rendered as
382 * well. This usually means software YUV, or hardware YUV with a
383 * different chroma. */
385 if( p_subpic != NULL && p_vout->p_picture[0].b_slow )
387 /* The picture buffer is in slow memory. We'll use
388 * the "2 * VOUT_MAX_PICTURES + 1" picture as a temporary
389 * one for subpictures rendering. */
390 picture_t *p_tmp_pic = &p_vout->p_picture[2 * VOUT_MAX_PICTURES];
391 if( p_tmp_pic->i_status == FREE_PICTURE )
393 vout_AllocatePicture( VLC_OBJECT(p_vout),
394 p_tmp_pic, p_vout->fmt_out.i_chroma,
395 p_vout->fmt_out.i_width,
396 p_vout->fmt_out.i_height,
397 p_vout->fmt_out.i_aspect );
398 p_tmp_pic->i_type = MEMORY_PICTURE;
399 p_tmp_pic->i_status = RESERVED_PICTURE;
400 /* some modules (such as blend) needs to know the extra information in picture heap */
401 p_tmp_pic->p_heap = &p_vout->output;
404 /* Convert image to the first direct buffer */
405 p_vout->p->p_chroma->p_owner = (filter_owner_sys_t *)p_tmp_pic;
406 p_vout->p->p_chroma->pf_video_filter( p_vout->p->p_chroma, p_pic );
408 /* Render subpictures on the first direct buffer */
409 spu_RenderSubpictures( p_vout->p_spu,
410 p_tmp_pic, &p_vout->fmt_out,
411 p_subpic, &p_vout->fmt_in, b_paused );
413 if( vout_LockPicture( p_vout, &p_vout->p_picture[0] ) )
416 picture_Copy( &p_vout->p_picture[0], p_tmp_pic );
420 if( vout_LockPicture( p_vout, &p_vout->p_picture[0] ) )
423 /* Convert image to the first direct buffer */
424 p_vout->p->p_chroma->p_owner = (filter_owner_sys_t *)&p_vout->p_picture[0];
425 p_vout->p->p_chroma->pf_video_filter( p_vout->p->p_chroma, p_pic );
427 /* Render subpictures on the first direct buffer */
428 spu_RenderSubpictures( p_vout->p_spu,
429 &p_vout->p_picture[0], &p_vout->fmt_out,
430 p_subpic, &p_vout->fmt_in, b_paused );
433 vout_UnlockPicture( p_vout, &p_vout->p_picture[0] );
435 return &p_vout->p_picture[0];
439 * Calculate image window coordinates
441 * This function will be accessed by plugins. It calculates the relative
442 * position of the output window and the image window.
444 void vout_PlacePicture( vout_thread_t *p_vout,
445 unsigned int i_width, unsigned int i_height,
446 unsigned int *pi_x, unsigned int *pi_y,
447 unsigned int *pi_width, unsigned int *pi_height )
449 if( (i_width <= 0) || (i_height <=0) )
451 *pi_width = *pi_height = *pi_x = *pi_y = 0;
455 if( p_vout->b_scale )
458 *pi_height = i_height;
462 *pi_width = __MIN( i_width, p_vout->fmt_in.i_visible_width );
463 *pi_height = __MIN( i_height, p_vout->fmt_in.i_visible_height );
466 int64_t i_scaled_width = p_vout->fmt_in.i_visible_width * (int64_t)p_vout->fmt_in.i_sar_num *
467 *pi_height / p_vout->fmt_in.i_visible_height / p_vout->fmt_in.i_sar_den;
468 int64_t i_scaled_height = p_vout->fmt_in.i_visible_height * (int64_t)p_vout->fmt_in.i_sar_den *
469 *pi_width / p_vout->fmt_in.i_visible_width / p_vout->fmt_in.i_sar_num;
471 if( i_scaled_width <= 0 || i_scaled_height <= 0 )
473 msg_Warn( p_vout, "ignoring broken aspect ratio" );
474 i_scaled_width = *pi_width;
475 i_scaled_height = *pi_height;
478 if( i_scaled_width > *pi_width )
479 *pi_height = i_scaled_height;
481 *pi_width = i_scaled_width;
483 switch( p_vout->i_alignment & VOUT_ALIGN_HMASK )
485 case VOUT_ALIGN_LEFT:
488 case VOUT_ALIGN_RIGHT:
489 *pi_x = i_width - *pi_width;
492 *pi_x = ( i_width - *pi_width ) / 2;
495 switch( p_vout->i_alignment & VOUT_ALIGN_VMASK )
500 case VOUT_ALIGN_BOTTOM:
501 *pi_y = i_height - *pi_height;
504 *pi_y = ( i_height - *pi_height ) / 2;
509 * Allocate a new picture in the heap.
511 * This function allocates a fake direct buffer in memory, which can be
512 * used exactly like a video buffer. The video output thread then manages
513 * how it gets displayed.
515 int __vout_AllocatePicture( vlc_object_t *p_this, picture_t *p_pic,
516 vlc_fourcc_t i_chroma,
517 int i_width, int i_height, int i_aspect )
519 int i_bytes, i_index, i_width_aligned, i_height_aligned;
521 /* Make sure the real dimensions are a multiple of 16 */
522 i_width_aligned = (i_width + 15) >> 4 << 4;
523 i_height_aligned = (i_height + 15) >> 4 << 4;
525 if( vout_InitPicture( p_this, p_pic, i_chroma,
526 i_width, i_height, i_aspect ) != VLC_SUCCESS )
532 /* Calculate how big the new image should be */
533 i_bytes = p_pic->format.i_bits_per_pixel *
534 i_width_aligned * i_height_aligned / 8;
536 p_pic->p_data = vlc_memalign( &p_pic->p_data_orig, 16, i_bytes );
538 if( p_pic->p_data == NULL )
544 /* Fill the p_pixels field for each plane */
545 p_pic->p[ 0 ].p_pixels = p_pic->p_data;
547 for( i_index = 1; i_index < p_pic->i_planes; i_index++ )
549 p_pic->p[i_index].p_pixels = p_pic->p[i_index-1].p_pixels +
550 p_pic->p[i_index-1].i_lines * p_pic->p[i_index-1].i_pitch;
557 * Initialise the video format fields given chroma/size.
559 * This function initializes all the video_frame_format_t fields given the
560 * static properties of a picture (chroma and size).
561 * \param p_format Pointer to the format structure to initialize
562 * \param i_chroma Chroma to set
563 * \param i_width Width to set
564 * \param i_height Height to set
565 * \param i_aspect Aspect ratio
567 void vout_InitFormat( video_frame_format_t *p_format, vlc_fourcc_t i_chroma,
568 int i_width, int i_height, int i_aspect )
570 p_format->i_chroma = i_chroma;
571 p_format->i_width = p_format->i_visible_width = i_width;
572 p_format->i_height = p_format->i_visible_height = i_height;
573 p_format->i_x_offset = p_format->i_y_offset = 0;
574 p_format->i_aspect = i_aspect;
577 /* Assume we have square pixels */
578 if( i_width && i_height )
579 p_format->i_aspect = i_width * VOUT_ASPECT_FACTOR / i_height;
581 p_format->i_aspect = 0;
587 p_format->i_bits_per_pixel = 32;
591 p_format->i_bits_per_pixel = 24;
597 p_format->i_bits_per_pixel = 16;
601 p_format->i_bits_per_pixel = 16;
608 p_format->i_bits_per_pixel = 12;
612 p_format->i_bits_per_pixel = 9;
615 p_format->i_bits_per_pixel = 8;
618 p_format->i_bits_per_pixel = 8;
623 p_format->i_bits_per_pixel = 32;
626 p_format->i_bits_per_pixel = 24;
630 p_format->i_bits_per_pixel = 16;
633 p_format->i_bits_per_pixel = 8;
640 p_format->i_bits_per_pixel = 8;
644 p_format->i_bits_per_pixel = 0;
650 * Initialise the picture_t fields given chroma/size.
652 * This function initializes most of the picture_t fields given a chroma and
653 * size. It makes the assumption that stride == width.
654 * \param p_this The calling object
655 * \param p_pic Pointer to the picture to initialize
656 * \param i_chroma The chroma fourcc to set
657 * \param i_width The width of the picture
658 * \param i_height The height of the picture
659 * \param i_aspect The aspect ratio of the picture
661 int __vout_InitPicture( vlc_object_t *p_this, picture_t *p_pic,
662 vlc_fourcc_t i_chroma,
663 int i_width, int i_height, int i_aspect )
665 int i_index, i_width_aligned, i_height_aligned;
667 /* Store default values */
668 for( i_index = 0; i_index < VOUT_MAX_PLANES; i_index++ )
670 p_pic->p[i_index].p_pixels = NULL;
671 p_pic->p[i_index].i_pixel_pitch = 1;
674 p_pic->pf_release = NULL;
675 p_pic->pf_lock = NULL;
676 p_pic->pf_unlock = NULL;
677 p_pic->i_refcount = 0;
680 p_pic->i_qstride = 0;
683 vout_InitFormat( &p_pic->format, i_chroma, i_width, i_height, i_aspect );
685 /* Make sure the real dimensions are a multiple of 16 */
686 i_width_aligned = (i_width + 15) >> 4 << 4;
687 i_height_aligned = (i_height + 15) >> 4 << 4;
689 /* Calculate coordinates */
693 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
694 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
695 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
696 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
697 p_pic->p[ U_PLANE ].i_lines = i_height_aligned;
698 p_pic->p[ U_PLANE ].i_visible_lines = i_height;
699 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 4;
700 p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 4;
701 p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
702 p_pic->p[ V_PLANE ].i_visible_lines = i_height;
703 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 4;
704 p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 4;
710 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
711 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
712 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
713 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
714 p_pic->p[ U_PLANE ].i_lines = i_height_aligned / 4;
715 p_pic->p[ U_PLANE ].i_visible_lines = i_height / 4;
716 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 4;
717 p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 4;
718 p_pic->p[ V_PLANE ].i_lines = i_height_aligned / 4;
719 p_pic->p[ V_PLANE ].i_visible_lines = i_height / 4;
720 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 4;
721 p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 4;
729 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
730 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
731 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
732 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
733 p_pic->p[ U_PLANE ].i_lines = i_height_aligned / 2;
734 p_pic->p[ U_PLANE ].i_visible_lines = i_height / 2;
735 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 2;
736 p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 2;
737 p_pic->p[ V_PLANE ].i_lines = i_height_aligned / 2;
738 p_pic->p[ V_PLANE ].i_visible_lines = i_height / 2;
739 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 2;
740 p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 2;
746 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
747 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
748 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
749 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
750 p_pic->p[ U_PLANE ].i_lines = i_height_aligned;
751 p_pic->p[ U_PLANE ].i_visible_lines = i_height;
752 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 2;
753 p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 2;
754 p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
755 p_pic->p[ V_PLANE ].i_visible_lines = i_height;
756 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 2;
757 p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 2;
763 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
764 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
765 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
766 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
767 p_pic->p[ U_PLANE ].i_lines = i_height_aligned / 2;
768 p_pic->p[ U_PLANE ].i_visible_lines = i_height / 2;
769 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned;
770 p_pic->p[ U_PLANE ].i_visible_pitch = i_width;
771 p_pic->p[ V_PLANE ].i_lines = i_height_aligned / 2;
772 p_pic->p[ V_PLANE ].i_visible_lines = i_height / 2;
773 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned;
774 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;
796 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
797 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
798 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
799 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
800 p_pic->p[ U_PLANE ].i_lines = i_height_aligned;
801 p_pic->p[ U_PLANE ].i_visible_lines = i_height;
802 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned;
803 p_pic->p[ U_PLANE ].i_visible_pitch = i_width;
804 p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
805 p_pic->p[ V_PLANE ].i_visible_lines = i_height;
806 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned;
807 p_pic->p[ V_PLANE ].i_visible_pitch = i_width;
808 p_pic->p[ A_PLANE ].i_lines = i_height_aligned;
809 p_pic->p[ A_PLANE ].i_visible_lines = i_height;
810 p_pic->p[ A_PLANE ].i_pitch = i_width_aligned;
811 p_pic->p[ A_PLANE ].i_visible_pitch = i_width;
816 p_pic->p->i_lines = i_height_aligned;
817 p_pic->p->i_visible_lines = i_height;
818 p_pic->p->i_pitch = i_width_aligned;
819 p_pic->p->i_visible_pitch = i_width;
820 p_pic->p->i_pixel_pitch = 8;
825 p_pic->p->i_lines = i_height_aligned;
826 p_pic->p->i_visible_lines = i_height;
827 p_pic->p->i_pitch = i_width_aligned;
828 p_pic->p->i_visible_pitch = i_width;
829 p_pic->p->i_pixel_pitch = 4;
835 p_pic->p->i_lines = i_height_aligned;
836 p_pic->p->i_visible_lines = i_height;
837 p_pic->p->i_pitch = i_width_aligned * 2;
838 p_pic->p->i_visible_pitch = i_width * 2;
839 p_pic->p->i_pixel_pitch = 4;
844 p_pic->p->i_lines = i_height_aligned;
845 p_pic->p->i_visible_lines = i_height;
846 p_pic->p->i_pitch = i_width_aligned;
847 p_pic->p->i_visible_pitch = i_width;
848 p_pic->p->i_pixel_pitch = 1;
853 p_pic->p->i_lines = i_height_aligned;
854 p_pic->p->i_visible_lines = i_height;
855 p_pic->p->i_pitch = i_width_aligned * 2;
856 p_pic->p->i_visible_pitch = i_width * 2;
857 p_pic->p->i_pixel_pitch = 2;
862 p_pic->p->i_lines = i_height_aligned;
863 p_pic->p->i_visible_lines = i_height;
864 p_pic->p->i_pitch = i_width_aligned * 2;
865 p_pic->p->i_visible_pitch = i_width * 2;
866 p_pic->p->i_pixel_pitch = 2;
871 p_pic->p->i_lines = i_height_aligned;
872 p_pic->p->i_visible_lines = i_height;
873 p_pic->p->i_pitch = i_width_aligned * 3;
874 p_pic->p->i_visible_pitch = i_width * 3;
875 p_pic->p->i_pixel_pitch = 3;
881 p_pic->p->i_lines = i_height_aligned;
882 p_pic->p->i_visible_lines = i_height;
883 p_pic->p->i_pitch = i_width_aligned * 4;
884 p_pic->p->i_visible_pitch = i_width * 4;
885 p_pic->p->i_pixel_pitch = 4;
893 p_pic->p->i_lines = i_height_aligned;
894 p_pic->p->i_visible_lines = i_height;
895 p_pic->p->i_pitch = i_width_aligned;
896 p_pic->p->i_visible_pitch = i_width;
897 p_pic->p->i_pixel_pitch = 1;
903 msg_Err( p_this, "unknown chroma type 0x%.8x (%4.4s)",
904 i_chroma, (char*)&i_chroma );
913 * Compare two chroma values
915 * This function returns 1 if the two fourcc values given as argument are
916 * the same format (eg. UYVY/UYNV) or almost the same format (eg. I420/YV12)
918 int vout_ChromaCmp( vlc_fourcc_t i_chroma, vlc_fourcc_t i_amorhc )
920 /* If they are the same, they are the same ! */
921 if( i_chroma == i_amorhc )
926 /* Check for equivalence classes */
988 /*****************************************************************************
990 *****************************************************************************/
991 static void PictureReleaseCallback( picture_t *p_picture )
993 if( --p_picture->i_refcount > 0 )
995 picture_Delete( p_picture );
997 /*****************************************************************************
999 *****************************************************************************/
1000 picture_t *picture_New( vlc_fourcc_t i_chroma, int i_width, int i_height, int i_aspect )
1002 picture_t *p_picture = malloc( sizeof(*p_picture) );
1007 memset( p_picture, 0, sizeof(*p_picture) );
1008 if( __vout_AllocatePicture( NULL, p_picture,
1009 i_chroma, i_width, i_height, i_aspect ) )
1015 p_picture->i_refcount = 1;
1016 p_picture->pf_release = PictureReleaseCallback;
1017 p_picture->i_status = RESERVED_PICTURE;
1022 /*****************************************************************************
1024 *****************************************************************************/
1025 void picture_Delete( picture_t *p_picture )
1027 assert( p_picture && p_picture->i_refcount == 0 );
1029 free( p_picture->p_q );
1030 free( p_picture->p_data_orig );
1031 free( p_picture->p_sys );
1035 /*****************************************************************************
1037 *****************************************************************************/
1038 void picture_CopyPixels( picture_t *p_dst, const picture_t *p_src )
1042 for( i = 0; i < p_src->i_planes ; i++ )
1043 plane_CopyPixels( p_dst->p+i, p_src->p+i );
1046 void plane_CopyPixels( plane_t *p_dst, const plane_t *p_src )
1048 const unsigned i_width = __MIN( p_dst->i_visible_pitch,
1049 p_src->i_visible_pitch );
1050 const unsigned i_height = __MIN( p_dst->i_visible_lines,
1051 p_src->i_visible_lines );
1053 if( p_src->i_pitch == p_dst->i_pitch )
1055 /* There are margins, but with the same width : perfect ! */
1056 vlc_memcpy( p_dst->p_pixels, p_src->p_pixels,
1057 p_src->i_pitch * i_height );
1061 /* We need to proceed line by line */
1062 uint8_t *p_in = p_src->p_pixels;
1063 uint8_t *p_out = p_dst->p_pixels;
1069 for( i_line = i_height; i_line--; )
1071 vlc_memcpy( p_out, p_in, i_width );
1072 p_in += p_src->i_pitch;
1073 p_out += p_dst->i_pitch;
1078 /*****************************************************************************
1080 *****************************************************************************/