summaryrefslogtreecommitdiff
path: root/vp8/encoder/quantize.c
diff options
context:
space:
mode:
authorJohn Koleszar <jkoleszar@google.com>2010-11-11 12:41:07 -0500
committerJohn Koleszar <jkoleszar@google.com>2010-11-11 13:05:20 -0500
commit0a49747b01401900272ccf0dfbb6481429707ad5 (patch)
treeb82ba1c84fadf030ef7ab0471aab661c91a247ad /vp8/encoder/quantize.c
parent58083cb34db84349d8f138e1ee59f4aee77e6624 (diff)
downloadlibvpx-0a49747b01401900272ccf0dfbb6481429707ad5.tar
libvpx-0a49747b01401900272ccf0dfbb6481429707ad5.tar.gz
libvpx-0a49747b01401900272ccf0dfbb6481429707ad5.tar.bz2
libvpx-0a49747b01401900272ccf0dfbb6481429707ad5.zip
quantizer: fix assertion in fast quantizer path
The fast quantizer assembly code has not been updated to match the new exact quantizer, which was made the default in commit 6adbe09. Specifically, they are not aware of the potential for the coefficient to be scaled, which results in the quantized result exceeding the range of the DCT. This patch restores the previous behavior of using the non-shifted coefficients when in the fast quantizer code path, but unfortunately requires rebuilding the tables when switching between the two. Change-Id: I0a33f5b3850335011a06906f49fafed54dda9546
Diffstat (limited to 'vp8/encoder/quantize.c')
-rw-r--r--vp8/encoder/quantize.c75
1 files changed, 41 insertions, 34 deletions
diff --git a/vp8/encoder/quantize.c b/vp8/encoder/quantize.c
index c2c0351c0..a1be6614b 100644
--- a/vp8/encoder/quantize.c
+++ b/vp8/encoder/quantize.c
@@ -17,7 +17,8 @@
#include "predictdc.h"
#define EXACT_QUANT
-#ifdef EXACT_QUANT
+
+#ifdef EXACT_FASTQUANT
void vp8_fast_quantize_b_c(BLOCK *b, BLOCKD *d)
{
int i, rc, eob;
@@ -64,6 +65,45 @@ void vp8_fast_quantize_b_c(BLOCK *b, BLOCKD *d)
d->eob = eob + 1;
}
+#else
+
+void vp8_fast_quantize_b_c(BLOCK *b, BLOCKD *d)
+{
+ int i, rc, eob;
+ int zbin;
+ int x, y, z, sz;
+ short *coeff_ptr = b->coeff;
+ short *round_ptr = b->round;
+ short *quant_ptr = b->quant;
+ short *qcoeff_ptr = d->qcoeff;
+ short *dqcoeff_ptr = d->dqcoeff;
+ short *dequant_ptr = d->dequant;
+
+ eob = -1;
+ for (i = 0; i < 16; i++)
+ {
+ rc = vp8_default_zig_zag1d[i];
+ z = coeff_ptr[rc];
+
+ sz = (z >> 31); // sign of z
+ x = (z ^ sz) - sz; // x = abs(z)
+
+ y = ((x + round_ptr[rc]) * quant_ptr[rc]) >> 16; // quantize (x)
+ x = (y ^ sz) - sz; // get the sign back
+ qcoeff_ptr[rc] = x; // write to destination
+ dqcoeff_ptr[rc] = x * dequant_ptr[rc]; // dequantized value
+
+ if (y)
+ {
+ eob = i; // last nonzero coeffs
+ }
+ }
+ d->eob = eob + 1;
+}
+
+#endif
+
+#ifdef EXACT_QUANT
void vp8_regular_quantize_b(BLOCK *b, BLOCKD *d)
{
int i, rc, eob;
@@ -178,39 +218,6 @@ void vp8_strict_quantize_b(BLOCK *b, BLOCKD *d)
}
#else
-void vp8_fast_quantize_b_c(BLOCK *b, BLOCKD *d)
-{
- int i, rc, eob;
- int zbin;
- int x, y, z, sz;
- short *coeff_ptr = b->coeff;
- short *round_ptr = b->round;
- short *quant_ptr = b->quant;
- short *qcoeff_ptr = d->qcoeff;
- short *dqcoeff_ptr = d->dqcoeff;
- short *dequant_ptr = d->dequant;
-
- eob = -1;
- for (i = 0; i < 16; i++)
- {
- rc = vp8_default_zig_zag1d[i];
- z = coeff_ptr[rc];
-
- sz = (z >> 31); // sign of z
- x = (z ^ sz) - sz; // x = abs(z)
-
- y = ((x + round_ptr[rc]) * quant_ptr[rc]) >> 16; // quantize (x)
- x = (y ^ sz) - sz; // get the sign back
- qcoeff_ptr[rc] = x; // write to destination
- dqcoeff_ptr[rc] = x * dequant_ptr[rc]; // dequantized value
-
- if (y)
- {
- eob = i; // last nonzero coeffs
- }
- }
- d->eob = eob + 1;
-}
void vp8_regular_quantize_b(BLOCK *b, BLOCKD *d)
{