2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
13 #include "vpx_mem/vpx_mem.h"
17 #include "predictdc.h"
21 #ifdef EXACT_FASTQUANT
22 void vp8_fast_quantize_b_c(BLOCK *b, BLOCKD *d)
27 short *coeff_ptr = b->coeff;
28 short *zbin_ptr = b->zbin;
29 short *round_ptr = b->round;
30 short *quant_ptr = b->quant_fast;
31 short *quant_shift_ptr = b->quant_shift;
32 short *qcoeff_ptr = d->qcoeff;
33 short *dqcoeff_ptr = d->dqcoeff;
34 short *dequant_ptr = d->dequant;
36 vpx_memset(qcoeff_ptr, 0, 32);
37 vpx_memset(dqcoeff_ptr, 0, 32);
41 for (i = 0; i < 16; i++)
43 rc = vp8_default_zig_zag1d[i];
47 sz = (z >> 31); // sign of z
48 x = (z ^ sz) - sz; // x = abs(z)
53 y = (((x * quant_ptr[rc]) >> 16) + x)
54 >> quant_shift_ptr[rc]; // quantize (x)
55 x = (y ^ sz) - sz; // get the sign back
56 qcoeff_ptr[rc] = x; // write to destination
57 dqcoeff_ptr[rc] = x * dequant_ptr[rc]; // dequantized value
61 eob = i; // last nonzero coeffs
70 void vp8_fast_quantize_b_c(BLOCK *b, BLOCKD *d)
75 short *coeff_ptr = b->coeff;
76 short *round_ptr = b->round;
77 short *quant_ptr = b->quant_fast;
78 short *qcoeff_ptr = d->qcoeff;
79 short *dqcoeff_ptr = d->dqcoeff;
80 short *dequant_ptr = d->dequant;
83 for (i = 0; i < 16; i++)
85 rc = vp8_default_zig_zag1d[i];
88 sz = (z >> 31); // sign of z
89 x = (z ^ sz) - sz; // x = abs(z)
91 y = ((x + round_ptr[rc]) * quant_ptr[rc]) >> 16; // quantize (x)
92 x = (y ^ sz) - sz; // get the sign back
93 qcoeff_ptr[rc] = x; // write to destination
94 dqcoeff_ptr[rc] = x * dequant_ptr[rc]; // dequantized value
98 eob = i; // last nonzero coeffs
107 void vp8_regular_quantize_b(BLOCK *b, BLOCKD *d)
112 short *zbin_boost_ptr = b->zrun_zbin_boost;
113 short *coeff_ptr = b->coeff;
114 short *zbin_ptr = b->zbin;
115 short *round_ptr = b->round;
116 short *quant_ptr = b->quant;
117 short *quant_shift_ptr = b->quant_shift;
118 short *qcoeff_ptr = d->qcoeff;
119 short *dqcoeff_ptr = d->dqcoeff;
120 short *dequant_ptr = d->dequant;
121 short zbin_oq_value = b->zbin_extra;
123 vpx_memset(qcoeff_ptr, 0, 32);
124 vpx_memset(dqcoeff_ptr, 0, 32);
128 for (i = 0; i < 16; i++)
130 rc = vp8_default_zig_zag1d[i];
134 // zbin = zbin_ptr[rc] + *zbin_boost_ptr + zbin_oq_value/2;
136 zbin = zbin_ptr[rc] + *zbin_boost_ptr + zbin_oq_value;
139 sz = (z >> 31); // sign of z
140 x = (z ^ sz) - sz; // x = abs(z)
145 y = (((x * quant_ptr[rc]) >> 16) + x)
146 >> quant_shift_ptr[rc]; // quantize (x)
147 x = (y ^ sz) - sz; // get the sign back
148 qcoeff_ptr[rc] = x; // write to destination
149 dqcoeff_ptr[rc] = x * dequant_ptr[rc]; // dequantized value
153 eob = i; // last nonzero coeffs
154 zbin_boost_ptr = &b->zrun_zbin_boost[0]; // reset zero runlength
162 /* Perform regular quantization, with unbiased rounding and no zero bin. */
163 void vp8_strict_quantize_b(BLOCK *b, BLOCKD *d)
174 short *quant_shift_ptr;
179 coeff_ptr = b->coeff;
180 quant_ptr = b->quant;
181 quant_shift_ptr = b->quant_shift;
182 qcoeff_ptr = d->qcoeff;
183 dqcoeff_ptr = d->dqcoeff;
184 dequant_ptr = d->dequant;
186 vpx_memset(qcoeff_ptr, 0, 32);
187 vpx_memset(dqcoeff_ptr, 0, 32);
188 for (i = 0; i < 16; i++)
193 /*TODO: These arrays should be stored in zig-zag order.*/
194 rc = vp8_default_zig_zag1d[i];
196 dq = dequant_ptr[rc];
205 y = (((x * quant_ptr[rc]) >> 16) + x) >> quant_shift_ptr[rc];
206 /* Put the sign back. */
208 /* Save the coefficient and its dequantized value. */
210 dqcoeff_ptr[rc] = x * dq;
211 /* Remember the last non-zero coefficient. */
222 void vp8_regular_quantize_b(BLOCK *b, BLOCKD *d)
227 short *zbin_boost_ptr = b->zrun_zbin_boost;
228 short *coeff_ptr = b->coeff;
229 short *zbin_ptr = b->zbin;
230 short *round_ptr = b->round;
231 short *quant_ptr = b->quant;
232 short *qcoeff_ptr = d->qcoeff;
233 short *dqcoeff_ptr = d->dqcoeff;
234 short *dequant_ptr = d->dequant;
235 short zbin_oq_value = b->zbin_extra;
237 vpx_memset(qcoeff_ptr, 0, 32);
238 vpx_memset(dqcoeff_ptr, 0, 32);
242 for (i = 0; i < 16; i++)
244 rc = vp8_default_zig_zag1d[i];
248 // zbin = zbin_ptr[rc] + *zbin_boost_ptr + zbin_oq_value/2;
250 zbin = zbin_ptr[rc] + *zbin_boost_ptr + zbin_oq_value;
253 sz = (z >> 31); // sign of z
254 x = (z ^ sz) - sz; // x = abs(z)
258 y = ((x + round_ptr[rc]) * quant_ptr[rc]) >> 16; // quantize (x)
259 x = (y ^ sz) - sz; // get the sign back
260 qcoeff_ptr[rc] = x; // write to destination
261 dqcoeff_ptr[rc] = x * dequant_ptr[rc]; // dequantized value
265 eob = i; // last nonzero coeffs
266 zbin_boost_ptr = &b->zrun_zbin_boost[0]; // reset zero runlength
276 void vp8_quantize_mby(MACROBLOCK *x)
279 int has_2nd_order = (x->e_mbd.mode_info_context->mbmi.mode != B_PRED
280 && x->e_mbd.mode_info_context->mbmi.mode != SPLITMV);
282 for (i = 0; i < 16; i++)
283 x->quantize_b(&x->block[i], &x->e_mbd.block[i]);
286 x->quantize_b(&x->block[24], &x->e_mbd.block[24]);
289 void vp8_quantize_mb(MACROBLOCK *x)
292 int has_2nd_order=(x->e_mbd.mode_info_context->mbmi.mode != B_PRED
293 && x->e_mbd.mode_info_context->mbmi.mode != SPLITMV);
295 for (i = 0; i < 24+has_2nd_order; i++)
296 x->quantize_b(&x->block[i], &x->e_mbd.block[i]);
300 void vp8_quantize_mbuv(MACROBLOCK *x)
304 for (i = 16; i < 24; i++)
305 x->quantize_b(&x->block[i], &x->e_mbd.block[i]);