Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Side by Side Diff: source/libvpx/vp9/encoder/vp9_quantize.c

Issue 111463005: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_quantize.h ('k') | source/libvpx/vp9/encoder/vp9_ratectrl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <math.h> 11 #include <math.h>
12 #include "vpx_mem/vpx_mem.h" 12 #include "vpx_mem/vpx_mem.h"
13 13
14 #include "vp9/encoder/vp9_onyx_int.h" 14 #include "vp9/encoder/vp9_onyx_int.h"
15 #include "vp9/encoder/vp9_rdopt.h" 15 #include "vp9/encoder/vp9_rdopt.h"
16 #include "vp9/encoder/vp9_quantize.h" 16 #include "vp9/encoder/vp9_quantize.h"
17 #include "vp9/common/vp9_quant_common.h" 17 #include "vp9/common/vp9_quant_common.h"
18 18
19 #include "vp9/common/vp9_seg_common.h" 19 #include "vp9/common/vp9_seg_common.h"
20 20
21 #ifdef ENC_DEBUG 21 #ifdef ENC_DEBUG
22 extern int enc_debug; 22 extern int enc_debug;
23 #endif 23 #endif
24 24
25 void vp9_quantize_b_c(const int16_t *coeff_ptr, intptr_t n_coeffs, 25 void vp9_quantize_b_c(const int16_t *coeff_ptr, intptr_t count,
26 int skip_block, 26 int skip_block,
27 const int16_t *zbin_ptr, const int16_t *round_ptr, 27 const int16_t *zbin_ptr, const int16_t *round_ptr,
28 const int16_t *quant_ptr, const int16_t *quant_shift_ptr, 28 const int16_t *quant_ptr, const int16_t *quant_shift_ptr,
29 int16_t *qcoeff_ptr, int16_t *dqcoeff_ptr, 29 int16_t *qcoeff_ptr, int16_t *dqcoeff_ptr,
30 const int16_t *dequant_ptr, 30 const int16_t *dequant_ptr,
31 int zbin_oq_value, uint16_t *eob_ptr, 31 int zbin_oq_value, uint16_t *eob_ptr,
32 const int16_t *scan, const int16_t *iscan) { 32 const int16_t *scan, const int16_t *iscan) {
33 int i, rc, eob; 33 int i, non_zero_count = count, eob = -1;
34 int zbins[2], nzbins[2], zbin; 34 const int zbins[2] = { zbin_ptr[0] + zbin_oq_value,
35 int x, y, z, sz; 35 zbin_ptr[1] + zbin_oq_value };
36 int zero_flag = n_coeffs; 36 const int nzbins[2] = { zbins[0] * -1,
37 zbins[1] * -1 };
37 38
38 vpx_memset(qcoeff_ptr, 0, n_coeffs*sizeof(int16_t)); 39 vpx_memset(qcoeff_ptr, 0, count * sizeof(int16_t));
39 vpx_memset(dqcoeff_ptr, 0, n_coeffs*sizeof(int16_t)); 40 vpx_memset(dqcoeff_ptr, 0, count * sizeof(int16_t));
40
41 eob = -1;
42
43 // Base ZBIN
44 zbins[0] = zbin_ptr[0] + zbin_oq_value;
45 zbins[1] = zbin_ptr[1] + zbin_oq_value;
46 nzbins[0] = zbins[0] * -1;
47 nzbins[1] = zbins[1] * -1;
48 41
49 if (!skip_block) { 42 if (!skip_block) {
50 // Pre-scan pass 43 // Pre-scan pass
51 for (i = n_coeffs - 1; i >= 0; i--) { 44 for (i = count - 1; i >= 0; i--) {
52 rc = scan[i]; 45 const int rc = scan[i];
53 z = coeff_ptr[rc]; 46 const int coeff = coeff_ptr[rc];
54 47
55 if (z < zbins[rc != 0] && z > nzbins[rc != 0]) { 48 if (coeff < zbins[rc != 0] && coeff > nzbins[rc != 0])
56 zero_flag--; 49 non_zero_count--;
57 } else { 50 else
58 break; 51 break;
59 }
60 } 52 }
61 53
62 // Quantization pass: All coefficients with index >= zero_flag are 54 // Quantization pass: All coefficients with index >= zero_flag are
63 // skippable. Note: zero_flag can be zero. 55 // skippable. Note: zero_flag can be zero.
64 for (i = 0; i < zero_flag; i++) { 56 for (i = 0; i < non_zero_count; i++) {
65 rc = scan[i]; 57 const int rc = scan[i];
66 z = coeff_ptr[rc]; 58 const int coeff = coeff_ptr[rc];
59 const int coeff_sign = (coeff >> 31);
60 const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign;
67 61
68 zbin = (zbins[rc != 0]); 62 if (abs_coeff >= zbins[rc != 0]) {
63 int tmp = clamp(abs_coeff + round_ptr[rc != 0], INT16_MIN, INT16_MAX);
64 tmp = ((((tmp * quant_ptr[rc != 0]) >> 16) + tmp) *
65 quant_shift_ptr[rc != 0]) >> 16; // quantization
66 qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign;
67 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr[rc != 0];
69 68
70 sz = (z >> 31); // sign of z 69 if (tmp)
71 x = (z ^ sz) - sz; 70 eob = i;
72
73 if (x >= zbin) {
74 x += (round_ptr[rc != 0]);
75 x = clamp(x, INT16_MIN, INT16_MAX);
76 y = (((int)(((int)(x * quant_ptr[rc != 0]) >> 16) + x)) *
77 quant_shift_ptr[rc != 0]) >> 16; // quantize (x)
78 x = (y ^ sz) - sz; // get the sign back
79 qcoeff_ptr[rc] = x; // write to destination
80 dqcoeff_ptr[rc] = x * dequant_ptr[rc != 0]; // dequantized value
81
82 if (y) {
83 eob = i; // last nonzero coeffs
84 }
85 } 71 }
86 } 72 }
87 } 73 }
88 *eob_ptr = eob + 1; 74 *eob_ptr = eob + 1;
89 } 75 }
90 76
91 void vp9_quantize_b_32x32_c(const int16_t *coeff_ptr, intptr_t n_coeffs, 77 void vp9_quantize_b_32x32_c(const int16_t *coeff_ptr, intptr_t n_coeffs,
92 int skip_block, 78 int skip_block,
93 const int16_t *zbin_ptr, const int16_t *round_ptr, 79 const int16_t *zbin_ptr, const int16_t *round_ptr,
94 const int16_t *quant_ptr, 80 const int16_t *quant_ptr,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 qcoeff_ptr[rc] = x; // write to destination 130 qcoeff_ptr[rc] = x; // write to destination
145 dqcoeff_ptr[rc] = x * dequant_ptr[rc != 0] / 2; // dequantized value 131 dqcoeff_ptr[rc] = x * dequant_ptr[rc != 0] / 2; // dequantized value
146 132
147 if (y) 133 if (y)
148 eob = idx_arr[i]; // last nonzero coeffs 134 eob = idx_arr[i]; // last nonzero coeffs
149 } 135 }
150 } 136 }
151 *eob_ptr = eob + 1; 137 *eob_ptr = eob + 1;
152 } 138 }
153 139
154 struct plane_block_idx { 140 void vp9_regular_quantize_b_4x4(MACROBLOCK *x, int plane, int block,
155 int plane;
156 int block;
157 };
158
159 // TODO(jkoleszar): returning a struct so it can be used in a const context,
160 // expect to refactor this further later.
161 static INLINE struct plane_block_idx plane_block_idx(int y_blocks,
162 int b_idx) {
163 const int v_offset = y_blocks * 5 / 4;
164 struct plane_block_idx res;
165
166 if (b_idx < y_blocks) {
167 res.plane = 0;
168 res.block = b_idx;
169 } else if (b_idx < v_offset) {
170 res.plane = 1;
171 res.block = b_idx - y_blocks;
172 } else {
173 assert(b_idx < y_blocks * 3 / 2);
174 res.plane = 2;
175 res.block = b_idx - v_offset;
176 }
177 return res;
178 }
179
180 void vp9_regular_quantize_b_4x4(MACROBLOCK *x, int y_blocks, int b_idx,
181 const int16_t *scan, const int16_t *iscan) { 141 const int16_t *scan, const int16_t *iscan) {
182 MACROBLOCKD *const xd = &x->e_mbd; 142 MACROBLOCKD *const xd = &x->e_mbd;
183 const struct plane_block_idx pb_idx = plane_block_idx(y_blocks, b_idx); 143 struct macroblock_plane* p = &x->plane[plane];
184 struct macroblock_plane* p = &x->plane[pb_idx.plane]; 144 struct macroblockd_plane* pd = &xd->plane[plane];
185 struct macroblockd_plane* pd = &xd->plane[pb_idx.plane];
186 145
187 vp9_quantize_b(BLOCK_OFFSET(p->coeff, pb_idx.block), 146 vp9_quantize_b(BLOCK_OFFSET(p->coeff, block),
188 16, x->skip_block, 147 16, x->skip_block,
189 p->zbin, p->round, p->quant, p->quant_shift, 148 p->zbin, p->round, p->quant, p->quant_shift,
190 BLOCK_OFFSET(pd->qcoeff, pb_idx.block), 149 BLOCK_OFFSET(p->qcoeff, block),
191 BLOCK_OFFSET(pd->dqcoeff, pb_idx.block), 150 BLOCK_OFFSET(pd->dqcoeff, block),
192 pd->dequant, p->zbin_extra, &pd->eobs[pb_idx.block], scan, iscan); 151 pd->dequant, p->zbin_extra, &p->eobs[block], scan, iscan);
193 } 152 }
194 153
195 static void invert_quant(int16_t *quant, int16_t *shift, int d) { 154 static void invert_quant(int16_t *quant, int16_t *shift, int d) {
196 unsigned t; 155 unsigned t;
197 int l; 156 int l;
198 t = d; 157 t = d;
199 for (l = 0; t > 1; l++) 158 for (l = 0; t > 1; l++)
200 t >>= 1; 159 t >>= 1;
201 t = 1 + (1 << (16 + l)) / d; 160 t = 1 + (1 << (16 + l)) / d;
202 *quant = (int16_t)(t - (1 << 16)); 161 *quant = (int16_t)(t - (1 << 16));
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 x->plane[3].zbin = cpi->a_zbin[qindex]; 267 x->plane[3].zbin = cpi->a_zbin[qindex];
309 x->plane[3].round = cpi->a_round[qindex]; 268 x->plane[3].round = cpi->a_round[qindex];
310 x->plane[3].zbin_extra = (int16_t)zbin_extra; 269 x->plane[3].zbin_extra = (int16_t)zbin_extra;
311 x->e_mbd.plane[3].dequant = cpi->common.a_dequant[qindex]; 270 x->e_mbd.plane[3].dequant = cpi->common.a_dequant[qindex];
312 #endif 271 #endif
313 272
314 x->skip_block = vp9_segfeature_active(&cpi->common.seg, segment_id, 273 x->skip_block = vp9_segfeature_active(&cpi->common.seg, segment_id,
315 SEG_LVL_SKIP); 274 SEG_LVL_SKIP);
316 275
317 /* save this macroblock QIndex for vp9_update_zbin_extra() */ 276 /* save this macroblock QIndex for vp9_update_zbin_extra() */
318 x->e_mbd.q_index = qindex; 277 x->q_index = qindex;
319 278
320 /* R/D setup */ 279 /* R/D setup */
321 cpi->mb.errorperbit = rdmult >> 6; 280 cpi->mb.errorperbit = rdmult >> 6;
322 cpi->mb.errorperbit += (cpi->mb.errorperbit == 0); 281 cpi->mb.errorperbit += (cpi->mb.errorperbit == 0);
323 282
324 vp9_initialize_me_consts(cpi, xd->q_index); 283 vp9_initialize_me_consts(cpi, x->q_index);
325 } 284 }
326 285
327 void vp9_update_zbin_extra(VP9_COMP *cpi, MACROBLOCK *x) { 286 void vp9_update_zbin_extra(VP9_COMP *cpi, MACROBLOCK *x) {
328 const int qindex = x->e_mbd.q_index; 287 const int qindex = x->q_index;
329 const int y_zbin_extra = (cpi->common.y_dequant[qindex][1] * 288 const int y_zbin_extra = (cpi->common.y_dequant[qindex][1] *
330 (cpi->zbin_mode_boost + x->act_zbin_adj)) >> 7; 289 (cpi->zbin_mode_boost + x->act_zbin_adj)) >> 7;
331 const int uv_zbin_extra = (cpi->common.uv_dequant[qindex][1] * 290 const int uv_zbin_extra = (cpi->common.uv_dequant[qindex][1] *
332 (cpi->zbin_mode_boost + x->act_zbin_adj)) >> 7; 291 (cpi->zbin_mode_boost + x->act_zbin_adj)) >> 7;
333 292
334 x->plane[0].zbin_extra = (int16_t)y_zbin_extra; 293 x->plane[0].zbin_extra = (int16_t)y_zbin_extra;
335 x->plane[1].zbin_extra = (int16_t)uv_zbin_extra; 294 x->plane[1].zbin_extra = (int16_t)uv_zbin_extra;
336 x->plane[2].zbin_extra = (int16_t)uv_zbin_extra; 295 x->plane[2].zbin_extra = (int16_t)uv_zbin_extra;
337 } 296 }
338 297
(...skipping 14 matching lines...) Expand all
353 // have to be set. 312 // have to be set.
354 cm->y_dc_delta_q = 0; 313 cm->y_dc_delta_q = 0;
355 cm->uv_dc_delta_q = 0; 314 cm->uv_dc_delta_q = 0;
356 cm->uv_ac_delta_q = 0; 315 cm->uv_ac_delta_q = 0;
357 316
358 // quantizer has to be reinitialized if any delta_q changes. 317 // quantizer has to be reinitialized if any delta_q changes.
359 // As there are not any here for now this is inactive code. 318 // As there are not any here for now this is inactive code.
360 // if(update) 319 // if(update)
361 // vp9_init_quantizer(cpi); 320 // vp9_init_quantizer(cpi);
362 } 321 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_quantize.h ('k') | source/libvpx/vp9/encoder/vp9_ratectrl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698