| 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 #include "vpx_mem/vpx_mem.h" |
| 12 #include "vpx_ports/mem.h" |
| 11 | 13 |
| 12 #include "vp9/common/vp9_blockd.h" | 14 #include "vp9/common/vp9_blockd.h" |
| 13 #include "vp9/common/vp9_common.h" | 15 #include "vp9/common/vp9_common.h" |
| 16 #include "vp9/common/vp9_seg_common.h" |
| 17 |
| 18 #include "vp9/decoder/vp9_detokenize.h" |
| 14 #include "vp9/decoder/vp9_onyxd_int.h" | 19 #include "vp9/decoder/vp9_onyxd_int.h" |
| 15 #include "vpx_mem/vpx_mem.h" | |
| 16 #include "vpx_ports/mem.h" | |
| 17 #include "vp9/decoder/vp9_detokenize.h" | |
| 18 #include "vp9/common/vp9_seg_common.h" | |
| 19 | 20 |
| 20 #if CONFIG_BALANCED_COEFTREE | 21 #if CONFIG_BALANCED_COEFTREE |
| 21 #define ZERO_CONTEXT_NODE 0 | 22 #define ZERO_CONTEXT_NODE 0 |
| 22 #define EOB_CONTEXT_NODE 1 | 23 #define EOB_CONTEXT_NODE 1 |
| 23 #else | 24 #else |
| 24 #define EOB_CONTEXT_NODE 0 | 25 #define EOB_CONTEXT_NODE 0 |
| 25 #define ZERO_CONTEXT_NODE 1 | 26 #define ZERO_CONTEXT_NODE 1 |
| 26 #endif | 27 #endif |
| 28 |
| 27 #define ONE_CONTEXT_NODE 2 | 29 #define ONE_CONTEXT_NODE 2 |
| 28 #define LOW_VAL_CONTEXT_NODE 3 | 30 #define LOW_VAL_CONTEXT_NODE 3 |
| 29 #define TWO_CONTEXT_NODE 4 | 31 #define TWO_CONTEXT_NODE 4 |
| 30 #define THREE_CONTEXT_NODE 5 | 32 #define THREE_CONTEXT_NODE 5 |
| 31 #define HIGH_LOW_CONTEXT_NODE 6 | 33 #define HIGH_LOW_CONTEXT_NODE 6 |
| 32 #define CAT_ONE_CONTEXT_NODE 7 | 34 #define CAT_ONE_CONTEXT_NODE 7 |
| 33 #define CAT_THREEFOUR_CONTEXT_NODE 8 | 35 #define CAT_THREEFOUR_CONTEXT_NODE 8 |
| 34 #define CAT_THREE_CONTEXT_NODE 9 | 36 #define CAT_THREE_CONTEXT_NODE 9 |
| 35 #define CAT_FIVE_CONTEXT_NODE 10 | 37 #define CAT_FIVE_CONTEXT_NODE 10 |
| 36 | 38 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 c++; \ | 84 c++; \ |
| 83 continue; \ | 85 continue; \ |
| 84 } | 86 } |
| 85 | 87 |
| 86 #define ADJUST_COEF(prob, bits_count) \ | 88 #define ADJUST_COEF(prob, bits_count) \ |
| 87 do { \ | 89 do { \ |
| 88 if (vp9_read(r, prob)) \ | 90 if (vp9_read(r, prob)) \ |
| 89 val += 1 << bits_count; \ | 91 val += 1 << bits_count; \ |
| 90 } while (0); | 92 } while (0); |
| 91 | 93 |
| 92 static int decode_coefs(VP9D_COMP *dx, const MACROBLOCKD *xd, | 94 static int decode_coefs(FRAME_CONTEXT *fc, const MACROBLOCKD *xd, |
| 93 vp9_reader *r, int block_idx, | 95 vp9_reader *r, int block_idx, |
| 94 PLANE_TYPE type, int seg_eob, int16_t *qcoeff_ptr, | 96 PLANE_TYPE type, int seg_eob, int16_t *qcoeff_ptr, |
| 95 TX_SIZE txfm_size, const int16_t *dq, | 97 TX_SIZE txfm_size, const int16_t *dq, |
| 96 ENTROPY_CONTEXT *A, ENTROPY_CONTEXT *L) { | 98 ENTROPY_CONTEXT *A, ENTROPY_CONTEXT *L) { |
| 97 ENTROPY_CONTEXT above_ec, left_ec; | 99 ENTROPY_CONTEXT above_ec, left_ec; |
| 98 FRAME_CONTEXT *const fc = &dx->common.fc; | |
| 99 int pt, c = 0, pad, default_eob; | 100 int pt, c = 0, pad, default_eob; |
| 100 int band; | 101 int band; |
| 101 vp9_prob (*coef_probs)[PREV_COEF_CONTEXTS][UNCONSTRAINED_NODES]; | 102 vp9_prob (*coef_probs)[PREV_COEF_CONTEXTS][UNCONSTRAINED_NODES]; |
| 102 vp9_prob coef_probs_full[COEF_BANDS][PREV_COEF_CONTEXTS][ENTROPY_NODES]; | 103 vp9_prob coef_probs_full[COEF_BANDS][PREV_COEF_CONTEXTS][ENTROPY_NODES]; |
| 103 uint8_t load_map[COEF_BANDS][PREV_COEF_CONTEXTS] = { | 104 uint8_t load_map[COEF_BANDS][PREV_COEF_CONTEXTS] = { |
| 104 {0, 0, 0, 0, 0, 0}, | 105 {0, 0, 0, 0, 0, 0}, |
| 105 {0, 0, 0, 0, 0, 0}, | 106 {0, 0, 0, 0, 0, 0}, |
| 106 {0, 0, 0, 0, 0, 0}, | 107 {0, 0, 0, 0, 0, 0}, |
| 107 {0, 0, 0, 0, 0, 0}, | 108 {0, 0, 0, 0, 0, 0}, |
| 108 {0, 0, 0, 0, 0, 0}, | 109 {0, 0, 0, 0, 0, 0}, |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 | 292 |
| 292 return c; | 293 return c; |
| 293 } | 294 } |
| 294 | 295 |
| 295 static int get_eob(MACROBLOCKD* const xd, int segment_id, int eob_max) { | 296 static int get_eob(MACROBLOCKD* const xd, int segment_id, int eob_max) { |
| 296 return vp9_segfeature_active(xd, segment_id, SEG_LVL_SKIP) ? 0 : eob_max; | 297 return vp9_segfeature_active(xd, segment_id, SEG_LVL_SKIP) ? 0 : eob_max; |
| 297 } | 298 } |
| 298 | 299 |
| 299 struct decode_block_args { | 300 struct decode_block_args { |
| 300 VP9D_COMP *pbi; | 301 VP9D_COMP *pbi; |
| 301 MACROBLOCKD *xd; | |
| 302 vp9_reader *r; | 302 vp9_reader *r; |
| 303 int *eobtotal; | 303 int *eobtotal; |
| 304 }; | 304 }; |
| 305 |
| 305 static void decode_block(int plane, int block, | 306 static void decode_block(int plane, int block, |
| 306 BLOCK_SIZE_TYPE bsize, | 307 BLOCK_SIZE_TYPE bsize, |
| 307 int ss_txfrm_size, | 308 int ss_txfrm_size, |
| 308 void *argv) { | 309 void *argv) { |
| 309 const struct decode_block_args* const arg = argv; | 310 const struct decode_block_args* const arg = argv; |
| 310 const int bw = b_width_log2(bsize); | 311 const int bw = b_width_log2(bsize); |
| 311 | 312 |
| 312 // find the maximum eob for this transform size, adjusted by segment | 313 // find the maximum eob for this transform size, adjusted by segment |
| 313 MACROBLOCKD *xd = arg->xd; | 314 MACROBLOCKD *xd = &arg->pbi->mb; |
| 314 const int segment_id = arg->xd->mode_info_context->mbmi.segment_id; | 315 struct macroblockd_plane* pd = &xd->plane[plane]; |
| 316 const int segment_id = xd->mode_info_context->mbmi.segment_id; |
| 315 const TX_SIZE ss_tx_size = ss_txfrm_size / 2; | 317 const TX_SIZE ss_tx_size = ss_txfrm_size / 2; |
| 316 const int seg_eob = get_eob(arg->xd, segment_id, 16 << ss_txfrm_size); | 318 const int seg_eob = get_eob(xd, segment_id, 16 << ss_txfrm_size); |
| 317 int16_t* const qcoeff_base = arg->xd->plane[plane].qcoeff; | |
| 318 const int off = block >> ss_txfrm_size; | 319 const int off = block >> ss_txfrm_size; |
| 319 const int mod = bw - ss_tx_size - arg->xd->plane[plane].subsampling_x; | 320 const int mod = bw - ss_tx_size - pd->subsampling_x; |
| 320 const int aoff = (off & ((1 << mod) - 1)) << ss_tx_size; | 321 const int aoff = (off & ((1 << mod) - 1)) << ss_tx_size; |
| 321 const int loff = (off >> mod) << ss_tx_size; | 322 const int loff = (off >> mod) << ss_tx_size; |
| 322 int pt; | 323 |
| 323 ENTROPY_CONTEXT *A = arg->xd->plane[plane].above_context + aoff; | 324 ENTROPY_CONTEXT *A = pd->above_context + aoff; |
| 324 ENTROPY_CONTEXT *L = arg->xd->plane[plane].left_context + loff; | 325 ENTROPY_CONTEXT *L = pd->left_context + loff; |
| 325 const int eob = decode_coefs(arg->pbi, arg->xd, arg->r, block, | 326 const int eob = decode_coefs(&arg->pbi->common.fc, xd, arg->r, block, |
| 326 arg->xd->plane[plane].plane_type, seg_eob, | 327 pd->plane_type, seg_eob, |
| 327 BLOCK_OFFSET(qcoeff_base, block, 16), | 328 BLOCK_OFFSET(pd->qcoeff, block, 16), |
| 328 ss_tx_size, arg->xd->plane[plane].dequant, | 329 ss_tx_size, pd->dequant, A, L); |
| 329 A, | |
| 330 L); | |
| 331 | 330 |
| 332 if (xd->mb_to_right_edge < 0 || xd->mb_to_bottom_edge < 0) { | 331 if (xd->mb_to_right_edge < 0 || xd->mb_to_bottom_edge < 0) { |
| 333 set_contexts_on_border(xd, bsize, plane, ss_tx_size, eob, aoff, loff, A, L); | 332 set_contexts_on_border(xd, bsize, plane, ss_tx_size, eob, aoff, loff, A, L); |
| 334 } else { | 333 } else { |
| 335 for (pt = 0; pt < (1 << ss_tx_size); pt++) { | 334 int pt; |
| 335 for (pt = 0; pt < (1 << ss_tx_size); pt++) |
| 336 A[pt] = L[pt] = eob > 0; | 336 A[pt] = L[pt] = eob > 0; |
| 337 } | |
| 338 } | 337 } |
| 339 arg->xd->plane[plane].eobs[block] = eob; | 338 pd->eobs[block] = eob; |
| 340 arg->eobtotal[0] += eob; | 339 *arg->eobtotal += eob; |
| 341 } | 340 } |
| 342 | 341 |
| 343 int vp9_decode_tokens(VP9D_COMP* const pbi, | 342 int vp9_decode_tokens(VP9D_COMP *pbi, vp9_reader *r, BLOCK_SIZE_TYPE bsize) { |
| 344 MACROBLOCKD* const xd, | |
| 345 vp9_reader *r, | |
| 346 BLOCK_SIZE_TYPE bsize) { | |
| 347 int eobtotal = 0; | 343 int eobtotal = 0; |
| 348 struct decode_block_args args = {pbi, xd, r, &eobtotal}; | 344 struct decode_block_args args = {pbi, r, &eobtotal}; |
| 349 foreach_transformed_block(xd, bsize, decode_block, &args); | 345 foreach_transformed_block(&pbi->mb, bsize, decode_block, &args); |
| 350 return eobtotal; | 346 return eobtotal; |
| 351 } | 347 } |
| OLD | NEW |