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

📄 edge-detec.c

📁 H.264 source codes
💻 C
📖 第 1 页 / 共 5 页
字号:
        i_refb = -2;        if( !IS_INTRA( mbn->i_type ) )        {            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 ) )    {        *mvxp = 0;        *mvyp = 0;    }    else    {        x264_macroblock_predict_mv( mb, 0, 0, 0, mvxp, mvyp );    }}static const int i_chroma_qp_table[52] ={     0,  1,  2,  3,  4,  5,  6,  7,  8,  9,    10, 11, 12, 13, 14, 15, 16, 17, 18, 19,    20, 21, 22, 23, 24, 25, 26, 27, 28, 29,    29, 30, 31, 32, 32, 33, 34, 34, 35, 35,    36, 36, 37, 37, 37, 38, 38, 38, 39, 39,    39, 39};static void x264_macroblock_mc( x264_t *h, x264_macroblock_t *mb, int b_luma ){    x264_mb_context_t *ctx = mb->context;    int ch;    int i_ref;    int mx, my;    if( mb->i_type == P_L0 )    {        int i_part;        for( i_part = 0; i_part < mb_partition_count( mb->i_partition ); i_part++ )        {            int i_width, i_height;            int x, y;            x264_macroblock_partition_get( mb, 0, i_part, 0, &i_ref, &mx, &my );            x264_macroblock_partition_getxy( mb, i_part, 0, &x, &y );            x264_macroblock_partition_size(  mb, i_part, 0, &i_width, &i_height );            if( b_luma )            {                int     i_src = ctx->i_fref0[i_ref][0];                uint8_t *p_src= ctx->p_fref0[i_ref][0];                int     i_dst = ctx->i_fdec[0];                uint8_t *p_dst= ctx->p_fdec[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 );            }            else            {                int     i_src,  i_dst;                uint8_t *p_src, *p_dst;                for( ch = 0; ch < 2; ch++ )                {                    i_src = ctx->i_fref0[i_ref][1+ch];                    p_src = ctx->p_fref0[i_ref][1+ch];                    i_dst = ctx->i_fdec[1+ch];                    p_dst = ctx->p_fdec[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 );                }            }        }    }    else if( mb->i_type == P_8x8 )    {        int i_part;        for( i_part = 0; i_part < 4; i_part++ )        {            int i_sub;            for( i_sub = 0; i_sub < mb_sub_partition_count( mb->i_sub_partition[i_part] ); i_sub++ )            {                int i_width, i_height;                int x, y;                x264_macroblock_partition_get(   mb, 0, i_part, i_sub, &i_ref, &mx, &my );                x264_macroblock_partition_getxy( mb, i_part, i_sub, &x, &y );                x264_macroblock_partition_size(  mb, i_part, i_sub, &i_width, &i_height );                if( b_luma )                {                    int     i_src = ctx->i_fref0[i_ref][0];                    uint8_t *p_src= ctx->p_fref0[i_ref][0];                    int     i_dst = ctx->i_fdec[0];                    uint8_t *p_dst= ctx->p_fdec[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 );                }                else                {                    int     i_src,  i_dst;                    uint8_t *p_src, *p_dst;                    for( ch = 0; ch < 2; ch++ )                    {                        i_src = ctx->i_fref0[i_ref][1+ch];                        p_src = ctx->p_fref0[i_ref][1+ch];                        i_dst = ctx->i_fdec[1+ch];                        p_dst = ctx->p_fdec[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 );                    }                }            }        }    }}/***************************************************************************** * x264_macroblock_neighbour_load: *****************************************************************************/void x264_macroblock_context_load( x264_t *h, x264_macroblock_t *mb, x264_mb_context_t *context ){    int i;    int x, y;    x264_macroblock_t *a = NULL;    x264_macroblock_t *b = NULL;    if( mb->i_neighbour&MB_LEFT )    {        a = mb - 1;    }    if( mb->i_neighbour&MB_TOP )    {        b = mb - h->sps.i_mb_width;    }#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( y = 0; y < 4; y++ )    {        for( x = 0; x < 4; x++ )        {            int idx;            int xa, yb;            x264_macroblock_t *mba;            x264_macroblock_t *mbb;            idx = block_idx_xy[x][y];            mba = mb;            mbb = mb;            xa = x - 1;            if (xa < 0 )            {                xa += 4;                mba = a;            }            /* up */            yb = y - 1;            if (yb < 0 )            {                yb += 4;                mbb = b;            }            context->block[idx].mba = mba;            context->block[idx].mbb = mbb;            context->block[idx].bka = mba ? &mba->block[block_idx_xy[xa][y]] : NULL;            context->block[idx].bkb = mbb ? &mbb->block[block_idx_xy[x][yb]] : NULL;            if( x < 2 && y < 2 )            {                int ch;                if( xa > 1 ) xa -= 2;   /* we have wrap but here step is 2 not 4 */                if( yb > 1 ) yb -= 2;   /* idem */                for( ch = 0; ch < 2; ch++ )                {                    context->block[16+4*ch+idx].mba = mba;                    context->block[16+4*ch+idx].mbb = mbb;                    context->block[16+4*ch+idx].bka = mba ? &mba->block[16+4*ch+block_idx_xy[xa][y]] : NULL;                    context->block[16+4*ch+idx].bkb = mbb ? &mbb->block[16+4*ch+block_idx_xy[x][yb]] : NULL;                }            }        }    }    mb->context = context;}/* (ref: JVT-B118) * x264_mb_decimate_score: given dct coeffs it returns a score to see if we could empty this dct coeffs * to 0 (low score means set it to null) * Used in inter macroblock (luma and chroma) *  luma: for a 8x8 block: if score < 4 -> null *        for the complete mb: if score < 6 -> null *  chroma: for the complete mb: if score < 7 -> null */static int x264_mb_decimate_score( int *dct, int i_max ){    static const int i_ds_table[16] = { 3, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };    int i_score = 0;    int idx = i_max - 1;    while( idx >= 0 && dct[idx] == 0 )    {        idx--;    }    while( idx >= 0 )    {        int i_run;        if( abs( dct[idx--] ) > 1 )        {            return 9;        }        i_run = 0;        while( idx >= 0 && dct[idx] == 0 )        {            idx--;            i_run++;        }        i_score += i_ds_table[i_run];    }    return i_score;}static void x264_mb_encode_4x4( x264_t *h, x264_macroblock_t *mb, int idx, int i_qscale ){    x264_mb_context_t *ctx = mb->context;    uint8_t *p_src = ctx->p_img[0] + 4 * block_idx_x[idx] + 4 * block_idx_y[idx] * ctx->i_img[0];    int      i_src = ctx->i_img[0];    uint8_t *p_dst = ctx->p_fdec[0] + 4 * block_idx_x[idx] + 4 * block_idx_y[idx] * ctx->i_fdec[0];    int      i_dst = ctx->i_fdec[0];    int16_t luma[4][4];    int16_t dct4x4[4][4];    /* we calculate diff */    h->pixf.sub4x4( luma, p_src, i_src, p_dst, i_dst );    /* calculate dct coeffs */    h->dctf.dct4x4( dct4x4, luma );    quant_4x4( dct4x4, i_qscale, 1 );    scan_zigzag_4x4full( mb->block[idx].luma4x4, dct4x4 );    /* output samples to fdec */    dequant_4x4( dct4x4, i_qscale );    h->dctf.idct4x4( luma, dct4x4 );    /* put pixel to fdec */    h->pixf.add4x4( p_dst, i_dst, luma );}static void x264_mb_encode_i16x16( x264_t *h, x264_macroblock_t *mb, int i_qscale ){    x264_mb_context_t *ctx = mb->context;    uint8_t *p_src = ctx->p_img[0];    int      i_src = ctx->i_img[0];    uint8_t *p_dst = ctx->p_fdec[0];    int      i_dst = ctx->i_fdec[0];    int16_t luma[16][4][4];    int16_t dct4x4[16+1][4][4];    int i;    /* calculate the diff */    h->pixf.sub16x16( luma, p_src, i_src, p_dst, i_dst );    /* calculate dct coeffs */    for( i = 0; i < 16; i++ )    {        h->dctf.dct4x4( dct4x4[i+1], luma[i] );        /* copy dc coeff */        dct4x4[0][block_idx_y[i]][block_idx_x[i]] = dct4x4[1+i][0][0];        quant_4x4( dct4x4[1+i], i_qscale, 1 );        scan_zigzag_4x4( mb->block[i].residual_ac, dct4x4[1+i] );    }    h->dctf.dct4x4dc( dct4x4[0], dct4x4[0] );    quant_4x4_dc( dct4x4[0], i_qscale, 1 );    scan_zigzag_4x4full( mb->luma16x16_dc, dct4x4[0] );    /* output samples to fdec */    h->dctf.idct4x4dc( dct4x4[0], dct4x4[0] );    dequant_4x4_dc( dct4x4[0], i_qscale );  /* XXX not inversed */    /* calculate dct coeffs */    for( i = 0; i < 16; i++ )    {        dequant_4x4( dct4x4[1+i], i_qscale );        /* copy dc coeff */        dct4x4[1+i][0][0] = dct4x4[0][block_idx_y[i]][block_idx_x[i]];        h->dctf.idct4x4( luma[i], dct4x4[i+1] );    }    /* put pixels to fdec */    h->pixf.add16x16( p_dst, i_dst, luma );}static void x264_mb_encode_8x8( x264_t *h, x264_macroblock_t *mb, int b_inter, int i_qscale ){    x264_mb_context_t *ctx = mb->context;    uint8_t *p_src, *p_dst;    int      i_src, i_dst;    int i, ch;    int i_decimate_score = 0;    for( ch = 0; ch < 2; ch++ )    {        int16_t chroma[4][4][4];        int16_t dct2x2[2][2];        int16_t dct4x4[4][4][4];        p_src = ctx->p_img[1+ch];        i_src = ctx->i_img[1+ch];        p_dst = ctx->p_fdec[1+ch];        i_dst = ctx->i_fdec[1+ch];        /* calculate the diff */        h->pixf.sub8x8( chroma, p_src, i_src, p_dst, i_dst );        /* calculate dct coeffs */        for( i = 0; i < 4; i++ )        {            h->dctf.dct4x4( dct4x4[i], chroma[i] );            /* copy dc coeff */            dct2x2[block_idx_y[i]][block_idx_x[i]] = dct4x4[i][0][0];            quant_4x4( dct4x4[i], i_qscale, 1 );            scan_zigzag_4x4( mb->block[16+i+ch*4].residual_ac, dct4x4[i] );            i_decimate_score += x264_mb_decimate_score( mb->block[16+i+ch*4].residual_ac, 15 );        }        h->dctf.dct2x2dc( dct2x2, dct2x2 );        quant_2x2_dc( dct2x2, i_qscale, 1 );        scan_zigzag_2x2_dc( mb->chroma_dc[ch], dct2x2 );        if( i_decimate_score < 7 && b_inter )        {            /* Near null chroma 8x8 block so make it null (bits saving) */            for( i = 0; i < 4; i++ )            {                int x, y;                for( x = 0; x < 15; x++ )                {                    mb->block[16+i+ch*4].residual_ac[x] = 0;                }                for( x = 0; x < 4; x++ )                {                    for( y = 0; y < 4; y++ )                    {                        dct4x4[i][x][y] = 0;                    }                }            }        }        /* output samples to fdec */        h->dctf.idct2x2dc( dct2x2, dct2x2 );        dequant_2x2_dc( dct2x2, i_qscale );  /* XXX not inversed */        /* calculate dct coeffs */        for( i = 0; i < 4; i++ )        {            dequant_4x4( dct4x4[i], i_qscale );            /* copy dc coeff */            dct4x4[i][0][0] = dct2x2[block_idx_y[i]][block_idx_x[i]];            h->dctf.idct4x4( chroma[i], dct4x4[i] );        }        h->pixf.add8x8( p_dst, i_dst, chroma );    }}static int x264_mb_pred_mode4x4_fix( int i_mode ){    if( i_mode == I_PRED_4x4_DC_LEFT || i_mode == I_PRED_4x4_DC_TOP || i_mode == I_PRED_4x4_DC_128 )    {        return I_PRED_4x4_DC;    }    return i_mode;}static int x264_mb_pred_mode16x16_fix( int i_mode ){    if( i_mode == I_PRED_16x16_DC_LEFT || i_mode == I_PRED_16x16_DC_TOP || i_mode == I_PRED_16x16_DC_128 )    {        return I_PRED_16x16_DC;    }    return i_mode;}

⌨️ 快捷键说明

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