- const int i_mb_type = h->mb.i_type;
-
- if( h->sh.b_mbaff &&
- (!(h->mb.i_mb_y & 1) || IS_SKIP(h->mb.type[h->mb.i_mb_xy - h->mb.i_mb_stride])) )
- {
- x264_cabac_encode_decision_noup( cb, 70 + h->mb.cache.i_neighbour_interlaced, h->mb.b_interlaced );
- }
-
- if( h->sh.i_type == SLICE_TYPE_I )
- {
- int ctx = 0;
- if( h->mb.i_mb_type_left >= 0 && h->mb.i_mb_type_left != I_4x4 )
- ctx++;
- if( h->mb.i_mb_type_top >= 0 && h->mb.i_mb_type_top != I_4x4 )
- ctx++;
-
- x264_cabac_mb_type_intra( h, cb, i_mb_type, 3+ctx, 3+3, 3+4, 3+5, 3+6, 3+7 );
- }
- else if( h->sh.i_type == SLICE_TYPE_P )
- {
- /* prefix: 14, suffix: 17 */
- if( i_mb_type == P_L0 )
- {
- if( h->mb.i_partition == D_16x16 )
- {
- x264_cabac_encode_decision_noup( cb, 14, 0 );
- x264_cabac_encode_decision_noup( cb, 15, 0 );
- x264_cabac_encode_decision_noup( cb, 16, 0 );
- }
- else if( h->mb.i_partition == D_16x8 )
- {
- x264_cabac_encode_decision_noup( cb, 14, 0 );
- x264_cabac_encode_decision_noup( cb, 15, 1 );
- x264_cabac_encode_decision_noup( cb, 17, 1 );
- }
- else if( h->mb.i_partition == D_8x16 )
- {
- x264_cabac_encode_decision_noup( cb, 14, 0 );
- x264_cabac_encode_decision_noup( cb, 15, 1 );
- x264_cabac_encode_decision_noup( cb, 17, 0 );
- }
- }
- else if( i_mb_type == P_8x8 )
- {
- x264_cabac_encode_decision_noup( cb, 14, 0 );
- x264_cabac_encode_decision_noup( cb, 15, 0 );
- x264_cabac_encode_decision_noup( cb, 16, 1 );
- }
- else /* intra */
- {
- /* prefix */
- x264_cabac_encode_decision_noup( cb, 14, 1 );
-
- /* suffix */
- x264_cabac_mb_type_intra( h, cb, i_mb_type, 17+0, 17+1, 17+2, 17+2, 17+3, 17+3 );
- }
- }
- else if( h->sh.i_type == SLICE_TYPE_B )
- {
- int ctx = 0;
- if( h->mb.i_mb_type_left >= 0 && h->mb.i_mb_type_left != B_SKIP && h->mb.i_mb_type_left != B_DIRECT )
- ctx++;
- if( h->mb.i_mb_type_top >= 0 && h->mb.i_mb_type_top != B_SKIP && h->mb.i_mb_type_top != B_DIRECT )
- ctx++;
-
- if( i_mb_type == B_DIRECT )
- x264_cabac_encode_decision_noup( cb, 27+ctx, 0 );
- else if( i_mb_type == B_8x8 )
- {
- x264_cabac_encode_decision_noup( cb, 27+ctx, 1 );
- x264_cabac_encode_decision_noup( cb, 27+3, 1 );
- x264_cabac_encode_decision_noup( cb, 27+4, 1 );
- x264_cabac_encode_decision( cb, 27+5, 1 );
- x264_cabac_encode_decision( cb, 27+5, 1 );
- x264_cabac_encode_decision_noup( cb, 27+5, 1 );
- }
- else if( IS_INTRA( i_mb_type ) )
- {
- /* prefix */
- x264_cabac_encode_decision_noup( cb, 27+ctx, 1 );
- x264_cabac_encode_decision_noup( cb, 27+3, 1 );
- x264_cabac_encode_decision_noup( cb, 27+4, 1 );
- x264_cabac_encode_decision( cb, 27+5, 1 );
- x264_cabac_encode_decision( cb, 27+5, 0 );
- x264_cabac_encode_decision( cb, 27+5, 1 );
-
- /* suffix */
- x264_cabac_mb_type_intra( h, cb, i_mb_type, 32+0, 32+1, 32+2, 32+2, 32+3, 32+3 );
- }
- else
- {
- static const int i_mb_len[9*3] =
- {
- 6, 6, 3, /* L0 L0 */
- 6, 6, 0, /* L0 L1 */
- 7, 7, 0, /* L0 BI */
- 6, 6, 0, /* L1 L0 */
- 6, 6, 3, /* L1 L1 */
- 7, 7, 0, /* L1 BI */
- 7, 7, 0, /* BI L0 */
- 7, 7, 0, /* BI L1 */
- 7, 7, 6, /* BI BI */
- };
- static const int i_mb_bits[9*3][7] =
- {
- { 1,1,0,0,0,1 }, { 1,1,0,0,1,0, }, { 1,0,0 }, /* L0 L0 */
- { 1,1,0,1,0,1 }, { 1,1,0,1,1,0 }, {0}, /* L0 L1 */
- { 1,1,1,0,0,0,0 }, { 1,1,1,0,0,0,1 }, {0}, /* L0 BI */
- { 1,1,0,1,1,1 }, { 1,1,1,1,1,0 }, {0}, /* L1 L0 */
- { 1,1,0,0,1,1 }, { 1,1,0,1,0,0 }, { 1,0,1 }, /* L1 L1 */
- { 1,1,1,0,0,1,0 }, { 1,1,1,0,0,1,1 }, {0}, /* L1 BI */
- { 1,1,1,0,1,0,0 }, { 1,1,1,0,1,0,1 }, {0}, /* BI L0 */
- { 1,1,1,0,1,1,0 }, { 1,1,1,0,1,1,1 }, {0}, /* BI L1 */
- { 1,1,1,1,0,0,0 }, { 1,1,1,1,0,0,1 }, { 1,1,0,0,0,0 }, /* BI BI */
- };
-
- const int idx = (i_mb_type - B_L0_L0) * 3 + (h->mb.i_partition - D_16x8);
- int i;
-
- x264_cabac_encode_decision_noup( cb, 27+ctx, i_mb_bits[idx][0] );
- x264_cabac_encode_decision_noup( cb, 27+3, i_mb_bits[idx][1] );
- x264_cabac_encode_decision( cb, 27+5-i_mb_bits[idx][1], i_mb_bits[idx][2] );
- for( i = 3; i < i_mb_len[idx]; i++ )
- x264_cabac_encode_decision( cb, 27+5, i_mb_bits[idx][i] );
- }
- }
- else
- {
- x264_log(h, X264_LOG_ERROR, "unknown SLICE_TYPE unsupported in x264_macroblock_write_cabac\n" );
- }