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

📄 macroblock_c.c

📁 法国人的264代码 大家看看啊,里面有很多可以借鉴的东西啊
💻 C
📖 第 1 页 / 共 4 页
字号:
                const int iv = i_mb_4x4 - s4x4 - 1;                h->mb.cache.ref[i_list][i8]  = h->mb.ref[i_list][ir];                h->mb.cache.mv[i_list][i8][0] = h->mb.mv[i_list][iv][0];                h->mb.cache.mv[i_list][i8][1] = h->mb.mv[i_list][iv][1];            }            else            {                const int i8 = x264_scan8[0] - 1 - 1*8;                h->mb.cache.ref[i_list][i8] = -2;                h->mb.cache.mv[i_list][i8][0] = 0;                h->mb.cache.mv[i_list][i8][1] = 0;            }            if( h->mb.i_neighbour & MB_TOP )            {                const int i8 = x264_scan8[0] - 8;                const int ir = i_mb_8x8 - s8x8;                const int iv = i_mb_4x4 - s4x4;                h->mb.cache.ref[i_list][i8+0] =                h->mb.cache.ref[i_list][i8+1] = h->mb.ref[i_list][ir + 0];                h->mb.cache.ref[i_list][i8+2] =                h->mb.cache.ref[i_list][i8+3] = h->mb.ref[i_list][ir + 1];                for( i = 0; i < 4; i++ )                {                    h->mb.cache.mv[i_list][i8+i][0] = h->mb.mv[i_list][iv + i][0];                    h->mb.cache.mv[i_list][i8+i][1] = h->mb.mv[i_list][iv + i][1];                }            }            else            {                const int i8 = x264_scan8[0] - 8;                for( i = 0; i < 4; i++ )                {                    h->mb.cache.ref[i_list][i8+i] = -2;                    h->mb.cache.mv[i_list][i8+i][0] =                    h->mb.cache.mv[i_list][i8+i][1] = 0;                }            }            if( h->mb.i_neighbour & MB_TOPRIGHT )            {                const int i8 = x264_scan8[0] + 4 - 1*8;                const int ir = i_mb_8x8 - s8x8 + 2;                const int iv = i_mb_4x4 - s4x4 + 4;                h->mb.cache.ref[i_list][i8]  = h->mb.ref[i_list][ir];                h->mb.cache.mv[i_list][i8][0] = h->mb.mv[i_list][iv][0];                h->mb.cache.mv[i_list][i8][1] = h->mb.mv[i_list][iv][1];            }            else            {                const int i8 = x264_scan8[0] + 4 - 1*8;                h->mb.cache.ref[i_list][i8] = -2;                h->mb.cache.mv[i_list][i8][0] = 0;                h->mb.cache.mv[i_list][i8][1] = 0;            }            if( h->mb.i_neighbour & MB_LEFT )            {                const int i8 = x264_scan8[0] - 1;                const int ir = i_mb_8x8 - 1;                const int iv = i_mb_4x4 - 1;                h->mb.cache.ref[i_list][i8+0*8] =                h->mb.cache.ref[i_list][i8+1*8] = h->mb.ref[i_list][ir + 0*s8x8];                h->mb.cache.ref[i_list][i8+2*8] =                h->mb.cache.ref[i_list][i8+3*8] = h->mb.ref[i_list][ir + 1*s8x8];                for( i = 0; i < 4; i++ )                {                    h->mb.cache.mv[i_list][i8+i*8][0] = h->mb.mv[i_list][iv + i*s4x4][0];                    h->mb.cache.mv[i_list][i8+i*8][1] = h->mb.mv[i_list][iv + i*s4x4][1];                }            }            else            {                const int i8 = x264_scan8[0] - 1;                for( i = 0; i < 4; i++ )                {                    h->mb.cache.ref[i_list][i8+i*8] = -2;                    h->mb.cache.mv[i_list][i8+i*8][0] =                    h->mb.cache.mv[i_list][i8+i*8][1] = 0;                }            }            if( h->param.b_cabac )            {                if( i_top_type >= 0 )                {                    const int i8 = x264_scan8[0] - 8;                    const int iv = i_mb_4x4 - s4x4;                    for( i = 0; i < 4; i++ )                    {                        h->mb.cache.mvd[i_list][i8+i][0] = h->mb.mvd[i_list][iv + i][0];                        h->mb.cache.mvd[i_list][i8+i][1] = h->mb.mvd[i_list][iv + i][1];                    }                }                else                {                    const int i8 = x264_scan8[0] - 8;                    for( i = 0; i < 4; i++ )                    {                        h->mb.cache.mvd[i_list][i8+i][0] =                        h->mb.cache.mvd[i_list][i8+i][1] = 0;                    }                }                if( i_left_type >= 0 )                {                    const int i8 = x264_scan8[0] - 1;                    const int iv = i_mb_4x4 - 1;                    for( i = 0; i < 4; i++ )                    {                        h->mb.cache.mvd[i_list][i8+i*8][0] = h->mb.mvd[i_list][iv + i*s4x4][0];                        h->mb.cache.mvd[i_list][i8+i*8][1] = h->mb.mvd[i_list][iv + i*s4x4][1];                    }                }                else                {                    const int i8 = x264_scan8[0] - 1;                    for( i = 0; i < 4; i++ )                    {                        h->mb.cache.mvd[i_list][i8+i*8][0] =                        h->mb.cache.mvd[i_list][i8+i*8][1] = 0;                    }                }            }        }        /* load skip */        if( h->sh.i_type == SLICE_TYPE_B && h->param.b_cabac )        {            memset( h->mb.cache.skip, 0, X264_SCAN8_SIZE * sizeof( int8_t ) );            if( i_left_type >= 0 )            {                h->mb.cache.skip[x264_scan8[0] - 1] = h->mb.skipbp[i_left_xy] & 0x2;                h->mb.cache.skip[x264_scan8[8] - 1] = h->mb.skipbp[i_left_xy] & 0x8;            }            if( i_top_type >= 0 )            {                h->mb.cache.skip[x264_scan8[0] - 8] = h->mb.skipbp[i_top_xy] & 0x4;                h->mb.cache.skip[x264_scan8[4] - 8] = h->mb.skipbp[i_top_xy] & 0x8;            }        }    }    h->mb.i_neighbour4[0] =    h->mb.i_neighbour8[0] = (h->mb.i_neighbour & (MB_TOP|MB_LEFT|MB_TOPLEFT))                            | ((h->mb.i_neighbour & MB_TOP) ? MB_TOPRIGHT : 0);    h->mb.i_neighbour4[4] =    h->mb.i_neighbour4[1] = MB_LEFT | ((h->mb.i_neighbour & MB_TOP) ? (MB_TOP|MB_TOPLEFT|MB_TOPRIGHT) : 0);    h->mb.i_neighbour4[2] =    h->mb.i_neighbour4[8] =    h->mb.i_neighbour4[10] =    h->mb.i_neighbour8[2] = MB_TOP|MB_TOPRIGHT | ((h->mb.i_neighbour & MB_LEFT) ? (MB_LEFT|MB_TOPLEFT) : 0);    h->mb.i_neighbour4[3] =    h->mb.i_neighbour4[7] =    h->mb.i_neighbour4[11] =    h->mb.i_neighbour4[13] =    h->mb.i_neighbour4[15] =    h->mb.i_neighbour8[3] = MB_LEFT|MB_TOP|MB_TOPLEFT;    h->mb.i_neighbour4[5] =    h->mb.i_neighbour8[1] = MB_LEFT | (h->mb.i_neighbour & MB_TOPRIGHT)                            | ((h->mb.i_neighbour & MB_TOP) ? MB_TOP|MB_TOPLEFT : 0);    h->mb.i_neighbour4[6] =    h->mb.i_neighbour4[9] =    h->mb.i_neighbour4[12] =    h->mb.i_neighbour4[14] = MB_LEFT|MB_TOP|MB_TOPLEFT|MB_TOPRIGHT;}void x264_macroblock_cache_save( x264_t *h ){    const int i_mb_xy = h->mb.i_mb_xy;    const int i_mb_type = x264_mb_type_fix[h->mb.i_type];    const int s8x8 = h->mb.i_b8_stride;    const int s4x4 = h->mb.i_b4_stride;    const int i_mb_4x4 = h->mb.i_b4_xy;    const int i_mb_8x8 = h->mb.i_b8_xy;    int i;    for( i = 0; i < 3; i++ )    {        int w = i ? 8 : 16;        h->mc.copy[i?PIXEL_8x8:PIXEL_16x16](            &h->fdec->plane[i][ w * (h->mb.i_mb_x + h->mb.i_mb_y * h->fdec->i_stride[i]) ],            h->fdec->i_stride[i],            h->mb.pic.p_fdec[i], FDEC_STRIDE, w );    }    h->mb.type[i_mb_xy] = i_mb_type;    if( h->mb.i_type != I_16x16 && h->mb.i_cbp_luma == 0 && h->mb.i_cbp_chroma == 0 )        h->mb.i_qp = h->mb.i_last_qp;    h->mb.qp[i_mb_xy] = h->mb.i_qp;    h->mb.i_last_dqp = h->mb.i_qp - h->mb.i_last_qp;    h->mb.i_last_qp = h->mb.i_qp;    /* save intra4x4 */    if( i_mb_type == I_4x4 )    {        h->mb.intra4x4_pred_mode[i_mb_xy][0] = h->mb.cache.intra4x4_pred_mode[x264_scan8[10] ];        h->mb.intra4x4_pred_mode[i_mb_xy][1] = h->mb.cache.intra4x4_pred_mode[x264_scan8[11] ];        h->mb.intra4x4_pred_mode[i_mb_xy][2] = h->mb.cache.intra4x4_pred_mode[x264_scan8[14] ];        h->mb.intra4x4_pred_mode[i_mb_xy][3] = h->mb.cache.intra4x4_pred_mode[x264_scan8[15] ];        h->mb.intra4x4_pred_mode[i_mb_xy][4] = h->mb.cache.intra4x4_pred_mode[x264_scan8[5] ];        h->mb.intra4x4_pred_mode[i_mb_xy][5] = h->mb.cache.intra4x4_pred_mode[x264_scan8[7] ];        h->mb.intra4x4_pred_mode[i_mb_xy][6] = h->mb.cache.intra4x4_pred_mode[x264_scan8[13] ];    }    else    {        h->mb.intra4x4_pred_mode[i_mb_xy][0] =        h->mb.intra4x4_pred_mode[i_mb_xy][1] =        h->mb.intra4x4_pred_mode[i_mb_xy][2] =        h->mb.intra4x4_pred_mode[i_mb_xy][3] =        h->mb.intra4x4_pred_mode[i_mb_xy][4] =        h->mb.intra4x4_pred_mode[i_mb_xy][5] =        h->mb.intra4x4_pred_mode[i_mb_xy][6] = I_PRED_4x4_DC;    }    if( i_mb_type == I_PCM )    {        h->mb.cbp[i_mb_xy] = 0x72f;   /* all set */        for( i = 0; i < 16 + 2*4; i++ )        {            h->mb.non_zero_count[i_mb_xy][i] = 16;        }    }    else    {        /* save non zero count */        for( i = 0; i < 16 + 2*4; i++ )        {            h->mb.non_zero_count[i_mb_xy][i] = h->mb.cache.non_zero_count[x264_scan8[i]];        }    }    if( h->mb.i_cbp_luma == 0 && h->mb.i_type != I_8x8 )        h->mb.b_transform_8x8 = 0;    h->mb.mb_transform_size[i_mb_xy] = h->mb.b_transform_8x8;    if( !IS_INTRA( i_mb_type ) )    {        int i_list;        for( i_list = 0; i_list < (h->sh.i_type == SLICE_TYPE_B ? 2  : 1 ); i_list++ )        {            int y,x;            h->mb.ref[i_list][i_mb_8x8+0+0*s8x8] = h->mb.cache.ref[i_list][x264_scan8[0]];            h->mb.ref[i_list][i_mb_8x8+1+0*s8x8] = h->mb.cache.ref[i_list][x264_scan8[4]];            h->mb.ref[i_list][i_mb_8x8+0+1*s8x8] = h->mb.cache.ref[i_list][x264_scan8[8]];            h->mb.ref[i_list][i_mb_8x8+1+1*s8x8] = h->mb.cache.ref[i_list][x264_scan8[12]];            for( y = 0; y < 4; y++ )            {                for( x = 0; x < 4; x++ )                {                    h->mb.mv[i_list][i_mb_4x4+x+y*s4x4][0] = h->mb.cache.mv[i_list][x264_scan8[0]+x+8*y][0];                    h->mb.mv[i_list][i_mb_4x4+x+y*s4x4][1] = h->mb.cache.mv[i_list][x264_scan8[0]+x+8*y][1];                }            }        }    }    else    {        int i_list;        for( i_list = 0; i_list < (h->sh.i_type == SLICE_TYPE_B ? 2  : 1 ); i_list++ )        {            int y,x;            h->mb.ref[i_list][i_mb_8x8+0+0*s8x8] =            h->mb.ref[i_list][i_mb_8x8+1+0*s8x8] =            h->mb.ref[i_list][i_mb_8x8+0+1*s8x8] =            h->mb.ref[i_list][i_mb_8x8+1+1*s8x8] = -1;            for( y = 0; y < 4; y++ )            {                for( x = 0; x < 4; x++ )                {                    h->mb.mv[i_list][i_mb_4x4+x+y*s4x4][0] = 0;                    h->mb.mv[i_list][i_mb_4x4+x+y*s4x4][1] = 0;                }            }        }    }    if( h->param.b_cabac )    {        if( i_mb_type == I_4x4 || i_mb_type == I_16x16 )            h->mb.chroma_pred_mode[i_mb_xy] = x264_mb_pred_mode8x8c_fix[ h->mb.i_chroma_pred_mode ];        else            h->mb.chroma_pred_mode[i_mb_xy] = I_PRED_CHROMA_DC;        if( !IS_INTRA( i_mb_type ) && !IS_SKIP( i_mb_type ) && !IS_DIRECT( i_mb_type ) )        {            int i_list;            for( i_list  = 0; i_list < 2; i_list++ )            {                const int s4x4 = 4 * h->mb.i_mb_stride;                int y,x;                for( y = 0; y < 4; y++ )                {                    for( x = 0; x < 4; x++ )                    {                        h->mb.mvd[i_list][i_mb_4x4+x+y*s4x4][0] = h->mb.cache.mvd[i_list][x264_scan8[0]+x+8*y][0];                        h->mb.mvd[i_list][i_mb_4x4+x+y*s4x4][1] = h->mb.cache.mvd[i_list][x264_scan8[0]+x+8*y][1];                    }                }            }        }        else        {            int i_list;            for( i_list  = 0; i_list < 2; i_list++ )            {                const int s4x4 = 4 * h->mb.i_mb_stride;                int y,x;                for( y = 0; y < 4; y++ )                {                    for( x = 0; x < 4; x++ )                    {                        h->mb.mvd[i_list][i_mb_4x4+x+y*s4x4][0] = 0;                        h->mb.mvd[i_list][i_mb_4x4+x+y*s4x4][1] = 0;                    }                }            }        }        if( h->sh.i_type == SLICE_TYPE_B )        {            if( i_mb_type == B_SKIP || i_mb_type == B_DIRECT )                h->mb.skipbp[i_mb_xy] = 0xf;            else if( i_mb_type == B_8x8 )            {                int skipbp = 0;                for( i = 0; i < 4; i++ )                    skipbp |= ( h->mb.i_sub_partition[i] == D_DIRECT_8x8 ) << i;                h->mb.skipbp[i_mb_xy] = skipbp;            }            else                h->mb.skipbp[i_mb_xy] = 0;        }    }}void x264_macroblock_bipred_init( x264_t *h ){    int i_ref0, i_ref1;    for( i_ref0 = 0; i_ref0 < h->i_ref0; i_ref0++ )    {        int poc0 = h->fref0[i_ref0]->i_poc;        for( i_ref1 = 0; i_ref1 < h->i_ref1; i_ref1++ )        {            int dist_scale_factor;            int poc1 = h->fref1[i_ref1]->i_poc;            int td = x264_clip3( poc1 - poc0, -128, 127 );            if( td == 0 /* || pic0 is a long-term ref */ )                dist_scale_factor = 256;            else            {                int tb = x264_clip3( h->fdec->i_poc - poc0, -128, 127 );                int tx = (16384 + (abs(td) >> 1)) / td;                dist_scale_factor = x264_clip3( (tb * tx + 32) >> 6, -1024, 1023 );            }            h->mb.dist_scale_factor[i_ref0][i_ref1] = dist_scale_factor;            dist_scale_factor >>= 2;            if( h->param.analyse.b_weighted_bipred                  && dist_scale_factor >= -64                  && dist_scale_factor <= 128 )                h->mb.bipred_weight[i_ref0][i_ref1] = 64 - dist_scale_factor;            else                h->mb.bipred_weight[i_ref0][i_ref1] = 32;        }    }}

⌨️ 快捷键说明

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