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
64 void vp8_regular_quantize_b(BLOCK *b, BLOCKD *d)
69 short *zbin_boost_ptr = &b->zrun_zbin_boost[0];
70 short *coeff_ptr = &b->coeff[0];
71 short *zbin_ptr = &b->zbin[0][0];
72 short *round_ptr = &b->round[0][0];
73 short *quant_ptr = &b->quant[0][0];
74 short *qcoeff_ptr = d->qcoeff;
75 short *dqcoeff_ptr = d->dqcoeff;
76 short *dequant_ptr = &d->dequant[0][0];
77 short zbin_oq_value = b->zbin_extra;
79 vpx_memset(qcoeff_ptr, 0, 32);
80 vpx_memset(dqcoeff_ptr, 0, 32);
84 for (i = 0; i < 16; i++)
86 rc = vp8_default_zig_zag1d[i];
90 // zbin = zbin_ptr[rc] + *zbin_boost_ptr + zbin_oq_value/2;
92 zbin = zbin_ptr[rc] + *zbin_boost_ptr + zbin_oq_value;
95 sz = (z >> 31); // sign of z
96 x = (z ^ sz) - sz; // x = abs(z)
100 y = ((x + round_ptr[rc]) * quant_ptr[rc]) >> 16; // quantize (x)
101 x = (y ^ sz) - sz; // get the sign back
102 qcoeff_ptr[rc] = x; // write to destination
103 dqcoeff_ptr[rc] = x * dequant_ptr[rc]; // dequantized value
107 eob = i; // last nonzero coeffs
108 zbin_boost_ptr = &b->zrun_zbin_boost[0]; // reset zero runlength
115 void vp8_quantize_mby(MACROBLOCK *x)
119 if (x->e_mbd.mbmi.mode != B_PRED && x->e_mbd.mbmi.mode != SPLITMV)
121 for (i = 0; i < 16; i++)
123 x->quantize_b(&x->block[i], &x->e_mbd.block[i]);
124 x->e_mbd.mbmi.mb_skip_coeff &= (x->e_mbd.block[i].eob < 2);
127 x->quantize_b(&x->block[24], &x->e_mbd.block[24]);
128 x->e_mbd.mbmi.mb_skip_coeff &= (!x->e_mbd.block[24].eob);
133 for (i = 0; i < 16; i++)
135 x->quantize_b(&x->block[i], &x->e_mbd.block[i]);
136 x->e_mbd.mbmi.mb_skip_coeff &= (!x->e_mbd.block[i].eob);
141 void vp8_quantize_mb(MACROBLOCK *x)
145 x->e_mbd.mbmi.mb_skip_coeff = 1;
147 if (x->e_mbd.mbmi.mode != B_PRED && x->e_mbd.mbmi.mode != SPLITMV)
149 for (i = 0; i < 16; i++)
151 x->quantize_b(&x->block[i], &x->e_mbd.block[i]);
152 x->e_mbd.mbmi.mb_skip_coeff &= (x->e_mbd.block[i].eob < 2);
155 for (i = 16; i < 25; i++)
157 x->quantize_b(&x->block[i], &x->e_mbd.block[i]);
158 x->e_mbd.mbmi.mb_skip_coeff &= (!x->e_mbd.block[i].eob);
163 for (i = 0; i < 24; i++)
165 x->quantize_b(&x->block[i], &x->e_mbd.block[i]);
166 x->e_mbd.mbmi.mb_skip_coeff &= (!x->e_mbd.block[i].eob);
173 void vp8_quantize_mbuv(MACROBLOCK *x)
177 for (i = 16; i < 24; i++)
179 x->quantize_b(&x->block[i], &x->e_mbd.block[i]);
180 x->e_mbd.mbmi.mb_skip_coeff &= (!x->e_mbd.block[i].eob);