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 "onyx_int.h" |
16 #include "quantize.h" | 16 #include "quantize.h" |
17 #include "vp8/common/quant_common.h" | 17 #include "vp8/common/quant_common.h" |
18 | 18 |
19 #define EXACT_QUANT | |
20 | |
21 #ifdef EXACT_FASTQUANT | |
22 void vp8_fast_quantize_b_c(BLOCK *b, BLOCKD *d) | |
23 { | |
24 int i, rc, eob; | |
25 int zbin; | |
26 int x, y, z, sz; | |
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; | |
35 | |
36 vpx_memset(qcoeff_ptr, 0, 32); | |
37 vpx_memset(dqcoeff_ptr, 0, 32); | |
38 | |
39 eob = -1; | |
40 | |
41 for (i = 0; i < 16; i++) | |
42 { | |
43 rc = vp8_default_zig_zag1d[i]; | |
44 z = coeff_ptr[rc]; | |
45 zbin = zbin_ptr[rc] ; | |
46 | |
47 sz = (z >> 31); /* sign of z */ | |
48 x = (z ^ sz) - sz; /* x = abs(z) */ | |
49 | |
50 if (x >= zbin) | |
51 { | |
52 x += round_ptr[rc]; | |
53 y = ((((x * quant_ptr[rc]) >> 16) + x) | |
54 * quant_shift_ptr[rc]) >> 16; /* 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 */ | |
58 | |
59 if (y) | |
60 { | |
61 eob = i; /* last nonzero coeffs */ | |
62 } | |
63 } | |
64 } | |
65 *d->eob = (char)(eob + 1); | |
66 } | |
67 | |
68 #else | |
69 | |
70 void vp8_fast_quantize_b_c(BLOCK *b, BLOCKD *d) | 19 void vp8_fast_quantize_b_c(BLOCK *b, BLOCKD *d) |
71 { | 20 { |
72 int i, rc, eob; | 21 int i, rc, eob; |
73 int x, y, z, sz; | 22 int x, y, z, sz; |
74 short *coeff_ptr = b->coeff; | 23 short *coeff_ptr = b->coeff; |
75 short *round_ptr = b->round; | 24 short *round_ptr = b->round; |
76 short *quant_ptr = b->quant_fast; | 25 short *quant_ptr = b->quant_fast; |
77 short *qcoeff_ptr = d->qcoeff; | 26 short *qcoeff_ptr = d->qcoeff; |
78 short *dqcoeff_ptr = d->dqcoeff; | 27 short *dqcoeff_ptr = d->dqcoeff; |
79 short *dequant_ptr = d->dequant; | 28 short *dequant_ptr = d->dequant; |
(...skipping 13 matching lines...) Expand all Loading... |
93 dqcoeff_ptr[rc] = x * dequant_ptr[rc]; /* dequantized value */ | 42 dqcoeff_ptr[rc] = x * dequant_ptr[rc]; /* dequantized value */ |
94 | 43 |
95 if (y) | 44 if (y) |
96 { | 45 { |
97 eob = i; /* last nonzero coeffs */ | 46 eob = i; /* last nonzero coeffs */ |
98 } | 47 } |
99 } | 48 } |
100 *d->eob = (char)(eob + 1); | 49 *d->eob = (char)(eob + 1); |
101 } | 50 } |
102 | 51 |
103 #endif | |
104 | |
105 #ifdef EXACT_QUANT | |
106 void vp8_regular_quantize_b_c(BLOCK *b, BLOCKD *d) | 52 void vp8_regular_quantize_b_c(BLOCK *b, BLOCKD *d) |
107 { | 53 { |
108 int i, rc, eob; | 54 int i, rc, eob; |
109 int zbin; | 55 int zbin; |
110 int x, y, z, sz; | 56 int x, y, z, sz; |
111 short *zbin_boost_ptr = b->zrun_zbin_boost; | 57 short *zbin_boost_ptr = b->zrun_zbin_boost; |
112 short *coeff_ptr = b->coeff; | 58 short *coeff_ptr = b->coeff; |
113 short *zbin_ptr = b->zbin; | 59 short *zbin_ptr = b->zbin; |
114 short *round_ptr = b->round; | 60 short *round_ptr = b->round; |
115 short *quant_ptr = b->quant; | 61 short *quant_ptr = b->quant; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 { | 94 { |
149 eob = i; /* last nonzero coeffs */ | 95 eob = i; /* last nonzero coeffs */ |
150 zbin_boost_ptr = b->zrun_zbin_boost; /* reset zero runlength */ | 96 zbin_boost_ptr = b->zrun_zbin_boost; /* reset zero runlength */ |
151 } | 97 } |
152 } | 98 } |
153 } | 99 } |
154 | 100 |
155 *d->eob = (char)(eob + 1); | 101 *d->eob = (char)(eob + 1); |
156 } | 102 } |
157 | 103 |
158 /* Perform regular quantization, with unbiased rounding and no zero bin. */ | |
159 void vp8_strict_quantize_b_c(BLOCK *b, BLOCKD *d) | |
160 { | |
161 int i; | |
162 int rc; | |
163 int eob; | |
164 int x; | |
165 int y; | |
166 int z; | |
167 int sz; | |
168 short *coeff_ptr; | |
169 short *quant_ptr; | |
170 short *quant_shift_ptr; | |
171 short *qcoeff_ptr; | |
172 short *dqcoeff_ptr; | |
173 short *dequant_ptr; | |
174 | |
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; | |
181 eob = - 1; | |
182 vpx_memset(qcoeff_ptr, 0, 32); | |
183 vpx_memset(dqcoeff_ptr, 0, 32); | |
184 for (i = 0; i < 16; i++) | |
185 { | |
186 int dq; | |
187 int rounding; | |
188 | |
189 /*TODO: These arrays should be stored in zig-zag order.*/ | |
190 rc = vp8_default_zig_zag1d[i]; | |
191 z = coeff_ptr[rc]; | |
192 dq = dequant_ptr[rc]; | |
193 rounding = dq >> 1; | |
194 /* Sign of z. */ | |
195 sz = -(z < 0); | |
196 x = (z + sz) ^ sz; | |
197 x += rounding; | |
198 if (x >= dq) | |
199 { | |
200 /* Quantize x. */ | |
201 y = ((((x * quant_ptr[rc]) >> 16) + x) * quant_shift_ptr[rc]) >> 16
; | |
202 /* Put the sign back. */ | |
203 x = (y + sz) ^ sz; | |
204 /* Save the coefficient and its dequantized value. */ | |
205 qcoeff_ptr[rc] = x; | |
206 dqcoeff_ptr[rc] = x * dq; | |
207 /* Remember the last non-zero coefficient. */ | |
208 if (y) | |
209 eob = i; | |
210 } | |
211 } | |
212 | |
213 *d->eob = (char)(eob + 1); | |
214 } | |
215 | |
216 #else | |
217 | |
218 void vp8_regular_quantize_b_c(BLOCK *b, BLOCKD *d) | |
219 { | |
220 int i, rc, eob; | |
221 int zbin; | |
222 int x, y, z, sz; | |
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; | |
232 | |
233 vpx_memset(qcoeff_ptr, 0, 32); | |
234 vpx_memset(dqcoeff_ptr, 0, 32); | |
235 | |
236 eob = -1; | |
237 | |
238 for (i = 0; i < 16; i++) | |
239 { | |
240 rc = vp8_default_zig_zag1d[i]; | |
241 z = coeff_ptr[rc]; | |
242 | |
243 zbin = zbin_ptr[rc] + *zbin_boost_ptr + zbin_oq_value; | |
244 | |
245 zbin_boost_ptr ++; | |
246 sz = (z >> 31); /* sign of z */ | |
247 x = (z ^ sz) - sz; /* x = abs(z) */ | |
248 | |
249 if (x >= zbin) | |
250 { | |
251 y = ((x + round_ptr[rc]) * quant_ptr[rc]) >> 16; /* quantize (x) */ | |
252 x = (y ^ sz) - sz; /* get the sign back */ | |
253 qcoeff_ptr[rc] = x; /* write to destination */ | |
254 dqcoeff_ptr[rc] = x * dequant_ptr[rc]; /* dequantized value */ | |
255 | |
256 if (y) | |
257 { | |
258 eob = i; /* last nonzero coeffs */ | |
259 zbin_boost_ptr = &b->zrun_zbin_boost[0]; /* reset zrl */ | |
260 } | |
261 } | |
262 } | |
263 | |
264 *d->eob = (char)(eob + 1); | |
265 } | |
266 | |
267 #endif | |
268 | |
269 void vp8_quantize_mby_c(MACROBLOCK *x) | 104 void vp8_quantize_mby_c(MACROBLOCK *x) |
270 { | 105 { |
271 int i; | 106 int i; |
272 int has_2nd_order = (x->e_mbd.mode_info_context->mbmi.mode != B_PRED | 107 int has_2nd_order = (x->e_mbd.mode_info_context->mbmi.mode != B_PRED |
273 && x->e_mbd.mode_info_context->mbmi.mode != SPLITMV); | 108 && x->e_mbd.mode_info_context->mbmi.mode != SPLITMV); |
274 | 109 |
275 for (i = 0; i < 16; i++) | 110 for (i = 0; i < 16; i++) |
276 x->quantize_b(&x->block[i], &x->e_mbd.block[i]); | 111 x->quantize_b(&x->block[i], &x->e_mbd.block[i]); |
277 | 112 |
278 if(has_2nd_order) | 113 if(has_2nd_order) |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 80, 80, 80, 80, 80, 80, 80, 80, | 231 80, 80, 80, 80, 80, 80, 80, 80, |
397 80, 80, 80, 80, 80, 80, 80, 80, | 232 80, 80, 80, 80, 80, 80, 80, 80, |
398 80, 80, 80, 80, 80, 80, 80, 80, | 233 80, 80, 80, 80, 80, 80, 80, 80, |
399 80, 80, 80, 80, 80, 80, 80, 80, | 234 80, 80, 80, 80, 80, 80, 80, 80, |
400 80, 80, 80, 80, 80, 80, 80, 80, | 235 80, 80, 80, 80, 80, 80, 80, 80, |
401 80, 80, 80, 80, 80, 80, 80, 80, | 236 80, 80, 80, 80, 80, 80, 80, 80, |
402 80 | 237 80 |
403 }; | 238 }; |
404 | 239 |
405 | 240 |
406 #define EXACT_QUANT | |
407 #ifdef EXACT_QUANT | |
408 static void invert_quant(int improved_quant, short *quant, | 241 static void invert_quant(int improved_quant, short *quant, |
409 short *shift, short d) | 242 short *shift, short d) |
410 { | 243 { |
411 if(improved_quant) | 244 if(improved_quant) |
412 { | 245 { |
413 unsigned t; | 246 unsigned t; |
414 int l; | 247 int l; |
415 t = d; | 248 t = d; |
416 for(l = 0; t > 1; l++) | 249 for(l = 0; t > 1; l++) |
417 t>>=1; | 250 t>>=1; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 cpi->UVquant_fast[Q][i] = cpi->UVquant_fast[Q][1]; | 352 cpi->UVquant_fast[Q][i] = cpi->UVquant_fast[Q][1]; |
520 cpi->UVquant[Q][i] = cpi->UVquant[Q][1]; | 353 cpi->UVquant[Q][i] = cpi->UVquant[Q][1]; |
521 cpi->UVquant_shift[Q][i] = cpi->UVquant_shift[Q][1]; | 354 cpi->UVquant_shift[Q][i] = cpi->UVquant_shift[Q][1]; |
522 cpi->UVzbin[Q][i] = cpi->UVzbin[Q][1]; | 355 cpi->UVzbin[Q][i] = cpi->UVzbin[Q][1]; |
523 cpi->UVround[Q][i] = cpi->UVround[Q][1]; | 356 cpi->UVround[Q][i] = cpi->UVround[Q][1]; |
524 cpi->zrun_zbin_boost_uv[Q][i] = (cpi->common.UVdequant[Q][1] * | 357 cpi->zrun_zbin_boost_uv[Q][i] = (cpi->common.UVdequant[Q][1] * |
525 zbin_boost[i]) >> 7; | 358 zbin_boost[i]) >> 7; |
526 } | 359 } |
527 } | 360 } |
528 } | 361 } |
529 #else | |
530 void vp8cx_init_quantizer(VP8_COMP *cpi) | |
531 { | |
532 int i; | |
533 int quant_val; | |
534 int Q; | |
535 | |
536 int zbin_boost[16] = {0, 0, 8, 10, 12, 14, 16, 20, 24, 28, 32, 36, 40, 44, 4
4, 44}; | |
537 | |
538 for (Q = 0; Q < QINDEX_RANGE; Q++) | |
539 { | |
540 /* dc values */ | |
541 quant_val = vp8_dc_quant(Q, cpi->common.y1dc_delta_q); | |
542 cpi->Y1quant[Q][0] = (1 << 16) / quant_val; | |
543 cpi->Y1zbin[Q][0] = ((qzbin_factors[Q] * quant_val) + 64) >> 7; | |
544 cpi->Y1round[Q][0] = (qrounding_factors[Q] * quant_val) >> 7; | |
545 cpi->common.Y1dequant[Q][0] = quant_val; | |
546 cpi->zrun_zbin_boost_y1[Q][0] = (quant_val * zbin_boost[0]) >> 7; | |
547 | |
548 quant_val = vp8_dc2quant(Q, cpi->common.y2dc_delta_q); | |
549 cpi->Y2quant[Q][0] = (1 << 16) / quant_val; | |
550 cpi->Y2zbin[Q][0] = ((qzbin_factors_y2[Q] * quant_val) + 64) >> 7; | |
551 cpi->Y2round[Q][0] = (qrounding_factors_y2[Q] * quant_val) >> 7; | |
552 cpi->common.Y2dequant[Q][0] = quant_val; | |
553 cpi->zrun_zbin_boost_y2[Q][0] = (quant_val * zbin_boost[0]) >> 7; | |
554 | |
555 quant_val = vp8_dc_uv_quant(Q, cpi->common.uvdc_delta_q); | |
556 cpi->UVquant[Q][0] = (1 << 16) / quant_val; | |
557 cpi->UVzbin[Q][0] = ((qzbin_factors[Q] * quant_val) + 64) >> 7;; | |
558 cpi->UVround[Q][0] = (qrounding_factors[Q] * quant_val) >> 7; | |
559 cpi->common.UVdequant[Q][0] = quant_val; | |
560 cpi->zrun_zbin_boost_uv[Q][0] = (quant_val * zbin_boost[0]) >> 7; | |
561 | |
562 /* all the ac values = ; */ | |
563 for (i = 1; i < 16; i++) | |
564 { | |
565 int rc = vp8_default_zig_zag1d[i]; | |
566 | |
567 quant_val = vp8_ac_yquant(Q); | |
568 cpi->Y1quant[Q][rc] = (1 << 16) / quant_val; | |
569 cpi->Y1zbin[Q][rc] = ((qzbin_factors[Q] * quant_val) + 64) >> 7; | |
570 cpi->Y1round[Q][rc] = (qrounding_factors[Q] * quant_val) >> 7; | |
571 cpi->common.Y1dequant[Q][rc] = quant_val; | |
572 cpi->zrun_zbin_boost_y1[Q][i] = (quant_val * zbin_boost[i]) >> 7; | |
573 | |
574 quant_val = vp8_ac2quant(Q, cpi->common.y2ac_delta_q); | |
575 cpi->Y2quant[Q][rc] = (1 << 16) / quant_val; | |
576 cpi->Y2zbin[Q][rc] = ((qzbin_factors_y2[Q] * quant_val) + 64) >> 7; | |
577 cpi->Y2round[Q][rc] = (qrounding_factors_y2[Q] * quant_val) >> 7; | |
578 cpi->common.Y2dequant[Q][rc] = quant_val; | |
579 cpi->zrun_zbin_boost_y2[Q][i] = (quant_val * zbin_boost[i]) >> 7; | |
580 | |
581 quant_val = vp8_ac_uv_quant(Q, cpi->common.uvac_delta_q); | |
582 cpi->UVquant[Q][rc] = (1 << 16) / quant_val; | |
583 cpi->UVzbin[Q][rc] = ((qzbin_factors[Q] * quant_val) + 64) >> 7; | |
584 cpi->UVround[Q][rc] = (qrounding_factors[Q] * quant_val) >> 7; | |
585 cpi->common.UVdequant[Q][rc] = quant_val; | |
586 cpi->zrun_zbin_boost_uv[Q][i] = (quant_val * zbin_boost[i]) >> 7; | |
587 } | |
588 } | |
589 } | |
590 #endif | |
591 | 362 |
592 #define ZBIN_EXTRA_Y \ | 363 #define ZBIN_EXTRA_Y \ |
593 (( cpi->common.Y1dequant[QIndex][1] * \ | 364 (( cpi->common.Y1dequant[QIndex][1] * \ |
594 ( x->zbin_over_quant + \ | 365 ( x->zbin_over_quant + \ |
595 x->zbin_mode_boost + \ | 366 x->zbin_mode_boost + \ |
596 x->act_zbin_adj ) ) >> 7) | 367 x->act_zbin_adj ) ) >> 7) |
597 | 368 |
598 #define ZBIN_EXTRA_UV \ | 369 #define ZBIN_EXTRA_UV \ |
599 (( cpi->common.UVdequant[QIndex][1] * \ | 370 (( cpi->common.UVdequant[QIndex][1] * \ |
600 ( x->zbin_over_quant + \ | 371 ( x->zbin_over_quant + \ |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 mbd->segment_feature_data[MB_LVL_ALT_Q][0] = cpi->segment_feature_data[MB_LV
L_ALT_Q][0]; | 577 mbd->segment_feature_data[MB_LVL_ALT_Q][0] = cpi->segment_feature_data[MB_LV
L_ALT_Q][0]; |
807 mbd->segment_feature_data[MB_LVL_ALT_Q][1] = cpi->segment_feature_data[MB_LV
L_ALT_Q][1]; | 578 mbd->segment_feature_data[MB_LVL_ALT_Q][1] = cpi->segment_feature_data[MB_LV
L_ALT_Q][1]; |
808 mbd->segment_feature_data[MB_LVL_ALT_Q][2] = cpi->segment_feature_data[MB_LV
L_ALT_Q][2]; | 579 mbd->segment_feature_data[MB_LVL_ALT_Q][2] = cpi->segment_feature_data[MB_LV
L_ALT_Q][2]; |
809 mbd->segment_feature_data[MB_LVL_ALT_Q][3] = cpi->segment_feature_data[MB_LV
L_ALT_Q][3]; | 580 mbd->segment_feature_data[MB_LVL_ALT_Q][3] = cpi->segment_feature_data[MB_LV
L_ALT_Q][3]; |
810 | 581 |
811 /* quantizer has to be reinitialized for any delta_q changes */ | 582 /* quantizer has to be reinitialized for any delta_q changes */ |
812 if(update) | 583 if(update) |
813 vp8cx_init_quantizer(cpi); | 584 vp8cx_init_quantizer(cpi); |
814 | 585 |
815 } | 586 } |
OLD | NEW |