Commit 3e9890a3 authored by Paul Wilkins's avatar Paul Wilkins

Merge Extended Q experiment.

Merge the extended Q experiment as indicated by the

Change-Id: I02d9e654fff9998cc7e9e2f1f5cd838dad8fb431
parent cf8af867
......@@ -119,14 +119,8 @@ static const Prob Pcat2[] = { 165, 145};
static const Prob Pcat3[] = { 173, 148, 140};
static const Prob Pcat4[] = { 176, 155, 140, 135};
static const Prob Pcat5[] = { 180, 157, 141, 134, 130};
#if CONFIG_EXTEND_QRANGE
static const Prob Pcat6[] =
{ 254, 254, 252, 249, 243, 230, 196, 177, 153, 140, 133, 130, 129};
#else
static const Prob Pcat6[] =
{ 254, 254, 243, 230, 196, 177, 153, 140, 133, 130, 129};
#endif
static vp8_tree_index cat1[2], cat2[4], cat3[6], cat4[8], cat5[10], cat6[26];
......@@ -166,11 +160,7 @@ static void init_bit_trees()
init_bit_tree(cat3, 3);
init_bit_tree(cat4, 4);
init_bit_tree(cat5, 5);
#if CONFIG_EXTEND_QRANGE
init_bit_tree(cat6, 13);
#else
init_bit_tree(cat6, 11);
#endif
}
vp8_extra_bit_struct vp8_extra_bits[12] =
......@@ -185,11 +175,7 @@ vp8_extra_bit_struct vp8_extra_bits[12] =
{ cat3, Pcat3, 3, 11},
{ cat4, Pcat4, 4, 19},
{ cat5, Pcat5, 5, 35},
#if CONFIG_EXTEND_QRANGE
{ cat6, Pcat6, 13, 67},
#else
{ cat6, Pcat6, 11, 67},
#endif
{ 0, 0, 0, 0}
};
......
......@@ -50,11 +50,7 @@ extern vp8_extra_bit_struct vp8_extra_bits[12]; /* indexed by token value */
#define PROB_UPDATE_BASELINE_COST 7
#define MAX_PROB 255
#if CONFIG_EXTEND_QRANGE
#define DCT_MAX_VALUE 8192
#else
#define DCT_MAX_VALUE 2048
#endif
/* Coefficients are predicted via a 3-dimensional probability table. */
......
......@@ -156,16 +156,12 @@ void vp8_machine_specific_config(VP8_COMMON *ctx)
#if ARCH_ARM
vp8_arch_arm_common_init(ctx);
#endif
#if CONFIG_EXTEND_QRANGE
rtcd->idct.idct1 = vp8_short_idct4x4llm_1_c;
rtcd->idct.idct16 = vp8_short_idct4x4llm_c;
rtcd->idct.idct1_scalar_add = vp8_dc_only_idct_add_c;
rtcd->idct.iwalsh1 = vp8_short_inv_walsh4x4_1_c;
rtcd->idct.iwalsh16 = vp8_short_inv_walsh4x4_c;
#endif
#if CONFIG_MULTITHREAD
ctx->processor_core_count = get_cpu_count();
#endif /* CONFIG_MULTITHREAD */
......
......@@ -80,20 +80,11 @@ void vp8_short_idct4x4llm_c(short *input, short *output, int pitch)
temp2 = (ip[3] * sinpi8sqrt2 + rounding) >> 16;
d1 = temp1 + temp2;
#if !CONFIG_EXTEND_QRANGE
op[0] = (a1 + d1 + 4) >> 3;
op[3] = (a1 - d1 + 4) >> 3;
op[1] = (b1 + c1 + 4) >> 3;
op[2] = (b1 - c1 + 4) >> 3;
#else
op[0] = (a1 + d1 + 16) >> 5;
op[3] = (a1 - d1 + 16) >> 5;
op[1] = (b1 + c1 + 16) >> 5;
op[2] = (b1 - c1 + 16) >> 5;
#endif
ip += shortpitch;
op += shortpitch;
......@@ -106,11 +97,7 @@ void vp8_short_idct4x4llm_1_c(short *input, short *output, int pitch)
int a1;
short *op = output;
int shortpitch = pitch >> 1;
#if !CONFIG_EXTEND_QRANGE
a1 = ((input[0] + 4) >> 3);
#else
a1 = ((input[0] + 16) >> 5);
#endif
for (i = 0; i < 4; i++)
{
op[0] = a1;
......@@ -123,11 +110,7 @@ void vp8_short_idct4x4llm_1_c(short *input, short *output, int pitch)
void vp8_dc_only_idct_add_c(short input_dc, unsigned char *pred_ptr, unsigned char *dst_ptr, int pitch, int stride)
{
#if !CONFIG_EXTEND_QRANGE
int a1 = ((input_dc + 4) >> 3);
#else
int a1 = ((input_dc + 16) >> 5);
#endif
int r, c;
for (r = 0; r < 4; r++)
......@@ -189,17 +172,11 @@ void vp8_short_inv_walsh4x4_c(short *input, short *output)
c2 = a1 - b1;
d2 = d1 - c1;
#if !CONFIG_EXTEND_QRANGE
op[0] = (a2 + 3) >> 3;
op[1] = (b2 + 3) >> 3;
op[2] = (c2 + 3) >> 3;
op[3] = (d2 + 3) >> 3;
#else
op[0] = (a2 + 1) >> 2;
op[1] = (b2 + 1) >> 2;
op[2] = (c2 + 1) >> 2;
op[3] = (d2 + 1) >> 2;
#endif
ip += 4;
op += 4;
}
......@@ -211,11 +188,7 @@ void vp8_short_inv_walsh4x4_1_c(short *input, short *output)
int a1;
short *op = output;
#if !CONFIG_EXTEND_QRANGE
a1 = (input[0] + 3 )>> 3;
#else
a1 = (input[0] + 1 )>> 2;
#endif
for (i = 0; i < 4; i++)
{
......
......@@ -33,14 +33,8 @@ void vp8_initialize_common(void);
#define MINQ 0
#if CONFIG_EXTEND_QRANGE
#define MAXQ 255
#define QINDEX_BITS 8
#else
#define MAXQ 127
#define QINDEX_BITS 7
#endif
#define QINDEX_RANGE (MAXQ + 1)
......
......@@ -11,54 +11,21 @@
#include "quant_common.h"
#if !CONFIG_EXTEND_QRANGE
static const int dc_qlookup[QINDEX_RANGE] =
{
4, 5, 6, 7, 8, 9, 10, 10, 11, 12, 13, 14, 15, 16, 17, 17,
18, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 25, 25, 26, 27, 28,
29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43,
44, 45, 46, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58,
59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
75, 76, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
91, 93, 95, 96, 98, 100, 101, 102, 104, 106, 108, 110, 112, 114, 116, 118,
122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 143, 145, 148, 151, 154, 157,
};
static const int ac_qlookup[QINDEX_RANGE] =
{
4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
52, 53, 54, 55, 56, 57, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76,
78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108,
110, 112, 114, 116, 119, 122, 125, 128, 131, 134, 137, 140, 143, 146, 149, 152,
155, 158, 161, 164, 167, 170, 173, 177, 181, 185, 189, 193, 197, 201, 205, 209,
213, 217, 221, 225, 229, 234, 239, 245, 249, 254, 259, 264, 269, 274, 279, 284,
};
#else
static int dc_qlookup[QINDEX_RANGE];
static int ac_qlookup[QINDEX_RANGE];
#endif
#if CONFIG_EXTEND_QRANGE
#define ACDC_MIN 4
void vp8_init_quant_tables()
{
int i;
//int current_val = 16;
//int last_val = 16;
int current_val = 4;
int last_val = 4;
int ac_val;
//int dc_max;
for ( i = 0; i < QINDEX_RANGE; i++ )
{
ac_qlookup[i] = current_val;
//current_val = (int)((double)current_val * 1.018);
current_val = (int)((double)current_val * 1.02);
if ( current_val == last_val )
current_val++;
......@@ -68,14 +35,10 @@ void vp8_init_quant_tables()
dc_qlookup[i] = (0.000000305 * ac_val * ac_val * ac_val) +
(-0.00065 * ac_val * ac_val) +
(0.9 * ac_val) + 0.5;
//dc_max = (int)(((double)ac_val * 0.75) + 0.5);
//if ( dc_qlookup[i] > dc_max )
// dc_qlookup[i] = dc_max;
if ( dc_qlookup[i] < ACDC_MIN )
dc_qlookup[i] = ACDC_MIN;
}
}
#endif
int vp8_dc_quant(int QIndex, int Delta)
{
......@@ -103,11 +66,8 @@ int vp8_dc2quant(int QIndex, int Delta)
else if (QIndex < 0)
QIndex = 0;
#if !CONFIG_EXTEND_QRANGE
retval = dc_qlookup[ QIndex ] * 2;
#else
retval = dc_qlookup[ QIndex ];
#endif
return retval;
}
......@@ -150,15 +110,11 @@ int vp8_ac2quant(int QIndex, int Delta)
QIndex = MAXQ;
else if (QIndex < 0)
QIndex = 0;
#if !CONFIG_EXTEND_QRANGE
retval = (ac_qlookup[ QIndex ] * 155) / 100;
if (retval < 8)
retval = 8;
#else
retval = (ac_qlookup[ QIndex ] * 775) / 1000;
if (retval < 4)
retval = 4;
#endif
return retval;
}
int vp8_ac_uv_quant(int QIndex, int Delta)
......
......@@ -13,9 +13,7 @@
#include "blockd.h"
#include "onyxc_int.h"
#if CONFIG_EXTEND_QRANGE
extern void vp8_init_quant_tables();
#endif
extern int vp8_ac_yquant(int QIndex);
extern int vp8_dc_quant(int QIndex, int Delta);
extern int vp8_dc2quant(int QIndex, int Delta);
......
......@@ -131,11 +131,7 @@ void vp8_dequantize_b_2x2_c(BLOCKD *d)
for (i = 0; i < 16; i++)
{
#if CONFIG_EXTEND_QRANGE
DQ[i] = (short)((Q[i] * DQC[i]+2)>>2);
#else
DQ[i] = (short)(Q[i] * DQC[i]);
#endif
}
#ifdef DEC_DEBUG
if (dec_debug) {
......@@ -168,20 +164,12 @@ void vp8_dequant_idct_add_8x8_c(short *input, short *dq, unsigned char *pred,
}
#endif
#if CONFIG_EXTEND_QRANGE
input[0]= (input[0] * dq[0]+2)>>2;
#else
input[0]= input[0] * dq[0];
#endif
input[0]= (input[0] * dq[0]+2)>>2;
// recover quantizer for 4 4x4 blocks
for (i = 1; i < 64; i++)
{
#if CONFIG_EXTEND_QRANGE
input[i]=(input[i] * dq[1]+2)>>2;
#else
input[i]=input[i] * dq[1];
#endif
}
#ifdef DEC_DEBUG
if (dec_debug) {
......@@ -274,11 +262,7 @@ void vp8_dequant_dc_idct_add_8x8_c(short *input, short *dq, unsigned char *pred,
#endif
for (i = 1; i < 64; i++)
{
#if CONFIG_EXTEND_QRANGE
input[i]=(input[i] * dq[1]+2)>>2;
#else
input[i]=input[i] * dq[1];
#endif
}
#ifdef DEC_DEBUG
......
......@@ -78,13 +78,8 @@ DECLARE_ALIGNED(64, static const unsigned char, coef_bands_x_8x8[64]) = {
#define CAT5_PROB3 157
#define CAT5_PROB4 180
#if CONFIG_EXTEND_QRANGE
static const unsigned char cat6_prob[14] =
{ 129, 130, 133, 140, 153, 177, 196, 230, 243, 249, 252, 254, 254, 0 };
#else
static const unsigned char cat6_prob[12] =
{ 129, 130, 133, 140, 153, 177, 196, 230, 243, 254, 254, 0 };
#endif
void vp8_reset_mb_tokens_context(MACROBLOCKD *x)
{
......@@ -379,7 +374,7 @@ CHECK_0_8x8_:
DECODE_AND_BRANCH_IF_ZERO(Prob[CAT_FIVE_CONTEXT_NODE],
CAT_FIVE_CONTEXT_NODE_0_8x8_);
val = CAT6_MIN_VAL;
bits_count = CONFIG_EXTEND_QRANGE?12:10;
bits_count = 12;
do
{
DECODE_EXTRABIT_AND_ADJUST_VAL(cat6_prob[bits_count], bits_count);
......@@ -718,7 +713,7 @@ CHECK_0_:
CAT_FIVE_CONTEXT_NODE_0_);
val = CAT6_MIN_VAL;
bits_count = CONFIG_EXTEND_QRANGE?12:10;
bits_count = 12;
do
{
......
......@@ -49,11 +49,9 @@ void vp8_dmachine_specific_config(VP8D_COMP *pbi)
vp8_arch_arm_decode_init(pbi);
#endif
#if CONFIG_EXTEND_QRANGE
pbi->dequant.idct_add = vp8_dequant_idct_add_c;
pbi->dequant.dc_idct_add = vp8_dequant_dc_idct_add_c;
pbi->dequant.dc_idct_add_y_block = vp8_dequant_dc_idct_add_y_block_c;
pbi->dequant.idct_add_y_block = vp8_dequant_idct_add_y_block_c;
pbi->dequant.idct_add_uv_block = vp8_dequant_idct_add_uv_block_c;
#endif
}
......@@ -124,9 +124,7 @@ void vp8dx_initialize()
if (!init_done)
{
vp8_initialize_common();
#if CONFIG_EXTEND_QRANGE
vp8_init_quant_tables();
#endif
vp8_scale_machine_specific_config();
init_done = 1;
}
......
......@@ -36,11 +36,7 @@ void vp8_short_fdct8x8_c(short *block, short *coefs, int pitch)
{
for (j = 0; j < 8; j++)
{
#if !CONFIG_EXTEND_QRANGE
b[j] = (float)( block[k + j]<<1);
#else
b[j] = (float)( block[k + j]<<3);
#endif
}
/* Horizontal transform */
for (j = 0; j < 4; j++)
......@@ -140,17 +136,11 @@ void vp8_short_fdct4x4_c(short *input, short *output, int pitch)
for (i = 0; i < 4; i++)
{
#if CONFIG_EXTEND_QRANGE
a1 = ((ip[0] + ip[3])<<5);
b1 = ((ip[1] + ip[2])<<5);
c1 = ((ip[1] - ip[2])<<5);
d1 = ((ip[0] - ip[3])<<5);
#else
a1 = ((ip[0] + ip[3])<<3);
b1 = ((ip[1] + ip[2])<<3);
c1 = ((ip[1] - ip[2])<<3);
d1 = ((ip[0] - ip[3])<<3);
#endif
op[0] = a1 + b1;
op[2] = a1 - b1;
......@@ -198,22 +188,12 @@ void vp8_short_walsh4x4_c(short *input, short *output, int pitch)
for (i = 0; i < 4; i++)
{
#if !CONFIG_EXTEND_QRANGE
a1 = ((ip[0] + ip[2])<<2);
d1 = ((ip[1] + ip[3])<<2);
c1 = ((ip[1] - ip[3])<<2);
b1 = ((ip[0] - ip[2])<<2);
op[0] = a1 + d1 + (a1!=0);
#else
a1 = ((ip[0] + ip[2]));
d1 = ((ip[1] + ip[3]));
c1 = ((ip[1] - ip[3]));
b1 = ((ip[0] - ip[2]));
op[0] = a1 + d1;
#endif
op[1] = b1 + c1;
op[2] = b1 - c1;
op[3] = a1 - d1;
......@@ -241,17 +221,11 @@ void vp8_short_walsh4x4_c(short *input, short *output, int pitch)
c2 += c2<0;
d2 += d2<0;
#if !CONFIG_EXTEND_QRANGE
op[0] = (a2+3) >> 3;
op[4] = (b2+3) >> 3;
op[8] = (c2+3) >> 3;
op[12]= (d2+3) >> 3;
#else
op[0] = (a2+1) >> 2;
op[4] = (b2+1) >> 2;
op[8] = (c2+1) >> 2;
op[12]= (d2+1) >> 2;
#endif
ip++;
op++;
}
......
......@@ -355,11 +355,7 @@ struct vp8_token_state{
// TODO: experiments to find optimal multiple numbers
#define Y1_RD_MULT 4
#define UV_RD_MULT 2
#if !CONFIG_EXTEND_QRANGE
#define Y2_RD_MULT 16
#else
#define Y2_RD_MULT 4
#endif
static const int plane_rd_mult[4]=
{
......@@ -615,7 +611,6 @@ static void optimize_b(MACROBLOCK *mb, int ib, int type,
*a = *l = (d->eob != !type);
}
#if CONFIG_EXTEND_QRANGE
/**************************************************************************
our inverse hadamard transform effectively is weighted sum of all 16 inputs
with weight either 1 or -1. It has a last stage scaling of (sum+1)>>2. And
......@@ -625,18 +620,6 @@ static void optimize_b(MACROBLOCK *mb, int ib, int type,
fall between -65 and +65.
**************************************************************************/
#define SUM_2ND_COEFF_THRESH 65
#else
/**************************************************************************
our inverse hadamard transform effectively is weighted sum of all 16 inputs
with weight either 1 or -1. It has a last stage scaling of (sum+3)>>3. And
dc only idct is (dc+4)>>3. So if all the sums are between -35 and 29, the
output after inverse wht and idct will be all zero. A sum of absolute value
smaller than 35 guarantees all 16 different (+1/-1) weighted sums in wht
fall between -35 and +35.
**************************************************************************/
#define SUM_2ND_COEFF_THRESH 35
#endif
static void check_reset_2nd_coeffs(MACROBLOCKD *x, int type,
ENTROPY_CONTEXT *a, ENTROPY_CONTEXT *l)
......@@ -1052,11 +1035,7 @@ void optimize_b_8x8(MACROBLOCK *mb, int i, int type,
final_eob = i;
rc = vp8_default_zig_zag1d_8x8[i];
qcoeff_ptr[rc] = x;
#if !CONFIG_EXTEND_QRANGE
dqcoeff_ptr[rc] = x * dequant_ptr[rc!=0];
#else
dqcoeff_ptr[rc] = (x * dequant_ptr[rc!=0]+2)>>2;
#endif
next = tokens[i][best].next;
best = (best_mask[best] >> i) & 1;
......
......@@ -121,12 +121,10 @@ void vp8_cmachine_specific_config(VP8_COMP *cpi)
vp8_arch_arm_encoder_init(cpi);
#endif
#if CONFIG_EXTEND_QRANGE
cpi->rtcd.fdct.short4x4 = vp8_short_fdct4x4_c;
cpi->rtcd.fdct.short8x4 = vp8_short_fdct8x4_c;
cpi->rtcd.fdct.fast4x4 = vp8_short_fdct4x4_c;
cpi->rtcd.fdct.fast8x4 = vp8_short_fdct8x4_c;
cpi->rtcd.fdct.walsh_short4x4 = vp8_short_walsh4x4_c;
#endif
}
......@@ -275,9 +275,7 @@ void vp8_initialize()
vp8_initialize_common();
//vp8_dmachine_specific_config();
vp8_tokenize_initialize();
#if CONFIG_EXTEND_QRANGE
vp8_init_quant_tables();
#endif
vp8_init_me_luts();
init_minq_luts();
init_base_skip_probs();
......@@ -1879,7 +1877,6 @@ void vp8_alloc_compressor_data(VP8_COMP *cpi)
//
// Table that converts 0-63 Q range values passed in outside to the Qindex
// range used internally.
#if CONFIG_EXTEND_QRANGE
static const int q_trans[] =
{
0, 4, 8, 12, 16, 20, 24, 28,
......@@ -1891,19 +1888,6 @@ static const int q_trans[] =
192, 196, 200, 204, 208, 212, 216, 220,
224, 228, 232, 236, 240, 244, 249, 255,
};
#else
static const int q_trans[] =
{
0, 1, 2, 3, 4, 5, 7, 8,
9, 10, 12, 13, 15, 17, 18, 19,
20, 21, 23, 24, 25, 26, 27, 28,
29, 30, 31, 33, 35, 37, 39, 41,
43, 45, 47, 49, 51, 53, 55, 57,
59, 61, 64, 67, 70, 73, 76, 79,
82, 85, 88, 91, 94, 97, 100, 103,
106, 109, 112, 115, 118, 121, 124, 127,
};
#endif
int vp8_reverse_trans(int x)
{
......@@ -3500,12 +3484,6 @@ static int decide_key_frame(VP8_COMP *cpi)
}
/*#if !CONFIG_EXTEND_QRANGE
#define FIRSTPASS_QINDEX 26
#else
#define FIRSTPASS_QINDEX 49
#endif*/
int find_fp_qindex()
{
int i;
......@@ -5062,11 +5040,7 @@ static void encode_frame_to_data_rate
(cpi->oxcf.starting_buffer_level-cpi->bits_off_target),
(int)cpi->total_actual_bits,
vp8_convert_qindex_to_q(cm->base_qindex),
#if CONFIG_EXTEND_QRANGE
(double)vp8_dc_quant(cm->base_qindex,0)/4.0,
#else
(double)vp8_dc_quant(cm->base_qindex,0),
#endif
vp8_convert_qindex_to_q(cpi->active_best_quality),
vp8_convert_qindex_to_q(cpi->active_worst_quality),
cpi->avg_q,
......@@ -5094,11 +5068,7 @@ static void encode_frame_to_data_rate
(cpi->oxcf.starting_buffer_level-cpi->bits_off_target),
(int)cpi->total_actual_bits,
vp8_convert_qindex_to_q(cm->base_qindex),
#if CONFIG_EXTEND_QRANGE
(double)vp8_dc_quant(cm->base_qindex,0)/4.0,
#else
(double)vp8_dc_quant(cm->base_qindex,0),
#endif
vp8_convert_qindex_to_q(cpi->active_best_quality),
vp8_convert_qindex_to_q(cpi->active_worst_quality),
cpi->avg_q,
......
......@@ -460,9 +460,7 @@ void vp8_fast_quantize_b_2x2_c(BLOCK *b, BLOCKD *d)
qcoeff_ptr[rc] = x; // write to destination
//dqcoeff_ptr[rc] = x * dequant_ptr[rc] / q2nd; // dequantized value
dqcoeff_ptr[rc] = x * dequant_ptr[rc]; // dequantized value
#if CONFIG_EXTEND_QRANGE
dqcoeff_ptr[rc] = (dqcoeff_ptr[rc]+2)>>2;
#endif
if (y)
{
......@@ -511,11 +509,7 @@ void vp8_fast_quantize_b_8x8_c(BLOCK *b, BLOCKD *d)
qcoeff_ptr[rc] = x; // write to destination
//dqcoeff_ptr[rc] = x * dequant_ptr[rc!=0] / q1st; // dequantized value
dqcoeff_ptr[rc] = x * dequant_ptr[rc!=0]; // dequantized value
#if CONFIG_EXTEND_QRANGE
dqcoeff_ptr[rc] = (dqcoeff_ptr[rc]+2)>>2;
#endif
if (y)
{
......@@ -572,10 +566,7 @@ void vp8_regular_quantize_b_2x2(BLOCK *b, BLOCKD *d)
qcoeff_ptr[rc] = x; // write to destination
//dqcoeff_ptr[rc] = x * dequant_ptr[rc]/q2nd; // dequantized value
dqcoeff_ptr[rc] = x * dequant_ptr[rc]; // dequantized value
#if CONFIG_EXTEND_QRANGE
dqcoeff_ptr[rc] = (dqcoeff_ptr[rc]+2)>>2;
#endif
if (y)
......@@ -636,9 +627,7 @@ void vp8_regular_quantize_b_8x8(BLOCK *b, BLOCKD *d)