⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 blend.c

📁 VLC Player Source Code
💻 C
📖 第 1 页 / 共 5 页
字号:
                               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,                                 picture_t *p_picture,                                 int i_plane,                                 int i_x_offset, int i_y_offset,                                 const video_format_t *p_fmt,                                 int r ){    const int i_pitch = p_picture->p[i_plane].i_pitch;    uint8_t *p_pixels = p_picture->p[i_plane].p_pixels;    const int i_dx = ( i_x_offset + p_fmt->i_x_offset ) / r;    const int i_dy = ( i_y_offset + p_fmt->i_y_offset ) / r;    if( pi_pitch )        *pi_pitch = i_pitch;    return &p_pixels[ i_dy * i_pitch + i_dx ];}static void vlc_yuv_packed_index( int *pi_y, int *pi_u, int *pi_v, vlc_fourcc_t i_chroma ){    static const struct {        vlc_fourcc_t chroma;        int y, u ,v;    } p_index[] = {        { FCC_YUY2, 0, 1, 3 },        { FCC_UYVY, 1, 0, 2 },        { FCC_YVYU, 0, 3, 1 },        { 0, 0, 0, 0 }    };    int i;    for( i = 0; p_index[i].chroma != 0; i++ )    {        if( p_index[i].chroma == i_chroma )            break;    }    *pi_y = p_index[i].y;    *pi_u = p_index[i].u;    *pi_v = p_index[i].v;}static void vlc_blend_packed( uint8_t *p_dst, const uint8_t *p_src,                              int i_offset0, int i_offset1, int i_offset2,                              int c0, int c1, int c2, int i_alpha,                              bool b_do12 ){    p_dst[i_offset0] = vlc_blend( c0, p_src[i_offset0], i_alpha );    if( b_do12 )    {        p_dst[i_offset1] = vlc_blend( c1, p_src[i_offset1], i_alpha );        p_dst[i_offset2] = vlc_blend( c2, p_src[i_offset2], i_alpha );    }}static void vlc_blend_rgb16( uint16_t *p_dst, const uint16_t *p_src,                             int R, int G, int B, int i_alpha,                             const video_format_t *p_fmt ){    const int i_pix = *p_src;    const int r = ( i_pix & p_fmt->i_rmask ) >> p_fmt->i_lrshift;    const int g = ( i_pix & p_fmt->i_gmask ) >> p_fmt->i_lgshift;    const int b = ( i_pix & p_fmt->i_bmask ) >> p_fmt->i_lbshift;    *p_dst = ( vlc_blend( R >> p_fmt->i_rrshift, r, i_alpha ) << p_fmt->i_lrshift ) |             ( vlc_blend( G >> p_fmt->i_rgshift, g, i_alpha ) << p_fmt->i_lgshift ) |             ( vlc_blend( B >> p_fmt->i_rbshift, b, i_alpha ) << p_fmt->i_lbshift );}static void vlc_rgb_index( int *pi_rindex, int *pi_gindex, int *pi_bindex,                           const video_format_t *p_fmt ){    if( p_fmt->i_chroma != FCC_RV24 && p_fmt->i_chroma != FCC_RV32 )        return;    /* XXX it will works only if mask are 8 bits aligned */#ifdef WORDS_BIGENDIAN    const int i_mask_bits = p_fmt->i_chroma == FCC_RV24 ? 24 : 32;    *pi_rindex = ( i_mask_bits - p_fmt->i_lrshift ) / 8;    *pi_gindex = ( i_mask_bits - p_fmt->i_lgshift ) / 8;    *pi_bindex = ( i_mask_bits - p_fmt->i_lbshift ) / 8;#else    *pi_rindex = p_fmt->i_lrshift / 8;    *pi_gindex = p_fmt->i_lgshift / 8;    *pi_bindex = p_fmt->i_lbshift / 8;#endif}/*********************************************************************** * YUVA ***********************************************************************/static void BlendYUVAI420( filter_t *p_filter, picture_t *p_dst,                           picture_t *p_dst_orig, picture_t *p_src,                           int i_x_offset, int i_y_offset,                           int i_width, int i_height, int i_alpha ){    int i_src1_pitch, i_src2_pitch, i_dst_pitch;    uint8_t *p_src1_y, *p_src2_y, *p_dst_y;    uint8_t *p_src1_u, *p_src2_u, *p_dst_u;    uint8_t *p_src1_v, *p_src2_v, *p_dst_v;    uint8_t *p_trans;    int i_x, i_y, i_trans = 0;    bool b_even_scanline = i_y_offset % 2;    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,                               i_x_offset, i_y_offset, &p_filter->fmt_out.video, 2 );    p_dst_v = vlc_plane_start( NULL, p_dst, V_PLANE,                               i_x_offset, i_y_offset, &p_filter->fmt_out.video, 2 );    p_src1_y = vlc_plane_start( &i_src1_pitch, p_dst_orig, Y_PLANE,                                i_x_offset, i_y_offset, &p_filter->fmt_out.video, 1 );    p_src1_u = vlc_plane_start( NULL, p_dst_orig, U_PLANE,                                i_x_offset, i_y_offset, &p_filter->fmt_out.video, 2 );    p_src1_v = vlc_plane_start( NULL, p_dst_orig, V_PLANE,                                i_x_offset, i_y_offset, &p_filter->fmt_out.video, 2 );    p_src2_y = vlc_plane_start( &i_src2_pitch, p_src, Y_PLANE,                                0, 0, &p_filter->fmt_in.video, 1 );    p_src2_u = vlc_plane_start( NULL, p_src, U_PLANE,                                0, 0, &p_filter->fmt_in.video, 2 );    p_src2_v = vlc_plane_start( NULL, p_src, V_PLANE,                                0, 0, &p_filter->fmt_in.video, 2 );    p_trans = vlc_plane_start( NULL, p_src, A_PLANE,                               0, 0, &p_filter->fmt_in.video, 1 );    /* Draw until we reach the bottom of the subtitle */    for( i_y = 0; i_y < i_height; i_y++, p_trans += i_src2_pitch,         p_dst_y += i_dst_pitch, p_src1_y += i_src1_pitch,         p_src2_y += i_src2_pitch,         p_dst_u += b_even_scanline ? i_dst_pitch/2 : 0,         p_src1_u += b_even_scanline ? i_src1_pitch/2 : 0,         p_src2_u += i_src2_pitch,         p_dst_v += b_even_scanline ? i_dst_pitch/2 : 0,         p_src1_v += b_even_scanline ? i_src1_pitch/2 : 0,         p_src2_v += i_src2_pitch )    {        b_even_scanline = !b_even_scanline;        /* Draw until we reach the end of the line */        for( i_x = 0; i_x < i_width; i_x++ )        {            if( p_trans )                i_trans = vlc_alpha( p_trans[i_x], i_alpha );            if( !i_trans )                continue;            /* Blending */            p_dst_y[i_x] = vlc_blend( p_src2_y[i_x], p_src1_y[i_x], i_trans );            if( b_even_scanline && i_x % 2 == 0 )            {                p_dst_u[i_x/2] = vlc_blend( p_src2_u[i_x], p_src1_u[i_x/2], i_trans );                p_dst_v[i_x/2] = vlc_blend( p_src2_v[i_x], p_src1_v[i_x/2], i_trans );            }        }    }}static void BlendYUVARV16( filter_t *p_filter, picture_t *p_dst_pic,                           picture_t *p_dst_orig, picture_t *p_src,                           int i_x_offset, int i_y_offset,                           int i_width, int i_height, int i_alpha ){    int i_src1_pitch, i_src2_pitch, i_dst_pitch;    uint8_t *p_dst, *p_src1, *p_src2_y;    uint8_t *p_src2_u, *p_src2_v;    uint8_t *p_trans;    int i_x, i_y, i_pix_pitch, i_trans = 0;    int r, g, b;    i_pix_pitch = p_dst_pic->p->i_pixel_pitch;    i_dst_pitch = p_dst_pic->p->i_pitch;    p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +            p_filter->fmt_out.video.i_x_offset * i_pix_pitch +            p_dst_pic->p->i_pitch *            ( i_y_offset + p_filter->fmt_out.video.i_y_offset );    i_src1_pitch = p_dst_orig->p[Y_PLANE].i_pitch;    p_src1 = p_dst_orig->p->p_pixels + i_x_offset * i_pix_pitch +               p_filter->fmt_out.video.i_x_offset * i_pix_pitch +               p_dst_orig->p->i_pitch *               ( i_y_offset + p_filter->fmt_out.video.i_y_offset );    p_src2_y = vlc_plane_start( &i_src2_pitch, p_src, Y_PLANE,                                0, 0, &p_filter->fmt_in.video, 1 );    p_src2_u = vlc_plane_start( NULL, p_src, U_PLANE,                                0, 0, &p_filter->fmt_in.video, 2 );    p_src2_v = vlc_plane_start( NULL, p_src, V_PLANE,                                0, 0, &p_filter->fmt_in.video, 2 );    p_trans = vlc_plane_start( NULL, p_src, A_PLANE,                               0, 0, &p_filter->fmt_in.video, 1 );    /* Draw until we reach the bottom of the subtitle */    for( i_y = 0; i_y < i_height; i_y++, p_trans += i_src2_pitch,         p_dst += i_dst_pitch, p_src1 += i_src1_pitch,         p_src2_y += i_src2_pitch, p_src2_u += i_src2_pitch,         p_src2_v += i_src2_pitch )    {        /* Draw until we reach the end of the line */        for( i_x = 0; i_x < i_width; i_x++ )        {            if( p_trans )                i_trans = vlc_alpha( p_trans[i_x], i_alpha );            if( !i_trans )                continue;            /* Blending */            yuv_to_rgb( &r, &g, &b,                        p_src2_y[i_x], p_src2_u[i_x], p_src2_v[i_x] );            vlc_blend_rgb16( (uint16_t*)&p_dst[i_x * i_pix_pitch],                             (const uint16_t*)&p_src1[i_x * i_pix_pitch],                             r, g, b, i_trans, &p_filter->fmt_out.video );        }    }}static void BlendYUVARV24( filter_t *p_filter, picture_t *p_dst_pic,                           picture_t *p_dst_orig, picture_t *p_src,                           int i_x_offset, int i_y_offset,                           int i_width, int i_height, int i_alpha ){    int i_src1_pitch, i_src2_pitch, i_dst_pitch;    uint8_t *p_dst, *p_src1, *p_src2_y;    uint8_t *p_src2_u, *p_src2_v;    uint8_t *p_trans;    int i_x, i_y, i_pix_pitch, i_trans = 0;    int r, g, b;    i_pix_pitch = p_dst_pic->p->i_pixel_pitch;    i_dst_pitch = p_dst_pic->p->i_pitch;    p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch +            p_filter->fmt_out.video.i_x_offset * i_pix_pitch +            p_dst_pic->p->i_pitch *            ( i_y_offset + p_filter->fmt_out.video.i_y_offset );    i_src1_pitch = p_dst_orig->p->i_pitch;    p_src1 = p_dst_orig->p->p_pixels + i_x_offset * i_pix_pitch +               p_filter->fmt_out.video.i_x_offset * i_pix_pitch +               p_dst_orig->p->i_pitch *               ( i_y_offset + p_filter->fmt_out.video.i_y_offset );    p_src2_y = vlc_plane_start( &i_src2_pitch, p_src, Y_PLANE,                                0, 0, &p_filter->fmt_in.video, 1 );    p_src2_u = vlc_plane_start( NULL, p_src, U_PLANE,                                0, 0, &p_filter->fmt_in.video, 2 );    p_src2_v = vlc_plane_start( NULL, p_src, V_PLANE,                                0, 0, &p_filter->fmt_in.video, 2 );    p_trans = vlc_plane_start( NULL, p_src, A_PLANE,                               0, 0, &p_filter->fmt_in.video, 1 );    if( (i_pix_pitch == 4)     && (((((intptr_t)p_dst)|((intptr_t)p_src1)|i_dst_pitch|i_src1_pitch)          & 3) == 0) )    {        /*        ** if picture pixels are 32 bits long and lines addresses are 32 bit        ** aligned, optimize rendering        */        uint32_t *p32_dst = (uint32_t *)p_dst;        uint32_t i32_dst_pitch = (uint32_t)(i_dst_pitch>>2);        uint32_t *p32_src1 = (uint32_t *)p_src1;        uint32_t i32_src1_pitch = (uint32_t)(i_src1_pitch>>2);        int i_rshift, i_gshift, i_bshift;        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;        i_rshift = p_filter->fmt_out.video.i_lrshift;        i_gshift = p_filter->fmt_out.video.i_lgshift;        i_bshift = p_filter->fmt_out.video.i_lbshift;        /* Draw until we reach the bottom of the subtitle */        for( i_y = 0; i_y < i_height; i_y++, p_trans += i_src2_pitch,             p32_dst += i32_dst_pitch, p32_src1 += i32_src1_pitch,             p_src2_y += i_src2_pitch, p_src2_u += i_src2_pitch,             p_src2_v += i_src2_pitch )        {            /* Draw until we reach the end of the line */            for( i_x = 0; i_x < i_width; i_x++ )            {                if( p_trans )                    i_trans = vlc_alpha( p_trans[i_x], i_alpha );                if( !i_trans )                    continue;                if( i_trans == MAX_TRANS )                {                    /* Completely opaque. Completely overwrite underlying pixel */                    yuv_to_rgb( &r, &g, &b,                                p_src2_y[i_x], p_src2_u[i_x], p_src2_v[i_x] );                    p32_dst[i_x] = (r<<i_rshift) |                                   (g<<i_gshift) |                                   (b<<i_bshift);                }                else                {                    /* Blending */                    uint32_t i_pix_src1 = p32_src1[i_x];                    yuv_to_rgb( &r, &g, &b,                                p_src2_y[i_x], p_src2_u[i_x], p_src2_v[i_x] );                    p32_dst[i_x] = ( vlc_blend( r, (i_pix_src1 & i_rmask)>>i_rshift, i_trans ) << i_rshift ) |                                   ( vlc_blend( g, (i_pix_src1 & i_gmask)>>i_gshift, i_trans ) << i_gshift ) |

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -