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

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

Issue 341293003: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 6 months 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 12
13 #include "vpx_mem/vpx_mem.h" 13 #include "vpx_mem/vpx_mem.h"
14 14
15 #include "vp9/common/vp9_quant_common.h" 15 #include "vp9/common/vp9_quant_common.h"
16 #include "vp9/common/vp9_seg_common.h" 16 #include "vp9/common/vp9_seg_common.h"
17 17
18 #include "vp9/encoder/vp9_encoder.h" 18 #include "vp9/encoder/vp9_encoder.h"
19 #include "vp9/encoder/vp9_quantize.h" 19 #include "vp9/encoder/vp9_quantize.h"
20 #include "vp9/encoder/vp9_rdopt.h" 20 #include "vp9/encoder/vp9_rdopt.h"
21 21
22 void vp9_quantize_dc(const int16_t *coeff_ptr, int skip_block,
23 const int16_t *round_ptr, const int16_t quant,
24 int16_t *qcoeff_ptr, int16_t *dqcoeff_ptr,
25 const int16_t dequant_ptr, uint16_t *eob_ptr) {
26 int eob = -1;
27
28 if (!skip_block) {
29 const int rc = 0;
30 const int coeff = coeff_ptr[rc];
31 const int coeff_sign = (coeff >> 31);
32 const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign;
33
34 int tmp = clamp(abs_coeff + round_ptr[rc != 0], INT16_MIN, INT16_MAX);
35 tmp = (tmp * quant) >> 16;
36 qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign;
37 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr;
38 if (tmp)
39 eob = 0;
40 }
41 *eob_ptr = eob + 1;
42 }
43
44 void vp9_quantize_dc_32x32(const int16_t *coeff_ptr, int skip_block,
45 const int16_t *round_ptr, const int16_t quant,
46 int16_t *qcoeff_ptr, int16_t *dqcoeff_ptr,
47 const int16_t dequant_ptr, uint16_t *eob_ptr) {
48 int eob = -1;
49
50 if (!skip_block) {
51 const int rc = 0;
52 const int coeff = coeff_ptr[rc];
53 const int coeff_sign = (coeff >> 31);
54 const int abs_coeff = (coeff ^ coeff_sign) - coeff_sign;
55
56 int tmp = clamp(abs_coeff + round_ptr[rc != 0], INT16_MIN, INT16_MAX);
57 tmp = (tmp * quant) >> 15;
58 qcoeff_ptr[rc] = (tmp ^ coeff_sign) - coeff_sign;
59 dqcoeff_ptr[rc] = qcoeff_ptr[rc] * dequant_ptr / 2;
60 if (tmp)
61 eob = 0;
62 }
63 *eob_ptr = eob + 1;
64 }
65
22 void vp9_quantize_b_c(const int16_t *coeff_ptr, intptr_t count, 66 void vp9_quantize_b_c(const int16_t *coeff_ptr, intptr_t count,
23 int skip_block, 67 int skip_block,
24 const int16_t *zbin_ptr, const int16_t *round_ptr, 68 const int16_t *zbin_ptr, const int16_t *round_ptr,
25 const int16_t *quant_ptr, const int16_t *quant_shift_ptr, 69 const int16_t *quant_ptr, const int16_t *quant_shift_ptr,
26 int16_t *qcoeff_ptr, int16_t *dqcoeff_ptr, 70 int16_t *qcoeff_ptr, int16_t *dqcoeff_ptr,
27 const int16_t *dequant_ptr, 71 const int16_t *dequant_ptr,
28 int zbin_oq_value, uint16_t *eob_ptr, 72 int zbin_oq_value, uint16_t *eob_ptr,
29 const int16_t *scan, const int16_t *iscan) { 73 const int16_t *scan, const int16_t *iscan) {
30 int i, non_zero_count = (int)count, eob = -1; 74 int i, non_zero_count = (int)count, eob = -1;
31 const int zbins[2] = { zbin_ptr[0] + zbin_oq_value, 75 const int zbins[2] = { zbin_ptr[0] + zbin_oq_value,
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 204
161 for (q = 0; q < QINDEX_RANGE; q++) { 205 for (q = 0; q < QINDEX_RANGE; q++) {
162 const int qzbin_factor = q == 0 ? 64 : (vp9_dc_quant(q, 0) < 148 ? 84 : 80); 206 const int qzbin_factor = q == 0 ? 64 : (vp9_dc_quant(q, 0) < 148 ? 84 : 80);
163 const int qrounding_factor = q == 0 ? 64 : 48; 207 const int qrounding_factor = q == 0 ? 64 : 48;
164 208
165 for (i = 0; i < 2; ++i) { 209 for (i = 0; i < 2; ++i) {
166 // y 210 // y
167 quant = i == 0 ? vp9_dc_quant(q, cm->y_dc_delta_q) 211 quant = i == 0 ? vp9_dc_quant(q, cm->y_dc_delta_q)
168 : vp9_ac_quant(q, 0); 212 : vp9_ac_quant(q, 0);
169 invert_quant(&quants->y_quant[q][i], &quants->y_quant_shift[q][i], quant); 213 invert_quant(&quants->y_quant[q][i], &quants->y_quant_shift[q][i], quant);
214 quants->y_quant_fp[q][i] = (1 << 16) / quant;
170 quants->y_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7); 215 quants->y_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7);
171 quants->y_round[q][i] = (qrounding_factor * quant) >> 7; 216 quants->y_round[q][i] = (qrounding_factor * quant) >> 7;
172 cm->y_dequant[q][i] = quant; 217 cm->y_dequant[q][i] = quant;
173 218
174 // uv 219 // uv
175 quant = i == 0 ? vp9_dc_quant(q, cm->uv_dc_delta_q) 220 quant = i == 0 ? vp9_dc_quant(q, cm->uv_dc_delta_q)
176 : vp9_ac_quant(q, cm->uv_ac_delta_q); 221 : vp9_ac_quant(q, cm->uv_ac_delta_q);
177 invert_quant(&quants->uv_quant[q][i], 222 invert_quant(&quants->uv_quant[q][i],
178 &quants->uv_quant_shift[q][i], quant); 223 &quants->uv_quant_shift[q][i], quant);
224 quants->uv_quant_fp[q][i] = (1 << 16) / quant;
179 quants->uv_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7); 225 quants->uv_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7);
180 quants->uv_round[q][i] = (qrounding_factor * quant) >> 7; 226 quants->uv_round[q][i] = (qrounding_factor * quant) >> 7;
181 cm->uv_dequant[q][i] = quant; 227 cm->uv_dequant[q][i] = quant;
182 228
183 #if CONFIG_ALPHA 229 #if CONFIG_ALPHA
184 // alpha 230 // alpha
185 quant = i == 0 ? vp9_dc_quant(q, cm->a_dc_delta_q) 231 quant = i == 0 ? vp9_dc_quant(q, cm->a_dc_delta_q)
186 : vp9_ac_quant(q, cm->a_ac_delta_q); 232 : vp9_ac_quant(q, cm->a_ac_delta_q);
187 invert_quant(&quants->a_quant[q][i], &quants->a_quant_shift[q][i], quant); 233 invert_quant(&quants->a_quant[q][i], &quants->a_quant_shift[q][i], quant);
188 quants->a_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7); 234 quants->a_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7);
189 quants->a_round[q][i] = (qrounding_factor * quant) >> 7; 235 quants->a_round[q][i] = (qrounding_factor * quant) >> 7;
190 cm->a_dequant[q][i] = quant; 236 cm->a_dequant[q][i] = quant;
191 #endif 237 #endif
192 } 238 }
193 239
194 for (i = 2; i < 8; i++) { 240 for (i = 2; i < 8; i++) {
195 quants->y_quant[q][i] = quants->y_quant[q][1]; 241 quants->y_quant[q][i] = quants->y_quant[q][1];
242 quants->y_quant_fp[q][i] = quants->y_quant_fp[q][1];
196 quants->y_quant_shift[q][i] = quants->y_quant_shift[q][1]; 243 quants->y_quant_shift[q][i] = quants->y_quant_shift[q][1];
197 quants->y_zbin[q][i] = quants->y_zbin[q][1]; 244 quants->y_zbin[q][i] = quants->y_zbin[q][1];
198 quants->y_round[q][i] = quants->y_round[q][1]; 245 quants->y_round[q][i] = quants->y_round[q][1];
199 cm->y_dequant[q][i] = cm->y_dequant[q][1]; 246 cm->y_dequant[q][i] = cm->y_dequant[q][1];
200 247
201 quants->uv_quant[q][i] = quants->uv_quant[q][1]; 248 quants->uv_quant[q][i] = quants->uv_quant[q][1];
249 quants->uv_quant_fp[q][i] = quants->uv_quant_fp[q][1];
202 quants->uv_quant_shift[q][i] = quants->uv_quant_shift[q][1]; 250 quants->uv_quant_shift[q][i] = quants->uv_quant_shift[q][1];
203 quants->uv_zbin[q][i] = quants->uv_zbin[q][1]; 251 quants->uv_zbin[q][i] = quants->uv_zbin[q][1];
204 quants->uv_round[q][i] = quants->uv_round[q][1]; 252 quants->uv_round[q][i] = quants->uv_round[q][1];
205 cm->uv_dequant[q][i] = cm->uv_dequant[q][1]; 253 cm->uv_dequant[q][i] = cm->uv_dequant[q][1];
206 254
207 #if CONFIG_ALPHA 255 #if CONFIG_ALPHA
208 quants->a_quant[q][i] = quants->a_quant[q][1]; 256 quants->a_quant[q][i] = quants->a_quant[q][1];
209 quants->a_quant_shift[q][i] = quants->a_quant_shift[q][1]; 257 quants->a_quant_shift[q][i] = quants->a_quant_shift[q][1];
210 quants->a_zbin[q][i] = quants->a_zbin[q][1]; 258 quants->a_zbin[q][i] = quants->a_zbin[q][1];
211 quants->a_round[q][i] = quants->a_round[q][1]; 259 quants->a_round[q][i] = quants->a_round[q][1];
212 cm->a_dequant[q][i] = cm->a_dequant[q][1]; 260 cm->a_dequant[q][i] = cm->a_dequant[q][1];
213 #endif 261 #endif
214 } 262 }
215 } 263 }
216 } 264 }
217 265
218 void vp9_init_plane_quantizers(VP9_COMP *cpi, MACROBLOCK *x) { 266 void vp9_init_plane_quantizers(VP9_COMP *cpi, MACROBLOCK *x) {
219 const VP9_COMMON *const cm = &cpi->common; 267 const VP9_COMMON *const cm = &cpi->common;
220 MACROBLOCKD *const xd = &x->e_mbd; 268 MACROBLOCKD *const xd = &x->e_mbd;
221 QUANTS *const quants = &cpi->quants; 269 QUANTS *const quants = &cpi->quants;
222 const int segment_id = xd->mi[0]->mbmi.segment_id; 270 const int segment_id = xd->mi[0]->mbmi.segment_id;
223 const int qindex = vp9_get_qindex(&cm->seg, segment_id, cm->base_qindex); 271 const int qindex = vp9_get_qindex(&cm->seg, segment_id, cm->base_qindex);
224 const int rdmult = vp9_compute_rd_mult(cpi, qindex + cm->y_dc_delta_q); 272 const int rdmult = vp9_compute_rd_mult(cpi, qindex + cm->y_dc_delta_q);
225 const int zbin = cpi->zbin_mode_boost; 273 const int zbin = cpi->zbin_mode_boost;
226 int i; 274 int i;
227 275
228 // Y 276 // Y
229 x->plane[0].quant = quants->y_quant[qindex]; 277 x->plane[0].quant = quants->y_quant[qindex];
278 x->plane[0].quant_fp = quants->y_quant_fp[qindex];
230 x->plane[0].quant_shift = quants->y_quant_shift[qindex]; 279 x->plane[0].quant_shift = quants->y_quant_shift[qindex];
231 x->plane[0].zbin = quants->y_zbin[qindex]; 280 x->plane[0].zbin = quants->y_zbin[qindex];
232 x->plane[0].round = quants->y_round[qindex]; 281 x->plane[0].round = quants->y_round[qindex];
233 x->plane[0].zbin_extra = (int16_t)((cm->y_dequant[qindex][1] * zbin) >> 7); 282 x->plane[0].zbin_extra = (int16_t)((cm->y_dequant[qindex][1] * zbin) >> 7);
234 xd->plane[0].dequant = cm->y_dequant[qindex]; 283 xd->plane[0].dequant = cm->y_dequant[qindex];
235 284
236 // UV 285 // UV
237 for (i = 1; i < 3; i++) { 286 for (i = 1; i < 3; i++) {
238 x->plane[i].quant = quants->uv_quant[qindex]; 287 x->plane[i].quant = quants->uv_quant[qindex];
288 x->plane[i].quant_fp = quants->uv_quant_fp[qindex];
239 x->plane[i].quant_shift = quants->uv_quant_shift[qindex]; 289 x->plane[i].quant_shift = quants->uv_quant_shift[qindex];
240 x->plane[i].zbin = quants->uv_zbin[qindex]; 290 x->plane[i].zbin = quants->uv_zbin[qindex];
241 x->plane[i].round = quants->uv_round[qindex]; 291 x->plane[i].round = quants->uv_round[qindex];
242 x->plane[i].zbin_extra = (int16_t)((cm->uv_dequant[qindex][1] * zbin) >> 7); 292 x->plane[i].zbin_extra = (int16_t)((cm->uv_dequant[qindex][1] * zbin) >> 7);
243 xd->plane[i].dequant = cm->uv_dequant[qindex]; 293 xd->plane[i].dequant = cm->uv_dequant[qindex];
244 } 294 }
245 295
246 #if CONFIG_ALPHA 296 #if CONFIG_ALPHA
247 x->plane[3].quant = quants->a_quant[qindex]; 297 x->plane[3].quant = quants->a_quant[qindex];
248 x->plane[3].quant_shift = quants->a_quant_shift[qindex]; 298 x->plane[3].quant_shift = quants->a_quant_shift[qindex];
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 356
307 int vp9_qindex_to_quantizer(int qindex) { 357 int vp9_qindex_to_quantizer(int qindex) {
308 int quantizer; 358 int quantizer;
309 359
310 for (quantizer = 0; quantizer < 64; ++quantizer) 360 for (quantizer = 0; quantizer < 64; ++quantizer)
311 if (quantizer_to_qindex[quantizer] >= qindex) 361 if (quantizer_to_qindex[quantizer] >= qindex)
312 return quantizer; 362 return quantizer;
313 363
314 return 63; 364 return 63;
315 } 365 }
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