2 * Copyright (c) 2010 The VP8 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"
19 void vp8_fast_quantize_b_c(BLOCK *b, BLOCKD *d)
24 short *coeff_ptr = &b->coeff[0];
25 short *zbin_ptr = &b->zbin[0][0];
26 short *round_ptr = &b->round[0][0];
27 short *quant_ptr = &b->quant[0][0];
28 short *qcoeff_ptr = d->qcoeff;
29 short *dqcoeff_ptr = d->dqcoeff;
30 short *dequant_ptr = &d->dequant[0][0];
32 vpx_memset(qcoeff_ptr, 0, 32);
33 vpx_memset(dqcoeff_ptr, 0, 32);
37 for (i = 0; i < 16; i++)
39 rc = vp8_default_zig_zag1d[i];
43 sz = (z >> 31); // sign of z
44 x = (z ^ sz) - sz; // x = abs(z)
48 y = ((x + round_ptr[rc]) * quant_ptr[rc]) >> 16; // quantize (x)
49 x = (y ^ sz) - sz; // get the sign back
50 qcoeff_ptr[rc] = x; // write to destination
51 dqcoeff_ptr[rc] = x * dequant_ptr[rc]; // dequantized value
55 eob = i; // last nonzero coeffs
62 void vp8_regular_quantize_b(BLOCK *b, BLOCKD *d)
67 short *zbin_boost_ptr = &b->zrun_zbin_boost[0];
68 short *coeff_ptr = &b->coeff[0];
69 short *zbin_ptr = &b->zbin[0][0];
70 short *round_ptr = &b->round[0][0];
71 short *quant_ptr = &b->quant[0][0];
72 short *qcoeff_ptr = d->qcoeff;
73 short *dqcoeff_ptr = d->dqcoeff;
74 short *dequant_ptr = &d->dequant[0][0];
75 short zbin_oq_value = b->zbin_extra;
77 vpx_memset(qcoeff_ptr, 0, 32);
78 vpx_memset(dqcoeff_ptr, 0, 32);
82 for (i = 0; i < 16; i++)
84 rc = vp8_default_zig_zag1d[i];
88 // zbin = zbin_ptr[rc] + *zbin_boost_ptr + zbin_oq_value/2;
90 zbin = zbin_ptr[rc] + *zbin_boost_ptr + zbin_oq_value;
93 sz = (z >> 31); // sign of z
94 x = (z ^ sz) - sz; // x = abs(z)
98 y = ((x + round_ptr[rc]) * quant_ptr[rc]) >> 16; // quantize (x)
99 x = (y ^ sz) - sz; // get the sign back
100 qcoeff_ptr[rc] = x; // write to destination
101 dqcoeff_ptr[rc] = x * dequant_ptr[rc]; // dequantized value
105 eob = i; // last nonzero coeffs
106 zbin_boost_ptr = &b->zrun_zbin_boost[0]; // reset zero runlength
114 void vp8_quantize_mby(MACROBLOCK *x)
117 int has_2nd_order = (x->e_mbd.mbmi.mode != B_PRED
118 && x->e_mbd.mbmi.mode != SPLITMV);
120 for (i = 0; i < 16; i++)
122 x->quantize_b(&x->block[i], &x->e_mbd.block[i]);
123 x->e_mbd.mbmi.mb_skip_coeff &=
124 (x->e_mbd.block[i].eob <= has_2nd_order);
129 x->quantize_b(&x->block[24], &x->e_mbd.block[24]);
130 x->e_mbd.mbmi.mb_skip_coeff &= (!x->e_mbd.block[24].eob);
134 void vp8_quantize_mb(MACROBLOCK *x)
137 int has_2nd_order=(x->e_mbd.mbmi.mode != B_PRED
138 && x->e_mbd.mbmi.mode != SPLITMV);
140 x->e_mbd.mbmi.mb_skip_coeff = 1;
141 for (i = 0; i < 24+has_2nd_order; i++)
143 x->quantize_b(&x->block[i], &x->e_mbd.block[i]);
144 x->e_mbd.mbmi.mb_skip_coeff &=
145 (x->e_mbd.block[i].eob <= (has_2nd_order && i<16));
150 void vp8_quantize_mbuv(MACROBLOCK *x)
154 for (i = 16; i < 24; i++)
156 x->quantize_b(&x->block[i], &x->e_mbd.block[i]);
157 x->e_mbd.mbmi.mb_skip_coeff &= (!x->e_mbd.block[i].eob);