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"
44 * Remove the reservation flag of a picture, which will cause it to be ready
45 * for display. The picture won't be displayed until vout_DatePicture has been
48 void vout_DisplayPicture( vout_thread_t *p_vout, picture_t *p_pic )
50 vlc_mutex_lock( &p_vout->picture_lock );
51 switch( p_pic->i_status )
53 case RESERVED_PICTURE:
54 p_pic->i_status = RESERVED_DISP_PICTURE;
56 case RESERVED_DATED_PICTURE:
57 p_pic->i_status = READY_PICTURE;
60 msg_Err( p_vout, "picture to display %p has invalid status %d",
61 p_pic, p_pic->i_status );
65 vlc_mutex_unlock( &p_vout->picture_lock );
71 * Remove the reservation flag of a picture, which will cause it to be ready
72 * for display. The picture won't be displayed until vout_DisplayPicture has
74 * \param p_vout The vout in question
75 * \param p_pic The picture to date
76 * \param date The date to display the picture
78 void vout_DatePicture( vout_thread_t *p_vout,
79 picture_t *p_pic, mtime_t date )
81 vlc_mutex_lock( &p_vout->picture_lock );
83 switch( p_pic->i_status )
85 case RESERVED_PICTURE:
86 p_pic->i_status = RESERVED_DATED_PICTURE;
88 case RESERVED_DISP_PICTURE:
89 p_pic->i_status = READY_PICTURE;
92 msg_Err( p_vout, "picture to date %p has invalid status %d",
93 p_pic, p_pic->i_status );
97 vlc_mutex_unlock( &p_vout->picture_lock );
101 * Allocate a picture in the video output heap.
103 * This function creates a reserved image in the video output heap.
104 * A null pointer is returned if the function fails. This method provides an
105 * already allocated zone of memory in the picture data fields.
106 * It needs locking since several pictures can be created by several producers
109 int vout_CountPictureAvailable( vout_thread_t *p_vout )
114 vlc_mutex_lock( &p_vout->picture_lock );
115 for( i_pic = 0; i_pic < I_RENDERPICTURES; i_pic++ )
117 picture_t *p_pic = PP_RENDERPICTURE[(p_vout->render.i_last_used_pic + i_pic + 1) % I_RENDERPICTURES];
119 switch( p_pic->i_status )
121 case DESTROYED_PICTURE:
133 vlc_mutex_unlock( &p_vout->picture_lock );
138 picture_t *vout_CreatePicture( vout_thread_t *p_vout,
140 bool b_top_field_first,
141 unsigned int i_nb_fields )
143 int i_pic; /* picture index */
145 picture_t * p_freepic = NULL; /* first free picture */
148 vlc_mutex_lock( &p_vout->picture_lock );
151 * Look for an empty place in the picture heap.
153 for( i_pic = 0; i_pic < I_RENDERPICTURES; i_pic++ )
155 p_pic = PP_RENDERPICTURE[(p_vout->render.i_last_used_pic + i_pic + 1)
158 switch( p_pic->i_status )
160 case DESTROYED_PICTURE:
161 /* Memory will not be reallocated, and function can end
162 * immediately - this is the best possible case, since no
163 * memory allocation needs to be done */
164 p_pic->i_status = RESERVED_PICTURE;
165 p_pic->i_refcount = 0;
168 p_pic->b_progressive = b_progressive;
169 p_pic->i_nb_fields = i_nb_fields;
170 p_pic->b_top_field_first = b_top_field_first;
172 p_vout->i_heap_size++;
173 p_vout->render.i_last_used_pic =
174 ( p_vout->render.i_last_used_pic + i_pic + 1 )
176 vlc_mutex_unlock( &p_vout->picture_lock );
180 /* Picture is empty and ready for allocation */
181 p_vout->render.i_last_used_pic =
182 ( p_vout->render.i_last_used_pic + i_pic + 1 )
195 if( p_freepic != NULL )
197 vout_AllocatePicture( VLC_OBJECT(p_vout),
198 p_freepic, p_vout->render.i_chroma,
199 p_vout->render.i_width, p_vout->render.i_height,
200 p_vout->render.i_aspect );
202 if( p_freepic->i_planes )
204 /* Copy picture information, set some default values */
205 p_freepic->i_status = RESERVED_PICTURE;
206 p_freepic->i_type = MEMORY_PICTURE;
207 p_freepic->b_slow = 0;
209 p_freepic->i_refcount = 0;
210 p_freepic->b_force = 0;
212 p_freepic->b_progressive = b_progressive;
213 p_freepic->i_nb_fields = i_nb_fields;
214 p_freepic->b_top_field_first = b_top_field_first;
216 p_freepic->i_matrix_coefficients = 1;
218 p_vout->i_heap_size++;
222 /* Memory allocation failed : set picture as empty */
223 p_freepic->i_status = FREE_PICTURE;
226 msg_Err( p_vout, "picture allocation failed" );
229 vlc_mutex_unlock( &p_vout->picture_lock );
234 /* No free or destroyed picture could be found, but the decoder
235 * will try again in a while. */
236 vlc_mutex_unlock( &p_vout->picture_lock );
242 * Remove a permanent or reserved picture from the heap
244 * This function frees a previously reserved picture or a permanent
245 * picture. It is meant to be used when the construction of a picture aborted.
246 * Note that the picture will be destroyed even if it is linked !
248 void vout_DestroyPicture( vout_thread_t *p_vout, picture_t *p_pic )
250 vlc_mutex_lock( &p_vout->picture_lock );
253 /* Check if picture status is valid */
254 if( (p_pic->i_status != RESERVED_PICTURE) &&
255 (p_pic->i_status != RESERVED_DATED_PICTURE) &&
256 (p_pic->i_status != RESERVED_DISP_PICTURE) )
258 msg_Err( p_vout, "picture to destroy %p has invalid status %d",
259 p_pic, p_pic->i_status );
263 p_pic->i_status = DESTROYED_PICTURE;
264 p_vout->i_heap_size--;
265 picture_CleanupQuant( p_pic );
267 vlc_mutex_unlock( &p_vout->picture_lock );
271 * Increment reference counter of a picture
273 * This function increments the reference counter of a picture in the video
274 * heap. It needs a lock since several producer threads can access the picture.
276 void vout_LinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
278 vlc_mutex_lock( &p_vout->picture_lock );
280 vlc_mutex_unlock( &p_vout->picture_lock );
284 * Decrement reference counter of a picture
286 * This function decrement the reference counter of a picture in the video heap
288 void vout_UnlinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
290 vlc_mutex_lock( &p_vout->picture_lock );
293 if( ( p_pic->i_refcount == 0 ) &&
294 ( p_pic->i_status == DISPLAYED_PICTURE ) )
296 p_pic->i_status = DESTROYED_PICTURE;
297 p_vout->i_heap_size--;
298 picture_CleanupQuant( p_pic );
301 vlc_mutex_unlock( &p_vout->picture_lock );
304 static int vout_LockPicture( vout_thread_t *p_vout, picture_t *p_picture )
306 if( p_picture->pf_lock )
307 return p_picture->pf_lock( p_vout, p_picture );
310 static void vout_UnlockPicture( vout_thread_t *p_vout, picture_t *p_picture )
312 if( p_picture->pf_unlock )
313 p_picture->pf_unlock( p_vout, p_picture );
319 * This function chooses whether the current picture needs to be copied
320 * before rendering, does the subpicture magic, and tells the video output
321 * thread which direct buffer needs to be displayed.
323 picture_t *vout_RenderPicture( vout_thread_t *p_vout, picture_t *p_pic,
324 subpicture_t *p_subpic )
329 if( p_pic->i_type == DIRECT_PICTURE )
331 /* Picture is in a direct buffer. */
333 if( p_subpic != NULL )
335 /* We have subtitles. First copy the picture to
336 * the spare direct buffer, then render the
338 if( vout_LockPicture( p_vout, PP_OUTPUTPICTURE[0] ) )
341 vout_CopyPicture( p_vout, PP_OUTPUTPICTURE[0], p_pic );
343 spu_RenderSubpictures( p_vout->p_spu,
344 PP_OUTPUTPICTURE[0], &p_vout->fmt_out,
345 p_subpic, &p_vout->fmt_in );
347 vout_UnlockPicture( p_vout, PP_OUTPUTPICTURE[0] );
349 return PP_OUTPUTPICTURE[0];
352 /* No subtitles, picture is in a directbuffer so
353 * we can display it directly (even if it is still
358 /* Not a direct buffer. We either need to copy it to a direct buffer,
359 * or render it if the chroma isn't the same. */
360 if( p_vout->b_direct )
362 /* Picture is not in a direct buffer, but is exactly the
363 * same size as the direct buffers. A memcpy() is enough,
364 * then render the subtitles. */
366 if( vout_LockPicture( p_vout, PP_OUTPUTPICTURE[0] ) )
369 vout_CopyPicture( p_vout, PP_OUTPUTPICTURE[0], p_pic );
370 spu_RenderSubpictures( p_vout->p_spu,
371 PP_OUTPUTPICTURE[0], &p_vout->fmt_out,
372 p_subpic, &p_vout->fmt_in );
374 vout_UnlockPicture( p_vout, PP_OUTPUTPICTURE[0] );
376 return PP_OUTPUTPICTURE[0];
379 /* Picture is not in a direct buffer, and needs to be converted to
380 * another size/chroma. Then the subtitles need to be rendered as
381 * well. This usually means software YUV, or hardware YUV with a
382 * different chroma. */
384 if( p_subpic != NULL && p_vout->p_picture[0].b_slow )
386 /* The picture buffer is in slow memory. We'll use
387 * the "2 * VOUT_MAX_PICTURES + 1" picture as a temporary
388 * one for subpictures rendering. */
389 picture_t *p_tmp_pic = &p_vout->p_picture[2 * VOUT_MAX_PICTURES];
390 if( p_tmp_pic->i_status == FREE_PICTURE )
392 vout_AllocatePicture( VLC_OBJECT(p_vout),
393 p_tmp_pic, p_vout->fmt_out.i_chroma,
394 p_vout->fmt_out.i_width,
395 p_vout->fmt_out.i_height,
396 p_vout->fmt_out.i_aspect );
397 p_tmp_pic->i_type = MEMORY_PICTURE;
398 p_tmp_pic->i_status = RESERVED_PICTURE;
399 /* some modules (such as blend) needs to know the extra information in picture heap */
400 p_tmp_pic->p_heap = &p_vout->output;
403 /* Convert image to the first direct buffer */
404 p_vout->p_chroma->p_owner = (filter_owner_sys_t *)p_tmp_pic;
405 p_vout->p_chroma->pf_video_filter( p_vout->p_chroma, p_pic );
407 /* Render subpictures on the first direct buffer */
408 spu_RenderSubpictures( p_vout->p_spu,
409 p_tmp_pic, &p_vout->fmt_out,
410 p_subpic, &p_vout->fmt_in );
412 if( vout_LockPicture( p_vout, &p_vout->p_picture[0] ) )
415 vout_CopyPicture( p_vout, &p_vout->p_picture[0], p_tmp_pic );
419 if( vout_LockPicture( p_vout, &p_vout->p_picture[0] ) )
422 /* Convert image to the first direct buffer */
423 p_vout->p_chroma->p_owner = (filter_owner_sys_t *)&p_vout->p_picture[0];
424 p_vout->p_chroma->pf_video_filter( p_vout->p_chroma, p_pic );
426 /* Render subpictures on the first direct buffer */
427 spu_RenderSubpictures( p_vout->p_spu,
428 &p_vout->p_picture[0], &p_vout->fmt_out,
429 p_subpic, &p_vout->fmt_in );
432 vout_UnlockPicture( p_vout, &p_vout->p_picture[0] );
434 return &p_vout->p_picture[0];
438 * Calculate image window coordinates
440 * This function will be accessed by plugins. It calculates the relative
441 * position of the output window and the image window.
443 void vout_PlacePicture( vout_thread_t *p_vout,
444 unsigned int i_width, unsigned int i_height,
445 unsigned int *pi_x, unsigned int *pi_y,
446 unsigned int *pi_width, unsigned int *pi_height )
448 if( (i_width <= 0) || (i_height <=0) )
450 *pi_width = *pi_height = *pi_x = *pi_y = 0;
454 if( p_vout->b_scale )
457 *pi_height = i_height;
461 *pi_width = __MIN( i_width, p_vout->fmt_in.i_visible_width );
462 *pi_height = __MIN( i_height, p_vout->fmt_in.i_visible_height );
465 int64_t i_scaled_width = p_vout->fmt_in.i_visible_width * (int64_t)p_vout->fmt_in.i_sar_num *
466 *pi_height / p_vout->fmt_in.i_visible_height / p_vout->fmt_in.i_sar_den;
467 int64_t i_scaled_height = p_vout->fmt_in.i_visible_height * (int64_t)p_vout->fmt_in.i_sar_den *
468 *pi_width / p_vout->fmt_in.i_visible_width / p_vout->fmt_in.i_sar_num;
470 if( i_scaled_width <= 0 || i_scaled_height <= 0 )
472 msg_Warn( p_vout, "ignoring broken aspect ratio" );
473 i_scaled_width = *pi_width;
474 i_scaled_height = *pi_height;
477 if( i_scaled_width > *pi_width )
478 *pi_height = i_scaled_height;
480 *pi_width = i_scaled_width;
482 switch( p_vout->i_alignment & VOUT_ALIGN_HMASK )
484 case VOUT_ALIGN_LEFT:
487 case VOUT_ALIGN_RIGHT:
488 *pi_x = i_width - *pi_width;
491 *pi_x = ( i_width - *pi_width ) / 2;
494 switch( p_vout->i_alignment & VOUT_ALIGN_VMASK )
499 case VOUT_ALIGN_BOTTOM:
500 *pi_y = i_height - *pi_height;
503 *pi_y = ( i_height - *pi_height ) / 2;
508 * Allocate a new picture in the heap.
510 * This function allocates a fake direct buffer in memory, which can be
511 * used exactly like a video buffer. The video output thread then manages
512 * how it gets displayed.
514 int __vout_AllocatePicture( vlc_object_t *p_this, picture_t *p_pic,
515 vlc_fourcc_t i_chroma,
516 int i_width, int i_height, int i_aspect )
518 int i_bytes, i_index, i_width_aligned, i_height_aligned;
520 /* Make sure the real dimensions are a multiple of 16 */
521 i_width_aligned = (i_width + 15) >> 4 << 4;
522 i_height_aligned = (i_height + 15) >> 4 << 4;
524 if( vout_InitPicture( p_this, p_pic, i_chroma,
525 i_width, i_height, i_aspect ) != VLC_SUCCESS )
531 /* Calculate how big the new image should be */
532 i_bytes = p_pic->format.i_bits_per_pixel *
533 i_width_aligned * i_height_aligned / 8;
535 p_pic->p_data = vlc_memalign( &p_pic->p_data_orig, 16, i_bytes );
537 if( p_pic->p_data == NULL )
543 /* Fill the p_pixels field for each plane */
544 p_pic->p[ 0 ].p_pixels = p_pic->p_data;
546 for( i_index = 1; i_index < p_pic->i_planes; i_index++ )
548 p_pic->p[i_index].p_pixels = p_pic->p[i_index-1].p_pixels +
549 p_pic->p[i_index-1].i_lines * p_pic->p[i_index-1].i_pitch;
556 * Initialise the video format fields given chroma/size.
558 * This function initializes all the video_frame_format_t fields given the
559 * static properties of a picture (chroma and size).
560 * \param p_format Pointer to the format structure to initialize
561 * \param i_chroma Chroma to set
562 * \param i_width Width to set
563 * \param i_height Height to set
564 * \param i_aspect Aspect ratio
566 void vout_InitFormat( video_frame_format_t *p_format, vlc_fourcc_t i_chroma,
567 int i_width, int i_height, int i_aspect )
569 p_format->i_chroma = i_chroma;
570 p_format->i_width = p_format->i_visible_width = i_width;
571 p_format->i_height = p_format->i_visible_height = i_height;
572 p_format->i_x_offset = p_format->i_y_offset = 0;
573 p_format->i_aspect = i_aspect;
576 /* Assume we have square pixels */
577 if( i_width && i_height )
578 p_format->i_aspect = i_width * VOUT_ASPECT_FACTOR / i_height;
580 p_format->i_aspect = 0;
586 p_format->i_bits_per_pixel = 32;
590 p_format->i_bits_per_pixel = 24;
596 p_format->i_bits_per_pixel = 16;
600 p_format->i_bits_per_pixel = 16;
607 p_format->i_bits_per_pixel = 12;
611 p_format->i_bits_per_pixel = 9;
614 p_format->i_bits_per_pixel = 8;
617 p_format->i_bits_per_pixel = 8;
622 p_format->i_bits_per_pixel = 32;
625 p_format->i_bits_per_pixel = 24;
629 p_format->i_bits_per_pixel = 16;
632 p_format->i_bits_per_pixel = 8;
639 p_format->i_bits_per_pixel = 8;
643 p_format->i_bits_per_pixel = 0;
649 * Initialise the picture_t fields given chroma/size.
651 * This function initializes most of the picture_t fields given a chroma and
652 * size. It makes the assumption that stride == width.
653 * \param p_this The calling object
654 * \param p_pic Pointer to the picture to initialize
655 * \param i_chroma The chroma fourcc to set
656 * \param i_width The width of the picture
657 * \param i_height The height of the picture
658 * \param i_aspect The aspect ratio of the picture
660 int __vout_InitPicture( vlc_object_t *p_this, picture_t *p_pic,
661 vlc_fourcc_t i_chroma,
662 int i_width, int i_height, int i_aspect )
664 int i_index, i_width_aligned, i_height_aligned;
666 /* Store default values */
667 for( i_index = 0; i_index < VOUT_MAX_PLANES; i_index++ )
669 p_pic->p[i_index].p_pixels = NULL;
670 p_pic->p[i_index].i_pixel_pitch = 1;
673 p_pic->pf_release = NULL;
674 p_pic->pf_lock = NULL;
675 p_pic->pf_unlock = NULL;
676 p_pic->i_refcount = 0;
679 p_pic->i_qstride = 0;
682 vout_InitFormat( &p_pic->format, i_chroma, i_width, i_height, i_aspect );
684 /* Make sure the real dimensions are a multiple of 16 */
685 i_width_aligned = (i_width + 15) >> 4 << 4;
686 i_height_aligned = (i_height + 15) >> 4 << 4;
688 /* Calculate coordinates */
692 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
693 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
694 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
695 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
696 p_pic->p[ U_PLANE ].i_lines = i_height_aligned;
697 p_pic->p[ U_PLANE ].i_visible_lines = i_height;
698 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 4;
699 p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 4;
700 p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
701 p_pic->p[ V_PLANE ].i_visible_lines = i_height;
702 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 4;
703 p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 4;
709 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
710 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
711 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
712 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
713 p_pic->p[ U_PLANE ].i_lines = i_height_aligned / 4;
714 p_pic->p[ U_PLANE ].i_visible_lines = i_height / 4;
715 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 4;
716 p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 4;
717 p_pic->p[ V_PLANE ].i_lines = i_height_aligned / 4;
718 p_pic->p[ V_PLANE ].i_visible_lines = i_height / 4;
719 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 4;
720 p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 4;
728 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
729 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
730 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
731 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
732 p_pic->p[ U_PLANE ].i_lines = i_height_aligned / 2;
733 p_pic->p[ U_PLANE ].i_visible_lines = i_height / 2;
734 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 2;
735 p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 2;
736 p_pic->p[ V_PLANE ].i_lines = i_height_aligned / 2;
737 p_pic->p[ V_PLANE ].i_visible_lines = i_height / 2;
738 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 2;
739 p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 2;
745 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
746 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
747 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
748 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
749 p_pic->p[ U_PLANE ].i_lines = i_height_aligned;
750 p_pic->p[ U_PLANE ].i_visible_lines = i_height;
751 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 2;
752 p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 2;
753 p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
754 p_pic->p[ V_PLANE ].i_visible_lines = i_height;
755 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 2;
756 p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 2;
762 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
763 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
764 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
765 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
766 p_pic->p[ U_PLANE ].i_lines = i_height_aligned / 2;
767 p_pic->p[ U_PLANE ].i_visible_lines = i_height / 2;
768 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned;
769 p_pic->p[ U_PLANE ].i_visible_pitch = i_width;
770 p_pic->p[ V_PLANE ].i_lines = i_height_aligned / 2;
771 p_pic->p[ V_PLANE ].i_visible_lines = i_height / 2;
772 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned;
773 p_pic->p[ V_PLANE ].i_visible_pitch = i_width;
779 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
780 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
781 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
782 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
783 p_pic->p[ U_PLANE ].i_lines = i_height_aligned;
784 p_pic->p[ U_PLANE ].i_visible_lines = i_height;
785 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned;
786 p_pic->p[ U_PLANE ].i_visible_pitch = i_width;
787 p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
788 p_pic->p[ V_PLANE ].i_visible_lines = i_height;
789 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned;
790 p_pic->p[ V_PLANE ].i_visible_pitch = i_width;
795 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
796 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
797 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
798 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
799 p_pic->p[ U_PLANE ].i_lines = i_height_aligned;
800 p_pic->p[ U_PLANE ].i_visible_lines = i_height;
801 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned;
802 p_pic->p[ U_PLANE ].i_visible_pitch = i_width;
803 p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
804 p_pic->p[ V_PLANE ].i_visible_lines = i_height;
805 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned;
806 p_pic->p[ V_PLANE ].i_visible_pitch = i_width;
807 p_pic->p[ A_PLANE ].i_lines = i_height_aligned;
808 p_pic->p[ A_PLANE ].i_visible_lines = i_height;
809 p_pic->p[ A_PLANE ].i_pitch = i_width_aligned;
810 p_pic->p[ A_PLANE ].i_visible_pitch = i_width;
815 p_pic->p->i_lines = i_height_aligned;
816 p_pic->p->i_visible_lines = i_height;
817 p_pic->p->i_pitch = i_width_aligned;
818 p_pic->p->i_visible_pitch = i_width;
819 p_pic->p->i_pixel_pitch = 8;
824 p_pic->p->i_lines = i_height_aligned;
825 p_pic->p->i_visible_lines = i_height;
826 p_pic->p->i_pitch = i_width_aligned;
827 p_pic->p->i_visible_pitch = i_width;
828 p_pic->p->i_pixel_pitch = 4;
834 p_pic->p->i_lines = i_height_aligned;
835 p_pic->p->i_visible_lines = i_height;
836 p_pic->p->i_pitch = i_width_aligned * 2;
837 p_pic->p->i_visible_pitch = i_width * 2;
838 p_pic->p->i_pixel_pitch = 4;
843 p_pic->p->i_lines = i_height_aligned;
844 p_pic->p->i_visible_lines = i_height;
845 p_pic->p->i_pitch = i_width_aligned;
846 p_pic->p->i_visible_pitch = i_width;
847 p_pic->p->i_pixel_pitch = 1;
852 p_pic->p->i_lines = i_height_aligned;
853 p_pic->p->i_visible_lines = i_height;
854 p_pic->p->i_pitch = i_width_aligned * 2;
855 p_pic->p->i_visible_pitch = i_width * 2;
856 p_pic->p->i_pixel_pitch = 2;
861 p_pic->p->i_lines = i_height_aligned;
862 p_pic->p->i_visible_lines = i_height;
863 p_pic->p->i_pitch = i_width_aligned * 2;
864 p_pic->p->i_visible_pitch = i_width * 2;
865 p_pic->p->i_pixel_pitch = 2;
870 p_pic->p->i_lines = i_height_aligned;
871 p_pic->p->i_visible_lines = i_height;
872 p_pic->p->i_pitch = i_width_aligned * 3;
873 p_pic->p->i_visible_pitch = i_width * 3;
874 p_pic->p->i_pixel_pitch = 3;
880 p_pic->p->i_lines = i_height_aligned;
881 p_pic->p->i_visible_lines = i_height;
882 p_pic->p->i_pitch = i_width_aligned * 4;
883 p_pic->p->i_visible_pitch = i_width * 4;
884 p_pic->p->i_pixel_pitch = 4;
892 p_pic->p->i_lines = i_height_aligned;
893 p_pic->p->i_visible_lines = i_height;
894 p_pic->p->i_pitch = i_width_aligned;
895 p_pic->p->i_visible_pitch = i_width;
896 p_pic->p->i_pixel_pitch = 1;
902 msg_Err( p_this, "unknown chroma type 0x%.8x (%4.4s)",
903 i_chroma, (char*)&i_chroma );
912 * Compare two chroma values
914 * This function returns 1 if the two fourcc values given as argument are
915 * the same format (eg. UYVY/UYNV) or almost the same format (eg. I420/YV12)
917 int vout_ChromaCmp( vlc_fourcc_t i_chroma, vlc_fourcc_t i_amorhc )
919 /* If they are the same, they are the same ! */
920 if( i_chroma == i_amorhc )
925 /* Check for equivalence classes */
987 /*****************************************************************************
988 * vout_CopyPicture: copy a picture to another one
989 *****************************************************************************
990 * This function takes advantage of the image format, and reduces the
991 * number of calls to memcpy() to the minimum. Source and destination
992 * images must have same width (hence i_visible_pitch), height, and chroma.
993 *****************************************************************************/
994 void __vout_CopyPicture( vlc_object_t *p_this,
995 picture_t *p_dest, picture_t *p_src )
998 picture_Copy( p_dest, p_src );
1001 /*****************************************************************************
1003 *****************************************************************************/
1004 static void PictureReleaseCallback( picture_t *p_picture )
1006 if( --p_picture->i_refcount > 0 )
1008 picture_Delete( p_picture );
1010 /*****************************************************************************
1012 *****************************************************************************/
1013 picture_t *picture_New( vlc_fourcc_t i_chroma, int i_width, int i_height, int i_aspect )
1015 picture_t *p_picture = malloc( sizeof(*p_picture) );
1020 memset( p_picture, 0, sizeof(*p_picture) );
1021 if( __vout_AllocatePicture( NULL, p_picture,
1022 i_chroma, i_width, i_height, i_aspect ) )
1028 p_picture->i_refcount = 1;
1029 p_picture->pf_release = PictureReleaseCallback;
1030 p_picture->i_status = RESERVED_PICTURE;
1035 /*****************************************************************************
1037 *****************************************************************************/
1038 void picture_Delete( picture_t *p_picture )
1040 assert( p_picture && p_picture->i_refcount == 0 );
1042 free( p_picture->p_q );
1043 free( p_picture->p_data_orig );
1044 free( p_picture->p_sys );
1048 /*****************************************************************************
1050 *****************************************************************************/
1051 void picture_CopyPixels( picture_t *p_dst, const picture_t *p_src )
1055 for( i = 0; i < p_src->i_planes ; i++ )
1056 plane_CopyPixels( p_dst->p+i, p_src->p+i );
1059 void plane_CopyPixels( plane_t *p_dst, const plane_t *p_src )
1061 const unsigned i_width = __MIN( p_dst->i_visible_pitch,
1062 p_src->i_visible_pitch );
1063 const unsigned i_height = __MIN( p_dst->i_visible_lines,
1064 p_src->i_visible_lines );
1066 if( p_src->i_pitch == p_dst->i_pitch )
1068 /* There are margins, but with the same width : perfect ! */
1069 vlc_memcpy( p_dst->p_pixels, p_src->p_pixels,
1070 p_src->i_pitch * i_height );
1074 /* We need to proceed line by line */
1075 uint8_t *p_in = p_src->p_pixels;
1076 uint8_t *p_out = p_dst->p_pixels;
1082 for( i_line = i_height; i_line--; )
1084 vlc_memcpy( p_out, p_in, i_width );
1085 p_in += p_src->i_pitch;
1086 p_out += p_dst->i_pitch;
1091 /*****************************************************************************
1093 *****************************************************************************/