Changeset 2bc5973b7e1c493aadd33c37a3c8a1d7b0e068b7

Show
Ignore:
Timestamp:
01/04/07 22:22:01 (2 years ago)
Author:
Antoine Cellerier <dionoea@videolan.org>
git-committer:
Antoine Cellerier <dionoea@videolan.org> 1175458921 +0000
git-parent:

[bc63ebc2ee1abb1b8a3cd49c1ed25128a3159ad2]

git-author:
Antoine Cellerier <dionoea@videolan.org> 1175458921 +0000
Message:

Untested RGBA -> RV16 blending (I420 and RV24 work fine).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/video_filter/blend.c

    r3d1de17 r2bc5973  
    4444static void CloseFilter( vlc_object_t * ); 
    4545 
     46static void Blend( filter_t *, picture_t *, picture_t *, picture_t *, 
     47                   int, int, int ); 
     48 
    4649/* TODO i_alpha support for BlendR16 */ 
    4750/* YUVA */ 
    48 static void Blend( filter_t *, picture_t *, picture_t *, picture_t *, 
    49                    int, int, int ); 
    5051static void BlendI420( filter_t *, picture_t *, picture_t *, picture_t *, 
    5152                       int, int, int, int, int ); 
     
    6869static void BlendRGBAI420( filter_t *, picture_t *, picture_t *, picture_t *, 
    6970                           int, int, int, int, int ); 
     71static void BlendRGBAR16( filter_t *, picture_t *, picture_t *, picture_t *, 
     72                          int, int, int, int, int ); 
    7073static void BlendRGBAR24( filter_t *, picture_t *, picture_t *, picture_t *, 
    7174                          int, int, int, int, int ); 
     
    107110        ( out_chroma != VLC_FOURCC('I','4','2','0') && 
    108111          out_chroma != VLC_FOURCC('Y','V','1','2') && 
     112          out_chroma != VLC_FOURCC('R','V','1','6') && 
    109113          out_chroma != VLC_FOURCC('R','V','2','4') && 
    110114          out_chroma != VLC_FOURCC('R','V','3','2' ) ) ) 
     
    162166 
    163167    if( i_width <= 0 || i_height <= 0 ) return; 
     168 
     169#if 0 
     170    printf( "chroma: %4.4s -> %4.4s\n", 
     171             (char *)&p_filter->fmt_in.video.i_chroma, 
     172             (char *)&p_filter->fmt_out.video.i_chroma ); 
     173#endif 
    164174 
    165175    switch( p_filter->fmt_in.video.i_chroma ) 
     
    232242                                  i_width, i_height, i_alpha ); 
    233243                    return; 
    234             } 
    235     } 
    236  
    237     msg_Dbg( p_filter, "no matching alpha blending routine" ); 
     244                case VLC_FOURCC('R','V','1','6'): 
     245                    BlendRGBAR16( p_filter, p_dst, p_dst_orig, p_src, 
     246                                  i_x_offset, i_y_offset, 
     247                                  i_width, i_height, i_alpha ); 
     248                    return; 
     249            } 
     250    } 
     251 
     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 ); 
    238256} 
    239257 
     
    11521170} 
    11531171 
    1154 static void BlendRGBAR24( filter_t *p_filter, picture_t *p_dst_pic, 
     1172static void BlendRGBAR16( filter_t *p_filter, picture_t *p_dst_pic, 
    11551173                          picture_t *p_dst_orig, picture_t *p_src, 
    11561174                          int i_x_offset, int i_y_offset, 
     
    12291247    return; 
    12301248} 
     1249 
     1250static void BlendRGBAR24( filter_t *p_filter, picture_t *p_dst_pic, 
     1251                          picture_t *p_dst_orig, picture_t *p_src, 
     1252                          int i_x_offset, int i_y_offset, 
     1253                          int i_width, int i_height, int i_alpha ) 
     1254{ 
     1255    int i_src1_pitch, i_src2_pitch, i_dst_pitch; 
     1256    uint8_t *p_dst, *p_src1, *p_src2; 
     1257    int i_x, i_y, i_pix_pitch, i_trans, i_src_pix_pitch; 
     1258    uint16_t i_pix; 
     1259 
     1260    i_pix_pitch = p_dst_pic->p->i_pixel_pitch; 
     1261    i_dst_pitch = p_dst_pic->p->i_pitch; 
     1262    p_dst = p_dst_pic->p->p_pixels + i_x_offset * i_pix_pitch + 
     1263            p_filter->fmt_out.video.i_x_offset * i_pix_pitch + 
     1264            p_dst_pic->p->i_pitch * 
     1265            ( i_y_offset + p_filter->fmt_out.video.i_y_offset ); 
     1266 
     1267    i_src1_pitch = p_dst_orig->p->i_pitch; 
     1268    p_src1 = p_dst_orig->p->p_pixels + i_x_offset * i_pix_pitch + 
     1269             p_filter->fmt_out.video.i_x_offset * i_pix_pitch + 
     1270             p_dst_orig->p->i_pitch * 
     1271             ( i_y_offset + p_filter->fmt_out.video.i_y_offset ); 
     1272 
     1273    i_src_pix_pitch = p_src->p->i_pixel_pitch; 
     1274    i_src2_pitch = p_src->p->i_pitch; 
     1275    p_src2 = p_src->p->p_pixels + 
     1276             p_filter->fmt_in.video.i_x_offset * i_pix_pitch + 
     1277             p_src->p->i_pitch * p_filter->fmt_in.video.i_y_offset; 
     1278 
     1279#define MAX_TRANS 255 
     1280#define TRANS_BITS  8 
     1281 
     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 ) 
     1285    { 
     1286        /* Draw until we reach the end of the line */ 
     1287        for( i_x = 0; i_x < i_width; i_x++ ) 
     1288        { 
     1289#define     R         ( p_src2[i_x * i_src_pix_pitch + 0] ) 
     1290#define     G         ( p_src2[i_x * i_src_pix_pitch + 1] ) 
     1291#define     B         ( p_src2[i_x * i_src_pix_pitch + 2] ) 
     1292            i_trans = ( p_src2[i_x * i_src_pix_pitch + 3] * i_alpha ) / 255; 
     1293            if( !i_trans ) 
     1294            { 
     1295                /* Completely transparent. Don't change pixel */ 
     1296                continue; 
     1297            } 
     1298            else if( i_trans == MAX_TRANS ) 
     1299            { 
     1300                /* Completely opaque. Completely overwrite underlying pixel */ 
     1301                *((uint16_t *)(&p_dst[i_x * i_pix_pitch])) = ((R >> 3) << 11) | ((G >> 2) << 5) | (B >> 3); 
     1302                continue; 
     1303            } 
     1304 
     1305            /* Blending */ 
     1306            i_pix = *((uint16_t *)(&p_dst[i_x * i_pix_pitch])); 
     1307            *((uint16_t *)(&p_dst[i_x * i_pix_pitch])) = 
     1308                ( ( ( (R >> 3)*i_trans 
     1309                    + (i_pix >> 11) * (MAX_TRANS - i_trans) ) 
     1310                    >> TRANS_BITS ) << 11 ) 
     1311              | ( ( ( (G >> 2)*i_trans 
     1312                    + ((i_pix & 0x07e0)>> 5) * (MAX_TRANS - i_trans) ) 
     1313                    >> TRANS_BITS ) << 5  ) 
     1314              | ( ( ( (B >> 3)*i_trans 
     1315                    + (i_pix & 0x001f) * (MAX_TRANS - i_trans) ) 
     1316                    >> TRANS_BITS ) ); 
     1317#undef      R 
     1318#undef      G 
     1319#undef      B 
     1320        } 
     1321    } 
     1322 
     1323#undef MAX_TRANS 
     1324#undef TRANS_BITS 
     1325 
     1326    return; 
     1327}