#define X264_MAX(a,b) ( (a)>(b) ? (a) : (b) )
#define X264_ABS(a) ( (a)< 0 ? -(a) : (a) )
#define X264_MIN3(a,b,c) X264_MIN((a),X264_MIN((b),(c)))
+#define X264_MAX3(a,b,c) X264_MAX((a),X264_MAX((b),(c)))
#define X264_MIN4(a,b,c,d) X264_MIN((a),X264_MIN3((b),(c),(d)))
+#define X264_MAX4(a,b,c,d) X264_MAX((a),X264_MAX3((b),(c),(d)))
/****************************************************************************
* Generals functions
int i_cabac_init_idc;
+ int i_qp;
int i_qp_delta;
int b_sp_for_swidth;
int i_qs_delta;
h->mb.type[i_mb_xy] = i_mb_type;
- if( IS_SKIP( h->mb.i_type ) )
- h->mb.qp[i_mb_xy] = h->mb.i_last_qp;
+ if( h->mb.i_type != I_16x16 && h->mb.i_cbp_luma == 0 && h->mb.i_cbp_chroma == 0 )
+ h->mb.i_qp = h->mb.i_last_qp;
+ h->mb.qp[i_mb_xy] = h->mb.i_qp;
- h->mb.i_last_dqp = h->mb.qp[i_mb_xy] - h->mb.i_last_qp;
- h->mb.i_last_qp = h->mb.qp[i_mb_xy];
+ h->mb.i_last_dqp = h->mb.i_qp - h->mb.i_last_qp;
+ h->mb.i_last_qp = h->mb.i_qp;
/* save intra4x4 */
if( i_mb_type == I_4x4 )
}
}
+ if( h->mb.i_cbp_luma == 0 && h->mb.i_type != I_8x8 )
+ h->mb.b_transform_8x8 = 0;
h->mb.mb_transform_size[i_mb_xy] = h->mb.b_transform_8x8;
if( !IS_INTRA( i_mb_type ) )
memset( a, 0, sizeof( x264_mb_analysis_t ) );
/* conduct the analysis using this lamda and QP */
- a->i_qp = i_qp;
+ a->i_qp = h->mb.i_qp = i_qp;
a->i_lambda = i_qp0_cost_table[i_qp];
a->i_lambda2 = i_qp0_cost2_table[i_qp];
a->b_mbrd = h->param.analyse.i_subpel_refine >= 6 && h->sh.i_type != SLICE_TYPE_B;
void x264_macroblock_analyse( x264_t *h )
{
x264_mb_analysis_t analysis;
+ int i_cost = COST_MAX;
int i;
- h->mb.i_qp =
- h->mb.qp[h->mb.i_mb_xy] = x264_ratecontrol_qp( h );
-
/* init analysis */
- x264_mb_analyse_init( h, &analysis, h->mb.qp[h->mb.i_mb_xy] );
+ x264_mb_analyse_init( h, &analysis, x264_ratecontrol_qp( h ) );
/*--------------------------- Do the analysis ---------------------------*/
if( h->sh.i_type == SLICE_TYPE_I )
{
- int i_cost;
x264_mb_analyse_intra( h, &analysis, COST_MAX );
i_cost = analysis.i_sad_i16x16;
else if( h->sh.i_type == SLICE_TYPE_P )
{
int b_skip = 0;
- int i_cost;
int i_intra_cost, i_intra_type;
/* Fast P_SKIP detection */
{
const unsigned int flags = h->param.analyse.inter;
int i_partition;
- int i_cost;
x264_mb_analyse_load_costs( h, &analysis );
}
else
{
+ int i_pred = x264_mb_pred_mode16x16_fix[h->mb.i_intra16x16_pred_mode];
+
x264_cabac_encode_decision( cb, ctx0, 1 );
x264_cabac_encode_terminal( cb, 0 );
x264_cabac_encode_decision( cb, ctx2, 1 );
x264_cabac_encode_decision( cb, ctx3, ( h->mb.i_cbp_chroma == 1 ? 0 : 1 ) );
}
- x264_cabac_encode_decision( cb, ctx4, ( (h->mb.i_intra16x16_pred_mode / 2) ? 1 : 0 ));
- x264_cabac_encode_decision( cb, ctx5, ( (h->mb.i_intra16x16_pred_mode % 2) ? 1 : 0 ));
+ x264_cabac_encode_decision( cb, ctx4, ( (i_pred / 2) ? 1 : 0 ));
+ x264_cabac_encode_decision( cb, ctx5, ( (i_pred % 2) ? 1 : 0 ));
}
}
static void x264_cabac_mb_qp_delta( x264_t *h, x264_cabac_t *cb )
{
int i_mbn_xy = h->mb.i_mb_xy - 1;
- int i_dqp = h->mb.qp[h->mb.i_mb_xy] - h->mb.i_last_qp;
+ int i_dqp = h->mb.i_qp - h->mb.i_last_qp;
int val = i_dqp <= 0 ? (-2*i_dqp) : (2*i_dqp - 1);
int ctx;
for( i = 0; i < 16; i += di )
{
const int i_pred = x264_mb_predict_intra4x4_mode( h, i );
- const int i_mode = h->mb.cache.intra4x4_pred_mode[x264_scan8[i]];
+ const int i_mode = x264_mb_pred_mode4x4_fix( h->mb.cache.intra4x4_pred_mode[x264_scan8[i]] );
x264_cabac_mb_intra4x4_pred_mode( cb, i_pred, i_mode );
}
}
for( i = 0; i < 16; i += di )
{
int i_pred = x264_mb_predict_intra4x4_mode( h, i );
- int i_mode = h->mb.cache.intra4x4_pred_mode[x264_scan8[i]];
+ int i_mode = x264_mb_pred_mode4x4_fix( h->mb.cache.intra4x4_pred_mode[x264_scan8[i]] );
if( i_pred == i_mode)
{
}
else if( i_mb_type == I_16x16 )
{
- bs_write_ue( s, i_mb_i_offset + 1 + h->mb.i_intra16x16_pred_mode +
+ bs_write_ue( s, i_mb_i_offset + 1 + x264_mb_pred_mode16x16_fix[h->mb.i_intra16x16_pred_mode] +
h->mb.i_cbp_chroma * 4 + ( h->mb.i_cbp_luma == 0 ? 0 : 12 ) );
bs_write_ue( s, x264_mb_pred_mode8x8c_fix[ h->mb.i_chroma_pred_mode ] );
}
/* write residual */
if( i_mb_type == I_16x16 )
{
- bs_write_se( s, h->mb.qp[h->mb.i_mb_xy] - h->mb.i_last_qp );
+ bs_write_se( s, h->mb.i_qp - h->mb.i_last_qp );
/* DC Luma */
block_residual_write_cavlc( h, s, BLOCK_INDEX_LUMA_DC , h->dct.luma16x16_dc, 16 );
}
else if( h->mb.i_cbp_luma != 0 || h->mb.i_cbp_chroma != 0 )
{
- bs_write_se( s, h->mb.qp[h->mb.i_mb_xy] - h->mb.i_last_qp );
+ bs_write_se( s, h->mb.i_qp - h->mb.i_last_qp );
x264_macroblock_luma_write_cavlc( h, s );
}
if( h->mb.i_cbp_chroma != 0 )
sh->i_cabac_init_idc = param->i_cabac_init_idc;
+ sh->i_qp = i_qp;
sh->i_qp_delta = i_qp - pps->i_pic_init_qp;
sh->b_sp_for_swidth = 0;
sh->i_qs_delta = 0;
bs_align_1( &h->out.bs );
/* init cabac */
- x264_cabac_context_init( &h->cabac, h->sh.i_type, h->sh.pps->i_pic_init_qp + h->sh.i_qp_delta, h->sh.i_cabac_init_idc );
+ x264_cabac_context_init( &h->cabac, h->sh.i_type, h->sh.i_qp, h->sh.i_cabac_init_idc );
x264_cabac_encode_init ( &h->cabac, &h->out.bs );
}
- h->mb.i_last_qp = h->pps->i_pic_init_qp + h->sh.i_qp_delta;
+ h->mb.i_last_qp = h->sh.i_qp;
h->mb.i_last_dqp = 0;
for( mb_xy = h->sh.i_first_mb, i_skip = 0; mb_xy < h->sh.i_last_mb; mb_xy++ )
/* update cabac */
if( h->param.b_cabac && h->param.i_cabac_init_idc == -1 )
{
- x264_cabac_model_update( &h->cabac, i_slice_type, h->sh.pps->i_pic_init_qp + h->sh.i_qp_delta );
+ x264_cabac_model_update( &h->cabac, i_slice_type, h->sh.i_qp );
}
/* handle references */
/* encode the 16x16 macroblock */
x264_mb_encode_i16x16( h, i_qp );
-
- /* fix the pred mode value */
- h->mb.i_intra16x16_pred_mode = x264_mb_pred_mode16x16_fix[i_mode];
}
else if( h->mb.i_type == I_8x8 )
{
h->predict_8x8[i_mode]( p_dst, i_dst, h->mb.i_neighbour8[i] );
x264_mb_encode_i8x8( h, i, i_qp );
- h->mb.cache.intra4x4_pred_mode[x264_scan8[4*i]] = x264_mb_pred_mode4x4_fix(i_mode);
}
}
else if( h->mb.i_type == I_4x4 )
h->predict_4x4[i_mode]( p_dst, i_dst );
x264_mb_encode_i4x4( h, i, i_qp );
- h->mb.cache.intra4x4_pred_mode[x264_scan8[i]] = x264_mb_pred_mode4x4_fix(i_mode);
}
}
else /* Inter MB */
/* store cbp */
h->mb.cbp[h->mb.i_mb_xy] = (i_cbp_dc << 8) | (h->mb.i_cbp_chroma << 4) | h->mb.i_cbp_luma;
- if( h->mb.i_type != I_16x16 && h->mb.i_cbp_luma == 0 && h->mb.i_cbp_chroma == 0 )
- {
- /* It won'y change anything at the decoder side but it is needed else the
- * decoder will fail to read the next QP */
- h->mb.qp[h->mb.i_mb_xy] = h->mb.i_last_qp;
- }
-
-
/* Check for P_SKIP
* XXX: in the me perhaps we should take x264_mb_predict_mv_pskip into account
* (if multiple mv give same result)*/
h->mb.cache.mv[0][x264_scan8[0]][1] == mvp[1] )
{
h->mb.i_type = P_SKIP;
- h->mb.qp[h->mb.i_mb_xy] = h->mb.i_last_qp; /* Needed */
- /* XXX qp reset may have issues when used in RD instead of the real encode */
}
}
h->mb.i_cbp_luma == 0x00 && h->mb.i_cbp_chroma== 0x00 )
{
h->mb.i_type = B_SKIP;
- h->mb.qp[h->mb.i_mb_xy] = h->mb.i_last_qp; /* Needed */
}
-
- if( h->mb.i_cbp_luma == 0 && h->mb.i_type != I_8x8 )
- h->mb.b_transform_8x8 = 0;
}
/*****************************************************************************