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

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

Issue 181493009: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 9 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 #include "vpx_mem/vpx_mem.h" 13 #include "vpx_mem/vpx_mem.h"
13 14
15 #include "vp9/common/vp9_quant_common.h"
16 #include "vp9/common/vp9_seg_common.h"
17
14 #include "vp9/encoder/vp9_onyx_int.h" 18 #include "vp9/encoder/vp9_onyx_int.h"
19 #include "vp9/encoder/vp9_quantize.h"
15 #include "vp9/encoder/vp9_rdopt.h" 20 #include "vp9/encoder/vp9_rdopt.h"
16 #include "vp9/encoder/vp9_quantize.h"
17 #include "vp9/common/vp9_quant_common.h"
18
19 #include "vp9/common/vp9_seg_common.h"
20 21
21 void vp9_quantize_b_c(const int16_t *coeff_ptr, intptr_t count, 22 void vp9_quantize_b_c(const int16_t *coeff_ptr, intptr_t count,
22 int skip_block, 23 int skip_block,
23 const int16_t *zbin_ptr, const int16_t *round_ptr, 24 const int16_t *zbin_ptr, const int16_t *round_ptr,
24 const int16_t *quant_ptr, const int16_t *quant_shift_ptr, 25 const int16_t *quant_ptr, const int16_t *quant_shift_ptr,
25 int16_t *qcoeff_ptr, int16_t *dqcoeff_ptr, 26 int16_t *qcoeff_ptr, int16_t *dqcoeff_ptr,
26 const int16_t *dequant_ptr, 27 const int16_t *dequant_ptr,
27 int zbin_oq_value, uint16_t *eob_ptr, 28 int zbin_oq_value, uint16_t *eob_ptr,
28 const int16_t *scan, const int16_t *iscan) { 29 const int16_t *scan, const int16_t *iscan) {
29 int i, non_zero_count = count, eob = -1; 30 int i, non_zero_count = (int)count, eob = -1;
30 const int zbins[2] = { zbin_ptr[0] + zbin_oq_value, 31 const int zbins[2] = { zbin_ptr[0] + zbin_oq_value,
31 zbin_ptr[1] + zbin_oq_value }; 32 zbin_ptr[1] + zbin_oq_value };
32 const int nzbins[2] = { zbins[0] * -1, 33 const int nzbins[2] = { zbins[0] * -1,
33 zbins[1] * -1 }; 34 zbins[1] * -1 };
34 35
35 vpx_memset(qcoeff_ptr, 0, count * sizeof(int16_t)); 36 vpx_memset(qcoeff_ptr, 0, count * sizeof(int16_t));
36 vpx_memset(dqcoeff_ptr, 0, count * sizeof(int16_t)); 37 vpx_memset(dqcoeff_ptr, 0, count * sizeof(int16_t));
37 38
38 if (!skip_block) { 39 if (!skip_block) {
39 // Pre-scan pass 40 // Pre-scan pass
40 for (i = count - 1; i >= 0; i--) { 41 for (i = (int)count - 1; i >= 0; i--) {
41 const int rc = scan[i]; 42 const int rc = scan[i];
42 const int coeff = coeff_ptr[rc]; 43 const int coeff = coeff_ptr[rc];
43 44
44 if (coeff < zbins[rc != 0] && coeff > nzbins[rc != 0]) 45 if (coeff < zbins[rc != 0] && coeff > nzbins[rc != 0])
45 non_zero_count--; 46 non_zero_count--;
46 else 47 else
47 break; 48 break;
48 } 49 }
49 50
50 // Quantization pass: All coefficients with index >= zero_flag are 51 // Quantization pass: All coefficients with index >= zero_flag are
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 int l; 145 int l;
145 t = d; 146 t = d;
146 for (l = 0; t > 1; l++) 147 for (l = 0; t > 1; l++)
147 t >>= 1; 148 t >>= 1;
148 t = 1 + (1 << (16 + l)) / d; 149 t = 1 + (1 << (16 + l)) / d;
149 *quant = (int16_t)(t - (1 << 16)); 150 *quant = (int16_t)(t - (1 << 16));
150 *shift = 1 << (16 - l); 151 *shift = 1 << (16 - l);
151 } 152 }
152 153
153 void vp9_init_quantizer(VP9_COMP *cpi) { 154 void vp9_init_quantizer(VP9_COMP *cpi) {
154 int i, q;
155 VP9_COMMON *const cm = &cpi->common; 155 VP9_COMMON *const cm = &cpi->common;
156 int i, q, quant;
156 157
157 for (q = 0; q < QINDEX_RANGE; q++) { 158 for (q = 0; q < QINDEX_RANGE; q++) {
158 const int qzbin_factor = q == 0 ? 64 : (vp9_dc_quant(q, 0) < 148 ? 84 : 80); 159 const int qzbin_factor = q == 0 ? 64 : (vp9_dc_quant(q, 0) < 148 ? 84 : 80);
159 const int qrounding_factor = q == 0 ? 64 : 48; 160 const int qrounding_factor = q == 0 ? 64 : 48;
160 161
161 // y
162 for (i = 0; i < 2; ++i) { 162 for (i = 0; i < 2; ++i) {
163 const int quant = i == 0 ? vp9_dc_quant(q, cm->y_dc_delta_q) 163 // y
164 : vp9_ac_quant(q, 0); 164 quant = i == 0 ? vp9_dc_quant(q, cm->y_dc_delta_q)
165 : vp9_ac_quant(q, 0);
165 invert_quant(&cpi->y_quant[q][i], &cpi->y_quant_shift[q][i], quant); 166 invert_quant(&cpi->y_quant[q][i], &cpi->y_quant_shift[q][i], quant);
166 cpi->y_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7); 167 cpi->y_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7);
167 cpi->y_round[q][i] = (qrounding_factor * quant) >> 7; 168 cpi->y_round[q][i] = (qrounding_factor * quant) >> 7;
168 cm->y_dequant[q][i] = quant; 169 cm->y_dequant[q][i] = quant;
169 }
170 170
171 // uv 171 // uv
172 for (i = 0; i < 2; ++i) { 172 quant = i == 0 ? vp9_dc_quant(q, cm->uv_dc_delta_q)
173 const int quant = i == 0 ? vp9_dc_quant(q, cm->uv_dc_delta_q) 173 : vp9_ac_quant(q, cm->uv_ac_delta_q);
174 : vp9_ac_quant(q, cm->uv_ac_delta_q);
175 invert_quant(&cpi->uv_quant[q][i], &cpi->uv_quant_shift[q][i], quant); 174 invert_quant(&cpi->uv_quant[q][i], &cpi->uv_quant_shift[q][i], quant);
176 cpi->uv_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7); 175 cpi->uv_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7);
177 cpi->uv_round[q][i] = (qrounding_factor * quant) >> 7; 176 cpi->uv_round[q][i] = (qrounding_factor * quant) >> 7;
178 cm->uv_dequant[q][i] = quant; 177 cm->uv_dequant[q][i] = quant;
179 }
180 178
181 #if CONFIG_ALPHA 179 #if CONFIG_ALPHA
182 // alpha 180 // alpha
183 for (i = 0; i < 2; ++i) { 181 quant = i == 0 ? vp9_dc_quant(q, cm->a_dc_delta_q)
184 const int quant = i == 0 ? vp9_dc_quant(q, cm->a_dc_delta_q) 182 : vp9_ac_quant(q, cm->a_ac_delta_q);
185 : vp9_ac_quant(q, cm->a_ac_delta_q);
186 invert_quant(&cpi->a_quant[q][i], &cpi->a_quant_shift[q][i], quant); 183 invert_quant(&cpi->a_quant[q][i], &cpi->a_quant_shift[q][i], quant);
187 cpi->a_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7); 184 cpi->a_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7);
188 cpi->a_round[q][i] = (qrounding_factor * quant) >> 7; 185 cpi->a_round[q][i] = (qrounding_factor * quant) >> 7;
189 cm->a_dequant[q][i] = quant; 186 cm->a_dequant[q][i] = quant;
187 #endif
190 } 188 }
191 #endif
192 189
193 for (i = 2; i < 8; i++) { 190 for (i = 2; i < 8; i++) {
194 cpi->y_quant[q][i] = cpi->y_quant[q][1]; 191 cpi->y_quant[q][i] = cpi->y_quant[q][1];
195 cpi->y_quant_shift[q][i] = cpi->y_quant_shift[q][1]; 192 cpi->y_quant_shift[q][i] = cpi->y_quant_shift[q][1];
196 cpi->y_zbin[q][i] = cpi->y_zbin[q][1]; 193 cpi->y_zbin[q][i] = cpi->y_zbin[q][1];
197 cpi->y_round[q][i] = cpi->y_round[q][1]; 194 cpi->y_round[q][i] = cpi->y_round[q][1];
198 cm->y_dequant[q][i] = cm->y_dequant[q][1]; 195 cm->y_dequant[q][i] = cm->y_dequant[q][1];
199 196
200 cpi->uv_quant[q][i] = cpi->uv_quant[q][1]; 197 cpi->uv_quant[q][i] = cpi->uv_quant[q][1];
201 cpi->uv_quant_shift[q][i] = cpi->uv_quant_shift[q][1]; 198 cpi->uv_quant_shift[q][i] = cpi->uv_quant_shift[q][1];
202 cpi->uv_zbin[q][i] = cpi->uv_zbin[q][1]; 199 cpi->uv_zbin[q][i] = cpi->uv_zbin[q][1];
203 cpi->uv_round[q][i] = cpi->uv_round[q][1]; 200 cpi->uv_round[q][i] = cpi->uv_round[q][1];
204 cm->uv_dequant[q][i] = cm->uv_dequant[q][1]; 201 cm->uv_dequant[q][i] = cm->uv_dequant[q][1];
205 202
206 #if CONFIG_ALPHA 203 #if CONFIG_ALPHA
207 cpi->a_quant[q][i] = cpi->a_quant[q][1]; 204 cpi->a_quant[q][i] = cpi->a_quant[q][1];
208 cpi->a_quant_shift[q][i] = cpi->a_quant_shift[q][1]; 205 cpi->a_quant_shift[q][i] = cpi->a_quant_shift[q][1];
209 cpi->a_zbin[q][i] = cpi->a_zbin[q][1]; 206 cpi->a_zbin[q][i] = cpi->a_zbin[q][1];
210 cpi->a_round[q][i] = cpi->a_round[q][1]; 207 cpi->a_round[q][i] = cpi->a_round[q][1];
211 cm->a_dequant[q][i] = cm->a_dequant[q][1]; 208 cm->a_dequant[q][i] = cm->a_dequant[q][1];
212 #endif 209 #endif
213 } 210 }
214 } 211 }
215 } 212 }
216 213
217 void vp9_mb_init_quantizer(VP9_COMP *cpi, MACROBLOCK *x) { 214 void vp9_init_plane_quantizers(VP9_COMP *cpi, MACROBLOCK *x) {
218 const VP9_COMMON *const cm = &cpi->common; 215 const VP9_COMMON *const cm = &cpi->common;
219 MACROBLOCKD *xd = &x->e_mbd; 216 MACROBLOCKD *xd = &x->e_mbd;
220 const int segment_id = xd->mi_8x8[0]->mbmi.segment_id; 217 const int segment_id = xd->mi_8x8[0]->mbmi.segment_id;
221 const int qindex = vp9_get_qindex(&cm->seg, segment_id, cm->base_qindex); 218 const int qindex = vp9_get_qindex(&cm->seg, segment_id, cm->base_qindex);
222 const int rdmult = vp9_compute_rd_mult(cpi, qindex + cm->y_dc_delta_q); 219 const int rdmult = vp9_compute_rd_mult(cpi, qindex + cm->y_dc_delta_q);
223 const int zbin = cpi->zbin_mode_boost + x->act_zbin_adj; 220 const int zbin = cpi->zbin_mode_boost + x->act_zbin_adj;
224 int i; 221 int i;
225 222
226 // Y 223 // Y
227 x->plane[0].quant = cpi->y_quant[qindex]; 224 x->plane[0].quant = cpi->y_quant[qindex];
(...skipping 11 matching lines...) Expand all
239 x->plane[i].round = cpi->uv_round[qindex]; 236 x->plane[i].round = cpi->uv_round[qindex];
240 x->plane[i].zbin_extra = (int16_t)((cm->uv_dequant[qindex][1] * zbin) >> 7); 237 x->plane[i].zbin_extra = (int16_t)((cm->uv_dequant[qindex][1] * zbin) >> 7);
241 xd->plane[i].dequant = cm->uv_dequant[qindex]; 238 xd->plane[i].dequant = cm->uv_dequant[qindex];
242 } 239 }
243 240
244 #if CONFIG_ALPHA 241 #if CONFIG_ALPHA
245 x->plane[3].quant = cpi->a_quant[qindex]; 242 x->plane[3].quant = cpi->a_quant[qindex];
246 x->plane[3].quant_shift = cpi->a_quant_shift[qindex]; 243 x->plane[3].quant_shift = cpi->a_quant_shift[qindex];
247 x->plane[3].zbin = cpi->a_zbin[qindex]; 244 x->plane[3].zbin = cpi->a_zbin[qindex];
248 x->plane[3].round = cpi->a_round[qindex]; 245 x->plane[3].round = cpi->a_round[qindex];
249 x->plane[3].zbin_extra = (int16_t)zbin_extra; 246 x->plane[3].zbin_extra = (int16_t)((cm->a_dequant[qindex][1] * zbin) >> 7);
250 xd->plane[3].dequant = cm->a_dequant[qindex]; 247 xd->plane[3].dequant = cm->a_dequant[qindex];
251 #endif 248 #endif
252 249
253 x->skip_block = vp9_segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP); 250 x->skip_block = vp9_segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP);
254 x->q_index = qindex; 251 x->q_index = qindex;
255 252
256 x->errorperbit = rdmult >> 6; 253 x->errorperbit = rdmult >> 6;
257 x->errorperbit += (x->errorperbit == 0); 254 x->errorperbit += (x->errorperbit == 0);
258 255
259 vp9_initialize_me_consts(cpi, x->q_index); 256 vp9_initialize_me_consts(cpi, x->q_index);
260 } 257 }
261 258
262 void vp9_update_zbin_extra(VP9_COMP *cpi, MACROBLOCK *x) { 259 void vp9_update_zbin_extra(VP9_COMP *cpi, MACROBLOCK *x) {
263 const int qindex = x->q_index; 260 const int qindex = x->q_index;
264 const int y_zbin_extra = (cpi->common.y_dequant[qindex][1] * 261 const int y_zbin_extra = (cpi->common.y_dequant[qindex][1] *
265 (cpi->zbin_mode_boost + x->act_zbin_adj)) >> 7; 262 (cpi->zbin_mode_boost + x->act_zbin_adj)) >> 7;
266 const int uv_zbin_extra = (cpi->common.uv_dequant[qindex][1] * 263 const int uv_zbin_extra = (cpi->common.uv_dequant[qindex][1] *
267 (cpi->zbin_mode_boost + x->act_zbin_adj)) >> 7; 264 (cpi->zbin_mode_boost + x->act_zbin_adj)) >> 7;
268 265
269 x->plane[0].zbin_extra = (int16_t)y_zbin_extra; 266 x->plane[0].zbin_extra = (int16_t)y_zbin_extra;
270 x->plane[1].zbin_extra = (int16_t)uv_zbin_extra; 267 x->plane[1].zbin_extra = (int16_t)uv_zbin_extra;
271 x->plane[2].zbin_extra = (int16_t)uv_zbin_extra; 268 x->plane[2].zbin_extra = (int16_t)uv_zbin_extra;
272 } 269 }
273 270
274 void vp9_frame_init_quantizer(VP9_COMP *cpi) { 271 void vp9_frame_init_quantizer(VP9_COMP *cpi) {
275 // Clear Zbin mode boost for default case
276 cpi->zbin_mode_boost = 0; 272 cpi->zbin_mode_boost = 0;
277 273 vp9_init_plane_quantizers(cpi, &cpi->mb);
278 // MB level quantizer setup
279 vp9_mb_init_quantizer(cpi, &cpi->mb);
280 } 274 }
281 275
282 void vp9_set_quantizer(struct VP9_COMP *cpi, int q) { 276 void vp9_set_quantizer(struct VP9_COMP *cpi, int q) {
283 VP9_COMMON *cm = &cpi->common; 277 VP9_COMMON *const cm = &cpi->common;
284 278
279 // quantizer has to be reinitialized with vp9_init_quantizer() if any
280 // delta_q changes.
285 cm->base_qindex = q; 281 cm->base_qindex = q;
286
287 // if any of the delta_q values are changing update flag will
288 // have to be set.
289 cm->y_dc_delta_q = 0; 282 cm->y_dc_delta_q = 0;
290 cm->uv_dc_delta_q = 0; 283 cm->uv_dc_delta_q = 0;
291 cm->uv_ac_delta_q = 0; 284 cm->uv_ac_delta_q = 0;
292
293 // quantizer has to be reinitialized if any delta_q changes.
294 // As there are not any here for now this is inactive code.
295 // if(update)
296 // vp9_init_quantizer(cpi);
297 } 285 }
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