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

📄 macroblock.c

📁 图象压缩程序
💻 C
📖 第 1 页 / 共 2 页
字号:
    }}void x264_mb_predict_mv_pskip( x264_macroblock_t *mb, int mv[2] ){    int x, y, xn, yn;    int i_refa = -1;    int i_refb = -1;    int mvxa = 0, mvxb = 0;    int mvya = 0, mvyb = 0;    x264_macroblock_t *mbn;    x264_mb_partition_getxy( mb, 0, 0, &x, &y );    /* Left  pixel (-1,0)*/    xn = x - 1;    mbn = mb;    if( xn < 0 )    {        xn += 4;        mbn = mb->context->mba;    }    if( mbn )    {        i_refa = -2;        if( !IS_INTRA( mbn->i_type ) && mbn->partition[xn][y].i_ref[0] != -1 )        {            i_refa = mbn->partition[xn][y].i_ref[0];            mvxa   = mbn->partition[xn][y].mv[0][0];            mvya   = mbn->partition[xn][y].mv[0][1];        }    }    /* Up ( pixel(0,-1)*/    yn = y - 1;    mbn = mb;    if( yn < 0 )    {        yn += 4;        mbn = mb->context->mbb;    }    if( mbn )    {        i_refb = -2;        if( !IS_INTRA( mbn->i_type ) && mbn->partition[x][yn].i_ref[0] != -1 )        {            i_refb = mbn->partition[x][yn].i_ref[0];            mvxb   = mbn->partition[x][yn].mv[0][0];            mvyb   = mbn->partition[x][yn].mv[0][1];        }    }    if( i_refa == -1 || i_refb == -1 ||        ( i_refa == 0 && mvxa == 0 && mvya == 0 ) ||        ( i_refb == 0 && mvxb == 0 && mvyb == 0 ) )    {        mv[0] = 0;        mv[1] = 0;    }    else    {        x264_mb_predict_mv( mb, 0, 0, 0, mv );    }}static inline void x264_mb_mc_partition_lx( x264_t *h, x264_macroblock_t *mb, int i_list, int i_part, int i_sub ){    const x264_mb_context_t *ctx = mb->context;    int mx, my;    int i_ref;    int i_width, i_height;    int x, y;    int ch;    int      i_dst;    uint8_t *p_dst;    int      i_src;    uint8_t *p_src;    x264_mb_partition_get(   mb, i_list, i_part, i_sub, &i_ref, &mx, &my );    x264_mb_partition_getxy( mb, i_part, i_sub, &x, &y );    x264_mb_partition_size(  mb, i_part, i_sub, &i_width, &i_height );    if( ( i_list == 0 && i_ref > h->i_ref0 ) ||        ( i_list == 1 && i_ref > h->i_ref1 ) ||        i_ref < 0 )    {        fprintf( stderr, "invalid ref frame\n" );        return;    }    i_dst = ctx->i_fdec[0];         p_dst = ctx->p_fdec[0];    if( i_list == 0 )    {        i_src = ctx->i_fref0[i_ref][0]; p_src= ctx->p_fref0[i_ref][0];    }    else    {        i_src = ctx->i_fref1[i_ref][0]; p_src= ctx->p_fref1[i_ref][0];    }    h->mc[MC_LUMA]( &p_src[4*(x+y*i_src)], i_src,                    &p_dst[4*(x+y*i_dst)], i_dst,                    mx, my, 4*i_width, 4*i_height );    for( ch = 0; ch < 2; ch++ )    {        i_dst = ctx->i_fdec[1+ch];         p_dst = ctx->p_fdec[1+ch];        if( i_list == 0 )        {            i_src = ctx->i_fref0[i_ref][1+ch]; p_src = ctx->p_fref0[i_ref][1+ch];        }        else        {            i_src = ctx->i_fref1[i_ref][1+ch]; p_src = ctx->p_fref1[i_ref][1+ch];        }        h->mc[MC_CHROMA]( &p_src[2*(x+y*i_src)], i_src,                          &p_dst[2*(x+y*i_dst)], i_dst,                          mx, my, 2*i_width, 2*i_height );    }}static void x264_mb_mc_partition_bi( x264_t *h, x264_macroblock_t *mb, int i_part, int i_sub ){    const x264_mb_context_t *ctx = mb->context;    int mx, my;    int i_ref;    int i_width, i_height;    int x, y;    int      i_dst;    uint8_t *p_dst;    int      i_src;    uint8_t *p_src;    int ch;    uint8_t tmp[16*16];    x264_mb_partition_getxy( mb, i_part, i_sub, &x, &y );    x264_mb_partition_size(  mb, i_part, i_sub, &i_width, &i_height );    /* first do l0 */    x264_mb_partition_get(   mb, 0, i_part, i_sub, &i_ref, &mx, &my );    if( i_ref > h->i_ref0 || i_ref < 0 )    {        fprintf( stderr, "invalid ref frame\n" );        return;    }    i_dst = ctx->i_fdec[0];         p_dst = ctx->p_fdec[0];    i_src = ctx->i_fref0[i_ref][0]; p_src= ctx->p_fref0[i_ref][0];    h->mc[MC_LUMA]( &p_src[4*(x+y*i_src)], i_src,                    &p_dst[4*(x+y*i_dst)], i_dst,                    mx, my, 4*i_width, 4*i_height );    for( ch = 0; ch < 2; ch++ )    {        i_dst = ctx->i_fdec[1+ch];         p_dst = ctx->p_fdec[1+ch];        i_src = ctx->i_fref0[i_ref][1+ch]; p_src = ctx->p_fref0[i_ref][1+ch];        h->mc[MC_CHROMA]( &p_src[2*(x+y*i_src)], i_src,                          &p_dst[2*(x+y*i_dst)], i_dst,                          mx, my, 2*i_width, 2*i_height );    }    /* next avg with l1 */    x264_mb_partition_get(   mb, 1, i_part, i_sub, &i_ref, &mx, &my );    if( i_ref > h->i_ref1 || i_ref < 0 )    {        fprintf( stderr, "invalid ref frame\n" );        return;    }    i_dst = ctx->i_fdec[0];         p_dst = ctx->p_fdec[0];    i_src = ctx->i_fref1[i_ref][0]; p_src= ctx->p_fref1[i_ref][0];    h->mc[MC_LUMA]( &p_src[4*(x+y*i_src)], i_src,                    tmp, 16,                    mx, my, 4*i_width, 4*i_height );    if( mb->i_partition == D_16x16 )    {        h->pixf.avg[PIXEL_16x16]( &p_dst[4*(x+y*i_dst)], i_dst, tmp, 16 );    }    else if( mb->i_partition == D_16x8 )    {        h->pixf.avg[PIXEL_16x8]( &p_dst[4*(x+y*i_dst)], i_dst, tmp, 16 );    }    else if( mb->i_partition == D_8x16 )    {        h->pixf.avg[PIXEL_8x16]( &p_dst[4*(x+y*i_dst)], i_dst, tmp, 16 );    }    else    {        fprintf( stderr, "MC BI with D_8x8 unsupported\n" );    }    for( ch = 0; ch < 2; ch++ )    {        i_dst = ctx->i_fdec[1+ch];         p_dst = ctx->p_fdec[1+ch];        i_src = ctx->i_fref1[i_ref][1+ch]; p_src = ctx->p_fref1[i_ref][1+ch];        h->mc[MC_CHROMA]( &p_src[2*(x+y*i_src)], i_src,                          tmp, 8,                          mx, my, 2*i_width, 2*i_height );        if( mb->i_partition == D_16x16 )        {            h->pixf.avg[PIXEL_8x8]( &p_dst[2*(x+y*i_dst)], i_dst, tmp, 8 );        }        else if( mb->i_partition == D_16x8 )        {            h->pixf.avg[PIXEL_8x4]( &p_dst[2*(x+y*i_dst)], i_dst, tmp, 8 );        }        else if( mb->i_partition == D_8x16 )        {            h->pixf.avg[PIXEL_4x8]( &p_dst[2*(x+y*i_dst)], i_dst, tmp, 8 );        }        else        {            fprintf( stderr, "MC BI with D_8x8 unsupported\n" );        }    }}void x264_mb_mc( x264_t *h, x264_macroblock_t *mb ){    const x264_mb_context_t *ctx = mb->context;    if( mb->i_type == P_L0 )    {        const int i_ref0 = mb->partition[0][0].i_ref[0];        const int mvx0 = mb->partition[0][0].mv[0][0];        const int mvy0 = mb->partition[0][0].mv[0][1];        if( mb->i_partition == D_16x16 )        {            h->mc[MC_LUMA]( ctx->p_fref0[i_ref0][0], ctx->i_fref0[i_ref0][0],                            ctx->p_fdec[0],          ctx->i_fdec[0],                            mvx0, mvy0, 16, 16 );            h->mc[MC_CHROMA]( ctx->p_fref0[i_ref0][1], ctx->i_fref0[i_ref0][1],                              ctx->p_fdec[1],          ctx->i_fdec[1],                              mvx0, mvy0, 8, 8 );            h->mc[MC_CHROMA]( ctx->p_fref0[i_ref0][2], ctx->i_fref0[i_ref0][2],                              ctx->p_fdec[2],          ctx->i_fdec[2],                              mvx0, mvy0, 8, 8 );        }        else if( mb->i_partition == D_16x8 )        {            const int i_ref1 = mb->partition[0][2].i_ref[0];            const int mvx1 = mb->partition[0][2].mv[0][0];            const int mvy1 = mb->partition[0][2].mv[0][1];            h->mc[MC_LUMA]( ctx->p_fref0[i_ref0][0], ctx->i_fref0[i_ref0][0],                            ctx->p_fdec[0],          ctx->i_fdec[0],                            mvx0, mvy0, 16, 8 );            h->mc[MC_CHROMA]( ctx->p_fref0[i_ref0][1], ctx->i_fref0[i_ref0][1],                              ctx->p_fdec[1],          ctx->i_fdec[1],                              mvx0, mvy0, 8, 4 );            h->mc[MC_CHROMA]( ctx->p_fref0[i_ref0][2], ctx->i_fref0[i_ref0][2],                              ctx->p_fdec[2],          ctx->i_fdec[2],                              mvx0, mvy0, 8, 4 );            h->mc[MC_LUMA]( &ctx->p_fref0[i_ref1][0][8*ctx->i_fref0[i_ref1][0]], ctx->i_fref0[i_ref1][0],                            &ctx->p_fdec[0][8*ctx->i_fdec[0]],                   ctx->i_fdec[0],                            mvx1, mvy1, 16, 8 );            h->mc[MC_CHROMA]( &ctx->p_fref0[i_ref1][1][4*ctx->i_fref0[i_ref1][1]], ctx->i_fref0[i_ref1][1],                              &ctx->p_fdec[1][4*ctx->i_fdec[1]],                   ctx->i_fdec[1],                              mvx1, mvy1, 8, 4 );            h->mc[MC_CHROMA]( &ctx->p_fref0[i_ref1][2][4*ctx->i_fref0[i_ref1][2]], ctx->i_fref0[i_ref1][2],                              &ctx->p_fdec[2][4*ctx->i_fdec[2]],                   ctx->i_fdec[2],                              mvx1, mvy1, 8, 4 );        }        else if( mb->i_partition == D_8x16 )        {            const int i_ref1 = mb->partition[2][0].i_ref[0];            const int mvx1 = mb->partition[2][0].mv[0][0];            const int mvy1 = mb->partition[2][0].mv[0][1];            h->mc[MC_LUMA]( ctx->p_fref0[i_ref0][0], ctx->i_fref0[i_ref0][0],                            ctx->p_fdec[0],          ctx->i_fdec[0],                            mvx0, mvy0, 8, 16 );            h->mc[MC_CHROMA]( ctx->p_fref0[i_ref0][1], ctx->i_fref0[i_ref0][1],                              ctx->p_fdec[1],          ctx->i_fdec[1],                              mvx0, mvy0, 4, 8 );            h->mc[MC_CHROMA]( ctx->p_fref0[i_ref0][2], ctx->i_fref0[i_ref0][2],                              ctx->p_fdec[2],          ctx->i_fdec[2],                              mvx0, mvy0, 4, 8 );            h->mc[MC_LUMA]( &ctx->p_fref0[i_ref1][0][8], ctx->i_fref0[i_ref1][0],                            &ctx->p_fdec[0][8],          ctx->i_fdec[0],                            mvx1, mvy1, 8, 16 );            h->mc[MC_CHROMA]( &ctx->p_fref0[i_ref1][1][4], ctx->i_fref0[i_ref1][1],                              &ctx->p_fdec[1][4],          ctx->i_fdec[1],                              mvx1, mvy1, 4, 8 );            h->mc[MC_CHROMA]( &ctx->p_fref0[i_ref1][2][4], ctx->i_fref0[i_ref1][2],                              &ctx->p_fdec[2][4],          ctx->i_fdec[2],                              mvx1, mvy1, 4, 8 );        }    }    else if( mb->i_type == P_8x8 )    {        int i_part;        int i_sub;        for( i_part = 0; i_part < 4; i_part++ )        {            for( i_sub = 0; i_sub < x264_mb_partition_count_table[mb->i_sub_partition[i_part]]; i_sub++ )            {                x264_mb_mc_partition_lx( h, mb, 0, i_part, i_sub );            }        }    }    else if( mb->i_type == B_8x8 || mb->i_type == B_DIRECT )    {        fprintf( stderr, "mc_luma with unsupported mb\n" );        return;    }    else    /* B_*x* */    {        int b_list0[2];        int b_list1[2];        int i;        /* init ref list utilisations */        for( i = 0; i < 2; i++ )        {            b_list0[i] = x264_mb_type_list0_table[mb->i_type][i];            b_list1[i] = x264_mb_type_list1_table[mb->i_type][i];        }        for( i = 0; i < x264_mb_partition_count_table[mb->i_partition]; i++ )        {            if( b_list0[i] && b_list1[i] )            {                x264_mb_mc_partition_bi( h, mb, i, 0 );            }            else if( b_list0[i] )            {                x264_mb_mc_partition_lx( h, mb, 0, i, 0 );            }            else if( b_list1[i] )            {                x264_mb_mc_partition_lx( h, mb, 1, i, 0 );            }        }    }}/***************************************************************************** * x264_macroblock_neighbour_load: *****************************************************************************/void x264_macroblock_context_load( x264_t *h, x264_macroblock_t *mb, x264_mb_context_t *context ){    int ch;    int i, j;    x264_macroblock_t *a = NULL;    x264_macroblock_t *b = NULL;    mb->context = context;    if( mb->i_neighbour&MB_LEFT )    {        a = mb - 1;    }    context->mba = a;    if( mb->i_neighbour&MB_TOP )    {        b = mb - h->sps->i_mb_width;    }    context->mbb = b;    context->mbc = NULL;    if( mb->i_neighbour&MB_TOPRIGHT )    {        context->mbc = b + 1;    }#define LOAD_PTR( dst, src ) \    context->p_##dst[0] = (src)->plane[0] + 16 * ( mb->i_mb_x + mb->i_mb_y * (src)->i_stride[0] ); \    context->p_##dst[1] = (src)->plane[1] +  8 * ( mb->i_mb_x + mb->i_mb_y * (src)->i_stride[1] ); \    context->p_##dst[2] = (src)->plane[2] +  8 * ( mb->i_mb_x + mb->i_mb_y * (src)->i_stride[2] ); \    context->i_##dst[0] = (src)->i_stride[0]; \    context->i_##dst[1] = (src)->i_stride[1]; \    context->i_##dst[2] = (src)->i_stride[2]    LOAD_PTR( img,  h->picture );    LOAD_PTR( fdec, h->fdec );    for( i = 0; i < h->i_ref0; i++ )    {        LOAD_PTR( fref0[i], h->fref0[i] );    }    for( i = 0; i < h->i_ref1; i++ )    {        LOAD_PTR( fref1[i], h->fref1[i] );    }#undef LOAD_PTR    for( i = 0; i < 4; i++ )    {        /* left */        context->block[block_idx_xy[0][i]].mba = a;        context->block[block_idx_xy[0][i]].bka = a ? &a->block[block_idx_xy[3][i]] : NULL;        /* up */        context->block[block_idx_xy[i][0]].mbb = b;        context->block[block_idx_xy[i][0]].bkb = b ? &b->block[block_idx_xy[i][3]] : NULL;        /* rest */        for( j = 1; j < 4; j++ )        {            context->block[block_idx_xy[j][i]].mba = mb;            context->block[block_idx_xy[j][i]].bka = &mb->block[block_idx_xy[j-1][i]];            context->block[block_idx_xy[i][j]].mbb = mb;            context->block[block_idx_xy[i][j]].bkb = &mb->block[block_idx_xy[i][j-1]];        }    }    for( ch = 0; ch < 2; ch++ )    {        for( i = 0; i < 2; i++ )        {            /* left */            context->block[16+4*ch+block_idx_xy[0][i]].mba = a;            context->block[16+4*ch+block_idx_xy[0][i]].bka = a ? &a->block[16+4*ch+block_idx_xy[1][i]] : NULL;            /* up */            context->block[16+4*ch+block_idx_xy[i][0]].mbb = b;            context->block[16+4*ch+block_idx_xy[i][0]].bkb = b ? &b->block[16+4*ch+block_idx_xy[i][1]] : NULL;            /* rest */            context->block[16+4*ch+block_idx_xy[1][i]].mba = mb;            context->block[16+4*ch+block_idx_xy[1][i]].bka = &mb->block[16+4*ch+block_idx_xy[0][i]];            context->block[16+4*ch+block_idx_xy[i][1]].mbb = mb;            context->block[16+4*ch+block_idx_xy[i][1]].bkb = &mb->block[16+4*ch+block_idx_xy[i][0]];        }    }}

⌨️ 快捷键说明

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