| 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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 | 145 |
| 146 if (y) { | 146 if (y) { |
| 147 eob = idx_arr[i]; // last nonzero coeffs | 147 eob = idx_arr[i]; // last nonzero coeffs |
| 148 } | 148 } |
| 149 } | 149 } |
| 150 } | 150 } |
| 151 } | 151 } |
| 152 *eob_ptr = eob + 1; | 152 *eob_ptr = eob + 1; |
| 153 } | 153 } |
| 154 | 154 |
| 155 struct plane_block_idx { |
| 156 int plane; |
| 157 int block; |
| 158 }; |
| 159 |
| 160 // TODO(jkoleszar): returning a struct so it can be used in a const context, |
| 161 // expect to refactor this further later. |
| 162 static INLINE struct plane_block_idx plane_block_idx(int y_blocks, |
| 163 int b_idx) { |
| 164 const int v_offset = y_blocks * 5 / 4; |
| 165 struct plane_block_idx res; |
| 166 |
| 167 if (b_idx < y_blocks) { |
| 168 res.plane = 0; |
| 169 res.block = b_idx; |
| 170 } else if (b_idx < v_offset) { |
| 171 res.plane = 1; |
| 172 res.block = b_idx - y_blocks; |
| 173 } else { |
| 174 assert(b_idx < y_blocks * 3 / 2); |
| 175 res.plane = 2; |
| 176 res.block = b_idx - v_offset; |
| 177 } |
| 178 return res; |
| 179 } |
| 180 |
| 155 void vp9_regular_quantize_b_4x4(MACROBLOCK *mb, int b_idx, TX_TYPE tx_type, | 181 void vp9_regular_quantize_b_4x4(MACROBLOCK *mb, int b_idx, TX_TYPE tx_type, |
| 156 int y_blocks) { | 182 int y_blocks) { |
| 157 MACROBLOCKD *const xd = &mb->e_mbd; | 183 MACROBLOCKD *const xd = &mb->e_mbd; |
| 158 const struct plane_block_idx pb_idx = plane_block_idx(y_blocks, b_idx); | 184 const struct plane_block_idx pb_idx = plane_block_idx(y_blocks, b_idx); |
| 159 const int16_t *scan = get_scan_4x4(tx_type); | 185 const int16_t *scan = get_scan_4x4(tx_type); |
| 160 const int16_t *iscan = get_iscan_4x4(tx_type); | 186 const int16_t *iscan = get_iscan_4x4(tx_type); |
| 161 | 187 |
| 162 vp9_quantize_b(BLOCK_OFFSET(mb->plane[pb_idx.plane].coeff, pb_idx.block, 16), | 188 vp9_quantize_b(BLOCK_OFFSET(mb->plane[pb_idx.plane].coeff, pb_idx.block), |
| 163 16, mb->skip_block, | 189 16, mb->skip_block, |
| 164 mb->plane[pb_idx.plane].zbin, | 190 mb->plane[pb_idx.plane].zbin, |
| 165 mb->plane[pb_idx.plane].round, | 191 mb->plane[pb_idx.plane].round, |
| 166 mb->plane[pb_idx.plane].quant, | 192 mb->plane[pb_idx.plane].quant, |
| 167 mb->plane[pb_idx.plane].quant_shift, | 193 mb->plane[pb_idx.plane].quant_shift, |
| 168 BLOCK_OFFSET(xd->plane[pb_idx.plane].qcoeff, pb_idx.block, 16), | 194 BLOCK_OFFSET(xd->plane[pb_idx.plane].qcoeff, pb_idx.block), |
| 169 BLOCK_OFFSET(xd->plane[pb_idx.plane].dqcoeff, pb_idx.block, 16), | 195 BLOCK_OFFSET(xd->plane[pb_idx.plane].dqcoeff, pb_idx.block), |
| 170 xd->plane[pb_idx.plane].dequant, | 196 xd->plane[pb_idx.plane].dequant, |
| 171 mb->plane[pb_idx.plane].zbin_extra, | 197 mb->plane[pb_idx.plane].zbin_extra, |
| 172 &xd->plane[pb_idx.plane].eobs[pb_idx.block], | 198 &xd->plane[pb_idx.plane].eobs[pb_idx.block], |
| 173 scan, iscan); | 199 scan, iscan); |
| 174 } | 200 } |
| 175 | 201 |
| 176 static void invert_quant(int16_t *quant, int16_t *shift, int d) { | 202 static void invert_quant(int16_t *quant, int16_t *shift, int d) { |
| 177 unsigned t; | 203 unsigned t; |
| 178 int l; | 204 int l; |
| 179 t = d; | 205 t = d; |
| 180 for (l = 0; t > 1; l++) | 206 for (l = 0; t > 1; l++) |
| 181 t >>= 1; | 207 t >>= 1; |
| 182 t = 1 + (1 << (16 + l)) / d; | 208 t = 1 + (1 << (16 + l)) / d; |
| 183 *quant = (int16_t)(t - (1 << 16)); | 209 *quant = (int16_t)(t - (1 << 16)); |
| 184 *shift = 1 << (16 - l); | 210 *shift = 1 << (16 - l); |
| 185 } | 211 } |
| 186 | 212 |
| 187 void vp9_init_quantizer(VP9_COMP *cpi) { | 213 void vp9_init_quantizer(VP9_COMP *cpi) { |
| 188 int i; | 214 int i, q; |
| 189 int quant_val; | 215 VP9_COMMON *const cm = &cpi->common; |
| 190 int quant_uv_val; | |
| 191 #if CONFIG_ALPHA | |
| 192 int quant_alpha_val; | |
| 193 #endif | |
| 194 int q; | |
| 195 | 216 |
| 196 for (q = 0; q < QINDEX_RANGE; q++) { | 217 for (q = 0; q < QINDEX_RANGE; q++) { |
| 197 int qzbin_factor = (vp9_dc_quant(q, 0) < 148) ? 84 : 80; | 218 const int qzbin_factor = q == 0 ? 64 : (vp9_dc_quant(q, 0) < 148 ? 84 : 80); |
| 198 int qrounding_factor = 48; | 219 const int qrounding_factor = q == 0 ? 64 : 48; |
| 199 if (q == 0) { | 220 |
| 200 qzbin_factor = 64; | 221 // y |
| 201 qrounding_factor = 64; | 222 for (i = 0; i < 2; ++i) { |
| 223 const int quant = i == 0 ? vp9_dc_quant(q, cm->y_dc_delta_q) |
| 224 : vp9_ac_quant(q, 0); |
| 225 invert_quant(&cpi->y_quant[q][i], &cpi->y_quant_shift[q][i], quant); |
| 226 cpi->y_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7); |
| 227 cpi->y_round[q][i] = (qrounding_factor * quant) >> 7; |
| 228 cm->y_dequant[q][i] = quant; |
| 202 } | 229 } |
| 203 | 230 |
| 204 // dc values | 231 // uv |
| 205 quant_val = vp9_dc_quant(q, cpi->common.y_dc_delta_q); | 232 for (i = 0; i < 2; ++i) { |
| 206 invert_quant(cpi->y_quant[q] + 0, cpi->y_quant_shift[q] + 0, quant_val); | 233 const int quant = i == 0 ? vp9_dc_quant(q, cm->uv_dc_delta_q) |
| 207 cpi->y_zbin[q][0] = ROUND_POWER_OF_TWO(qzbin_factor * quant_val, 7); | 234 : vp9_ac_quant(q, cm->uv_ac_delta_q); |
| 208 cpi->y_round[q][0] = (qrounding_factor * quant_val) >> 7; | 235 invert_quant(&cpi->uv_quant[q][i], &cpi->uv_quant_shift[q][i], quant); |
| 209 cpi->common.y_dequant[q][0] = quant_val; | 236 cpi->uv_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7); |
| 210 | 237 cpi->uv_round[q][i] = (qrounding_factor * quant) >> 7; |
| 211 quant_val = vp9_dc_quant(q, cpi->common.uv_dc_delta_q); | 238 cm->uv_dequant[q][i] = quant; |
| 212 invert_quant(cpi->uv_quant[q] + 0, cpi->uv_quant_shift[q] + 0, quant_val); | 239 } |
| 213 cpi->uv_zbin[q][0] = ROUND_POWER_OF_TWO(qzbin_factor * quant_val, 7); | |
| 214 cpi->uv_round[q][0] = (qrounding_factor * quant_val) >> 7; | |
| 215 cpi->common.uv_dequant[q][0] = quant_val; | |
| 216 | 240 |
| 217 #if CONFIG_ALPHA | 241 #if CONFIG_ALPHA |
| 218 quant_val = vp9_dc_quant(q, cpi->common.a_dc_delta_q); | 242 // alpha |
| 219 invert_quant(cpi->a_quant[q] + 0, cpi->a_quant_shift[q] + 0, quant_val); | 243 for (i = 0; i < 2; ++i) { |
| 220 cpi->a_zbin[q][0] = ROUND_POWER_OF_TWO(qzbin_factor * quant_val, 7); | 244 const int quant = i == 0 ? vp9_dc_quant(q, cm->a_dc_delta_q) |
| 221 cpi->a_round[q][0] = (qrounding_factor * quant_val) >> 7; | 245 : vp9_ac_quant(q, cm->a_ac_delta_q); |
| 222 cpi->common.a_dequant[q][0] = quant_val; | 246 invert_quant(&cpi->a_quant[q][i], &cpi->a_quant_shift[q][i], quant); |
| 223 #endif | 247 cpi->a_zbin[q][i] = ROUND_POWER_OF_TWO(qzbin_factor * quant, 7); |
| 224 | 248 cpi->a_round[q][i] = (qrounding_factor * quant) >> 7; |
| 225 quant_val = vp9_ac_quant(q, 0); | 249 cm->a_dequant[q][i] = quant; |
| 226 invert_quant(cpi->y_quant[q] + 1, cpi->y_quant_shift[q] + 1, quant_val); | 250 } |
| 227 cpi->y_zbin[q][1] = ROUND_POWER_OF_TWO(qzbin_factor * quant_val, 7); | |
| 228 cpi->y_round[q][1] = (qrounding_factor * quant_val) >> 7; | |
| 229 cpi->common.y_dequant[q][1] = quant_val; | |
| 230 | |
| 231 quant_uv_val = vp9_ac_quant(q, cpi->common.uv_ac_delta_q); | |
| 232 invert_quant(cpi->uv_quant[q] + 1, cpi->uv_quant_shift[q] + 1, | |
| 233 quant_uv_val); | |
| 234 cpi->uv_zbin[q][1] = ROUND_POWER_OF_TWO(qzbin_factor * quant_uv_val, 7); | |
| 235 cpi->uv_round[q][1] = (qrounding_factor * quant_uv_val) >> 7; | |
| 236 cpi->common.uv_dequant[q][1] = quant_uv_val; | |
| 237 | |
| 238 #if CONFIG_ALPHA | |
| 239 quant_alpha_val = vp9_ac_quant(q, cpi->common.a_ac_delta_q); | |
| 240 invert_quant(cpi->a_quant[q] + 1, cpi->a_quant_shift[q] + 1, | |
| 241 quant_alpha_val); | |
| 242 cpi->a_zbin[q][1] = ROUND_POWER_OF_TWO(qzbin_factor * quant_alpha_val, 7); | |
| 243 cpi->a_round[q][1] = (qrounding_factor * quant_alpha_val) >> 7; | |
| 244 cpi->common.a_dequant[q][1] = quant_alpha_val; | |
| 245 #endif | 251 #endif |
| 246 | 252 |
| 247 for (i = 2; i < 8; i++) { | 253 for (i = 2; i < 8; i++) { |
| 248 cpi->y_quant[q][i] = cpi->y_quant[q][1]; | 254 cpi->y_quant[q][i] = cpi->y_quant[q][1]; |
| 249 cpi->y_quant_shift[q][i] = cpi->y_quant_shift[q][1]; | 255 cpi->y_quant_shift[q][i] = cpi->y_quant_shift[q][1]; |
| 250 cpi->y_zbin[q][i] = cpi->y_zbin[q][1]; | 256 cpi->y_zbin[q][i] = cpi->y_zbin[q][1]; |
| 251 cpi->y_round[q][i] = cpi->y_round[q][1]; | 257 cpi->y_round[q][i] = cpi->y_round[q][1]; |
| 252 cpi->common.y_dequant[q][i] = cpi->common.y_dequant[q][1]; | 258 cm->y_dequant[q][i] = cm->y_dequant[q][1]; |
| 253 | 259 |
| 254 cpi->uv_quant[q][i] = cpi->uv_quant[q][1]; | 260 cpi->uv_quant[q][i] = cpi->uv_quant[q][1]; |
| 255 cpi->uv_quant_shift[q][i] = cpi->uv_quant_shift[q][1]; | 261 cpi->uv_quant_shift[q][i] = cpi->uv_quant_shift[q][1]; |
| 256 cpi->uv_zbin[q][i] = cpi->uv_zbin[q][1]; | 262 cpi->uv_zbin[q][i] = cpi->uv_zbin[q][1]; |
| 257 cpi->uv_round[q][i] = cpi->uv_round[q][1]; | 263 cpi->uv_round[q][i] = cpi->uv_round[q][1]; |
| 258 cpi->common.uv_dequant[q][i] = cpi->common.uv_dequant[q][1]; | 264 cm->uv_dequant[q][i] = cm->uv_dequant[q][1]; |
| 259 | 265 |
| 260 #if CONFIG_ALPHA | 266 #if CONFIG_ALPHA |
| 261 cpi->a_quant[q][i] = cpi->a_quant[q][1]; | 267 cpi->a_quant[q][i] = cpi->a_quant[q][1]; |
| 262 cpi->a_quant_shift[q][i] = cpi->a_quant_shift[q][1]; | 268 cpi->a_quant_shift[q][i] = cpi->a_quant_shift[q][1]; |
| 263 cpi->a_zbin[q][i] = cpi->a_zbin[q][1]; | 269 cpi->a_zbin[q][i] = cpi->a_zbin[q][1]; |
| 264 cpi->a_round[q][i] = cpi->a_round[q][1]; | 270 cpi->a_round[q][i] = cpi->a_round[q][1]; |
| 265 cpi->common.a_dequant[q][i] = cpi->common.a_dequant[q][1]; | 271 cm->a_dequant[q][i] = cm->a_dequant[q][1]; |
| 266 #endif | 272 #endif |
| 267 } | 273 } |
| 268 } | 274 } |
| 269 } | 275 } |
| 270 | 276 |
| 271 void vp9_mb_init_quantizer(VP9_COMP *cpi, MACROBLOCK *x) { | 277 void vp9_mb_init_quantizer(VP9_COMP *cpi, MACROBLOCK *x) { |
| 272 int i; | 278 int i; |
| 273 MACROBLOCKD *xd = &x->e_mbd; | 279 MACROBLOCKD *xd = &x->e_mbd; |
| 274 int zbin_extra; | 280 int zbin_extra; |
| 275 int segment_id = xd->mode_info_context->mbmi.segment_id; | 281 int segment_id = xd->mode_info_context->mbmi.segment_id; |
| 276 const int qindex = vp9_get_qindex(xd, segment_id, cpi->common.base_qindex); | 282 const int qindex = vp9_get_qindex(&cpi->common.seg, segment_id, |
| 283 cpi->common.base_qindex); |
| 277 | 284 |
| 278 // Y | 285 // Y |
| 279 zbin_extra = (cpi->common.y_dequant[qindex][1] * | 286 zbin_extra = (cpi->common.y_dequant[qindex][1] * |
| 280 (cpi->zbin_mode_boost + x->act_zbin_adj)) >> 7; | 287 (cpi->zbin_mode_boost + x->act_zbin_adj)) >> 7; |
| 281 | 288 |
| 282 x->plane[0].quant = cpi->y_quant[qindex]; | 289 x->plane[0].quant = cpi->y_quant[qindex]; |
| 283 x->plane[0].quant_shift = cpi->y_quant_shift[qindex]; | 290 x->plane[0].quant_shift = cpi->y_quant_shift[qindex]; |
| 284 x->plane[0].zbin = cpi->y_zbin[qindex]; | 291 x->plane[0].zbin = cpi->y_zbin[qindex]; |
| 285 x->plane[0].round = cpi->y_round[qindex]; | 292 x->plane[0].round = cpi->y_round[qindex]; |
| 286 x->plane[0].zbin_extra = (int16_t)zbin_extra; | 293 x->plane[0].zbin_extra = (int16_t)zbin_extra; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 301 | 308 |
| 302 #if CONFIG_ALPHA | 309 #if CONFIG_ALPHA |
| 303 x->plane[3].quant = cpi->a_quant[qindex]; | 310 x->plane[3].quant = cpi->a_quant[qindex]; |
| 304 x->plane[3].quant_shift = cpi->a_quant_shift[qindex]; | 311 x->plane[3].quant_shift = cpi->a_quant_shift[qindex]; |
| 305 x->plane[3].zbin = cpi->a_zbin[qindex]; | 312 x->plane[3].zbin = cpi->a_zbin[qindex]; |
| 306 x->plane[3].round = cpi->a_round[qindex]; | 313 x->plane[3].round = cpi->a_round[qindex]; |
| 307 x->plane[3].zbin_extra = (int16_t)zbin_extra; | 314 x->plane[3].zbin_extra = (int16_t)zbin_extra; |
| 308 x->e_mbd.plane[3].dequant = cpi->common.a_dequant[qindex]; | 315 x->e_mbd.plane[3].dequant = cpi->common.a_dequant[qindex]; |
| 309 #endif | 316 #endif |
| 310 | 317 |
| 311 x->skip_block = vp9_segfeature_active(&xd->seg, segment_id, SEG_LVL_SKIP); | 318 x->skip_block = vp9_segfeature_active(&cpi->common.seg, segment_id, |
| 319 SEG_LVL_SKIP); |
| 312 | 320 |
| 313 /* save this macroblock QIndex for vp9_update_zbin_extra() */ | 321 /* save this macroblock QIndex for vp9_update_zbin_extra() */ |
| 314 x->e_mbd.q_index = qindex; | 322 x->e_mbd.q_index = qindex; |
| 315 } | 323 } |
| 316 | 324 |
| 317 void vp9_update_zbin_extra(VP9_COMP *cpi, MACROBLOCK *x) { | 325 void vp9_update_zbin_extra(VP9_COMP *cpi, MACROBLOCK *x) { |
| 318 const int qindex = x->e_mbd.q_index; | 326 const int qindex = x->e_mbd.q_index; |
| 319 const int y_zbin_extra = (cpi->common.y_dequant[qindex][1] * | 327 const int y_zbin_extra = (cpi->common.y_dequant[qindex][1] * |
| 320 (cpi->zbin_mode_boost + x->act_zbin_adj)) >> 7; | 328 (cpi->zbin_mode_boost + x->act_zbin_adj)) >> 7; |
| 321 const int uv_zbin_extra = (cpi->common.uv_dequant[qindex][1] * | 329 const int uv_zbin_extra = (cpi->common.uv_dequant[qindex][1] * |
| (...skipping 21 matching lines...) Expand all Loading... |
| 343 // have to be set. | 351 // have to be set. |
| 344 cm->y_dc_delta_q = 0; | 352 cm->y_dc_delta_q = 0; |
| 345 cm->uv_dc_delta_q = 0; | 353 cm->uv_dc_delta_q = 0; |
| 346 cm->uv_ac_delta_q = 0; | 354 cm->uv_ac_delta_q = 0; |
| 347 | 355 |
| 348 // quantizer has to be reinitialized if any delta_q changes. | 356 // quantizer has to be reinitialized if any delta_q changes. |
| 349 // As there are not any here for now this is inactive code. | 357 // As there are not any here for now this is inactive code. |
| 350 // if(update) | 358 // if(update) |
| 351 // vp9_init_quantizer(cpi); | 359 // vp9_init_quantizer(cpi); |
| 352 } | 360 } |
| OLD | NEW |