X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fvideo_filter%2Fblend.c;h=aff38f49449677741f03981401a65f69643b0893;hb=1339e3572a7e8c643133a3261021b033e8e80fbf;hp=530be44c88b59c7371f1ee41cc819346a1a585a5;hpb=b522668d6b34f052afb9cc0a5d7d5f307abe0e5f;p=vlc diff --git a/modules/video_filter/blend.c b/modules/video_filter/blend.c index 530be44c88..aff38f4944 100644 --- a/modules/video_filter/blend.c +++ b/modules/video_filter/blend.c @@ -33,6 +33,7 @@ #include #include #include +#include "filter_picture.h" /***************************************************************************** * Module descriptor @@ -233,7 +234,7 @@ static void Blend( filter_t *p_filter, video_format_FixRgb( &p_filter->fmt_in.video ); #if 0 - msg_Dbg( p_filter, "chroma: %4.4s -> %4.4s\n", + msg_Dbg( p_filter, "chroma: %4.4s -> %4.4s", (char *)&p_filter->fmt_in.video.i_chroma, (char *)&p_filter->fmt_out.video.i_chroma ); #endif @@ -248,15 +249,6 @@ static void Blend( filter_t *p_filter, /*********************************************************************** * Utils ***********************************************************************/ -static inline uint8_t vlc_uint8( int v ) -{ - if( v > 255 ) - return 255; - else if( v < 0 ) - return 0; - return v; -} - #define MAX_TRANS 255 #define TRANS_BITS 8 @@ -277,39 +269,6 @@ static inline int vlc_alpha( int t, int a ) return (t * a) / 255; } -static inline void yuv_to_rgb( int *r, int *g, int *b, - uint8_t y1, uint8_t u1, uint8_t v1 ) -{ - /* macros used for YUV pixel conversions */ -# define SCALEBITS 10 -# define ONE_HALF (1 << (SCALEBITS - 1)) -# define FIX(x) ((int) ((x) * (1<> SCALEBITS ); - *g = vlc_uint8( (y + g_add) >> SCALEBITS ); - *b = vlc_uint8( (y + b_add) >> SCALEBITS ); -#undef FIX -#undef ONE_HALF -#undef SCALEBITS -} - -static inline void rgb_to_yuv( uint8_t *y, uint8_t *u, uint8_t *v, - int r, int g, int b ) -{ - *y = ( ( ( 66 * r + 129 * g + 25 * b + 128 ) >> 8 ) + 16 ); - *u = ( ( -38 * r - 74 * g + 112 * b + 128 ) >> 8 ) + 128 ; - *v = ( ( 112 * r - 94 * g - 18 * b + 128 ) >> 8 ) + 128 ; -} - static uint8_t *vlc_plane_start( int *pi_pitch, const picture_t *p_picture, int i_plane, @@ -414,11 +373,13 @@ static void BlendYUVAI420( filter_t *p_filter, int i_x, i_y, i_trans = 0; bool b_even_scanline = i_y_offset % 2; + bool b_swap_up = vlc_fourcc_AreUVPlanesSwapped( p_filter->fmt_out.video.i_chroma, + VLC_CODEC_I420 ); p_dst_y = vlc_plane_start( &i_dst_pitch, p_dst, Y_PLANE, i_x_offset, i_y_offset, &p_filter->fmt_out.video, 1 ); - p_dst_u = vlc_plane_start( NULL, p_dst, U_PLANE, + p_dst_u = vlc_plane_start( NULL, p_dst, b_swap_up ? V_PLANE : U_PLANE, i_x_offset, i_y_offset, &p_filter->fmt_out.video, 2 ); - p_dst_v = vlc_plane_start( NULL, p_dst, V_PLANE, + p_dst_v = vlc_plane_start( NULL, p_dst, b_swap_up ? U_PLANE : V_PLANE, i_x_offset, i_y_offset, &p_filter->fmt_out.video, 2 ); p_src_y = vlc_plane_start( &i_src_pitch, p_src, Y_PLANE, @@ -602,12 +563,6 @@ static void BlendYUVARV24( filter_t *p_filter, else { int i_rindex, i_gindex, i_bindex; - uint32_t i_rmask, i_gmask, i_bmask; - - i_rmask = p_filter->fmt_out.video.i_rmask; - i_gmask = p_filter->fmt_out.video.i_gmask; - i_bmask = p_filter->fmt_out.video.i_bmask; - vlc_rgb_index( &i_rindex, &i_gindex, &i_bindex, &p_filter->fmt_out.video ); /* Draw until we reach the bottom of the subtitle */ @@ -733,20 +688,23 @@ static void BlendI420I420( filter_t *p_filter, return; } - + bool b_swap_up = vlc_fourcc_AreUVPlanesSwapped( p_filter->fmt_out.video.i_chroma, + VLC_CODEC_I420 ); i_dst_pitch = p_dst->p[Y_PLANE].i_pitch; p_dst_y = p_dst->p[Y_PLANE].p_pixels + i_x_offset + p_filter->fmt_out.video.i_x_offset + p_dst->p[Y_PLANE].i_pitch * ( i_y_offset + p_filter->fmt_out.video.i_y_offset ); - p_dst_u = p_dst->p[U_PLANE].p_pixels + i_x_offset/2 + + const int i_u_plane = b_swap_up ? V_PLANE : U_PLANE; + p_dst_u = p_dst->p[i_u_plane].p_pixels + i_x_offset/2 + p_filter->fmt_out.video.i_x_offset/2 + ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 * - p_dst->p[U_PLANE].i_pitch; - p_dst_v = p_dst->p[V_PLANE].p_pixels + i_x_offset/2 + + p_dst->p[i_u_plane].i_pitch; + const int i_v_plane = b_swap_up ? U_PLANE : V_PLANE; + p_dst_v = p_dst->p[i_v_plane].p_pixels + i_x_offset/2 + p_filter->fmt_out.video.i_x_offset/2 + ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 * - p_dst->p[V_PLANE].i_pitch; + p_dst->p[i_v_plane].i_pitch; p_src_y = vlc_plane_start( &i_src_pitch, p_src, Y_PLANE, 0, 0, &p_filter->fmt_in.video, 1 ); @@ -801,19 +759,23 @@ static void BlendI420I420_no_alpha( filter_t *p_filter, int i_y; bool b_even_scanline = i_y_offset % 2; + bool b_swap_up = vlc_fourcc_AreUVPlanesSwapped( p_filter->fmt_out.video.i_chroma, + VLC_CODEC_I420 ); i_dst_pitch = p_dst->p[Y_PLANE].i_pitch; p_dst_y = p_dst->p[Y_PLANE].p_pixels + i_x_offset + p_filter->fmt_out.video.i_x_offset + p_dst->p[Y_PLANE].i_pitch * ( i_y_offset + p_filter->fmt_out.video.i_y_offset ); - p_dst_u = p_dst->p[U_PLANE].p_pixels + i_x_offset/2 + + const int i_u_plane = b_swap_up ? V_PLANE : U_PLANE; + p_dst_u = p_dst->p[i_u_plane].p_pixels + i_x_offset/2 + p_filter->fmt_out.video.i_x_offset/2 + ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 * - p_dst->p[U_PLANE].i_pitch; - p_dst_v = p_dst->p[V_PLANE].p_pixels + i_x_offset/2 + + p_dst->p[i_u_plane].i_pitch; + const int i_v_plane = b_swap_up ? U_PLANE : V_PLANE; + p_dst_v = p_dst->p[i_v_plane].p_pixels + i_x_offset/2 + p_filter->fmt_out.video.i_x_offset/2 + ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 * - p_dst->p[V_PLANE].i_pitch; + p_dst->p[i_v_plane].i_pitch; p_src_y = vlc_plane_start( &i_src_pitch, p_src, Y_PLANE, 0, 0, &p_filter->fmt_in.video, 1 ); @@ -1023,19 +985,23 @@ static void BlendPalI420( filter_t *p_filter, int i_x, i_y, i_trans; bool b_even_scanline = i_y_offset % 2; + bool b_swap_up = vlc_fourcc_AreUVPlanesSwapped( p_filter->fmt_out.video.i_chroma, + VLC_CODEC_I420 ); i_dst_pitch = p_dst->p[Y_PLANE].i_pitch; p_dst_y = p_dst->p[Y_PLANE].p_pixels + i_x_offset + p_filter->fmt_out.video.i_x_offset + p_dst->p[Y_PLANE].i_pitch * ( i_y_offset + p_filter->fmt_out.video.i_y_offset ); - p_dst_u = p_dst->p[U_PLANE].p_pixels + i_x_offset/2 + + const int i_u_plane = b_swap_up ? V_PLANE : U_PLANE; + p_dst_u = p_dst->p[i_u_plane].p_pixels + i_x_offset/2 + p_filter->fmt_out.video.i_x_offset/2 + ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 * - p_dst->p[U_PLANE].i_pitch; - p_dst_v = p_dst->p[V_PLANE].p_pixels + i_x_offset/2 + + p_dst->p[i_u_plane].i_pitch; + const int i_v_plane = b_swap_up ? U_PLANE : V_PLANE; + p_dst_v = p_dst->p[i_v_plane].p_pixels + i_x_offset/2 + p_filter->fmt_out.video.i_x_offset/2 + ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 * - p_dst->p[V_PLANE].i_pitch; + p_dst->p[i_v_plane].i_pitch; i_src_pitch = p_src_pic->p->i_pitch; p_src = p_src_pic->p->p_pixels + p_filter->fmt_in.video.i_x_offset + @@ -1226,20 +1192,23 @@ static void BlendRGBAI420( filter_t *p_filter, uint8_t y, u, v; bool b_even_scanline = i_y_offset % 2; - + bool b_swap_up = vlc_fourcc_AreUVPlanesSwapped( p_filter->fmt_out.video.i_chroma, + VLC_CODEC_I420 ); i_dst_pitch = p_dst->p[Y_PLANE].i_pitch; p_dst_y = p_dst->p[Y_PLANE].p_pixels + i_x_offset + p_filter->fmt_out.video.i_x_offset + p_dst->p[Y_PLANE].i_pitch * ( i_y_offset + p_filter->fmt_out.video.i_y_offset ); - p_dst_u = p_dst->p[U_PLANE].p_pixels + i_x_offset/2 + + const int i_u_plane = b_swap_up ? V_PLANE : U_PLANE; + p_dst_u = p_dst->p[i_u_plane].p_pixels + i_x_offset/2 + p_filter->fmt_out.video.i_x_offset/2 + ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 * - p_dst->p[U_PLANE].i_pitch; - p_dst_v = p_dst->p[V_PLANE].p_pixels + i_x_offset/2 + + p_dst->p[i_u_plane].i_pitch; + const int i_v_plane = b_swap_up ? U_PLANE : V_PLANE; + p_dst_v = p_dst->p[i_v_plane].p_pixels + i_x_offset/2 + p_filter->fmt_out.video.i_x_offset/2 + ( i_y_offset + p_filter->fmt_out.video.i_y_offset ) / 2 * - p_dst->p[V_PLANE].i_pitch; + p_dst->p[i_v_plane].i_pitch; i_src_pix_pitch = p_src_pic->p->i_pixel_pitch; i_src_pitch = p_src_pic->p->i_pitch;