diff options
Diffstat (limited to 'vp8/encoder')
-rw-r--r-- | vp8/encoder/encodeframe.c | 376 | ||||
-rw-r--r-- | vp8/encoder/encodeintra.c | 3 | ||||
-rw-r--r-- | vp8/encoder/encodeintra.h | 1 | ||||
-rw-r--r-- | vp8/encoder/generic/csystemdependent.c | 2 | ||||
-rw-r--r-- | vp8/encoder/onyx_if.c | 61 | ||||
-rw-r--r-- | vp8/encoder/onyx_int.h | 4 | ||||
-rw-r--r-- | vp8/encoder/pickinter.c | 29 | ||||
-rw-r--r-- | vp8/encoder/quantize.c | 418 | ||||
-rw-r--r-- | vp8/encoder/quantize.h | 7 | ||||
-rw-r--r-- | vp8/encoder/rdopt.c | 54 | ||||
-rw-r--r-- | vp8/encoder/variance.h | 2 | ||||
-rw-r--r-- | vp8/encoder/x86/x86_csystemdependent.c | 4 |
12 files changed, 495 insertions, 466 deletions
diff --git a/vp8/encoder/encodeframe.c b/vp8/encoder/encodeframe.c index 8668a6427..4d79d9cbe 100644 --- a/vp8/encoder/encodeframe.c +++ b/vp8/encoder/encodeframe.c @@ -60,370 +60,6 @@ unsigned int uv_modes[4] = {0, 0, 0, 0}; unsigned int b_modes[14] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; #endif -static const int qrounding_factors[129] = -{ - 48, 48, 48, 48, 48, 48, 48, 48, - 48, 48, 48, 48, 48, 48, 48, 48, - 48, 48, 48, 48, 48, 48, 48, 48, - 48, 48, 48, 48, 48, 48, 48, 48, - 48, 48, 48, 48, 48, 48, 48, 48, - 48, 48, 48, 48, 48, 48, 48, 48, - 48, 48, 48, 48, 48, 48, 48, 48, - 48, 48, 48, 48, 48, 48, 48, 48, - 48, 48, 48, 48, 48, 48, 48, 48, - 48, 48, 48, 48, 48, 48, 48, 48, - 48, 48, 48, 48, 48, 48, 48, 48, - 48, 48, 48, 48, 48, 48, 48, 48, - 48, 48, 48, 48, 48, 48, 48, 48, - 48, 48, 48, 48, 48, 48, 48, 48, - 48, 48, 48, 48, 48, 48, 48, 48, - 48, 48, 48, 48, 48, 48, 48, 48, - 48 -}; - -static const int qzbin_factors[129] = -{ - 84, 84, 84, 84, 84, 84, 84, 84, - 84, 84, 84, 84, 84, 84, 84, 84, - 84, 84, 84, 84, 84, 84, 84, 84, - 84, 84, 84, 84, 84, 84, 84, 84, - 84, 84, 84, 84, 84, 84, 84, 84, - 84, 84, 84, 84, 84, 84, 84, 84, - 80, 80, 80, 80, 80, 80, 80, 80, - 80, 80, 80, 80, 80, 80, 80, 80, - 80, 80, 80, 80, 80, 80, 80, 80, - 80, 80, 80, 80, 80, 80, 80, 80, - 80, 80, 80, 80, 80, 80, 80, 80, - 80, 80, 80, 80, 80, 80, 80, 80, - 80, 80, 80, 80, 80, 80, 80, 80, - 80, 80, 80, 80, 80, 80, 80, 80, - 80, 80, 80, 80, 80, 80, 80, 80, - 80, 80, 80, 80, 80, 80, 80, 80, - 80 -}; - -static const int qrounding_factors_y2[129] = -{ - 48, 48, 48, 48, 48, 48, 48, 48, - 48, 48, 48, 48, 48, 48, 48, 48, - 48, 48, 48, 48, 48, 48, 48, 48, - 48, 48, 48, 48, 48, 48, 48, 48, - 48, 48, 48, 48, 48, 48, 48, 48, - 48, 48, 48, 48, 48, 48, 48, 48, - 48, 48, 48, 48, 48, 48, 48, 48, - 48, 48, 48, 48, 48, 48, 48, 48, - 48, 48, 48, 48, 48, 48, 48, 48, - 48, 48, 48, 48, 48, 48, 48, 48, - 48, 48, 48, 48, 48, 48, 48, 48, - 48, 48, 48, 48, 48, 48, 48, 48, - 48, 48, 48, 48, 48, 48, 48, 48, - 48, 48, 48, 48, 48, 48, 48, 48, - 48, 48, 48, 48, 48, 48, 48, 48, - 48, 48, 48, 48, 48, 48, 48, 48, - 48 -}; - -static const int qzbin_factors_y2[129] = -{ - 84, 84, 84, 84, 84, 84, 84, 84, - 84, 84, 84, 84, 84, 84, 84, 84, - 84, 84, 84, 84, 84, 84, 84, 84, - 84, 84, 84, 84, 84, 84, 84, 84, - 84, 84, 84, 84, 84, 84, 84, 84, - 84, 84, 84, 84, 84, 84, 84, 84, - 80, 80, 80, 80, 80, 80, 80, 80, - 80, 80, 80, 80, 80, 80, 80, 80, - 80, 80, 80, 80, 80, 80, 80, 80, - 80, 80, 80, 80, 80, 80, 80, 80, - 80, 80, 80, 80, 80, 80, 80, 80, - 80, 80, 80, 80, 80, 80, 80, 80, - 80, 80, 80, 80, 80, 80, 80, 80, - 80, 80, 80, 80, 80, 80, 80, 80, - 80, 80, 80, 80, 80, 80, 80, 80, - 80, 80, 80, 80, 80, 80, 80, 80, - 80 -}; - -#define EXACT_QUANT -#ifdef EXACT_QUANT -static void vp8cx_invert_quant(int improved_quant, short *quant, - unsigned char *shift, short d) -{ - if(improved_quant) - { - unsigned t; - int l; - t = d; - for(l = 0; t > 1; l++) - t>>=1; - t = 1 + (1<<(16+l))/d; - *quant = (short)(t - (1<<16)); - *shift = l; - } - else - { - *quant = (1 << 16) / d; - *shift = 0; - } -} - -void vp8cx_init_quantizer(VP8_COMP *cpi) -{ - int i; - int quant_val; - int Q; - - int zbin_boost[16] = {0, 0, 8, 10, 12, 14, 16, 20, 24, 28, 32, 36, 40, 44, 44, 44}; - - for (Q = 0; Q < QINDEX_RANGE; Q++) - { - // dc values - quant_val = vp8_dc_quant(Q, cpi->common.y1dc_delta_q); - cpi->Y1quant_fast[Q][0] = (1 << 16) / quant_val; - vp8cx_invert_quant(cpi->sf.improved_quant, cpi->Y1quant[Q] + 0, - cpi->Y1quant_shift[Q] + 0, quant_val); - cpi->Y1zbin[Q][0] = ((qzbin_factors[Q] * quant_val) + 64) >> 7; - cpi->Y1round[Q][0] = (qrounding_factors[Q] * quant_val) >> 7; - cpi->common.Y1dequant[Q][0] = quant_val; - cpi->zrun_zbin_boost_y1[Q][0] = (quant_val * zbin_boost[0]) >> 7; - - quant_val = vp8_dc2quant(Q, cpi->common.y2dc_delta_q); - cpi->Y2quant_fast[Q][0] = (1 << 16) / quant_val; - vp8cx_invert_quant(cpi->sf.improved_quant, cpi->Y2quant[Q] + 0, - cpi->Y2quant_shift[Q] + 0, quant_val); - cpi->Y2zbin[Q][0] = ((qzbin_factors_y2[Q] * quant_val) + 64) >> 7; - cpi->Y2round[Q][0] = (qrounding_factors_y2[Q] * quant_val) >> 7; - cpi->common.Y2dequant[Q][0] = quant_val; - cpi->zrun_zbin_boost_y2[Q][0] = (quant_val * zbin_boost[0]) >> 7; - - quant_val = vp8_dc_uv_quant(Q, cpi->common.uvdc_delta_q); - cpi->UVquant_fast[Q][0] = (1 << 16) / quant_val; - vp8cx_invert_quant(cpi->sf.improved_quant, cpi->UVquant[Q] + 0, - cpi->UVquant_shift[Q] + 0, quant_val); - cpi->UVzbin[Q][0] = ((qzbin_factors[Q] * quant_val) + 64) >> 7;; - cpi->UVround[Q][0] = (qrounding_factors[Q] * quant_val) >> 7; - cpi->common.UVdequant[Q][0] = quant_val; - cpi->zrun_zbin_boost_uv[Q][0] = (quant_val * zbin_boost[0]) >> 7; - - // all the ac values = ; - for (i = 1; i < 16; i++) - { - int rc = vp8_default_zig_zag1d[i]; - - quant_val = vp8_ac_yquant(Q); - cpi->Y1quant_fast[Q][rc] = (1 << 16) / quant_val; - vp8cx_invert_quant(cpi->sf.improved_quant, cpi->Y1quant[Q] + rc, - cpi->Y1quant_shift[Q] + rc, quant_val); - cpi->Y1zbin[Q][rc] = ((qzbin_factors[Q] * quant_val) + 64) >> 7; - cpi->Y1round[Q][rc] = (qrounding_factors[Q] * quant_val) >> 7; - cpi->common.Y1dequant[Q][rc] = quant_val; - cpi->zrun_zbin_boost_y1[Q][i] = (quant_val * zbin_boost[i]) >> 7; - - quant_val = vp8_ac2quant(Q, cpi->common.y2ac_delta_q); - cpi->Y2quant_fast[Q][rc] = (1 << 16) / quant_val; - vp8cx_invert_quant(cpi->sf.improved_quant, cpi->Y2quant[Q] + rc, - cpi->Y2quant_shift[Q] + rc, quant_val); - cpi->Y2zbin[Q][rc] = ((qzbin_factors_y2[Q] * quant_val) + 64) >> 7; - cpi->Y2round[Q][rc] = (qrounding_factors_y2[Q] * quant_val) >> 7; - cpi->common.Y2dequant[Q][rc] = quant_val; - cpi->zrun_zbin_boost_y2[Q][i] = (quant_val * zbin_boost[i]) >> 7; - - quant_val = vp8_ac_uv_quant(Q, cpi->common.uvac_delta_q); - cpi->UVquant_fast[Q][rc] = (1 << 16) / quant_val; - vp8cx_invert_quant(cpi->sf.improved_quant, cpi->UVquant[Q] + rc, - cpi->UVquant_shift[Q] + rc, quant_val); - cpi->UVzbin[Q][rc] = ((qzbin_factors[Q] * quant_val) + 64) >> 7; - cpi->UVround[Q][rc] = (qrounding_factors[Q] * quant_val) >> 7; - cpi->common.UVdequant[Q][rc] = quant_val; - cpi->zrun_zbin_boost_uv[Q][i] = (quant_val * zbin_boost[i]) >> 7; - } - } -} -#else -void vp8cx_init_quantizer(VP8_COMP *cpi) -{ - int i; - int quant_val; - int Q; - - int zbin_boost[16] = {0, 0, 8, 10, 12, 14, 16, 20, 24, 28, 32, 36, 40, 44, 44, 44}; - - for (Q = 0; Q < QINDEX_RANGE; Q++) - { - // dc values - quant_val = vp8_dc_quant(Q, cpi->common.y1dc_delta_q); - cpi->Y1quant[Q][0] = (1 << 16) / quant_val; - cpi->Y1zbin[Q][0] = ((qzbin_factors[Q] * quant_val) + 64) >> 7; - cpi->Y1round[Q][0] = (qrounding_factors[Q] * quant_val) >> 7; - cpi->common.Y1dequant[Q][0] = quant_val; - cpi->zrun_zbin_boost_y1[Q][0] = (quant_val * zbin_boost[0]) >> 7; - - quant_val = vp8_dc2quant(Q, cpi->common.y2dc_delta_q); - cpi->Y2quant[Q][0] = (1 << 16) / quant_val; - cpi->Y2zbin[Q][0] = ((qzbin_factors_y2[Q] * quant_val) + 64) >> 7; - cpi->Y2round[Q][0] = (qrounding_factors_y2[Q] * quant_val) >> 7; - cpi->common.Y2dequant[Q][0] = quant_val; - cpi->zrun_zbin_boost_y2[Q][0] = (quant_val * zbin_boost[0]) >> 7; - - quant_val = vp8_dc_uv_quant(Q, cpi->common.uvdc_delta_q); - cpi->UVquant[Q][0] = (1 << 16) / quant_val; - cpi->UVzbin[Q][0] = ((qzbin_factors[Q] * quant_val) + 64) >> 7;; - cpi->UVround[Q][0] = (qrounding_factors[Q] * quant_val) >> 7; - cpi->common.UVdequant[Q][0] = quant_val; - cpi->zrun_zbin_boost_uv[Q][0] = (quant_val * zbin_boost[0]) >> 7; - - // all the ac values = ; - for (i = 1; i < 16; i++) - { - int rc = vp8_default_zig_zag1d[i]; - - quant_val = vp8_ac_yquant(Q); - cpi->Y1quant[Q][rc] = (1 << 16) / quant_val; - cpi->Y1zbin[Q][rc] = ((qzbin_factors[Q] * quant_val) + 64) >> 7; - cpi->Y1round[Q][rc] = (qrounding_factors[Q] * quant_val) >> 7; - cpi->common.Y1dequant[Q][rc] = quant_val; - cpi->zrun_zbin_boost_y1[Q][i] = (quant_val * zbin_boost[i]) >> 7; - - quant_val = vp8_ac2quant(Q, cpi->common.y2ac_delta_q); - cpi->Y2quant[Q][rc] = (1 << 16) / quant_val; - cpi->Y2zbin[Q][rc] = ((qzbin_factors_y2[Q] * quant_val) + 64) >> 7; - cpi->Y2round[Q][rc] = (qrounding_factors_y2[Q] * quant_val) >> 7; - cpi->common.Y2dequant[Q][rc] = quant_val; - cpi->zrun_zbin_boost_y2[Q][i] = (quant_val * zbin_boost[i]) >> 7; - - quant_val = vp8_ac_uv_quant(Q, cpi->common.uvac_delta_q); - cpi->UVquant[Q][rc] = (1 << 16) / quant_val; - cpi->UVzbin[Q][rc] = ((qzbin_factors[Q] * quant_val) + 64) >> 7; - cpi->UVround[Q][rc] = (qrounding_factors[Q] * quant_val) >> 7; - cpi->common.UVdequant[Q][rc] = quant_val; - cpi->zrun_zbin_boost_uv[Q][i] = (quant_val * zbin_boost[i]) >> 7; - } - } -} -#endif -void vp8cx_mb_init_quantizer(VP8_COMP *cpi, MACROBLOCK *x) -{ - int i; - int QIndex; - MACROBLOCKD *xd = &x->e_mbd; - int zbin_extra; - - // Select the baseline MB Q index. - if (xd->segmentation_enabled) - { - // Abs Value - if (xd->mb_segement_abs_delta == SEGMENT_ABSDATA) - - QIndex = xd->segment_feature_data[MB_LVL_ALT_Q][xd->mode_info_context->mbmi.segment_id]; - // Delta Value - else - { - QIndex = cpi->common.base_qindex + xd->segment_feature_data[MB_LVL_ALT_Q][xd->mode_info_context->mbmi.segment_id]; - QIndex = (QIndex >= 0) ? ((QIndex <= MAXQ) ? QIndex : MAXQ) : 0; // Clamp to valid range - } - } - else - QIndex = cpi->common.base_qindex; - - // Y - zbin_extra = ( cpi->common.Y1dequant[QIndex][1] * - ( cpi->zbin_over_quant + - cpi->zbin_mode_boost + - x->act_zbin_adj ) ) >> 7; - - for (i = 0; i < 16; i++) - { - x->block[i].quant = cpi->Y1quant[QIndex]; - x->block[i].quant_fast = cpi->Y1quant_fast[QIndex]; - x->block[i].quant_shift = cpi->Y1quant_shift[QIndex]; - x->block[i].zbin = cpi->Y1zbin[QIndex]; - x->block[i].round = cpi->Y1round[QIndex]; - x->e_mbd.block[i].dequant = cpi->common.Y1dequant[QIndex]; - x->block[i].zrun_zbin_boost = cpi->zrun_zbin_boost_y1[QIndex]; - x->block[i].zbin_extra = (short)zbin_extra; - } - - // UV - zbin_extra = ( cpi->common.UVdequant[QIndex][1] * - ( cpi->zbin_over_quant + - cpi->zbin_mode_boost + - x->act_zbin_adj ) ) >> 7; - - for (i = 16; i < 24; i++) - { - x->block[i].quant = cpi->UVquant[QIndex]; - x->block[i].quant_fast = cpi->UVquant_fast[QIndex]; - x->block[i].quant_shift = cpi->UVquant_shift[QIndex]; - x->block[i].zbin = cpi->UVzbin[QIndex]; - x->block[i].round = cpi->UVround[QIndex]; - x->e_mbd.block[i].dequant = cpi->common.UVdequant[QIndex]; - x->block[i].zrun_zbin_boost = cpi->zrun_zbin_boost_uv[QIndex]; - x->block[i].zbin_extra = (short)zbin_extra; - } - - // Y2 - zbin_extra = ( cpi->common.Y2dequant[QIndex][1] * - ( (cpi->zbin_over_quant / 2) + - cpi->zbin_mode_boost + - x->act_zbin_adj ) ) >> 7; - - x->block[24].quant_fast = cpi->Y2quant_fast[QIndex]; - x->block[24].quant = cpi->Y2quant[QIndex]; - x->block[24].quant_shift = cpi->Y2quant_shift[QIndex]; - x->block[24].zbin = cpi->Y2zbin[QIndex]; - x->block[24].round = cpi->Y2round[QIndex]; - x->e_mbd.block[24].dequant = cpi->common.Y2dequant[QIndex]; - x->block[24].zrun_zbin_boost = cpi->zrun_zbin_boost_y2[QIndex]; - x->block[24].zbin_extra = (short)zbin_extra; - - /* save this macroblock QIndex for vp8_update_zbin_extra() */ - x->q_index = QIndex; -} -void vp8_update_zbin_extra(VP8_COMP *cpi, MACROBLOCK *x) -{ - int i; - int QIndex = x->q_index; - int zbin_extra; - - // Y - zbin_extra = ( cpi->common.Y1dequant[QIndex][1] * - ( cpi->zbin_over_quant + - cpi->zbin_mode_boost + - x->act_zbin_adj ) ) >> 7; - for (i = 0; i < 16; i++) - { - x->block[i].zbin_extra = (short)zbin_extra; - } - - // UV - zbin_extra = ( cpi->common.UVdequant[QIndex][1] * - ( cpi->zbin_over_quant + - cpi->zbin_mode_boost + - x->act_zbin_adj ) ) >> 7; - - for (i = 16; i < 24; i++) - { - x->block[i].zbin_extra = (short)zbin_extra; - } - - // Y2 - zbin_extra = ( cpi->common.Y2dequant[QIndex][1] * - ( (cpi->zbin_over_quant / 2) + - cpi->zbin_mode_boost + - x->act_zbin_adj ) ) >> 7; - - x->block[24].zbin_extra = (short)zbin_extra; -} - -void vp8cx_frame_init_quantizer(VP8_COMP *cpi) -{ - // Clear Zbin mode boost for default case - cpi->zbin_mode_boost = 0; - - // MB level quantizer setup - vp8cx_mb_init_quantizer(cpi, &cpi->mb); -} - /* activity_avg must be positive, or flat regions could get a zero weight * (infinite lambda), which confounds analysis. @@ -444,7 +80,7 @@ static const unsigned char VP8_VAR_OFFS[16]= // Original activity measure from Tim T's code. -unsigned int tt_activity_measure( VP8_COMP *cpi, MACROBLOCK *x ) +static unsigned int tt_activity_measure( VP8_COMP *cpi, MACROBLOCK *x ) { unsigned int act; unsigned int sse; @@ -474,7 +110,7 @@ unsigned int tt_activity_measure( VP8_COMP *cpi, MACROBLOCK *x ) } // Stub for alternative experimental activity measures. -unsigned int alt_activity_measure( VP8_COMP *cpi, MACROBLOCK *x ) +static unsigned int alt_activity_measure( VP8_COMP *cpi, MACROBLOCK *x ) { unsigned int mb_activity = VP8_ACTIVITY_AVG_MIN; @@ -492,7 +128,7 @@ unsigned int alt_activity_measure( VP8_COMP *cpi, MACROBLOCK *x ) // Measure the activity of the current macroblock // What we measure here is TBD so abstracted to this function -unsigned int mb_activity_measure( VP8_COMP *cpi, MACROBLOCK *x ) +static unsigned int mb_activity_measure( VP8_COMP *cpi, MACROBLOCK *x ) { unsigned int mb_activity; @@ -511,7 +147,7 @@ unsigned int mb_activity_measure( VP8_COMP *cpi, MACROBLOCK *x ) } // Calculate an "average" mb activity value for the frame -void calc_av_activity( VP8_COMP *cpi, INT64 activity_sum ) +static void calc_av_activity( VP8_COMP *cpi, INT64 activity_sum ) { // Simple mean for now cpi->activity_avg = (unsigned int)(activity_sum/cpi->common.MBs); @@ -521,7 +157,7 @@ void calc_av_activity( VP8_COMP *cpi, INT64 activity_sum ) #define OUTPUT_NORM_ACT_STATS 0 // Calculate a normalized activity value for each mb -void calc_norm_activity( VP8_COMP *cpi, MACROBLOCK *x ) +static void calc_norm_activity( VP8_COMP *cpi, MACROBLOCK *x ) { VP8_COMMON *const cm = & cpi->common; int mb_row, mb_col; @@ -585,7 +221,7 @@ void calc_norm_activity( VP8_COMP *cpi, MACROBLOCK *x ) // Loop through all MBs. Note activity of each, average activity and // calculate a normalized activity for each -void build_activity_map( VP8_COMP *cpi ) +static void build_activity_map( VP8_COMP *cpi ) { MACROBLOCK *const x = & cpi->mb; VP8_COMMON *const cm = & cpi->common; diff --git a/vp8/encoder/encodeintra.c b/vp8/encoder/encodeintra.c index 5d52c9fc4..6f7e66371 100644 --- a/vp8/encoder/encodeintra.c +++ b/vp8/encoder/encodeintra.c @@ -21,9 +21,6 @@ #include "vp8/common/g_common.h" #include "encodeintra.h" -#define intra4x4ibias_rate 128 -#define intra4x4pbias_rate 256 - #if CONFIG_RUNTIME_CPU_DETECT #define IF_RTCD(x) (x) diff --git a/vp8/encoder/encodeintra.h b/vp8/encoder/encodeintra.h index 40930bc42..8159097c6 100644 --- a/vp8/encoder/encodeintra.h +++ b/vp8/encoder/encodeintra.h @@ -17,6 +17,5 @@ void vp8_encode_intra16x16mby(const VP8_ENCODER_RTCD *, MACROBLOCK *x); void vp8_encode_intra16x16mbuv(const VP8_ENCODER_RTCD *, MACROBLOCK *x); void vp8_encode_intra4x4mby(const VP8_ENCODER_RTCD *, MACROBLOCK *mb); void vp8_encode_intra4x4block(const VP8_ENCODER_RTCD *, MACROBLOCK *x, BLOCK *be, BLOCKD *b, int best_mode); -void vp8_encode_intra4x4block_rd(const VP8_ENCODER_RTCD *, MACROBLOCK *x, BLOCK *be, BLOCKD *b, int best_mode); #endif diff --git a/vp8/encoder/generic/csystemdependent.c b/vp8/encoder/generic/csystemdependent.c index d127ed114..35d2d5332 100644 --- a/vp8/encoder/generic/csystemdependent.c +++ b/vp8/encoder/generic/csystemdependent.c @@ -100,7 +100,7 @@ void vp8_cmachine_specific_config(VP8_COMP *cpi) // Pure C: vp8_yv12_copy_partial_frame_ptr = vp8_yv12_copy_partial_frame; -#if CONFIG_PSNR +#if CONFIG_INTERNAL_STATS cpi->rtcd.variance.ssimpf_8x8 = ssim_parms_8x8_c; cpi->rtcd.variance.ssimpf = ssim_parms_c; #endif diff --git a/vp8/encoder/onyx_if.c b/vp8/encoder/onyx_if.c index 64396409d..0460f4377 100644 --- a/vp8/encoder/onyx_if.c +++ b/vp8/encoder/onyx_if.c @@ -75,7 +75,7 @@ static void set_default_lf_deltas(VP8_COMP *cpi); extern const int vp8_gf_interval_table[101]; -#if CONFIG_PSNR +#if CONFIG_INTERNAL_STATS #include "math.h" extern double vp8_calc_ssim @@ -1301,7 +1301,7 @@ void vp8_set_speed_features(VP8_COMP *cpi) cpi->find_fractional_mv_step = vp8_skip_fractional_mv_step; } - if (cpi->sf.optimize_coefficients == 1) + if (cpi->sf.optimize_coefficients == 1 && cpi->pass!=1) cpi->mb.optimize = 1; else cpi->mb.optimize = 0; @@ -1986,8 +1986,8 @@ VP8_PTR vp8_create_compressor(VP8_CONFIG *oxcf) cpi->source_alt_ref_active = FALSE; cpi->common.refresh_alt_ref_frame = 0; - cpi->b_calculate_psnr = CONFIG_PSNR; -#if CONFIG_PSNR + cpi->b_calculate_psnr = CONFIG_INTERNAL_STATS; +#if CONFIG_INTERNAL_STATS cpi->b_calculate_ssimg = 0; cpi->count = 0; @@ -2206,7 +2206,7 @@ void vp8_remove_compressor(VP8_PTR *ptr) print_mode_context(); #endif -#if CONFIG_PSNR +#if CONFIG_INTERNAL_STATS if (cpi->pass != 1) { @@ -2722,45 +2722,6 @@ static void resize_key_frame(VP8_COMP *cpi) } -static void set_quantizer(VP8_COMP *cpi, int Q) -{ - VP8_COMMON *cm = &cpi->common; - MACROBLOCKD *mbd = &cpi->mb.e_mbd; - int update = 0; - int new_delta_q; - cm->base_qindex = Q; - - /* if any of the delta_q values are changing update flag has to be set */ - /* currently only y2dc_delta_q may change */ - - cm->y1dc_delta_q = 0; - cm->y2ac_delta_q = 0; - cm->uvdc_delta_q = 0; - cm->uvac_delta_q = 0; - - if (Q < 4) - { - new_delta_q = 4-Q; - } - else - new_delta_q = 0; - - update |= cm->y2dc_delta_q != new_delta_q; - cm->y2dc_delta_q = new_delta_q; - - - // Set Segment specific quatizers - mbd->segment_feature_data[MB_LVL_ALT_Q][0] = cpi->segment_feature_data[MB_LVL_ALT_Q][0]; - mbd->segment_feature_data[MB_LVL_ALT_Q][1] = cpi->segment_feature_data[MB_LVL_ALT_Q][1]; - mbd->segment_feature_data[MB_LVL_ALT_Q][2] = cpi->segment_feature_data[MB_LVL_ALT_Q][2]; - mbd->segment_feature_data[MB_LVL_ALT_Q][3] = cpi->segment_feature_data[MB_LVL_ALT_Q][3]; - - /* quantizer has to be reinitialized for any delta_q changes */ - if(update) - vp8cx_init_quantizer(cpi); - -} - static void update_alt_ref_frame_and_stats(VP8_COMP *cpi) { VP8_COMMON *cm = &cpi->common; @@ -3109,7 +3070,7 @@ static void Pass1Encode(VP8_COMP *cpi, unsigned long *size, unsigned char *dest, (void) size; (void) dest; (void) frame_flags; - set_quantizer(cpi, 26); + vp8_set_quantizer(cpi, 26); scale_and_extend_source(cpi->un_scaled_source, cpi); vp8_first_pass(cpi); @@ -3502,7 +3463,7 @@ static void encode_frame_to_data_rate cm->current_video_frame++; cpi->frames_since_key++; -#if CONFIG_PSNR +#if CONFIG_INTERNAL_STATS cpi->count ++; #endif @@ -3769,7 +3730,7 @@ static void encode_frame_to_data_rate Q = 127; */ - set_quantizer(cpi, Q); + vp8_set_quantizer(cpi, Q); this_q = Q; // setup skip prob for costing in mode/mv decision @@ -4114,7 +4075,7 @@ static void encode_frame_to_data_rate { vp8_restore_coding_context(cpi); loop_count++; -#if CONFIG_PSNR +#if CONFIG_INTERNAL_STATS cpi->tot_recode_hits++; #endif } @@ -4388,7 +4349,7 @@ static void encode_frame_to_data_rate } } -#if 0 && CONFIG_PSNR +#if 0 && CONFIG_INTERNAL_STATS { FILE *f = fopen("tmp.stt", "a"); @@ -4958,7 +4919,7 @@ int vp8_get_compressed_data(VP8_PTR ptr, unsigned int *frame_flags, unsigned lon generate_psnr_packet(cpi); } -#if CONFIG_PSNR +#if CONFIG_INTERNAL_STATS if (cpi->pass != 1) { diff --git a/vp8/encoder/onyx_int.h b/vp8/encoder/onyx_int.h index 8b17178b3..e23e9d371 100644 --- a/vp8/encoder/onyx_int.h +++ b/vp8/encoder/onyx_int.h @@ -240,7 +240,7 @@ enum BLOCK_MAX_SEGMENTS }; -typedef struct +typedef struct VP8_COMP { DECLARE_ALIGNED(16, short, Y1quant[QINDEX_RANGE][16]); @@ -620,7 +620,7 @@ typedef struct int fixed_divide[512]; #endif -#if CONFIG_PSNR +#if CONFIG_INTERNAL_STATS int count; double total_y; double total_u; diff --git a/vp8/encoder/pickinter.c b/vp8/encoder/pickinter.c index 1785edb1c..c2524921d 100644 --- a/vp8/encoder/pickinter.c +++ b/vp8/encoder/pickinter.c @@ -426,24 +426,29 @@ void vp8_pick_intra_mbuv_mode(MACROBLOCK *mb) } -static void vp8_update_mvcount(VP8_COMP *cpi, MACROBLOCKD *xd, int_mv *best_ref_mv) +static void update_mvcount(VP8_COMP *cpi, MACROBLOCKD *xd, int_mv *best_ref_mv) { - /* Split MV modes currently not supported when RD is nopt enabled, therefore, only need to modify MVcount in NEWMV mode. */ + /* Split MV modes currently not supported when RD is nopt enabled, + * therefore, only need to modify MVcount in NEWMV mode. */ if (xd->mode_info_context->mbmi.mode == NEWMV) { - cpi->MVcount[0][mv_max+((xd->block[0].bmi.mv.as_mv.row - best_ref_mv->as_mv.row) >> 1)]++; - cpi->MVcount[1][mv_max+((xd->block[0].bmi.mv.as_mv.col - best_ref_mv->as_mv.col) >> 1)]++; + cpi->MVcount[0][mv_max+((xd->block[0].bmi.mv.as_mv.row - + best_ref_mv->as_mv.row) >> 1)]++; + cpi->MVcount[1][mv_max+((xd->block[0].bmi.mv.as_mv.col - + best_ref_mv->as_mv.col) >> 1)]++; } } -void vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int recon_uvoffset, int *returnrate, int *returndistortion, int *returnintra) +void vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, + int recon_uvoffset, int *returnrate, + int *returndistortion, int *returnintra) { BLOCK *b = &x->block[0]; BLOCKD *d = &x->e_mbd.block[0]; MACROBLOCKD *xd = &x->e_mbd; B_MODE_INFO best_bmodes[16]; MB_MODE_INFO best_mbmode; - PARTITION_INFO best_partition; + int_mv best_ref_mv; int_mv mode_mv[MB_MODE_COUNT]; MB_PREDICTION_MODE this_mode; @@ -878,9 +883,8 @@ void vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int re *returndistortion = distortion2; best_rd = this_rd; vpx_memcpy(&best_mbmode, &x->e_mbd.mode_info_context->mbmi, sizeof(MB_MODE_INFO)); - vpx_memcpy(&best_partition, x->partition_info, sizeof(PARTITION_INFO)); - if (this_mode == B_PRED || this_mode == SPLITMV) + if (this_mode == B_PRED) for (i = 0; i < 16; i++) { vpx_memcpy(&best_bmodes[i], &x->e_mbd.block[i].bmi, sizeof(B_MODE_INFO)); @@ -952,7 +956,6 @@ void vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int re best_mbmode.partitioning = 0; vpx_memcpy(&x->e_mbd.mode_info_context->mbmi, &best_mbmode, sizeof(MB_MODE_INFO)); - vpx_memcpy(x->partition_info, &best_partition, sizeof(PARTITION_INFO)); for (i = 0; i < 16; i++) { @@ -963,12 +966,10 @@ void vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int re return; } - // macroblock modes vpx_memcpy(&x->e_mbd.mode_info_context->mbmi, &best_mbmode, sizeof(MB_MODE_INFO)); - vpx_memcpy(x->partition_info, &best_partition, sizeof(PARTITION_INFO)); - if (x->e_mbd.mode_info_context->mbmi.mode == B_PRED || x->e_mbd.mode_info_context->mbmi.mode == SPLITMV) + if (x->e_mbd.mode_info_context->mbmi.mode == B_PRED) for (i = 0; i < 16; i++) { vpx_memcpy(&x->e_mbd.block[i].bmi, &best_bmodes[i], sizeof(B_MODE_INFO)); @@ -979,7 +980,5 @@ void vp8_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int re vp8_set_mbmode_and_mvs(x, x->e_mbd.mode_info_context->mbmi.mode, &best_bmodes[0].mv); } - x->e_mbd.mode_info_context->mbmi.mv.as_mv = x->e_mbd.block[15].bmi.mv.as_mv; - - vp8_update_mvcount(cpi, &x->e_mbd, &frame_best_ref_mv[xd->mode_info_context->mbmi.ref_frame]); + update_mvcount(cpi, &x->e_mbd, &frame_best_ref_mv[xd->mode_info_context->mbmi.ref_frame]); } diff --git a/vp8/encoder/quantize.c b/vp8/encoder/quantize.c index 86ed267fb..49e8e1b9b 100644 --- a/vp8/encoder/quantize.c +++ b/vp8/encoder/quantize.c @@ -12,8 +12,9 @@ #include <math.h> #include "vpx_mem/vpx_mem.h" +#include "onyx_int.h" #include "quantize.h" -#include "vp8/common/entropy.h" +#include "vp8/common/quant_common.h" #define EXACT_QUANT @@ -299,3 +300,418 @@ void vp8_quantize_mbuv(MACROBLOCK *x) for (i = 16; i < 24; i++) x->quantize_b(&x->block[i], &x->e_mbd.block[i]); } + + +static const int qrounding_factors[129] = +{ + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48 +}; + + +static const int qzbin_factors[129] = +{ + 84, 84, 84, 84, 84, 84, 84, 84, + 84, 84, 84, 84, 84, 84, 84, 84, + 84, 84, 84, 84, 84, 84, 84, 84, + 84, 84, 84, 84, 84, 84, 84, 84, + 84, 84, 84, 84, 84, 84, 84, 84, + 84, 84, 84, 84, 84, 84, 84, 84, + 80, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 80, + 80 +}; + + +static const int qrounding_factors_y2[129] = +{ + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, + 48 +}; + + +static const int qzbin_factors_y2[129] = +{ + 84, 84, 84, 84, 84, 84, 84, 84, + 84, 84, 84, 84, 84, 84, 84, 84, + 84, 84, 84, 84, 84, 84, 84, 84, + 84, 84, 84, 84, 84, 84, 84, 84, + 84, 84, 84, 84, 84, 84, 84, 84, + 84, 84, 84, 84, 84, 84, 84, 84, + 80, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 80, + 80, 80, 80, 80, 80, 80, 80, 80, + 80 +}; + + +#define EXACT_QUANT +#ifdef EXACT_QUANT +static void invert_quant(int improved_quant, short *quant, + unsigned char *shift, short d) +{ + if(improved_quant) + { + unsigned t; + int l; + t = d; + for(l = 0; t > 1; l++) + t>>=1; + t = 1 + (1<<(16+l))/d; + *quant = (short)(t - (1<<16)); + *shift = l; + } + else + { + *quant = (1 << 16) / d; + *shift = 0; + } +} + + +void vp8cx_init_quantizer(VP8_COMP *cpi) +{ + int i; + int quant_val; + int Q; + + int zbin_boost[16] = {0, 0, 8, 10, 12, 14, 16, 20, 24, 28, 32, 36, 40, 44, 44, 44}; + + for (Q = 0; Q < QINDEX_RANGE; Q++) + { + // dc values + quant_val = vp8_dc_quant(Q, cpi->common.y1dc_delta_q); + cpi->Y1quant_fast[Q][0] = (1 << 16) / quant_val; + invert_quant(cpi->sf.improved_quant, cpi->Y1quant[Q] + 0, + cpi->Y1quant_shift[Q] + 0, quant_val); + cpi->Y1zbin[Q][0] = ((qzbin_factors[Q] * quant_val) + 64) >> 7; + cpi->Y1round[Q][0] = (qrounding_factors[Q] * quant_val) >> 7; + cpi->common.Y1dequant[Q][0] = quant_val; + cpi->zrun_zbin_boost_y1[Q][0] = (quant_val * zbin_boost[0]) >> 7; + + quant_val = vp8_dc2quant(Q, cpi->common.y2dc_delta_q); + cpi->Y2quant_fast[Q][0] = (1 << 16) / quant_val; + invert_quant(cpi->sf.improved_quant, cpi->Y2quant[Q] + 0, + cpi->Y2quant_shift[Q] + 0, quant_val); + cpi->Y2zbin[Q][0] = ((qzbin_factors_y2[Q] * quant_val) + 64) >> 7; + cpi->Y2round[Q][0] = (qrounding_factors_y2[Q] * quant_val) >> 7; + cpi->common.Y2dequant[Q][0] = quant_val; + cpi->zrun_zbin_boost_y2[Q][0] = (quant_val * zbin_boost[0]) >> 7; + + quant_val = vp8_dc_uv_quant(Q, cpi->common.uvdc_delta_q); + cpi->UVquant_fast[Q][0] = (1 << 16) / quant_val; + invert_quant(cpi->sf.improved_quant, cpi->UVquant[Q] + 0, + cpi->UVquant_shift[Q] + 0, quant_val); + cpi->UVzbin[Q][0] = ((qzbin_factors[Q] * quant_val) + 64) >> 7;; + cpi->UVround[Q][0] = (qrounding_factors[Q] * quant_val) >> 7; + cpi->common.UVdequant[Q][0] = quant_val; + cpi->zrun_zbin_boost_uv[Q][0] = (quant_val * zbin_boost[0]) >> 7; + + // all the ac values = ; + for (i = 1; i < 16; i++) + { + int rc = vp8_default_zig_zag1d[i]; + + quant_val = vp8_ac_yquant(Q); + cpi->Y1quant_fast[Q][rc] = (1 << 16) / quant_val; + invert_quant(cpi->sf.improved_quant, cpi->Y1quant[Q] + rc, + cpi->Y1quant_shift[Q] + rc, quant_val); + cpi->Y1zbin[Q][rc] = ((qzbin_factors[Q] * quant_val) + 64) >> 7; + cpi->Y1round[Q][rc] = (qrounding_factors[Q] * quant_val) >> 7; + cpi->common.Y1dequant[Q][rc] = quant_val; + cpi->zrun_zbin_boost_y1[Q][i] = (quant_val * zbin_boost[i]) >> 7; + + quant_val = vp8_ac2quant(Q, cpi->common.y2ac_delta_q); + cpi->Y2quant_fast[Q][rc] = (1 << 16) / quant_val; + invert_quant(cpi->sf.improved_quant, cpi->Y2quant[Q] + rc, + cpi->Y2quant_shift[Q] + rc, quant_val); + cpi->Y2zbin[Q][rc] = ((qzbin_factors_y2[Q] * quant_val) + 64) >> 7; + cpi->Y2round[Q][rc] = (qrounding_factors_y2[Q] * quant_val) >> 7; + cpi->common.Y2dequant[Q][rc] = quant_val; + cpi->zrun_zbin_boost_y2[Q][i] = (quant_val * zbin_boost[i]) >> 7; + + quant_val = vp8_ac_uv_quant(Q, cpi->common.uvac_delta_q); + cpi->UVquant_fast[Q][rc] = (1 << 16) / quant_val; + invert_quant(cpi->sf.improved_quant, cpi->UVquant[Q] + rc, + cpi->UVquant_shift[Q] + rc, quant_val); + cpi->UVzbin[Q][rc] = ((qzbin_factors[Q] * quant_val) + 64) >> 7; + cpi->UVround[Q][rc] = (qrounding_factors[Q] * quant_val) >> 7; + cpi->common.UVdequant[Q][rc] = quant_val; + cpi->zrun_zbin_boost_uv[Q][i] = (quant_val * zbin_boost[i]) >> 7; + } + } +} +#else +void vp8cx_init_quantizer(VP8_COMP *cpi) +{ + int i; + int quant_val; + int Q; + + int zbin_boost[16] = {0, 0, 8, 10, 12, 14, 16, 20, 24, 28, 32, 36, 40, 44, 44, 44}; + + for (Q = 0; Q < QINDEX_RANGE; Q++) + { + // dc values + quant_val = vp8_dc_quant(Q, cpi->common.y1dc_delta_q); + cpi->Y1quant[Q][0] = (1 << 16) / quant_val; + cpi->Y1zbin[Q][0] = ((qzbin_factors[Q] * quant_val) + 64) >> 7; + cpi->Y1round[Q][0] = (qrounding_factors[Q] * quant_val) >> 7; + cpi->common.Y1dequant[Q][0] = quant_val; + cpi->zrun_zbin_boost_y1[Q][0] = (quant_val * zbin_boost[0]) >> 7; + + quant_val = vp8_dc2quant(Q, cpi->common.y2dc_delta_q); + cpi->Y2quant[Q][0] = (1 << 16) / quant_val; + cpi->Y2zbin[Q][0] = ((qzbin_factors_y2[Q] * quant_val) + 64) >> 7; + cpi->Y2round[Q][0] = (qrounding_factors_y2[Q] * quant_val) >> 7; + cpi->common.Y2dequant[Q][0] = quant_val; + cpi->zrun_zbin_boost_y2[Q][0] = (quant_val * zbin_boost[0]) >> 7; + + quant_val = vp8_dc_uv_quant(Q, cpi->common.uvdc_delta_q); + cpi->UVquant[Q][0] = (1 << 16) / quant_val; + cpi->UVzbin[Q][0] = ((qzbin_factors[Q] * quant_val) + 64) >> 7;; + cpi->UVround[Q][0] = (qrounding_factors[Q] * quant_val) >> 7; + cpi->common.UVdequant[Q][0] = quant_val; + cpi->zrun_zbin_boost_uv[Q][0] = (quant_val * zbin_boost[0]) >> 7; + + // all the ac values = ; + for (i = 1; i < 16; i++) + { + int rc = vp8_default_zig_zag1d[i]; + + quant_val = vp8_ac_yquant(Q); + cpi->Y1quant[Q][rc] = (1 << 16) / quant_val; + cpi->Y1zbin[Q][rc] = ((qzbin_factors[Q] * quant_val) + 64) >> 7; + cpi->Y1round[Q][rc] = (qrounding_factors[Q] * quant_val) >> 7; + cpi->common.Y1dequant[Q][rc] = quant_val; + cpi->zrun_zbin_boost_y1[Q][i] = (quant_val * zbin_boost[i]) >> 7; + + quant_val = vp8_ac2quant(Q, cpi->common.y2ac_delta_q); + cpi->Y2quant[Q][rc] = (1 << 16) / quant_val; + cpi->Y2zbin[Q][rc] = ((qzbin_factors_y2[Q] * quant_val) + 64) >> 7; + cpi->Y2round[Q][rc] = (qrounding_factors_y2[Q] * quant_val) >> 7; + cpi->common.Y2dequant[Q][rc] = quant_val; + cpi->zrun_zbin_boost_y2[Q][i] = (quant_val * zbin_boost[i]) >> 7; + + quant_val = vp8_ac_uv_quant(Q, cpi->common.uvac_delta_q); + cpi->UVquant[Q][rc] = (1 << 16) / quant_val; + cpi->UVzbin[Q][rc] = ((qzbin_factors[Q] * quant_val) + 64) >> 7; + cpi->UVround[Q][rc] = (qrounding_factors[Q] * quant_val) >> 7; + cpi->common.UVdequant[Q][rc] = quant_val; + cpi->zrun_zbin_boost_uv[Q][i] = (quant_val * zbin_boost[i]) >> 7; + } + } +} +#endif + + +void vp8cx_mb_init_quantizer(VP8_COMP *cpi, MACROBLOCK *x) +{ + int i; + int QIndex; + MACROBLOCKD *xd = &x->e_mbd; + int zbin_extra; + + // Select the baseline MB Q index. + if (xd->segmentation_enabled) + { + // Abs Value + if (xd->mb_segement_abs_delta == SEGMENT_ABSDATA) + + QIndex = xd->segment_feature_data[MB_LVL_ALT_Q][xd->mode_info_context->mbmi.segment_id]; + // Delta Value + else + { + QIndex = cpi->common.base_qindex + xd->segment_feature_data[MB_LVL_ALT_Q][xd->mode_info_context->mbmi.segment_id]; + QIndex = (QIndex >= 0) ? ((QIndex <= MAXQ) ? QIndex : MAXQ) : 0; // Clamp to valid range + } + } + else + QIndex = cpi->common.base_qindex; + + // Y + zbin_extra = ( cpi->common.Y1dequant[QIndex][1] * + ( cpi->zbin_over_quant + + cpi->zbin_mode_boost + + x->act_zbin_adj ) ) >> 7; + + for (i = 0; i < 16; i++) + { + x->block[i].quant = cpi->Y1quant[QIndex]; + x->block[i].quant_fast = cpi->Y1quant_fast[QIndex]; + x->block[i].quant_shift = cpi->Y1quant_shift[QIndex]; + x->block[i].zbin = cpi->Y1zbin[QIndex]; + x->block[i].round = cpi->Y1round[QIndex]; + x->e_mbd.block[i].dequant = cpi->common.Y1dequant[QIndex]; + x->block[i].zrun_zbin_boost = cpi->zrun_zbin_boost_y1[QIndex]; + x->block[i].zbin_extra = (short)zbin_extra; + } + + // UV + zbin_extra = ( cpi->common.UVdequant[QIndex][1] * + ( cpi->zbin_over_quant + + cpi->zbin_mode_boost + + x->act_zbin_adj ) ) >> 7; + + for (i = 16; i < 24; i++) + { + x->block[i].quant = cpi->UVquant[QIndex]; + x->block[i].quant_fast = cpi->UVquant_fast[QIndex]; + x->block[i].quant_shift = cpi->UVquant_shift[QIndex]; + x->block[i].zbin = cpi->UVzbin[QIndex]; + x->block[i].round = cpi->UVround[QIndex]; + x->e_mbd.block[i].dequant = cpi->common.UVdequant[QIndex]; + x->block[i].zrun_zbin_boost = cpi->zrun_zbin_boost_uv[QIndex]; + x->block[i].zbin_extra = (short)zbin_extra; + } + + // Y2 + zbin_extra = ( cpi->common.Y2dequant[QIndex][1] * + ( (cpi->zbin_over_quant / 2) + + cpi->zbin_mode_boost + + x->act_zbin_adj ) ) >> 7; + + x->block[24].quant_fast = cpi->Y2quant_fast[QIndex]; + x->block[24].quant = cpi->Y2quant[QIndex]; + x->block[24].quant_shift = cpi->Y2quant_shift[QIndex]; + x->block[24].zbin = cpi->Y2zbin[QIndex]; + x->block[24].round = cpi->Y2round[QIndex]; + x->e_mbd.block[24].dequant = cpi->common.Y2dequant[QIndex]; + x->block[24].zrun_zbin_boost = cpi->zrun_zbin_boost_y2[QIndex]; + x->block[24].zbin_extra = (short)zbin_extra; + + /* save this macroblock QIndex for vp8_update_zbin_extra() */ + x->q_index = QIndex; +} + + +void vp8_update_zbin_extra(VP8_COMP *cpi, MACROBLOCK *x) +{ + int i; + int QIndex = x->q_index; + int zbin_extra; + + // Y + zbin_extra = ( cpi->common.Y1dequant[QIndex][1] * + ( cpi->zbin_over_quant + + cpi->zbin_mode_boost + + x->act_zbin_adj ) ) >> 7; + for (i = 0; i < 16; i++) + { + x->block[i].zbin_extra = (short)zbin_extra; + } + + // UV + zbin_extra = ( cpi->common.UVdequant[QIndex][1] * + ( cpi->zbin_over_quant + + cpi->zbin_mode_boost + + x->act_zbin_adj ) ) >> 7; + + for (i = 16; i < 24; i++) + { + x->block[i].zbin_extra = (short)zbin_extra; + } + + // Y2 + zbin_extra = ( cpi->common.Y2dequant[QIndex][1] * + ( (cpi->zbin_over_quant / 2) + + cpi->zbin_mode_boost + + x->act_zbin_adj ) ) >> 7; + + x->block[24].zbin_extra = (short)zbin_extra; +} + + +void vp8cx_frame_init_quantizer(VP8_COMP *cpi) +{ + // Clear Zbin mode boost for default case + cpi->zbin_mode_boost = 0; + + // MB level quantizer setup + vp8cx_mb_init_quantizer(cpi, &cpi->mb); +} + + +void vp8_set_quantizer(struct VP8_COMP *cpi, int Q) +{ + VP8_COMMON *cm = &cpi->common; + MACROBLOCKD *mbd = &cpi->mb.e_mbd; + int update = 0; + int new_delta_q; + cm->base_qindex = Q; + + /* if any of the delta_q values are changing update flag has to be set */ + /* currently only y2dc_delta_q may change */ + + cm->y1dc_delta_q = 0; + cm->y2ac_delta_q = 0; + cm->uvdc_delta_q = 0; + cm->uvac_delta_q = 0; + + if (Q < 4) + { + new_delta_q = 4-Q; + } + else + new_delta_q = 0; + + update |= cm->y2dc_delta_q != new_delta_q; + cm->y2dc_delta_q = new_delta_q; + + + // Set Segment specific quatizers + mbd->segment_feature_data[MB_LVL_ALT_Q][0] = cpi->segment_feature_data[MB_LVL_ALT_Q][0]; + mbd->segment_feature_data[MB_LVL_ALT_Q][1] = cpi->segment_feature_data[MB_LVL_ALT_Q][1]; + mbd->segment_feature_data[MB_LVL_ALT_Q][2] = cpi->segment_feature_data[MB_LVL_ALT_Q][2]; + mbd->segment_feature_data[MB_LVL_ALT_Q][3] = cpi->segment_feature_data[MB_LVL_ALT_Q][3]; + + /* quantizer has to be reinitialized for any delta_q changes */ + if(update) + vp8cx_init_quantizer(cpi); + +} diff --git a/vp8/encoder/quantize.h b/vp8/encoder/quantize.h index e4c32a570..d9a041071 100644 --- a/vp8/encoder/quantize.h +++ b/vp8/encoder/quantize.h @@ -55,4 +55,11 @@ extern void vp8_quantize_mb(MACROBLOCK *x); extern void vp8_quantize_mbuv(MACROBLOCK *x); extern void vp8_quantize_mby(MACROBLOCK *x); +struct VP8_COMP; +extern void vp8_set_quantizer(struct VP8_COMP *cpi, int Q); +extern void vp8cx_frame_init_quantizer(struct VP8_COMP *cpi); +extern void vp8_update_zbin_extra(struct VP8_COMP *cpi, MACROBLOCK *x); +extern void vp8cx_mb_init_quantizer(struct VP8_COMP *cpi, MACROBLOCK *x); +extern void vp8cx_init_quantizer(struct VP8_COMP *cpi); + #endif diff --git a/vp8/encoder/rdopt.c b/vp8/encoder/rdopt.c index aa8202b2e..48070ab49 100644 --- a/vp8/encoder/rdopt.c +++ b/vp8/encoder/rdopt.c @@ -994,9 +994,11 @@ static int labels2mode( cost = x->inter_bmode_costs[ m]; } - d->bmi.mode = m; d->bmi.mv.as_int = this_mv->as_int; + x->partition_info->bmi[i].mode = m; + x->partition_info->bmi[i].mv.as_int = this_mv->as_int; + } while (++i < 16); @@ -1340,8 +1342,8 @@ static void rd_check_segment(VP8_COMP *cpi, MACROBLOCK *x, { BLOCKD *bd = &x->e_mbd.block[i]; - bsi->mvs[i].as_mv = bd->bmi.mv.as_mv; - bsi->modes[i] = bd->bmi.mode; + bsi->mvs[i].as_mv = x->partition_info->bmi[i].mv.as_mv; + bsi->modes[i] = x->partition_info->bmi[i].mode; bsi->eobs[i] = bd->eob; } } @@ -1471,7 +1473,6 @@ static int vp8_rd_pick_best_mbsegmentation(VP8_COMP *cpi, MACROBLOCK *x, BLOCKD *bd = &x->e_mbd.block[i]; bd->bmi.mv.as_mv = bsi.mvs[i].as_mv; - bd->bmi.mode = bsi.modes[i]; bd->eob = bsi.eobs[i]; } @@ -1489,9 +1490,13 @@ static int vp8_rd_pick_best_mbsegmentation(VP8_COMP *cpi, MACROBLOCK *x, j = vp8_mbsplit_offset[bsi.segment_num][i]; - x->partition_info->bmi[i].mode = x->e_mbd.block[j].bmi.mode; - x->partition_info->bmi[i].mv.as_mv = x->e_mbd.block[j].bmi.mv.as_mv; + x->partition_info->bmi[i].mode = bsi.modes[j]; + x->partition_info->bmi[i].mv.as_mv = bsi.mvs[j].as_mv; } + /* + * used to set x->e_mbd.mode_info_context->mbmi.mv.as_int + */ + x->partition_info->bmi[15].mv.as_int = bsi.mvs[15].as_int; return bsi.segment_rd; } @@ -1751,25 +1756,29 @@ void vp8_cal_sad(VP8_COMP *cpi, MACROBLOCKD *xd, MACROBLOCK *x, int recon_yoffse } } -static void vp8_rd_update_mvcount(VP8_COMP *cpi, MACROBLOCKD *xd, int_mv *best_ref_mv) +static void rd_update_mvcount(VP8_COMP *cpi, MACROBLOCK *x, int_mv *best_ref_mv) { - int i; - - if (xd->mode_info_context->mbmi.mode == SPLITMV) + if (x->e_mbd.mode_info_context->mbmi.mode == SPLITMV) { - for (i = 0; i < 16; i++) + int i; + + for (i = 0; i < x->partition_info->count; i++) { - if (xd->block[i].bmi.mode == NEW4X4) + if (x->partition_info->bmi[i].mode == NEW4X4) { - cpi->MVcount[0][mv_max+((xd->block[i].bmi.mv.as_mv.row - best_ref_mv->as_mv.row) >> 1)]++; - cpi->MVcount[1][mv_max+((xd->block[i].bmi.mv.as_mv.col - best_ref_mv->as_mv.col) >> 1)]++; + cpi->MVcount[0][mv_max+((x->partition_info->bmi[i].mv.as_mv.row + - best_ref_mv->as_mv.row) >> 1)]++; + cpi->MVcount[1][mv_max+((x->partition_info->bmi[i].mv.as_mv.col + - best_ref_mv->as_mv.col) >> 1)]++; } } } - else if (xd->mode_info_context->mbmi.mode == NEWMV) + else if (x->e_mbd.mode_info_context->mbmi.mode == NEWMV) { - cpi->MVcount[0][mv_max+((xd->block[0].bmi.mv.as_mv.row - best_ref_mv->as_mv.row) >> 1)]++; - cpi->MVcount[1][mv_max+((xd->block[0].bmi.mv.as_mv.col - best_ref_mv->as_mv.col) >> 1)]++; + cpi->MVcount[0][mv_max+((x->e_mbd.mode_info_context->mbmi.mv.as_mv.row + - best_ref_mv->as_mv.row) >> 1)]++; + cpi->MVcount[1][mv_max+((x->e_mbd.mode_info_context->mbmi.mv.as_mv.col + - best_ref_mv->as_mv.col) >> 1)]++; } } @@ -2479,14 +2488,19 @@ void vp8_rd_pick_inter_mode(VP8_COMP *cpi, MACROBLOCK *x, int recon_yoffset, int // macroblock modes vpx_memcpy(&x->e_mbd.mode_info_context->mbmi, &best_mbmode, sizeof(MB_MODE_INFO)); - vpx_memcpy(x->partition_info, &best_partition, sizeof(PARTITION_INFO)); for (i = 0; i < 16; i++) { vpx_memcpy(&x->e_mbd.block[i].bmi, &best_bmodes[i], sizeof(B_MODE_INFO)); } - x->e_mbd.mode_info_context->mbmi.mv.as_mv = x->e_mbd.block[15].bmi.mv.as_mv; + if (best_mbmode.mode == SPLITMV) + { + vpx_memcpy(x->partition_info, &best_partition, sizeof(PARTITION_INFO)); + x->e_mbd.mode_info_context->mbmi.mv.as_int = + x->partition_info->bmi[15].mv.as_int; + } + + rd_update_mvcount(cpi, x, &frame_best_ref_mv[xd->mode_info_context->mbmi.ref_frame]); - vp8_rd_update_mvcount(cpi, &x->e_mbd, &frame_best_ref_mv[xd->mode_info_context->mbmi.ref_frame]); } diff --git a/vp8/encoder/variance.h b/vp8/encoder/variance.h index bf17ea8b6..da5a5364a 100644 --- a/vp8/encoder/variance.h +++ b/vp8/encoder/variance.h @@ -391,7 +391,7 @@ typedef struct vp8_sad_multi_d_fn_t sad8x8x4d; vp8_sad_multi_d_fn_t sad4x4x4d; -#if CONFIG_PSNR +#if CONFIG_INTERNAL_STATS vp8_ssimpf_fn_t ssimpf_8x8; vp8_ssimpf_fn_t ssimpf; #endif diff --git a/vp8/encoder/x86/x86_csystemdependent.c b/vp8/encoder/x86/x86_csystemdependent.c index f65ef8a5f..378b14066 100644 --- a/vp8/encoder/x86/x86_csystemdependent.c +++ b/vp8/encoder/x86/x86_csystemdependent.c @@ -112,7 +112,7 @@ static void subtract_b_sse2(BLOCK *be, BLOCKD *bd, int pitch) #endif #if HAVE_SSSE3 -#if CONFIG_PSNR +#if CONFIG_INTERNAL_STATS #if ARCH_X86_64 typedef void ssimpf ( @@ -287,7 +287,7 @@ void vp8_arch_x86_encoder_init(VP8_COMP *cpi) cpi->rtcd.quantize.fastquantb = vp8_fast_quantize_b_ssse3; -#if CONFIG_PSNR +#if CONFIG_INTERNAL_STATS #if ARCH_X86_64 cpi->rtcd.variance.ssimpf_8x8 = vp8_ssim_parms_8x8_sse3; cpi->rtcd.variance.ssimpf = vp8_ssim_parms_16x16_sse3; |