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_FOURCC('Y','U','V','A')
60 #define FCC_YUVP VLC_FOURCC('Y','U','V','P')
61 #define FCC_RGBA VLC_FOURCC('R','G','B','A')
63 #define FCC_I420 VLC_FOURCC('I','4','2','0')
64 #define FCC_YV12 VLC_FOURCC('Y','V','1','2')
65 #define FCC_YUY2 VLC_FOURCC('Y','U','Y','2')
66 #define FCC_UYVY VLC_FOURCC('U','Y','V','Y')
67 #define FCC_YVYU VLC_FOURCC('Y','V','Y','U')
68 #define FCC_RV15 VLC_FOURCC('R','V','1','5')
69 #define FCC_RV16 VLC_FOURCC('R','V','1','6')
70 #define FCC_RV24 VLC_FOURCC('R','V','2','4')
71 #define FCC_RV32 VLC_FOURCC('R','V','3','2')
73 /****************************************************************************
75 ****************************************************************************/
76 static void Blend( filter_t *, picture_t *, picture_t *, picture_t *,
80 static void BlendYUVAI420( filter_t *, picture_t *, picture_t *, picture_t *,
81 int, int, int, int, int );
82 static void BlendYUVARV16( filter_t *, picture_t *, picture_t *, picture_t *,
83 int, int, int, int, int );
84 static void BlendYUVARV24( filter_t *, picture_t *, picture_t *, picture_t *,
85 int, int, int, int, int );
86 static void BlendYUVAYUVPacked( filter_t *, picture_t *, picture_t *, picture_t *,
87 int, int, int, int, int );
90 static void BlendI420I420( filter_t *, picture_t *, picture_t *, picture_t *,
91 int, int, int, int, int );
92 static void BlendI420I420_no_alpha(
93 filter_t *, picture_t *, picture_t *, picture_t *,
95 static void BlendI420R16( filter_t *, picture_t *, picture_t *, picture_t *,
96 int, int, int, int, int );
97 static void BlendI420R24( filter_t *, picture_t *, picture_t *, picture_t *,
98 int, int, int, int, int );
99 static void BlendI420YUVPacked( filter_t *, picture_t *, picture_t *,
100 picture_t *, int, int, int, int, int );
103 static void BlendPalI420( filter_t *, picture_t *, picture_t *, picture_t *,
104 int, int, int, int, int );
105 static void BlendPalYUVPacked( filter_t *, picture_t *, picture_t *, picture_t *,
106 int, int, int, int, int );
107 static void BlendPalRV( filter_t *, picture_t *, picture_t *, picture_t *,
108 int, int, int, int, int );
111 static void BlendRGBAI420( filter_t *, picture_t *, picture_t *, picture_t *,
112 int, int, int, int, int );
113 static void BlendRGBAYUVPacked( filter_t *, picture_t *, picture_t *,
114 picture_t *, int, int, int, int, int );
115 static void BlendRGBAR16( filter_t *, picture_t *, picture_t *, picture_t *,
116 int, int, int, int, int );
117 static void BlendRGBAR24( filter_t *, picture_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 *, picture_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, picture_t *p_dst,
211 picture_t *p_dst_orig, 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_dst_orig, p_src,
247 i_x_offset, i_y_offset, i_width, i_height, i_alpha );
252 msg_Dbg( p_filter, "no matching alpha blending routine "
253 "(chroma: %4.4s -> %4.4s)",
254 (char *)&p_filter->fmt_in.video.i_chroma,
255 (char *)&p_filter->fmt_out.video.i_chroma );
258 /***********************************************************************
260 ***********************************************************************/
261 static inline uint8_t vlc_uint8( int v )
270 #define MAX_TRANS 255
273 static inline int vlc_blend( int v1, int v2, int a )
275 /* TODO bench if the tests really increase speed */
278 else if( a == MAX_TRANS )
280 return ( v1 * a + v2 * (MAX_TRANS - a ) ) >> TRANS_BITS;
283 static inline int vlc_alpha( int t, int a )
287 return (t * a) / 255;
290 static inline void yuv_to_rgb( int *r, int *g, int *b,
291 uint8_t y1, uint8_t u1, uint8_t v1 )
293 /* macros used for YUV pixel conversions */
294 # define SCALEBITS 10
295 # define ONE_HALF (1 << (SCALEBITS - 1))
296 # define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5))
298 int y, cb, cr, r_add, g_add, b_add;
302 r_add = FIX(1.40200*255.0/224.0) * cr + ONE_HALF;
303 g_add = - FIX(0.34414*255.0/224.0) * cb
304 - FIX(0.71414*255.0/224.0) * cr + ONE_HALF;
305 b_add = FIX(1.77200*255.0/224.0) * cb + ONE_HALF;
306 y = (y1 - 16) * FIX(255.0/219.0);
307 *r = vlc_uint8( (y + r_add) >> SCALEBITS );
308 *g = vlc_uint8( (y + g_add) >> SCALEBITS );
309 *b = vlc_uint8( (y + b_add) >> SCALEBITS );
315 static inline void rgb_to_yuv( uint8_t *y, uint8_t *u, uint8_t *v,
316 int r, int g, int b )
318 *y = ( ( ( 66 * r + 129 * g + 25 * b + 128 ) >> 8 ) + 16 );
319 *u = ( ( -38 * r - 74 * g + 112 * b + 128 ) >> 8 ) + 128 ;
320 *v = ( ( 112 * r - 94 * g - 18 * b + 128 ) >> 8 ) + 128 ;
323 static uint8_t *vlc_plane_start( int *pi_pitch,
324 picture_t *p_picture,
326 int i_x_offset, int i_y_offset,
327 const video_format_t *p_fmt,
330 const int i_pitch = p_picture->p[i_plane].i_pitch;
331 uint8_t *p_pixels = p_picture->p[i_plane].p_pixels;
333 const int i_dx = ( i_x_offset + p_fmt->i_x_offset ) / r;
334 const int i_dy = ( i_y_offset + p_fmt->i_y_offset ) / r;
338 return &p_pixels[ i_dy * i_pitch + i_dx ];
341 static void vlc_yuv_packed_index( int *pi_y, int *pi_u, int *pi_v, vlc_fourcc_t i_chroma )
343 static const struct {
347 { FCC_YUY2, 0, 1, 3 },
348 { FCC_UYVY, 1, 0, 2 },
349 { FCC_YVYU, 0, 3, 1 },
354 for( i = 0; p_index[i].chroma != 0; i++ )
356 if( p_index[i].chroma == i_chroma )
359 *pi_y = p_index[i].y;
360 *pi_u = p_index[i].u;
361 *pi_v = p_index[i].v;
364 static void vlc_blend_packed( uint8_t *p_dst, const uint8_t *p_src,
365 int i_offset0, int i_offset1, int i_offset2,
366 int c0, int c1, int c2, int i_alpha,
369 p_dst[i_offset0] = vlc_blend( c0, p_src[i_offset0], i_alpha );
372 p_dst[i_offset1] = vlc_blend( c1, p_src[i_offset1], i_alpha );
373 p_dst[i_offset2] = vlc_blend( c2, p_src[i_offset2], i_alpha );
377 static void vlc_blend_rgb16( uint16_t *p_dst, const uint16_t *p_src,
378 int R, int G, int B, int i_alpha,
379 const video_format_t *p_fmt )
381 const int i_pix = *p_src;
382 const int r = ( i_pix & p_fmt->i_rmask ) >> p_fmt->i_lrshift;
383 const int g = ( i_pix & p_fmt->i_gmask ) >> p_fmt->i_lgshift;
384 const int b = ( i_pix & p_fmt->i_bmask ) >> p_fmt->i_lbshift;
386 *p_dst = ( vlc_blend( R >> p_fmt->i_rrshift, r, i_alpha ) << p_fmt->i_lrshift ) |
387 ( vlc_blend( G >> p_fmt->i_rgshift, g, i_alpha ) << p_fmt->i_lgshift ) |
388 ( vlc_blend( B >> p_fmt->i_rbshift, b, i_alpha ) << p_fmt->i_lbshift );
391 static void vlc_rgb_index( int *pi_rindex, int *pi_gindex, int *pi_bindex,
392 const video_format_t *p_fmt )
394 if( p_fmt->i_chroma != FCC_RV24 && p_fmt->i_chroma != FCC_RV32 )
397 /* XXX it will works only if mask are 8 bits aligned */
398 #ifdef WORDS_BIGENDIAN
399 const int i_mask_bits = p_fmt->i_chroma == FCC_RV24 ? 24 : 32;
400 *pi_rindex = ( i_mask_bits - p_fmt->i_lrshift ) / 8;
401 *pi_gindex = ( i_mask_bits - p_fmt->i_lgshift ) / 8;
402 *pi_bindex = ( i_mask_bits - p_fmt->i_lbshift ) / 8;
404 *pi_rindex = p_fmt->i_lrshift / 8;
405 *pi_gindex = p_fmt->i_lgshift / 8;
406 *pi_bindex = p_fmt->i_lbshift / 8;
410 /***********************************************************************
412 ***********************************************************************/
413 static void BlendYUVAI420( filter_t *p_filter, picture_t *p_dst,
414 picture_t *p_dst_orig, picture_t *p_src,
415 int i_x_offset, int i_y_offset,
416 int i_width, int i_height, int i_alpha )
418 int i_src1_pitch, i_src2_pitch, i_dst_pitch;
419 uint8_t *p_src1_y, *p_src2_y, *p_dst_y;
420 uint8_t *p_src1_u, *p_src2_u, *p_dst_u;
421 uint8_t *p_src1_v, *p_src2_v, *p_dst_v;
423 int i_x, i_y, i_trans = 0;
424 bool b_even_scanline = i_y_offset % 2;
426 p_dst_y = vlc_plane_start( &i_dst_pitch, p_dst, Y_PLANE,
427 i_x_offset, i_y_offset, &p_filter->fmt_out.video, 1 );
428 p_dst_u = vlc_plane_start( NULL, p_dst, U_PLANE,
429 i_x_offset, i_y_offset, &p_filter->fmt_out.video, 2 );
430 p_dst_v = vlc_plane_start( NULL, p_dst, V_PLANE,
431 i_x_offset, i_y_offset, &p_filter->fmt_out.video, 2 );
433 p_src1_y = vlc_plane_start( &i_src1_pitch, p_dst_orig, Y_PLANE,
434 i_x_offset, i_y_offset, &p_filter->fmt_out.video, 1 );
435 p_src1_u = vlc_plane_start( NULL, p_dst_orig, U_PLANE,
436 i_x_offset, i_y_offset, &p_filter->fmt_out.video, 2 );
437 p_src1_v = vlc_plane_start( NULL, p_dst_orig, V_PLANE,
438 i_x_offset, i_y_offset, &p_filter->fmt_out.video, 2 );
440 p_src2_y = vlc_plane_start( &i_src2_pitch, p_src, Y_PLANE,
441 0, 0, &p_filter->fmt_in.video, 1 );
442 p_src2_u = vlc_plane_start( NULL, p_src, U_PLANE,
443 0, 0, &p_filter->fmt_in.video, 2 );
444 p_src2_v = vlc_plane_start( NULL, p_src, V_PLANE,
445 0, 0, &p_filter->fmt_in.video, 2 );
446 p_trans = vlc_plane_start( NULL, p_src, A_PLANE,
447 0, 0, &p_filter->fmt_in.video, 1 );
449 /* Draw until we reach the bottom of the subtitle */
450 for( i_y = 0; i_y < i_height; i_y++, p_trans += i_src2_pitch,
451 p_dst_y += i_dst_pitch, p_src1_y += i_src1_pitch,
452 p_src2_y += i_src2_pitch,
453 p_dst_u += b_even_scanline ? i_dst_pitch/2 : 0,
454 p_src1_u += b_even_scanline ? i_src1_pitch/2 : 0,
455 p_src2_u += i_src2_pitch,
456 p_dst_v += b_even_scanline ? i_dst_pitch/2 : 0,
457 p_src1_v += b_even_scanline ? i_src1_pitch/2 : 0,
458 p_src2_v += i_src2_pitch )
460 b_even_scanline = !b_even_scanline;
462 /* Draw until we reach the end of the line */
463 for( i_x = 0; i_x < i_width; i_x++ )
466 i_trans = vlc_alpha( p_trans[i_x], i_alpha );
472 p_dst_y[i_x] = vlc_blend( p_src2_y[i_x], p_src1_y[i_x], i_trans );
473 if( b_even_scanline && i_x % 2 == 0 )
475 p_dst_u[i_x/2] = vlc_blend( p_src2_u[i_x], p_src1_u[i_x/2], i_trans );
476 p_dst_v[i_x/2] = vlc_blend( p_src2_v[i_x], p_src1_v[i_x/2], i_trans );
482 static void BlendYUVARV16( filter_t *p_filter, picture_t *p_dst_pic,
483 picture_t *p_dst_orig, picture_t *p_src,
484 int i_x_offset, int i_y_offset,
485 int i_width, int i_height, int i_alpha )
487 int i_src1_pitch, i_src2_pitch, i_dst_pitch;
488 uint8_t *p_dst, *p_src1, *p_src2_y;
489 uint8_t *p_src2_u, *p_src2_v;
491 int i_x, i_y, i_pix_pitch, i_trans = 0;
494 i_pix_pitch = p_dst_pic->p->i_pixel_pitch;
495 i_dst_pitch = p_dst_pic->p->i_pitch;
496 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
497 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
498 p_dst_pic->p->i_pitch *
499 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
501 i_src1_pitch = p_dst_orig->p[Y_PLANE].i_pitch;
502 p_src1 = p_dst_orig->p->p_pixels + i_x_offset * i_pix_pitch +
503 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
504 p_dst_orig->p->i_pitch *
505 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
507 p_src2_y = vlc_plane_start( &i_src2_pitch, p_src, Y_PLANE,
508 0, 0, &p_filter->fmt_in.video, 1 );
509 p_src2_u = vlc_plane_start( NULL, p_src, U_PLANE,
510 0, 0, &p_filter->fmt_in.video, 2 );
511 p_src2_v = vlc_plane_start( NULL, p_src, V_PLANE,
512 0, 0, &p_filter->fmt_in.video, 2 );
513 p_trans = vlc_plane_start( NULL, p_src, A_PLANE,
514 0, 0, &p_filter->fmt_in.video, 1 );
516 /* Draw until we reach the bottom of the subtitle */
517 for( i_y = 0; i_y < i_height; i_y++, p_trans += i_src2_pitch,
518 p_dst += i_dst_pitch, p_src1 += i_src1_pitch,
519 p_src2_y += i_src2_pitch, p_src2_u += i_src2_pitch,
520 p_src2_v += i_src2_pitch )
522 /* Draw until we reach the end of the line */
523 for( i_x = 0; i_x < i_width; i_x++ )
526 i_trans = vlc_alpha( p_trans[i_x], i_alpha );
531 yuv_to_rgb( &r, &g, &b,
532 p_src2_y[i_x], p_src2_u[i_x], p_src2_v[i_x] );
534 vlc_blend_rgb16( (uint16_t*)&p_dst[i_x * i_pix_pitch],
535 (const uint16_t*)&p_src1[i_x * i_pix_pitch],
536 r, g, b, i_trans, &p_filter->fmt_out.video );
541 static void BlendYUVARV24( filter_t *p_filter, picture_t *p_dst_pic,
542 picture_t *p_dst_orig, picture_t *p_src,
543 int i_x_offset, int i_y_offset,
544 int i_width, int i_height, int i_alpha )
546 int i_src1_pitch, i_src2_pitch, i_dst_pitch;
547 uint8_t *p_dst, *p_src1, *p_src2_y;
548 uint8_t *p_src2_u, *p_src2_v;
550 int i_x, i_y, i_pix_pitch, i_trans = 0;
553 i_pix_pitch = p_dst_pic->p->i_pixel_pitch;
554 i_dst_pitch = p_dst_pic->p->i_pitch;
555 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
556 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
557 p_dst_pic->p->i_pitch *
558 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
560 i_src1_pitch = p_dst_orig->p->i_pitch;
561 p_src1 = p_dst_orig->p->p_pixels + i_x_offset * i_pix_pitch +
562 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
563 p_dst_orig->p->i_pitch *
564 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
566 p_src2_y = vlc_plane_start( &i_src2_pitch, p_src, Y_PLANE,
567 0, 0, &p_filter->fmt_in.video, 1 );
568 p_src2_u = vlc_plane_start( NULL, p_src, U_PLANE,
569 0, 0, &p_filter->fmt_in.video, 2 );
570 p_src2_v = vlc_plane_start( NULL, p_src, V_PLANE,
571 0, 0, &p_filter->fmt_in.video, 2 );
572 p_trans = vlc_plane_start( NULL, p_src, A_PLANE,
573 0, 0, &p_filter->fmt_in.video, 1 );
575 if( (i_pix_pitch == 4)
576 && (((((intptr_t)p_dst)|((intptr_t)p_src1)|i_dst_pitch|i_src1_pitch)
580 ** if picture pixels are 32 bits long and lines addresses are 32 bit
581 ** aligned, optimize rendering
583 uint32_t *p32_dst = (uint32_t *)p_dst;
584 uint32_t i32_dst_pitch = (uint32_t)(i_dst_pitch>>2);
585 uint32_t *p32_src1 = (uint32_t *)p_src1;
586 uint32_t i32_src1_pitch = (uint32_t)(i_src1_pitch>>2);
588 int i_rshift, i_gshift, i_bshift;
589 uint32_t i_rmask, i_gmask, i_bmask;
591 i_rmask = p_filter->fmt_out.video.i_rmask;
592 i_gmask = p_filter->fmt_out.video.i_gmask;
593 i_bmask = p_filter->fmt_out.video.i_bmask;
594 i_rshift = p_filter->fmt_out.video.i_lrshift;
595 i_gshift = p_filter->fmt_out.video.i_lgshift;
596 i_bshift = p_filter->fmt_out.video.i_lbshift;
598 /* Draw until we reach the bottom of the subtitle */
599 for( i_y = 0; i_y < i_height; i_y++, p_trans += i_src2_pitch,
600 p32_dst += i32_dst_pitch, p32_src1 += i32_src1_pitch,
601 p_src2_y += i_src2_pitch, p_src2_u += i_src2_pitch,
602 p_src2_v += i_src2_pitch )
604 /* Draw until we reach the end of the line */
605 for( i_x = 0; i_x < i_width; i_x++ )
608 i_trans = vlc_alpha( p_trans[i_x], i_alpha );
612 if( i_trans == MAX_TRANS )
614 /* Completely opaque. Completely overwrite underlying pixel */
615 yuv_to_rgb( &r, &g, &b,
616 p_src2_y[i_x], p_src2_u[i_x], p_src2_v[i_x] );
618 p32_dst[i_x] = (r<<i_rshift) |
625 uint32_t i_pix_src1 = p32_src1[i_x];
626 yuv_to_rgb( &r, &g, &b,
627 p_src2_y[i_x], p_src2_u[i_x], p_src2_v[i_x] );
629 p32_dst[i_x] = ( vlc_blend( r, (i_pix_src1 & i_rmask)>>i_rshift, i_trans ) << i_rshift ) |
630 ( vlc_blend( g, (i_pix_src1 & i_gmask)>>i_gshift, i_trans ) << i_gshift ) |
631 ( vlc_blend( b, (i_pix_src1 & i_bmask)>>i_bshift, i_trans ) << i_bshift );
638 int i_rindex, i_gindex, i_bindex;
639 uint32_t i_rmask, i_gmask, i_bmask;
641 i_rmask = p_filter->fmt_out.video.i_rmask;
642 i_gmask = p_filter->fmt_out.video.i_gmask;
643 i_bmask = p_filter->fmt_out.video.i_bmask;
645 vlc_rgb_index( &i_rindex, &i_gindex, &i_bindex, &p_filter->fmt_out.video );
647 /* Draw until we reach the bottom of the subtitle */
648 for( i_y = 0; i_y < i_height; i_y++, p_trans += i_src2_pitch,
649 p_dst += i_dst_pitch, p_src1 += i_src1_pitch,
650 p_src2_y += i_src2_pitch, p_src2_u += i_src2_pitch,
651 p_src2_v += i_src2_pitch )
653 /* Draw until we reach the end of the line */
654 for( i_x = 0; i_x < i_width; i_x++ )
657 i_trans = vlc_alpha( p_trans[i_x], i_alpha );
662 yuv_to_rgb( &r, &g, &b,
663 p_src2_y[i_x], p_src2_u[i_x], p_src2_v[i_x] );
665 vlc_blend_packed( &p_dst[ i_x * i_pix_pitch],
666 &p_src1[i_x * i_pix_pitch],
667 i_rindex, i_gindex, i_bindex,
668 r, g, b, i_alpha, true );
674 static void BlendYUVAYUVPacked( filter_t *p_filter, picture_t *p_dst_pic,
675 picture_t *p_dst_orig, picture_t *p_src,
676 int i_x_offset, int i_y_offset,
677 int i_width, int i_height, int i_alpha )
679 int i_src1_pitch, i_src2_pitch, i_dst_pitch;
680 uint8_t *p_dst, *p_src1, *p_src2_y;
681 uint8_t *p_src2_u, *p_src2_v;
683 int i_x, i_y, i_pix_pitch, i_trans = 0;
684 bool b_even = !((i_x_offset + p_filter->fmt_out.video.i_x_offset)%2);
685 int i_l_offset, i_u_offset, i_v_offset;
687 vlc_yuv_packed_index( &i_l_offset, &i_u_offset, &i_v_offset,
688 p_filter->fmt_out.video.i_chroma );
691 i_dst_pitch = p_dst_pic->p->i_pitch;
692 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
693 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
694 p_dst_pic->p->i_pitch *
695 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
697 i_src1_pitch = p_dst_orig->p[Y_PLANE].i_pitch;
698 p_src1 = p_dst_orig->p->p_pixels + i_x_offset * i_pix_pitch +
699 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
700 p_dst_orig->p->i_pitch *
701 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
703 p_src2_y = vlc_plane_start( &i_src2_pitch, p_src, Y_PLANE,
704 0, 0, &p_filter->fmt_in.video, 1 );
705 p_src2_u = vlc_plane_start( NULL, p_src, U_PLANE,
706 0, 0, &p_filter->fmt_in.video, 2 );
707 p_src2_v = vlc_plane_start( NULL, p_src, V_PLANE,
708 0, 0, &p_filter->fmt_in.video, 2 );
709 p_trans = vlc_plane_start( NULL, p_src, A_PLANE,
710 0, 0, &p_filter->fmt_in.video, 1 );
712 i_width &= ~1; /* Needs to be a multiple of 2 */
714 /* Draw until we reach the bottom of the subtitle */
715 for( i_y = 0; i_y < i_height; i_y++, p_trans += i_src2_pitch,
716 p_dst += i_dst_pitch, p_src1 += i_src1_pitch,
717 p_src2_y += i_src2_pitch, p_src2_u += i_src2_pitch,
718 p_src2_v += i_src2_pitch )
720 /* Draw until we reach the end of the line */
721 for( i_x = 0; i_x < i_width; i_x++, b_even = !b_even )
723 i_trans = vlc_alpha( p_trans[i_x], i_alpha );
732 /* FIXME what's with 0xaa ? */
733 if( p_trans[i_x+1] > 0xaa )
735 i_u = (p_src2_u[i_x]+p_src2_u[i_x+1])>>1;
736 i_v = (p_src2_v[i_x]+p_src2_v[i_x+1])>>1;
744 vlc_blend_packed( &p_dst[i_x * 2], &p_src1[i_x * 2],
745 i_l_offset, i_u_offset, i_v_offset,
746 p_src2_y[i_x], i_u, i_v, i_trans, true );
750 p_dst[i_x * 2 + i_l_offset] = vlc_blend( p_src2_y[i_x], p_src1[i_x * 2 + i_l_offset], i_trans );
755 /***********************************************************************
757 ***********************************************************************/
758 static void BlendI420I420( filter_t *p_filter, picture_t *p_dst,
759 picture_t *p_dst_orig, picture_t *p_src,
760 int i_x_offset, int i_y_offset,
761 int i_width, int i_height, int i_alpha )
763 int i_src1_pitch, i_src2_pitch, i_dst_pitch;
764 uint8_t *p_src1_y, *p_src2_y, *p_dst_y;
765 uint8_t *p_src1_u, *p_src2_u, *p_dst_u;
766 uint8_t *p_src1_v, *p_src2_v, *p_dst_v;
768 bool b_even_scanline = i_y_offset % 2;
770 if( i_alpha == 0xff )
772 BlendI420I420_no_alpha( p_filter, p_dst, p_dst_orig, p_src,
773 i_x_offset, i_y_offset, i_width, i_height );
778 i_dst_pitch = p_dst->p[Y_PLANE].i_pitch;
779 p_dst_y = p_dst->p[Y_PLANE].p_pixels + i_x_offset +
780 p_filter->fmt_out.video.i_x_offset +
781 p_dst->p[Y_PLANE].i_pitch *
782 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
783 p_dst_u = p_dst->p[U_PLANE].p_pixels + i_x_offset/2 +
784 p_filter->fmt_out.video.i_x_offset/2 +
785 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
786 p_dst->p[U_PLANE].i_pitch;
787 p_dst_v = p_dst->p[V_PLANE].p_pixels + i_x_offset/2 +
788 p_filter->fmt_out.video.i_x_offset/2 +
789 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
790 p_dst->p[V_PLANE].i_pitch;
792 i_src1_pitch = p_dst_orig->p[Y_PLANE].i_pitch;
793 p_src1_y = p_dst_orig->p[Y_PLANE].p_pixels + i_x_offset +
794 p_filter->fmt_out.video.i_x_offset +
795 p_dst_orig->p[Y_PLANE].i_pitch *
796 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
797 p_src1_u = p_dst_orig->p[U_PLANE].p_pixels + i_x_offset/2 +
798 p_filter->fmt_out.video.i_x_offset/2 +
799 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
800 p_dst_orig->p[U_PLANE].i_pitch;
801 p_src1_v = p_dst_orig->p[V_PLANE].p_pixels + i_x_offset/2 +
802 p_filter->fmt_out.video.i_x_offset/2 +
803 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
804 p_dst_orig->p[V_PLANE].i_pitch;
806 p_src2_y = vlc_plane_start( &i_src2_pitch, p_src, Y_PLANE,
807 0, 0, &p_filter->fmt_in.video, 1 );
808 p_src2_u = vlc_plane_start( NULL, p_src, U_PLANE,
809 0, 0, &p_filter->fmt_in.video, 2 );
810 p_src2_v = vlc_plane_start( NULL, p_src, V_PLANE,
811 0, 0, &p_filter->fmt_in.video, 2 );
814 /* Draw until we reach the bottom of the subtitle */
815 for( i_y = 0; i_y < i_height; i_y++,
816 p_dst_y += i_dst_pitch, p_src1_y += i_src1_pitch,
817 p_src2_y += i_src2_pitch )
819 if( b_even_scanline )
821 p_dst_u += i_dst_pitch/2;
822 p_dst_v += i_dst_pitch/2;
823 p_src1_u += i_src1_pitch/2;
824 p_src1_v += i_src1_pitch/2;
826 b_even_scanline = !b_even_scanline;
828 /* Draw until we reach the end of the line */
829 for( i_x = 0; i_x < i_width; i_x++ )
835 p_dst_y[i_x] = vlc_blend( p_src2_y[i_x], p_src1_y[i_x], i_alpha );
836 if( b_even_scanline && i_x % 2 == 0 )
838 p_dst_u[i_x/2] = vlc_blend( p_src2_u[i_x/2], p_src1_u[i_x/2], i_alpha );
839 p_dst_v[i_x/2] = vlc_blend( p_src2_v[i_x/2], p_src1_v[i_x/2], i_alpha );
844 p_src2_u += i_src2_pitch/2;
845 p_src2_v += i_src2_pitch/2;
849 static void BlendI420I420_no_alpha( filter_t *p_filter, picture_t *p_dst,
850 picture_t *p_dst_orig, picture_t *p_src,
851 int i_x_offset, int i_y_offset,
852 int i_width, int i_height )
854 int i_src2_pitch, i_dst_pitch;
855 uint8_t *p_src2_y, *p_dst_y;
856 uint8_t *p_src2_u, *p_dst_u;
857 uint8_t *p_src2_v, *p_dst_v;
859 bool b_even_scanline = i_y_offset % 2;
861 i_dst_pitch = p_dst->p[Y_PLANE].i_pitch;
862 p_dst_y = p_dst->p[Y_PLANE].p_pixels + i_x_offset +
863 p_filter->fmt_out.video.i_x_offset +
864 p_dst->p[Y_PLANE].i_pitch *
865 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
866 p_dst_u = p_dst->p[U_PLANE].p_pixels + i_x_offset/2 +
867 p_filter->fmt_out.video.i_x_offset/2 +
868 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
869 p_dst->p[U_PLANE].i_pitch;
870 p_dst_v = p_dst->p[V_PLANE].p_pixels + i_x_offset/2 +
871 p_filter->fmt_out.video.i_x_offset/2 +
872 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
873 p_dst->p[V_PLANE].i_pitch;
875 p_src2_y = vlc_plane_start( &i_src2_pitch, p_src, Y_PLANE,
876 0, 0, &p_filter->fmt_in.video, 1 );
877 p_src2_u = vlc_plane_start( NULL, p_src, U_PLANE,
878 0, 0, &p_filter->fmt_in.video, 2 );
879 p_src2_v = vlc_plane_start( NULL, p_src, V_PLANE,
880 0, 0, &p_filter->fmt_in.video, 2 );
884 /* Draw until we reach the bottom of the subtitle */
885 for( i_y = 0; i_y < i_height;
886 i_y++, p_dst_y += i_dst_pitch, p_src2_y += i_src2_pitch )
888 /* Completely opaque. Completely overwrite underlying pixel */
889 vlc_memcpy( p_dst_y, p_src2_y, i_width );
890 if( b_even_scanline )
892 p_dst_u += i_dst_pitch/2;
893 p_dst_v += i_dst_pitch/2;
897 vlc_memcpy( p_dst_u, p_src2_u, i_width/2 );
898 vlc_memcpy( p_dst_v, p_src2_v, i_width/2 );
900 b_even_scanline = !b_even_scanline;
903 p_src2_u += i_src2_pitch/2;
904 p_src2_v += i_src2_pitch/2;
909 static void BlendI420R16( filter_t *p_filter, picture_t *p_dst_pic,
910 picture_t *p_dst_orig, picture_t *p_src,
911 int i_x_offset, int i_y_offset,
912 int i_width, int i_height, int i_alpha )
914 int i_src1_pitch, i_src2_pitch, i_dst_pitch;
915 uint8_t *p_dst, *p_src1, *p_src2_y;
916 uint8_t *p_src2_u, *p_src2_v;
917 int i_x, i_y, i_pix_pitch;
920 i_pix_pitch = p_dst_pic->p->i_pixel_pitch;
921 i_dst_pitch = p_dst_pic->p->i_pitch;
922 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
923 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
924 p_dst_pic->p->i_pitch *
925 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
927 i_src1_pitch = p_dst_orig->p[Y_PLANE].i_pitch;
928 p_src1 = p_dst_orig->p->p_pixels + i_x_offset * i_pix_pitch +
929 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
930 p_dst_orig->p->i_pitch *
931 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
933 p_src2_y = vlc_plane_start( &i_src2_pitch, p_src, Y_PLANE,
934 0, 0, &p_filter->fmt_in.video, 1 );
935 p_src2_u = vlc_plane_start( NULL, p_src, U_PLANE,
936 0, 0, &p_filter->fmt_in.video, 2 );
937 p_src2_v = vlc_plane_start( NULL, p_src, V_PLANE,
938 0, 0, &p_filter->fmt_in.video, 2 );
940 /* Draw until we reach the bottom of the subtitle */
941 for( i_y = 0; i_y < i_height; i_y++,
942 p_dst += i_dst_pitch, p_src1 += i_src1_pitch,
943 p_src2_y += i_src2_pitch )
945 /* Draw until we reach the end of the line */
946 for( i_x = 0; i_x < i_width; i_x++ )
949 yuv_to_rgb( &r, &g, &b,
950 p_src2_y[i_x], p_src2_u[i_x/2], p_src2_v[i_x/2] );
952 vlc_blend_rgb16( (uint16_t*)&p_dst[i_x * i_pix_pitch],
953 (const uint16_t*)&p_src1[i_x * i_pix_pitch],
954 r, g, b, 0xff, &p_filter->fmt_out.video );
958 p_src2_u += i_src2_pitch/2;
959 p_src2_v += i_src2_pitch/2;
964 static void BlendI420R24( filter_t *p_filter, picture_t *p_dst_pic,
965 picture_t *p_dst_orig, picture_t *p_src,
966 int i_x_offset, int i_y_offset,
967 int i_width, int i_height, int i_alpha )
969 int i_src1_pitch, i_src2_pitch, i_dst_pitch;
970 uint8_t *p_dst, *p_src1, *p_src2_y;
971 uint8_t *p_src2_u, *p_src2_v;
972 int i_x, i_y, i_pix_pitch;
973 int i_rindex, i_gindex, i_bindex;
976 i_pix_pitch = p_dst_pic->p->i_pixel_pitch;
977 i_dst_pitch = p_dst_pic->p->i_pitch;
978 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
979 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
980 p_dst_pic->p->i_pitch *
981 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
983 i_src1_pitch = p_dst_orig->p[Y_PLANE].i_pitch;
984 p_src1 = p_dst_orig->p->p_pixels + i_x_offset * i_pix_pitch +
985 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
986 p_dst_orig->p->i_pitch *
987 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
989 p_src2_y = vlc_plane_start( &i_src2_pitch, p_src, Y_PLANE,
990 0, 0, &p_filter->fmt_in.video, 1 );
991 p_src2_u = vlc_plane_start( NULL, p_src, U_PLANE,
992 0, 0, &p_filter->fmt_in.video, 2 );
993 p_src2_v = vlc_plane_start( NULL, p_src, V_PLANE,
994 0, 0, &p_filter->fmt_in.video, 2 );
996 vlc_rgb_index( &i_rindex, &i_gindex, &i_bindex, &p_filter->fmt_out.video );
998 /* Draw until we reach the bottom of the subtitle */
999 for( i_y = 0; i_y < i_height; i_y++,
1000 p_dst += i_dst_pitch, p_src1 += i_src1_pitch,
1001 p_src2_y += i_src2_pitch, p_src2_u += i_src2_pitch,
1002 p_src2_v += i_src2_pitch )
1004 /* Draw until we reach the end of the line */
1005 for( i_x = 0; i_x < i_width; i_x++ )
1011 yuv_to_rgb( &r, &g, &b,
1012 p_src2_y[i_x], p_src2_u[i_x/2], p_src2_v[i_x/2] );
1014 vlc_blend_packed( &p_dst[i_x * i_pix_pitch], &p_src1[i_x * i_pix_pitch],
1015 i_rindex, i_gindex, i_bindex, r, g, b, i_alpha, true );
1019 p_src2_u += i_src2_pitch/2;
1020 p_src2_v += i_src2_pitch/2;
1025 static void BlendI420YUVPacked( filter_t *p_filter, picture_t *p_dst_pic,
1026 picture_t *p_dst_orig, picture_t *p_src,
1027 int i_x_offset, int i_y_offset,
1028 int i_width, int i_height, int i_alpha )
1030 int i_src1_pitch, i_src2_pitch, i_dst_pitch;
1031 uint8_t *p_dst, *p_src1, *p_src2_y;
1032 uint8_t *p_src2_u, *p_src2_v;
1033 int i_x, i_y, i_pix_pitch;
1034 bool b_even = !((i_x_offset + p_filter->fmt_out.video.i_x_offset)%2);
1035 int i_l_offset, i_u_offset, i_v_offset;
1037 vlc_yuv_packed_index( &i_l_offset, &i_u_offset, &i_v_offset,
1038 p_filter->fmt_out.video.i_chroma );
1041 i_dst_pitch = p_dst_pic->p->i_pitch;
1042 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
1043 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
1044 p_dst_pic->p->i_pitch *
1045 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1047 i_src1_pitch = p_dst_orig->p[Y_PLANE].i_pitch;
1048 p_src1 = p_dst_orig->p->p_pixels + i_x_offset * i_pix_pitch +
1049 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
1050 p_dst_orig->p->i_pitch *
1051 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1053 p_src2_y = vlc_plane_start( &i_src2_pitch, p_src, Y_PLANE,
1054 0, 0, &p_filter->fmt_in.video, 1 );
1055 p_src2_u = vlc_plane_start( NULL, p_src, U_PLANE,
1056 0, 0, &p_filter->fmt_in.video, 2 );
1057 p_src2_v = vlc_plane_start( NULL, p_src, V_PLANE,
1058 0, 0, &p_filter->fmt_in.video, 2 );
1060 i_width &= ~1; /* Needs to be a multiple of 2 */
1062 /* Draw until we reach the bottom of the subtitle */
1063 for( i_y = 0; i_y < i_height; i_y++,
1064 p_dst += i_dst_pitch, p_src1 += i_src1_pitch,
1065 p_src2_y += i_src2_pitch, p_src2_u += i_src2_pitch,
1066 p_src2_v += i_src2_pitch )
1068 /* Draw until we reach the end of the line */
1069 for( i_x = 0; i_x < i_width; i_x++, b_even = !b_even )
1075 vlc_blend_packed( &p_dst[i_x * 2], &p_src1[i_x * 2],
1076 i_l_offset, i_u_offset, i_v_offset,
1077 p_src2_y[i_x], p_src2_u[i_x/2], p_src2_v[i_x/2], i_alpha, b_even );
1081 p_src2_u += i_src2_pitch/2;
1082 p_src2_v += i_src2_pitch/2;
1087 /***********************************************************************
1089 ***********************************************************************/
1090 static void BlendPalI420( filter_t *p_filter, picture_t *p_dst,
1091 picture_t *p_dst_orig, picture_t *p_src,
1092 int i_x_offset, int i_y_offset,
1093 int i_width, int i_height, int i_alpha )
1095 int i_src1_pitch, i_src2_pitch, i_dst_pitch;
1096 uint8_t *p_src1_y, *p_src2, *p_dst_y;
1097 uint8_t *p_src1_u, *p_dst_u;
1098 uint8_t *p_src1_v, *p_dst_v;
1099 int i_x, i_y, i_trans;
1100 bool b_even_scanline = i_y_offset % 2;
1102 i_dst_pitch = p_dst->p[Y_PLANE].i_pitch;
1103 p_dst_y = p_dst->p[Y_PLANE].p_pixels + i_x_offset +
1104 p_filter->fmt_out.video.i_x_offset +
1105 p_dst->p[Y_PLANE].i_pitch *
1106 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1107 p_dst_u = p_dst->p[U_PLANE].p_pixels + i_x_offset/2 +
1108 p_filter->fmt_out.video.i_x_offset/2 +
1109 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
1110 p_dst->p[U_PLANE].i_pitch;
1111 p_dst_v = p_dst->p[V_PLANE].p_pixels + i_x_offset/2 +
1112 p_filter->fmt_out.video.i_x_offset/2 +
1113 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
1114 p_dst->p[V_PLANE].i_pitch;
1116 i_src1_pitch = p_dst_orig->p[Y_PLANE].i_pitch;
1117 p_src1_y = p_dst_orig->p[Y_PLANE].p_pixels + i_x_offset +
1118 p_filter->fmt_out.video.i_x_offset +
1119 p_dst_orig->p[Y_PLANE].i_pitch *
1120 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1121 p_src1_u = p_dst_orig->p[U_PLANE].p_pixels + i_x_offset/2 +
1122 p_filter->fmt_out.video.i_x_offset/2 +
1123 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
1124 p_dst_orig->p[U_PLANE].i_pitch;
1125 p_src1_v = p_dst_orig->p[V_PLANE].p_pixels + i_x_offset/2 +
1126 p_filter->fmt_out.video.i_x_offset/2 +
1127 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
1128 p_dst_orig->p[V_PLANE].i_pitch;
1130 i_src2_pitch = p_src->p->i_pitch;
1131 p_src2 = p_src->p->p_pixels + p_filter->fmt_in.video.i_x_offset +
1132 i_src2_pitch * p_filter->fmt_in.video.i_y_offset;
1134 const uint8_t *p_trans = p_src2;
1135 #define p_pal p_filter->fmt_in.video.p_palette->palette
1137 /* Draw until we reach the bottom of the subtitle */
1138 for( i_y = 0; i_y < i_height; i_y++,
1139 p_dst_y += i_dst_pitch, p_src1_y += i_src1_pitch,
1140 p_src2 += i_src2_pitch,
1141 p_dst_u += b_even_scanline ? i_dst_pitch/2 : 0,
1142 p_src1_u += b_even_scanline ? i_src1_pitch/2 : 0,
1143 p_dst_v += b_even_scanline ? i_dst_pitch/2 : 0,
1144 p_src1_v += b_even_scanline ? i_src1_pitch/2 : 0 )
1146 b_even_scanline = !b_even_scanline;
1148 /* Draw until we reach the end of the line */
1149 for( i_x = 0; i_x < i_width; i_x++ )
1151 i_trans = vlc_alpha( p_pal[p_trans[i_x]][3], i_alpha );
1156 p_dst_y[i_x] = vlc_blend( p_pal[p_src2[i_x]][0], p_src1_y[i_x], i_trans );
1157 if( b_even_scanline && ((i_x % 2) == 0) )
1159 p_dst_u[i_x/2] = vlc_blend( p_pal[p_src2[i_x]][1], p_src1_u[i_x/2], i_trans );
1160 p_dst_v[i_x/2] = vlc_blend( p_pal[p_src2[i_x]][2], p_src1_v[i_x/2], i_trans );
1167 static void BlendPalYUVPacked( filter_t *p_filter, picture_t *p_dst_pic,
1168 picture_t *p_dst_orig, picture_t *p_src,
1169 int i_x_offset, int i_y_offset,
1170 int i_width, int i_height, int i_alpha )
1172 int i_src1_pitch, i_src2_pitch, i_dst_pitch;
1173 uint8_t *p_src1, *p_src2, *p_dst;
1174 int i_x, i_y, i_pix_pitch, i_trans;
1175 bool b_even = !((i_x_offset + p_filter->fmt_out.video.i_x_offset)%2);
1176 int i_l_offset, i_u_offset, i_v_offset;
1178 vlc_yuv_packed_index( &i_l_offset, &i_u_offset, &i_v_offset,
1179 p_filter->fmt_out.video.i_chroma );
1182 i_dst_pitch = p_dst_pic->p->i_pitch;
1183 p_dst = p_dst_pic->p->p_pixels + i_pix_pitch * (i_x_offset +
1184 p_filter->fmt_out.video.i_x_offset) + p_dst_pic->p->i_pitch *
1185 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1187 i_src1_pitch = p_dst_orig->p->i_pitch;
1188 p_src1 = p_dst_orig->p->p_pixels + i_pix_pitch * (i_x_offset +
1189 p_filter->fmt_out.video.i_x_offset) + p_dst_orig->p->i_pitch *
1190 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1192 i_src2_pitch = p_src->p->i_pitch;
1193 p_src2 = p_src->p->p_pixels + p_filter->fmt_in.video.i_x_offset +
1194 i_src2_pitch * p_filter->fmt_in.video.i_y_offset;
1196 i_width &= ~1; /* Needs to be a multiple of 2 */
1198 const uint8_t *p_trans = p_src2;
1199 #define p_pal p_filter->fmt_in.video.p_palette->palette
1201 /* Draw until we reach the bottom of the subtitle */
1202 for( i_y = 0; i_y < i_height; i_y++,
1203 p_dst += i_dst_pitch, p_src1 += i_src1_pitch, p_src2 += i_src2_pitch )
1205 /* Draw until we reach the end of the line */
1206 for( i_x = 0; i_x < i_width; i_x++, b_even = !b_even )
1208 i_trans = vlc_alpha( p_pal[p_trans[i_x]][3], i_alpha );
1217 if( p_trans[i_x+1] > 0xaa )
1219 i_u = (p_pal[p_src2[i_x]][1] + p_pal[p_src2[i_x+1]][1]) >> 1;
1220 i_v = (p_pal[p_src2[i_x]][2] + p_pal[p_src2[i_x+1]][2]) >> 1;
1224 i_u = p_pal[p_src2[i_x]][1];
1225 i_v = p_pal[p_src2[i_x]][2];
1228 vlc_blend_packed( &p_dst[i_x * 2], &p_src1[i_x * 2],
1229 i_l_offset, i_u_offset, i_v_offset,
1230 p_pal[p_src2[i_x]][0], i_u, i_v, i_trans, true );
1234 p_dst[i_x * 2 + i_l_offset] = vlc_blend( p_pal[p_src2[i_x]][0], p_src1[i_x * 2 + i_l_offset], i_trans );
1241 static void BlendPalRV( filter_t *p_filter, picture_t *p_dst_pic,
1242 picture_t *p_dst_orig, picture_t *p_src,
1243 int i_x_offset, int i_y_offset,
1244 int i_width, int i_height, int i_alpha )
1246 int i_src1_pitch, i_src2_pitch, i_dst_pitch;
1247 uint8_t *p_src1, *p_src2, *p_dst;
1248 int i_x, i_y, i_pix_pitch, i_trans;
1250 video_palette_t rgbpalette;
1251 int i_rindex, i_gindex, i_bindex;
1253 i_pix_pitch = p_dst_pic->p->i_pixel_pitch;
1254 i_dst_pitch = p_dst_pic->p->i_pitch;
1255 p_dst = p_dst_pic->p->p_pixels + i_pix_pitch * (i_x_offset +
1256 p_filter->fmt_out.video.i_x_offset) + p_dst_pic->p->i_pitch *
1257 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1259 i_src1_pitch = p_dst_orig->p->i_pitch;
1260 p_src1 = p_dst_orig->p->p_pixels + i_pix_pitch * (i_x_offset +
1261 p_filter->fmt_out.video.i_x_offset) + p_dst_orig->p->i_pitch *
1262 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1264 i_src2_pitch = p_src->p->i_pitch;
1265 p_src2 = p_src->p->p_pixels + p_filter->fmt_in.video.i_x_offset +
1266 i_src2_pitch * p_filter->fmt_in.video.i_y_offset;
1268 const uint8_t *p_trans = p_src2;
1269 #define p_pal p_filter->fmt_in.video.p_palette->palette
1270 #define rgbpal rgbpalette.palette
1272 /* Convert palette first */
1273 for( i_y = 0; i_y < p_filter->fmt_in.video.p_palette->i_entries && i_y < 256; i_y++ )
1275 yuv_to_rgb( &r, &g, &b, p_pal[i_y][0], p_pal[i_y][1], p_pal[i_y][2] );
1276 rgbpal[i_y][0] = r; rgbpal[i_y][1] = g; rgbpal[i_y][2] = b;
1280 vlc_rgb_index( &i_rindex, &i_gindex, &i_bindex, &p_filter->fmt_out.video );
1282 /* Draw until we reach the bottom of the subtitle */
1283 for( i_y = 0; i_y < i_height; i_y++,
1284 p_dst += i_dst_pitch, p_src1 += i_src1_pitch, p_src2 += i_src2_pitch )
1286 /* Draw until we reach the end of the line */
1287 for( i_x = 0; i_x < i_width; i_x++ )
1289 i_trans = vlc_alpha( p_pal[p_trans[i_x]][3], i_alpha );
1294 if( p_filter->fmt_out.video.i_chroma == FCC_RV15 || p_filter->fmt_out.video.i_chroma == FCC_RV16 )
1295 vlc_blend_rgb16( (uint16_t*)&p_dst[i_x * i_pix_pitch],
1296 (const uint16_t*)&p_src1[i_x * i_pix_pitch],
1297 rgbpal[p_src2[i_x]][0], rgbpal[p_src2[i_x]][1], rgbpal[p_src2[i_x]][3],
1299 &p_filter->fmt_out.video );
1301 vlc_blend_packed( &p_dst[i_x * i_pix_pitch], &p_src1[i_x * i_pix_pitch],
1302 i_rindex, i_gindex, i_bindex,
1303 rgbpal[p_src2[i_x]][0], rgbpal[p_src2[i_x]][1], rgbpal[p_src2[i_x]][3],
1312 /***********************************************************************
1314 ***********************************************************************/
1315 static void BlendRGBAI420( filter_t *p_filter, picture_t *p_dst,
1316 picture_t *p_dst_orig, picture_t *p_src,
1317 int i_x_offset, int i_y_offset,
1318 int i_width, int i_height, int i_alpha )
1320 int i_src1_pitch, i_src2_pitch, i_dst_pitch, i_src_pix_pitch;
1321 uint8_t *p_src1_y, *p_dst_y;
1322 uint8_t *p_src1_u, *p_dst_u;
1323 uint8_t *p_src1_v, *p_dst_v;
1325 int i_x, i_y, i_trans;
1328 bool b_even_scanline = i_y_offset % 2;
1330 i_dst_pitch = p_dst->p[Y_PLANE].i_pitch;
1331 p_dst_y = p_dst->p[Y_PLANE].p_pixels + i_x_offset +
1332 p_filter->fmt_out.video.i_x_offset +
1333 p_dst->p[Y_PLANE].i_pitch *
1334 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1335 p_dst_u = p_dst->p[U_PLANE].p_pixels + i_x_offset/2 +
1336 p_filter->fmt_out.video.i_x_offset/2 +
1337 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
1338 p_dst->p[U_PLANE].i_pitch;
1339 p_dst_v = p_dst->p[V_PLANE].p_pixels + i_x_offset/2 +
1340 p_filter->fmt_out.video.i_x_offset/2 +
1341 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
1342 p_dst->p[V_PLANE].i_pitch;
1344 i_src1_pitch = p_dst_orig->p[Y_PLANE].i_pitch;
1345 p_src1_y = p_dst_orig->p[Y_PLANE].p_pixels + i_x_offset +
1346 p_filter->fmt_out.video.i_x_offset +
1347 p_dst_orig->p[Y_PLANE].i_pitch *
1348 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1349 p_src1_u = p_dst_orig->p[U_PLANE].p_pixels + i_x_offset/2 +
1350 p_filter->fmt_out.video.i_x_offset/2 +
1351 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
1352 p_dst_orig->p[U_PLANE].i_pitch;
1353 p_src1_v = p_dst_orig->p[V_PLANE].p_pixels + i_x_offset/2 +
1354 p_filter->fmt_out.video.i_x_offset/2 +
1355 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
1356 p_dst_orig->p[V_PLANE].i_pitch;
1358 i_src_pix_pitch = p_src->p->i_pixel_pitch;
1359 i_src2_pitch = p_src->p->i_pitch;
1360 p_src2 = p_src->p->p_pixels +
1361 p_filter->fmt_in.video.i_x_offset * i_src2_pitch +
1362 p_src->p->i_pitch * p_filter->fmt_in.video.i_y_offset;
1365 /* Draw until we reach the bottom of the subtitle */
1366 for( i_y = 0; i_y < i_height; i_y++,
1367 p_dst_y += i_dst_pitch, p_src1_y += i_src1_pitch,
1368 p_dst_u += b_even_scanline ? i_dst_pitch/2 : 0,
1369 p_src1_u += b_even_scanline ? i_src1_pitch/2 : 0,
1370 p_dst_v += b_even_scanline ? i_dst_pitch/2 : 0,
1371 p_src1_v += b_even_scanline ? i_src1_pitch/2 : 0,
1372 p_src2 += i_src2_pitch )
1374 b_even_scanline = !b_even_scanline;
1376 /* Draw until we reach the end of the line */
1377 for( i_x = 0; i_x < i_width; i_x++ )
1379 const int R = p_src2[i_x * i_src_pix_pitch + 0];
1380 const int G = p_src2[i_x * i_src_pix_pitch + 1];
1381 const int B = p_src2[i_x * i_src_pix_pitch + 2];
1383 i_trans = vlc_alpha( p_src2[i_x * i_src_pix_pitch + 3], i_alpha );
1388 rgb_to_yuv( &y, &u, &v, R, G, B );
1390 p_dst_y[i_x] = vlc_blend( y, p_src1_y[i_x], i_trans );
1391 if( b_even_scanline && i_x % 2 == 0 )
1393 p_dst_u[i_x/2] = vlc_blend( u, p_src1_u[i_x/2], i_trans );
1394 p_dst_v[i_x/2] = vlc_blend( v, p_src1_v[i_x/2], i_trans );
1400 static void BlendRGBAR24( filter_t *p_filter, picture_t *p_dst_pic,
1401 picture_t *p_dst_orig, picture_t *p_src,
1402 int i_x_offset, int i_y_offset,
1403 int i_width, int i_height, int i_alpha )
1405 int i_src1_pitch, i_src2_pitch, i_dst_pitch;
1406 uint8_t *p_dst, *p_src1, *p_src2;
1407 int i_x, i_y, i_pix_pitch, i_trans, i_src_pix_pitch;
1408 int i_rindex, i_gindex, i_bindex;
1410 i_pix_pitch = p_dst_pic->p->i_pixel_pitch;
1411 i_dst_pitch = p_dst_pic->p->i_pitch;
1412 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
1413 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
1414 p_dst_pic->p->i_pitch *
1415 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1417 i_src1_pitch = p_dst_orig->p->i_pitch;
1418 p_src1 = p_dst_orig->p->p_pixels + i_x_offset * i_pix_pitch +
1419 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
1420 p_dst_orig->p->i_pitch *
1421 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1423 i_src_pix_pitch = p_src->p->i_pixel_pitch;
1424 i_src2_pitch = p_src->p->i_pitch;
1425 p_src2 = p_src->p->p_pixels +
1426 p_filter->fmt_in.video.i_x_offset * i_pix_pitch +
1427 p_src->p->i_pitch * p_filter->fmt_in.video.i_y_offset;
1429 vlc_rgb_index( &i_rindex, &i_gindex, &i_bindex, &p_filter->fmt_out.video );
1431 /* Draw until we reach the bottom of the subtitle */
1432 for( i_y = 0; i_y < i_height; i_y++,
1433 p_dst += i_dst_pitch, p_src1 += i_src1_pitch, p_src2 += i_src2_pitch )
1435 /* Draw until we reach the end of the line */
1436 for( i_x = 0; i_x < i_width; i_x++ )
1438 const int R = p_src2[i_x * i_src_pix_pitch + 0];
1439 const int G = p_src2[i_x * i_src_pix_pitch + 1];
1440 const int B = p_src2[i_x * i_src_pix_pitch + 2];
1442 i_trans = vlc_alpha( p_src2[i_x * i_src_pix_pitch + 3], i_alpha );
1447 vlc_blend_packed( &p_dst[i_x * i_pix_pitch], &p_src1[i_x * i_pix_pitch],
1448 i_rindex, i_gindex, i_bindex,
1449 R, G, B, i_trans, true );
1454 static void BlendRGBAR16( filter_t *p_filter, picture_t *p_dst_pic,
1455 picture_t *p_dst_orig, picture_t *p_src,
1456 int i_x_offset, int i_y_offset,
1457 int i_width, int i_height, int i_alpha )
1459 int i_src1_pitch, i_src2_pitch, i_dst_pitch;
1460 uint8_t *p_dst, *p_src1, *p_src2;
1461 int i_x, i_y, i_pix_pitch, i_trans, i_src_pix_pitch;
1463 i_pix_pitch = p_dst_pic->p->i_pixel_pitch;
1464 i_dst_pitch = p_dst_pic->p->i_pitch;
1465 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
1466 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
1467 p_dst_pic->p->i_pitch *
1468 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1470 i_src1_pitch = p_dst_orig->p->i_pitch;
1471 p_src1 = p_dst_orig->p->p_pixels + i_x_offset * i_pix_pitch +
1472 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
1473 p_dst_orig->p->i_pitch *
1474 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1476 i_src_pix_pitch = p_src->p->i_pixel_pitch;
1477 i_src2_pitch = p_src->p->i_pitch;
1478 p_src2 = p_src->p->p_pixels +
1479 p_filter->fmt_in.video.i_x_offset * i_pix_pitch +
1480 p_src->p->i_pitch * p_filter->fmt_in.video.i_y_offset;
1482 /* Draw until we reach the bottom of the subtitle */
1483 for( i_y = 0; i_y < i_height; i_y++,
1484 p_dst += i_dst_pitch, p_src1 += i_src1_pitch, p_src2 += i_src2_pitch )
1486 /* Draw until we reach the end of the line */
1487 for( i_x = 0; i_x < i_width; i_x++ )
1489 const int R = p_src2[i_x * i_src_pix_pitch + 0];
1490 const int G = p_src2[i_x * i_src_pix_pitch + 1];
1491 const int B = p_src2[i_x * i_src_pix_pitch + 2];
1493 i_trans = vlc_alpha( p_src2[i_x * i_src_pix_pitch + 3], i_alpha );
1498 vlc_blend_rgb16( (uint16_t*)&p_dst[i_x * i_pix_pitch],
1499 (const uint16_t*)&p_src1[i_x * i_pix_pitch],
1500 R, G, B, i_trans, &p_filter->fmt_out.video );
1505 static void BlendRGBAYUVPacked( filter_t *p_filter, picture_t *p_dst_pic,
1506 picture_t *p_dst_orig, picture_t *p_src,
1507 int i_x_offset, int i_y_offset,
1508 int i_width, int i_height, int i_alpha )
1510 int i_src1_pitch, i_src2_pitch, i_dst_pitch, i_src_pix_pitch;
1511 uint8_t *p_dst, *p_src1, *p_src2;
1513 int i_x, i_y, i_pix_pitch, i_trans;
1514 bool b_even = !((i_x_offset + p_filter->fmt_out.video.i_x_offset)%2);
1515 int i_l_offset, i_u_offset, i_v_offset;
1518 vlc_yuv_packed_index( &i_l_offset, &i_u_offset, &i_v_offset,
1519 p_filter->fmt_out.video.i_chroma );
1522 i_dst_pitch = p_dst_pic->p->i_pitch;
1523 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
1524 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
1525 p_dst_pic->p->i_pitch *
1526 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1528 i_src1_pitch = p_dst_orig->p[Y_PLANE].i_pitch;
1529 p_src1 = p_dst_orig->p->p_pixels + i_x_offset * i_pix_pitch +
1530 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
1531 p_dst_orig->p->i_pitch *
1532 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1534 i_src_pix_pitch = p_src->p->i_pixel_pitch;
1535 i_src2_pitch = p_src->p->i_pitch;
1536 p_src2 = p_src->p->p_pixels +
1537 p_filter->fmt_in.video.i_x_offset * i_src2_pitch +
1538 p_src->p->i_pitch * p_filter->fmt_in.video.i_y_offset;
1540 i_width &= ~1; /* Needs to be a multiple of 2 */
1542 /* Draw until we reach the bottom of the subtitle */
1543 for( i_y = 0; i_y < i_height; i_y++, p_trans += i_src2_pitch,
1544 p_dst += i_dst_pitch, p_src1 += i_src1_pitch,
1545 p_src2 += i_src2_pitch )
1547 /* Draw until we reach the end of the line */
1548 for( i_x = 0; i_x < i_width; i_x++, b_even = !b_even )
1550 const int R = p_src2[i_x * i_src_pix_pitch + 0];
1551 const int G = p_src2[i_x * i_src_pix_pitch + 1];
1552 const int B = p_src2[i_x * i_src_pix_pitch + 2];
1554 i_trans = vlc_alpha( p_src2[i_x * i_src_pix_pitch + 3], i_alpha );
1559 rgb_to_yuv( &y, &u, &v, R, G, B );
1561 vlc_blend_packed( &p_dst[i_x * 2], &p_src1[i_x * 2],
1562 i_l_offset, i_u_offset, i_v_offset,
1563 y, u, v, i_trans, b_even );