1 /*****************************************************************************
2 * blend.c: alpha blend 2 pictures together
3 *****************************************************************************
4 * Copyright (C) 2003-2008 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>
36 #include "vlc_filter.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 )
51 /*****************************************************************************
52 * filter_sys_t : filter descriptor
53 *****************************************************************************/
59 #define FCC_YUVA VLC_CODEC_YUVA
60 #define FCC_YUVP VLC_CODEC_YUVP
61 #define FCC_RGBA VLC_CODEC_RGBA
63 #define FCC_I420 VLC_CODEC_I420
64 #define FCC_YV12 VLC_CODEC_YV12
65 #define FCC_YUY2 VLC_CODEC_YUYV
66 #define FCC_UYVY VLC_CODEC_UYVY
67 #define FCC_YVYU VLC_CODEC_YVYU
68 #define FCC_RV15 VLC_CODEC_RGB15
69 #define FCC_RV16 VLC_CODEC_RGB16
70 #define FCC_RV24 VLC_CODEC_RGB24
71 #define FCC_RV32 VLC_CODEC_RGB32
73 /****************************************************************************
75 ****************************************************************************/
76 static void Blend( filter_t *, picture_t *, picture_t *,
80 static void BlendYUVAI420( filter_t *, picture_t *, picture_t *,
81 int, int, int, int, int );
82 static void BlendYUVARV16( filter_t *, picture_t *, picture_t *,
83 int, int, int, int, int );
84 static void BlendYUVARV24( filter_t *, picture_t *, picture_t *,
85 int, int, int, int, int );
86 static void BlendYUVAYUVPacked( filter_t *, picture_t *, picture_t *,
87 int, int, int, int, int );
90 static void BlendI420I420( filter_t *, picture_t *, picture_t *,
91 int, int, int, int, int );
92 static void BlendI420I420_no_alpha(
93 filter_t *, picture_t *, picture_t *,
95 static void BlendI420R16( filter_t *, picture_t *, picture_t *,
96 int, int, int, int, int );
97 static void BlendI420R24( filter_t *, picture_t *, picture_t *,
98 int, int, int, int, int );
99 static void BlendI420YUVPacked( filter_t *, picture_t *,
100 picture_t *, int, int, int, int, int );
103 static void BlendPalI420( filter_t *, picture_t *, picture_t *,
104 int, int, int, int, int );
105 static void BlendPalYUVPacked( filter_t *, picture_t *, picture_t *,
106 int, int, int, int, int );
107 static void BlendPalRV( filter_t *, picture_t *, picture_t *,
108 int, int, int, int, int );
111 static void BlendRGBAI420( filter_t *, picture_t *, picture_t *,
112 int, int, int, int, int );
113 static void BlendRGBAYUVPacked( filter_t *, picture_t *,
114 picture_t *, int, int, int, int, int );
115 static void BlendRGBAR16( filter_t *, picture_t *, picture_t *,
116 int, int, int, int, int );
117 static void BlendRGBAR24( filter_t *, picture_t *, picture_t *,
118 int, int, int, int, int );
120 /*****************************************************************************
121 * OpenFilter: probe the filter and return score
122 *****************************************************************************/
123 static int OpenFilter( vlc_object_t *p_this )
125 filter_t *p_filter = (filter_t*)p_this;
128 /* Check if we can handle that format.
129 * We could try to use a chroma filter if we can't. */
130 int in_chroma = p_filter->fmt_in.video.i_chroma;
131 int out_chroma = p_filter->fmt_out.video.i_chroma;
132 if( ( in_chroma != FCC_YUVA && in_chroma != FCC_I420 &&
133 in_chroma != FCC_YV12 && in_chroma != FCC_YUVP &&
134 in_chroma != FCC_RGBA ) ||
135 ( out_chroma != FCC_I420 && out_chroma != FCC_YUY2 &&
136 out_chroma != FCC_YV12 && out_chroma != FCC_UYVY &&
137 out_chroma != FCC_YVYU && out_chroma != FCC_RV15 &&
138 out_chroma != FCC_YVYU && out_chroma != FCC_RV16 &&
139 out_chroma != FCC_RV24 && out_chroma != FCC_RV32 ) )
144 /* Allocate the memory needed to store the decoder's structure */
145 p_filter->p_sys = p_sys = malloc(sizeof(filter_sys_t));
150 p_filter->pf_video_blend = Blend;
152 msg_Dbg( p_filter, "chroma: %4.4s -> %4.4s",
153 (char *)&p_filter->fmt_in.video.i_chroma,
154 (char *)&p_filter->fmt_out.video.i_chroma );
159 /*****************************************************************************
160 * CloseFilter: clean up the filter
161 *****************************************************************************/
162 static void CloseFilter( vlc_object_t *p_this )
164 filter_t *p_filter = (filter_t*)p_this;
165 filter_sys_t *p_sys = p_filter->p_sys;
170 /****************************************************************************
171 * Blend: the whole thing
172 ****************************************************************************
173 * This function is called just after the thread is launched.
174 ****************************************************************************/
175 typedef void (*BlendFunction)( filter_t *,
176 picture_t *, picture_t *,
177 int , int , int , int , int );
179 #define FCC_PLANAR_420 { FCC_I420, FCC_YV12, 0 }
180 #define FCC_PACKED_422 { FCC_YUY2, FCC_UYVY, FCC_YVYU, 0 }
181 #define FCC_RGB_16 { FCC_RV15, FCC_RV16, 0 }
182 #define FCC_RGB_24 { FCC_RV24, FCC_RV32, 0 }
184 #define BLEND_CFG( fccSrc, fctPlanar, fctPacked, fctRgb16, fctRgb24 ) \
185 { .src = fccSrc, .p_dst = FCC_PLANAR_420, .pf_blend = fctPlanar }, \
186 { .src = fccSrc, .p_dst = FCC_PACKED_422, .pf_blend = fctPacked }, \
187 { .src = fccSrc, .p_dst = FCC_RGB_16, .pf_blend = fctRgb16 }, \
188 { .src = fccSrc, .p_dst = FCC_RGB_24, .pf_blend = fctRgb24 }
193 vlc_fourcc_t p_dst[16];
194 BlendFunction pf_blend;
197 BLEND_CFG( FCC_YUVA, BlendYUVAI420, BlendYUVAYUVPacked, BlendYUVARV16, BlendYUVARV24 ),
199 BLEND_CFG( FCC_YUVP, BlendPalI420, BlendPalYUVPacked, BlendPalRV, BlendPalRV ),
201 BLEND_CFG( FCC_RGBA, BlendRGBAI420, BlendRGBAYUVPacked, BlendRGBAR16, BlendRGBAR24 ),
203 BLEND_CFG( FCC_I420, BlendI420I420, BlendI420YUVPacked, BlendI420R16, BlendI420R24 ),
205 BLEND_CFG( FCC_YV12, BlendI420I420, BlendI420YUVPacked, BlendI420R16, BlendI420R24 ),
210 static void Blend( filter_t *p_filter,
211 picture_t *p_dst, picture_t *p_src,
212 int i_x_offset, int i_y_offset, int i_alpha )
214 int i_width, i_height;
219 i_width = __MIN((int)p_filter->fmt_out.video.i_visible_width - i_x_offset,
220 (int)p_filter->fmt_in.video.i_visible_width);
222 i_height = __MIN((int)p_filter->fmt_out.video.i_visible_height -i_y_offset,
223 (int)p_filter->fmt_in.video.i_visible_height);
225 if( i_width <= 0 || i_height <= 0 )
228 video_format_FixRgb( &p_filter->fmt_out.video );
229 video_format_FixRgb( &p_filter->fmt_in.video );
232 msg_Dbg( p_filter, "chroma: %4.4s -> %4.4s\n",
233 (char *)&p_filter->fmt_in.video.i_chroma,
234 (char *)&p_filter->fmt_out.video.i_chroma );
237 for( int i = 0; p_blend_cfg[i].src != 0; i++ )
239 if( p_blend_cfg[i].src != p_filter->fmt_in.video.i_chroma )
241 for( int j = 0; p_blend_cfg[i].p_dst[j] != 0; j++ )
243 if( p_blend_cfg[i].p_dst[j] != p_filter->fmt_out.video.i_chroma )
246 p_blend_cfg[i].pf_blend( p_filter, p_dst, p_src,
247 i_x_offset, i_y_offset,
248 i_width, i_height, i_alpha );
253 msg_Dbg( p_filter, "no matching alpha blending routine "
254 "(chroma: %4.4s -> %4.4s)",
255 (char *)&p_filter->fmt_in.video.i_chroma,
256 (char *)&p_filter->fmt_out.video.i_chroma );
259 /***********************************************************************
261 ***********************************************************************/
262 static inline uint8_t vlc_uint8( int v )
271 #define MAX_TRANS 255
274 static inline int vlc_blend( int v1, int v2, int a )
276 /* TODO bench if the tests really increase speed */
279 else if( a == MAX_TRANS )
281 return ( v1 * a + v2 * (MAX_TRANS - a ) ) >> TRANS_BITS;
284 static inline int vlc_alpha( int t, int a )
288 return (t * a) / 255;
291 static inline void yuv_to_rgb( int *r, int *g, int *b,
292 uint8_t y1, uint8_t u1, uint8_t v1 )
294 /* macros used for YUV pixel conversions */
295 # define SCALEBITS 10
296 # define ONE_HALF (1 << (SCALEBITS - 1))
297 # define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5))
299 int y, cb, cr, r_add, g_add, b_add;
303 r_add = FIX(1.40200*255.0/224.0) * cr + ONE_HALF;
304 g_add = - FIX(0.34414*255.0/224.0) * cb
305 - FIX(0.71414*255.0/224.0) * cr + ONE_HALF;
306 b_add = FIX(1.77200*255.0/224.0) * cb + ONE_HALF;
307 y = (y1 - 16) * FIX(255.0/219.0);
308 *r = vlc_uint8( (y + r_add) >> SCALEBITS );
309 *g = vlc_uint8( (y + g_add) >> SCALEBITS );
310 *b = vlc_uint8( (y + b_add) >> SCALEBITS );
316 static inline void rgb_to_yuv( uint8_t *y, uint8_t *u, uint8_t *v,
317 int r, int g, int b )
319 *y = ( ( ( 66 * r + 129 * g + 25 * b + 128 ) >> 8 ) + 16 );
320 *u = ( ( -38 * r - 74 * g + 112 * b + 128 ) >> 8 ) + 128 ;
321 *v = ( ( 112 * r - 94 * g - 18 * b + 128 ) >> 8 ) + 128 ;
324 static uint8_t *vlc_plane_start( int *pi_pitch,
325 picture_t *p_picture,
327 int i_x_offset, int i_y_offset,
328 const video_format_t *p_fmt,
331 const int i_pitch = p_picture->p[i_plane].i_pitch;
332 uint8_t *p_pixels = p_picture->p[i_plane].p_pixels;
334 const int i_dx = ( i_x_offset + p_fmt->i_x_offset ) / r;
335 const int i_dy = ( i_y_offset + p_fmt->i_y_offset ) / r;
339 return &p_pixels[ i_dy * i_pitch + i_dx ];
342 static void vlc_yuv_packed_index( int *pi_y, int *pi_u, int *pi_v, vlc_fourcc_t i_chroma )
344 static const struct {
348 { FCC_YUY2, 0, 1, 3 },
349 { FCC_UYVY, 1, 0, 2 },
350 { FCC_YVYU, 0, 3, 1 },
355 for( i = 0; p_index[i].chroma != 0; i++ )
357 if( p_index[i].chroma == i_chroma )
360 *pi_y = p_index[i].y;
361 *pi_u = p_index[i].u;
362 *pi_v = p_index[i].v;
365 static void vlc_blend_packed( uint8_t *p_dst,
366 int i_offset0, int i_offset1, int i_offset2,
367 int c0, int c1, int c2, int i_alpha,
370 p_dst[i_offset0] = vlc_blend( c0, p_dst[i_offset0], i_alpha );
373 p_dst[i_offset1] = vlc_blend( c1, p_dst[i_offset1], i_alpha );
374 p_dst[i_offset2] = vlc_blend( c2, p_dst[i_offset2], i_alpha );
378 static void vlc_blend_rgb16( uint16_t *p_dst,
379 int R, int G, int B, int i_alpha,
380 const video_format_t *p_fmt )
382 const int i_pix = *p_dst;
383 const int r = ( i_pix & p_fmt->i_rmask ) >> p_fmt->i_lrshift;
384 const int g = ( i_pix & p_fmt->i_gmask ) >> p_fmt->i_lgshift;
385 const int b = ( i_pix & p_fmt->i_bmask ) >> p_fmt->i_lbshift;
387 *p_dst = ( vlc_blend( R >> p_fmt->i_rrshift, r, i_alpha ) << p_fmt->i_lrshift ) |
388 ( vlc_blend( G >> p_fmt->i_rgshift, g, i_alpha ) << p_fmt->i_lgshift ) |
389 ( vlc_blend( B >> p_fmt->i_rbshift, b, i_alpha ) << p_fmt->i_lbshift );
392 static void vlc_rgb_index( int *pi_rindex, int *pi_gindex, int *pi_bindex,
393 const video_format_t *p_fmt )
395 if( p_fmt->i_chroma != FCC_RV24 && p_fmt->i_chroma != FCC_RV32 )
398 /* XXX it will works only if mask are 8 bits aligned */
399 #ifdef WORDS_BIGENDIAN
400 const int i_mask_bits = p_fmt->i_chroma == FCC_RV24 ? 24 : 32;
401 *pi_rindex = ( i_mask_bits - p_fmt->i_lrshift ) / 8;
402 *pi_gindex = ( i_mask_bits - p_fmt->i_lgshift ) / 8;
403 *pi_bindex = ( i_mask_bits - p_fmt->i_lbshift ) / 8;
405 *pi_rindex = p_fmt->i_lrshift / 8;
406 *pi_gindex = p_fmt->i_lgshift / 8;
407 *pi_bindex = p_fmt->i_lbshift / 8;
411 /***********************************************************************
413 ***********************************************************************/
414 static void BlendYUVAI420( filter_t *p_filter,
415 picture_t *p_dst, picture_t *p_src,
416 int i_x_offset, int i_y_offset,
417 int i_width, int i_height, int i_alpha )
419 int i_src_pitch, i_dst_pitch;
420 uint8_t *p_src_y, *p_dst_y;
421 uint8_t *p_src_u, *p_dst_u;
422 uint8_t *p_src_v, *p_dst_v;
424 int i_x, i_y, i_trans = 0;
425 bool b_even_scanline = i_y_offset % 2;
427 p_dst_y = vlc_plane_start( &i_dst_pitch, p_dst, Y_PLANE,
428 i_x_offset, i_y_offset, &p_filter->fmt_out.video, 1 );
429 p_dst_u = vlc_plane_start( NULL, p_dst, U_PLANE,
430 i_x_offset, i_y_offset, &p_filter->fmt_out.video, 2 );
431 p_dst_v = vlc_plane_start( NULL, p_dst, V_PLANE,
432 i_x_offset, i_y_offset, &p_filter->fmt_out.video, 2 );
434 p_src_y = vlc_plane_start( &i_src_pitch, p_src, Y_PLANE,
435 0, 0, &p_filter->fmt_in.video, 1 );
436 p_src_u = vlc_plane_start( NULL, p_src, U_PLANE,
437 0, 0, &p_filter->fmt_in.video, 2 );
438 p_src_v = vlc_plane_start( NULL, p_src, V_PLANE,
439 0, 0, &p_filter->fmt_in.video, 2 );
440 p_trans = vlc_plane_start( NULL, p_src, A_PLANE,
441 0, 0, &p_filter->fmt_in.video, 1 );
443 /* Draw until we reach the bottom of the subtitle */
444 for( i_y = 0; i_y < i_height; i_y++, p_trans += i_src_pitch,
445 p_dst_y += i_dst_pitch, p_src_y += i_src_pitch,
446 p_dst_u += b_even_scanline ? i_dst_pitch/2 : 0,
447 p_src_u += i_src_pitch,
448 p_dst_v += b_even_scanline ? i_dst_pitch/2 : 0,
449 p_src_v += i_src_pitch )
451 b_even_scanline = !b_even_scanline;
453 /* Draw until we reach the end of the line */
454 for( i_x = 0; i_x < i_width; i_x++ )
457 i_trans = vlc_alpha( p_trans[i_x], i_alpha );
463 p_dst_y[i_x] = vlc_blend( p_src_y[i_x], p_dst_y[i_x], i_trans );
464 if( b_even_scanline && i_x % 2 == 0 )
466 p_dst_u[i_x/2] = vlc_blend( p_src_u[i_x], p_dst_u[i_x/2], i_trans );
467 p_dst_v[i_x/2] = vlc_blend( p_src_v[i_x], p_dst_v[i_x/2], i_trans );
473 static void BlendYUVARV16( filter_t *p_filter,
474 picture_t *p_dst_pic, picture_t *p_src,
475 int i_x_offset, int i_y_offset,
476 int i_width, int i_height, int i_alpha )
478 int i_src_pitch, i_dst_pitch;
479 uint8_t *p_dst, *p_src_y;
480 uint8_t *p_src_u, *p_src_v;
482 int i_x, i_y, i_pix_pitch, i_trans = 0;
485 i_pix_pitch = p_dst_pic->p->i_pixel_pitch;
486 i_dst_pitch = p_dst_pic->p->i_pitch;
487 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
488 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
489 p_dst_pic->p->i_pitch *
490 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
492 p_src_y = vlc_plane_start( &i_src_pitch, p_src, Y_PLANE,
493 0, 0, &p_filter->fmt_in.video, 1 );
494 p_src_u = vlc_plane_start( NULL, p_src, U_PLANE,
495 0, 0, &p_filter->fmt_in.video, 2 );
496 p_src_v = vlc_plane_start( NULL, p_src, V_PLANE,
497 0, 0, &p_filter->fmt_in.video, 2 );
498 p_trans = vlc_plane_start( NULL, p_src, A_PLANE,
499 0, 0, &p_filter->fmt_in.video, 1 );
501 /* Draw until we reach the bottom of the subtitle */
502 for( i_y = 0; i_y < i_height; i_y++, p_trans += i_src_pitch,
503 p_dst += i_dst_pitch,
504 p_src_y += i_src_pitch, p_src_u += i_src_pitch,
505 p_src_v += i_src_pitch )
507 /* Draw until we reach the end of the line */
508 for( i_x = 0; i_x < i_width; i_x++ )
511 i_trans = vlc_alpha( p_trans[i_x], i_alpha );
516 yuv_to_rgb( &r, &g, &b,
517 p_src_y[i_x], p_src_u[i_x], p_src_v[i_x] );
519 vlc_blend_rgb16( (uint16_t*)&p_dst[i_x * i_pix_pitch],
520 r, g, b, i_trans, &p_filter->fmt_out.video );
525 static void BlendYUVARV24( filter_t *p_filter,
526 picture_t *p_dst_pic, picture_t *p_src,
527 int i_x_offset, int i_y_offset,
528 int i_width, int i_height, int i_alpha )
530 int i_src_pitch, i_dst_pitch;
531 uint8_t *p_dst, *p_src_y;
532 uint8_t *p_src_u, *p_src_v;
534 int i_x, i_y, i_pix_pitch, i_trans = 0;
537 i_pix_pitch = p_dst_pic->p->i_pixel_pitch;
538 i_dst_pitch = p_dst_pic->p->i_pitch;
539 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
540 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
541 p_dst_pic->p->i_pitch *
542 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
544 p_src_y = vlc_plane_start( &i_src_pitch, p_src, Y_PLANE,
545 0, 0, &p_filter->fmt_in.video, 1 );
546 p_src_u = vlc_plane_start( NULL, p_src, U_PLANE,
547 0, 0, &p_filter->fmt_in.video, 2 );
548 p_src_v = vlc_plane_start( NULL, p_src, V_PLANE,
549 0, 0, &p_filter->fmt_in.video, 2 );
550 p_trans = vlc_plane_start( NULL, p_src, A_PLANE,
551 0, 0, &p_filter->fmt_in.video, 1 );
553 if( (i_pix_pitch == 4)
554 && (((((intptr_t)p_dst)|i_dst_pitch) /* FIXME? */
558 ** if picture pixels are 32 bits long and lines addresses are 32 bit
559 ** aligned, optimize rendering
561 uint32_t *p32_dst = (uint32_t *)p_dst;
562 uint32_t i32_dst_pitch = (uint32_t)(i_dst_pitch>>2);
564 int i_rshift, i_gshift, i_bshift;
565 uint32_t i_rmask, i_gmask, i_bmask;
567 i_rmask = p_filter->fmt_out.video.i_rmask;
568 i_gmask = p_filter->fmt_out.video.i_gmask;
569 i_bmask = p_filter->fmt_out.video.i_bmask;
570 i_rshift = p_filter->fmt_out.video.i_lrshift;
571 i_gshift = p_filter->fmt_out.video.i_lgshift;
572 i_bshift = p_filter->fmt_out.video.i_lbshift;
574 /* Draw until we reach the bottom of the subtitle */
575 for( i_y = 0; i_y < i_height; i_y++, p_trans += i_src_pitch,
576 p32_dst += i32_dst_pitch,
577 p_src_y += i_src_pitch, p_src_u += i_src_pitch,
578 p_src_v += i_src_pitch )
580 /* Draw until we reach the end of the line */
581 for( i_x = 0; i_x < i_width; i_x++ )
584 i_trans = vlc_alpha( p_trans[i_x], i_alpha );
588 if( i_trans == MAX_TRANS )
590 /* Completely opaque. Completely overwrite underlying pixel */
591 yuv_to_rgb( &r, &g, &b,
592 p_src_y[i_x], p_src_u[i_x], p_src_v[i_x] );
594 p32_dst[i_x] = (r<<i_rshift) |
601 uint32_t i_pix_dst = p32_dst[i_x];
602 yuv_to_rgb( &r, &g, &b,
603 p_src_y[i_x], p_src_u[i_x], p_src_v[i_x] );
605 p32_dst[i_x] = ( vlc_blend( r, (i_pix_dst & i_rmask)>>i_rshift, i_trans ) << i_rshift ) |
606 ( vlc_blend( g, (i_pix_dst & i_gmask)>>i_gshift, i_trans ) << i_gshift ) |
607 ( vlc_blend( b, (i_pix_dst & i_bmask)>>i_bshift, i_trans ) << i_bshift );
614 int i_rindex, i_gindex, i_bindex;
615 uint32_t i_rmask, i_gmask, i_bmask;
617 i_rmask = p_filter->fmt_out.video.i_rmask;
618 i_gmask = p_filter->fmt_out.video.i_gmask;
619 i_bmask = p_filter->fmt_out.video.i_bmask;
621 vlc_rgb_index( &i_rindex, &i_gindex, &i_bindex, &p_filter->fmt_out.video );
623 /* Draw until we reach the bottom of the subtitle */
624 for( i_y = 0; i_y < i_height; i_y++, p_trans += i_src_pitch,
625 p_dst += i_dst_pitch,
626 p_src_y += i_src_pitch, p_src_u += i_src_pitch,
627 p_src_v += i_src_pitch )
629 /* Draw until we reach the end of the line */
630 for( i_x = 0; i_x < i_width; i_x++ )
633 i_trans = vlc_alpha( p_trans[i_x], i_alpha );
638 yuv_to_rgb( &r, &g, &b,
639 p_src_y[i_x], p_src_u[i_x], p_src_v[i_x] );
641 vlc_blend_packed( &p_dst[ i_x * i_pix_pitch],
642 i_rindex, i_gindex, i_bindex,
643 r, g, b, i_alpha, true );
649 static void BlendYUVAYUVPacked( filter_t *p_filter,
650 picture_t *p_dst_pic, picture_t *p_src,
651 int i_x_offset, int i_y_offset,
652 int i_width, int i_height, int i_alpha )
654 int i_src_pitch, i_dst_pitch;
655 uint8_t *p_dst, *p_src_y;
656 uint8_t *p_src_u, *p_src_v;
658 int i_x, i_y, i_pix_pitch, i_trans = 0;
659 bool b_even = !((i_x_offset + p_filter->fmt_out.video.i_x_offset)%2);
660 int i_l_offset, i_u_offset, i_v_offset;
662 vlc_yuv_packed_index( &i_l_offset, &i_u_offset, &i_v_offset,
663 p_filter->fmt_out.video.i_chroma );
666 i_dst_pitch = p_dst_pic->p->i_pitch;
667 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
668 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
669 p_dst_pic->p->i_pitch *
670 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
672 p_src_y = vlc_plane_start( &i_src_pitch, p_src, Y_PLANE,
673 0, 0, &p_filter->fmt_in.video, 1 );
674 p_src_u = vlc_plane_start( NULL, p_src, U_PLANE,
675 0, 0, &p_filter->fmt_in.video, 2 );
676 p_src_v = vlc_plane_start( NULL, p_src, V_PLANE,
677 0, 0, &p_filter->fmt_in.video, 2 );
678 p_trans = vlc_plane_start( NULL, p_src, A_PLANE,
679 0, 0, &p_filter->fmt_in.video, 1 );
681 i_width &= ~1; /* Needs to be a multiple of 2 */
683 /* Draw until we reach the bottom of the subtitle */
684 for( i_y = 0; i_y < i_height; i_y++, p_trans += i_src_pitch,
685 p_dst += i_dst_pitch,
686 p_src_y += i_src_pitch, p_src_u += i_src_pitch,
687 p_src_v += i_src_pitch )
689 /* Draw until we reach the end of the line */
690 for( i_x = 0; i_x < i_width; i_x++, b_even = !b_even )
692 i_trans = vlc_alpha( p_trans[i_x], i_alpha );
701 /* FIXME what's with 0xaa ? */
702 if( p_trans[i_x+1] > 0xaa )
704 i_u = (p_src_u[i_x]+p_src_u[i_x+1])>>1;
705 i_v = (p_src_v[i_x]+p_src_v[i_x+1])>>1;
713 vlc_blend_packed( &p_dst[i_x * 2],
714 i_l_offset, i_u_offset, i_v_offset,
715 p_src_y[i_x], i_u, i_v, i_trans, true );
719 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 );
724 /***********************************************************************
726 ***********************************************************************/
727 static void BlendI420I420( filter_t *p_filter,
728 picture_t *p_dst, picture_t *p_src,
729 int i_x_offset, int i_y_offset,
730 int i_width, int i_height, int i_alpha )
732 int i_src_pitch, i_dst_pitch;
733 uint8_t *p_src_y, *p_dst_y;
734 uint8_t *p_src_u, *p_dst_u;
735 uint8_t *p_src_v, *p_dst_v;
737 bool b_even_scanline = i_y_offset % 2;
739 if( i_alpha == 0xff )
741 BlendI420I420_no_alpha( p_filter, p_dst, p_src,
742 i_x_offset, i_y_offset, i_width, i_height );
747 i_dst_pitch = p_dst->p[Y_PLANE].i_pitch;
748 p_dst_y = p_dst->p[Y_PLANE].p_pixels + i_x_offset +
749 p_filter->fmt_out.video.i_x_offset +
750 p_dst->p[Y_PLANE].i_pitch *
751 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
752 p_dst_u = p_dst->p[U_PLANE].p_pixels + i_x_offset/2 +
753 p_filter->fmt_out.video.i_x_offset/2 +
754 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
755 p_dst->p[U_PLANE].i_pitch;
756 p_dst_v = p_dst->p[V_PLANE].p_pixels + i_x_offset/2 +
757 p_filter->fmt_out.video.i_x_offset/2 +
758 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
759 p_dst->p[V_PLANE].i_pitch;
761 p_src_y = vlc_plane_start( &i_src_pitch, p_src, Y_PLANE,
762 0, 0, &p_filter->fmt_in.video, 1 );
763 p_src_u = vlc_plane_start( NULL, p_src, U_PLANE,
764 0, 0, &p_filter->fmt_in.video, 2 );
765 p_src_v = vlc_plane_start( NULL, p_src, V_PLANE,
766 0, 0, &p_filter->fmt_in.video, 2 );
769 /* Draw until we reach the bottom of the subtitle */
770 for( i_y = 0; i_y < i_height; i_y++,
771 p_dst_y += i_dst_pitch,
772 p_src_y += i_src_pitch )
774 if( b_even_scanline )
776 p_dst_u += i_dst_pitch/2;
777 p_dst_v += i_dst_pitch/2;
779 b_even_scanline = !b_even_scanline;
781 /* Draw until we reach the end of the line */
782 for( i_x = 0; i_x < i_width; i_x++ )
788 p_dst_y[i_x] = vlc_blend( p_src_y[i_x], p_dst_y[i_x], i_alpha );
789 if( b_even_scanline && i_x % 2 == 0 )
791 p_dst_u[i_x/2] = vlc_blend( p_src_u[i_x/2], p_dst_u[i_x/2], i_alpha );
792 p_dst_v[i_x/2] = vlc_blend( p_src_v[i_x/2], p_dst_v[i_x/2], i_alpha );
797 p_src_u += i_src_pitch/2;
798 p_src_v += i_src_pitch/2;
802 static void BlendI420I420_no_alpha( filter_t *p_filter,
803 picture_t *p_dst, picture_t *p_src,
804 int i_x_offset, int i_y_offset,
805 int i_width, int i_height )
807 int i_src_pitch, i_dst_pitch;
808 uint8_t *p_src_y, *p_dst_y;
809 uint8_t *p_src_u, *p_dst_u;
810 uint8_t *p_src_v, *p_dst_v;
812 bool b_even_scanline = i_y_offset % 2;
814 i_dst_pitch = p_dst->p[Y_PLANE].i_pitch;
815 p_dst_y = p_dst->p[Y_PLANE].p_pixels + i_x_offset +
816 p_filter->fmt_out.video.i_x_offset +
817 p_dst->p[Y_PLANE].i_pitch *
818 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
819 p_dst_u = p_dst->p[U_PLANE].p_pixels + i_x_offset/2 +
820 p_filter->fmt_out.video.i_x_offset/2 +
821 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
822 p_dst->p[U_PLANE].i_pitch;
823 p_dst_v = p_dst->p[V_PLANE].p_pixels + i_x_offset/2 +
824 p_filter->fmt_out.video.i_x_offset/2 +
825 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
826 p_dst->p[V_PLANE].i_pitch;
828 p_src_y = vlc_plane_start( &i_src_pitch, p_src, Y_PLANE,
829 0, 0, &p_filter->fmt_in.video, 1 );
830 p_src_u = vlc_plane_start( NULL, p_src, U_PLANE,
831 0, 0, &p_filter->fmt_in.video, 2 );
832 p_src_v = vlc_plane_start( NULL, p_src, V_PLANE,
833 0, 0, &p_filter->fmt_in.video, 2 );
837 /* Draw until we reach the bottom of the subtitle */
838 for( i_y = 0; i_y < i_height;
839 i_y++, p_dst_y += i_dst_pitch, p_src_y += i_src_pitch )
841 /* Completely opaque. Completely overwrite underlying pixel */
842 vlc_memcpy( p_dst_y, p_src_y, i_width );
843 if( b_even_scanline )
845 p_dst_u += i_dst_pitch/2;
846 p_dst_v += i_dst_pitch/2;
850 vlc_memcpy( p_dst_u, p_src_u, i_width/2 );
851 vlc_memcpy( p_dst_v, p_src_v, i_width/2 );
853 b_even_scanline = !b_even_scanline;
856 p_src_u += i_src_pitch/2;
857 p_src_v += i_src_pitch/2;
862 static void BlendI420R16( filter_t *p_filter,
863 picture_t *p_dst_pic, 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;
873 i_pix_pitch = p_dst_pic->p->i_pixel_pitch;
874 i_dst_pitch = p_dst_pic->p->i_pitch;
875 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
876 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
877 p_dst_pic->p->i_pitch *
878 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
880 p_src_y = vlc_plane_start( &i_src_pitch, p_src, Y_PLANE,
881 0, 0, &p_filter->fmt_in.video, 1 );
882 p_src_u = vlc_plane_start( NULL, p_src, U_PLANE,
883 0, 0, &p_filter->fmt_in.video, 2 );
884 p_src_v = vlc_plane_start( NULL, p_src, V_PLANE,
885 0, 0, &p_filter->fmt_in.video, 2 );
887 /* Draw until we reach the bottom of the subtitle */
888 for( i_y = 0; i_y < i_height; i_y++,
889 p_dst += i_dst_pitch,
890 p_src_y += i_src_pitch )
892 /* Draw until we reach the end of the line */
893 for( i_x = 0; i_x < i_width; i_x++ )
896 yuv_to_rgb( &r, &g, &b,
897 p_src_y[i_x], p_src_u[i_x/2], p_src_v[i_x/2] );
899 vlc_blend_rgb16( (uint16_t*)&p_dst[i_x * i_pix_pitch],
900 r, g, b, i_alpha, &p_filter->fmt_out.video );
904 p_src_u += i_src_pitch/2;
905 p_src_v += i_src_pitch/2;
910 static void BlendI420R24( filter_t *p_filter,
911 picture_t *p_dst_pic, picture_t *p_src,
912 int i_x_offset, int i_y_offset,
913 int i_width, int i_height, int i_alpha )
915 int i_src_pitch, i_dst_pitch;
916 uint8_t *p_dst, *p_src_y;
917 uint8_t *p_src_u, *p_src_v;
918 int i_x, i_y, i_pix_pitch;
919 int i_rindex, i_gindex, i_bindex;
922 i_pix_pitch = p_dst_pic->p->i_pixel_pitch;
923 i_dst_pitch = p_dst_pic->p->i_pitch;
924 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
925 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
926 p_dst_pic->p->i_pitch *
927 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
929 p_src_y = vlc_plane_start( &i_src_pitch, p_src, Y_PLANE,
930 0, 0, &p_filter->fmt_in.video, 1 );
931 p_src_u = vlc_plane_start( NULL, p_src, U_PLANE,
932 0, 0, &p_filter->fmt_in.video, 2 );
933 p_src_v = vlc_plane_start( NULL, p_src, V_PLANE,
934 0, 0, &p_filter->fmt_in.video, 2 );
936 vlc_rgb_index( &i_rindex, &i_gindex, &i_bindex, &p_filter->fmt_out.video );
938 /* Draw until we reach the bottom of the subtitle */
939 for( i_y = 0; i_y < i_height; i_y++,
940 p_dst += i_dst_pitch,
941 p_src_y += i_src_pitch, p_src_u += i_src_pitch,
942 p_src_v += i_src_pitch )
944 /* Draw until we reach the end of the line */
945 for( i_x = 0; i_x < i_width; i_x++ )
951 yuv_to_rgb( &r, &g, &b,
952 p_src_y[i_x], p_src_u[i_x/2], p_src_v[i_x/2] );
954 vlc_blend_packed( &p_dst[i_x * i_pix_pitch],
955 i_rindex, i_gindex, i_bindex, r, g, b, i_alpha, true );
959 p_src_u += i_src_pitch/2;
960 p_src_v += i_src_pitch/2;
965 static void BlendI420YUVPacked( filter_t *p_filter,
966 picture_t *p_dst_pic, picture_t *p_src,
967 int i_x_offset, int i_y_offset,
968 int i_width, int i_height, int i_alpha )
970 int i_src_pitch, i_dst_pitch;
971 uint8_t *p_dst, *p_src_y;
972 uint8_t *p_src_u, *p_src_v;
973 int i_x, i_y, i_pix_pitch;
974 bool b_even = !((i_x_offset + p_filter->fmt_out.video.i_x_offset)%2);
975 int i_l_offset, i_u_offset, i_v_offset;
977 vlc_yuv_packed_index( &i_l_offset, &i_u_offset, &i_v_offset,
978 p_filter->fmt_out.video.i_chroma );
981 i_dst_pitch = p_dst_pic->p->i_pitch;
982 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
983 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
984 p_dst_pic->p->i_pitch *
985 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
987 p_src_y = vlc_plane_start( &i_src_pitch, p_src, Y_PLANE,
988 0, 0, &p_filter->fmt_in.video, 1 );
989 p_src_u = vlc_plane_start( NULL, p_src, U_PLANE,
990 0, 0, &p_filter->fmt_in.video, 2 );
991 p_src_v = vlc_plane_start( NULL, p_src, V_PLANE,
992 0, 0, &p_filter->fmt_in.video, 2 );
994 i_width &= ~1; /* Needs to be a multiple of 2 */
996 /* Draw until we reach the bottom of the subtitle */
997 for( i_y = 0; i_y < i_height; i_y++,
998 p_dst += i_dst_pitch,
999 p_src_y += i_src_pitch, p_src_u += i_src_pitch,
1000 p_src_v += i_src_pitch )
1002 /* Draw until we reach the end of the line */
1003 for( i_x = 0; i_x < i_width; i_x++, b_even = !b_even )
1009 vlc_blend_packed( &p_dst[i_x * 2],
1010 i_l_offset, i_u_offset, i_v_offset,
1011 p_src_y[i_x], p_src_u[i_x/2], p_src_v[i_x/2], i_alpha, b_even );
1015 p_src_u += i_src_pitch/2;
1016 p_src_v += i_src_pitch/2;
1021 /***********************************************************************
1023 ***********************************************************************/
1024 static void BlendPalI420( filter_t *p_filter,
1025 picture_t *p_dst, picture_t *p_src_pic,
1026 int i_x_offset, int i_y_offset,
1027 int i_width, int i_height, int i_alpha )
1029 int i_src_pitch, i_dst_pitch;
1030 uint8_t *p_src, *p_dst_y;
1033 int i_x, i_y, i_trans;
1034 bool b_even_scanline = i_y_offset % 2;
1036 i_dst_pitch = p_dst->p[Y_PLANE].i_pitch;
1037 p_dst_y = p_dst->p[Y_PLANE].p_pixels + i_x_offset +
1038 p_filter->fmt_out.video.i_x_offset +
1039 p_dst->p[Y_PLANE].i_pitch *
1040 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1041 p_dst_u = p_dst->p[U_PLANE].p_pixels + i_x_offset/2 +
1042 p_filter->fmt_out.video.i_x_offset/2 +
1043 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
1044 p_dst->p[U_PLANE].i_pitch;
1045 p_dst_v = p_dst->p[V_PLANE].p_pixels + i_x_offset/2 +
1046 p_filter->fmt_out.video.i_x_offset/2 +
1047 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
1048 p_dst->p[V_PLANE].i_pitch;
1050 i_src_pitch = p_src_pic->p->i_pitch;
1051 p_src = p_src_pic->p->p_pixels + p_filter->fmt_in.video.i_x_offset +
1052 i_src_pitch * p_filter->fmt_in.video.i_y_offset;
1054 #define p_pal p_filter->fmt_in.video.p_palette->palette
1056 /* Draw until we reach the bottom of the subtitle */
1057 for( i_y = 0; i_y < i_height; i_y++,
1058 p_dst_y += i_dst_pitch,
1059 p_src += i_src_pitch,
1060 p_dst_u += b_even_scanline ? i_dst_pitch/2 : 0,
1061 p_dst_v += b_even_scanline ? i_dst_pitch/2 : 0 )
1063 const uint8_t *p_trans = p_src;
1064 b_even_scanline = !b_even_scanline;
1066 /* Draw until we reach the end of the line */
1067 for( i_x = 0; i_x < i_width; i_x++ )
1069 i_trans = vlc_alpha( p_pal[p_trans[i_x]][3], i_alpha );
1074 p_dst_y[i_x] = vlc_blend( p_pal[p_src[i_x]][0], p_dst_y[i_x], i_trans );
1075 if( b_even_scanline && ((i_x % 2) == 0) )
1077 p_dst_u[i_x/2] = vlc_blend( p_pal[p_src[i_x]][1], p_dst_u[i_x/2], i_trans );
1078 p_dst_v[i_x/2] = vlc_blend( p_pal[p_src[i_x]][2], p_dst_v[i_x/2], i_trans );
1085 static void BlendPalYUVPacked( filter_t *p_filter,
1086 picture_t *p_dst_pic, picture_t *p_src_pic,
1087 int i_x_offset, int i_y_offset,
1088 int i_width, int i_height, int i_alpha )
1090 int i_src_pitch, i_dst_pitch;
1091 uint8_t *p_src, *p_dst;
1092 int i_x, i_y, i_pix_pitch, i_trans;
1093 bool b_even = !((i_x_offset + p_filter->fmt_out.video.i_x_offset)%2);
1094 int i_l_offset, i_u_offset, i_v_offset;
1096 vlc_yuv_packed_index( &i_l_offset, &i_u_offset, &i_v_offset,
1097 p_filter->fmt_out.video.i_chroma );
1100 i_dst_pitch = p_dst_pic->p->i_pitch;
1101 p_dst = p_dst_pic->p->p_pixels + i_pix_pitch * (i_x_offset +
1102 p_filter->fmt_out.video.i_x_offset) + p_dst_pic->p->i_pitch *
1103 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1105 i_src_pitch = p_src_pic->p->i_pitch;
1106 p_src = p_src_pic->p->p_pixels + p_filter->fmt_in.video.i_x_offset +
1107 i_src_pitch * p_filter->fmt_in.video.i_y_offset;
1109 i_width &= ~1; /* Needs to be a multiple of 2 */
1111 #define p_pal p_filter->fmt_in.video.p_palette->palette
1113 /* Draw until we reach the bottom of the subtitle */
1114 for( i_y = 0; i_y < i_height; i_y++,
1115 p_dst += i_dst_pitch, p_src += i_src_pitch )
1117 const uint8_t *p_trans = p_src;
1118 /* Draw until we reach the end of the line */
1119 for( i_x = 0; i_x < i_width; i_x++, b_even = !b_even )
1121 i_trans = vlc_alpha( p_pal[p_trans[i_x]][3], i_alpha );
1130 if( p_trans[i_x+1] > 0xaa )
1132 i_u = (p_pal[p_src[i_x]][1] + p_pal[p_src[i_x+1]][1]) >> 1;
1133 i_v = (p_pal[p_src[i_x]][2] + p_pal[p_src[i_x+1]][2]) >> 1;
1137 i_u = p_pal[p_src[i_x]][1];
1138 i_v = p_pal[p_src[i_x]][2];
1141 vlc_blend_packed( &p_dst[i_x * 2],
1142 i_l_offset, i_u_offset, i_v_offset,
1143 p_pal[p_src[i_x]][0], i_u, i_v, i_trans, true );
1147 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 );
1154 static void BlendPalRV( filter_t *p_filter,
1155 picture_t *p_dst_pic, picture_t *p_src_pic,
1156 int i_x_offset, int i_y_offset,
1157 int i_width, int i_height, int i_alpha )
1159 int i_src_pitch, i_dst_pitch;
1160 uint8_t *p_src, *p_dst;
1161 int i_x, i_y, i_pix_pitch, i_trans;
1162 video_palette_t rgbpalette;
1163 int i_rindex, i_gindex, i_bindex;
1165 i_pix_pitch = p_dst_pic->p->i_pixel_pitch;
1166 i_dst_pitch = p_dst_pic->p->i_pitch;
1167 p_dst = p_dst_pic->p->p_pixels + i_pix_pitch * (i_x_offset +
1168 p_filter->fmt_out.video.i_x_offset) + p_dst_pic->p->i_pitch *
1169 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1171 i_src_pitch = p_src_pic->p->i_pitch;
1172 p_src = p_src_pic->p->p_pixels + p_filter->fmt_in.video.i_x_offset +
1173 i_src_pitch * p_filter->fmt_in.video.i_y_offset;
1175 #define p_pal p_filter->fmt_in.video.p_palette->palette
1176 #define rgbpal rgbpalette.palette
1178 /* Convert palette first */
1179 for( i_y = 0; i_y < p_filter->fmt_in.video.p_palette->i_entries && i_y < 256; i_y++ )
1183 yuv_to_rgb( &r, &g, &b, p_pal[i_y][0], p_pal[i_y][1], p_pal[i_y][2] );
1190 vlc_rgb_index( &i_rindex, &i_gindex, &i_bindex, &p_filter->fmt_out.video );
1192 /* Draw until we reach the bottom of the subtitle */
1193 for( i_y = 0; i_y < i_height; i_y++,
1194 p_dst += i_dst_pitch, p_src += i_src_pitch )
1196 const uint8_t *p_trans = p_src;
1197 /* Draw until we reach the end of the line */
1198 for( i_x = 0; i_x < i_width; i_x++ )
1200 i_trans = vlc_alpha( p_pal[p_trans[i_x]][3], i_alpha );
1205 if( p_filter->fmt_out.video.i_chroma == FCC_RV15 || p_filter->fmt_out.video.i_chroma == FCC_RV16 )
1206 vlc_blend_rgb16( (uint16_t*)&p_dst[i_x * i_pix_pitch],
1207 rgbpal[p_src[i_x]][0], rgbpal[p_src[i_x]][1], rgbpal[p_src[i_x]][2],
1209 &p_filter->fmt_out.video );
1211 vlc_blend_packed( &p_dst[i_x * i_pix_pitch],
1212 i_rindex, i_gindex, i_bindex,
1213 rgbpal[p_src[i_x]][0], rgbpal[p_src[i_x]][1], rgbpal[p_src[i_x]][2],
1222 /***********************************************************************
1224 ***********************************************************************/
1225 static void BlendRGBAI420( filter_t *p_filter,
1226 picture_t *p_dst, picture_t *p_src_pic,
1227 int i_x_offset, int i_y_offset,
1228 int i_width, int i_height, int i_alpha )
1230 int i_src_pitch, i_dst_pitch, i_src_pix_pitch;
1235 int i_x, i_y, i_trans;
1238 bool b_even_scanline = i_y_offset % 2;
1240 i_dst_pitch = p_dst->p[Y_PLANE].i_pitch;
1241 p_dst_y = p_dst->p[Y_PLANE].p_pixels + i_x_offset +
1242 p_filter->fmt_out.video.i_x_offset +
1243 p_dst->p[Y_PLANE].i_pitch *
1244 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1245 p_dst_u = p_dst->p[U_PLANE].p_pixels + i_x_offset/2 +
1246 p_filter->fmt_out.video.i_x_offset/2 +
1247 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
1248 p_dst->p[U_PLANE].i_pitch;
1249 p_dst_v = p_dst->p[V_PLANE].p_pixels + i_x_offset/2 +
1250 p_filter->fmt_out.video.i_x_offset/2 +
1251 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
1252 p_dst->p[V_PLANE].i_pitch;
1254 i_src_pix_pitch = p_src_pic->p->i_pixel_pitch;
1255 i_src_pitch = p_src_pic->p->i_pitch;
1256 p_src = p_src_pic->p->p_pixels +
1257 p_filter->fmt_in.video.i_x_offset * i_src_pix_pitch +
1258 p_src_pic->p->i_pitch * p_filter->fmt_in.video.i_y_offset;
1261 /* Draw until we reach the bottom of the subtitle */
1262 for( i_y = 0; i_y < i_height; i_y++,
1263 p_dst_y += i_dst_pitch,
1264 p_dst_u += b_even_scanline ? i_dst_pitch/2 : 0,
1265 p_dst_v += b_even_scanline ? i_dst_pitch/2 : 0,
1266 p_src += i_src_pitch )
1268 b_even_scanline = !b_even_scanline;
1270 /* Draw until we reach the end of the line */
1271 for( i_x = 0; i_x < i_width; i_x++ )
1273 const int R = p_src[i_x * i_src_pix_pitch + 0];
1274 const int G = p_src[i_x * i_src_pix_pitch + 1];
1275 const int B = p_src[i_x * i_src_pix_pitch + 2];
1277 i_trans = vlc_alpha( p_src[i_x * i_src_pix_pitch + 3], i_alpha );
1282 rgb_to_yuv( &y, &u, &v, R, G, B );
1284 p_dst_y[i_x] = vlc_blend( y, p_dst_y[i_x], i_trans );
1285 if( b_even_scanline && i_x % 2 == 0 )
1287 p_dst_u[i_x/2] = vlc_blend( u, p_dst_u[i_x/2], i_trans );
1288 p_dst_v[i_x/2] = vlc_blend( v, p_dst_v[i_x/2], i_trans );
1294 static void BlendRGBAR24( filter_t *p_filter,
1295 picture_t *p_dst_pic, picture_t *p_src_pic,
1296 int i_x_offset, int i_y_offset,
1297 int i_width, int i_height, int i_alpha )
1299 int i_src_pitch, i_dst_pitch;
1300 uint8_t *p_dst, *p_src;
1301 int i_x, i_y, i_pix_pitch, i_trans, i_src_pix_pitch;
1302 int i_rindex, i_gindex, i_bindex;
1304 i_pix_pitch = p_dst_pic->p->i_pixel_pitch;
1305 i_dst_pitch = p_dst_pic->p->i_pitch;
1306 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
1307 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
1308 p_dst_pic->p->i_pitch *
1309 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1311 i_src_pix_pitch = p_src_pic->p->i_pixel_pitch;
1312 i_src_pitch = p_src_pic->p->i_pitch;
1313 p_src = p_src_pic->p->p_pixels +
1314 p_filter->fmt_in.video.i_x_offset * i_src_pix_pitch +
1315 p_src_pic->p->i_pitch * p_filter->fmt_in.video.i_y_offset;
1317 vlc_rgb_index( &i_rindex, &i_gindex, &i_bindex, &p_filter->fmt_out.video );
1319 /* Draw until we reach the bottom of the subtitle */
1320 for( i_y = 0; i_y < i_height; i_y++,
1321 p_dst += i_dst_pitch, p_src += i_src_pitch )
1323 /* Draw until we reach the end of the line */
1324 for( i_x = 0; i_x < i_width; i_x++ )
1326 const int R = p_src[i_x * i_src_pix_pitch + 0];
1327 const int G = p_src[i_x * i_src_pix_pitch + 1];
1328 const int B = p_src[i_x * i_src_pix_pitch + 2];
1330 i_trans = vlc_alpha( p_src[i_x * i_src_pix_pitch + 3], i_alpha );
1335 vlc_blend_packed( &p_dst[i_x * i_pix_pitch],
1336 i_rindex, i_gindex, i_bindex,
1337 R, G, B, i_trans, true );
1342 static void BlendRGBAR16( filter_t *p_filter,
1343 picture_t *p_dst_pic, picture_t *p_src_pic,
1344 int i_x_offset, int i_y_offset,
1345 int i_width, int i_height, int i_alpha )
1347 int i_src_pitch, i_dst_pitch;
1348 uint8_t *p_dst, *p_src;
1349 int i_x, i_y, i_pix_pitch, i_trans, i_src_pix_pitch;
1351 i_pix_pitch = p_dst_pic->p->i_pixel_pitch;
1352 i_dst_pitch = p_dst_pic->p->i_pitch;
1353 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
1354 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
1355 p_dst_pic->p->i_pitch *
1356 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1358 i_src_pix_pitch = p_src_pic->p->i_pixel_pitch;
1359 i_src_pitch = p_src_pic->p->i_pitch;
1360 p_src = p_src_pic->p->p_pixels +
1361 p_filter->fmt_in.video.i_x_offset * i_src_pix_pitch +
1362 p_src_pic->p->i_pitch * p_filter->fmt_in.video.i_y_offset;
1364 /* Draw until we reach the bottom of the subtitle */
1365 for( i_y = 0; i_y < i_height; i_y++,
1366 p_dst += i_dst_pitch, p_src += i_src_pitch )
1368 /* Draw until we reach the end of the line */
1369 for( i_x = 0; i_x < i_width; i_x++ )
1371 const int R = p_src[i_x * i_src_pix_pitch + 0];
1372 const int G = p_src[i_x * i_src_pix_pitch + 1];
1373 const int B = p_src[i_x * i_src_pix_pitch + 2];
1375 i_trans = vlc_alpha( p_src[i_x * i_src_pix_pitch + 3], i_alpha );
1380 vlc_blend_rgb16( (uint16_t*)&p_dst[i_x * i_pix_pitch],
1381 R, G, B, i_trans, &p_filter->fmt_out.video );
1386 static void BlendRGBAYUVPacked( filter_t *p_filter,
1387 picture_t *p_dst_pic, picture_t *p_src_pic,
1388 int i_x_offset, int i_y_offset,
1389 int i_width, int i_height, int i_alpha )
1391 int i_src_pitch, i_dst_pitch, i_src_pix_pitch;
1392 uint8_t *p_dst, *p_src;
1393 int i_x, i_y, i_pix_pitch, i_trans;
1394 bool b_even = !((i_x_offset + p_filter->fmt_out.video.i_x_offset)%2);
1395 int i_l_offset, i_u_offset, i_v_offset;
1398 vlc_yuv_packed_index( &i_l_offset, &i_u_offset, &i_v_offset,
1399 p_filter->fmt_out.video.i_chroma );
1402 i_dst_pitch = p_dst_pic->p->i_pitch;
1403 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
1404 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
1405 p_dst_pic->p->i_pitch *
1406 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1408 i_src_pix_pitch = p_src_pic->p->i_pixel_pitch;
1409 i_src_pitch = p_src_pic->p->i_pitch;
1410 p_src = p_src_pic->p->p_pixels +
1411 p_filter->fmt_in.video.i_x_offset * i_src_pitch +
1412 p_src_pic->p->i_pitch * p_filter->fmt_in.video.i_y_offset;
1414 i_width &= ~1; /* Needs to be a multiple of 2 */
1416 /* Draw until we reach the bottom of the subtitle */
1417 for( i_y = 0; i_y < i_height; i_y++,
1418 p_dst += i_dst_pitch,
1419 p_src += i_src_pitch )
1421 /* Draw until we reach the end of the line */
1422 for( i_x = 0; i_x < i_width; i_x++, b_even = !b_even )
1424 const int R = p_src[i_x * i_src_pix_pitch + 0];
1425 const int G = p_src[i_x * i_src_pix_pitch + 1];
1426 const int B = p_src[i_x * i_src_pix_pitch + 2];
1428 i_trans = vlc_alpha( p_src[i_x * i_src_pix_pitch + 3], i_alpha );
1433 rgb_to_yuv( &y, &u, &v, R, G, B );
1435 vlc_blend_packed( &p_dst[i_x * 2],
1436 i_l_offset, i_u_offset, i_v_offset,
1437 y, u, v, i_trans, b_even );