1 /*****************************************************************************
2 * blend.c: alpha blend 2 pictures together
3 *****************************************************************************
4 * Copyright (C) 2003-2009 the VideoLAN team
7 * Authors: Gildas Bazin <gbazin@videolan.org>
8 * Antoine Cellerier <dionoea @t videolan dot 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>
34 #include <vlc_plugin.h>
35 #include <vlc_filter.h>
36 #include "filter_picture.h"
38 /*****************************************************************************
40 *****************************************************************************/
41 static int OpenFilter ( vlc_object_t * );
42 static void CloseFilter( vlc_object_t * );
45 set_description( N_("Video pictures blending") )
46 set_capability( "video blending", 100 )
47 set_callbacks( OpenFilter, CloseFilter )
50 /****************************************************************************
52 ****************************************************************************/
53 static void Blend( filter_t *, picture_t *, const picture_t *,
57 static void BlendYUVAI420( filter_t *, picture_t *, const picture_t *,
58 int, int, int, int, int );
59 static void BlendYUVARV16( filter_t *, picture_t *, const picture_t *,
60 int, int, int, int, int );
61 static void BlendYUVARV24( filter_t *, picture_t *, const picture_t *,
62 int, int, int, int, int );
63 static void BlendYUVAYUVPacked( filter_t *, picture_t *, const picture_t *,
64 int, int, int, int, int );
67 static void BlendI420I420( filter_t *, picture_t *, const picture_t *,
68 int, int, int, int, int );
69 static void BlendI420I420_no_alpha(
70 filter_t *, picture_t *, const picture_t *,
72 static void BlendI420R16( filter_t *, picture_t *, const picture_t *,
73 int, int, int, int, int );
74 static void BlendI420R24( filter_t *, picture_t *, const picture_t *,
75 int, int, int, int, int );
76 static void BlendI420YUVPacked( filter_t *, picture_t *,
77 const picture_t *, int, int, int, int, int );
80 static void BlendPalI420( filter_t *, picture_t *, const picture_t *,
81 int, int, int, int, int );
82 static void BlendPalYUVPacked( filter_t *, picture_t *, const picture_t *,
83 int, int, int, int, int );
84 static void BlendPalRV( filter_t *, picture_t *, const picture_t *,
85 int, int, int, int, int );
88 static void BlendRGBAI420( filter_t *, picture_t *, const picture_t *,
89 int, int, int, int, int );
90 static void BlendRGBAYUVPacked( filter_t *, picture_t *,
91 const picture_t *, int, int, int, int, int );
92 static void BlendRGBAR16( filter_t *, picture_t *, const picture_t *,
93 int, int, int, int, int );
94 static void BlendRGBAR24( filter_t *, picture_t *, const picture_t *,
95 int, int, int, int, int );
102 typedef void (*BlendFunction)( filter_t *,
103 picture_t *, const picture_t *,
104 int , int , int , int , int );
106 #define VLC_CODEC_PLANAR_420 { VLC_CODEC_I420, VLC_CODEC_J420, VLC_CODEC_YV12, 0 }
107 #define VLC_CODEC_PACKED_422 { VLC_CODEC_YUYV, VLC_CODEC_UYVY, VLC_CODEC_YVYU, VLC_CODEC_VYUY, 0 }
108 #define VLC_CODEC_RGB_16 { VLC_CODEC_RGB15, VLC_CODEC_RGB16, 0 }
109 #define VLC_CODEC_RGB_24 { VLC_CODEC_RGB24, VLC_CODEC_RGB32, 0 }
111 #define BLEND_CFG( fccSrc, fctPlanar, fctPacked, fctRgb16, fctRgb24 ) \
112 { .src = fccSrc, .p_dst = VLC_CODEC_PLANAR_420, .pf_blend = fctPlanar }, \
113 { .src = fccSrc, .p_dst = VLC_CODEC_PACKED_422, .pf_blend = fctPacked }, \
114 { .src = fccSrc, .p_dst = VLC_CODEC_RGB_16, .pf_blend = fctRgb16 }, \
115 { .src = fccSrc, .p_dst = VLC_CODEC_RGB_24, .pf_blend = fctRgb24 }
120 vlc_fourcc_t p_dst[16];
121 BlendFunction pf_blend;
124 BLEND_CFG( VLC_CODEC_YUVA, BlendYUVAI420, BlendYUVAYUVPacked, BlendYUVARV16, BlendYUVARV24 ),
126 BLEND_CFG( VLC_CODEC_YUVP, BlendPalI420, BlendPalYUVPacked, BlendPalRV, BlendPalRV ),
128 BLEND_CFG( VLC_CODEC_RGBA, BlendRGBAI420, BlendRGBAYUVPacked, BlendRGBAR16, BlendRGBAR24 ),
130 BLEND_CFG( VLC_CODEC_I420, BlendI420I420, BlendI420YUVPacked, BlendI420R16, BlendI420R24 ),
132 BLEND_CFG( VLC_CODEC_YV12, BlendI420I420, BlendI420YUVPacked, BlendI420R16, BlendI420R24 ),
137 /*****************************************************************************
138 * OpenFilter: probe the filter and return score
139 *****************************************************************************/
140 static int OpenFilter( vlc_object_t *p_this )
142 filter_t *p_filter = (filter_t*)p_this;
143 filter_sys_t *p_sys = (filter_sys_t *)malloc( sizeof( filter_sys_t ) );
146 p_filter->p_sys = p_sys;
147 p_filter->p_sys->i_blendcfg = -1;
149 /* Check if we can handle that format.
150 * We could try to use a chroma filter if we can't. */
151 int in_chroma = p_filter->fmt_in.video.i_chroma;
152 int out_chroma = p_filter->fmt_out.video.i_chroma;
154 if( ( in_chroma != VLC_CODEC_YUVA && in_chroma != VLC_CODEC_I420 &&
155 in_chroma != VLC_CODEC_YV12 && in_chroma != VLC_CODEC_YUVP &&
156 in_chroma != VLC_CODEC_RGBA ) ||
157 ( out_chroma != VLC_CODEC_I420 && out_chroma != VLC_CODEC_J420 &&
158 out_chroma != VLC_CODEC_YV12 &&
159 out_chroma != VLC_CODEC_YUYV && out_chroma != VLC_CODEC_YVYU &&
160 out_chroma != VLC_CODEC_UYVY && out_chroma != VLC_CODEC_VYUY &&
161 out_chroma != VLC_CODEC_RGB15 &&
162 out_chroma != VLC_CODEC_RGB16 &&
163 out_chroma != VLC_CODEC_RGB24 &&
164 out_chroma != VLC_CODEC_RGB32 ) )
168 for( int i = 0; p_blend_cfg[i].src != 0; i++ )
170 if( p_blend_cfg[i].src != p_filter->fmt_in.video.i_chroma )
172 for( int j = 0; p_blend_cfg[i].p_dst[j] != 0; j++ )
174 if( p_blend_cfg[i].p_dst[j] != p_filter->fmt_out.video.i_chroma )
176 p_sys->i_blendcfg = i;
180 if( p_sys->i_blendcfg == -1 )
182 msg_Dbg( p_filter, "no matching alpha blending routine "
183 "(chroma: %4.4s -> %4.4s)",
184 (char *)&p_filter->fmt_in.video.i_chroma,
185 (char *)&p_filter->fmt_out.video.i_chroma );
191 p_filter->pf_video_blend = Blend;
193 msg_Dbg( p_filter, "chroma: %4.4s -> %4.4s",
194 (char *)&p_filter->fmt_in.video.i_chroma,
195 (char *)&p_filter->fmt_out.video.i_chroma );
200 /*****************************************************************************
201 * CloseFilter: clean up the filter
202 *****************************************************************************/
203 static void CloseFilter( vlc_object_t *p_this )
205 filter_t *p_filter = (filter_t*)p_this;
206 free( p_filter->p_sys );
209 /****************************************************************************
210 * Blend: the whole thing
211 ****************************************************************************
212 * This function is called just after the thread is launched.
213 ****************************************************************************/
215 static void Blend( filter_t *p_filter,
216 picture_t *p_dst, const picture_t *p_src,
217 int i_x_offset, int i_y_offset, int i_alpha )
219 int i_width, i_height;
224 i_width = __MIN((int)p_filter->fmt_out.video.i_visible_width - i_x_offset,
225 (int)p_filter->fmt_in.video.i_visible_width);
227 i_height = __MIN((int)p_filter->fmt_out.video.i_visible_height -i_y_offset,
228 (int)p_filter->fmt_in.video.i_visible_height);
230 if( i_width <= 0 || i_height <= 0 )
233 video_format_FixRgb( &p_filter->fmt_out.video );
234 video_format_FixRgb( &p_filter->fmt_in.video );
237 msg_Dbg( p_filter, "chroma: %4.4s -> %4.4s",
238 (char *)&p_filter->fmt_in.video.i_chroma,
239 (char *)&p_filter->fmt_out.video.i_chroma );
243 p_blend_cfg[p_filter->p_sys->i_blendcfg].pf_blend( p_filter, p_dst, p_src,
244 i_x_offset, i_y_offset,
245 i_width, i_height, i_alpha );
249 /***********************************************************************
251 ***********************************************************************/
252 #define MAX_TRANS 255
255 static inline int vlc_blend( int v1, int v2, int a )
257 /* TODO bench if the tests really increase speed */
260 else if( a == MAX_TRANS )
262 return ( v1 * a + v2 * (MAX_TRANS - a ) ) >> TRANS_BITS;
265 static inline int vlc_alpha( int t, int a )
269 return (t * a) / 255;
272 static uint8_t *vlc_plane_start( int *pi_pitch,
273 const picture_t *p_picture,
275 int i_x_offset, int i_y_offset,
276 const video_format_t *p_fmt,
279 const int i_pitch = p_picture->p[i_plane].i_pitch;
280 uint8_t *p_pixels = p_picture->p[i_plane].p_pixels;
282 const int i_dx = ( i_x_offset + p_fmt->i_x_offset ) / r;
283 const int i_dy = ( i_y_offset + p_fmt->i_y_offset ) / r;
287 return &p_pixels[ i_dy * i_pitch + i_dx ];
290 static void vlc_yuv_packed_index( int *pi_y, int *pi_u, int *pi_v, vlc_fourcc_t i_chroma )
292 static const struct {
296 { VLC_CODEC_YUYV, 0, 1, 3 },
297 { VLC_CODEC_UYVY, 1, 0, 2 },
298 { VLC_CODEC_YVYU, 0, 3, 1 },
299 { VLC_CODEC_VYUY, 1, 2, 0 },
304 for( i = 0; p_index[i].chroma != 0; i++ )
306 if( p_index[i].chroma == i_chroma )
309 *pi_y = p_index[i].y;
310 *pi_u = p_index[i].u;
311 *pi_v = p_index[i].v;
314 static void vlc_blend_packed( uint8_t *p_dst,
315 int i_offset0, int i_offset1, int i_offset2,
316 int c0, int c1, int c2, int i_alpha,
319 p_dst[i_offset0] = vlc_blend( c0, p_dst[i_offset0], i_alpha );
322 p_dst[i_offset1] = vlc_blend( c1, p_dst[i_offset1], i_alpha );
323 p_dst[i_offset2] = vlc_blend( c2, p_dst[i_offset2], i_alpha );
327 static void vlc_blend_rgb16( uint16_t *p_dst,
328 int R, int G, int B, int i_alpha,
329 const video_format_t *p_fmt )
331 const int i_pix = *p_dst;
332 const int r = ( i_pix & p_fmt->i_rmask ) >> p_fmt->i_lrshift;
333 const int g = ( i_pix & p_fmt->i_gmask ) >> p_fmt->i_lgshift;
334 const int b = ( i_pix & p_fmt->i_bmask ) >> p_fmt->i_lbshift;
336 *p_dst = ( vlc_blend( R >> p_fmt->i_rrshift, r, i_alpha ) << p_fmt->i_lrshift ) |
337 ( vlc_blend( G >> p_fmt->i_rgshift, g, i_alpha ) << p_fmt->i_lgshift ) |
338 ( vlc_blend( B >> p_fmt->i_rbshift, b, i_alpha ) << p_fmt->i_lbshift );
341 static void vlc_rgb_index( int *pi_rindex, int *pi_gindex, int *pi_bindex,
342 const video_format_t *p_fmt )
344 if( p_fmt->i_chroma != VLC_CODEC_RGB24 && p_fmt->i_chroma != VLC_CODEC_RGB32 )
347 /* XXX it will works only if mask are 8 bits aligned */
348 #ifdef WORDS_BIGENDIAN
349 const int i_mask_bits = p_fmt->i_chroma == VLC_CODEC_RGB24 ? 24 : 32;
350 *pi_rindex = ( i_mask_bits - p_fmt->i_lrshift ) / 8;
351 *pi_gindex = ( i_mask_bits - p_fmt->i_lgshift ) / 8;
352 *pi_bindex = ( i_mask_bits - p_fmt->i_lbshift ) / 8;
354 *pi_rindex = p_fmt->i_lrshift / 8;
355 *pi_gindex = p_fmt->i_lgshift / 8;
356 *pi_bindex = p_fmt->i_lbshift / 8;
360 /***********************************************************************
362 ***********************************************************************/
363 static void BlendYUVAI420( filter_t *p_filter,
364 picture_t *p_dst, const picture_t *p_src,
365 int i_x_offset, int i_y_offset,
366 int i_width, int i_height, int i_alpha )
368 int i_src_pitch, i_dst_pitch;
369 uint8_t *p_src_y, *p_dst_y;
370 uint8_t *p_src_u, *p_dst_u;
371 uint8_t *p_src_v, *p_dst_v;
373 int i_x, i_y, i_trans = 0;
374 bool b_even_scanline = i_y_offset % 2;
376 bool b_swap_up = vlc_fourcc_AreUVPlanesSwapped( p_filter->fmt_out.video.i_chroma,
378 p_dst_y = vlc_plane_start( &i_dst_pitch, p_dst, Y_PLANE,
379 i_x_offset, i_y_offset, &p_filter->fmt_out.video, 1 );
380 p_dst_u = vlc_plane_start( NULL, p_dst, b_swap_up ? V_PLANE : U_PLANE,
381 i_x_offset, i_y_offset, &p_filter->fmt_out.video, 2 );
382 p_dst_v = vlc_plane_start( NULL, p_dst, b_swap_up ? U_PLANE : V_PLANE,
383 i_x_offset, i_y_offset, &p_filter->fmt_out.video, 2 );
385 p_src_y = vlc_plane_start( &i_src_pitch, p_src, Y_PLANE,
386 0, 0, &p_filter->fmt_in.video, 1 );
387 p_src_u = vlc_plane_start( NULL, p_src, U_PLANE,
388 0, 0, &p_filter->fmt_in.video, 2 );
389 p_src_v = vlc_plane_start( NULL, p_src, V_PLANE,
390 0, 0, &p_filter->fmt_in.video, 2 );
391 p_trans = vlc_plane_start( NULL, p_src, A_PLANE,
392 0, 0, &p_filter->fmt_in.video, 1 );
394 /* Draw until we reach the bottom of the subtitle */
395 for( i_y = 0; i_y < i_height; i_y++, p_trans += i_src_pitch,
396 p_dst_y += i_dst_pitch, p_src_y += i_src_pitch,
397 p_dst_u += b_even_scanline ? i_dst_pitch/2 : 0,
398 p_src_u += i_src_pitch,
399 p_dst_v += b_even_scanline ? i_dst_pitch/2 : 0,
400 p_src_v += i_src_pitch )
402 b_even_scanline = !b_even_scanline;
404 /* Draw until we reach the end of the line */
405 for( i_x = 0; i_x < i_width; i_x++ )
408 i_trans = vlc_alpha( p_trans[i_x], i_alpha );
414 p_dst_y[i_x] = vlc_blend( p_src_y[i_x], p_dst_y[i_x], i_trans );
415 if( b_even_scanline && i_x % 2 == 0 )
417 p_dst_u[i_x/2] = vlc_blend( p_src_u[i_x], p_dst_u[i_x/2], i_trans );
418 p_dst_v[i_x/2] = vlc_blend( p_src_v[i_x], p_dst_v[i_x/2], i_trans );
424 static void BlendYUVARV16( filter_t *p_filter,
425 picture_t *p_dst_pic, const picture_t *p_src,
426 int i_x_offset, int i_y_offset,
427 int i_width, int i_height, int i_alpha )
429 int i_src_pitch, i_dst_pitch;
430 uint8_t *p_dst, *p_src_y;
431 uint8_t *p_src_u, *p_src_v;
433 int i_x, i_y, i_pix_pitch, i_trans = 0;
436 i_pix_pitch = p_dst_pic->p->i_pixel_pitch;
437 i_dst_pitch = p_dst_pic->p->i_pitch;
438 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
439 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
440 p_dst_pic->p->i_pitch *
441 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
443 p_src_y = vlc_plane_start( &i_src_pitch, p_src, Y_PLANE,
444 0, 0, &p_filter->fmt_in.video, 1 );
445 p_src_u = vlc_plane_start( NULL, p_src, U_PLANE,
446 0, 0, &p_filter->fmt_in.video, 2 );
447 p_src_v = vlc_plane_start( NULL, p_src, V_PLANE,
448 0, 0, &p_filter->fmt_in.video, 2 );
449 p_trans = vlc_plane_start( NULL, p_src, A_PLANE,
450 0, 0, &p_filter->fmt_in.video, 1 );
452 /* Draw until we reach the bottom of the subtitle */
453 for( i_y = 0; i_y < i_height; i_y++, p_trans += i_src_pitch,
454 p_dst += i_dst_pitch,
455 p_src_y += i_src_pitch, p_src_u += i_src_pitch,
456 p_src_v += i_src_pitch )
458 /* Draw until we reach the end of the line */
459 for( i_x = 0; i_x < i_width; i_x++ )
462 i_trans = vlc_alpha( p_trans[i_x], i_alpha );
467 yuv_to_rgb( &r, &g, &b,
468 p_src_y[i_x], p_src_u[i_x], p_src_v[i_x] );
470 vlc_blend_rgb16( (uint16_t*)&p_dst[i_x * i_pix_pitch],
471 r, g, b, i_trans, &p_filter->fmt_out.video );
476 static void BlendYUVARV24( filter_t *p_filter,
477 picture_t *p_dst_pic, const picture_t *p_src,
478 int i_x_offset, int i_y_offset,
479 int i_width, int i_height, int i_alpha )
481 int i_src_pitch, i_dst_pitch;
482 uint8_t *p_dst, *p_src_y;
483 uint8_t *p_src_u, *p_src_v;
485 int i_x, i_y, i_pix_pitch, i_trans = 0;
488 i_pix_pitch = p_dst_pic->p->i_pixel_pitch;
489 i_dst_pitch = p_dst_pic->p->i_pitch;
490 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
491 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
492 p_dst_pic->p->i_pitch *
493 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
495 p_src_y = vlc_plane_start( &i_src_pitch, p_src, Y_PLANE,
496 0, 0, &p_filter->fmt_in.video, 1 );
497 p_src_u = vlc_plane_start( NULL, p_src, U_PLANE,
498 0, 0, &p_filter->fmt_in.video, 2 );
499 p_src_v = vlc_plane_start( NULL, p_src, V_PLANE,
500 0, 0, &p_filter->fmt_in.video, 2 );
501 p_trans = vlc_plane_start( NULL, p_src, A_PLANE,
502 0, 0, &p_filter->fmt_in.video, 1 );
504 if( (i_pix_pitch == 4)
505 && (((((intptr_t)p_dst)|i_dst_pitch) /* FIXME? */
509 ** if picture pixels are 32 bits long and lines addresses are 32 bit
510 ** aligned, optimize rendering
512 uint32_t *p32_dst = (uint32_t *)p_dst;
513 uint32_t i32_dst_pitch = (uint32_t)(i_dst_pitch>>2);
515 int i_rshift, i_gshift, i_bshift;
516 uint32_t i_rmask, i_gmask, i_bmask;
518 i_rmask = p_filter->fmt_out.video.i_rmask;
519 i_gmask = p_filter->fmt_out.video.i_gmask;
520 i_bmask = p_filter->fmt_out.video.i_bmask;
521 i_rshift = p_filter->fmt_out.video.i_lrshift;
522 i_gshift = p_filter->fmt_out.video.i_lgshift;
523 i_bshift = p_filter->fmt_out.video.i_lbshift;
525 /* Draw until we reach the bottom of the subtitle */
526 for( i_y = 0; i_y < i_height; i_y++, p_trans += i_src_pitch,
527 p32_dst += i32_dst_pitch,
528 p_src_y += i_src_pitch, p_src_u += i_src_pitch,
529 p_src_v += i_src_pitch )
531 /* Draw until we reach the end of the line */
532 for( i_x = 0; i_x < i_width; i_x++ )
535 i_trans = vlc_alpha( p_trans[i_x], i_alpha );
539 if( i_trans == MAX_TRANS )
541 /* Completely opaque. Completely overwrite underlying pixel */
542 yuv_to_rgb( &r, &g, &b,
543 p_src_y[i_x], p_src_u[i_x], p_src_v[i_x] );
545 p32_dst[i_x] = (r<<i_rshift) |
552 uint32_t i_pix_dst = p32_dst[i_x];
553 yuv_to_rgb( &r, &g, &b,
554 p_src_y[i_x], p_src_u[i_x], p_src_v[i_x] );
556 p32_dst[i_x] = ( vlc_blend( r, (i_pix_dst & i_rmask)>>i_rshift, i_trans ) << i_rshift ) |
557 ( vlc_blend( g, (i_pix_dst & i_gmask)>>i_gshift, i_trans ) << i_gshift ) |
558 ( vlc_blend( b, (i_pix_dst & i_bmask)>>i_bshift, i_trans ) << i_bshift );
565 int i_rindex, i_gindex, i_bindex;
566 vlc_rgb_index( &i_rindex, &i_gindex, &i_bindex, &p_filter->fmt_out.video );
568 /* Draw until we reach the bottom of the subtitle */
569 for( i_y = 0; i_y < i_height; i_y++, p_trans += i_src_pitch,
570 p_dst += i_dst_pitch,
571 p_src_y += i_src_pitch, p_src_u += i_src_pitch,
572 p_src_v += i_src_pitch )
574 /* Draw until we reach the end of the line */
575 for( i_x = 0; i_x < i_width; i_x++ )
578 i_trans = vlc_alpha( p_trans[i_x], i_alpha );
583 yuv_to_rgb( &r, &g, &b,
584 p_src_y[i_x], p_src_u[i_x], p_src_v[i_x] );
586 vlc_blend_packed( &p_dst[ i_x * i_pix_pitch],
587 i_rindex, i_gindex, i_bindex,
588 r, g, b, i_alpha, true );
594 static void BlendYUVAYUVPacked( filter_t *p_filter,
595 picture_t *p_dst_pic, const picture_t *p_src,
596 int i_x_offset, int i_y_offset,
597 int i_width, int i_height, int i_alpha )
599 int i_src_pitch, i_dst_pitch;
600 uint8_t *p_dst, *p_src_y;
601 uint8_t *p_src_u, *p_src_v;
603 int i_x, i_y, i_pix_pitch, i_trans = 0;
604 bool b_even = !((i_x_offset + p_filter->fmt_out.video.i_x_offset)%2);
605 int i_l_offset, i_u_offset, i_v_offset;
607 vlc_yuv_packed_index( &i_l_offset, &i_u_offset, &i_v_offset,
608 p_filter->fmt_out.video.i_chroma );
611 i_dst_pitch = p_dst_pic->p->i_pitch;
612 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
613 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
614 p_dst_pic->p->i_pitch *
615 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
617 p_src_y = vlc_plane_start( &i_src_pitch, p_src, Y_PLANE,
618 0, 0, &p_filter->fmt_in.video, 1 );
619 p_src_u = vlc_plane_start( NULL, p_src, U_PLANE,
620 0, 0, &p_filter->fmt_in.video, 2 );
621 p_src_v = vlc_plane_start( NULL, p_src, V_PLANE,
622 0, 0, &p_filter->fmt_in.video, 2 );
623 p_trans = vlc_plane_start( NULL, p_src, A_PLANE,
624 0, 0, &p_filter->fmt_in.video, 1 );
626 i_width &= ~1; /* Needs to be a multiple of 2 */
628 /* Draw until we reach the bottom of the subtitle */
629 for( i_y = 0; i_y < i_height; i_y++, p_trans += i_src_pitch,
630 p_dst += i_dst_pitch,
631 p_src_y += i_src_pitch, p_src_u += i_src_pitch,
632 p_src_v += i_src_pitch )
634 /* Draw until we reach the end of the line */
635 for( i_x = 0; i_x < i_width; i_x++, b_even = !b_even )
637 i_trans = vlc_alpha( p_trans[i_x], i_alpha );
646 /* FIXME what's with 0xaa ? */
647 if( p_trans[i_x+1] > 0xaa )
649 i_u = (p_src_u[i_x]+p_src_u[i_x+1])>>1;
650 i_v = (p_src_v[i_x]+p_src_v[i_x+1])>>1;
658 vlc_blend_packed( &p_dst[i_x * 2],
659 i_l_offset, i_u_offset, i_v_offset,
660 p_src_y[i_x], i_u, i_v, i_trans, true );
664 p_dst[i_x * 2 + i_l_offset] = vlc_blend( p_src_y[i_x], p_dst[i_x * 2 + i_l_offset], i_trans );
669 /***********************************************************************
671 ***********************************************************************/
672 static void BlendI420I420( filter_t *p_filter,
673 picture_t *p_dst, const picture_t *p_src,
674 int i_x_offset, int i_y_offset,
675 int i_width, int i_height, int i_alpha )
677 int i_src_pitch, i_dst_pitch;
678 uint8_t *p_src_y, *p_dst_y;
679 uint8_t *p_src_u, *p_dst_u;
680 uint8_t *p_src_v, *p_dst_v;
682 bool b_even_scanline = i_y_offset % 2;
684 if( i_alpha == 0xff )
686 BlendI420I420_no_alpha( p_filter, p_dst, p_src,
687 i_x_offset, i_y_offset, i_width, i_height );
691 bool b_swap_up = vlc_fourcc_AreUVPlanesSwapped( p_filter->fmt_out.video.i_chroma,
693 i_dst_pitch = p_dst->p[Y_PLANE].i_pitch;
694 p_dst_y = p_dst->p[Y_PLANE].p_pixels + i_x_offset +
695 p_filter->fmt_out.video.i_x_offset +
696 p_dst->p[Y_PLANE].i_pitch *
697 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
698 const int i_u_plane = b_swap_up ? V_PLANE : U_PLANE;
699 p_dst_u = p_dst->p[i_u_plane].p_pixels + i_x_offset/2 +
700 p_filter->fmt_out.video.i_x_offset/2 +
701 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
702 p_dst->p[i_u_plane].i_pitch;
703 const int i_v_plane = b_swap_up ? U_PLANE : V_PLANE;
704 p_dst_v = p_dst->p[i_v_plane].p_pixels + i_x_offset/2 +
705 p_filter->fmt_out.video.i_x_offset/2 +
706 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
707 p_dst->p[i_v_plane].i_pitch;
709 p_src_y = vlc_plane_start( &i_src_pitch, p_src, Y_PLANE,
710 0, 0, &p_filter->fmt_in.video, 1 );
711 p_src_u = vlc_plane_start( NULL, p_src, U_PLANE,
712 0, 0, &p_filter->fmt_in.video, 2 );
713 p_src_v = vlc_plane_start( NULL, p_src, V_PLANE,
714 0, 0, &p_filter->fmt_in.video, 2 );
717 /* Draw until we reach the bottom of the subtitle */
718 for( i_y = 0; i_y < i_height; i_y++,
719 p_dst_y += i_dst_pitch,
720 p_src_y += i_src_pitch )
722 if( b_even_scanline )
724 p_dst_u += i_dst_pitch/2;
725 p_dst_v += i_dst_pitch/2;
727 b_even_scanline = !b_even_scanline;
729 /* Draw until we reach the end of the line */
730 for( i_x = 0; i_x < i_width; i_x++ )
736 p_dst_y[i_x] = vlc_blend( p_src_y[i_x], p_dst_y[i_x], i_alpha );
737 if( b_even_scanline && i_x % 2 == 0 )
739 p_dst_u[i_x/2] = vlc_blend( p_src_u[i_x/2], p_dst_u[i_x/2], i_alpha );
740 p_dst_v[i_x/2] = vlc_blend( p_src_v[i_x/2], p_dst_v[i_x/2], i_alpha );
745 p_src_u += i_src_pitch/2;
746 p_src_v += i_src_pitch/2;
750 static void BlendI420I420_no_alpha( filter_t *p_filter,
751 picture_t *p_dst, const picture_t *p_src,
752 int i_x_offset, int i_y_offset,
753 int i_width, int i_height )
755 int i_src_pitch, i_dst_pitch;
756 uint8_t *p_src_y, *p_dst_y;
757 uint8_t *p_src_u, *p_dst_u;
758 uint8_t *p_src_v, *p_dst_v;
760 bool b_even_scanline = i_y_offset % 2;
762 bool b_swap_up = vlc_fourcc_AreUVPlanesSwapped( p_filter->fmt_out.video.i_chroma,
764 i_dst_pitch = p_dst->p[Y_PLANE].i_pitch;
765 p_dst_y = p_dst->p[Y_PLANE].p_pixels + i_x_offset +
766 p_filter->fmt_out.video.i_x_offset +
767 p_dst->p[Y_PLANE].i_pitch *
768 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
769 const int i_u_plane = b_swap_up ? V_PLANE : U_PLANE;
770 p_dst_u = p_dst->p[i_u_plane].p_pixels + i_x_offset/2 +
771 p_filter->fmt_out.video.i_x_offset/2 +
772 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
773 p_dst->p[i_u_plane].i_pitch;
774 const int i_v_plane = b_swap_up ? U_PLANE : V_PLANE;
775 p_dst_v = p_dst->p[i_v_plane].p_pixels + i_x_offset/2 +
776 p_filter->fmt_out.video.i_x_offset/2 +
777 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
778 p_dst->p[i_v_plane].i_pitch;
780 p_src_y = vlc_plane_start( &i_src_pitch, p_src, Y_PLANE,
781 0, 0, &p_filter->fmt_in.video, 1 );
782 p_src_u = vlc_plane_start( NULL, p_src, U_PLANE,
783 0, 0, &p_filter->fmt_in.video, 2 );
784 p_src_v = vlc_plane_start( NULL, p_src, V_PLANE,
785 0, 0, &p_filter->fmt_in.video, 2 );
789 /* Draw until we reach the bottom of the subtitle */
790 for( i_y = 0; i_y < i_height;
791 i_y++, p_dst_y += i_dst_pitch, p_src_y += i_src_pitch )
793 /* Completely opaque. Completely overwrite underlying pixel */
794 vlc_memcpy( p_dst_y, p_src_y, i_width );
795 if( b_even_scanline )
797 p_dst_u += i_dst_pitch/2;
798 p_dst_v += i_dst_pitch/2;
802 vlc_memcpy( p_dst_u, p_src_u, i_width/2 );
803 vlc_memcpy( p_dst_v, p_src_v, i_width/2 );
805 b_even_scanline = !b_even_scanline;
808 p_src_u += i_src_pitch/2;
809 p_src_v += i_src_pitch/2;
814 static void BlendI420R16( filter_t *p_filter,
815 picture_t *p_dst_pic, const picture_t *p_src,
816 int i_x_offset, int i_y_offset,
817 int i_width, int i_height, int i_alpha )
819 int i_src_pitch, i_dst_pitch;
820 uint8_t *p_dst, *p_src_y;
821 uint8_t *p_src_u, *p_src_v;
822 int i_x, i_y, i_pix_pitch;
825 i_pix_pitch = p_dst_pic->p->i_pixel_pitch;
826 i_dst_pitch = p_dst_pic->p->i_pitch;
827 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
828 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
829 p_dst_pic->p->i_pitch *
830 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
832 p_src_y = vlc_plane_start( &i_src_pitch, p_src, Y_PLANE,
833 0, 0, &p_filter->fmt_in.video, 1 );
834 p_src_u = vlc_plane_start( NULL, p_src, U_PLANE,
835 0, 0, &p_filter->fmt_in.video, 2 );
836 p_src_v = vlc_plane_start( NULL, p_src, V_PLANE,
837 0, 0, &p_filter->fmt_in.video, 2 );
839 /* Draw until we reach the bottom of the subtitle */
840 for( i_y = 0; i_y < i_height; i_y++,
841 p_dst += i_dst_pitch,
842 p_src_y += i_src_pitch )
844 /* Draw until we reach the end of the line */
845 for( i_x = 0; i_x < i_width; i_x++ )
848 yuv_to_rgb( &r, &g, &b,
849 p_src_y[i_x], p_src_u[i_x/2], p_src_v[i_x/2] );
851 vlc_blend_rgb16( (uint16_t*)&p_dst[i_x * i_pix_pitch],
852 r, g, b, i_alpha, &p_filter->fmt_out.video );
856 p_src_u += i_src_pitch/2;
857 p_src_v += i_src_pitch/2;
862 static void BlendI420R24( filter_t *p_filter,
863 picture_t *p_dst_pic, const picture_t *p_src,
864 int i_x_offset, int i_y_offset,
865 int i_width, int i_height, int i_alpha )
867 int i_src_pitch, i_dst_pitch;
868 uint8_t *p_dst, *p_src_y;
869 uint8_t *p_src_u, *p_src_v;
870 int i_x, i_y, i_pix_pitch;
871 int i_rindex, i_gindex, i_bindex;
874 i_pix_pitch = p_dst_pic->p->i_pixel_pitch;
875 i_dst_pitch = p_dst_pic->p->i_pitch;
876 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
877 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
878 p_dst_pic->p->i_pitch *
879 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
881 p_src_y = vlc_plane_start( &i_src_pitch, p_src, Y_PLANE,
882 0, 0, &p_filter->fmt_in.video, 1 );
883 p_src_u = vlc_plane_start( NULL, p_src, U_PLANE,
884 0, 0, &p_filter->fmt_in.video, 2 );
885 p_src_v = vlc_plane_start( NULL, p_src, V_PLANE,
886 0, 0, &p_filter->fmt_in.video, 2 );
888 vlc_rgb_index( &i_rindex, &i_gindex, &i_bindex, &p_filter->fmt_out.video );
890 /* Draw until we reach the bottom of the subtitle */
891 for( i_y = 0; i_y < i_height; i_y++,
892 p_dst += i_dst_pitch,
893 p_src_y += i_src_pitch, p_src_u += i_src_pitch,
894 p_src_v += i_src_pitch )
896 /* Draw until we reach the end of the line */
897 for( i_x = 0; i_x < i_width; i_x++ )
903 yuv_to_rgb( &r, &g, &b,
904 p_src_y[i_x], p_src_u[i_x/2], p_src_v[i_x/2] );
906 vlc_blend_packed( &p_dst[i_x * i_pix_pitch],
907 i_rindex, i_gindex, i_bindex, r, g, b, i_alpha, true );
911 p_src_u += i_src_pitch/2;
912 p_src_v += i_src_pitch/2;
917 static void BlendI420YUVPacked( filter_t *p_filter,
918 picture_t *p_dst_pic, const picture_t *p_src,
919 int i_x_offset, int i_y_offset,
920 int i_width, int i_height, int i_alpha )
922 int i_src_pitch, i_dst_pitch;
923 uint8_t *p_dst, *p_src_y;
924 uint8_t *p_src_u, *p_src_v;
925 int i_x, i_y, i_pix_pitch;
926 bool b_even = !((i_x_offset + p_filter->fmt_out.video.i_x_offset)%2);
927 int i_l_offset, i_u_offset, i_v_offset;
929 vlc_yuv_packed_index( &i_l_offset, &i_u_offset, &i_v_offset,
930 p_filter->fmt_out.video.i_chroma );
933 i_dst_pitch = p_dst_pic->p->i_pitch;
934 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
935 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
936 p_dst_pic->p->i_pitch *
937 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
939 p_src_y = vlc_plane_start( &i_src_pitch, p_src, Y_PLANE,
940 0, 0, &p_filter->fmt_in.video, 1 );
941 p_src_u = vlc_plane_start( NULL, p_src, U_PLANE,
942 0, 0, &p_filter->fmt_in.video, 2 );
943 p_src_v = vlc_plane_start( NULL, p_src, V_PLANE,
944 0, 0, &p_filter->fmt_in.video, 2 );
946 i_width &= ~1; /* Needs to be a multiple of 2 */
948 /* Draw until we reach the bottom of the subtitle */
949 for( i_y = 0; i_y < i_height; i_y++,
950 p_dst += i_dst_pitch,
951 p_src_y += i_src_pitch, p_src_u += i_src_pitch,
952 p_src_v += i_src_pitch )
954 /* Draw until we reach the end of the line */
955 for( i_x = 0; i_x < i_width; i_x++, b_even = !b_even )
961 vlc_blend_packed( &p_dst[i_x * 2],
962 i_l_offset, i_u_offset, i_v_offset,
963 p_src_y[i_x], p_src_u[i_x/2], p_src_v[i_x/2], i_alpha, b_even );
967 p_src_u += i_src_pitch/2;
968 p_src_v += i_src_pitch/2;
973 /***********************************************************************
975 ***********************************************************************/
976 static void BlendPalI420( filter_t *p_filter,
977 picture_t *p_dst, const picture_t *p_src_pic,
978 int i_x_offset, int i_y_offset,
979 int i_width, int i_height, int i_alpha )
981 int i_src_pitch, i_dst_pitch;
982 uint8_t *p_src, *p_dst_y;
985 int i_x, i_y, i_trans;
986 bool b_even_scanline = i_y_offset % 2;
988 bool b_swap_up = vlc_fourcc_AreUVPlanesSwapped( p_filter->fmt_out.video.i_chroma,
990 i_dst_pitch = p_dst->p[Y_PLANE].i_pitch;
991 p_dst_y = p_dst->p[Y_PLANE].p_pixels + i_x_offset +
992 p_filter->fmt_out.video.i_x_offset +
993 p_dst->p[Y_PLANE].i_pitch *
994 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
995 const int i_u_plane = b_swap_up ? V_PLANE : U_PLANE;
996 p_dst_u = p_dst->p[i_u_plane].p_pixels + i_x_offset/2 +
997 p_filter->fmt_out.video.i_x_offset/2 +
998 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
999 p_dst->p[i_u_plane].i_pitch;
1000 const int i_v_plane = b_swap_up ? U_PLANE : V_PLANE;
1001 p_dst_v = p_dst->p[i_v_plane].p_pixels + i_x_offset/2 +
1002 p_filter->fmt_out.video.i_x_offset/2 +
1003 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
1004 p_dst->p[i_v_plane].i_pitch;
1006 i_src_pitch = p_src_pic->p->i_pitch;
1007 p_src = p_src_pic->p->p_pixels + p_filter->fmt_in.video.i_x_offset +
1008 i_src_pitch * p_filter->fmt_in.video.i_y_offset;
1010 #define p_pal p_filter->fmt_in.video.p_palette->palette
1012 /* Draw until we reach the bottom of the subtitle */
1013 for( i_y = 0; i_y < i_height; i_y++,
1014 p_dst_y += i_dst_pitch,
1015 p_src += i_src_pitch,
1016 p_dst_u += b_even_scanline ? i_dst_pitch/2 : 0,
1017 p_dst_v += b_even_scanline ? i_dst_pitch/2 : 0 )
1019 const uint8_t *p_trans = p_src;
1020 b_even_scanline = !b_even_scanline;
1022 /* Draw until we reach the end of the line */
1023 for( i_x = 0; i_x < i_width; i_x++ )
1025 i_trans = vlc_alpha( p_pal[p_trans[i_x]][3], i_alpha );
1030 p_dst_y[i_x] = vlc_blend( p_pal[p_src[i_x]][0], p_dst_y[i_x], i_trans );
1031 if( b_even_scanline && ((i_x % 2) == 0) )
1033 p_dst_u[i_x/2] = vlc_blend( p_pal[p_src[i_x]][1], p_dst_u[i_x/2], i_trans );
1034 p_dst_v[i_x/2] = vlc_blend( p_pal[p_src[i_x]][2], p_dst_v[i_x/2], i_trans );
1041 static void BlendPalYUVPacked( filter_t *p_filter,
1042 picture_t *p_dst_pic, const picture_t *p_src_pic,
1043 int i_x_offset, int i_y_offset,
1044 int i_width, int i_height, int i_alpha )
1046 int i_src_pitch, i_dst_pitch;
1047 uint8_t *p_src, *p_dst;
1048 int i_x, i_y, i_pix_pitch, i_trans;
1049 bool b_even = !((i_x_offset + p_filter->fmt_out.video.i_x_offset)%2);
1050 int i_l_offset, i_u_offset, i_v_offset;
1052 vlc_yuv_packed_index( &i_l_offset, &i_u_offset, &i_v_offset,
1053 p_filter->fmt_out.video.i_chroma );
1056 i_dst_pitch = p_dst_pic->p->i_pitch;
1057 p_dst = p_dst_pic->p->p_pixels + i_pix_pitch * (i_x_offset +
1058 p_filter->fmt_out.video.i_x_offset) + p_dst_pic->p->i_pitch *
1059 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1061 i_src_pitch = p_src_pic->p->i_pitch;
1062 p_src = p_src_pic->p->p_pixels + p_filter->fmt_in.video.i_x_offset +
1063 i_src_pitch * p_filter->fmt_in.video.i_y_offset;
1065 i_width &= ~1; /* Needs to be a multiple of 2 */
1067 #define p_pal p_filter->fmt_in.video.p_palette->palette
1069 /* Draw until we reach the bottom of the subtitle */
1070 for( i_y = 0; i_y < i_height; i_y++,
1071 p_dst += i_dst_pitch, p_src += i_src_pitch )
1073 const uint8_t *p_trans = p_src;
1074 /* Draw until we reach the end of the line */
1075 for( i_x = 0; i_x < i_width; i_x++, b_even = !b_even )
1077 i_trans = vlc_alpha( p_pal[p_trans[i_x]][3], i_alpha );
1086 if( p_trans[i_x+1] > 0xaa )
1088 i_u = (p_pal[p_src[i_x]][1] + p_pal[p_src[i_x+1]][1]) >> 1;
1089 i_v = (p_pal[p_src[i_x]][2] + p_pal[p_src[i_x+1]][2]) >> 1;
1093 i_u = p_pal[p_src[i_x]][1];
1094 i_v = p_pal[p_src[i_x]][2];
1097 vlc_blend_packed( &p_dst[i_x * 2],
1098 i_l_offset, i_u_offset, i_v_offset,
1099 p_pal[p_src[i_x]][0], i_u, i_v, i_trans, true );
1103 p_dst[i_x * 2 + i_l_offset] = vlc_blend( p_pal[p_src[i_x]][0], p_dst[i_x * 2 + i_l_offset], i_trans );
1110 static void BlendPalRV( filter_t *p_filter,
1111 picture_t *p_dst_pic, const picture_t *p_src_pic,
1112 int i_x_offset, int i_y_offset,
1113 int i_width, int i_height, int i_alpha )
1115 int i_src_pitch, i_dst_pitch;
1116 uint8_t *p_src, *p_dst;
1117 int i_x, i_y, i_pix_pitch, i_trans;
1118 video_palette_t rgbpalette;
1119 int i_rindex, i_gindex, i_bindex;
1121 i_pix_pitch = p_dst_pic->p->i_pixel_pitch;
1122 i_dst_pitch = p_dst_pic->p->i_pitch;
1123 p_dst = p_dst_pic->p->p_pixels + i_pix_pitch * (i_x_offset +
1124 p_filter->fmt_out.video.i_x_offset) + p_dst_pic->p->i_pitch *
1125 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1127 i_src_pitch = p_src_pic->p->i_pitch;
1128 p_src = p_src_pic->p->p_pixels + p_filter->fmt_in.video.i_x_offset +
1129 i_src_pitch * p_filter->fmt_in.video.i_y_offset;
1131 #define p_pal p_filter->fmt_in.video.p_palette->palette
1132 #define rgbpal rgbpalette.palette
1134 /* Convert palette first */
1135 for( i_y = 0; i_y < p_filter->fmt_in.video.p_palette->i_entries && i_y < 256; i_y++ )
1139 yuv_to_rgb( &r, &g, &b, p_pal[i_y][0], p_pal[i_y][1], p_pal[i_y][2] );
1146 vlc_rgb_index( &i_rindex, &i_gindex, &i_bindex, &p_filter->fmt_out.video );
1148 /* Draw until we reach the bottom of the subtitle */
1149 for( i_y = 0; i_y < i_height; i_y++,
1150 p_dst += i_dst_pitch, p_src += i_src_pitch )
1152 const uint8_t *p_trans = p_src;
1153 /* Draw until we reach the end of the line */
1154 for( i_x = 0; i_x < i_width; i_x++ )
1156 i_trans = vlc_alpha( p_pal[p_trans[i_x]][3], i_alpha );
1161 if( p_filter->fmt_out.video.i_chroma == VLC_CODEC_RGB15 || p_filter->fmt_out.video.i_chroma == VLC_CODEC_RGB16 )
1162 vlc_blend_rgb16( (uint16_t*)&p_dst[i_x * i_pix_pitch],
1163 rgbpal[p_src[i_x]][0], rgbpal[p_src[i_x]][1], rgbpal[p_src[i_x]][2],
1165 &p_filter->fmt_out.video );
1167 vlc_blend_packed( &p_dst[i_x * i_pix_pitch],
1168 i_rindex, i_gindex, i_bindex,
1169 rgbpal[p_src[i_x]][0], rgbpal[p_src[i_x]][1], rgbpal[p_src[i_x]][2],
1178 /***********************************************************************
1180 ***********************************************************************/
1181 static void BlendRGBAI420( filter_t *p_filter,
1182 picture_t *p_dst, const picture_t *p_src_pic,
1183 int i_x_offset, int i_y_offset,
1184 int i_width, int i_height, int i_alpha )
1186 int i_src_pitch, i_dst_pitch, i_src_pix_pitch;
1191 int i_x, i_y, i_trans;
1194 bool b_even_scanline = i_y_offset % 2;
1195 bool b_swap_up = vlc_fourcc_AreUVPlanesSwapped( p_filter->fmt_out.video.i_chroma,
1197 i_dst_pitch = p_dst->p[Y_PLANE].i_pitch;
1198 p_dst_y = p_dst->p[Y_PLANE].p_pixels + i_x_offset +
1199 p_filter->fmt_out.video.i_x_offset +
1200 p_dst->p[Y_PLANE].i_pitch *
1201 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1202 const int i_u_plane = b_swap_up ? V_PLANE : U_PLANE;
1203 p_dst_u = p_dst->p[i_u_plane].p_pixels + i_x_offset/2 +
1204 p_filter->fmt_out.video.i_x_offset/2 +
1205 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
1206 p_dst->p[i_u_plane].i_pitch;
1207 const int i_v_plane = b_swap_up ? U_PLANE : V_PLANE;
1208 p_dst_v = p_dst->p[i_v_plane].p_pixels + i_x_offset/2 +
1209 p_filter->fmt_out.video.i_x_offset/2 +
1210 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
1211 p_dst->p[i_v_plane].i_pitch;
1213 i_src_pix_pitch = p_src_pic->p->i_pixel_pitch;
1214 i_src_pitch = p_src_pic->p->i_pitch;
1215 p_src = p_src_pic->p->p_pixels +
1216 p_filter->fmt_in.video.i_x_offset * i_src_pix_pitch +
1217 p_src_pic->p->i_pitch * p_filter->fmt_in.video.i_y_offset;
1220 /* Draw until we reach the bottom of the subtitle */
1221 for( i_y = 0; i_y < i_height; i_y++,
1222 p_dst_y += i_dst_pitch,
1223 p_dst_u += b_even_scanline ? i_dst_pitch/2 : 0,
1224 p_dst_v += b_even_scanline ? i_dst_pitch/2 : 0,
1225 p_src += i_src_pitch )
1227 b_even_scanline = !b_even_scanline;
1229 /* Draw until we reach the end of the line */
1230 for( i_x = 0; i_x < i_width; i_x++ )
1232 const int R = p_src[i_x * i_src_pix_pitch + 0];
1233 const int G = p_src[i_x * i_src_pix_pitch + 1];
1234 const int B = p_src[i_x * i_src_pix_pitch + 2];
1236 i_trans = vlc_alpha( p_src[i_x * i_src_pix_pitch + 3], i_alpha );
1241 rgb_to_yuv( &y, &u, &v, R, G, B );
1243 p_dst_y[i_x] = vlc_blend( y, p_dst_y[i_x], i_trans );
1244 if( b_even_scanline && i_x % 2 == 0 )
1246 p_dst_u[i_x/2] = vlc_blend( u, p_dst_u[i_x/2], i_trans );
1247 p_dst_v[i_x/2] = vlc_blend( v, p_dst_v[i_x/2], i_trans );
1253 static void BlendRGBAR24( filter_t *p_filter,
1254 picture_t *p_dst_pic, const picture_t *p_src_pic,
1255 int i_x_offset, int i_y_offset,
1256 int i_width, int i_height, int i_alpha )
1258 int i_src_pitch, i_dst_pitch;
1259 uint8_t *p_dst, *p_src;
1260 int i_x, i_y, i_pix_pitch, i_trans, i_src_pix_pitch;
1261 int i_rindex, i_gindex, i_bindex;
1263 i_pix_pitch = p_dst_pic->p->i_pixel_pitch;
1264 i_dst_pitch = p_dst_pic->p->i_pitch;
1265 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
1266 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
1267 p_dst_pic->p->i_pitch *
1268 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1270 i_src_pix_pitch = p_src_pic->p->i_pixel_pitch;
1271 i_src_pitch = p_src_pic->p->i_pitch;
1272 p_src = p_src_pic->p->p_pixels +
1273 p_filter->fmt_in.video.i_x_offset * i_src_pix_pitch +
1274 p_src_pic->p->i_pitch * p_filter->fmt_in.video.i_y_offset;
1276 vlc_rgb_index( &i_rindex, &i_gindex, &i_bindex, &p_filter->fmt_out.video );
1278 /* Draw until we reach the bottom of the subtitle */
1279 for( i_y = 0; i_y < i_height; i_y++,
1280 p_dst += i_dst_pitch, p_src += i_src_pitch )
1282 /* Draw until we reach the end of the line */
1283 for( i_x = 0; i_x < i_width; i_x++ )
1285 const int R = p_src[i_x * i_src_pix_pitch + 0];
1286 const int G = p_src[i_x * i_src_pix_pitch + 1];
1287 const int B = p_src[i_x * i_src_pix_pitch + 2];
1289 i_trans = vlc_alpha( p_src[i_x * i_src_pix_pitch + 3], i_alpha );
1294 vlc_blend_packed( &p_dst[i_x * i_pix_pitch],
1295 i_rindex, i_gindex, i_bindex,
1296 R, G, B, i_trans, true );
1301 static void BlendRGBAR16( filter_t *p_filter,
1302 picture_t *p_dst_pic, const picture_t *p_src_pic,
1303 int i_x_offset, int i_y_offset,
1304 int i_width, int i_height, int i_alpha )
1306 int i_src_pitch, i_dst_pitch;
1307 uint8_t *p_dst, *p_src;
1308 int i_x, i_y, i_pix_pitch, i_trans, i_src_pix_pitch;
1310 i_pix_pitch = p_dst_pic->p->i_pixel_pitch;
1311 i_dst_pitch = p_dst_pic->p->i_pitch;
1312 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
1313 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
1314 p_dst_pic->p->i_pitch *
1315 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1317 i_src_pix_pitch = p_src_pic->p->i_pixel_pitch;
1318 i_src_pitch = p_src_pic->p->i_pitch;
1319 p_src = p_src_pic->p->p_pixels +
1320 p_filter->fmt_in.video.i_x_offset * i_src_pix_pitch +
1321 p_src_pic->p->i_pitch * p_filter->fmt_in.video.i_y_offset;
1323 /* Draw until we reach the bottom of the subtitle */
1324 for( i_y = 0; i_y < i_height; i_y++,
1325 p_dst += i_dst_pitch, p_src += i_src_pitch )
1327 /* Draw until we reach the end of the line */
1328 for( i_x = 0; i_x < i_width; i_x++ )
1330 const int R = p_src[i_x * i_src_pix_pitch + 0];
1331 const int G = p_src[i_x * i_src_pix_pitch + 1];
1332 const int B = p_src[i_x * i_src_pix_pitch + 2];
1334 i_trans = vlc_alpha( p_src[i_x * i_src_pix_pitch + 3], i_alpha );
1339 vlc_blend_rgb16( (uint16_t*)&p_dst[i_x * i_pix_pitch],
1340 R, G, B, i_trans, &p_filter->fmt_out.video );
1345 static void BlendRGBAYUVPacked( filter_t *p_filter,
1346 picture_t *p_dst_pic, const picture_t *p_src_pic,
1347 int i_x_offset, int i_y_offset,
1348 int i_width, int i_height, int i_alpha )
1350 int i_src_pitch, i_dst_pitch, i_src_pix_pitch;
1351 uint8_t *p_dst, *p_src;
1352 int i_x, i_y, i_pix_pitch, i_trans;
1353 bool b_even = !((i_x_offset + p_filter->fmt_out.video.i_x_offset)%2);
1354 int i_l_offset, i_u_offset, i_v_offset;
1357 vlc_yuv_packed_index( &i_l_offset, &i_u_offset, &i_v_offset,
1358 p_filter->fmt_out.video.i_chroma );
1361 i_dst_pitch = p_dst_pic->p->i_pitch;
1362 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
1363 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
1364 p_dst_pic->p->i_pitch *
1365 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1367 i_src_pix_pitch = p_src_pic->p->i_pixel_pitch;
1368 i_src_pitch = p_src_pic->p->i_pitch;
1369 p_src = p_src_pic->p->p_pixels +
1370 p_filter->fmt_in.video.i_x_offset * i_src_pitch +
1371 p_src_pic->p->i_pitch * p_filter->fmt_in.video.i_y_offset;
1373 i_width &= ~1; /* Needs to be a multiple of 2 */
1375 /* Draw until we reach the bottom of the subtitle */
1376 for( i_y = 0; i_y < i_height; i_y++,
1377 p_dst += i_dst_pitch,
1378 p_src += i_src_pitch )
1380 /* Draw until we reach the end of the line */
1381 for( i_x = 0; i_x < i_width; i_x++, b_even = !b_even )
1383 const int R = p_src[i_x * i_src_pix_pitch + 0];
1384 const int G = p_src[i_x * i_src_pix_pitch + 1];
1385 const int B = p_src[i_x * i_src_pix_pitch + 2];
1387 i_trans = vlc_alpha( p_src[i_x * i_src_pix_pitch + 3], i_alpha );
1392 rgb_to_yuv( &y, &u, &v, R, G, B );
1394 vlc_blend_packed( &p_dst[i_x * 2],
1395 i_l_offset, i_u_offset, i_v_offset,
1396 y, u, v, i_trans, b_even );