OLD | NEW |
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_quantize.h" | 16 #include "vp9/encoder/vp9_quantize.h" |
16 #include "vp9/common/vp9_quant_common.h" | 17 #include "vp9/common/vp9_quant_common.h" |
17 | 18 |
18 #include "vp9/common/vp9_seg_common.h" | 19 #include "vp9/common/vp9_seg_common.h" |
19 | 20 |
20 #ifdef ENC_DEBUG | 21 #ifdef ENC_DEBUG |
21 extern int enc_debug; | 22 extern int enc_debug; |
22 #endif | 23 #endif |
23 | 24 |
24 void vp9_quantize_b_c(int16_t *coeff_ptr, intptr_t n_coeffs, int skip_block, | 25 void vp9_quantize_b_c(const int16_t *coeff_ptr, intptr_t n_coeffs, |
25 int16_t *zbin_ptr, int16_t *round_ptr, int16_t *quant_ptr, | 26 int skip_block, |
26 int16_t *quant_shift_ptr, int16_t *qcoeff_ptr, | 27 const int16_t *zbin_ptr, const int16_t *round_ptr, |
27 int16_t *dqcoeff_ptr, int16_t *dequant_ptr, | 28 const int16_t *quant_ptr, const int16_t *quant_shift_ptr, |
28 int zbin_oq_value, uint16_t *eob_ptr, const int16_t *scan, | 29 int16_t *qcoeff_ptr, int16_t *dqcoeff_ptr, |
29 const int16_t *iscan) { | 30 const int16_t *dequant_ptr, |
| 31 int zbin_oq_value, uint16_t *eob_ptr, |
| 32 const int16_t *scan, const int16_t *iscan) { |
30 int i, rc, eob; | 33 int i, rc, eob; |
31 int zbins[2], nzbins[2], zbin; | 34 int zbins[2], nzbins[2], zbin; |
32 int x, y, z, sz; | 35 int x, y, z, sz; |
33 int zero_flag = n_coeffs; | 36 int zero_flag = n_coeffs; |
34 | 37 |
35 vpx_memset(qcoeff_ptr, 0, n_coeffs*sizeof(int16_t)); | 38 vpx_memset(qcoeff_ptr, 0, n_coeffs*sizeof(int16_t)); |
36 vpx_memset(dqcoeff_ptr, 0, n_coeffs*sizeof(int16_t)); | 39 vpx_memset(dqcoeff_ptr, 0, n_coeffs*sizeof(int16_t)); |
37 | 40 |
38 eob = -1; | 41 eob = -1; |
39 | 42 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 81 |
79 if (y) { | 82 if (y) { |
80 eob = i; // last nonzero coeffs | 83 eob = i; // last nonzero coeffs |
81 } | 84 } |
82 } | 85 } |
83 } | 86 } |
84 } | 87 } |
85 *eob_ptr = eob + 1; | 88 *eob_ptr = eob + 1; |
86 } | 89 } |
87 | 90 |
88 void vp9_quantize_b_32x32_c(int16_t *coeff_ptr, intptr_t n_coeffs, | 91 void vp9_quantize_b_32x32_c(const int16_t *coeff_ptr, intptr_t n_coeffs, |
89 int skip_block, | 92 int skip_block, |
90 int16_t *zbin_ptr, int16_t *round_ptr, | 93 const int16_t *zbin_ptr, const int16_t *round_ptr, |
91 int16_t *quant_ptr, int16_t *quant_shift_ptr, | 94 const int16_t *quant_ptr, |
| 95 const int16_t *quant_shift_ptr, |
92 int16_t *qcoeff_ptr, int16_t *dqcoeff_ptr, | 96 int16_t *qcoeff_ptr, int16_t *dqcoeff_ptr, |
93 int16_t *dequant_ptr, int zbin_oq_value, | 97 const int16_t *dequant_ptr, |
94 uint16_t *eob_ptr, const int16_t *scan, | 98 int zbin_oq_value, uint16_t *eob_ptr, |
95 const int16_t *iscan) { | 99 const int16_t *scan, const int16_t *iscan) { |
96 int i, rc, eob; | 100 int i, rc, eob; |
97 int zbins[2], nzbins[2]; | 101 int zbins[2], nzbins[2]; |
98 int x, y, z, sz; | 102 int x, y, z, sz; |
99 int idx = 0; | 103 int idx = 0; |
100 int idx_arr[1024]; | 104 int idx_arr[1024]; |
101 | 105 |
102 vpx_memset(qcoeff_ptr, 0, n_coeffs*sizeof(int16_t)); | 106 vpx_memset(qcoeff_ptr, 0, n_coeffs*sizeof(int16_t)); |
103 vpx_memset(dqcoeff_ptr, 0, n_coeffs*sizeof(int16_t)); | 107 vpx_memset(dqcoeff_ptr, 0, n_coeffs*sizeof(int16_t)); |
104 | 108 |
105 eob = -1; | 109 eob = -1; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 res.plane = 1; | 170 res.plane = 1; |
167 res.block = b_idx - y_blocks; | 171 res.block = b_idx - y_blocks; |
168 } else { | 172 } else { |
169 assert(b_idx < y_blocks * 3 / 2); | 173 assert(b_idx < y_blocks * 3 / 2); |
170 res.plane = 2; | 174 res.plane = 2; |
171 res.block = b_idx - v_offset; | 175 res.block = b_idx - v_offset; |
172 } | 176 } |
173 return res; | 177 return res; |
174 } | 178 } |
175 | 179 |
176 void vp9_regular_quantize_b_4x4(MACROBLOCK *mb, int b_idx, TX_TYPE tx_type, | 180 void vp9_regular_quantize_b_4x4(MACROBLOCK *x, int y_blocks, int b_idx, |
177 int y_blocks) { | 181 const int16_t *scan, const int16_t *iscan) { |
178 MACROBLOCKD *const xd = &mb->e_mbd; | 182 MACROBLOCKD *const xd = &x->e_mbd; |
179 const struct plane_block_idx pb_idx = plane_block_idx(y_blocks, b_idx); | 183 const struct plane_block_idx pb_idx = plane_block_idx(y_blocks, b_idx); |
180 const int16_t *scan = get_scan_4x4(tx_type); | 184 struct macroblock_plane* p = &x->plane[pb_idx.plane]; |
181 const int16_t *iscan = get_iscan_4x4(tx_type); | 185 struct macroblockd_plane* pd = &xd->plane[pb_idx.plane]; |
182 | 186 |
183 vp9_quantize_b(BLOCK_OFFSET(mb->plane[pb_idx.plane].coeff, pb_idx.block), | 187 vp9_quantize_b(BLOCK_OFFSET(p->coeff, pb_idx.block), |
184 16, mb->skip_block, | 188 16, x->skip_block, |
185 mb->plane[pb_idx.plane].zbin, | 189 p->zbin, p->round, p->quant, p->quant_shift, |
186 mb->plane[pb_idx.plane].round, | 190 BLOCK_OFFSET(pd->qcoeff, pb_idx.block), |
187 mb->plane[pb_idx.plane].quant, | 191 BLOCK_OFFSET(pd->dqcoeff, pb_idx.block), |
188 mb->plane[pb_idx.plane].quant_shift, | 192 pd->dequant, p->zbin_extra, &pd->eobs[pb_idx.block], scan, iscan); |
189 BLOCK_OFFSET(xd->plane[pb_idx.plane].qcoeff, pb_idx.block), | |
190 BLOCK_OFFSET(xd->plane[pb_idx.plane].dqcoeff, pb_idx.block), | |
191 xd->plane[pb_idx.plane].dequant, | |
192 mb->plane[pb_idx.plane].zbin_extra, | |
193 &xd->plane[pb_idx.plane].eobs[pb_idx.block], | |
194 scan, iscan); | |
195 } | 193 } |
196 | 194 |
197 static void invert_quant(int16_t *quant, int16_t *shift, int d) { | 195 static void invert_quant(int16_t *quant, int16_t *shift, int d) { |
198 unsigned t; | 196 unsigned t; |
199 int l; | 197 int l; |
200 t = d; | 198 t = d; |
201 for (l = 0; t > 1; l++) | 199 for (l = 0; t > 1; l++) |
202 t >>= 1; | 200 t >>= 1; |
203 t = 1 + (1 << (16 + l)) / d; | 201 t = 1 + (1 << (16 + l)) / d; |
204 *quant = (int16_t)(t - (1 << 16)); | 202 *quant = (int16_t)(t - (1 << 16)); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 cpi->a_zbin[q][i] = cpi->a_zbin[q][1]; | 262 cpi->a_zbin[q][i] = cpi->a_zbin[q][1]; |
265 cpi->a_round[q][i] = cpi->a_round[q][1]; | 263 cpi->a_round[q][i] = cpi->a_round[q][1]; |
266 cm->a_dequant[q][i] = cm->a_dequant[q][1]; | 264 cm->a_dequant[q][i] = cm->a_dequant[q][1]; |
267 #endif | 265 #endif |
268 } | 266 } |
269 } | 267 } |
270 } | 268 } |
271 | 269 |
272 void vp9_mb_init_quantizer(VP9_COMP *cpi, MACROBLOCK *x) { | 270 void vp9_mb_init_quantizer(VP9_COMP *cpi, MACROBLOCK *x) { |
273 int i; | 271 int i; |
| 272 VP9_COMMON *const cm = &cpi->common; |
274 MACROBLOCKD *xd = &x->e_mbd; | 273 MACROBLOCKD *xd = &x->e_mbd; |
275 int zbin_extra; | 274 int zbin_extra; |
276 int segment_id = xd->this_mi->mbmi.segment_id; | 275 int segment_id = xd->mi_8x8[0]->mbmi.segment_id; |
277 const int qindex = vp9_get_qindex(&cpi->common.seg, segment_id, | 276 const int qindex = vp9_get_qindex(&cpi->common.seg, segment_id, |
278 cpi->common.base_qindex); | 277 cpi->common.base_qindex); |
279 | 278 |
| 279 int rdmult = vp9_compute_rd_mult(cpi, qindex + cm->y_dc_delta_q); |
| 280 |
280 // Y | 281 // Y |
281 zbin_extra = (cpi->common.y_dequant[qindex][1] * | 282 zbin_extra = (cpi->common.y_dequant[qindex][1] * |
282 (cpi->zbin_mode_boost + x->act_zbin_adj)) >> 7; | 283 (cpi->zbin_mode_boost + x->act_zbin_adj)) >> 7; |
283 | 284 |
284 x->plane[0].quant = cpi->y_quant[qindex]; | 285 x->plane[0].quant = cpi->y_quant[qindex]; |
285 x->plane[0].quant_shift = cpi->y_quant_shift[qindex]; | 286 x->plane[0].quant_shift = cpi->y_quant_shift[qindex]; |
286 x->plane[0].zbin = cpi->y_zbin[qindex]; | 287 x->plane[0].zbin = cpi->y_zbin[qindex]; |
287 x->plane[0].round = cpi->y_round[qindex]; | 288 x->plane[0].round = cpi->y_round[qindex]; |
288 x->plane[0].zbin_extra = (int16_t)zbin_extra; | 289 x->plane[0].zbin_extra = (int16_t)zbin_extra; |
289 x->e_mbd.plane[0].dequant = cpi->common.y_dequant[qindex]; | 290 x->e_mbd.plane[0].dequant = cpi->common.y_dequant[qindex]; |
(...skipping 18 matching lines...) Expand all Loading... |
308 x->plane[3].round = cpi->a_round[qindex]; | 309 x->plane[3].round = cpi->a_round[qindex]; |
309 x->plane[3].zbin_extra = (int16_t)zbin_extra; | 310 x->plane[3].zbin_extra = (int16_t)zbin_extra; |
310 x->e_mbd.plane[3].dequant = cpi->common.a_dequant[qindex]; | 311 x->e_mbd.plane[3].dequant = cpi->common.a_dequant[qindex]; |
311 #endif | 312 #endif |
312 | 313 |
313 x->skip_block = vp9_segfeature_active(&cpi->common.seg, segment_id, | 314 x->skip_block = vp9_segfeature_active(&cpi->common.seg, segment_id, |
314 SEG_LVL_SKIP); | 315 SEG_LVL_SKIP); |
315 | 316 |
316 /* save this macroblock QIndex for vp9_update_zbin_extra() */ | 317 /* save this macroblock QIndex for vp9_update_zbin_extra() */ |
317 x->e_mbd.q_index = qindex; | 318 x->e_mbd.q_index = qindex; |
| 319 |
| 320 /* R/D setup */ |
| 321 cpi->mb.errorperbit = rdmult >> 6; |
| 322 cpi->mb.errorperbit += (cpi->mb.errorperbit == 0); |
| 323 |
| 324 vp9_initialize_me_consts(cpi, xd->q_index); |
318 } | 325 } |
319 | 326 |
320 void vp9_update_zbin_extra(VP9_COMP *cpi, MACROBLOCK *x) { | 327 void vp9_update_zbin_extra(VP9_COMP *cpi, MACROBLOCK *x) { |
321 const int qindex = x->e_mbd.q_index; | 328 const int qindex = x->e_mbd.q_index; |
322 const int y_zbin_extra = (cpi->common.y_dequant[qindex][1] * | 329 const int y_zbin_extra = (cpi->common.y_dequant[qindex][1] * |
323 (cpi->zbin_mode_boost + x->act_zbin_adj)) >> 7; | 330 (cpi->zbin_mode_boost + x->act_zbin_adj)) >> 7; |
324 const int uv_zbin_extra = (cpi->common.uv_dequant[qindex][1] * | 331 const int uv_zbin_extra = (cpi->common.uv_dequant[qindex][1] * |
325 (cpi->zbin_mode_boost + x->act_zbin_adj)) >> 7; | 332 (cpi->zbin_mode_boost + x->act_zbin_adj)) >> 7; |
326 | 333 |
327 x->plane[0].zbin_extra = (int16_t)y_zbin_extra; | 334 x->plane[0].zbin_extra = (int16_t)y_zbin_extra; |
328 x->plane[1].zbin_extra = (int16_t)uv_zbin_extra; | 335 x->plane[1].zbin_extra = (int16_t)uv_zbin_extra; |
329 x->plane[2].zbin_extra = (int16_t)uv_zbin_extra; | 336 x->plane[2].zbin_extra = (int16_t)uv_zbin_extra; |
330 } | 337 } |
331 | 338 |
332 void vp9_frame_init_quantizer(VP9_COMP *cpi) { | 339 void vp9_frame_init_quantizer(VP9_COMP *cpi) { |
333 // Clear Zbin mode boost for default case | 340 // Clear Zbin mode boost for default case |
334 cpi->zbin_mode_boost = 0; | 341 cpi->zbin_mode_boost = 0; |
335 | 342 |
336 // MB level quantizer setup | 343 // MB level quantizer setup |
337 vp9_mb_init_quantizer(cpi, &cpi->mb); | 344 vp9_mb_init_quantizer(cpi, &cpi->mb); |
338 } | 345 } |
339 | 346 |
340 void vp9_set_quantizer(struct VP9_COMP *cpi, int Q) { | 347 void vp9_set_quantizer(struct VP9_COMP *cpi, int q) { |
341 VP9_COMMON *cm = &cpi->common; | 348 VP9_COMMON *cm = &cpi->common; |
342 | 349 |
343 cm->base_qindex = Q; | 350 cm->base_qindex = q; |
344 | 351 |
345 // if any of the delta_q values are changing update flag will | 352 // if any of the delta_q values are changing update flag will |
346 // have to be set. | 353 // have to be set. |
347 cm->y_dc_delta_q = 0; | 354 cm->y_dc_delta_q = 0; |
348 cm->uv_dc_delta_q = 0; | 355 cm->uv_dc_delta_q = 0; |
349 cm->uv_ac_delta_q = 0; | 356 cm->uv_ac_delta_q = 0; |
350 | 357 |
351 // quantizer has to be reinitialized if any delta_q changes. | 358 // quantizer has to be reinitialized if any delta_q changes. |
352 // As there are not any here for now this is inactive code. | 359 // As there are not any here for now this is inactive code. |
353 // if(update) | 360 // if(update) |
354 // vp9_init_quantizer(cpi); | 361 // vp9_init_quantizer(cpi); |
355 } | 362 } |
OLD | NEW |