| 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 | 11 |
| 12 #include <math.h> | 12 #include <math.h> |
| 13 #include "vpx_mem/vpx_mem.h" | 13 #include "vpx_mem/vpx_mem.h" |
| 14 | 14 |
| 15 #include "onyx_int.h" |
| 15 #include "quantize.h" | 16 #include "quantize.h" |
| 16 #include "vp8/common/entropy.h" | 17 #include "vp8/common/quant_common.h" |
| 17 | 18 |
| 18 #define EXACT_QUANT | 19 #define EXACT_QUANT |
| 19 | 20 |
| 20 #ifdef EXACT_FASTQUANT | 21 #ifdef EXACT_FASTQUANT |
| 21 void vp8_fast_quantize_b_c(BLOCK *b, BLOCKD *d) | 22 void vp8_fast_quantize_b_c(BLOCK *b, BLOCKD *d) |
| 22 { | 23 { |
| 23 int i, rc, eob; | 24 int i, rc, eob; |
| 24 int zbin; | 25 int zbin; |
| 25 int x, y, z, sz; | 26 int x, y, z, sz; |
| 26 short *coeff_ptr = b->coeff; | 27 short *coeff_ptr = b->coeff; |
| 27 short *zbin_ptr = b->zbin; | 28 short *zbin_ptr = b->zbin; |
| 28 short *round_ptr = b->round; | 29 short *round_ptr = b->round; |
| 29 short *quant_ptr = b->quant_fast; | 30 short *quant_ptr = b->quant_fast; |
| 30 short *quant_shift_ptr = b->quant_shift; | 31 unsigned char *quant_shift_ptr = b->quant_shift; |
| 31 short *qcoeff_ptr = d->qcoeff; | 32 short *qcoeff_ptr = d->qcoeff; |
| 32 short *dqcoeff_ptr = d->dqcoeff; | 33 short *dqcoeff_ptr = d->dqcoeff; |
| 33 short *dequant_ptr = d->dequant; | 34 short *dequant_ptr = d->dequant; |
| 34 | 35 |
| 35 vpx_memset(qcoeff_ptr, 0, 32); | 36 vpx_memset(qcoeff_ptr, 0, 32); |
| 36 vpx_memset(dqcoeff_ptr, 0, 32); | 37 vpx_memset(dqcoeff_ptr, 0, 32); |
| 37 | 38 |
| 38 eob = -1; | 39 eob = -1; |
| 39 | 40 |
| 40 for (i = 0; i < 16; i++) | 41 for (i = 0; i < 16; i++) |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 void vp8_regular_quantize_b(BLOCK *b, BLOCKD *d) | 106 void vp8_regular_quantize_b(BLOCK *b, BLOCKD *d) |
| 106 { | 107 { |
| 107 int i, rc, eob; | 108 int i, rc, eob; |
| 108 int zbin; | 109 int zbin; |
| 109 int x, y, z, sz; | 110 int x, y, z, sz; |
| 110 short *zbin_boost_ptr = b->zrun_zbin_boost; | 111 short *zbin_boost_ptr = b->zrun_zbin_boost; |
| 111 short *coeff_ptr = b->coeff; | 112 short *coeff_ptr = b->coeff; |
| 112 short *zbin_ptr = b->zbin; | 113 short *zbin_ptr = b->zbin; |
| 113 short *round_ptr = b->round; | 114 short *round_ptr = b->round; |
| 114 short *quant_ptr = b->quant; | 115 short *quant_ptr = b->quant; |
| 115 short *quant_shift_ptr = b->quant_shift; | 116 unsigned char *quant_shift_ptr = b->quant_shift; |
| 116 short *qcoeff_ptr = d->qcoeff; | 117 short *qcoeff_ptr = d->qcoeff; |
| 117 short *dqcoeff_ptr = d->dqcoeff; | 118 short *dqcoeff_ptr = d->dqcoeff; |
| 118 short *dequant_ptr = d->dequant; | 119 short *dequant_ptr = d->dequant; |
| 119 short zbin_oq_value = b->zbin_extra; | 120 short zbin_oq_value = b->zbin_extra; |
| 120 | 121 |
| 121 vpx_memset(qcoeff_ptr, 0, 32); | 122 vpx_memset(qcoeff_ptr, 0, 32); |
| 122 vpx_memset(dqcoeff_ptr, 0, 32); | 123 vpx_memset(dqcoeff_ptr, 0, 32); |
| 123 | 124 |
| 124 eob = -1; | 125 eob = -1; |
| 125 | 126 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 { | 160 { |
| 160 int i; | 161 int i; |
| 161 int rc; | 162 int rc; |
| 162 int eob; | 163 int eob; |
| 163 int x; | 164 int x; |
| 164 int y; | 165 int y; |
| 165 int z; | 166 int z; |
| 166 int sz; | 167 int sz; |
| 167 short *coeff_ptr; | 168 short *coeff_ptr; |
| 168 short *quant_ptr; | 169 short *quant_ptr; |
| 169 short *quant_shift_ptr; | 170 unsigned char *quant_shift_ptr; |
| 170 short *qcoeff_ptr; | 171 short *qcoeff_ptr; |
| 171 short *dqcoeff_ptr; | 172 short *dqcoeff_ptr; |
| 172 short *dequant_ptr; | 173 short *dequant_ptr; |
| 173 | 174 |
| 174 coeff_ptr = b->coeff; | 175 coeff_ptr = b->coeff; |
| 175 quant_ptr = b->quant; | 176 quant_ptr = b->quant; |
| 176 quant_shift_ptr = b->quant_shift; | 177 quant_shift_ptr = b->quant_shift; |
| 177 qcoeff_ptr = d->qcoeff; | 178 qcoeff_ptr = d->qcoeff; |
| 178 dqcoeff_ptr = d->dqcoeff; | 179 dqcoeff_ptr = d->dqcoeff; |
| 179 dequant_ptr = d->dequant; | 180 dequant_ptr = d->dequant; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 zbin_boost_ptr = &b->zrun_zbin_boost[0]; // reset zero runlen
gth | 262 zbin_boost_ptr = &b->zrun_zbin_boost[0]; // reset zero runlen
gth |
| 262 } | 263 } |
| 263 } | 264 } |
| 264 } | 265 } |
| 265 | 266 |
| 266 d->eob = eob + 1; | 267 d->eob = eob + 1; |
| 267 } | 268 } |
| 268 | 269 |
| 269 #endif | 270 #endif |
| 270 | 271 |
| 271 void vp8_quantize_mby(MACROBLOCK *x) | 272 void vp8_quantize_mby_c(MACROBLOCK *x) |
| 272 { | 273 { |
| 273 int i; | 274 int i; |
| 274 int has_2nd_order = (x->e_mbd.mode_info_context->mbmi.mode != B_PRED | 275 int has_2nd_order = (x->e_mbd.mode_info_context->mbmi.mode != B_PRED |
| 275 && x->e_mbd.mode_info_context->mbmi.mode != SPLITMV); | 276 && x->e_mbd.mode_info_context->mbmi.mode != SPLITMV); |
| 276 | 277 |
| 277 for (i = 0; i < 16; i++) | 278 for (i = 0; i < 16; i++) |
| 278 x->quantize_b(&x->block[i], &x->e_mbd.block[i]); | 279 x->quantize_b(&x->block[i], &x->e_mbd.block[i]); |
| 279 | 280 |
| 280 if(has_2nd_order) | 281 if(has_2nd_order) |
| 281 x->quantize_b(&x->block[24], &x->e_mbd.block[24]); | 282 x->quantize_b(&x->block[24], &x->e_mbd.block[24]); |
| 282 } | 283 } |
| 283 | 284 |
| 284 void vp8_quantize_mb(MACROBLOCK *x) | 285 void vp8_quantize_mb_c(MACROBLOCK *x) |
| 285 { | 286 { |
| 286 int i; | 287 int i; |
| 287 int has_2nd_order=(x->e_mbd.mode_info_context->mbmi.mode != B_PRED | 288 int has_2nd_order=(x->e_mbd.mode_info_context->mbmi.mode != B_PRED |
| 288 && x->e_mbd.mode_info_context->mbmi.mode != SPLITMV); | 289 && x->e_mbd.mode_info_context->mbmi.mode != SPLITMV); |
| 289 | 290 |
| 290 for (i = 0; i < 24+has_2nd_order; i++) | 291 for (i = 0; i < 24+has_2nd_order; i++) |
| 291 x->quantize_b(&x->block[i], &x->e_mbd.block[i]); | 292 x->quantize_b(&x->block[i], &x->e_mbd.block[i]); |
| 292 } | 293 } |
| 293 | 294 |
| 294 | 295 |
| 295 void vp8_quantize_mbuv(MACROBLOCK *x) | 296 void vp8_quantize_mbuv_c(MACROBLOCK *x) |
| 296 { | 297 { |
| 297 int i; | 298 int i; |
| 298 | 299 |
| 299 for (i = 16; i < 24; i++) | 300 for (i = 16; i < 24; i++) |
| 300 x->quantize_b(&x->block[i], &x->e_mbd.block[i]); | 301 x->quantize_b(&x->block[i], &x->e_mbd.block[i]); |
| 301 } | 302 } |
| 303 |
| 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 |
| 307 * of blocks. */ |
| 308 void vp8_regular_quantize_b_pair(BLOCK *b1, BLOCK *b2, BLOCKD *d1, BLOCKD *d2) |
| 309 { |
| 310 vp8_regular_quantize_b(b1, d1); |
| 311 vp8_regular_quantize_b(b2, d2); |
| 312 } |
| 313 |
| 314 void vp8_fast_quantize_b_pair_c(BLOCK *b1, BLOCK *b2, BLOCKD *d1, BLOCKD *d2) |
| 315 { |
| 316 vp8_fast_quantize_b_c(b1, d1); |
| 317 vp8_fast_quantize_b_c(b2, d2); |
| 318 } |
| 319 |
| 320 |
| 321 static const int qrounding_factors[129] = |
| 322 { |
| 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, |
| 339 48 |
| 340 }; |
| 341 |
| 342 |
| 343 static const int qzbin_factors[129] = |
| 344 { |
| 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, |
| 361 80 |
| 362 }; |
| 363 |
| 364 |
| 365 static const int qrounding_factors_y2[129] = |
| 366 { |
| 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, |
| 383 48 |
| 384 }; |
| 385 |
| 386 |
| 387 static const int qzbin_factors_y2[129] = |
| 388 { |
| 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, |
| 405 80 |
| 406 }; |
| 407 |
| 408 |
| 409 #define EXACT_QUANT |
| 410 #ifdef EXACT_QUANT |
| 411 static void invert_quant(int improved_quant, short *quant, |
| 412 unsigned char *shift, short d) |
| 413 { |
| 414 if(improved_quant) |
| 415 { |
| 416 unsigned t; |
| 417 int l; |
| 418 t = d; |
| 419 for(l = 0; t > 1; l++) |
| 420 t>>=1; |
| 421 t = 1 + (1<<(16+l))/d; |
| 422 *quant = (short)(t - (1<<16)); |
| 423 *shift = l; |
| 424 } |
| 425 else |
| 426 { |
| 427 *quant = (1 << 16) / d; |
| 428 *shift = 0; |
| 429 } |
| 430 } |
| 431 |
| 432 |
| 433 void vp8cx_init_quantizer(VP8_COMP *cpi) |
| 434 { |
| 435 int i; |
| 436 int quant_val; |
| 437 int Q; |
| 438 |
| 439 int zbin_boost[16] = {0, 0, 8, 10, 12, 14, 16, 20, 24, 28, 32, 36, 40, 44, 4
4, 44}; |
| 440 |
| 441 for (Q = 0; Q < QINDEX_RANGE; Q++) |
| 442 { |
| 443 // dc values |
| 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; |
| 452 |
| 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; |
| 461 |
| 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; |
| 470 |
| 471 // all the ac values = ; |
| 472 for (i = 1; i < 16; i++) |
| 473 { |
| 474 int rc = vp8_default_zig_zag1d[i]; |
| 475 |
| 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; |
| 484 |
| 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; |
| 493 |
| 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; |
| 502 } |
| 503 } |
| 504 } |
| 505 #else |
| 506 void vp8cx_init_quantizer(VP8_COMP *cpi) |
| 507 { |
| 508 int i; |
| 509 int quant_val; |
| 510 int Q; |
| 511 |
| 512 int zbin_boost[16] = {0, 0, 8, 10, 12, 14, 16, 20, 24, 28, 32, 36, 40, 44, 4
4, 44}; |
| 513 |
| 514 for (Q = 0; Q < QINDEX_RANGE; Q++) |
| 515 { |
| 516 // dc values |
| 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; |
| 523 |
| 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; |
| 530 |
| 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; |
| 537 |
| 538 // all the ac values = ; |
| 539 for (i = 1; i < 16; i++) |
| 540 { |
| 541 int rc = vp8_default_zig_zag1d[i]; |
| 542 |
| 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; |
| 549 |
| 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; |
| 556 |
| 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; |
| 563 } |
| 564 } |
| 565 } |
| 566 #endif |
| 567 |
| 568 |
| 569 void vp8cx_mb_init_quantizer(VP8_COMP *cpi, MACROBLOCK *x) |
| 570 { |
| 571 int i; |
| 572 int QIndex; |
| 573 MACROBLOCKD *xd = &x->e_mbd; |
| 574 int zbin_extra; |
| 575 |
| 576 // Select the baseline MB Q index. |
| 577 if (xd->segmentation_enabled) |
| 578 { |
| 579 // Abs Value |
| 580 if (xd->mb_segement_abs_delta == SEGMENT_ABSDATA) |
| 581 |
| 582 QIndex = xd->segment_feature_data[MB_LVL_ALT_Q][xd->mode_info_contex
t->mbmi.segment_id]; |
| 583 // Delta Value |
| 584 else |
| 585 { |
| 586 QIndex = cpi->common.base_qindex + xd->segment_feature_data[MB_LVL_A
LT_Q][xd->mode_info_context->mbmi.segment_id]; |
| 587 QIndex = (QIndex >= 0) ? ((QIndex <= MAXQ) ? QIndex : MAXQ) : 0;
// Clamp to valid range |
| 588 } |
| 589 } |
| 590 else |
| 591 QIndex = cpi->common.base_qindex; |
| 592 |
| 593 // Y |
| 594 zbin_extra = ( cpi->common.Y1dequant[QIndex][1] * |
| 595 ( cpi->zbin_over_quant + |
| 596 cpi->zbin_mode_boost + |
| 597 x->act_zbin_adj ) ) >> 7; |
| 598 |
| 599 for (i = 0; i < 16; i++) |
| 600 { |
| 601 x->block[i].quant = cpi->Y1quant[QIndex]; |
| 602 x->block[i].quant_fast = cpi->Y1quant_fast[QIndex]; |
| 603 x->block[i].quant_shift = cpi->Y1quant_shift[QIndex]; |
| 604 x->block[i].zbin = cpi->Y1zbin[QIndex]; |
| 605 x->block[i].round = cpi->Y1round[QIndex]; |
| 606 x->e_mbd.block[i].dequant = cpi->common.Y1dequant[QIndex]; |
| 607 x->block[i].zrun_zbin_boost = cpi->zrun_zbin_boost_y1[QIndex]; |
| 608 x->block[i].zbin_extra = (short)zbin_extra; |
| 609 } |
| 610 |
| 611 // UV |
| 612 zbin_extra = ( cpi->common.UVdequant[QIndex][1] * |
| 613 ( cpi->zbin_over_quant + |
| 614 cpi->zbin_mode_boost + |
| 615 x->act_zbin_adj ) ) >> 7; |
| 616 |
| 617 for (i = 16; i < 24; i++) |
| 618 { |
| 619 x->block[i].quant = cpi->UVquant[QIndex]; |
| 620 x->block[i].quant_fast = cpi->UVquant_fast[QIndex]; |
| 621 x->block[i].quant_shift = cpi->UVquant_shift[QIndex]; |
| 622 x->block[i].zbin = cpi->UVzbin[QIndex]; |
| 623 x->block[i].round = cpi->UVround[QIndex]; |
| 624 x->e_mbd.block[i].dequant = cpi->common.UVdequant[QIndex]; |
| 625 x->block[i].zrun_zbin_boost = cpi->zrun_zbin_boost_uv[QIndex]; |
| 626 x->block[i].zbin_extra = (short)zbin_extra; |
| 627 } |
| 628 |
| 629 // Y2 |
| 630 zbin_extra = ( cpi->common.Y2dequant[QIndex][1] * |
| 631 ( (cpi->zbin_over_quant / 2) + |
| 632 cpi->zbin_mode_boost + |
| 633 x->act_zbin_adj ) ) >> 7; |
| 634 |
| 635 x->block[24].quant_fast = cpi->Y2quant_fast[QIndex]; |
| 636 x->block[24].quant = cpi->Y2quant[QIndex]; |
| 637 x->block[24].quant_shift = cpi->Y2quant_shift[QIndex]; |
| 638 x->block[24].zbin = cpi->Y2zbin[QIndex]; |
| 639 x->block[24].round = cpi->Y2round[QIndex]; |
| 640 x->e_mbd.block[24].dequant = cpi->common.Y2dequant[QIndex]; |
| 641 x->block[24].zrun_zbin_boost = cpi->zrun_zbin_boost_y2[QIndex]; |
| 642 x->block[24].zbin_extra = (short)zbin_extra; |
| 643 |
| 644 /* save this macroblock QIndex for vp8_update_zbin_extra() */ |
| 645 x->q_index = QIndex; |
| 646 } |
| 647 |
| 648 |
| 649 void vp8_update_zbin_extra(VP8_COMP *cpi, MACROBLOCK *x) |
| 650 { |
| 651 int i; |
| 652 int QIndex = x->q_index; |
| 653 int zbin_extra; |
| 654 |
| 655 // Y |
| 656 zbin_extra = ( cpi->common.Y1dequant[QIndex][1] * |
| 657 ( cpi->zbin_over_quant + |
| 658 cpi->zbin_mode_boost + |
| 659 x->act_zbin_adj ) ) >> 7; |
| 660 for (i = 0; i < 16; i++) |
| 661 { |
| 662 x->block[i].zbin_extra = (short)zbin_extra; |
| 663 } |
| 664 |
| 665 // UV |
| 666 zbin_extra = ( cpi->common.UVdequant[QIndex][1] * |
| 667 ( cpi->zbin_over_quant + |
| 668 cpi->zbin_mode_boost + |
| 669 x->act_zbin_adj ) ) >> 7; |
| 670 |
| 671 for (i = 16; i < 24; i++) |
| 672 { |
| 673 x->block[i].zbin_extra = (short)zbin_extra; |
| 674 } |
| 675 |
| 676 // Y2 |
| 677 zbin_extra = ( cpi->common.Y2dequant[QIndex][1] * |
| 678 ( (cpi->zbin_over_quant / 2) + |
| 679 cpi->zbin_mode_boost + |
| 680 x->act_zbin_adj ) ) >> 7; |
| 681 |
| 682 x->block[24].zbin_extra = (short)zbin_extra; |
| 683 } |
| 684 |
| 685 |
| 686 void vp8cx_frame_init_quantizer(VP8_COMP *cpi) |
| 687 { |
| 688 // Clear Zbin mode boost for default case |
| 689 cpi->zbin_mode_boost = 0; |
| 690 |
| 691 // MB level quantizer setup |
| 692 vp8cx_mb_init_quantizer(cpi, &cpi->mb); |
| 693 } |
| 694 |
| 695 |
| 696 void vp8_set_quantizer(struct VP8_COMP *cpi, int Q) |
| 697 { |
| 698 VP8_COMMON *cm = &cpi->common; |
| 699 MACROBLOCKD *mbd = &cpi->mb.e_mbd; |
| 700 int update = 0; |
| 701 int new_delta_q; |
| 702 cm->base_qindex = Q; |
| 703 |
| 704 /* if any of the delta_q values are changing update flag has to be set */ |
| 705 /* currently only y2dc_delta_q may change */ |
| 706 |
| 707 cm->y1dc_delta_q = 0; |
| 708 cm->y2ac_delta_q = 0; |
| 709 cm->uvdc_delta_q = 0; |
| 710 cm->uvac_delta_q = 0; |
| 711 |
| 712 if (Q < 4) |
| 713 { |
| 714 new_delta_q = 4-Q; |
| 715 } |
| 716 else |
| 717 new_delta_q = 0; |
| 718 |
| 719 update |= cm->y2dc_delta_q != new_delta_q; |
| 720 cm->y2dc_delta_q = new_delta_q; |
| 721 |
| 722 |
| 723 // Set Segment specific quatizers |
| 724 mbd->segment_feature_data[MB_LVL_ALT_Q][0] = cpi->segment_feature_data[MB_LV
L_ALT_Q][0]; |
| 725 mbd->segment_feature_data[MB_LVL_ALT_Q][1] = cpi->segment_feature_data[MB_LV
L_ALT_Q][1]; |
| 726 mbd->segment_feature_data[MB_LVL_ALT_Q][2] = cpi->segment_feature_data[MB_LV
L_ALT_Q][2]; |
| 727 mbd->segment_feature_data[MB_LVL_ALT_Q][3] = cpi->segment_feature_data[MB_LV
L_ALT_Q][3]; |
| 728 |
| 729 /* quantizer has to be reinitialized for any delta_q changes */ |
| 730 if(update) |
| 731 vp8cx_init_quantizer(cpi); |
| 732 |
| 733 } |
| 734 |
| OLD | NEW |