📄 cabac.c.svn-base
字号:
int val = i_dqp <= 0 ? (-2*i_dqp) : (2*i_dqp - 1); int ctx; /* No need to test for PCM / SKIP */ if( i_mbn_xy >= h->sh.i_first_mb && h->mb.i_last_dqp != 0 && ( h->mb.type[i_mbn_xy] == I_16x16 || (h->mb.cbp[i_mbn_xy]&0x3f) ) ) ctx = 1; else ctx = 0; while( val > 0 ) { x264_cabac_encode_decision( cb, 60 + ctx, 1 ); if( ctx < 2 ) ctx = 2; else ctx = 3; val--; } x264_cabac_encode_decision( cb, 60 + ctx, 0 );}void x264_cabac_mb_skip( x264_t *h, int b_skip ){ int ctx = 0; if( h->mb.i_mb_type_left >= 0 && !IS_SKIP( h->mb.i_mb_type_left ) ) { ctx++; } if( h->mb.i_mb_type_top >= 0 && !IS_SKIP( h->mb.i_mb_type_top ) ) { ctx++; } if( h->sh.i_type == SLICE_TYPE_P ) x264_cabac_encode_decision( &h->cabac, 11 + ctx, b_skip ? 1 : 0 ); else /* SLICE_TYPE_B */ x264_cabac_encode_decision( &h->cabac, 24 + ctx, b_skip ? 1 : 0 );}static inline void x264_cabac_mb_sub_p_partition( x264_cabac_t *cb, int i_sub ){ if( i_sub == D_L0_8x8 ) { x264_cabac_encode_decision( cb, 21, 1 ); } else if( i_sub == D_L0_8x4 ) { x264_cabac_encode_decision( cb, 21, 0 ); x264_cabac_encode_decision( cb, 22, 0 ); } else if( i_sub == D_L0_4x8 ) { x264_cabac_encode_decision( cb, 21, 0 ); x264_cabac_encode_decision( cb, 22, 1 ); x264_cabac_encode_decision( cb, 23, 1 ); } else if( i_sub == D_L0_4x4 ) { x264_cabac_encode_decision( cb, 21, 0 ); x264_cabac_encode_decision( cb, 22, 1 ); x264_cabac_encode_decision( cb, 23, 0 ); }}static inline void x264_cabac_mb_sub_b_partition( x264_cabac_t *cb, int i_sub ){#define WRITE_SUB_3(a,b,c) {\ x264_cabac_encode_decision( cb, 36, a );\ x264_cabac_encode_decision( cb, 37, b );\ x264_cabac_encode_decision( cb, 39, c );\ }#define WRITE_SUB_5(a,b,c,d,e) {\ x264_cabac_encode_decision( cb, 36, a );\ x264_cabac_encode_decision( cb, 37, b );\ x264_cabac_encode_decision( cb, 38, c );\ x264_cabac_encode_decision( cb, 39, d );\ x264_cabac_encode_decision( cb, 39, e );\ }#define WRITE_SUB_6(a,b,c,d,e,f) {\ WRITE_SUB_5(a,b,c,d,e)\ x264_cabac_encode_decision( cb, 39, f );\ } switch( i_sub ) { case D_DIRECT_8x8: x264_cabac_encode_decision( cb, 36, 0 ); break; case D_L0_8x8: WRITE_SUB_3(1,0,0); break; case D_L1_8x8: WRITE_SUB_3(1,0,1); break; case D_BI_8x8: WRITE_SUB_5(1,1,0,0,0); break; case D_L0_8x4: WRITE_SUB_5(1,1,0,0,1); break; case D_L0_4x8: WRITE_SUB_5(1,1,0,1,0); break; case D_L1_8x4: WRITE_SUB_5(1,1,0,1,1); break; case D_L1_4x8: WRITE_SUB_6(1,1,1,0,0,0); break; case D_BI_8x4: WRITE_SUB_6(1,1,1,0,0,1); break; case D_BI_4x8: WRITE_SUB_6(1,1,1,0,1,0); break; case D_L0_4x4: WRITE_SUB_6(1,1,1,0,1,1); break; case D_L1_4x4: WRITE_SUB_5(1,1,1,1,0); break; case D_BI_4x4: WRITE_SUB_5(1,1,1,1,1); break; }}static inline void x264_cabac_mb_transform_size( x264_t *h, x264_cabac_t *cb ){ int ctx = 399 + h->mb.cache.i_neighbour_transform_size; x264_cabac_encode_decision( cb, ctx, h->mb.b_transform_8x8 );}static inline void x264_cabac_mb_ref( x264_t *h, x264_cabac_t *cb, int i_list, int idx ){ const int i8 = x264_scan8[idx]; const int i_refa = h->mb.cache.ref[i_list][i8 - 1]; const int i_refb = h->mb.cache.ref[i_list][i8 - 8]; int i_ref = h->mb.cache.ref[i_list][i8]; int ctx = 0; if( i_refa > 0 && !h->mb.cache.skip[i8 - 1]) ctx++; if( i_refb > 0 && !h->mb.cache.skip[i8 - 8]) ctx += 2; while( i_ref > 0 ) { x264_cabac_encode_decision( cb, 54 + ctx, 1 ); if( ctx < 4 ) ctx = 4; else ctx = 5; i_ref--; } x264_cabac_encode_decision( cb, 54 + ctx, 0 );}static inline void x264_cabac_mb_mvd_cpn( x264_t *h, x264_cabac_t *cb, int i_list, int idx, int l, int mvd ){ const int amvd = abs( h->mb.cache.mvd[i_list][x264_scan8[idx] - 1][l] ) + abs( h->mb.cache.mvd[i_list][x264_scan8[idx] - 8][l] ); const int i_abs = abs( mvd ); const int i_prefix = X264_MIN( i_abs, 9 ); const int ctxbase = (l == 0 ? 40 : 47); int ctx; int i; if( amvd < 3 ) ctx = 0; else if( amvd > 32 ) ctx = 2; else ctx = 1; for( i = 0; i < i_prefix; i++ ) { x264_cabac_encode_decision( cb, ctxbase + ctx, 1 ); if( ctx < 3 ) ctx = 3; else if( ctx < 6 ) ctx++; } if( i_prefix < 9 ) x264_cabac_encode_decision( cb, ctxbase + ctx, 0 ); else x264_cabac_encode_ue_bypass( cb, 3, i_abs - 9 ); /* sign */ if( mvd > 0 ) x264_cabac_encode_bypass( cb, 0 ); else if( mvd < 0 ) x264_cabac_encode_bypass( cb, 1 );}static inline void x264_cabac_mb_mvd( x264_t *h, x264_cabac_t *cb, int i_list, int idx, int width, int height ){ int mvp[2]; int mdx, mdy; /* Calculate mvd */ x264_mb_predict_mv( h, i_list, idx, width, mvp ); mdx = h->mb.cache.mv[i_list][x264_scan8[idx]][0] - mvp[0]; mdy = h->mb.cache.mv[i_list][x264_scan8[idx]][1] - mvp[1]; /* encode */ x264_cabac_mb_mvd_cpn( h, cb, i_list, idx, 0, mdx ); x264_cabac_mb_mvd_cpn( h, cb, i_list, idx, 1, mdy ); /* save value */ x264_macroblock_cache_mvd( h, block_idx_x[idx], block_idx_y[idx], width, height, i_list, mdx, mdy );}static inline void x264_cabac_mb8x8_mvd( x264_t *h, x264_cabac_t *cb, int i_list ){ int i; for( i = 0; i < 4; i++ ) { if( !x264_mb_partition_listX_table[i_list][ h->mb.i_sub_partition[i] ] ) { continue; } switch( h->mb.i_sub_partition[i] ) { case D_L0_8x8: case D_L1_8x8: case D_BI_8x8: x264_cabac_mb_mvd( h, cb, i_list, 4*i, 2, 2 ); break; case D_L0_8x4: case D_L1_8x4: case D_BI_8x4: x264_cabac_mb_mvd( h, cb, i_list, 4*i+0, 2, 1 ); x264_cabac_mb_mvd( h, cb, i_list, 4*i+2, 2, 1 ); break; case D_L0_4x8: case D_L1_4x8: case D_BI_4x8: x264_cabac_mb_mvd( h, cb, i_list, 4*i+0, 1, 2 ); x264_cabac_mb_mvd( h, cb, i_list, 4*i+1, 1, 2 ); break; case D_L0_4x4: case D_L1_4x4: case D_BI_4x4: x264_cabac_mb_mvd( h, cb, i_list, 4*i+0, 1, 1 ); x264_cabac_mb_mvd( h, cb, i_list, 4*i+1, 1, 1 ); x264_cabac_mb_mvd( h, cb, i_list, 4*i+2, 1, 1 ); x264_cabac_mb_mvd( h, cb, i_list, 4*i+3, 1, 1 ); break; } }}static int x264_cabac_mb_cbf_ctxidxinc( x264_t *h, int i_cat, int i_idx ){ /* TODO: clean up/optimize */ int i_mba_xy = -1; int i_mbb_xy = -1; int i_nza = -1; int i_nzb = -1; int ctx = 4 * i_cat; if( i_cat == DCT_LUMA_DC ) { if( h->mb.i_neighbour & MB_LEFT ) { i_mba_xy = h->mb.i_mb_xy -1; if( h->mb.type[i_mba_xy] == I_16x16 ) { i_nza = h->mb.cbp[i_mba_xy]&0x100; } } if( h->mb.i_neighbour & MB_TOP ) { i_mbb_xy = h->mb.i_mb_xy - h->mb.i_mb_stride; if( h->mb.type[i_mbb_xy] == I_16x16 ) { i_nzb = h->mb.cbp[i_mbb_xy]&0x100; } } } else if( i_cat == DCT_LUMA_AC || i_cat == DCT_LUMA_4x4 ) { int x = block_idx_x[i_idx]; int y = block_idx_y[i_idx]; if( x > 0 ) i_mba_xy = h->mb.i_mb_xy; else if( h->mb.i_neighbour & MB_LEFT ) i_mba_xy = h->mb.i_mb_xy -1; if( y > 0 ) i_mbb_xy = h->mb.i_mb_xy; else if( h->mb.i_neighbour & MB_TOP ) i_mbb_xy = h->mb.i_mb_xy - h->mb.i_mb_stride; /* no need to test for skip/pcm */ if( i_mba_xy >= 0 ) { const int i8x8a = block_idx_xy[(x-1)&0x03][y]/4; if( (h->mb.cbp[i_mba_xy]&0x0f)>> i8x8a ) { i_nza = h->mb.cache.non_zero_count[x264_scan8[i_idx] - 1]; } } if( i_mbb_xy >= 0 ) { const int i8x8b = block_idx_xy[x][(y-1)&0x03]/4; if( (h->mb.cbp[i_mbb_xy]&0x0f)>> i8x8b ) { i_nzb = h->mb.cache.non_zero_count[x264_scan8[i_idx] - 8]; } } } else if( i_cat == DCT_CHROMA_DC ) { /* no need to test skip/pcm */ if( h->mb.i_neighbour & MB_LEFT ) { i_mba_xy = h->mb.i_mb_xy -1; if( h->mb.cbp[i_mba_xy]&0x30 ) { i_nza = h->mb.cbp[i_mba_xy]&( 0x02 << ( 8 + i_idx) ); } } if( h->mb.i_neighbour & MB_TOP ) { i_mbb_xy = h->mb.i_mb_xy - h->mb.i_mb_stride; if( h->mb.cbp[i_mbb_xy]&0x30 ) { i_nzb = h->mb.cbp[i_mbb_xy]&( 0x02 << ( 8 + i_idx) ); } } } else if( i_cat == DCT_CHROMA_AC ) { if( i_idx & 1 ) i_mba_xy = h->mb.i_mb_xy; else if( h->mb.i_neighbour & MB_LEFT ) i_mba_xy = h->mb.i_mb_xy - 1; if( i_idx & 2 ) i_mbb_xy = h->mb.i_mb_xy; else if( h->mb.i_neighbour & MB_TOP ) i_mbb_xy = h->mb.i_mb_xy - h->mb.i_mb_stride; /* no need to test skip/pcm */ if( i_mba_xy >= 0 && (h->mb.cbp[i_mba_xy]&0x30) == 0x20 ) { i_nza = h->mb.cache.non_zero_count[x264_scan8[16+i_idx] - 1]; } if( i_mbb_xy >= 0 && (h->mb.cbp[i_mbb_xy]&0x30) == 0x20 ) { i_nzb = h->mb.cache.non_zero_count[x264_scan8[16+i_idx] - 8]; } } if( ( i_mba_xy < 0 && IS_INTRA( h->mb.i_type ) ) || i_nza > 0 ) { ctx++; } if( ( i_mbb_xy < 0 && IS_INTRA( h->mb.i_type ) ) || i_nzb > 0 ) { ctx += 2; } return ctx;}static const int significant_coeff_flag_offset[6] = { 105, 120, 134, 149, 152, 402 };static const int last_coeff_flag_offset[6] = { 166, 181, 195, 210, 213, 417 };static const int coeff_abs_level_m1_offset[6] = { 227, 237, 247, 257, 266, 426 };static const int significant_coeff_flag_offset_8x8[63] = { 0, 1, 2, 3, 4, 5, 5, 4, 4, 3, 3, 4, 4, 4, 5, 5, 4, 4, 4, 4, 3, 3, 6, 7, 7, 7, 8, 9,10, 9, 8, 7,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -