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 VLC_UNUSED(p_dst_orig);
855 int i_src2_pitch, i_dst_pitch;
856 uint8_t *p_src2_y, *p_dst_y;
857 uint8_t *p_src2_u, *p_dst_u;
858 uint8_t *p_src2_v, *p_dst_v;
860 bool b_even_scanline = i_y_offset % 2;
862 i_dst_pitch = p_dst->p[Y_PLANE].i_pitch;
863 p_dst_y = p_dst->p[Y_PLANE].p_pixels + i_x_offset +
864 p_filter->fmt_out.video.i_x_offset +
865 p_dst->p[Y_PLANE].i_pitch *
866 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
867 p_dst_u = p_dst->p[U_PLANE].p_pixels + i_x_offset/2 +
868 p_filter->fmt_out.video.i_x_offset/2 +
869 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
870 p_dst->p[U_PLANE].i_pitch;
871 p_dst_v = p_dst->p[V_PLANE].p_pixels + i_x_offset/2 +
872 p_filter->fmt_out.video.i_x_offset/2 +
873 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
874 p_dst->p[V_PLANE].i_pitch;
876 p_src2_y = vlc_plane_start( &i_src2_pitch, p_src, Y_PLANE,
877 0, 0, &p_filter->fmt_in.video, 1 );
878 p_src2_u = vlc_plane_start( NULL, p_src, U_PLANE,
879 0, 0, &p_filter->fmt_in.video, 2 );
880 p_src2_v = vlc_plane_start( NULL, p_src, V_PLANE,
881 0, 0, &p_filter->fmt_in.video, 2 );
885 /* Draw until we reach the bottom of the subtitle */
886 for( i_y = 0; i_y < i_height;
887 i_y++, p_dst_y += i_dst_pitch, p_src2_y += i_src2_pitch )
889 /* Completely opaque. Completely overwrite underlying pixel */
890 vlc_memcpy( p_dst_y, p_src2_y, i_width );
891 if( b_even_scanline )
893 p_dst_u += i_dst_pitch/2;
894 p_dst_v += i_dst_pitch/2;
898 vlc_memcpy( p_dst_u, p_src2_u, i_width/2 );
899 vlc_memcpy( p_dst_v, p_src2_v, i_width/2 );
901 b_even_scanline = !b_even_scanline;
904 p_src2_u += i_src2_pitch/2;
905 p_src2_v += i_src2_pitch/2;
910 static void BlendI420R16( filter_t *p_filter, picture_t *p_dst_pic,
911 picture_t *p_dst_orig, 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_src1_pitch, i_src2_pitch, i_dst_pitch;
916 uint8_t *p_dst, *p_src1, *p_src2_y;
917 uint8_t *p_src2_u, *p_src2_v;
918 int i_x, i_y, i_pix_pitch;
921 i_pix_pitch = p_dst_pic->p->i_pixel_pitch;
922 i_dst_pitch = p_dst_pic->p->i_pitch;
923 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
924 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
925 p_dst_pic->p->i_pitch *
926 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
928 i_src1_pitch = p_dst_orig->p[Y_PLANE].i_pitch;
929 p_src1 = p_dst_orig->p->p_pixels + i_x_offset * i_pix_pitch +
930 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
931 p_dst_orig->p->i_pitch *
932 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
934 p_src2_y = vlc_plane_start( &i_src2_pitch, p_src, Y_PLANE,
935 0, 0, &p_filter->fmt_in.video, 1 );
936 p_src2_u = vlc_plane_start( NULL, p_src, U_PLANE,
937 0, 0, &p_filter->fmt_in.video, 2 );
938 p_src2_v = vlc_plane_start( NULL, p_src, V_PLANE,
939 0, 0, &p_filter->fmt_in.video, 2 );
941 /* Draw until we reach the bottom of the subtitle */
942 for( i_y = 0; i_y < i_height; i_y++,
943 p_dst += i_dst_pitch, p_src1 += i_src1_pitch,
944 p_src2_y += i_src2_pitch )
946 /* Draw until we reach the end of the line */
947 for( i_x = 0; i_x < i_width; i_x++ )
950 yuv_to_rgb( &r, &g, &b,
951 p_src2_y[i_x], p_src2_u[i_x/2], p_src2_v[i_x/2] );
953 vlc_blend_rgb16( (uint16_t*)&p_dst[i_x * i_pix_pitch],
954 (const uint16_t*)&p_src1[i_x * i_pix_pitch],
955 r, g, b, i_alpha, &p_filter->fmt_out.video );
959 p_src2_u += i_src2_pitch/2;
960 p_src2_v += i_src2_pitch/2;
965 static void BlendI420R24( filter_t *p_filter, picture_t *p_dst_pic,
966 picture_t *p_dst_orig, 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_src1_pitch, i_src2_pitch, i_dst_pitch;
971 uint8_t *p_dst, *p_src1, *p_src2_y;
972 uint8_t *p_src2_u, *p_src2_v;
973 int i_x, i_y, i_pix_pitch;
974 int i_rindex, i_gindex, i_bindex;
977 i_pix_pitch = p_dst_pic->p->i_pixel_pitch;
978 i_dst_pitch = p_dst_pic->p->i_pitch;
979 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
980 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
981 p_dst_pic->p->i_pitch *
982 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
984 i_src1_pitch = p_dst_orig->p[Y_PLANE].i_pitch;
985 p_src1 = p_dst_orig->p->p_pixels + i_x_offset * i_pix_pitch +
986 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
987 p_dst_orig->p->i_pitch *
988 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
990 p_src2_y = vlc_plane_start( &i_src2_pitch, p_src, Y_PLANE,
991 0, 0, &p_filter->fmt_in.video, 1 );
992 p_src2_u = vlc_plane_start( NULL, p_src, U_PLANE,
993 0, 0, &p_filter->fmt_in.video, 2 );
994 p_src2_v = vlc_plane_start( NULL, p_src, V_PLANE,
995 0, 0, &p_filter->fmt_in.video, 2 );
997 vlc_rgb_index( &i_rindex, &i_gindex, &i_bindex, &p_filter->fmt_out.video );
999 /* Draw until we reach the bottom of the subtitle */
1000 for( i_y = 0; i_y < i_height; i_y++,
1001 p_dst += i_dst_pitch, p_src1 += i_src1_pitch,
1002 p_src2_y += i_src2_pitch, p_src2_u += i_src2_pitch,
1003 p_src2_v += i_src2_pitch )
1005 /* Draw until we reach the end of the line */
1006 for( i_x = 0; i_x < i_width; i_x++ )
1012 yuv_to_rgb( &r, &g, &b,
1013 p_src2_y[i_x], p_src2_u[i_x/2], p_src2_v[i_x/2] );
1015 vlc_blend_packed( &p_dst[i_x * i_pix_pitch], &p_src1[i_x * i_pix_pitch],
1016 i_rindex, i_gindex, i_bindex, r, g, b, i_alpha, true );
1020 p_src2_u += i_src2_pitch/2;
1021 p_src2_v += i_src2_pitch/2;
1026 static void BlendI420YUVPacked( filter_t *p_filter, picture_t *p_dst_pic,
1027 picture_t *p_dst_orig, picture_t *p_src,
1028 int i_x_offset, int i_y_offset,
1029 int i_width, int i_height, int i_alpha )
1031 int i_src1_pitch, i_src2_pitch, i_dst_pitch;
1032 uint8_t *p_dst, *p_src1, *p_src2_y;
1033 uint8_t *p_src2_u, *p_src2_v;
1034 int i_x, i_y, i_pix_pitch;
1035 bool b_even = !((i_x_offset + p_filter->fmt_out.video.i_x_offset)%2);
1036 int i_l_offset, i_u_offset, i_v_offset;
1038 vlc_yuv_packed_index( &i_l_offset, &i_u_offset, &i_v_offset,
1039 p_filter->fmt_out.video.i_chroma );
1042 i_dst_pitch = p_dst_pic->p->i_pitch;
1043 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
1044 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
1045 p_dst_pic->p->i_pitch *
1046 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1048 i_src1_pitch = p_dst_orig->p[Y_PLANE].i_pitch;
1049 p_src1 = p_dst_orig->p->p_pixels + i_x_offset * i_pix_pitch +
1050 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
1051 p_dst_orig->p->i_pitch *
1052 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1054 p_src2_y = vlc_plane_start( &i_src2_pitch, p_src, Y_PLANE,
1055 0, 0, &p_filter->fmt_in.video, 1 );
1056 p_src2_u = vlc_plane_start( NULL, p_src, U_PLANE,
1057 0, 0, &p_filter->fmt_in.video, 2 );
1058 p_src2_v = vlc_plane_start( NULL, p_src, V_PLANE,
1059 0, 0, &p_filter->fmt_in.video, 2 );
1061 i_width &= ~1; /* Needs to be a multiple of 2 */
1063 /* Draw until we reach the bottom of the subtitle */
1064 for( i_y = 0; i_y < i_height; i_y++,
1065 p_dst += i_dst_pitch, p_src1 += i_src1_pitch,
1066 p_src2_y += i_src2_pitch, p_src2_u += i_src2_pitch,
1067 p_src2_v += i_src2_pitch )
1069 /* Draw until we reach the end of the line */
1070 for( i_x = 0; i_x < i_width; i_x++, b_even = !b_even )
1076 vlc_blend_packed( &p_dst[i_x * 2], &p_src1[i_x * 2],
1077 i_l_offset, i_u_offset, i_v_offset,
1078 p_src2_y[i_x], p_src2_u[i_x/2], p_src2_v[i_x/2], i_alpha, b_even );
1082 p_src2_u += i_src2_pitch/2;
1083 p_src2_v += i_src2_pitch/2;
1088 /***********************************************************************
1090 ***********************************************************************/
1091 static void BlendPalI420( filter_t *p_filter, picture_t *p_dst,
1092 picture_t *p_dst_orig, picture_t *p_src,
1093 int i_x_offset, int i_y_offset,
1094 int i_width, int i_height, int i_alpha )
1096 int i_src1_pitch, i_src2_pitch, i_dst_pitch;
1097 uint8_t *p_src1_y, *p_src2, *p_dst_y;
1098 uint8_t *p_src1_u, *p_dst_u;
1099 uint8_t *p_src1_v, *p_dst_v;
1100 int i_x, i_y, i_trans;
1101 bool b_even_scanline = i_y_offset % 2;
1103 i_dst_pitch = p_dst->p[Y_PLANE].i_pitch;
1104 p_dst_y = p_dst->p[Y_PLANE].p_pixels + i_x_offset +
1105 p_filter->fmt_out.video.i_x_offset +
1106 p_dst->p[Y_PLANE].i_pitch *
1107 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1108 p_dst_u = p_dst->p[U_PLANE].p_pixels + i_x_offset/2 +
1109 p_filter->fmt_out.video.i_x_offset/2 +
1110 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
1111 p_dst->p[U_PLANE].i_pitch;
1112 p_dst_v = p_dst->p[V_PLANE].p_pixels + i_x_offset/2 +
1113 p_filter->fmt_out.video.i_x_offset/2 +
1114 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
1115 p_dst->p[V_PLANE].i_pitch;
1117 i_src1_pitch = p_dst_orig->p[Y_PLANE].i_pitch;
1118 p_src1_y = p_dst_orig->p[Y_PLANE].p_pixels + i_x_offset +
1119 p_filter->fmt_out.video.i_x_offset +
1120 p_dst_orig->p[Y_PLANE].i_pitch *
1121 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1122 p_src1_u = p_dst_orig->p[U_PLANE].p_pixels + i_x_offset/2 +
1123 p_filter->fmt_out.video.i_x_offset/2 +
1124 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
1125 p_dst_orig->p[U_PLANE].i_pitch;
1126 p_src1_v = p_dst_orig->p[V_PLANE].p_pixels + i_x_offset/2 +
1127 p_filter->fmt_out.video.i_x_offset/2 +
1128 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
1129 p_dst_orig->p[V_PLANE].i_pitch;
1131 i_src2_pitch = p_src->p->i_pitch;
1132 p_src2 = p_src->p->p_pixels + p_filter->fmt_in.video.i_x_offset +
1133 i_src2_pitch * p_filter->fmt_in.video.i_y_offset;
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 const uint8_t *p_trans = p_src2;
1147 b_even_scanline = !b_even_scanline;
1149 /* Draw until we reach the end of the line */
1150 for( i_x = 0; i_x < i_width; i_x++ )
1152 i_trans = vlc_alpha( p_pal[p_trans[i_x]][3], i_alpha );
1157 p_dst_y[i_x] = vlc_blend( p_pal[p_src2[i_x]][0], p_src1_y[i_x], i_trans );
1158 if( b_even_scanline && ((i_x % 2) == 0) )
1160 p_dst_u[i_x/2] = vlc_blend( p_pal[p_src2[i_x]][1], p_src1_u[i_x/2], i_trans );
1161 p_dst_v[i_x/2] = vlc_blend( p_pal[p_src2[i_x]][2], p_src1_v[i_x/2], i_trans );
1168 static void BlendPalYUVPacked( filter_t *p_filter, picture_t *p_dst_pic,
1169 picture_t *p_dst_orig, picture_t *p_src,
1170 int i_x_offset, int i_y_offset,
1171 int i_width, int i_height, int i_alpha )
1173 int i_src1_pitch, i_src2_pitch, i_dst_pitch;
1174 uint8_t *p_src1, *p_src2, *p_dst;
1175 int i_x, i_y, i_pix_pitch, i_trans;
1176 bool b_even = !((i_x_offset + p_filter->fmt_out.video.i_x_offset)%2);
1177 int i_l_offset, i_u_offset, i_v_offset;
1179 vlc_yuv_packed_index( &i_l_offset, &i_u_offset, &i_v_offset,
1180 p_filter->fmt_out.video.i_chroma );
1183 i_dst_pitch = p_dst_pic->p->i_pitch;
1184 p_dst = p_dst_pic->p->p_pixels + i_pix_pitch * (i_x_offset +
1185 p_filter->fmt_out.video.i_x_offset) + p_dst_pic->p->i_pitch *
1186 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1188 i_src1_pitch = p_dst_orig->p->i_pitch;
1189 p_src1 = p_dst_orig->p->p_pixels + i_pix_pitch * (i_x_offset +
1190 p_filter->fmt_out.video.i_x_offset) + p_dst_orig->p->i_pitch *
1191 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1193 i_src2_pitch = p_src->p->i_pitch;
1194 p_src2 = p_src->p->p_pixels + p_filter->fmt_in.video.i_x_offset +
1195 i_src2_pitch * p_filter->fmt_in.video.i_y_offset;
1197 i_width &= ~1; /* Needs to be a multiple of 2 */
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 const uint8_t *p_trans = p_src2;
1206 /* Draw until we reach the end of the line */
1207 for( i_x = 0; i_x < i_width; i_x++, b_even = !b_even )
1209 i_trans = vlc_alpha( p_pal[p_trans[i_x]][3], i_alpha );
1218 if( p_trans[i_x+1] > 0xaa )
1220 i_u = (p_pal[p_src2[i_x]][1] + p_pal[p_src2[i_x+1]][1]) >> 1;
1221 i_v = (p_pal[p_src2[i_x]][2] + p_pal[p_src2[i_x+1]][2]) >> 1;
1225 i_u = p_pal[p_src2[i_x]][1];
1226 i_v = p_pal[p_src2[i_x]][2];
1229 vlc_blend_packed( &p_dst[i_x * 2], &p_src1[i_x * 2],
1230 i_l_offset, i_u_offset, i_v_offset,
1231 p_pal[p_src2[i_x]][0], i_u, i_v, i_trans, true );
1235 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 );
1242 static void BlendPalRV( filter_t *p_filter, picture_t *p_dst_pic,
1243 picture_t *p_dst_orig, picture_t *p_src,
1244 int i_x_offset, int i_y_offset,
1245 int i_width, int i_height, int i_alpha )
1247 int i_src1_pitch, i_src2_pitch, i_dst_pitch;
1248 uint8_t *p_src1, *p_src2, *p_dst;
1249 int i_x, i_y, i_pix_pitch, i_trans;
1251 video_palette_t rgbpalette;
1252 int i_rindex, i_gindex, i_bindex;
1254 i_pix_pitch = p_dst_pic->p->i_pixel_pitch;
1255 i_dst_pitch = p_dst_pic->p->i_pitch;
1256 p_dst = p_dst_pic->p->p_pixels + i_pix_pitch * (i_x_offset +
1257 p_filter->fmt_out.video.i_x_offset) + p_dst_pic->p->i_pitch *
1258 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1260 i_src1_pitch = p_dst_orig->p->i_pitch;
1261 p_src1 = p_dst_orig->p->p_pixels + i_pix_pitch * (i_x_offset +
1262 p_filter->fmt_out.video.i_x_offset) + p_dst_orig->p->i_pitch *
1263 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1265 i_src2_pitch = p_src->p->i_pitch;
1266 p_src2 = p_src->p->p_pixels + p_filter->fmt_in.video.i_x_offset +
1267 i_src2_pitch * p_filter->fmt_in.video.i_y_offset;
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 const uint8_t *p_trans = p_src2;
1287 /* Draw until we reach the end of the line */
1288 for( i_x = 0; i_x < i_width; i_x++ )
1290 i_trans = vlc_alpha( p_pal[p_trans[i_x]][3], i_alpha );
1295 if( p_filter->fmt_out.video.i_chroma == FCC_RV15 || p_filter->fmt_out.video.i_chroma == FCC_RV16 )
1296 vlc_blend_rgb16( (uint16_t*)&p_dst[i_x * i_pix_pitch],
1297 (const uint16_t*)&p_src1[i_x * i_pix_pitch],
1298 rgbpal[p_src2[i_x]][0], rgbpal[p_src2[i_x]][1], rgbpal[p_src2[i_x]][3],
1300 &p_filter->fmt_out.video );
1302 vlc_blend_packed( &p_dst[i_x * i_pix_pitch], &p_src1[i_x * i_pix_pitch],
1303 i_rindex, i_gindex, i_bindex,
1304 rgbpal[p_src2[i_x]][0], rgbpal[p_src2[i_x]][1], rgbpal[p_src2[i_x]][3],
1313 /***********************************************************************
1315 ***********************************************************************/
1316 static void BlendRGBAI420( filter_t *p_filter, picture_t *p_dst,
1317 picture_t *p_dst_orig, picture_t *p_src,
1318 int i_x_offset, int i_y_offset,
1319 int i_width, int i_height, int i_alpha )
1321 int i_src1_pitch, i_src2_pitch, i_dst_pitch, i_src_pix_pitch;
1322 uint8_t *p_src1_y, *p_dst_y;
1323 uint8_t *p_src1_u, *p_dst_u;
1324 uint8_t *p_src1_v, *p_dst_v;
1326 int i_x, i_y, i_trans;
1329 bool b_even_scanline = i_y_offset % 2;
1331 i_dst_pitch = p_dst->p[Y_PLANE].i_pitch;
1332 p_dst_y = p_dst->p[Y_PLANE].p_pixels + i_x_offset +
1333 p_filter->fmt_out.video.i_x_offset +
1334 p_dst->p[Y_PLANE].i_pitch *
1335 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1336 p_dst_u = p_dst->p[U_PLANE].p_pixels + i_x_offset/2 +
1337 p_filter->fmt_out.video.i_x_offset/2 +
1338 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
1339 p_dst->p[U_PLANE].i_pitch;
1340 p_dst_v = p_dst->p[V_PLANE].p_pixels + i_x_offset/2 +
1341 p_filter->fmt_out.video.i_x_offset/2 +
1342 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
1343 p_dst->p[V_PLANE].i_pitch;
1345 i_src1_pitch = p_dst_orig->p[Y_PLANE].i_pitch;
1346 p_src1_y = p_dst_orig->p[Y_PLANE].p_pixels + i_x_offset +
1347 p_filter->fmt_out.video.i_x_offset +
1348 p_dst_orig->p[Y_PLANE].i_pitch *
1349 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1350 p_src1_u = p_dst_orig->p[U_PLANE].p_pixels + i_x_offset/2 +
1351 p_filter->fmt_out.video.i_x_offset/2 +
1352 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
1353 p_dst_orig->p[U_PLANE].i_pitch;
1354 p_src1_v = p_dst_orig->p[V_PLANE].p_pixels + i_x_offset/2 +
1355 p_filter->fmt_out.video.i_x_offset/2 +
1356 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
1357 p_dst_orig->p[V_PLANE].i_pitch;
1359 i_src_pix_pitch = p_src->p->i_pixel_pitch;
1360 i_src2_pitch = p_src->p->i_pitch;
1361 p_src2 = p_src->p->p_pixels +
1362 p_filter->fmt_in.video.i_x_offset * i_src_pix_pitch +
1363 p_src->p->i_pitch * p_filter->fmt_in.video.i_y_offset;
1366 /* Draw until we reach the bottom of the subtitle */
1367 for( i_y = 0; i_y < i_height; i_y++,
1368 p_dst_y += i_dst_pitch, p_src1_y += i_src1_pitch,
1369 p_dst_u += b_even_scanline ? i_dst_pitch/2 : 0,
1370 p_src1_u += b_even_scanline ? i_src1_pitch/2 : 0,
1371 p_dst_v += b_even_scanline ? i_dst_pitch/2 : 0,
1372 p_src1_v += b_even_scanline ? i_src1_pitch/2 : 0,
1373 p_src2 += i_src2_pitch )
1375 b_even_scanline = !b_even_scanline;
1377 /* Draw until we reach the end of the line */
1378 for( i_x = 0; i_x < i_width; i_x++ )
1380 const int R = p_src2[i_x * i_src_pix_pitch + 0];
1381 const int G = p_src2[i_x * i_src_pix_pitch + 1];
1382 const int B = p_src2[i_x * i_src_pix_pitch + 2];
1384 i_trans = vlc_alpha( p_src2[i_x * i_src_pix_pitch + 3], i_alpha );
1389 rgb_to_yuv( &y, &u, &v, R, G, B );
1391 p_dst_y[i_x] = vlc_blend( y, p_src1_y[i_x], i_trans );
1392 if( b_even_scanline && i_x % 2 == 0 )
1394 p_dst_u[i_x/2] = vlc_blend( u, p_src1_u[i_x/2], i_trans );
1395 p_dst_v[i_x/2] = vlc_blend( v, p_src1_v[i_x/2], i_trans );
1401 static void BlendRGBAR24( filter_t *p_filter, picture_t *p_dst_pic,
1402 picture_t *p_dst_orig, picture_t *p_src,
1403 int i_x_offset, int i_y_offset,
1404 int i_width, int i_height, int i_alpha )
1406 int i_src1_pitch, i_src2_pitch, i_dst_pitch;
1407 uint8_t *p_dst, *p_src1, *p_src2;
1408 int i_x, i_y, i_pix_pitch, i_trans, i_src_pix_pitch;
1409 int i_rindex, i_gindex, i_bindex;
1411 i_pix_pitch = p_dst_pic->p->i_pixel_pitch;
1412 i_dst_pitch = p_dst_pic->p->i_pitch;
1413 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
1414 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
1415 p_dst_pic->p->i_pitch *
1416 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1418 i_src1_pitch = p_dst_orig->p->i_pitch;
1419 p_src1 = p_dst_orig->p->p_pixels + i_x_offset * i_pix_pitch +
1420 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
1421 p_dst_orig->p->i_pitch *
1422 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1424 i_src_pix_pitch = p_src->p->i_pixel_pitch;
1425 i_src2_pitch = p_src->p->i_pitch;
1426 p_src2 = p_src->p->p_pixels +
1427 p_filter->fmt_in.video.i_x_offset * i_src_pix_pitch +
1428 p_src->p->i_pitch * p_filter->fmt_in.video.i_y_offset;
1430 vlc_rgb_index( &i_rindex, &i_gindex, &i_bindex, &p_filter->fmt_out.video );
1432 /* Draw until we reach the bottom of the subtitle */
1433 for( i_y = 0; i_y < i_height; i_y++,
1434 p_dst += i_dst_pitch, p_src1 += i_src1_pitch, p_src2 += i_src2_pitch )
1436 /* Draw until we reach the end of the line */
1437 for( i_x = 0; i_x < i_width; i_x++ )
1439 const int R = p_src2[i_x * i_src_pix_pitch + 0];
1440 const int G = p_src2[i_x * i_src_pix_pitch + 1];
1441 const int B = p_src2[i_x * i_src_pix_pitch + 2];
1443 i_trans = vlc_alpha( p_src2[i_x * i_src_pix_pitch + 3], i_alpha );
1448 vlc_blend_packed( &p_dst[i_x * i_pix_pitch], &p_src1[i_x * i_pix_pitch],
1449 i_rindex, i_gindex, i_bindex,
1450 R, G, B, i_trans, true );
1455 static void BlendRGBAR16( filter_t *p_filter, picture_t *p_dst_pic,
1456 picture_t *p_dst_orig, picture_t *p_src,
1457 int i_x_offset, int i_y_offset,
1458 int i_width, int i_height, int i_alpha )
1460 int i_src1_pitch, i_src2_pitch, i_dst_pitch;
1461 uint8_t *p_dst, *p_src1, *p_src2;
1462 int i_x, i_y, i_pix_pitch, i_trans, i_src_pix_pitch;
1464 i_pix_pitch = p_dst_pic->p->i_pixel_pitch;
1465 i_dst_pitch = p_dst_pic->p->i_pitch;
1466 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
1467 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
1468 p_dst_pic->p->i_pitch *
1469 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1471 i_src1_pitch = p_dst_orig->p->i_pitch;
1472 p_src1 = p_dst_orig->p->p_pixels + i_x_offset * i_pix_pitch +
1473 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
1474 p_dst_orig->p->i_pitch *
1475 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1477 i_src_pix_pitch = p_src->p->i_pixel_pitch;
1478 i_src2_pitch = p_src->p->i_pitch;
1479 p_src2 = p_src->p->p_pixels +
1480 p_filter->fmt_in.video.i_x_offset * i_src_pix_pitch +
1481 p_src->p->i_pitch * p_filter->fmt_in.video.i_y_offset;
1483 /* Draw until we reach the bottom of the subtitle */
1484 for( i_y = 0; i_y < i_height; i_y++,
1485 p_dst += i_dst_pitch, p_src1 += i_src1_pitch, p_src2 += i_src2_pitch )
1487 /* Draw until we reach the end of the line */
1488 for( i_x = 0; i_x < i_width; i_x++ )
1490 const int R = p_src2[i_x * i_src_pix_pitch + 0];
1491 const int G = p_src2[i_x * i_src_pix_pitch + 1];
1492 const int B = p_src2[i_x * i_src_pix_pitch + 2];
1494 i_trans = vlc_alpha( p_src2[i_x * i_src_pix_pitch + 3], i_alpha );
1499 vlc_blend_rgb16( (uint16_t*)&p_dst[i_x * i_pix_pitch],
1500 (const uint16_t*)&p_src1[i_x * i_pix_pitch],
1501 R, G, B, i_trans, &p_filter->fmt_out.video );
1506 static void BlendRGBAYUVPacked( filter_t *p_filter, picture_t *p_dst_pic,
1507 picture_t *p_dst_orig, picture_t *p_src,
1508 int i_x_offset, int i_y_offset,
1509 int i_width, int i_height, int i_alpha )
1511 int i_src1_pitch, i_src2_pitch, i_dst_pitch, i_src_pix_pitch;
1512 uint8_t *p_dst, *p_src1, *p_src2;
1514 int i_x, i_y, i_pix_pitch, i_trans;
1515 bool b_even = !((i_x_offset + p_filter->fmt_out.video.i_x_offset)%2);
1516 int i_l_offset, i_u_offset, i_v_offset;
1519 vlc_yuv_packed_index( &i_l_offset, &i_u_offset, &i_v_offset,
1520 p_filter->fmt_out.video.i_chroma );
1523 i_dst_pitch = p_dst_pic->p->i_pitch;
1524 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
1525 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
1526 p_dst_pic->p->i_pitch *
1527 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1529 i_src1_pitch = p_dst_orig->p[Y_PLANE].i_pitch;
1530 p_src1 = p_dst_orig->p->p_pixels + i_x_offset * i_pix_pitch +
1531 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
1532 p_dst_orig->p->i_pitch *
1533 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1535 i_src_pix_pitch = p_src->p->i_pixel_pitch;
1536 i_src2_pitch = p_src->p->i_pitch;
1537 p_src2 = p_src->p->p_pixels +
1538 p_filter->fmt_in.video.i_x_offset * i_src2_pitch +
1539 p_src->p->i_pitch * p_filter->fmt_in.video.i_y_offset;
1541 i_width &= ~1; /* Needs to be a multiple of 2 */
1543 /* Draw until we reach the bottom of the subtitle */
1544 for( i_y = 0; i_y < i_height; i_y++, p_trans += i_src2_pitch,
1545 p_dst += i_dst_pitch, p_src1 += i_src1_pitch,
1546 p_src2 += i_src2_pitch )
1548 /* Draw until we reach the end of the line */
1549 for( i_x = 0; i_x < i_width; i_x++, b_even = !b_even )
1551 const int R = p_src2[i_x * i_src_pix_pitch + 0];
1552 const int G = p_src2[i_x * i_src_pix_pitch + 1];
1553 const int B = p_src2[i_x * i_src_pix_pitch + 2];
1555 i_trans = vlc_alpha( p_src2[i_x * i_src_pix_pitch + 3], i_alpha );
1560 rgb_to_yuv( &y, &u, &v, R, G, B );
1562 vlc_blend_packed( &p_dst[i_x * 2], &p_src1[i_x * 2],
1563 i_l_offset, i_u_offset, i_v_offset,
1564 y, u, v, i_trans, b_even );