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

📄 cabac.c

📁 h.264编码库 (T264)..........................
💻 C
📖 第 1 页 / 共 4 页
字号:
//            int i, b_part_mode, part_mode0, part_mode1;
//			static const int b_part_mode_map[3][3] = {
//				{ B_L0_L0, B_L0_L1, B_L0_BI },
//				{ B_L1_L0, B_L1_L1, B_L1_BI },
//				{ B_BI_L0, B_BI_L1, B_BI_BI }
//			};
//
//			switch(t->mb.mb_part)
//			{
//			case MB_16x16:
//				part_mode0 = t->mb.mb_part2[0] - B_L0_16x16;
//				b_part_mode = b_part_mode_map[part_mode0][part_mode0];
//				break;
//			case MB_16x8:
//				part_mode0 = t->mb.mb_part2[0] - B_L0_16x8;
//				part_mode1 = t->mb.mb_part2[1] - B_L0_16x8;
//				b_part_mode = b_part_mode_map[part_mode0][part_mode1];
//				break;
//			case MB_8x16:
//				part_mode0 = t->mb.mb_part2[0] - B_L0_8x16;
//				part_mode1 = t->mb.mb_part2[1] - B_L0_8x16;
//				b_part_mode = b_part_mode_map[part_mode0][part_mode1];
//				break;
//			}
//            switch( b_part_mode )
//            {
//                /* D_16x16, D_16x8, D_8x16 */
//                case B_BI_BI: idx += 3;
//                case B_L1_L1: idx += 3;
//                case B_L0_L0:
//                    if( i_partition == MB_16x8 )
//                        idx += 1;
//                    else if( i_partition == MB_8x16 )
//                        idx += 2;
//                    break;
//
//                /* D_16x8, D_8x16 */
//                case B_BI_L1: idx += 2;
//                case B_BI_L0: idx += 2;
//                case B_L1_BI: idx += 2;
//                case B_L0_BI: idx += 2;
//                case B_L1_L0: idx += 2;
//                case B_L0_L1:
//                    idx += 3*3;
//                    if( i_partition == MB_8x16 )
//                        idx++;
//                    break;
//                default:
//					return;
//			}
//
//            T264_cabac_encode_decision( &t->cabac, 27+ctx,                         i_mb_bits[idx][0] );
//            T264_cabac_encode_decision( &t->cabac, 27+3,                           i_mb_bits[idx][1] );
//            T264_cabac_encode_decision( &t->cabac, 27+(i_mb_bits[idx][1] != 0 ? 4 : 5), i_mb_bits[idx][2] );
//            for( i = 3; i < i_mb_len[idx]; i++ )
//            {
//                T264_cabac_encode_decision( &t->cabac, 27+5,                       i_mb_bits[idx][i] );
//            }
//        }
//    }
//    else
//    {
//		//dummy here
//    }
//}
//
//static void T264_cabac_mb_intra4x4_pred_mode( T264_t *t, int i_pred, int i_mode )
//{
//    if( i_pred == i_mode )
//    {
//        /* b_prev_intra4x4_pred_mode */
//        T264_cabac_encode_decision( &t->cabac, 68, 1 );
//    }
//    else
//    {
//        /* b_prev_intra4x4_pred_mode */
//        T264_cabac_encode_decision( &t->cabac, 68, 0 );
//        if( i_mode > i_pred  )
//        {
//            i_mode--;
//        }
//        T264_cabac_encode_decision( &t->cabac, 69, (i_mode     )&0x01 );
//        T264_cabac_encode_decision( &t->cabac, 69, (i_mode >> 1)&0x01 );
//        T264_cabac_encode_decision( &t->cabac, 69, (i_mode >> 2)&0x01 );
//    }
//}
//
//static void T264_cabac_mb_intra8x8_pred_mode( T264_t *t )
//{
//    const int i_mode  = t->mb.mb_mode_uv;
//	T264_mb_context_t *mb_ctxs = &(t->rec->mb[0]);
//
//	int ctx = 0;
//	if( t->mb.mb_x > 0 && mb_ctxs[t->mb.mb_xy-1].mb_mode_uv != Intra_8x8_DC)
//	{
//		ctx++;
//	}
//	if( t->mb.mb_y > 0 && mb_ctxs[t->mb.mb_xy - t->mb_stride].mb_mode_uv != Intra_8x8_DC )
//	{
//		ctx++;
//	}
//	
//    if( i_mode == Intra_8x8_DC )
//    {
//        T264_cabac_encode_decision( &t->cabac, 64 + ctx, Intra_8x8_DC );
//    }
//    else
//    {
//        T264_cabac_encode_decision( &t->cabac, 64 + ctx, 1 );
//        T264_cabac_encode_decision( &t->cabac, 64 + 3, ( i_mode == 1 ? 0 : 1 ) );
//        if( i_mode > 1 )
//        {
//            T264_cabac_encode_decision( &t->cabac, 64 + 3, ( i_mode == 2 ? 0 : 1 ) );
//        }
//    }
//}
//
//static void T264_cabac_mb_cbp_luma( T264_t *t )
//{
//    /* TODO: clean up and optimize */
//	T264_mb_context_t *mb_ctxs = &(t->rec->mb[0]);
//    int i8x8;
//    for( i8x8 = 0; i8x8 < 4; i8x8++ )
//    {
//        int i_mba_xy = -1;
//        int i_mbb_xy = -1;
//        int x = luma_inverse_x[4*i8x8];
//        int y = luma_inverse_y[4*i8x8];
//        int ctx = 0;
//
//        if( x > 0 )
//            i_mba_xy = t->mb.mb_xy;
//        else if( t->mb.mb_x > 0 )
//            i_mba_xy = t->mb.mb_xy - 1;
//
//        if( y > 0 )
//            i_mbb_xy = t->mb.mb_xy;
//        else if( t->mb.mb_y > 0 )
//            i_mbb_xy = t->mb.mb_xy - t->mb_stride;
//
//
//        /* No need to test for PCM and SKIP */
//        if( i_mba_xy >= 0 )
//        {
//            const int i8x8a = block_idx_xy[(x-1)&0x03][y]/4;
//            if( ((mb_ctxs[i_mba_xy].cbp_y >> i8x8a)&0x01) == 0 )
//            {
//                ctx++;
//            }
//        }
//
//        if( i_mbb_xy >= 0 )
//        {
//            const int i8x8b = block_idx_xy[x][(y-1)&0x03]/4;
//            if( ((mb_ctxs[i_mbb_xy].cbp_y >> i8x8b)&0x01) == 0 )
//            {
//                ctx += 2;
//            }
//        }
//															   
//        T264_cabac_encode_decision( &t->cabac, 73 + ctx, (t->mb.cbp_y >> i8x8)&0x01 );
//    }
//}
//
//static void T264_cabac_mb_cbp_chroma( T264_t *t )
//{
//    int cbp_a = -1;
//    int cbp_b = -1;
//    int ctx;
//	T264_mb_context_t *mb_ctxs = &(t->rec->mb[0]);
//    /* No need to test for SKIP/PCM */
//    if( t->mb.mb_x > 0 )
//    {
//        cbp_a = (mb_ctxs[t->mb.mb_xy - 1].cbp_c)&0x3;
//    }
//
//    if( t->mb.mb_y > 0 )
//    {
//        cbp_b = (mb_ctxs[t->mb.mb_xy - t->mb_stride].cbp_c)&0x3;
//    }
//
//    ctx = 0;
//    if( cbp_a > 0 ) ctx++;
//    if( cbp_b > 0 ) ctx += 2;
//    if( t->mb.cbp_c == 0 )
//    {
//        T264_cabac_encode_decision( &t->cabac, 77 + ctx, 0 );
//    }
//    else
//    {
//        T264_cabac_encode_decision( &t->cabac, 77 + ctx, 1 );
//
//        ctx = 4;
//        if( cbp_a == 2 ) ctx++;
//        if( cbp_b == 2 ) ctx += 2;
//        T264_cabac_encode_decision( &t->cabac, 77 + ctx, t->mb.cbp_c > 1 ? 1 : 0 );
//    }
//}
//
///* TODO check it with != qp per mb */
//static void T264_cabac_mb_qp_delta( T264_t *t )
//{
//    int i_mbn_xy = t->mb.mb_xy - 1;
//    int i_dqp = t->mb.mb_qp_delta;
//    int val = i_dqp <= 0 ? (-2*i_dqp) : (2*i_dqp - 1);
//    int ctx;
//	T264_mb_context_t *mb_ctxs = &(t->rec->mb[0]);
//
//    /* No need to test for PCM / SKIP */
//    if( i_mbn_xy >= 0 && mb_ctxs[i_mbn_xy].mb_qp_delta != 0 &&
//        ( mb_ctxs[i_mbn_xy].mb_mode == I_16x16 || mb_ctxs[i_mbn_xy].cbp_y || mb_ctxs[i_mbn_xy].cbp_c) )
//        ctx = 1;
//    else
//        ctx = 0;
//
//    while( val > 0 )
//    {
//        T264_cabac_encode_decision( &t->cabac,  60 + ctx, 1 );
//        if( ctx < 2 )
//            ctx = 2;
//        else
//            ctx = 3;
//        val--;
//    }
//    T264_cabac_encode_decision( &t->cabac,  60 + ctx, 0 );
//}
//
//void T264_cabac_mb_skip( T264_t *t, int b_skip )
//{
//	T264_mb_context_t *mb_ctxs = &(t->rec->mb[0]);
//    int ctx = 0;
//
//    if( t->mb.mb_x > 0 && !IS_SKIP( mb_ctxs[t->mb.mb_xy -1].mb_mode) )
//    {
//        ctx++;
//    }
//    if( t->mb.mb_y > 0 && !IS_SKIP( mb_ctxs[t->mb.mb_xy - t->mb_stride].mb_mode) )
//    {
//        ctx++;
//    }
//
//    if( t->slice_type == SLICE_P )
//        T264_cabac_encode_decision( &t->cabac, 11 + ctx, b_skip ? 1 : 0 );
//    else /* SLICE_TYPE_B */
//        T264_cabac_encode_decision( &t->cabac, 24 + ctx, b_skip ? 1 : 0 );
//}
//
//static __inline  void T264_cabac_mb_sub_p_partition( T264_t *t, int i_sub )
//{
//    if( i_sub == MB_8x8 )
//    {
//            T264_cabac_encode_decision( &t->cabac, 21, 1 );
//    }
//    else if( i_sub == MB_8x4 )
//    {
//            T264_cabac_encode_decision( &t->cabac, 21, 0 );
//            T264_cabac_encode_decision( &t->cabac, 22, 0 );
//    }
//    else if( i_sub == MB_4x8 )
//    {
//            T264_cabac_encode_decision( &t->cabac, 21, 0 );
//            T264_cabac_encode_decision( &t->cabac, 22, 1 );
//            T264_cabac_encode_decision( &t->cabac, 23, 1 );
//    }
//    else if( i_sub == MB_4x4 )
//    {
//            T264_cabac_encode_decision( &t->cabac, 21, 0 );
//            T264_cabac_encode_decision( &t->cabac, 22, 1 );
//            T264_cabac_encode_decision( &t->cabac, 23, 0 );
//    }
//}
//
//static __inline  void T264_cabac_mb_sub_b_partition( T264_t *t, int i_sub )
//{
//    if( i_sub == B_DIRECT_8x8 )
//    {
//        T264_cabac_encode_decision( &t->cabac, 36, 0 );
//    }
//    else if( i_sub == B_L0_8x8 )
//    {
//        T264_cabac_encode_decision( &t->cabac, 36, 1 );
//        T264_cabac_encode_decision( &t->cabac, 37, 0 );
//        T264_cabac_encode_decision( &t->cabac, 39, 0 );
//    }
//    else if( i_sub == B_L1_8x8 )
//    {
//        T264_cabac_encode_decision( &t->cabac, 36, 1 );
//        T264_cabac_encode_decision( &t->cabac, 37, 0 );
//        T264_cabac_encode_decision( &t->cabac, 39, 1 );
//    }
//    else if( i_sub == B_Bi_8x8 )
//    {
//        T264_cabac_encode_decision( &t->cabac, 36, 1 );
//        T264_cabac_encode_decision( &t->cabac, 37, 1 );
//        T264_cabac_encode_decision( &t->cabac, 38, 0 );
//        T264_cabac_encode_decision( &t->cabac, 39, 0 );
//        T264_cabac_encode_decision( &t->cabac, 39, 0 );
//    }
//    else if( i_sub == B_L0_8x4 )
//    {
//        T264_cabac_encode_decision( &t->cabac, 36, 1 );
//        T264_cabac_encode_decision( &t->cabac, 37, 1 );
//        T264_cabac_encode_decision( &t->cabac, 38, 0 );
//        T264_cabac_encode_decision( &t->cabac, 39, 0 );
//        T264_cabac_encode_decision( &t->cabac, 39, 1 );
//    }
//    else if( i_sub == B_L0_4x8 )
//    {
//        T264_cabac_encode_decision( &t->cabac, 36, 1 );
//        T264_cabac_encode_decision( &t->cabac, 37, 1 );
//        T264_cabac_encode_decision( &t->cabac, 38, 0 );
//        T264_cabac_encode_decision( &t->cabac, 39, 1 );
//        T264_cabac_encode_decision( &t->cabac, 39, 0 );
//    }
//    else if( i_sub == B_L1_8x4 )
//    {
//        T264_cabac_encode_decision( &t->cabac, 36, 1 );
//        T264_cabac_encode_decision( &t->cabac, 37, 1 );
//        T264_cabac_encode_decision( &t->cabac, 38, 0 );
//        T264_cabac_encode_decision( &t->cabac, 39, 1 );
//        T264_cabac_encode_decision( &t->cabac, 39, 1 );
//    }
//    else if( i_sub == B_L1_4x8 )
//    {
//        T264_cabac_encode_decision( &t->cabac, 36, 1 );
//        T264_cabac_encode_decision( &t->cabac, 37, 1 );
//        T264_cabac_encode_decision( &t->cabac, 38, 1 );
//        T264_cabac_encode_decision( &t->cabac, 39, 0 );
//        T264_cabac_encode_decision( &t->cabac, 39, 0 );
//        T264_cabac_encode_decision( &t->cabac, 39, 0 );
//    }
//    else if( i_sub == B_Bi_8x4 )
//    {
//        T264_cabac_encode_decision( &t->cabac, 36, 1 );
//        T264_cabac_encode_decision( &t->cabac, 37, 1 );
//        T264_cabac_encode_decision( &t->cabac, 38, 1 );
//        T264_cabac_encode_decision( &t->cabac, 39, 0 );
//        T264_cabac_encode_decision( &t->cabac, 39, 0 );
//        T264_cabac_encode_decision( &t->cabac, 39, 1 );
//    }
//    else if( i_sub == B_Bi_4x8 )
//    {
//        T264_cabac_encode_decision( &t->cabac, 36, 1 );
//        T264_cabac_encode_decision( &t->cabac, 37, 1 );
//        T264_cabac_encode_decision( &t->cabac, 38, 1 );
//        T264_cabac_encode_decision( &t->cabac, 39, 0 );
//        T264_cabac_encode_decision( &t->cabac, 39, 1 );
//        T264_cabac_encode_decision( &t->cabac, 39, 0 );
//    }
//    else if( i_sub == B_L0_4x4 )
//    {
//        T264_cabac_encode_decision( &t->cabac, 36, 1 );
//        T264_cabac_encode_decision( &t->cabac, 37, 1 );
//        T264_cabac_encode_decision( &t->cabac, 38, 1 );
//        T264_cabac_encode_decision( &t->cabac, 39, 0 );
//        T264_cabac_encode_decision( &t->cabac, 39, 1 );
//        T264_cabac_encode_decision( &t->cabac, 39, 1 );
//    }
//    else if( i_sub == B_L1_4x4 )
//    {
//        T264_cabac_encode_decision( &t->cabac, 36, 1 );
//        T264_cabac_encode_decision( &t->cabac, 37, 1 );
//        T264_cabac_encode_decision( &t->cabac, 38, 1 );
//        T264_cabac_encode_decision( &t->cabac, 39, 1 );
//        T264_cabac_encode_decision( &t->cabac, 39, 0 );
//    }
//    else if( i_sub == B_Bi_4x4 )
//    {

⌨️ 快捷键说明

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