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 |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 t = d; | 146 t = d; |
147 for (l = 0; t > 1; l++) | 147 for (l = 0; t > 1; l++) |
148 t >>= 1; | 148 t >>= 1; |
149 t = 1 + (1 << (16 + l)) / d; | 149 t = 1 + (1 << (16 + l)) / d; |
150 *quant = (int16_t)(t - (1 << 16)); | 150 *quant = (int16_t)(t - (1 << 16)); |
151 *shift = 1 << (16 - l); | 151 *shift = 1 << (16 - l); |
152 } | 152 } |
153 | 153 |
154 void vp9_init_quantizer(VP9_COMP *cpi) { | 154 void vp9_init_quantizer(VP9_COMP *cpi) { |
155 VP9_COMMON *const cm = &cpi->common; | 155 VP9_COMMON *const cm = &cpi->common; |
| 156 QUANTS *const quants = &cpi->quants; |
156 int i, q, quant; | 157 int i, q, quant; |
157 | 158 |
158 for (q = 0; q < QINDEX_RANGE; q++) { | 159 for (q = 0; q < QINDEX_RANGE; q++) { |
159 const int qzbin_factor = q == 0 ? 64 : (vp9_dc_quant(q, 0) < 148 ? 84 : 80); | 160 const int qzbin_factor = q == 0 ? 64 : (vp9_dc_quant(q, 0) < 148 ? 84 : 80); |
160 const int qrounding_factor = q == 0 ? 64 : 48; | 161 const int qrounding_factor = q == 0 ? 64 : 48; |
161 | 162 |
162 for (i = 0; i < 2; ++i) { | 163 for (i = 0; i < 2; ++i) { |
163 // y | 164 // y |
164 quant = i == 0 ? vp9_dc_quant(q, cm->y_dc_delta_q) | 165 quant = i == 0 ? vp9_dc_quant(q, cm->y_dc_delta_q) |
165 : vp9_ac_quant(q, 0); | 166 : vp9_ac_quant(q, 0); |
166 invert_quant(&cpi->y_quant[q][i], &cpi->y_quant_shift[q][i], quant); | 167 invert_quant(&quants->y_quant[q][i], &quants->y_quant_shift[q][i], quant); |
167 cpi->y_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7); | 168 quants->y_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7); |
168 cpi->y_round[q][i] = (qrounding_factor * quant) >> 7; | 169 quants->y_round[q][i] = (qrounding_factor * quant) >> 7; |
169 cm->y_dequant[q][i] = quant; | 170 cm->y_dequant[q][i] = quant; |
170 | 171 |
171 // uv | 172 // uv |
172 quant = i == 0 ? vp9_dc_quant(q, cm->uv_dc_delta_q) | 173 quant = i == 0 ? vp9_dc_quant(q, cm->uv_dc_delta_q) |
173 : vp9_ac_quant(q, cm->uv_ac_delta_q); | 174 : vp9_ac_quant(q, cm->uv_ac_delta_q); |
174 invert_quant(&cpi->uv_quant[q][i], &cpi->uv_quant_shift[q][i], quant); | 175 invert_quant(&quants->uv_quant[q][i], |
175 cpi->uv_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7); | 176 &quants->uv_quant_shift[q][i], quant); |
176 cpi->uv_round[q][i] = (qrounding_factor * quant) >> 7; | 177 quants->uv_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7); |
| 178 quants->uv_round[q][i] = (qrounding_factor * quant) >> 7; |
177 cm->uv_dequant[q][i] = quant; | 179 cm->uv_dequant[q][i] = quant; |
178 | 180 |
179 #if CONFIG_ALPHA | 181 #if CONFIG_ALPHA |
180 // alpha | 182 // alpha |
181 quant = i == 0 ? vp9_dc_quant(q, cm->a_dc_delta_q) | 183 quant = i == 0 ? vp9_dc_quant(q, cm->a_dc_delta_q) |
182 : vp9_ac_quant(q, cm->a_ac_delta_q); | 184 : vp9_ac_quant(q, cm->a_ac_delta_q); |
183 invert_quant(&cpi->a_quant[q][i], &cpi->a_quant_shift[q][i], quant); | 185 invert_quant(&quants->a_quant[q][i], &quants->a_quant_shift[q][i], quant); |
184 cpi->a_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7); | 186 quants->a_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7); |
185 cpi->a_round[q][i] = (qrounding_factor * quant) >> 7; | 187 quants->a_round[q][i] = (qrounding_factor * quant) >> 7; |
186 cm->a_dequant[q][i] = quant; | 188 cm->a_dequant[q][i] = quant; |
187 #endif | 189 #endif |
188 } | 190 } |
189 | 191 |
190 for (i = 2; i < 8; i++) { | 192 for (i = 2; i < 8; i++) { |
191 cpi->y_quant[q][i] = cpi->y_quant[q][1]; | 193 quants->y_quant[q][i] = quants->y_quant[q][1]; |
192 cpi->y_quant_shift[q][i] = cpi->y_quant_shift[q][1]; | 194 quants->y_quant_shift[q][i] = quants->y_quant_shift[q][1]; |
193 cpi->y_zbin[q][i] = cpi->y_zbin[q][1]; | 195 quants->y_zbin[q][i] = quants->y_zbin[q][1]; |
194 cpi->y_round[q][i] = cpi->y_round[q][1]; | 196 quants->y_round[q][i] = quants->y_round[q][1]; |
195 cm->y_dequant[q][i] = cm->y_dequant[q][1]; | 197 cm->y_dequant[q][i] = cm->y_dequant[q][1]; |
196 | 198 |
197 cpi->uv_quant[q][i] = cpi->uv_quant[q][1]; | 199 quants->uv_quant[q][i] = quants->uv_quant[q][1]; |
198 cpi->uv_quant_shift[q][i] = cpi->uv_quant_shift[q][1]; | 200 quants->uv_quant_shift[q][i] = quants->uv_quant_shift[q][1]; |
199 cpi->uv_zbin[q][i] = cpi->uv_zbin[q][1]; | 201 quants->uv_zbin[q][i] = quants->uv_zbin[q][1]; |
200 cpi->uv_round[q][i] = cpi->uv_round[q][1]; | 202 quants->uv_round[q][i] = quants->uv_round[q][1]; |
201 cm->uv_dequant[q][i] = cm->uv_dequant[q][1]; | 203 cm->uv_dequant[q][i] = cm->uv_dequant[q][1]; |
202 | 204 |
203 #if CONFIG_ALPHA | 205 #if CONFIG_ALPHA |
204 cpi->a_quant[q][i] = cpi->a_quant[q][1]; | 206 quants->a_quant[q][i] = quants->a_quant[q][1]; |
205 cpi->a_quant_shift[q][i] = cpi->a_quant_shift[q][1]; | 207 quants->a_quant_shift[q][i] = quants->a_quant_shift[q][1]; |
206 cpi->a_zbin[q][i] = cpi->a_zbin[q][1]; | 208 quants->a_zbin[q][i] = quants->a_zbin[q][1]; |
207 cpi->a_round[q][i] = cpi->a_round[q][1]; | 209 quants->a_round[q][i] = quants->a_round[q][1]; |
208 cm->a_dequant[q][i] = cm->a_dequant[q][1]; | 210 cm->a_dequant[q][i] = cm->a_dequant[q][1]; |
209 #endif | 211 #endif |
210 } | 212 } |
211 } | 213 } |
212 } | 214 } |
213 | 215 |
214 void vp9_init_plane_quantizers(VP9_COMP *cpi, MACROBLOCK *x) { | 216 void vp9_init_plane_quantizers(VP9_COMP *cpi, MACROBLOCK *x) { |
215 const VP9_COMMON *const cm = &cpi->common; | 217 const VP9_COMMON *const cm = &cpi->common; |
216 MACROBLOCKD *xd = &x->e_mbd; | 218 MACROBLOCKD *const xd = &x->e_mbd; |
217 const int segment_id = xd->mi_8x8[0]->mbmi.segment_id; | 219 QUANTS *const quants = &cpi->quants; |
| 220 const int segment_id = xd->mi[0]->mbmi.segment_id; |
218 const int qindex = vp9_get_qindex(&cm->seg, segment_id, cm->base_qindex); | 221 const int qindex = vp9_get_qindex(&cm->seg, segment_id, cm->base_qindex); |
219 const int rdmult = vp9_compute_rd_mult(cpi, qindex + cm->y_dc_delta_q); | 222 const int rdmult = vp9_compute_rd_mult(cpi, qindex + cm->y_dc_delta_q); |
220 const int zbin = cpi->zbin_mode_boost + x->act_zbin_adj; | 223 const int zbin = cpi->zbin_mode_boost + x->act_zbin_adj; |
221 int i; | 224 int i; |
222 | 225 |
223 // Y | 226 // Y |
224 x->plane[0].quant = cpi->y_quant[qindex]; | 227 x->plane[0].quant = quants->y_quant[qindex]; |
225 x->plane[0].quant_shift = cpi->y_quant_shift[qindex]; | 228 x->plane[0].quant_shift = quants->y_quant_shift[qindex]; |
226 x->plane[0].zbin = cpi->y_zbin[qindex]; | 229 x->plane[0].zbin = quants->y_zbin[qindex]; |
227 x->plane[0].round = cpi->y_round[qindex]; | 230 x->plane[0].round = quants->y_round[qindex]; |
228 x->plane[0].zbin_extra = (int16_t)((cm->y_dequant[qindex][1] * zbin) >> 7); | 231 x->plane[0].zbin_extra = (int16_t)((cm->y_dequant[qindex][1] * zbin) >> 7); |
229 xd->plane[0].dequant = cm->y_dequant[qindex]; | 232 xd->plane[0].dequant = cm->y_dequant[qindex]; |
230 | 233 |
231 // UV | 234 // UV |
232 for (i = 1; i < 3; i++) { | 235 for (i = 1; i < 3; i++) { |
233 x->plane[i].quant = cpi->uv_quant[qindex]; | 236 x->plane[i].quant = quants->uv_quant[qindex]; |
234 x->plane[i].quant_shift = cpi->uv_quant_shift[qindex]; | 237 x->plane[i].quant_shift = quants->uv_quant_shift[qindex]; |
235 x->plane[i].zbin = cpi->uv_zbin[qindex]; | 238 x->plane[i].zbin = quants->uv_zbin[qindex]; |
236 x->plane[i].round = cpi->uv_round[qindex]; | 239 x->plane[i].round = quants->uv_round[qindex]; |
237 x->plane[i].zbin_extra = (int16_t)((cm->uv_dequant[qindex][1] * zbin) >> 7); | 240 x->plane[i].zbin_extra = (int16_t)((cm->uv_dequant[qindex][1] * zbin) >> 7); |
238 xd->plane[i].dequant = cm->uv_dequant[qindex]; | 241 xd->plane[i].dequant = cm->uv_dequant[qindex]; |
239 } | 242 } |
240 | 243 |
241 #if CONFIG_ALPHA | 244 #if CONFIG_ALPHA |
242 x->plane[3].quant = cpi->a_quant[qindex]; | 245 x->plane[3].quant = cpi->a_quant[qindex]; |
243 x->plane[3].quant_shift = cpi->a_quant_shift[qindex]; | 246 x->plane[3].quant_shift = cpi->a_quant_shift[qindex]; |
244 x->plane[3].zbin = cpi->a_zbin[qindex]; | 247 x->plane[3].zbin = cpi->a_zbin[qindex]; |
245 x->plane[3].round = cpi->a_round[qindex]; | 248 x->plane[3].round = cpi->a_round[qindex]; |
246 x->plane[3].zbin_extra = (int16_t)((cm->a_dequant[qindex][1] * zbin) >> 7); | 249 x->plane[3].zbin_extra = (int16_t)((cm->a_dequant[qindex][1] * zbin) >> 7); |
(...skipping 19 matching lines...) Expand all Loading... |
266 x->plane[0].zbin_extra = (int16_t)y_zbin_extra; | 269 x->plane[0].zbin_extra = (int16_t)y_zbin_extra; |
267 x->plane[1].zbin_extra = (int16_t)uv_zbin_extra; | 270 x->plane[1].zbin_extra = (int16_t)uv_zbin_extra; |
268 x->plane[2].zbin_extra = (int16_t)uv_zbin_extra; | 271 x->plane[2].zbin_extra = (int16_t)uv_zbin_extra; |
269 } | 272 } |
270 | 273 |
271 void vp9_frame_init_quantizer(VP9_COMP *cpi) { | 274 void vp9_frame_init_quantizer(VP9_COMP *cpi) { |
272 cpi->zbin_mode_boost = 0; | 275 cpi->zbin_mode_boost = 0; |
273 vp9_init_plane_quantizers(cpi, &cpi->mb); | 276 vp9_init_plane_quantizers(cpi, &cpi->mb); |
274 } | 277 } |
275 | 278 |
276 void vp9_set_quantizer(struct VP9_COMP *cpi, int q) { | 279 void vp9_set_quantizer(VP9_COMMON *cm, int q) { |
277 VP9_COMMON *const cm = &cpi->common; | |
278 | |
279 // quantizer has to be reinitialized with vp9_init_quantizer() if any | 280 // quantizer has to be reinitialized with vp9_init_quantizer() if any |
280 // delta_q changes. | 281 // delta_q changes. |
281 cm->base_qindex = q; | 282 cm->base_qindex = q; |
282 cm->y_dc_delta_q = 0; | 283 cm->y_dc_delta_q = 0; |
283 cm->uv_dc_delta_q = 0; | 284 cm->uv_dc_delta_q = 0; |
284 cm->uv_ac_delta_q = 0; | 285 cm->uv_ac_delta_q = 0; |
285 } | 286 } |
| 287 |
| 288 // Table that converts 0-63 Q-range values passed in outside to the Qindex |
| 289 // range used internally. |
| 290 static const int quantizer_to_qindex[] = { |
| 291 0, 4, 8, 12, 16, 20, 24, 28, |
| 292 32, 36, 40, 44, 48, 52, 56, 60, |
| 293 64, 68, 72, 76, 80, 84, 88, 92, |
| 294 96, 100, 104, 108, 112, 116, 120, 124, |
| 295 128, 132, 136, 140, 144, 148, 152, 156, |
| 296 160, 164, 168, 172, 176, 180, 184, 188, |
| 297 192, 196, 200, 204, 208, 212, 216, 220, |
| 298 224, 228, 232, 236, 240, 244, 249, 255, |
| 299 }; |
| 300 |
| 301 int vp9_quantizer_to_qindex(int quantizer) { |
| 302 return quantizer_to_qindex[quantizer]; |
| 303 } |
| 304 |
| 305 int vp9_qindex_to_quantizer(int qindex) { |
| 306 int quantizer; |
| 307 |
| 308 for (quantizer = 0; quantizer < 64; ++quantizer) |
| 309 if (quantizer_to_qindex[quantizer] >= qindex) |
| 310 return quantizer; |
| 311 |
| 312 return 63; |
| 313 } |
OLD | NEW |