2 * Copyright (c) 2010 The WebM 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 "vp8/common/quant_common.h"
21 #ifdef EXACT_FASTQUANT
22 void vp8_fast_quantize_b_c(BLOCK *b, BLOCKD *d)
27 short *coeff_ptr = b->coeff;
28 short *zbin_ptr = b->zbin;
29 short *round_ptr = b->round;
30 short *quant_ptr = b->quant_fast;
31 unsigned char *quant_shift_ptr = b->quant_shift;
32 short *qcoeff_ptr = d->qcoeff;
33 short *dqcoeff_ptr = d->dqcoeff;
34 short *dequant_ptr = d->dequant;
36 vpx_memset(qcoeff_ptr, 0, 32);
37 vpx_memset(dqcoeff_ptr, 0, 32);
41 for (i = 0; i < 16; i++)
43 rc = vp8_default_zig_zag1d[i];
47 sz = (z >> 31); // sign of z
48 x = (z ^ sz) - sz; // x = abs(z)
53 y = (((x * quant_ptr[rc]) >> 16) + x)
54 >> quant_shift_ptr[rc]; // quantize (x)
55 x = (y ^ sz) - sz; // get the sign back
56 qcoeff_ptr[rc] = x; // write to destination
57 dqcoeff_ptr[rc] = x * dequant_ptr[rc]; // dequantized value
61 eob = i; // last nonzero coeffs
65 *d->eob = (char)(eob + 1);
70 void vp8_fast_quantize_b_c(BLOCK *b, BLOCKD *d)
74 short *coeff_ptr = b->coeff;
75 short *round_ptr = b->round;
76 short *quant_ptr = b->quant_fast;
77 short *qcoeff_ptr = d->qcoeff;
78 short *dqcoeff_ptr = d->dqcoeff;
79 short *dequant_ptr = d->dequant;
82 for (i = 0; i < 16; i++)
84 rc = vp8_default_zig_zag1d[i];
87 sz = (z >> 31); // sign of z
88 x = (z ^ sz) - sz; // x = abs(z)
90 y = ((x + round_ptr[rc]) * quant_ptr[rc]) >> 16; // quantize (x)
91 x = (y ^ sz) - sz; // get the sign back
92 qcoeff_ptr[rc] = x; // write to destination
93 dqcoeff_ptr[rc] = x * dequant_ptr[rc]; // dequantized value
97 eob = i; // last nonzero coeffs
100 *d->eob = (char)(eob + 1);
106 void vp8_regular_quantize_b(BLOCK *b, BLOCKD *d)
111 short *zbin_boost_ptr = b->zrun_zbin_boost;
112 short *coeff_ptr = b->coeff;
113 short *zbin_ptr = b->zbin;
114 short *round_ptr = b->round;
115 short *quant_ptr = b->quant;
116 unsigned char *quant_shift_ptr = b->quant_shift;
117 short *qcoeff_ptr = d->qcoeff;
118 short *dqcoeff_ptr = d->dqcoeff;
119 short *dequant_ptr = d->dequant;
120 short zbin_oq_value = b->zbin_extra;
122 vpx_memset(qcoeff_ptr, 0, 32);
123 vpx_memset(dqcoeff_ptr, 0, 32);
127 for (i = 0; i < 16; i++)
129 rc = vp8_default_zig_zag1d[i];
132 zbin = zbin_ptr[rc] + *zbin_boost_ptr + zbin_oq_value;
135 sz = (z >> 31); // sign of z
136 x = (z ^ sz) - sz; // x = abs(z)
141 y = (((x * quant_ptr[rc]) >> 16) + x)
142 >> quant_shift_ptr[rc]; // quantize (x)
143 x = (y ^ sz) - sz; // get the sign back
144 qcoeff_ptr[rc] = x; // write to destination
145 dqcoeff_ptr[rc] = x * dequant_ptr[rc]; // dequantized value
149 eob = i; // last nonzero coeffs
150 zbin_boost_ptr = b->zrun_zbin_boost; // reset zero runlength
155 *d->eob = (char)(eob + 1);
158 /* Perform regular quantization, with unbiased rounding and no zero bin. */
159 void vp8_strict_quantize_b(BLOCK *b, BLOCKD *d)
170 unsigned char *quant_shift_ptr;
175 coeff_ptr = b->coeff;
176 quant_ptr = b->quant;
177 quant_shift_ptr = b->quant_shift;
178 qcoeff_ptr = d->qcoeff;
179 dqcoeff_ptr = d->dqcoeff;
180 dequant_ptr = d->dequant;
182 vpx_memset(qcoeff_ptr, 0, 32);
183 vpx_memset(dqcoeff_ptr, 0, 32);
184 for (i = 0; i < 16; i++)
189 /*TODO: These arrays should be stored in zig-zag order.*/
190 rc = vp8_default_zig_zag1d[i];
192 dq = dequant_ptr[rc];
201 y = (((x * quant_ptr[rc]) >> 16) + x) >> quant_shift_ptr[rc];
202 /* Put the sign back. */
204 /* Save the coefficient and its dequantized value. */
206 dqcoeff_ptr[rc] = x * dq;
207 /* Remember the last non-zero coefficient. */
213 *d->eob = (char)(eob + 1);
218 void vp8_regular_quantize_b(BLOCK *b, BLOCKD *d)
223 short *zbin_boost_ptr = b->zrun_zbin_boost;
224 short *coeff_ptr = b->coeff;
225 short *zbin_ptr = b->zbin;
226 short *round_ptr = b->round;
227 short *quant_ptr = b->quant;
228 short *qcoeff_ptr = d->qcoeff;
229 short *dqcoeff_ptr = d->dqcoeff;
230 short *dequant_ptr = d->dequant;
231 short zbin_oq_value = b->zbin_extra;
233 vpx_memset(qcoeff_ptr, 0, 32);
234 vpx_memset(dqcoeff_ptr, 0, 32);
238 for (i = 0; i < 16; i++)
240 rc = vp8_default_zig_zag1d[i];
244 // zbin = zbin_ptr[rc] + *zbin_boost_ptr + zbin_oq_value/2;
246 zbin = zbin_ptr[rc] + *zbin_boost_ptr + zbin_oq_value;
249 sz = (z >> 31); // sign of z
250 x = (z ^ sz) - sz; // x = abs(z)
254 y = ((x + round_ptr[rc]) * quant_ptr[rc]) >> 16; // quantize (x)
255 x = (y ^ sz) - sz; // get the sign back
256 qcoeff_ptr[rc] = x; // write to destination
257 dqcoeff_ptr[rc] = x * dequant_ptr[rc]; // dequantized value
261 eob = i; // last nonzero coeffs
262 zbin_boost_ptr = &b->zrun_zbin_boost[0]; // reset zero runlength
267 *d->eob = (char)(eob + 1);
272 void vp8_quantize_mby_c(MACROBLOCK *x)
275 int has_2nd_order = (x->e_mbd.mode_info_context->mbmi.mode != B_PRED
276 && x->e_mbd.mode_info_context->mbmi.mode != SPLITMV);
278 for (i = 0; i < 16; i++)
279 x->quantize_b(&x->block[i], &x->e_mbd.block[i]);
282 x->quantize_b(&x->block[24], &x->e_mbd.block[24]);
285 void vp8_quantize_mb_c(MACROBLOCK *x)
288 int has_2nd_order=(x->e_mbd.mode_info_context->mbmi.mode != B_PRED
289 && x->e_mbd.mode_info_context->mbmi.mode != SPLITMV);
291 for (i = 0; i < 24+has_2nd_order; i++)
292 x->quantize_b(&x->block[i], &x->e_mbd.block[i]);
296 void vp8_quantize_mbuv_c(MACROBLOCK *x)
300 for (i = 16; i < 24; i++)
301 x->quantize_b(&x->block[i], &x->e_mbd.block[i]);
304 /* quantize_b_pair function pointer in MACROBLOCK structure is set to one of
305 * these two C functions if corresponding optimized routine is not available.
306 * NEON optimized version implements currently the fast quantization for pair
308 void vp8_regular_quantize_b_pair(BLOCK *b1, BLOCK *b2, BLOCKD *d1, BLOCKD *d2)
310 vp8_regular_quantize_b(b1, d1);
311 vp8_regular_quantize_b(b2, d2);
314 void vp8_fast_quantize_b_pair_c(BLOCK *b1, BLOCK *b2, BLOCKD *d1, BLOCKD *d2)
316 vp8_fast_quantize_b_c(b1, d1);
317 vp8_fast_quantize_b_c(b2, d2);
321 static const int qrounding_factors[129] =
323 48, 48, 48, 48, 48, 48, 48, 48,
324 48, 48, 48, 48, 48, 48, 48, 48,
325 48, 48, 48, 48, 48, 48, 48, 48,
326 48, 48, 48, 48, 48, 48, 48, 48,
327 48, 48, 48, 48, 48, 48, 48, 48,
328 48, 48, 48, 48, 48, 48, 48, 48,
329 48, 48, 48, 48, 48, 48, 48, 48,
330 48, 48, 48, 48, 48, 48, 48, 48,
331 48, 48, 48, 48, 48, 48, 48, 48,
332 48, 48, 48, 48, 48, 48, 48, 48,
333 48, 48, 48, 48, 48, 48, 48, 48,
334 48, 48, 48, 48, 48, 48, 48, 48,
335 48, 48, 48, 48, 48, 48, 48, 48,
336 48, 48, 48, 48, 48, 48, 48, 48,
337 48, 48, 48, 48, 48, 48, 48, 48,
338 48, 48, 48, 48, 48, 48, 48, 48,
343 static const int qzbin_factors[129] =
345 84, 84, 84, 84, 84, 84, 84, 84,
346 84, 84, 84, 84, 84, 84, 84, 84,
347 84, 84, 84, 84, 84, 84, 84, 84,
348 84, 84, 84, 84, 84, 84, 84, 84,
349 84, 84, 84, 84, 84, 84, 84, 84,
350 84, 84, 84, 84, 84, 84, 84, 84,
351 80, 80, 80, 80, 80, 80, 80, 80,
352 80, 80, 80, 80, 80, 80, 80, 80,
353 80, 80, 80, 80, 80, 80, 80, 80,
354 80, 80, 80, 80, 80, 80, 80, 80,
355 80, 80, 80, 80, 80, 80, 80, 80,
356 80, 80, 80, 80, 80, 80, 80, 80,
357 80, 80, 80, 80, 80, 80, 80, 80,
358 80, 80, 80, 80, 80, 80, 80, 80,
359 80, 80, 80, 80, 80, 80, 80, 80,
360 80, 80, 80, 80, 80, 80, 80, 80,
365 static const int qrounding_factors_y2[129] =
367 48, 48, 48, 48, 48, 48, 48, 48,
368 48, 48, 48, 48, 48, 48, 48, 48,
369 48, 48, 48, 48, 48, 48, 48, 48,
370 48, 48, 48, 48, 48, 48, 48, 48,
371 48, 48, 48, 48, 48, 48, 48, 48,
372 48, 48, 48, 48, 48, 48, 48, 48,
373 48, 48, 48, 48, 48, 48, 48, 48,
374 48, 48, 48, 48, 48, 48, 48, 48,
375 48, 48, 48, 48, 48, 48, 48, 48,
376 48, 48, 48, 48, 48, 48, 48, 48,
377 48, 48, 48, 48, 48, 48, 48, 48,
378 48, 48, 48, 48, 48, 48, 48, 48,
379 48, 48, 48, 48, 48, 48, 48, 48,
380 48, 48, 48, 48, 48, 48, 48, 48,
381 48, 48, 48, 48, 48, 48, 48, 48,
382 48, 48, 48, 48, 48, 48, 48, 48,
387 static const int qzbin_factors_y2[129] =
389 84, 84, 84, 84, 84, 84, 84, 84,
390 84, 84, 84, 84, 84, 84, 84, 84,
391 84, 84, 84, 84, 84, 84, 84, 84,
392 84, 84, 84, 84, 84, 84, 84, 84,
393 84, 84, 84, 84, 84, 84, 84, 84,
394 84, 84, 84, 84, 84, 84, 84, 84,
395 80, 80, 80, 80, 80, 80, 80, 80,
396 80, 80, 80, 80, 80, 80, 80, 80,
397 80, 80, 80, 80, 80, 80, 80, 80,
398 80, 80, 80, 80, 80, 80, 80, 80,
399 80, 80, 80, 80, 80, 80, 80, 80,
400 80, 80, 80, 80, 80, 80, 80, 80,
401 80, 80, 80, 80, 80, 80, 80, 80,
402 80, 80, 80, 80, 80, 80, 80, 80,
403 80, 80, 80, 80, 80, 80, 80, 80,
404 80, 80, 80, 80, 80, 80, 80, 80,
411 static void invert_quant(int improved_quant, short *quant,
412 unsigned char *shift, short d)
419 for(l = 0; t > 1; l++)
421 t = 1 + (1<<(16+l))/d;
422 *quant = (short)(t - (1<<16));
427 *quant = (1 << 16) / d;
433 void vp8cx_init_quantizer(VP8_COMP *cpi)
439 int zbin_boost[16] = {0, 0, 8, 10, 12, 14, 16, 20, 24, 28, 32, 36, 40, 44, 44, 44};
441 for (Q = 0; Q < QINDEX_RANGE; Q++)
444 quant_val = vp8_dc_quant(Q, cpi->common.y1dc_delta_q);
445 cpi->Y1quant_fast[Q][0] = (1 << 16) / quant_val;
446 invert_quant(cpi->sf.improved_quant, cpi->Y1quant[Q] + 0,
447 cpi->Y1quant_shift[Q] + 0, quant_val);
448 cpi->Y1zbin[Q][0] = ((qzbin_factors[Q] * quant_val) + 64) >> 7;
449 cpi->Y1round[Q][0] = (qrounding_factors[Q] * quant_val) >> 7;
450 cpi->common.Y1dequant[Q][0] = quant_val;
451 cpi->zrun_zbin_boost_y1[Q][0] = (quant_val * zbin_boost[0]) >> 7;
453 quant_val = vp8_dc2quant(Q, cpi->common.y2dc_delta_q);
454 cpi->Y2quant_fast[Q][0] = (1 << 16) / quant_val;
455 invert_quant(cpi->sf.improved_quant, cpi->Y2quant[Q] + 0,
456 cpi->Y2quant_shift[Q] + 0, quant_val);
457 cpi->Y2zbin[Q][0] = ((qzbin_factors_y2[Q] * quant_val) + 64) >> 7;
458 cpi->Y2round[Q][0] = (qrounding_factors_y2[Q] * quant_val) >> 7;
459 cpi->common.Y2dequant[Q][0] = quant_val;
460 cpi->zrun_zbin_boost_y2[Q][0] = (quant_val * zbin_boost[0]) >> 7;
462 quant_val = vp8_dc_uv_quant(Q, cpi->common.uvdc_delta_q);
463 cpi->UVquant_fast[Q][0] = (1 << 16) / quant_val;
464 invert_quant(cpi->sf.improved_quant, cpi->UVquant[Q] + 0,
465 cpi->UVquant_shift[Q] + 0, quant_val);
466 cpi->UVzbin[Q][0] = ((qzbin_factors[Q] * quant_val) + 64) >> 7;;
467 cpi->UVround[Q][0] = (qrounding_factors[Q] * quant_val) >> 7;
468 cpi->common.UVdequant[Q][0] = quant_val;
469 cpi->zrun_zbin_boost_uv[Q][0] = (quant_val * zbin_boost[0]) >> 7;
471 // all the ac values = ;
472 for (i = 1; i < 16; i++)
474 int rc = vp8_default_zig_zag1d[i];
476 quant_val = vp8_ac_yquant(Q);
477 cpi->Y1quant_fast[Q][rc] = (1 << 16) / quant_val;
478 invert_quant(cpi->sf.improved_quant, cpi->Y1quant[Q] + rc,
479 cpi->Y1quant_shift[Q] + rc, quant_val);
480 cpi->Y1zbin[Q][rc] = ((qzbin_factors[Q] * quant_val) + 64) >> 7;
481 cpi->Y1round[Q][rc] = (qrounding_factors[Q] * quant_val) >> 7;
482 cpi->common.Y1dequant[Q][rc] = quant_val;
483 cpi->zrun_zbin_boost_y1[Q][i] = (quant_val * zbin_boost[i]) >> 7;
485 quant_val = vp8_ac2quant(Q, cpi->common.y2ac_delta_q);
486 cpi->Y2quant_fast[Q][rc] = (1 << 16) / quant_val;
487 invert_quant(cpi->sf.improved_quant, cpi->Y2quant[Q] + rc,
488 cpi->Y2quant_shift[Q] + rc, quant_val);
489 cpi->Y2zbin[Q][rc] = ((qzbin_factors_y2[Q] * quant_val) + 64) >> 7;
490 cpi->Y2round[Q][rc] = (qrounding_factors_y2[Q] * quant_val) >> 7;
491 cpi->common.Y2dequant[Q][rc] = quant_val;
492 cpi->zrun_zbin_boost_y2[Q][i] = (quant_val * zbin_boost[i]) >> 7;
494 quant_val = vp8_ac_uv_quant(Q, cpi->common.uvac_delta_q);
495 cpi->UVquant_fast[Q][rc] = (1 << 16) / quant_val;
496 invert_quant(cpi->sf.improved_quant, cpi->UVquant[Q] + rc,
497 cpi->UVquant_shift[Q] + rc, quant_val);
498 cpi->UVzbin[Q][rc] = ((qzbin_factors[Q] * quant_val) + 64) >> 7;
499 cpi->UVround[Q][rc] = (qrounding_factors[Q] * quant_val) >> 7;
500 cpi->common.UVdequant[Q][rc] = quant_val;
501 cpi->zrun_zbin_boost_uv[Q][i] = (quant_val * zbin_boost[i]) >> 7;
506 void vp8cx_init_quantizer(VP8_COMP *cpi)
512 int zbin_boost[16] = {0, 0, 8, 10, 12, 14, 16, 20, 24, 28, 32, 36, 40, 44, 44, 44};
514 for (Q = 0; Q < QINDEX_RANGE; Q++)
517 quant_val = vp8_dc_quant(Q, cpi->common.y1dc_delta_q);
518 cpi->Y1quant[Q][0] = (1 << 16) / quant_val;
519 cpi->Y1zbin[Q][0] = ((qzbin_factors[Q] * quant_val) + 64) >> 7;
520 cpi->Y1round[Q][0] = (qrounding_factors[Q] * quant_val) >> 7;
521 cpi->common.Y1dequant[Q][0] = quant_val;
522 cpi->zrun_zbin_boost_y1[Q][0] = (quant_val * zbin_boost[0]) >> 7;
524 quant_val = vp8_dc2quant(Q, cpi->common.y2dc_delta_q);
525 cpi->Y2quant[Q][0] = (1 << 16) / quant_val;
526 cpi->Y2zbin[Q][0] = ((qzbin_factors_y2[Q] * quant_val) + 64) >> 7;
527 cpi->Y2round[Q][0] = (qrounding_factors_y2[Q] * quant_val) >> 7;
528 cpi->common.Y2dequant[Q][0] = quant_val;
529 cpi->zrun_zbin_boost_y2[Q][0] = (quant_val * zbin_boost[0]) >> 7;
531 quant_val = vp8_dc_uv_quant(Q, cpi->common.uvdc_delta_q);
532 cpi->UVquant[Q][0] = (1 << 16) / quant_val;
533 cpi->UVzbin[Q][0] = ((qzbin_factors[Q] * quant_val) + 64) >> 7;;
534 cpi->UVround[Q][0] = (qrounding_factors[Q] * quant_val) >> 7;
535 cpi->common.UVdequant[Q][0] = quant_val;
536 cpi->zrun_zbin_boost_uv[Q][0] = (quant_val * zbin_boost[0]) >> 7;
538 // all the ac values = ;
539 for (i = 1; i < 16; i++)
541 int rc = vp8_default_zig_zag1d[i];
543 quant_val = vp8_ac_yquant(Q);
544 cpi->Y1quant[Q][rc] = (1 << 16) / quant_val;
545 cpi->Y1zbin[Q][rc] = ((qzbin_factors[Q] * quant_val) + 64) >> 7;
546 cpi->Y1round[Q][rc] = (qrounding_factors[Q] * quant_val) >> 7;
547 cpi->common.Y1dequant[Q][rc] = quant_val;
548 cpi->zrun_zbin_boost_y1[Q][i] = (quant_val * zbin_boost[i]) >> 7;
550 quant_val = vp8_ac2quant(Q, cpi->common.y2ac_delta_q);
551 cpi->Y2quant[Q][rc] = (1 << 16) / quant_val;
552 cpi->Y2zbin[Q][rc] = ((qzbin_factors_y2[Q] * quant_val) + 64) >> 7;
553 cpi->Y2round[Q][rc] = (qrounding_factors_y2[Q] * quant_val) >> 7;
554 cpi->common.Y2dequant[Q][rc] = quant_val;
555 cpi->zrun_zbin_boost_y2[Q][i] = (quant_val * zbin_boost[i]) >> 7;
557 quant_val = vp8_ac_uv_quant(Q, cpi->common.uvac_delta_q);
558 cpi->UVquant[Q][rc] = (1 << 16) / quant_val;
559 cpi->UVzbin[Q][rc] = ((qzbin_factors[Q] * quant_val) + 64) >> 7;
560 cpi->UVround[Q][rc] = (qrounding_factors[Q] * quant_val) >> 7;
561 cpi->common.UVdequant[Q][rc] = quant_val;
562 cpi->zrun_zbin_boost_uv[Q][i] = (quant_val * zbin_boost[i]) >> 7;
568 #define ZBIN_EXTRA_Y \
569 (( cpi->common.Y1dequant[QIndex][1] * \
570 ( cpi->zbin_over_quant + \
571 cpi->zbin_mode_boost + \
572 x->act_zbin_adj ) ) >> 7)
574 #define ZBIN_EXTRA_UV \
575 (( cpi->common.UVdequant[QIndex][1] * \
576 ( cpi->zbin_over_quant + \
577 cpi->zbin_mode_boost + \
578 x->act_zbin_adj ) ) >> 7)
580 #define ZBIN_EXTRA_Y2 \
581 (( cpi->common.Y2dequant[QIndex][1] * \
582 ( (cpi->zbin_over_quant / 2) + \
583 cpi->zbin_mode_boost + \
584 x->act_zbin_adj ) ) >> 7)
586 void vp8cx_mb_init_quantizer(VP8_COMP *cpi, MACROBLOCK *x)
590 MACROBLOCKD *xd = &x->e_mbd;
593 // Select the baseline MB Q index.
594 if (xd->segmentation_enabled)
597 if (xd->mb_segement_abs_delta == SEGMENT_ABSDATA)
599 QIndex = xd->segment_feature_data[MB_LVL_ALT_Q][xd->mode_info_context->mbmi.segment_id];
603 QIndex = cpi->common.base_qindex + xd->segment_feature_data[MB_LVL_ALT_Q][xd->mode_info_context->mbmi.segment_id];
604 QIndex = (QIndex >= 0) ? ((QIndex <= MAXQ) ? QIndex : MAXQ) : 0; // Clamp to valid range
608 QIndex = cpi->common.base_qindex;
610 if (QIndex != x->q_index)
613 zbin_extra = ZBIN_EXTRA_Y;
615 for (i = 0; i < 16; i++)
617 x->block[i].quant = cpi->Y1quant[QIndex];
618 x->block[i].quant_fast = cpi->Y1quant_fast[QIndex];
619 x->block[i].quant_shift = cpi->Y1quant_shift[QIndex];
620 x->block[i].zbin = cpi->Y1zbin[QIndex];
621 x->block[i].round = cpi->Y1round[QIndex];
622 x->e_mbd.block[i].dequant = cpi->common.Y1dequant[QIndex];
623 x->block[i].zrun_zbin_boost = cpi->zrun_zbin_boost_y1[QIndex];
624 x->block[i].zbin_extra = (short)zbin_extra;
628 zbin_extra = ZBIN_EXTRA_UV;
630 for (i = 16; i < 24; i++)
632 x->block[i].quant = cpi->UVquant[QIndex];
633 x->block[i].quant_fast = cpi->UVquant_fast[QIndex];
634 x->block[i].quant_shift = cpi->UVquant_shift[QIndex];
635 x->block[i].zbin = cpi->UVzbin[QIndex];
636 x->block[i].round = cpi->UVround[QIndex];
637 x->e_mbd.block[i].dequant = cpi->common.UVdequant[QIndex];
638 x->block[i].zrun_zbin_boost = cpi->zrun_zbin_boost_uv[QIndex];
639 x->block[i].zbin_extra = (short)zbin_extra;
643 zbin_extra = ZBIN_EXTRA_Y2;
645 x->block[24].quant_fast = cpi->Y2quant_fast[QIndex];
646 x->block[24].quant = cpi->Y2quant[QIndex];
647 x->block[24].quant_shift = cpi->Y2quant_shift[QIndex];
648 x->block[24].zbin = cpi->Y2zbin[QIndex];
649 x->block[24].round = cpi->Y2round[QIndex];
650 x->e_mbd.block[24].dequant = cpi->common.Y2dequant[QIndex];
651 x->block[24].zrun_zbin_boost = cpi->zrun_zbin_boost_y2[QIndex];
652 x->block[24].zbin_extra = (short)zbin_extra;
654 /* save this macroblock QIndex for vp8_update_zbin_extra() */
657 cpi->last_zbin_over_quant = cpi->zbin_over_quant;
658 cpi->last_zbin_mode_boost = cpi->zbin_mode_boost;
659 x->last_act_zbin_adj = x->act_zbin_adj;
661 else if(cpi->last_zbin_over_quant != cpi->zbin_over_quant
662 || cpi->last_zbin_mode_boost != cpi->zbin_mode_boost
663 || x->last_act_zbin_adj != x->act_zbin_adj)
666 zbin_extra = ZBIN_EXTRA_Y;
668 for (i = 0; i < 16; i++)
669 x->block[i].zbin_extra = (short)zbin_extra;
672 zbin_extra = ZBIN_EXTRA_UV;
674 for (i = 16; i < 24; i++)
675 x->block[i].zbin_extra = (short)zbin_extra;
678 zbin_extra = ZBIN_EXTRA_Y2;
679 x->block[24].zbin_extra = (short)zbin_extra;
681 cpi->last_zbin_over_quant = cpi->zbin_over_quant;
682 cpi->last_zbin_mode_boost = cpi->zbin_mode_boost;
683 x->last_act_zbin_adj = x->act_zbin_adj;
687 void vp8_update_zbin_extra(VP8_COMP *cpi, MACROBLOCK *x)
690 int QIndex = x->q_index;
694 zbin_extra = ZBIN_EXTRA_Y;
696 for (i = 0; i < 16; i++)
697 x->block[i].zbin_extra = (short)zbin_extra;
700 zbin_extra = ZBIN_EXTRA_UV;
702 for (i = 16; i < 24; i++)
703 x->block[i].zbin_extra = (short)zbin_extra;
706 zbin_extra = ZBIN_EXTRA_Y2;
707 x->block[24].zbin_extra = (short)zbin_extra;
713 void vp8cx_frame_init_quantizer(VP8_COMP *cpi)
715 // Clear Zbin mode boost for default case
716 cpi->zbin_mode_boost = 0;
718 // MB level quantizer setup
719 vp8cx_mb_init_quantizer(cpi, &cpi->mb);
723 void vp8_set_quantizer(struct VP8_COMP *cpi, int Q)
725 VP8_COMMON *cm = &cpi->common;
726 MACROBLOCKD *mbd = &cpi->mb.e_mbd;
731 /* if any of the delta_q values are changing update flag has to be set */
732 /* currently only y2dc_delta_q may change */
734 cm->y1dc_delta_q = 0;
735 cm->y2ac_delta_q = 0;
736 cm->uvdc_delta_q = 0;
737 cm->uvac_delta_q = 0;
746 update |= cm->y2dc_delta_q != new_delta_q;
747 cm->y2dc_delta_q = new_delta_q;
750 // Set Segment specific quatizers
751 mbd->segment_feature_data[MB_LVL_ALT_Q][0] = cpi->segment_feature_data[MB_LVL_ALT_Q][0];
752 mbd->segment_feature_data[MB_LVL_ALT_Q][1] = cpi->segment_feature_data[MB_LVL_ALT_Q][1];
753 mbd->segment_feature_data[MB_LVL_ALT_Q][2] = cpi->segment_feature_data[MB_LVL_ALT_Q][2];
754 mbd->segment_feature_data[MB_LVL_ALT_Q][3] = cpi->segment_feature_data[MB_LVL_ALT_Q][3];
756 /* quantizer has to be reinitialized for any delta_q changes */
758 vp8cx_init_quantizer(cpi);