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 *,
80 static void BlendYUVAI420( filter_t *, picture_t *, picture_t *,
81 int, int, int, int, int );
82 static void BlendYUVARV16( filter_t *, picture_t *, picture_t *,
83 int, int, int, int, int );
84 static void BlendYUVARV24( filter_t *, picture_t *, picture_t *,
85 int, int, int, int, int );
86 static void BlendYUVAYUVPacked( filter_t *, picture_t *, picture_t *,
87 int, int, int, int, int );
90 static void BlendI420I420( filter_t *, picture_t *, picture_t *,
91 int, int, int, int, int );
92 static void BlendI420I420_no_alpha(
93 filter_t *, picture_t *, picture_t *,
95 static void BlendI420R16( filter_t *, picture_t *, picture_t *,
96 int, int, int, int, int );
97 static void BlendI420R24( filter_t *, picture_t *, picture_t *,
98 int, int, int, int, int );
99 static void BlendI420YUVPacked( filter_t *, picture_t *,
100 picture_t *, int, int, int, int, int );
103 static void BlendPalI420( filter_t *, picture_t *, picture_t *,
104 int, int, int, int, int );
105 static void BlendPalYUVPacked( filter_t *, picture_t *, picture_t *,
106 int, int, int, int, int );
107 static void BlendPalRV( filter_t *, picture_t *, picture_t *,
108 int, int, int, int, int );
111 static void BlendRGBAI420( filter_t *, picture_t *, picture_t *,
112 int, int, int, int, int );
113 static void BlendRGBAYUVPacked( filter_t *, picture_t *,
114 picture_t *, int, int, int, int, int );
115 static void BlendRGBAR16( filter_t *, picture_t *, picture_t *,
116 int, int, int, int, int );
117 static void BlendRGBAR24( filter_t *, picture_t *, picture_t *,
118 int, int, int, int, int );
120 /*****************************************************************************
121 * OpenFilter: probe the filter and return score
122 *****************************************************************************/
123 static int OpenFilter( vlc_object_t *p_this )
125 filter_t *p_filter = (filter_t*)p_this;
128 /* Check if we can handle that format.
129 * We could try to use a chroma filter if we can't. */
130 int in_chroma = p_filter->fmt_in.video.i_chroma;
131 int out_chroma = p_filter->fmt_out.video.i_chroma;
132 if( ( in_chroma != FCC_YUVA && in_chroma != FCC_I420 &&
133 in_chroma != FCC_YV12 && in_chroma != FCC_YUVP &&
134 in_chroma != FCC_RGBA ) ||
135 ( out_chroma != FCC_I420 && out_chroma != FCC_YUY2 &&
136 out_chroma != FCC_YV12 && out_chroma != FCC_UYVY &&
137 out_chroma != FCC_YVYU && out_chroma != FCC_RV15 &&
138 out_chroma != FCC_YVYU && out_chroma != FCC_RV16 &&
139 out_chroma != FCC_RV24 && out_chroma != FCC_RV32 ) )
144 /* Allocate the memory needed to store the decoder's structure */
145 p_filter->p_sys = p_sys = malloc(sizeof(filter_sys_t));
150 p_filter->pf_video_blend = Blend;
152 msg_Dbg( p_filter, "chroma: %4.4s -> %4.4s",
153 (char *)&p_filter->fmt_in.video.i_chroma,
154 (char *)&p_filter->fmt_out.video.i_chroma );
159 /*****************************************************************************
160 * CloseFilter: clean up the filter
161 *****************************************************************************/
162 static void CloseFilter( vlc_object_t *p_this )
164 filter_t *p_filter = (filter_t*)p_this;
165 filter_sys_t *p_sys = p_filter->p_sys;
170 /****************************************************************************
171 * Blend: the whole thing
172 ****************************************************************************
173 * This function is called just after the thread is launched.
174 ****************************************************************************/
175 typedef void (*BlendFunction)( filter_t *,
176 picture_t *, picture_t *,
177 int , int , int , int , int );
179 #define FCC_PLANAR_420 { FCC_I420, FCC_YV12, 0 }
180 #define FCC_PACKED_422 { FCC_YUY2, FCC_UYVY, FCC_YVYU, 0 }
181 #define FCC_RGB_16 { FCC_RV15, FCC_RV16, 0 }
182 #define FCC_RGB_24 { FCC_RV24, FCC_RV32, 0 }
184 #define BLEND_CFG( fccSrc, fctPlanar, fctPacked, fctRgb16, fctRgb24 ) \
185 { .src = fccSrc, .p_dst = FCC_PLANAR_420, .pf_blend = fctPlanar }, \
186 { .src = fccSrc, .p_dst = FCC_PACKED_422, .pf_blend = fctPacked }, \
187 { .src = fccSrc, .p_dst = FCC_RGB_16, .pf_blend = fctRgb16 }, \
188 { .src = fccSrc, .p_dst = FCC_RGB_24, .pf_blend = fctRgb24 }
193 vlc_fourcc_t p_dst[16];
194 BlendFunction pf_blend;
197 BLEND_CFG( FCC_YUVA, BlendYUVAI420, BlendYUVAYUVPacked, BlendYUVARV16, BlendYUVARV24 ),
199 BLEND_CFG( FCC_YUVP, BlendPalI420, BlendPalYUVPacked, BlendPalRV, BlendPalRV ),
201 BLEND_CFG( FCC_RGBA, BlendRGBAI420, BlendRGBAYUVPacked, BlendRGBAR16, BlendRGBAR24 ),
203 BLEND_CFG( FCC_I420, BlendI420I420, BlendI420YUVPacked, BlendI420R16, BlendI420R24 ),
205 BLEND_CFG( FCC_YV12, BlendI420I420, BlendI420YUVPacked, BlendI420R16, BlendI420R24 ),
210 static void Blend( filter_t *p_filter,
211 picture_t *p_dst, picture_t *p_src,
212 int i_x_offset, int i_y_offset, int i_alpha )
214 int i_width, i_height;
219 i_width = __MIN((int)p_filter->fmt_out.video.i_visible_width - i_x_offset,
220 (int)p_filter->fmt_in.video.i_visible_width);
222 i_height = __MIN((int)p_filter->fmt_out.video.i_visible_height -i_y_offset,
223 (int)p_filter->fmt_in.video.i_visible_height);
225 if( i_width <= 0 || i_height <= 0 )
228 video_format_FixRgb( &p_filter->fmt_out.video );
229 video_format_FixRgb( &p_filter->fmt_in.video );
232 msg_Dbg( p_filter, "chroma: %4.4s -> %4.4s\n",
233 (char *)&p_filter->fmt_in.video.i_chroma,
234 (char *)&p_filter->fmt_out.video.i_chroma );
237 for( int i = 0; p_blend_cfg[i].src != 0; i++ )
239 if( p_blend_cfg[i].src != p_filter->fmt_in.video.i_chroma )
241 for( int j = 0; p_blend_cfg[i].p_dst[j] != 0; j++ )
243 if( p_blend_cfg[i].p_dst[j] != p_filter->fmt_out.video.i_chroma )
246 p_blend_cfg[i].pf_blend( p_filter, p_dst, p_src,
247 i_x_offset, i_y_offset,
248 i_width, i_height, i_alpha );
253 msg_Dbg( p_filter, "no matching alpha blending routine "
254 "(chroma: %4.4s -> %4.4s)",
255 (char *)&p_filter->fmt_in.video.i_chroma,
256 (char *)&p_filter->fmt_out.video.i_chroma );
259 /***********************************************************************
261 ***********************************************************************/
262 static inline uint8_t vlc_uint8( int v )
271 #define MAX_TRANS 255
274 static inline int vlc_blend( int v1, int v2, int a )
276 /* TODO bench if the tests really increase speed */
279 else if( a == MAX_TRANS )
281 return ( v1 * a + v2 * (MAX_TRANS - a ) ) >> TRANS_BITS;
284 static inline int vlc_alpha( int t, int a )
288 return (t * a) / 255;
291 static inline void yuv_to_rgb( int *r, int *g, int *b,
292 uint8_t y1, uint8_t u1, uint8_t v1 )
294 /* macros used for YUV pixel conversions */
295 # define SCALEBITS 10
296 # define ONE_HALF (1 << (SCALEBITS - 1))
297 # define FIX(x) ((int) ((x) * (1<<SCALEBITS) + 0.5))
299 int y, cb, cr, r_add, g_add, b_add;
303 r_add = FIX(1.40200*255.0/224.0) * cr + ONE_HALF;
304 g_add = - FIX(0.34414*255.0/224.0) * cb
305 - FIX(0.71414*255.0/224.0) * cr + ONE_HALF;
306 b_add = FIX(1.77200*255.0/224.0) * cb + ONE_HALF;
307 y = (y1 - 16) * FIX(255.0/219.0);
308 *r = vlc_uint8( (y + r_add) >> SCALEBITS );
309 *g = vlc_uint8( (y + g_add) >> SCALEBITS );
310 *b = vlc_uint8( (y + b_add) >> SCALEBITS );
316 static inline void rgb_to_yuv( uint8_t *y, uint8_t *u, uint8_t *v,
317 int r, int g, int b )
319 *y = ( ( ( 66 * r + 129 * g + 25 * b + 128 ) >> 8 ) + 16 );
320 *u = ( ( -38 * r - 74 * g + 112 * b + 128 ) >> 8 ) + 128 ;
321 *v = ( ( 112 * r - 94 * g - 18 * b + 128 ) >> 8 ) + 128 ;
324 static uint8_t *vlc_plane_start( int *pi_pitch,
325 picture_t *p_picture,
327 int i_x_offset, int i_y_offset,
328 const video_format_t *p_fmt,
331 const int i_pitch = p_picture->p[i_plane].i_pitch;
332 uint8_t *p_pixels = p_picture->p[i_plane].p_pixels;
334 const int i_dx = ( i_x_offset + p_fmt->i_x_offset ) / r;
335 const int i_dy = ( i_y_offset + p_fmt->i_y_offset ) / r;
339 return &p_pixels[ i_dy * i_pitch + i_dx ];
342 static void vlc_yuv_packed_index( int *pi_y, int *pi_u, int *pi_v, vlc_fourcc_t i_chroma )
344 static const struct {
348 { FCC_YUY2, 0, 1, 3 },
349 { FCC_UYVY, 1, 0, 2 },
350 { FCC_YVYU, 0, 3, 1 },
355 for( i = 0; p_index[i].chroma != 0; i++ )
357 if( p_index[i].chroma == i_chroma )
360 *pi_y = p_index[i].y;
361 *pi_u = p_index[i].u;
362 *pi_v = p_index[i].v;
365 static void vlc_blend_packed( uint8_t *p_dst, const uint8_t *p_src,
366 int i_offset0, int i_offset1, int i_offset2,
367 int c0, int c1, int c2, int i_alpha,
370 p_dst[i_offset0] = vlc_blend( c0, p_src[i_offset0], i_alpha );
373 p_dst[i_offset1] = vlc_blend( c1, p_src[i_offset1], i_alpha );
374 p_dst[i_offset2] = vlc_blend( c2, p_src[i_offset2], i_alpha );
378 static void vlc_blend_rgb16( uint16_t *p_dst, const uint16_t *p_src,
379 int R, int G, int B, int i_alpha,
380 const video_format_t *p_fmt )
382 const int i_pix = *p_src;
383 const int r = ( i_pix & p_fmt->i_rmask ) >> p_fmt->i_lrshift;
384 const int g = ( i_pix & p_fmt->i_gmask ) >> p_fmt->i_lgshift;
385 const int b = ( i_pix & p_fmt->i_bmask ) >> p_fmt->i_lbshift;
387 *p_dst = ( vlc_blend( R >> p_fmt->i_rrshift, r, i_alpha ) << p_fmt->i_lrshift ) |
388 ( vlc_blend( G >> p_fmt->i_rgshift, g, i_alpha ) << p_fmt->i_lgshift ) |
389 ( vlc_blend( B >> p_fmt->i_rbshift, b, i_alpha ) << p_fmt->i_lbshift );
392 static void vlc_rgb_index( int *pi_rindex, int *pi_gindex, int *pi_bindex,
393 const video_format_t *p_fmt )
395 if( p_fmt->i_chroma != FCC_RV24 && p_fmt->i_chroma != FCC_RV32 )
398 /* XXX it will works only if mask are 8 bits aligned */
399 #ifdef WORDS_BIGENDIAN
400 const int i_mask_bits = p_fmt->i_chroma == FCC_RV24 ? 24 : 32;
401 *pi_rindex = ( i_mask_bits - p_fmt->i_lrshift ) / 8;
402 *pi_gindex = ( i_mask_bits - p_fmt->i_lgshift ) / 8;
403 *pi_bindex = ( i_mask_bits - p_fmt->i_lbshift ) / 8;
405 *pi_rindex = p_fmt->i_lrshift / 8;
406 *pi_gindex = p_fmt->i_lgshift / 8;
407 *pi_bindex = p_fmt->i_lbshift / 8;
411 /***********************************************************************
413 ***********************************************************************/
414 static void BlendYUVAI420( filter_t *p_filter,
415 picture_t *p_dst, picture_t *p_src,
416 int i_x_offset, int i_y_offset,
417 int i_width, int i_height, int i_alpha )
419 int i_src_pitch, i_dst_pitch;
420 uint8_t *p_src_y, *p_dst_y;
421 uint8_t *p_src_u, *p_dst_u;
422 uint8_t *p_src_v, *p_dst_v;
424 int i_x, i_y, i_trans = 0;
425 bool b_even_scanline = i_y_offset % 2;
427 p_dst_y = vlc_plane_start( &i_dst_pitch, p_dst, Y_PLANE,
428 i_x_offset, i_y_offset, &p_filter->fmt_out.video, 1 );
429 p_dst_u = vlc_plane_start( NULL, p_dst, U_PLANE,
430 i_x_offset, i_y_offset, &p_filter->fmt_out.video, 2 );
431 p_dst_v = vlc_plane_start( NULL, p_dst, V_PLANE,
432 i_x_offset, i_y_offset, &p_filter->fmt_out.video, 2 );
434 p_src_y = vlc_plane_start( &i_src_pitch, p_src, Y_PLANE,
435 0, 0, &p_filter->fmt_in.video, 1 );
436 p_src_u = vlc_plane_start( NULL, p_src, U_PLANE,
437 0, 0, &p_filter->fmt_in.video, 2 );
438 p_src_v = vlc_plane_start( NULL, p_src, V_PLANE,
439 0, 0, &p_filter->fmt_in.video, 2 );
440 p_trans = vlc_plane_start( NULL, p_src, A_PLANE,
441 0, 0, &p_filter->fmt_in.video, 1 );
443 /* Draw until we reach the bottom of the subtitle */
444 for( i_y = 0; i_y < i_height; i_y++, p_trans += i_src_pitch,
445 p_dst_y += i_dst_pitch, p_src_y += i_src_pitch,
446 p_dst_u += b_even_scanline ? i_dst_pitch/2 : 0,
447 p_src_u += i_src_pitch,
448 p_dst_v += b_even_scanline ? i_dst_pitch/2 : 0,
449 p_src_v += i_src_pitch )
451 b_even_scanline = !b_even_scanline;
453 /* Draw until we reach the end of the line */
454 for( i_x = 0; i_x < i_width; i_x++ )
457 i_trans = vlc_alpha( p_trans[i_x], i_alpha );
463 p_dst_y[i_x] = vlc_blend( p_src_y[i_x], p_dst_y[i_x], i_trans );
464 if( b_even_scanline && i_x % 2 == 0 )
466 p_dst_u[i_x/2] = vlc_blend( p_src_u[i_x], p_dst_u[i_x/2], i_trans );
467 p_dst_v[i_x/2] = vlc_blend( p_src_v[i_x], p_dst_v[i_x/2], i_trans );
473 static void BlendYUVARV16( filter_t *p_filter,
474 picture_t *p_dst_pic, picture_t *p_src,
475 int i_x_offset, int i_y_offset,
476 int i_width, int i_height, int i_alpha )
478 int i_src_pitch, i_dst_pitch;
479 uint8_t *p_dst, *p_src_y;
480 uint8_t *p_src_u, *p_src_v;
482 int i_x, i_y, i_pix_pitch, i_trans = 0;
485 i_pix_pitch = p_dst_pic->p->i_pixel_pitch;
486 i_dst_pitch = p_dst_pic->p->i_pitch;
487 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
488 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
489 p_dst_pic->p->i_pitch *
490 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
492 p_src_y = vlc_plane_start( &i_src_pitch, p_src, Y_PLANE,
493 0, 0, &p_filter->fmt_in.video, 1 );
494 p_src_u = vlc_plane_start( NULL, p_src, U_PLANE,
495 0, 0, &p_filter->fmt_in.video, 2 );
496 p_src_v = vlc_plane_start( NULL, p_src, V_PLANE,
497 0, 0, &p_filter->fmt_in.video, 2 );
498 p_trans = vlc_plane_start( NULL, p_src, A_PLANE,
499 0, 0, &p_filter->fmt_in.video, 1 );
501 /* Draw until we reach the bottom of the subtitle */
502 for( i_y = 0; i_y < i_height; i_y++, p_trans += i_src_pitch,
503 p_dst += i_dst_pitch,
504 p_src_y += i_src_pitch, p_src_u += i_src_pitch,
505 p_src_v += i_src_pitch )
507 /* Draw until we reach the end of the line */
508 for( i_x = 0; i_x < i_width; i_x++ )
511 i_trans = vlc_alpha( p_trans[i_x], i_alpha );
516 yuv_to_rgb( &r, &g, &b,
517 p_src_y[i_x], p_src_u[i_x], p_src_v[i_x] );
519 vlc_blend_rgb16( (uint16_t*)&p_dst[i_x * i_pix_pitch],
520 (const uint16_t*)&p_dst[i_x * i_pix_pitch],
521 r, g, b, i_trans, &p_filter->fmt_out.video );
526 static void BlendYUVARV24( filter_t *p_filter,
527 picture_t *p_dst_pic, picture_t *p_src,
528 int i_x_offset, int i_y_offset,
529 int i_width, int i_height, int i_alpha )
531 int i_src_pitch, i_dst_pitch;
532 uint8_t *p_dst, *p_src_y;
533 uint8_t *p_src_u, *p_src_v;
535 int i_x, i_y, i_pix_pitch, i_trans = 0;
538 i_pix_pitch = p_dst_pic->p->i_pixel_pitch;
539 i_dst_pitch = p_dst_pic->p->i_pitch;
540 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
541 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
542 p_dst_pic->p->i_pitch *
543 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
545 p_src_y = vlc_plane_start( &i_src_pitch, p_src, Y_PLANE,
546 0, 0, &p_filter->fmt_in.video, 1 );
547 p_src_u = vlc_plane_start( NULL, p_src, U_PLANE,
548 0, 0, &p_filter->fmt_in.video, 2 );
549 p_src_v = vlc_plane_start( NULL, p_src, V_PLANE,
550 0, 0, &p_filter->fmt_in.video, 2 );
551 p_trans = vlc_plane_start( NULL, p_src, A_PLANE,
552 0, 0, &p_filter->fmt_in.video, 1 );
554 if( (i_pix_pitch == 4)
555 && (((((intptr_t)p_dst)|i_dst_pitch) /* FIXME? */
559 ** if picture pixels are 32 bits long and lines addresses are 32 bit
560 ** aligned, optimize rendering
562 uint32_t *p32_dst = (uint32_t *)p_dst;
563 uint32_t i32_dst_pitch = (uint32_t)(i_dst_pitch>>2);
565 int i_rshift, i_gshift, i_bshift;
566 uint32_t i_rmask, i_gmask, i_bmask;
568 i_rmask = p_filter->fmt_out.video.i_rmask;
569 i_gmask = p_filter->fmt_out.video.i_gmask;
570 i_bmask = p_filter->fmt_out.video.i_bmask;
571 i_rshift = p_filter->fmt_out.video.i_lrshift;
572 i_gshift = p_filter->fmt_out.video.i_lgshift;
573 i_bshift = p_filter->fmt_out.video.i_lbshift;
575 /* Draw until we reach the bottom of the subtitle */
576 for( i_y = 0; i_y < i_height; i_y++, p_trans += i_src_pitch,
577 p32_dst += i32_dst_pitch,
578 p_src_y += i_src_pitch, p_src_u += i_src_pitch,
579 p_src_v += i_src_pitch )
581 /* Draw until we reach the end of the line */
582 for( i_x = 0; i_x < i_width; i_x++ )
585 i_trans = vlc_alpha( p_trans[i_x], i_alpha );
589 if( i_trans == MAX_TRANS )
591 /* Completely opaque. Completely overwrite underlying pixel */
592 yuv_to_rgb( &r, &g, &b,
593 p_src_y[i_x], p_src_u[i_x], p_src_v[i_x] );
595 p32_dst[i_x] = (r<<i_rshift) |
602 uint32_t i_pix_dst = p32_dst[i_x];
603 yuv_to_rgb( &r, &g, &b,
604 p_src_y[i_x], p_src_u[i_x], p_src_v[i_x] );
606 p32_dst[i_x] = ( vlc_blend( r, (i_pix_dst & i_rmask)>>i_rshift, i_trans ) << i_rshift ) |
607 ( vlc_blend( g, (i_pix_dst & i_gmask)>>i_gshift, i_trans ) << i_gshift ) |
608 ( vlc_blend( b, (i_pix_dst & i_bmask)>>i_bshift, i_trans ) << i_bshift );
615 int i_rindex, i_gindex, i_bindex;
616 uint32_t i_rmask, i_gmask, i_bmask;
618 i_rmask = p_filter->fmt_out.video.i_rmask;
619 i_gmask = p_filter->fmt_out.video.i_gmask;
620 i_bmask = p_filter->fmt_out.video.i_bmask;
622 vlc_rgb_index( &i_rindex, &i_gindex, &i_bindex, &p_filter->fmt_out.video );
624 /* Draw until we reach the bottom of the subtitle */
625 for( i_y = 0; i_y < i_height; i_y++, p_trans += i_src_pitch,
626 p_dst += i_dst_pitch,
627 p_src_y += i_src_pitch, p_src_u += i_src_pitch,
628 p_src_v += i_src_pitch )
630 /* Draw until we reach the end of the line */
631 for( i_x = 0; i_x < i_width; i_x++ )
634 i_trans = vlc_alpha( p_trans[i_x], i_alpha );
639 yuv_to_rgb( &r, &g, &b,
640 p_src_y[i_x], p_src_u[i_x], p_src_v[i_x] );
642 vlc_blend_packed( &p_dst[ i_x * i_pix_pitch],
643 &p_dst[i_x * i_pix_pitch],
644 i_rindex, i_gindex, i_bindex,
645 r, g, b, i_alpha, true );
651 static void BlendYUVAYUVPacked( filter_t *p_filter,
652 picture_t *p_dst_pic, picture_t *p_src,
653 int i_x_offset, int i_y_offset,
654 int i_width, int i_height, int i_alpha )
656 int i_src_pitch, i_dst_pitch;
657 uint8_t *p_dst, *p_src_y;
658 uint8_t *p_src_u, *p_src_v;
660 int i_x, i_y, i_pix_pitch, i_trans = 0;
661 bool b_even = !((i_x_offset + p_filter->fmt_out.video.i_x_offset)%2);
662 int i_l_offset, i_u_offset, i_v_offset;
664 vlc_yuv_packed_index( &i_l_offset, &i_u_offset, &i_v_offset,
665 p_filter->fmt_out.video.i_chroma );
668 i_dst_pitch = p_dst_pic->p->i_pitch;
669 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
670 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
671 p_dst_pic->p->i_pitch *
672 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
674 p_src_y = vlc_plane_start( &i_src_pitch, p_src, Y_PLANE,
675 0, 0, &p_filter->fmt_in.video, 1 );
676 p_src_u = vlc_plane_start( NULL, p_src, U_PLANE,
677 0, 0, &p_filter->fmt_in.video, 2 );
678 p_src_v = vlc_plane_start( NULL, p_src, V_PLANE,
679 0, 0, &p_filter->fmt_in.video, 2 );
680 p_trans = vlc_plane_start( NULL, p_src, A_PLANE,
681 0, 0, &p_filter->fmt_in.video, 1 );
683 i_width &= ~1; /* Needs to be a multiple of 2 */
685 /* Draw until we reach the bottom of the subtitle */
686 for( i_y = 0; i_y < i_height; i_y++, p_trans += i_src_pitch,
687 p_dst += i_dst_pitch,
688 p_src_y += i_src_pitch, p_src_u += i_src_pitch,
689 p_src_v += i_src_pitch )
691 /* Draw until we reach the end of the line */
692 for( i_x = 0; i_x < i_width; i_x++, b_even = !b_even )
694 i_trans = vlc_alpha( p_trans[i_x], i_alpha );
703 /* FIXME what's with 0xaa ? */
704 if( p_trans[i_x+1] > 0xaa )
706 i_u = (p_src_u[i_x]+p_src_u[i_x+1])>>1;
707 i_v = (p_src_v[i_x]+p_src_v[i_x+1])>>1;
715 vlc_blend_packed( &p_dst[i_x * 2], &p_dst[i_x * 2],
716 i_l_offset, i_u_offset, i_v_offset,
717 p_src_y[i_x], i_u, i_v, i_trans, true );
721 p_dst[i_x * 2 + i_l_offset] = vlc_blend( p_src_y[i_x], p_dst[i_x * 2 + i_l_offset], i_trans );
726 /***********************************************************************
728 ***********************************************************************/
729 static void BlendI420I420( filter_t *p_filter,
730 picture_t *p_dst, picture_t *p_src,
731 int i_x_offset, int i_y_offset,
732 int i_width, int i_height, int i_alpha )
734 int i_src_pitch, i_dst_pitch;
735 uint8_t *p_src_y, *p_dst_y;
736 uint8_t *p_src_u, *p_dst_u;
737 uint8_t *p_src_v, *p_dst_v;
739 bool b_even_scanline = i_y_offset % 2;
741 if( i_alpha == 0xff )
743 BlendI420I420_no_alpha( p_filter, p_dst, p_src,
744 i_x_offset, i_y_offset, i_width, i_height );
749 i_dst_pitch = p_dst->p[Y_PLANE].i_pitch;
750 p_dst_y = p_dst->p[Y_PLANE].p_pixels + i_x_offset +
751 p_filter->fmt_out.video.i_x_offset +
752 p_dst->p[Y_PLANE].i_pitch *
753 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
754 p_dst_u = p_dst->p[U_PLANE].p_pixels + i_x_offset/2 +
755 p_filter->fmt_out.video.i_x_offset/2 +
756 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
757 p_dst->p[U_PLANE].i_pitch;
758 p_dst_v = p_dst->p[V_PLANE].p_pixels + i_x_offset/2 +
759 p_filter->fmt_out.video.i_x_offset/2 +
760 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
761 p_dst->p[V_PLANE].i_pitch;
763 p_src_y = vlc_plane_start( &i_src_pitch, p_src, Y_PLANE,
764 0, 0, &p_filter->fmt_in.video, 1 );
765 p_src_u = vlc_plane_start( NULL, p_src, U_PLANE,
766 0, 0, &p_filter->fmt_in.video, 2 );
767 p_src_v = vlc_plane_start( NULL, p_src, V_PLANE,
768 0, 0, &p_filter->fmt_in.video, 2 );
771 /* Draw until we reach the bottom of the subtitle */
772 for( i_y = 0; i_y < i_height; i_y++,
773 p_dst_y += i_dst_pitch,
774 p_src_y += i_src_pitch )
776 if( b_even_scanline )
778 p_dst_u += i_dst_pitch/2;
779 p_dst_v += i_dst_pitch/2;
781 b_even_scanline = !b_even_scanline;
783 /* Draw until we reach the end of the line */
784 for( i_x = 0; i_x < i_width; i_x++ )
790 p_dst_y[i_x] = vlc_blend( p_src_y[i_x], p_dst_y[i_x], i_alpha );
791 if( b_even_scanline && i_x % 2 == 0 )
793 p_dst_u[i_x/2] = vlc_blend( p_src_u[i_x/2], p_dst_u[i_x/2], i_alpha );
794 p_dst_v[i_x/2] = vlc_blend( p_src_v[i_x/2], p_dst_v[i_x/2], i_alpha );
799 p_src_u += i_src_pitch/2;
800 p_src_v += i_src_pitch/2;
804 static void BlendI420I420_no_alpha( filter_t *p_filter,
805 picture_t *p_dst, picture_t *p_src,
806 int i_x_offset, int i_y_offset,
807 int i_width, int i_height )
809 int i_src_pitch, i_dst_pitch;
810 uint8_t *p_src_y, *p_dst_y;
811 uint8_t *p_src_u, *p_dst_u;
812 uint8_t *p_src_v, *p_dst_v;
814 bool b_even_scanline = i_y_offset % 2;
816 i_dst_pitch = p_dst->p[Y_PLANE].i_pitch;
817 p_dst_y = p_dst->p[Y_PLANE].p_pixels + i_x_offset +
818 p_filter->fmt_out.video.i_x_offset +
819 p_dst->p[Y_PLANE].i_pitch *
820 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
821 p_dst_u = p_dst->p[U_PLANE].p_pixels + i_x_offset/2 +
822 p_filter->fmt_out.video.i_x_offset/2 +
823 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
824 p_dst->p[U_PLANE].i_pitch;
825 p_dst_v = p_dst->p[V_PLANE].p_pixels + i_x_offset/2 +
826 p_filter->fmt_out.video.i_x_offset/2 +
827 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
828 p_dst->p[V_PLANE].i_pitch;
830 p_src_y = vlc_plane_start( &i_src_pitch, p_src, Y_PLANE,
831 0, 0, &p_filter->fmt_in.video, 1 );
832 p_src_u = vlc_plane_start( NULL, p_src, U_PLANE,
833 0, 0, &p_filter->fmt_in.video, 2 );
834 p_src_v = vlc_plane_start( NULL, p_src, V_PLANE,
835 0, 0, &p_filter->fmt_in.video, 2 );
839 /* Draw until we reach the bottom of the subtitle */
840 for( i_y = 0; i_y < i_height;
841 i_y++, p_dst_y += i_dst_pitch, p_src_y += i_src_pitch )
843 /* Completely opaque. Completely overwrite underlying pixel */
844 vlc_memcpy( p_dst_y, p_src_y, i_width );
845 if( b_even_scanline )
847 p_dst_u += i_dst_pitch/2;
848 p_dst_v += i_dst_pitch/2;
852 vlc_memcpy( p_dst_u, p_src_u, i_width/2 );
853 vlc_memcpy( p_dst_v, p_src_v, i_width/2 );
855 b_even_scanline = !b_even_scanline;
858 p_src_u += i_src_pitch/2;
859 p_src_v += i_src_pitch/2;
864 static void BlendI420R16( filter_t *p_filter,
865 picture_t *p_dst_pic, picture_t *p_src,
866 int i_x_offset, int i_y_offset,
867 int i_width, int i_height, int i_alpha )
869 int i_src_pitch, i_dst_pitch;
870 uint8_t *p_dst, *p_src_y;
871 uint8_t *p_src_u, *p_src_v;
872 int i_x, i_y, i_pix_pitch;
875 i_pix_pitch = p_dst_pic->p->i_pixel_pitch;
876 i_dst_pitch = p_dst_pic->p->i_pitch;
877 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
878 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
879 p_dst_pic->p->i_pitch *
880 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
882 p_src_y = vlc_plane_start( &i_src_pitch, p_src, Y_PLANE,
883 0, 0, &p_filter->fmt_in.video, 1 );
884 p_src_u = vlc_plane_start( NULL, p_src, U_PLANE,
885 0, 0, &p_filter->fmt_in.video, 2 );
886 p_src_v = vlc_plane_start( NULL, p_src, V_PLANE,
887 0, 0, &p_filter->fmt_in.video, 2 );
889 /* Draw until we reach the bottom of the subtitle */
890 for( i_y = 0; i_y < i_height; i_y++,
891 p_dst += i_dst_pitch,
892 p_src_y += i_src_pitch )
894 /* Draw until we reach the end of the line */
895 for( i_x = 0; i_x < i_width; i_x++ )
898 yuv_to_rgb( &r, &g, &b,
899 p_src_y[i_x], p_src_u[i_x/2], p_src_v[i_x/2] );
901 vlc_blend_rgb16( (uint16_t*)&p_dst[i_x * i_pix_pitch],
902 (const uint16_t*)&p_dst[i_x * i_pix_pitch],
903 r, g, b, i_alpha, &p_filter->fmt_out.video );
907 p_src_u += i_src_pitch/2;
908 p_src_v += i_src_pitch/2;
913 static void BlendI420R24( filter_t *p_filter,
914 picture_t *p_dst_pic, picture_t *p_src,
915 int i_x_offset, int i_y_offset,
916 int i_width, int i_height, int i_alpha )
918 int i_src_pitch, i_dst_pitch;
919 uint8_t *p_dst, *p_src_y;
920 uint8_t *p_src_u, *p_src_v;
921 int i_x, i_y, i_pix_pitch;
922 int i_rindex, i_gindex, i_bindex;
925 i_pix_pitch = p_dst_pic->p->i_pixel_pitch;
926 i_dst_pitch = p_dst_pic->p->i_pitch;
927 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
928 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
929 p_dst_pic->p->i_pitch *
930 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
932 p_src_y = vlc_plane_start( &i_src_pitch, p_src, Y_PLANE,
933 0, 0, &p_filter->fmt_in.video, 1 );
934 p_src_u = vlc_plane_start( NULL, p_src, U_PLANE,
935 0, 0, &p_filter->fmt_in.video, 2 );
936 p_src_v = vlc_plane_start( NULL, p_src, V_PLANE,
937 0, 0, &p_filter->fmt_in.video, 2 );
939 vlc_rgb_index( &i_rindex, &i_gindex, &i_bindex, &p_filter->fmt_out.video );
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,
944 p_src_y += i_src_pitch, p_src_u += i_src_pitch,
945 p_src_v += i_src_pitch )
947 /* Draw until we reach the end of the line */
948 for( i_x = 0; i_x < i_width; i_x++ )
954 yuv_to_rgb( &r, &g, &b,
955 p_src_y[i_x], p_src_u[i_x/2], p_src_v[i_x/2] );
957 vlc_blend_packed( &p_dst[i_x * i_pix_pitch], &p_dst[i_x * i_pix_pitch],
958 i_rindex, i_gindex, i_bindex, r, g, b, i_alpha, true );
962 p_src_u += i_src_pitch/2;
963 p_src_v += i_src_pitch/2;
968 static void BlendI420YUVPacked( filter_t *p_filter,
969 picture_t *p_dst_pic, picture_t *p_src,
970 int i_x_offset, int i_y_offset,
971 int i_width, int i_height, int i_alpha )
973 int i_src_pitch, i_dst_pitch;
974 uint8_t *p_dst, *p_src_y;
975 uint8_t *p_src_u, *p_src_v;
976 int i_x, i_y, i_pix_pitch;
977 bool b_even = !((i_x_offset + p_filter->fmt_out.video.i_x_offset)%2);
978 int i_l_offset, i_u_offset, i_v_offset;
980 vlc_yuv_packed_index( &i_l_offset, &i_u_offset, &i_v_offset,
981 p_filter->fmt_out.video.i_chroma );
984 i_dst_pitch = p_dst_pic->p->i_pitch;
985 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
986 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
987 p_dst_pic->p->i_pitch *
988 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
990 p_src_y = vlc_plane_start( &i_src_pitch, p_src, Y_PLANE,
991 0, 0, &p_filter->fmt_in.video, 1 );
992 p_src_u = vlc_plane_start( NULL, p_src, U_PLANE,
993 0, 0, &p_filter->fmt_in.video, 2 );
994 p_src_v = vlc_plane_start( NULL, p_src, V_PLANE,
995 0, 0, &p_filter->fmt_in.video, 2 );
997 i_width &= ~1; /* Needs to be a multiple of 2 */
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,
1002 p_src_y += i_src_pitch, p_src_u += i_src_pitch,
1003 p_src_v += i_src_pitch )
1005 /* Draw until we reach the end of the line */
1006 for( i_x = 0; i_x < i_width; i_x++, b_even = !b_even )
1012 vlc_blend_packed( &p_dst[i_x * 2], &p_dst[i_x * 2],
1013 i_l_offset, i_u_offset, i_v_offset,
1014 p_src_y[i_x], p_src_u[i_x/2], p_src_v[i_x/2], i_alpha, b_even );
1018 p_src_u += i_src_pitch/2;
1019 p_src_v += i_src_pitch/2;
1024 /***********************************************************************
1026 ***********************************************************************/
1027 static void BlendPalI420( filter_t *p_filter,
1028 picture_t *p_dst, picture_t *p_src_pic,
1029 int i_x_offset, int i_y_offset,
1030 int i_width, int i_height, int i_alpha )
1032 int i_src_pitch, i_dst_pitch;
1033 uint8_t *p_src, *p_dst_y;
1036 int i_x, i_y, i_trans;
1037 bool b_even_scanline = i_y_offset % 2;
1039 i_dst_pitch = p_dst->p[Y_PLANE].i_pitch;
1040 p_dst_y = p_dst->p[Y_PLANE].p_pixels + i_x_offset +
1041 p_filter->fmt_out.video.i_x_offset +
1042 p_dst->p[Y_PLANE].i_pitch *
1043 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1044 p_dst_u = p_dst->p[U_PLANE].p_pixels + i_x_offset/2 +
1045 p_filter->fmt_out.video.i_x_offset/2 +
1046 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
1047 p_dst->p[U_PLANE].i_pitch;
1048 p_dst_v = p_dst->p[V_PLANE].p_pixels + i_x_offset/2 +
1049 p_filter->fmt_out.video.i_x_offset/2 +
1050 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
1051 p_dst->p[V_PLANE].i_pitch;
1053 i_src_pitch = p_src_pic->p->i_pitch;
1054 p_src = p_src_pic->p->p_pixels + p_filter->fmt_in.video.i_x_offset +
1055 i_src_pitch * p_filter->fmt_in.video.i_y_offset;
1057 #define p_pal p_filter->fmt_in.video.p_palette->palette
1059 /* Draw until we reach the bottom of the subtitle */
1060 for( i_y = 0; i_y < i_height; i_y++,
1061 p_dst_y += i_dst_pitch,
1062 p_src += i_src_pitch,
1063 p_dst_u += b_even_scanline ? i_dst_pitch/2 : 0,
1064 p_dst_v += b_even_scanline ? i_dst_pitch/2 : 0 )
1066 const uint8_t *p_trans = p_src;
1067 b_even_scanline = !b_even_scanline;
1069 /* Draw until we reach the end of the line */
1070 for( i_x = 0; i_x < i_width; i_x++ )
1072 i_trans = vlc_alpha( p_pal[p_trans[i_x]][3], i_alpha );
1077 p_dst_y[i_x] = vlc_blend( p_pal[p_src[i_x]][0], p_dst_y[i_x], i_trans );
1078 if( b_even_scanline && ((i_x % 2) == 0) )
1080 p_dst_u[i_x/2] = vlc_blend( p_pal[p_src[i_x]][1], p_dst_u[i_x/2], i_trans );
1081 p_dst_v[i_x/2] = vlc_blend( p_pal[p_src[i_x]][2], p_dst_v[i_x/2], i_trans );
1088 static void BlendPalYUVPacked( filter_t *p_filter,
1089 picture_t *p_dst_pic, picture_t *p_src_pic,
1090 int i_x_offset, int i_y_offset,
1091 int i_width, int i_height, int i_alpha )
1093 int i_src_pitch, i_dst_pitch;
1094 uint8_t *p_src, *p_dst;
1095 int i_x, i_y, i_pix_pitch, i_trans;
1096 bool b_even = !((i_x_offset + p_filter->fmt_out.video.i_x_offset)%2);
1097 int i_l_offset, i_u_offset, i_v_offset;
1099 vlc_yuv_packed_index( &i_l_offset, &i_u_offset, &i_v_offset,
1100 p_filter->fmt_out.video.i_chroma );
1103 i_dst_pitch = p_dst_pic->p->i_pitch;
1104 p_dst = p_dst_pic->p->p_pixels + i_pix_pitch * (i_x_offset +
1105 p_filter->fmt_out.video.i_x_offset) + p_dst_pic->p->i_pitch *
1106 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1108 i_src_pitch = p_src_pic->p->i_pitch;
1109 p_src = p_src_pic->p->p_pixels + p_filter->fmt_in.video.i_x_offset +
1110 i_src_pitch * p_filter->fmt_in.video.i_y_offset;
1112 i_width &= ~1; /* Needs to be a multiple of 2 */
1114 #define p_pal p_filter->fmt_in.video.p_palette->palette
1116 /* Draw until we reach the bottom of the subtitle */
1117 for( i_y = 0; i_y < i_height; i_y++,
1118 p_dst += i_dst_pitch, p_src += i_src_pitch )
1120 const uint8_t *p_trans = p_src;
1121 /* Draw until we reach the end of the line */
1122 for( i_x = 0; i_x < i_width; i_x++, b_even = !b_even )
1124 i_trans = vlc_alpha( p_pal[p_trans[i_x]][3], i_alpha );
1133 if( p_trans[i_x+1] > 0xaa )
1135 i_u = (p_pal[p_src[i_x]][1] + p_pal[p_src[i_x+1]][1]) >> 1;
1136 i_v = (p_pal[p_src[i_x]][2] + p_pal[p_src[i_x+1]][2]) >> 1;
1140 i_u = p_pal[p_src[i_x]][1];
1141 i_v = p_pal[p_src[i_x]][2];
1144 vlc_blend_packed( &p_dst[i_x * 2], &p_dst[i_x * 2],
1145 i_l_offset, i_u_offset, i_v_offset,
1146 p_pal[p_src[i_x]][0], i_u, i_v, i_trans, true );
1150 p_dst[i_x * 2 + i_l_offset] = vlc_blend( p_pal[p_src[i_x]][0], p_dst[i_x * 2 + i_l_offset], i_trans );
1157 static void BlendPalRV( filter_t *p_filter,
1158 picture_t *p_dst_pic, picture_t *p_src_pic,
1159 int i_x_offset, int i_y_offset,
1160 int i_width, int i_height, int i_alpha )
1162 int i_src_pitch, i_dst_pitch;
1163 uint8_t *p_src, *p_dst;
1164 int i_x, i_y, i_pix_pitch, i_trans;
1165 video_palette_t rgbpalette;
1166 int i_rindex, i_gindex, i_bindex;
1168 i_pix_pitch = p_dst_pic->p->i_pixel_pitch;
1169 i_dst_pitch = p_dst_pic->p->i_pitch;
1170 p_dst = p_dst_pic->p->p_pixels + i_pix_pitch * (i_x_offset +
1171 p_filter->fmt_out.video.i_x_offset) + p_dst_pic->p->i_pitch *
1172 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1174 i_src_pitch = p_src_pic->p->i_pitch;
1175 p_src = p_src_pic->p->p_pixels + p_filter->fmt_in.video.i_x_offset +
1176 i_src_pitch * p_filter->fmt_in.video.i_y_offset;
1178 #define p_pal p_filter->fmt_in.video.p_palette->palette
1179 #define rgbpal rgbpalette.palette
1181 /* Convert palette first */
1182 for( i_y = 0; i_y < p_filter->fmt_in.video.p_palette->i_entries && i_y < 256; i_y++ )
1186 yuv_to_rgb( &r, &g, &b, p_pal[i_y][0], p_pal[i_y][1], p_pal[i_y][2] );
1193 vlc_rgb_index( &i_rindex, &i_gindex, &i_bindex, &p_filter->fmt_out.video );
1195 /* Draw until we reach the bottom of the subtitle */
1196 for( i_y = 0; i_y < i_height; i_y++,
1197 p_dst += i_dst_pitch, p_src += i_src_pitch )
1199 const uint8_t *p_trans = p_src;
1200 /* Draw until we reach the end of the line */
1201 for( i_x = 0; i_x < i_width; i_x++ )
1203 i_trans = vlc_alpha( p_pal[p_trans[i_x]][3], i_alpha );
1208 if( p_filter->fmt_out.video.i_chroma == FCC_RV15 || p_filter->fmt_out.video.i_chroma == FCC_RV16 )
1209 vlc_blend_rgb16( (uint16_t*)&p_dst[i_x * i_pix_pitch],
1210 (const uint16_t*)&p_dst[i_x * i_pix_pitch],
1211 rgbpal[p_src[i_x]][0], rgbpal[p_src[i_x]][1], rgbpal[p_src[i_x]][2],
1213 &p_filter->fmt_out.video );
1215 vlc_blend_packed( &p_dst[i_x * i_pix_pitch], &p_dst[i_x * i_pix_pitch],
1216 i_rindex, i_gindex, i_bindex,
1217 rgbpal[p_src[i_x]][0], rgbpal[p_src[i_x]][1], rgbpal[p_src[i_x]][2],
1226 /***********************************************************************
1228 ***********************************************************************/
1229 static void BlendRGBAI420( filter_t *p_filter,
1230 picture_t *p_dst, picture_t *p_src_pic,
1231 int i_x_offset, int i_y_offset,
1232 int i_width, int i_height, int i_alpha )
1234 int i_src_pitch, i_dst_pitch, i_src_pix_pitch;
1239 int i_x, i_y, i_trans;
1242 bool b_even_scanline = i_y_offset % 2;
1244 i_dst_pitch = p_dst->p[Y_PLANE].i_pitch;
1245 p_dst_y = p_dst->p[Y_PLANE].p_pixels + i_x_offset +
1246 p_filter->fmt_out.video.i_x_offset +
1247 p_dst->p[Y_PLANE].i_pitch *
1248 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1249 p_dst_u = p_dst->p[U_PLANE].p_pixels + i_x_offset/2 +
1250 p_filter->fmt_out.video.i_x_offset/2 +
1251 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
1252 p_dst->p[U_PLANE].i_pitch;
1253 p_dst_v = p_dst->p[V_PLANE].p_pixels + i_x_offset/2 +
1254 p_filter->fmt_out.video.i_x_offset/2 +
1255 ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 *
1256 p_dst->p[V_PLANE].i_pitch;
1258 i_src_pix_pitch = p_src_pic->p->i_pixel_pitch;
1259 i_src_pitch = p_src_pic->p->i_pitch;
1260 p_src = p_src_pic->p->p_pixels +
1261 p_filter->fmt_in.video.i_x_offset * i_src_pix_pitch +
1262 p_src_pic->p->i_pitch * p_filter->fmt_in.video.i_y_offset;
1265 /* Draw until we reach the bottom of the subtitle */
1266 for( i_y = 0; i_y < i_height; i_y++,
1267 p_dst_y += i_dst_pitch,
1268 p_dst_u += b_even_scanline ? i_dst_pitch/2 : 0,
1269 p_dst_v += b_even_scanline ? i_dst_pitch/2 : 0,
1270 p_src += i_src_pitch )
1272 b_even_scanline = !b_even_scanline;
1274 /* Draw until we reach the end of the line */
1275 for( i_x = 0; i_x < i_width; i_x++ )
1277 const int R = p_src[i_x * i_src_pix_pitch + 0];
1278 const int G = p_src[i_x * i_src_pix_pitch + 1];
1279 const int B = p_src[i_x * i_src_pix_pitch + 2];
1281 i_trans = vlc_alpha( p_src[i_x * i_src_pix_pitch + 3], i_alpha );
1286 rgb_to_yuv( &y, &u, &v, R, G, B );
1288 p_dst_y[i_x] = vlc_blend( y, p_dst_y[i_x], i_trans );
1289 if( b_even_scanline && i_x % 2 == 0 )
1291 p_dst_u[i_x/2] = vlc_blend( u, p_dst_u[i_x/2], i_trans );
1292 p_dst_v[i_x/2] = vlc_blend( v, p_dst_v[i_x/2], i_trans );
1298 static void BlendRGBAR24( filter_t *p_filter,
1299 picture_t *p_dst_pic, picture_t *p_src_pic,
1300 int i_x_offset, int i_y_offset,
1301 int i_width, int i_height, int i_alpha )
1303 int i_src_pitch, i_dst_pitch;
1304 uint8_t *p_dst, *p_src;
1305 int i_x, i_y, i_pix_pitch, i_trans, i_src_pix_pitch;
1306 int i_rindex, i_gindex, i_bindex;
1308 i_pix_pitch = p_dst_pic->p->i_pixel_pitch;
1309 i_dst_pitch = p_dst_pic->p->i_pitch;
1310 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
1311 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
1312 p_dst_pic->p->i_pitch *
1313 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1315 i_src_pix_pitch = p_src_pic->p->i_pixel_pitch;
1316 i_src_pitch = p_src_pic->p->i_pitch;
1317 p_src = p_src_pic->p->p_pixels +
1318 p_filter->fmt_in.video.i_x_offset * i_src_pix_pitch +
1319 p_src_pic->p->i_pitch * p_filter->fmt_in.video.i_y_offset;
1321 vlc_rgb_index( &i_rindex, &i_gindex, &i_bindex, &p_filter->fmt_out.video );
1323 /* Draw until we reach the bottom of the subtitle */
1324 for( i_y = 0; i_y < i_height; i_y++,
1325 p_dst += i_dst_pitch, p_src += i_src_pitch )
1327 /* Draw until we reach the end of the line */
1328 for( i_x = 0; i_x < i_width; i_x++ )
1330 const int R = p_src[i_x * i_src_pix_pitch + 0];
1331 const int G = p_src[i_x * i_src_pix_pitch + 1];
1332 const int B = p_src[i_x * i_src_pix_pitch + 2];
1334 i_trans = vlc_alpha( p_src[i_x * i_src_pix_pitch + 3], i_alpha );
1339 vlc_blend_packed( &p_dst[i_x * i_pix_pitch], &p_dst[i_x * i_pix_pitch],
1340 i_rindex, i_gindex, i_bindex,
1341 R, G, B, i_trans, true );
1346 static void BlendRGBAR16( filter_t *p_filter,
1347 picture_t *p_dst_pic, picture_t *p_src_pic,
1348 int i_x_offset, int i_y_offset,
1349 int i_width, int i_height, int i_alpha )
1351 int i_src_pitch, i_dst_pitch;
1352 uint8_t *p_dst, *p_src;
1353 int i_x, i_y, i_pix_pitch, i_trans, i_src_pix_pitch;
1355 i_pix_pitch = p_dst_pic->p->i_pixel_pitch;
1356 i_dst_pitch = p_dst_pic->p->i_pitch;
1357 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
1358 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
1359 p_dst_pic->p->i_pitch *
1360 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1362 i_src_pix_pitch = p_src_pic->p->i_pixel_pitch;
1363 i_src_pitch = p_src_pic->p->i_pitch;
1364 p_src = p_src_pic->p->p_pixels +
1365 p_filter->fmt_in.video.i_x_offset * i_src_pix_pitch +
1366 p_src_pic->p->i_pitch * p_filter->fmt_in.video.i_y_offset;
1368 /* Draw until we reach the bottom of the subtitle */
1369 for( i_y = 0; i_y < i_height; i_y++,
1370 p_dst += i_dst_pitch, p_src += i_src_pitch )
1372 /* Draw until we reach the end of the line */
1373 for( i_x = 0; i_x < i_width; i_x++ )
1375 const int R = p_src[i_x * i_src_pix_pitch + 0];
1376 const int G = p_src[i_x * i_src_pix_pitch + 1];
1377 const int B = p_src[i_x * i_src_pix_pitch + 2];
1379 i_trans = vlc_alpha( p_src[i_x * i_src_pix_pitch + 3], i_alpha );
1384 vlc_blend_rgb16( (uint16_t*)&p_dst[i_x * i_pix_pitch],
1385 (const uint16_t*)&p_dst[i_x * i_pix_pitch],
1386 R, G, B, i_trans, &p_filter->fmt_out.video );
1391 static void BlendRGBAYUVPacked( filter_t *p_filter,
1392 picture_t *p_dst_pic, picture_t *p_src_pic,
1393 int i_x_offset, int i_y_offset,
1394 int i_width, int i_height, int i_alpha )
1396 int i_src_pitch, i_dst_pitch, i_src_pix_pitch;
1397 uint8_t *p_dst, *p_src;
1399 int i_x, i_y, i_pix_pitch, i_trans;
1400 bool b_even = !((i_x_offset + p_filter->fmt_out.video.i_x_offset)%2);
1401 int i_l_offset, i_u_offset, i_v_offset;
1404 vlc_yuv_packed_index( &i_l_offset, &i_u_offset, &i_v_offset,
1405 p_filter->fmt_out.video.i_chroma );
1408 i_dst_pitch = p_dst_pic->p->i_pitch;
1409 p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +
1410 p_filter->fmt_out.video.i_x_offset * i_pix_pitch +
1411 p_dst_pic->p->i_pitch *
1412 ( i_y_offset + p_filter->fmt_out.video.i_y_offset );
1414 i_src_pix_pitch = p_src_pic->p->i_pixel_pitch;
1415 i_src_pitch = p_src_pic->p->i_pitch;
1416 p_src = p_src_pic->p->p_pixels +
1417 p_filter->fmt_in.video.i_x_offset * i_src_pitch +
1418 p_src_pic->p->i_pitch * p_filter->fmt_in.video.i_y_offset;
1420 i_width &= ~1; /* Needs to be a multiple of 2 */
1422 /* Draw until we reach the bottom of the subtitle */
1423 for( i_y = 0; i_y < i_height; i_y++, p_trans += i_src_pitch,
1424 p_dst += i_dst_pitch,
1425 p_src += i_src_pitch )
1427 /* Draw until we reach the end of the line */
1428 for( i_x = 0; i_x < i_width; i_x++, b_even = !b_even )
1430 const int R = p_src[i_x * i_src_pix_pitch + 0];
1431 const int G = p_src[i_x * i_src_pix_pitch + 1];
1432 const int B = p_src[i_x * i_src_pix_pitch + 2];
1434 i_trans = vlc_alpha( p_src[i_x * i_src_pix_pitch + 3], i_alpha );
1439 rgb_to_yuv( &y, &u, &v, R, G, B );
1441 vlc_blend_packed( &p_dst[i_x * 2], &p_dst[i_x * 2],
1442 i_l_offset, i_u_offset, i_v_offset,
1443 y, u, v, i_trans, b_even );