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

Side by Side Diff: source/libvpx/vp8/encoder/quantize.c

Issue 13042014: Description: (Closed) Base URL: https://src.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: libvpx: Pull from upstream Created 7 years, 8 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
« no previous file with comments | « source/libvpx/vp8/encoder/onyx_int.h ('k') | source/libvpx/vp8/encoder/vp8_asm_enc_offsets.c » ('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
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 rc = vp8_default_zig_zag1d[i]; 43 rc = vp8_default_zig_zag1d[i];
44 z = coeff_ptr[rc]; 44 z = coeff_ptr[rc];
45 zbin = zbin_ptr[rc] ; 45 zbin = zbin_ptr[rc] ;
46 46
47 sz = (z >> 31); /* sign of z */ 47 sz = (z >> 31); /* sign of z */
48 x = (z ^ sz) - sz; /* x = abs(z) */ 48 x = (z ^ sz) - sz; /* x = abs(z) */
49 49
50 if (x >= zbin) 50 if (x >= zbin)
51 { 51 {
52 x += round_ptr[rc]; 52 x += round_ptr[rc];
53 y = (((x * quant_ptr[rc]) >> 16) + x) 53 y = ((((x * quant_ptr[rc]) >> 16) + x)
54 >> quant_shift_ptr[rc]; /* quantize (x) */ 54 * quant_shift_ptr[rc]) >> 16; /* quantize (x) */
55 x = (y ^ sz) - sz; /* get the sign back */ 55 x = (y ^ sz) - sz; /* get the sign back */
56 qcoeff_ptr[rc] = x; /* write to destination */ 56 qcoeff_ptr[rc] = x; /* write to destination */
57 dqcoeff_ptr[rc] = x * dequant_ptr[rc]; /* dequantized value */ 57 dqcoeff_ptr[rc] = x * dequant_ptr[rc]; /* dequantized value */
58 58
59 if (y) 59 if (y)
60 { 60 {
61 eob = i; /* last nonzero coeffs */ 61 eob = i; /* last nonzero coeffs */
62 } 62 }
63 } 63 }
64 } 64 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 void vp8_regular_quantize_b_c(BLOCK *b, BLOCKD *d) 106 void vp8_regular_quantize_b_c(BLOCK *b, BLOCKD *d)
107 { 107 {
108 int i, rc, eob; 108 int i, rc, eob;
109 int zbin; 109 int zbin;
110 int x, y, z, sz; 110 int x, y, z, sz;
111 short *zbin_boost_ptr = b->zrun_zbin_boost; 111 short *zbin_boost_ptr = b->zrun_zbin_boost;
112 short *coeff_ptr = b->coeff; 112 short *coeff_ptr = b->coeff;
113 short *zbin_ptr = b->zbin; 113 short *zbin_ptr = b->zbin;
114 short *round_ptr = b->round; 114 short *round_ptr = b->round;
115 short *quant_ptr = b->quant; 115 short *quant_ptr = b->quant;
116 unsigned char *quant_shift_ptr = b->quant_shift; 116 short *quant_shift_ptr = b->quant_shift;
117 short *qcoeff_ptr = d->qcoeff; 117 short *qcoeff_ptr = d->qcoeff;
118 short *dqcoeff_ptr = d->dqcoeff; 118 short *dqcoeff_ptr = d->dqcoeff;
119 short *dequant_ptr = d->dequant; 119 short *dequant_ptr = d->dequant;
120 short zbin_oq_value = b->zbin_extra; 120 short zbin_oq_value = b->zbin_extra;
121 121
122 vpx_memset(qcoeff_ptr, 0, 32); 122 vpx_memset(qcoeff_ptr, 0, 32);
123 vpx_memset(dqcoeff_ptr, 0, 32); 123 vpx_memset(dqcoeff_ptr, 0, 32);
124 124
125 eob = -1; 125 eob = -1;
126 126
127 for (i = 0; i < 16; i++) 127 for (i = 0; i < 16; i++)
128 { 128 {
129 rc = vp8_default_zig_zag1d[i]; 129 rc = vp8_default_zig_zag1d[i];
130 z = coeff_ptr[rc]; 130 z = coeff_ptr[rc];
131 131
132 zbin = zbin_ptr[rc] + *zbin_boost_ptr + zbin_oq_value; 132 zbin = zbin_ptr[rc] + *zbin_boost_ptr + zbin_oq_value;
133 133
134 zbin_boost_ptr ++; 134 zbin_boost_ptr ++;
135 sz = (z >> 31); /* sign of z */ 135 sz = (z >> 31); /* sign of z */
136 x = (z ^ sz) - sz; /* x = abs(z) */ 136 x = (z ^ sz) - sz; /* x = abs(z) */
137 137
138 if (x >= zbin) 138 if (x >= zbin)
139 { 139 {
140 x += round_ptr[rc]; 140 x += round_ptr[rc];
141 y = (((x * quant_ptr[rc]) >> 16) + x) 141 y = ((((x * quant_ptr[rc]) >> 16) + x)
142 >> quant_shift_ptr[rc]; /* quantize (x) */ 142 * quant_shift_ptr[rc]) >> 16; /* quantize (x) */
143 x = (y ^ sz) - sz; /* get the sign back */ 143 x = (y ^ sz) - sz; /* get the sign back */
144 qcoeff_ptr[rc] = x; /* write to destination */ 144 qcoeff_ptr[rc] = x; /* write to destination */
145 dqcoeff_ptr[rc] = x * dequant_ptr[rc]; /* dequantized value */ 145 dqcoeff_ptr[rc] = x * dequant_ptr[rc]; /* dequantized value */
146 146
147 if (y) 147 if (y)
148 { 148 {
149 eob = i; /* last nonzero coeffs */ 149 eob = i; /* last nonzero coeffs */
150 zbin_boost_ptr = b->zrun_zbin_boost; /* reset zero runlength */ 150 zbin_boost_ptr = b->zrun_zbin_boost; /* reset zero runlength */
151 } 151 }
152 } 152 }
153 } 153 }
154 154
155 *d->eob = (char)(eob + 1); 155 *d->eob = (char)(eob + 1);
156 } 156 }
157 157
158 /* Perform regular quantization, with unbiased rounding and no zero bin. */ 158 /* Perform regular quantization, with unbiased rounding and no zero bin. */
159 void vp8_strict_quantize_b_c(BLOCK *b, BLOCKD *d) 159 void vp8_strict_quantize_b_c(BLOCK *b, BLOCKD *d)
160 { 160 {
161 int i; 161 int i;
162 int rc; 162 int rc;
163 int eob; 163 int eob;
164 int x; 164 int x;
165 int y; 165 int y;
166 int z; 166 int z;
167 int sz; 167 int sz;
168 short *coeff_ptr; 168 short *coeff_ptr;
169 short *quant_ptr; 169 short *quant_ptr;
170 unsigned char *quant_shift_ptr; 170 short *quant_shift_ptr;
171 short *qcoeff_ptr; 171 short *qcoeff_ptr;
172 short *dqcoeff_ptr; 172 short *dqcoeff_ptr;
173 short *dequant_ptr; 173 short *dequant_ptr;
174 174
175 coeff_ptr = b->coeff; 175 coeff_ptr = b->coeff;
176 quant_ptr = b->quant; 176 quant_ptr = b->quant;
177 quant_shift_ptr = b->quant_shift; 177 quant_shift_ptr = b->quant_shift;
178 qcoeff_ptr = d->qcoeff; 178 qcoeff_ptr = d->qcoeff;
179 dqcoeff_ptr = d->dqcoeff; 179 dqcoeff_ptr = d->dqcoeff;
180 dequant_ptr = d->dequant; 180 dequant_ptr = d->dequant;
(...skipping 10 matching lines...) Expand all
191 z = coeff_ptr[rc]; 191 z = coeff_ptr[rc];
192 dq = dequant_ptr[rc]; 192 dq = dequant_ptr[rc];
193 round = dq >> 1; 193 round = dq >> 1;
194 /* Sign of z. */ 194 /* Sign of z. */
195 sz = -(z < 0); 195 sz = -(z < 0);
196 x = (z + sz) ^ sz; 196 x = (z + sz) ^ sz;
197 x += round; 197 x += round;
198 if (x >= dq) 198 if (x >= dq)
199 { 199 {
200 /* Quantize x. */ 200 /* Quantize x. */
201 y = (((x * quant_ptr[rc]) >> 16) + x) >> quant_shift_ptr[rc]; 201 y = ((((x * quant_ptr[rc]) >> 16) + x) * quant_shift_ptr[rc]) >> 16 ;
202 /* Put the sign back. */ 202 /* Put the sign back. */
203 x = (y + sz) ^ sz; 203 x = (y + sz) ^ sz;
204 /* Save the coefficient and its dequantized value. */ 204 /* Save the coefficient and its dequantized value. */
205 qcoeff_ptr[rc] = x; 205 qcoeff_ptr[rc] = x;
206 dqcoeff_ptr[rc] = x * dq; 206 dqcoeff_ptr[rc] = x * dq;
207 /* Remember the last non-zero coefficient. */ 207 /* Remember the last non-zero coefficient. */
208 if (y) 208 if (y)
209 eob = i; 209 eob = i;
210 } 210 }
211 } 211 }
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 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, 400 80, 80, 80, 80, 80, 80, 80, 80,
401 80, 80, 80, 80, 80, 80, 80, 80, 401 80, 80, 80, 80, 80, 80, 80, 80,
402 80 402 80
403 }; 403 };
404 404
405 405
406 #define EXACT_QUANT 406 #define EXACT_QUANT
407 #ifdef EXACT_QUANT 407 #ifdef EXACT_QUANT
408 static void invert_quant(int improved_quant, short *quant, 408 static void invert_quant(int improved_quant, short *quant,
409 unsigned char *shift, short d) 409 short *shift, short d)
410 { 410 {
411 if(improved_quant) 411 if(improved_quant)
412 { 412 {
413 unsigned t; 413 unsigned t;
414 int l; 414 int l;
415 t = d; 415 t = d;
416 for(l = 0; t > 1; l++) 416 for(l = 0; t > 1; l++)
417 t>>=1; 417 t>>=1;
418 t = 1 + (1<<(16+l))/d; 418 t = 1 + (1<<(16+l))/d;
419 *quant = (short)(t - (1<<16)); 419 *quant = (short)(t - (1<<16));
420 *shift = l; 420 *shift = l;
421 /* use multiplication and constant shift by 16 */
422 *shift = 1 << (16 - *shift);
421 } 423 }
422 else 424 else
423 { 425 {
424 *quant = (1 << 16) / d; 426 *quant = (1 << 16) / d;
425 *shift = 0; 427 *shift = 0;
428 /* use multiplication and constant shift by 16 */
429 *shift = 1 << (16 - *shift);
426 } 430 }
427 } 431 }
428 432
429 433
430 void vp8cx_init_quantizer(VP8_COMP *cpi) 434 void vp8cx_init_quantizer(VP8_COMP *cpi)
431 { 435 {
432 int i; 436 int i;
433 int quant_val; 437 int quant_val;
434 int Q; 438 int Q;
435 439
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 mbd->segment_feature_data[MB_LVL_ALT_Q][0] = cpi->segment_feature_data[MB_LV L_ALT_Q][0]; 806 mbd->segment_feature_data[MB_LVL_ALT_Q][0] = cpi->segment_feature_data[MB_LV L_ALT_Q][0];
803 mbd->segment_feature_data[MB_LVL_ALT_Q][1] = cpi->segment_feature_data[MB_LV L_ALT_Q][1]; 807 mbd->segment_feature_data[MB_LVL_ALT_Q][1] = cpi->segment_feature_data[MB_LV L_ALT_Q][1];
804 mbd->segment_feature_data[MB_LVL_ALT_Q][2] = cpi->segment_feature_data[MB_LV L_ALT_Q][2]; 808 mbd->segment_feature_data[MB_LVL_ALT_Q][2] = cpi->segment_feature_data[MB_LV L_ALT_Q][2];
805 mbd->segment_feature_data[MB_LVL_ALT_Q][3] = cpi->segment_feature_data[MB_LV L_ALT_Q][3]; 809 mbd->segment_feature_data[MB_LVL_ALT_Q][3] = cpi->segment_feature_data[MB_LV L_ALT_Q][3];
806 810
807 /* quantizer has to be reinitialized for any delta_q changes */ 811 /* quantizer has to be reinitialized for any delta_q changes */
808 if(update) 812 if(update)
809 vp8cx_init_quantizer(cpi); 813 vp8cx_init_quantizer(cpi);
810 814
811 } 815 }
OLDNEW
« no previous file with comments | « source/libvpx/vp8/encoder/onyx_int.h ('k') | source/libvpx/vp8/encoder/vp8_asm_enc_offsets.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698