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" | 11 #include "vpx_mem/vpx_mem.h" |
12 #include "vpx_ports/mem.h" | 12 #include "vpx_ports/mem.h" |
13 | 13 |
14 #include "vp9/common/vp9_blockd.h" | 14 #include "vp9/common/vp9_blockd.h" |
15 #include "vp9/common/vp9_common.h" | 15 #include "vp9/common/vp9_common.h" |
16 #include "vp9/common/vp9_seg_common.h" | 16 #include "vp9/common/vp9_seg_common.h" |
17 | 17 |
| 18 #include "vp9/decoder/vp9_dboolhuff.h" |
18 #include "vp9/decoder/vp9_detokenize.h" | 19 #include "vp9/decoder/vp9_detokenize.h" |
19 #include "vp9/decoder/vp9_onyxd_int.h" | 20 #include "vp9/decoder/vp9_onyxd_int.h" |
| 21 #include "vp9/decoder/vp9_treereader.h" |
20 | 22 |
21 #define EOB_CONTEXT_NODE 0 | 23 #define EOB_CONTEXT_NODE 0 |
22 #define ZERO_CONTEXT_NODE 1 | 24 #define ZERO_CONTEXT_NODE 1 |
23 #define ONE_CONTEXT_NODE 2 | 25 #define ONE_CONTEXT_NODE 2 |
24 #define LOW_VAL_CONTEXT_NODE 3 | 26 #define LOW_VAL_CONTEXT_NODE 3 |
25 #define TWO_CONTEXT_NODE 4 | 27 #define TWO_CONTEXT_NODE 4 |
26 #define THREE_CONTEXT_NODE 5 | 28 #define THREE_CONTEXT_NODE 5 |
27 #define HIGH_LOW_CONTEXT_NODE 6 | 29 #define HIGH_LOW_CONTEXT_NODE 6 |
28 #define CAT_ONE_CONTEXT_NODE 7 | 30 #define CAT_ONE_CONTEXT_NODE 7 |
29 #define CAT_THREEFOUR_CONTEXT_NODE 8 | 31 #define CAT_THREEFOUR_CONTEXT_NODE 8 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 coef_counts[type][ref][band][pt] \ | 68 coef_counts[type][ref][band][pt] \ |
67 [token >= TWO_TOKEN ? \ | 69 [token >= TWO_TOKEN ? \ |
68 (token == DCT_EOB_TOKEN ? DCT_EOB_MODEL_TOKEN : TWO_TOKEN) : \ | 70 (token == DCT_EOB_TOKEN ? DCT_EOB_MODEL_TOKEN : TWO_TOKEN) : \ |
69 token]++; \ | 71 token]++; \ |
70 token_cache[scan[c]] = vp9_pt_energy_class[token]; \ | 72 token_cache[scan[c]] = vp9_pt_energy_class[token]; \ |
71 } while (0) | 73 } while (0) |
72 | 74 |
73 #define WRITE_COEF_CONTINUE(val, token) \ | 75 #define WRITE_COEF_CONTINUE(val, token) \ |
74 { \ | 76 { \ |
75 qcoeff_ptr[scan[c]] = vp9_read_and_apply_sign(r, val) * \ | 77 qcoeff_ptr[scan[c]] = vp9_read_and_apply_sign(r, val) * \ |
76 dq[c > 0] / (1 + (txfm_size == TX_32X32)); \ | 78 dq[c > 0] / (1 + (tx_size == TX_32X32)); \ |
77 INCREMENT_COUNT(token); \ | 79 INCREMENT_COUNT(token); \ |
78 c++; \ | 80 c++; \ |
79 continue; \ | 81 continue; \ |
80 } | 82 } |
81 | 83 |
82 #define ADJUST_COEF(prob, bits_count) \ | 84 #define ADJUST_COEF(prob, bits_count) \ |
83 do { \ | 85 do { \ |
84 if (vp9_read(r, prob)) \ | 86 if (vp9_read(r, prob)) \ |
85 val += 1 << bits_count; \ | 87 val += 1 << bits_count; \ |
86 } while (0); | 88 } while (0); |
87 | 89 |
88 static int decode_coefs(VP9_COMMON *cm, const MACROBLOCKD *xd, | 90 static int decode_coefs(VP9_COMMON *cm, const MACROBLOCKD *xd, |
89 vp9_reader *r, int block_idx, | 91 vp9_reader *r, int block_idx, |
90 PLANE_TYPE type, int seg_eob, int16_t *qcoeff_ptr, | 92 PLANE_TYPE type, int seg_eob, int16_t *qcoeff_ptr, |
91 TX_SIZE txfm_size, const int16_t *dq, | 93 TX_SIZE tx_size, const int16_t *dq, |
92 ENTROPY_CONTEXT *A, ENTROPY_CONTEXT *L) { | 94 ENTROPY_CONTEXT *A, ENTROPY_CONTEXT *L) { |
93 FRAME_CONTEXT *const fc = &cm->fc; | 95 FRAME_CONTEXT *const fc = &cm->fc; |
94 FRAME_COUNTS *const counts = &cm->counts; | 96 FRAME_COUNTS *const counts = &cm->counts; |
95 ENTROPY_CONTEXT above_ec, left_ec; | 97 ENTROPY_CONTEXT above_ec, left_ec; |
96 int pt, c = 0; | 98 const int ref = is_inter_block(&xd->mode_info_context->mbmi); |
97 int band; | 99 int band, pt, c = 0; |
98 vp9_prob (*coef_probs)[PREV_COEF_CONTEXTS][UNCONSTRAINED_NODES]; | 100 vp9_prob (*coef_probs)[PREV_COEF_CONTEXTS][UNCONSTRAINED_NODES] = |
| 101 fc->coef_probs[tx_size][type][ref]; |
99 vp9_prob coef_probs_full[COEF_BANDS][PREV_COEF_CONTEXTS][ENTROPY_NODES]; | 102 vp9_prob coef_probs_full[COEF_BANDS][PREV_COEF_CONTEXTS][ENTROPY_NODES]; |
100 uint8_t load_map[COEF_BANDS][PREV_COEF_CONTEXTS] = { | 103 uint8_t load_map[COEF_BANDS][PREV_COEF_CONTEXTS] = { { 0 } }; |
101 {0, 0, 0, 0, 0, 0}, | |
102 {0, 0, 0, 0, 0, 0}, | |
103 {0, 0, 0, 0, 0, 0}, | |
104 {0, 0, 0, 0, 0, 0}, | |
105 {0, 0, 0, 0, 0, 0}, | |
106 {0, 0, 0, 0, 0, 0}, | |
107 }; | |
108 | |
109 vp9_prob *prob; | 104 vp9_prob *prob; |
110 vp9_coeff_count_model *coef_counts; | 105 vp9_coeff_count_model *coef_counts = counts->coef[tx_size]; |
111 const int ref = xd->mode_info_context->mbmi.ref_frame[0] != INTRA_FRAME; | |
112 const int16_t *scan, *nb; | 106 const int16_t *scan, *nb; |
113 uint8_t token_cache[1024]; | 107 uint8_t token_cache[1024]; |
114 const uint8_t * band_translate; | 108 const uint8_t *band_translate; |
115 coef_probs = fc->coef_probs[txfm_size][type][ref]; | 109 |
116 coef_counts = counts->coef[txfm_size]; | 110 switch (tx_size) { |
117 switch (txfm_size) { | |
118 default: | 111 default: |
119 case TX_4X4: { | 112 case TX_4X4: |
120 scan = get_scan_4x4(get_tx_type_4x4(type, xd, block_idx)); | 113 scan = get_scan_4x4(get_tx_type_4x4(type, xd, block_idx)); |
121 above_ec = A[0] != 0; | 114 above_ec = A[0] != 0; |
122 left_ec = L[0] != 0; | 115 left_ec = L[0] != 0; |
123 band_translate = vp9_coefband_trans_4x4; | 116 band_translate = vp9_coefband_trans_4x4; |
124 break; | 117 break; |
125 } | 118 case TX_8X8: |
126 case TX_8X8: { | |
127 scan = get_scan_8x8(get_tx_type_8x8(type, xd)); | 119 scan = get_scan_8x8(get_tx_type_8x8(type, xd)); |
128 above_ec = (A[0] + A[1]) != 0; | 120 above_ec = !!*(uint16_t *)A; |
129 left_ec = (L[0] + L[1]) != 0; | 121 left_ec = !!*(uint16_t *)L; |
130 band_translate = vp9_coefband_trans_8x8plus; | 122 band_translate = vp9_coefband_trans_8x8plus; |
131 break; | 123 break; |
132 } | 124 case TX_16X16: |
133 case TX_16X16: { | |
134 scan = get_scan_16x16(get_tx_type_16x16(type, xd)); | 125 scan = get_scan_16x16(get_tx_type_16x16(type, xd)); |
135 above_ec = (A[0] + A[1] + A[2] + A[3]) != 0; | 126 above_ec = !!*(uint32_t *)A; |
136 left_ec = (L[0] + L[1] + L[2] + L[3]) != 0; | 127 left_ec = !!*(uint32_t *)L; |
137 band_translate = vp9_coefband_trans_8x8plus; | 128 band_translate = vp9_coefband_trans_8x8plus; |
138 break; | 129 break; |
139 } | |
140 case TX_32X32: | 130 case TX_32X32: |
141 scan = vp9_default_scan_32x32; | 131 scan = vp9_default_scan_32x32; |
142 above_ec = (A[0] + A[1] + A[2] + A[3] + A[4] + A[5] + A[6] + A[7]) != 0; | 132 above_ec = !!*(uint64_t *)A; |
143 left_ec = (L[0] + L[1] + L[2] + L[3] + L[4] + L[5] + L[6] + L[7]) != 0; | 133 left_ec = !!*(uint64_t *)L; |
144 band_translate = vp9_coefband_trans_8x8plus; | 134 band_translate = vp9_coefband_trans_8x8plus; |
145 break; | 135 break; |
146 } | 136 } |
147 | 137 |
148 pt = combine_entropy_contexts(above_ec, left_ec); | 138 pt = combine_entropy_contexts(above_ec, left_ec); |
149 nb = vp9_get_coef_neighbors_handle(scan); | 139 nb = vp9_get_coef_neighbors_handle(scan); |
150 | 140 |
151 while (1) { | 141 while (1) { |
152 int val; | 142 int val; |
153 const uint8_t *cat6 = cat6_prob; | 143 const uint8_t *cat6 = cat6_prob; |
154 if (c >= seg_eob) | 144 if (c >= seg_eob) |
155 break; | 145 break; |
156 if (c) | 146 if (c) |
157 pt = get_coef_context(nb, token_cache, c); | 147 pt = get_coef_context(nb, token_cache, c); |
158 band = get_coef_band(band_translate, c); | 148 band = get_coef_band(band_translate, c); |
159 prob = coef_probs[band][pt]; | 149 prob = coef_probs[band][pt]; |
160 counts->eob_branch[txfm_size][type][ref][band][pt]++; | 150 counts->eob_branch[tx_size][type][ref][band][pt]++; |
161 if (!vp9_read(r, prob[EOB_CONTEXT_NODE])) | 151 if (!vp9_read(r, prob[EOB_CONTEXT_NODE])) |
162 break; | 152 break; |
163 | 153 |
164 SKIP_START: | 154 SKIP_START: |
165 if (c >= seg_eob) | 155 if (c >= seg_eob) |
166 break; | 156 break; |
167 if (c) | 157 if (c) |
168 pt = get_coef_context(nb, token_cache, c); | 158 pt = get_coef_context(nb, token_cache, c); |
169 band = get_coef_band(band_translate, c); | 159 band = get_coef_band(band_translate, c); |
170 prob = coef_probs[band][pt]; | 160 prob = coef_probs[band][pt]; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 static int get_eob(struct segmentation *seg, int segment_id, int eob_max) { | 242 static int get_eob(struct segmentation *seg, int segment_id, int eob_max) { |
253 return vp9_segfeature_active(seg, segment_id, SEG_LVL_SKIP) ? 0 : eob_max; | 243 return vp9_segfeature_active(seg, segment_id, SEG_LVL_SKIP) ? 0 : eob_max; |
254 } | 244 } |
255 | 245 |
256 struct decode_block_args { | 246 struct decode_block_args { |
257 VP9D_COMP *pbi; | 247 VP9D_COMP *pbi; |
258 vp9_reader *r; | 248 vp9_reader *r; |
259 int *eobtotal; | 249 int *eobtotal; |
260 }; | 250 }; |
261 | 251 |
262 static void decode_block(int plane, int block, | 252 static void decode_block(int plane, int block, BLOCK_SIZE plane_bsize, |
263 BLOCK_SIZE_TYPE bsize, | 253 TX_SIZE tx_size, void *argv) { |
264 int ss_txfrm_size, | |
265 void *argv) { | |
266 const struct decode_block_args* const arg = argv; | 254 const struct decode_block_args* const arg = argv; |
267 const int bw = b_width_log2(bsize); | |
268 | 255 |
269 // find the maximum eob for this transform size, adjusted by segment | 256 // find the maximum eob for this transform size, adjusted by segment |
270 MACROBLOCKD *xd = &arg->pbi->mb; | 257 MACROBLOCKD *xd = &arg->pbi->mb; |
| 258 struct segmentation *seg = &arg->pbi->common.seg; |
271 struct macroblockd_plane* pd = &xd->plane[plane]; | 259 struct macroblockd_plane* pd = &xd->plane[plane]; |
272 const int segment_id = xd->mode_info_context->mbmi.segment_id; | 260 const int segment_id = xd->mode_info_context->mbmi.segment_id; |
273 const TX_SIZE ss_tx_size = ss_txfrm_size / 2; | 261 const int ss_txfrm_size = tx_size << 1; |
274 const int seg_eob = get_eob(&xd->seg, segment_id, 16 << ss_txfrm_size); | 262 const int seg_eob = get_eob(seg, segment_id, 16 << ss_txfrm_size); |
275 const int off = block >> ss_txfrm_size; | 263 int aoff, loff, eob; |
276 const int mod = bw - ss_tx_size - pd->subsampling_x; | |
277 const int aoff = (off & ((1 << mod) - 1)) << ss_tx_size; | |
278 const int loff = (off >> mod) << ss_tx_size; | |
279 | 264 |
280 ENTROPY_CONTEXT *A = pd->above_context + aoff; | 265 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &aoff, &loff); |
281 ENTROPY_CONTEXT *L = pd->left_context + loff; | |
282 const int eob = decode_coefs(&arg->pbi->common, xd, arg->r, block, | |
283 pd->plane_type, seg_eob, | |
284 BLOCK_OFFSET(pd->qcoeff, block, 16), | |
285 ss_tx_size, pd->dequant, A, L); | |
286 | 266 |
287 if (xd->mb_to_right_edge < 0 || xd->mb_to_bottom_edge < 0) { | 267 eob = decode_coefs(&arg->pbi->common, xd, arg->r, block, |
288 set_contexts_on_border(xd, bsize, plane, ss_tx_size, eob, aoff, loff, A, L); | 268 pd->plane_type, seg_eob, BLOCK_OFFSET(pd->qcoeff, block), |
289 } else { | 269 tx_size, pd->dequant, |
290 int pt; | 270 pd->above_context + aoff, pd->left_context + loff); |
291 for (pt = 0; pt < (1 << ss_tx_size); pt++) | 271 |
292 A[pt] = L[pt] = eob > 0; | 272 set_contexts(xd, pd, plane_bsize, tx_size, eob > 0, aoff, loff); |
293 } | 273 |
294 pd->eobs[block] = eob; | 274 pd->eobs[block] = eob; |
295 *arg->eobtotal += eob; | 275 *arg->eobtotal += eob; |
296 } | 276 } |
297 | 277 |
298 int vp9_decode_tokens(VP9D_COMP *pbi, vp9_reader *r, BLOCK_SIZE_TYPE bsize) { | 278 int vp9_decode_tokens(VP9D_COMP *pbi, vp9_reader *r, BLOCK_SIZE bsize) { |
299 int eobtotal = 0; | 279 int eobtotal = 0; |
300 struct decode_block_args args = {pbi, r, &eobtotal}; | 280 struct decode_block_args args = {pbi, r, &eobtotal}; |
301 foreach_transformed_block(&pbi->mb, bsize, decode_block, &args); | 281 foreach_transformed_block(&pbi->mb, bsize, decode_block, &args); |
302 return eobtotal; | 282 return eobtotal; |
303 } | 283 } |
OLD | NEW |