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 *****************************************************************************/
32 #include "vout_pictures.h"
37 * Remove the reservation flag of a picture, which will cause it to be ready
38 * for display. The picture won't be displayed until vout_DatePicture has been
41 void vout_DisplayPicture( vout_thread_t *p_vout, picture_t *p_pic )
43 vlc_mutex_lock( &p_vout->picture_lock );
44 switch( p_pic->i_status )
46 case RESERVED_PICTURE:
47 p_pic->i_status = RESERVED_DISP_PICTURE;
49 case RESERVED_DATED_PICTURE:
50 p_pic->i_status = READY_PICTURE;
53 msg_Err( p_vout, "picture to display %p has invalid status %d",
54 p_pic, p_pic->i_status );
58 vlc_mutex_unlock( &p_vout->picture_lock );
64 * Remove the reservation flag of a picture, which will cause it to be ready
65 * for display. The picture won't be displayed until vout_DisplayPicture has
67 * \param p_vout The vout in question
68 * \param p_pic The picture to date
69 * \param date The date to display the picture
71 void vout_DatePicture( vout_thread_t *p_vout,
72 picture_t *p_pic, mtime_t date )
74 vlc_mutex_lock( &p_vout->picture_lock );
76 switch( p_pic->i_status )
78 case RESERVED_PICTURE:
79 p_pic->i_status = RESERVED_DATED_PICTURE;
81 case RESERVED_DISP_PICTURE:
82 p_pic->i_status = READY_PICTURE;
85 msg_Err( p_vout, "picture to date %p has invalid status %d",
86 p_pic, p_pic->i_status );
90 vlc_mutex_unlock( &p_vout->picture_lock );
94 * Allocate a picture in the video output heap.
96 * This function creates a reserved image in the video output heap.
97 * A null pointer is returned if the function fails. This method provides an
98 * already allocated zone of memory in the picture data fields.
99 * It needs locking since several pictures can be created by several producers
102 picture_t *vout_CreatePicture( vout_thread_t *p_vout,
103 vlc_bool_t b_progressive,
104 vlc_bool_t b_top_field_first,
105 unsigned int i_nb_fields )
107 int i_pic; /* picture index */
109 picture_t * p_freepic = NULL; /* first free picture */
112 vlc_mutex_lock( &p_vout->picture_lock );
115 * Look for an empty place in the picture heap.
117 for( i_pic = 0; i_pic < I_RENDERPICTURES; i_pic++ )
119 p_pic = PP_RENDERPICTURE[(p_vout->render.i_last_used_pic + i_pic + 1)
122 switch( p_pic->i_status )
124 case DESTROYED_PICTURE:
125 /* Memory will not be reallocated, and function can end
126 * immediately - this is the best possible case, since no
127 * memory allocation needs to be done */
128 p_pic->i_status = RESERVED_PICTURE;
129 p_pic->i_refcount = 0;
132 p_pic->b_progressive = b_progressive;
133 p_pic->i_nb_fields = i_nb_fields;
134 p_pic->b_top_field_first = b_top_field_first;
136 p_vout->i_heap_size++;
137 p_vout->render.i_last_used_pic =
138 ( p_vout->render.i_last_used_pic + i_pic + 1 )
140 vlc_mutex_unlock( &p_vout->picture_lock );
144 /* Picture is empty and ready for allocation */
145 p_vout->render.i_last_used_pic =
146 ( p_vout->render.i_last_used_pic + i_pic + 1 )
159 if( p_freepic != NULL )
161 vout_AllocatePicture( VLC_OBJECT(p_vout),
162 p_freepic, p_vout->render.i_chroma,
163 p_vout->render.i_width, p_vout->render.i_height,
164 p_vout->render.i_aspect );
166 if( p_freepic->i_planes )
168 /* Copy picture information, set some default values */
169 p_freepic->i_status = RESERVED_PICTURE;
170 p_freepic->i_type = MEMORY_PICTURE;
171 p_freepic->b_slow = 0;
173 p_freepic->i_refcount = 0;
174 p_freepic->b_force = 0;
176 p_freepic->b_progressive = b_progressive;
177 p_freepic->i_nb_fields = i_nb_fields;
178 p_freepic->b_top_field_first = b_top_field_first;
180 p_freepic->i_matrix_coefficients = 1;
182 p_vout->i_heap_size++;
186 /* Memory allocation failed : set picture as empty */
187 p_freepic->i_status = FREE_PICTURE;
190 msg_Err( p_vout, "picture allocation failed" );
193 vlc_mutex_unlock( &p_vout->picture_lock );
198 /* No free or destroyed picture could be found, but the decoder
199 * will try again in a while. */
200 vlc_mutex_unlock( &p_vout->picture_lock );
206 * Remove a permanent or reserved picture from the heap
208 * This function frees a previously reserved picture or a permanent
209 * picture. It is meant to be used when the construction of a picture aborted.
210 * Note that the picture will be destroyed even if it is linked !
212 void vout_DestroyPicture( vout_thread_t *p_vout, picture_t *p_pic )
214 vlc_mutex_lock( &p_vout->picture_lock );
217 /* Check if picture status is valid */
218 if( (p_pic->i_status != RESERVED_PICTURE) &&
219 (p_pic->i_status != RESERVED_DATED_PICTURE) &&
220 (p_pic->i_status != RESERVED_DISP_PICTURE) )
222 msg_Err( p_vout, "picture to destroy %p has invalid status %d",
223 p_pic, p_pic->i_status );
227 p_pic->i_status = DESTROYED_PICTURE;
228 p_vout->i_heap_size--;
230 vlc_mutex_unlock( &p_vout->picture_lock );
234 * Increment reference counter of a picture
236 * This function increments the reference counter of a picture in the video
237 * heap. It needs a lock since several producer threads can access the picture.
239 void vout_LinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
241 vlc_mutex_lock( &p_vout->picture_lock );
243 vlc_mutex_unlock( &p_vout->picture_lock );
247 * Decrement reference counter of a picture
249 * This function decrement the reference counter of a picture in the video heap
251 void vout_UnlinkPicture( vout_thread_t *p_vout, picture_t *p_pic )
253 vlc_mutex_lock( &p_vout->picture_lock );
256 if( ( p_pic->i_refcount == 0 ) &&
257 ( p_pic->i_status == DISPLAYED_PICTURE ) )
259 p_pic->i_status = DESTROYED_PICTURE;
260 p_vout->i_heap_size--;
263 vlc_mutex_unlock( &p_vout->picture_lock );
269 * This function chooses whether the current picture needs to be copied
270 * before rendering, does the subpicture magic, and tells the video output
271 * thread which direct buffer needs to be displayed.
273 picture_t * vout_RenderPicture( vout_thread_t *p_vout, picture_t *p_pic,
274 subpicture_t *p_subpic )
276 int i_scale_width, i_scale_height;
284 i_scale_width = p_vout->fmt_out.i_visible_width * 1000 /
285 p_vout->fmt_in.i_visible_width;
286 i_scale_height = p_vout->fmt_out.i_visible_height * 1000 /
287 p_vout->fmt_in.i_visible_height;
289 if( p_pic->i_type == DIRECT_PICTURE )
291 if( !p_vout->render.b_allow_modify_pics || p_pic->i_refcount ||
294 /* Picture is in a direct buffer and is still in use,
295 * we need to copy it to another direct buffer before
296 * displaying it if there are subtitles. */
297 if( p_subpic != NULL )
299 /* We have subtitles. First copy the picture to
300 * the spare direct buffer, then render the
302 vout_CopyPicture( p_vout, PP_OUTPUTPICTURE[0], p_pic );
304 spu_RenderSubpictures( p_vout->p_spu, &p_vout->fmt_out,
305 PP_OUTPUTPICTURE[0], p_pic, p_subpic,
306 i_scale_width, i_scale_height );
308 return PP_OUTPUTPICTURE[0];
311 /* No subtitles, picture is in a directbuffer so
312 * we can display it directly even if it is still
317 /* Picture is in a direct buffer but isn't used by the
318 * decoder. We can safely render subtitles on it and
320 spu_RenderSubpictures( p_vout->p_spu, &p_vout->fmt_out, p_pic, p_pic,
321 p_subpic, i_scale_width, i_scale_height );
326 /* Not a direct buffer. We either need to copy it to a direct buffer,
327 * or render it if the chroma isn't the same. */
328 if( p_vout->b_direct )
330 /* Picture is not in a direct buffer, but is exactly the
331 * same size as the direct buffers. A memcpy() is enough,
332 * then render the subtitles. */
334 if( PP_OUTPUTPICTURE[0]->pf_lock )
335 if( PP_OUTPUTPICTURE[0]->pf_lock( p_vout, PP_OUTPUTPICTURE[0] ) )
338 vout_CopyPicture( p_vout, PP_OUTPUTPICTURE[0], p_pic );
339 spu_RenderSubpictures( p_vout->p_spu, &p_vout->fmt_out,
340 PP_OUTPUTPICTURE[0], p_pic,
341 p_subpic, i_scale_width, i_scale_height );
343 if( PP_OUTPUTPICTURE[0]->pf_unlock )
344 PP_OUTPUTPICTURE[0]->pf_unlock( p_vout, PP_OUTPUTPICTURE[0] );
346 return PP_OUTPUTPICTURE[0];
349 /* Picture is not in a direct buffer, and needs to be converted to
350 * another size/chroma. Then the subtitles need to be rendered as
351 * well. This usually means software YUV, or hardware YUV with a
352 * different chroma. */
354 if( p_subpic != NULL && p_vout->p_picture[0].b_slow )
356 /* The picture buffer is in slow memory. We'll use
357 * the "2 * VOUT_MAX_PICTURES + 1" picture as a temporary
358 * one for subpictures rendering. */
359 picture_t *p_tmp_pic = &p_vout->p_picture[2 * VOUT_MAX_PICTURES];
360 if( p_tmp_pic->i_status == FREE_PICTURE )
362 vout_AllocatePicture( VLC_OBJECT(p_vout),
363 p_tmp_pic, p_vout->fmt_out.i_chroma,
364 p_vout->fmt_out.i_width,
365 p_vout->fmt_out.i_height,
366 p_vout->fmt_out.i_aspect );
367 p_tmp_pic->i_type = MEMORY_PICTURE;
368 p_tmp_pic->i_status = RESERVED_PICTURE;
369 /* some modules (such as blend) needs to know the extra information in picture heap */
370 p_tmp_pic->p_heap = &p_vout->output;
373 /* Convert image to the first direct buffer */
374 p_vout->chroma.pf_convert( p_vout, p_pic, p_tmp_pic );
376 /* Render subpictures on the first direct buffer */
377 spu_RenderSubpictures( p_vout->p_spu, &p_vout->fmt_out, p_tmp_pic,
379 i_scale_width, i_scale_height );
381 if( p_vout->p_picture[0].pf_lock )
382 if( p_vout->p_picture[0].pf_lock( p_vout, &p_vout->p_picture[0] ) )
385 vout_CopyPicture( p_vout, &p_vout->p_picture[0], p_tmp_pic );
389 if( p_vout->p_picture[0].pf_lock )
390 if( p_vout->p_picture[0].pf_lock( p_vout, &p_vout->p_picture[0] ) )
393 /* Convert image to the first direct buffer */
394 p_vout->chroma.pf_convert( p_vout, p_pic, &p_vout->p_picture[0] );
396 /* Render subpictures on the first direct buffer */
397 spu_RenderSubpictures( p_vout->p_spu, &p_vout->fmt_out,
398 &p_vout->p_picture[0], &p_vout->p_picture[0],
399 p_subpic, i_scale_width, i_scale_height );
402 if( p_vout->p_picture[0].pf_unlock )
403 p_vout->p_picture[0].pf_unlock( p_vout, &p_vout->p_picture[0] );
405 return &p_vout->p_picture[0];
409 * Calculate image window coordinates
411 * This function will be accessed by plugins. It calculates the relative
412 * position of the output window and the image window.
414 void vout_PlacePicture( vout_thread_t *p_vout,
415 unsigned int i_width, unsigned int i_height,
416 unsigned int *pi_x, unsigned int *pi_y,
417 unsigned int *pi_width, unsigned int *pi_height )
419 if( (i_width <= 0) || (i_height <=0) )
421 *pi_width = *pi_height = *pi_x = *pi_y = 0;
425 if( p_vout->b_scale )
428 *pi_height = i_height;
432 *pi_width = __MIN( i_width, p_vout->fmt_in.i_visible_width );
433 *pi_height = __MIN( i_height, p_vout->fmt_in.i_visible_height );
436 if( p_vout->fmt_in.i_visible_width * (int64_t)p_vout->fmt_in.i_sar_num *
437 *pi_height / p_vout->fmt_in.i_visible_height /
438 p_vout->fmt_in.i_sar_den > *pi_width )
440 *pi_height = p_vout->fmt_in.i_visible_height *
441 (int64_t)p_vout->fmt_in.i_sar_den * *pi_width /
442 p_vout->fmt_in.i_visible_width / p_vout->fmt_in.i_sar_num;
446 *pi_width = p_vout->fmt_in.i_visible_width *
447 (int64_t)p_vout->fmt_in.i_sar_num * *pi_height /
448 p_vout->fmt_in.i_visible_height / p_vout->fmt_in.i_sar_den;
451 switch( p_vout->i_alignment & VOUT_ALIGN_HMASK )
453 case VOUT_ALIGN_LEFT:
456 case VOUT_ALIGN_RIGHT:
457 *pi_x = i_width - *pi_width;
460 *pi_x = ( i_width - *pi_width ) / 2;
463 switch( p_vout->i_alignment & VOUT_ALIGN_VMASK )
468 case VOUT_ALIGN_BOTTOM:
469 *pi_y = i_height - *pi_height;
472 *pi_y = ( i_height - *pi_height ) / 2;
477 * Allocate a new picture in the heap.
479 * This function allocates a fake direct buffer in memory, which can be
480 * used exactly like a video buffer. The video output thread then manages
481 * how it gets displayed.
483 int __vout_AllocatePicture( vlc_object_t *p_this, picture_t *p_pic,
484 vlc_fourcc_t i_chroma,
485 int i_width, int i_height, int i_aspect )
487 int i_bytes, i_index, i_width_aligned, i_height_aligned;
489 /* Make sure the real dimensions are a multiple of 16 */
490 i_width_aligned = (i_width + 15) >> 4 << 4;
491 i_height_aligned = (i_height + 15) >> 4 << 4;
493 if( vout_InitPicture( p_this, p_pic, i_chroma,
494 i_width, i_height, i_aspect ) != VLC_SUCCESS )
500 /* Calculate how big the new image should be */
501 i_bytes = p_pic->format.i_bits_per_pixel *
502 i_width_aligned * i_height_aligned / 8;
504 p_pic->p_data = vlc_memalign( &p_pic->p_data_orig, 16, i_bytes );
506 if( p_pic->p_data == NULL )
512 /* Fill the p_pixels field for each plane */
513 p_pic->p[ 0 ].p_pixels = p_pic->p_data;
515 for( i_index = 1; i_index < p_pic->i_planes; i_index++ )
517 p_pic->p[i_index].p_pixels = p_pic->p[i_index-1].p_pixels +
518 p_pic->p[i_index-1].i_lines * p_pic->p[i_index-1].i_pitch;
525 * Initialise the video format fields given chroma/size.
527 * This function initializes all the video_frame_format_t fields given the
528 * static properties of a picture (chroma and size).
529 * \param p_format Pointer to the format structure to initialize
530 * \param i_chroma Chroma to set
531 * \param i_width Width to set
532 * \param i_height Height to set
533 * \param i_aspect Aspect ratio
535 void vout_InitFormat( video_frame_format_t *p_format, vlc_fourcc_t i_chroma,
536 int i_width, int i_height, int i_aspect )
538 p_format->i_chroma = i_chroma;
539 p_format->i_width = p_format->i_visible_width = i_width;
540 p_format->i_height = p_format->i_visible_height = i_height;
541 p_format->i_x_offset = p_format->i_y_offset = 0;
542 p_format->i_aspect = i_aspect;
545 /* Assume we have square pixels */
546 if( i_width && i_height )
547 p_format->i_aspect = i_width * VOUT_ASPECT_FACTOR / i_height;
549 p_format->i_aspect = 0;
555 p_format->i_bits_per_pixel = 32;
559 p_format->i_bits_per_pixel = 24;
565 p_format->i_bits_per_pixel = 16;
572 p_format->i_bits_per_pixel = 12;
576 p_format->i_bits_per_pixel = 9;
579 p_format->i_bits_per_pixel = 8;
582 p_format->i_bits_per_pixel = 8;
587 p_format->i_bits_per_pixel = 32;
590 p_format->i_bits_per_pixel = 24;
594 p_format->i_bits_per_pixel = 16;
597 p_format->i_bits_per_pixel = 8;
601 p_format->i_bits_per_pixel = 8;
605 p_format->i_bits_per_pixel = 0;
611 * Initialise the picture_t fields given chroma/size.
613 * This function initializes most of the picture_t fields given a chroma and
614 * size. It makes the assumption that stride == width.
615 * \param p_this The calling object
616 * \param p_pic Pointer to the picture to initialize
617 * \param i_chroma The chroma fourcc to set
618 * \param i_width The width of the picture
619 * \param i_height The height of the picture
620 * \param i_aspect The aspect ratio of the picture
622 int __vout_InitPicture( vlc_object_t *p_this, picture_t *p_pic,
623 vlc_fourcc_t i_chroma,
624 int i_width, int i_height, int i_aspect )
626 int i_index, i_width_aligned, i_height_aligned;
628 /* Store default values */
629 for( i_index = 0; i_index < VOUT_MAX_PLANES; i_index++ )
631 p_pic->p[i_index].p_pixels = NULL;
632 p_pic->p[i_index].i_pixel_pitch = 1;
635 p_pic->pf_release = 0;
637 p_pic->pf_unlock = 0;
638 p_pic->i_refcount = 0;
640 vout_InitFormat( &p_pic->format, i_chroma, i_width, i_height, i_aspect );
642 /* Make sure the real dimensions are a multiple of 16 */
643 i_width_aligned = (i_width + 15) >> 4 << 4;
644 i_height_aligned = (i_height + 15) >> 4 << 4;
646 /* Calculate coordinates */
650 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
651 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
652 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
653 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
654 p_pic->p[ U_PLANE ].i_lines = i_height_aligned;
655 p_pic->p[ U_PLANE ].i_visible_lines = i_height;
656 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 4;
657 p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 4;
658 p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
659 p_pic->p[ V_PLANE ].i_visible_lines = i_height;
660 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 4;
661 p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 4;
667 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
668 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
669 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
670 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
671 p_pic->p[ U_PLANE ].i_lines = i_height_aligned / 4;
672 p_pic->p[ U_PLANE ].i_visible_lines = i_height / 4;
673 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 4;
674 p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 4;
675 p_pic->p[ V_PLANE ].i_lines = i_height_aligned / 4;
676 p_pic->p[ V_PLANE ].i_visible_lines = i_height / 4;
677 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 4;
678 p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 4;
686 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
687 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
688 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
689 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
690 p_pic->p[ U_PLANE ].i_lines = i_height_aligned / 2;
691 p_pic->p[ U_PLANE ].i_visible_lines = i_height / 2;
692 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 2;
693 p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 2;
694 p_pic->p[ V_PLANE ].i_lines = i_height_aligned / 2;
695 p_pic->p[ V_PLANE ].i_visible_lines = i_height / 2;
696 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 2;
697 p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 2;
703 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
704 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
705 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
706 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
707 p_pic->p[ U_PLANE ].i_lines = i_height_aligned;
708 p_pic->p[ U_PLANE ].i_visible_lines = i_height;
709 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned / 2;
710 p_pic->p[ U_PLANE ].i_visible_pitch = i_width / 2;
711 p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
712 p_pic->p[ V_PLANE ].i_visible_lines = i_height;
713 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned / 2;
714 p_pic->p[ V_PLANE ].i_visible_pitch = i_width / 2;
720 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
721 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
722 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
723 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
724 p_pic->p[ U_PLANE ].i_lines = i_height_aligned;
725 p_pic->p[ U_PLANE ].i_visible_lines = i_height;
726 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned;
727 p_pic->p[ U_PLANE ].i_visible_pitch = i_width;
728 p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
729 p_pic->p[ V_PLANE ].i_visible_lines = i_height;
730 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned;
731 p_pic->p[ V_PLANE ].i_visible_pitch = i_width;
736 p_pic->p[ Y_PLANE ].i_lines = i_height_aligned;
737 p_pic->p[ Y_PLANE ].i_visible_lines = i_height;
738 p_pic->p[ Y_PLANE ].i_pitch = i_width_aligned;
739 p_pic->p[ Y_PLANE ].i_visible_pitch = i_width;
740 p_pic->p[ U_PLANE ].i_lines = i_height_aligned;
741 p_pic->p[ U_PLANE ].i_visible_lines = i_height;
742 p_pic->p[ U_PLANE ].i_pitch = i_width_aligned;
743 p_pic->p[ U_PLANE ].i_visible_pitch = i_width;
744 p_pic->p[ V_PLANE ].i_lines = i_height_aligned;
745 p_pic->p[ V_PLANE ].i_visible_lines = i_height;
746 p_pic->p[ V_PLANE ].i_pitch = i_width_aligned;
747 p_pic->p[ V_PLANE ].i_visible_pitch = i_width;
748 p_pic->p[ A_PLANE ].i_lines = i_height_aligned;
749 p_pic->p[ A_PLANE ].i_visible_lines = i_height;
750 p_pic->p[ A_PLANE ].i_pitch = i_width_aligned;
751 p_pic->p[ A_PLANE ].i_visible_pitch = i_width;
756 p_pic->p->i_lines = i_height_aligned;
757 p_pic->p->i_visible_lines = i_height;
758 p_pic->p->i_pitch = i_width_aligned;
759 p_pic->p->i_visible_pitch = i_width;
760 p_pic->p->i_pixel_pitch = 8;
765 p_pic->p->i_lines = i_height_aligned;
766 p_pic->p->i_visible_lines = i_height;
767 p_pic->p->i_pitch = i_width_aligned;
768 p_pic->p->i_visible_pitch = i_width;
769 p_pic->p->i_pixel_pitch = 4;
775 p_pic->p->i_lines = i_height_aligned;
776 p_pic->p->i_visible_lines = i_height;
777 p_pic->p->i_pitch = i_width_aligned * 2;
778 p_pic->p->i_visible_pitch = i_width * 2;
779 p_pic->p->i_pixel_pitch = 4;
784 p_pic->p->i_lines = i_height_aligned;
785 p_pic->p->i_visible_lines = i_height;
786 p_pic->p->i_pitch = i_width_aligned;
787 p_pic->p->i_visible_pitch = i_width;
788 p_pic->p->i_pixel_pitch = 1;
793 p_pic->p->i_lines = i_height_aligned;
794 p_pic->p->i_visible_lines = i_height;
795 p_pic->p->i_pitch = i_width_aligned * 2;
796 p_pic->p->i_visible_pitch = i_width * 2;
797 p_pic->p->i_pixel_pitch = 2;
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 * 2;
805 p_pic->p->i_visible_pitch = i_width * 2;
806 p_pic->p->i_pixel_pitch = 2;
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 * 3;
814 p_pic->p->i_visible_pitch = i_width * 3;
815 p_pic->p->i_pixel_pitch = 3;
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 * 4;
824 p_pic->p->i_visible_pitch = i_width * 4;
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 msg_Err( p_this, "unknown chroma type 0x%.8x (%4.4s)",
840 i_chroma, (char*)&i_chroma );
849 * Compare two chroma values
851 * This function returns 1 if the two fourcc values given as argument are
852 * the same format (eg. UYVY/UYNV) or almost the same format (eg. I420/YV12)
854 int vout_ChromaCmp( vlc_fourcc_t i_chroma, vlc_fourcc_t i_amorhc )
856 /* If they are the same, they are the same ! */
857 if( i_chroma == i_amorhc )
862 /* Check for equivalence classes */
910 /*****************************************************************************
911 * vout_CopyPicture: copy a picture to another one
912 *****************************************************************************
913 * This function takes advantage of the image format, and reduces the
914 * number of calls to memcpy() to the minimum. Source and destination
915 * images must have same width (hence i_visible_pitch), height, and chroma.
916 *****************************************************************************/
917 void __vout_CopyPicture( vlc_object_t *p_this,
918 picture_t *p_dest, picture_t *p_src )
922 for( i = 0; i < p_src->i_planes ; i++ )
924 if( p_src->p[i].i_pitch == p_dest->p[i].i_pitch )
926 /* There are margins, but with the same width : perfect ! */
927 p_this->p_libvlc->pf_memcpy(
928 p_dest->p[i].p_pixels, p_src->p[i].p_pixels,
929 p_src->p[i].i_pitch * p_src->p[i].i_visible_lines );
933 /* We need to proceed line by line */
934 uint8_t *p_in = p_src->p[i].p_pixels;
935 uint8_t *p_out = p_dest->p[i].p_pixels;
938 for( i_line = p_src->p[i].i_visible_lines; i_line--; )
940 p_this->p_libvlc->pf_memcpy( p_out, p_in,
941 p_src->p[i].i_visible_pitch );
942 p_in += p_src->p[i].i_pitch;
943 p_out += p_dest->p[i].i_pitch;
948 p_dest->date = p_src->date;
949 p_dest->b_force = p_src->b_force;
950 p_dest->i_nb_fields = p_src->i_nb_fields;
951 p_dest->b_progressive = p_src->b_progressive;
952 p_dest->b_top_field_first = p_src->b_top_field_first;