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

Side by Side Diff: source/libvpx/vp9/decoder/vp9_detokenize.c

Issue 11974002: libvpx: Pull from upstream (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « source/libvpx/vp9/decoder/vp9_detokenize.h ('k') | source/libvpx/vp9/decoder/vp9_idct_blk.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
11 11
12 #include "vp9/common/vp9_type_aliases.h"
13 #include "vp9/common/vp9_blockd.h" 12 #include "vp9/common/vp9_blockd.h"
14 #include "vp9/decoder/vp9_onyxd_int.h" 13 #include "vp9/decoder/vp9_onyxd_int.h"
15 #include "vpx_mem/vpx_mem.h" 14 #include "vpx_mem/vpx_mem.h"
16 #include "vpx_ports/mem.h" 15 #include "vpx_ports/mem.h"
17 #include "vp9/decoder/vp9_detokenize.h" 16 #include "vp9/decoder/vp9_detokenize.h"
18
19 #include "vp9/common/vp9_seg_common.h" 17 #include "vp9/common/vp9_seg_common.h"
20 18
21 #define EOB_CONTEXT_NODE 0 19 #define EOB_CONTEXT_NODE 0
22 #define ZERO_CONTEXT_NODE 1 20 #define ZERO_CONTEXT_NODE 1
23 #define ONE_CONTEXT_NODE 2 21 #define ONE_CONTEXT_NODE 2
24 #define LOW_VAL_CONTEXT_NODE 3 22 #define LOW_VAL_CONTEXT_NODE 3
25 #define TWO_CONTEXT_NODE 4 23 #define TWO_CONTEXT_NODE 4
26 #define THREE_CONTEXT_NODE 5 24 #define THREE_CONTEXT_NODE 5
27 #define HIGH_LOW_CONTEXT_NODE 6 25 #define HIGH_LOW_CONTEXT_NODE 6
28 #define CAT_ONE_CONTEXT_NODE 7 26 #define CAT_ONE_CONTEXT_NODE 7
(...skipping 19 matching lines...) Expand all
48 #define CAT4_PROB1 140 46 #define CAT4_PROB1 140
49 #define CAT4_PROB2 155 47 #define CAT4_PROB2 155
50 #define CAT4_PROB3 176 48 #define CAT4_PROB3 176
51 49
52 #define CAT5_PROB0 130 50 #define CAT5_PROB0 130
53 #define CAT5_PROB1 134 51 #define CAT5_PROB1 134
54 #define CAT5_PROB2 141 52 #define CAT5_PROB2 141
55 #define CAT5_PROB3 157 53 #define CAT5_PROB3 157
56 #define CAT5_PROB4 180 54 #define CAT5_PROB4 180
57 55
58 static const unsigned char cat6_prob[14] = 56 static const vp9_prob cat6_prob[15] = {
59 { 254, 254, 252, 249, 243, 230, 196, 177, 153, 140, 133, 130, 129, 0 }; 57 254, 254, 254, 252, 249, 243, 230, 196, 177, 153, 140, 133, 130, 129, 0
58 };
60 59
61 void vp9_reset_mb_tokens_context(MACROBLOCKD* const xd) { 60 DECLARE_ALIGNED(16, extern const uint8_t, vp9_norm[256]);
62 /* Clear entropy contexts */ 61
63 if ((xd->mode_info_context->mbmi.mode != B_PRED && 62 static int get_signed(BOOL_DECODER *br, int value_to_sign) {
64 xd->mode_info_context->mbmi.mode != I8X8_PRED && 63 return decode_bool(br, 128) ? -value_to_sign : value_to_sign;
65 xd->mode_info_context->mbmi.mode != SPLITMV)
66 || xd->mode_info_context->mbmi.txfm_size == TX_16X16) {
67 vpx_memset(xd->above_context, 0, sizeof(ENTROPY_CONTEXT_PLANES));
68 vpx_memset(xd->left_context, 0, sizeof(ENTROPY_CONTEXT_PLANES));
69 } else {
70 vpx_memset(xd->above_context, 0, sizeof(ENTROPY_CONTEXT_PLANES) - 1);
71 vpx_memset(xd->left_context, 0, sizeof(ENTROPY_CONTEXT_PLANES) - 1);
72 xd->above_context->y2 = 1;
73 xd->left_context->y2 = 1;
74 }
75 } 64 }
76 65
77 DECLARE_ALIGNED(16, extern const unsigned char, vp9_norm[256]); 66 #if CONFIG_NEWCOEFCONTEXT
78 67 #define PT pn
79 static int get_signed(BOOL_DECODER *br, int value_to_sign) { 68 #define INCREMENT_COUNT(token) \
80 const int split = (br->range + 1) >> 1; 69 do { \
81 const VP9_BD_VALUE bigsplit = (VP9_BD_VALUE)split << (VP9_BD_VALUE_SIZE - 8); 70 coef_counts[type][coef_bands[c]][pn][token]++; \
82 int v; 71 pn = pt = vp9_prev_token_class[token]; \
83 72 if (c < seg_eob - 1 && NEWCOEFCONTEXT_BAND_COND(coef_bands[c + 1])) \
84 if (br->count < 0) 73 pn = vp9_get_coef_neighbor_context( \
85 vp9_bool_decoder_fill(br); 74 qcoeff_ptr, nodc, neighbors, scan[c + 1]); \
86 75 } while (0)
87 if (br->value < bigsplit) { 76 #else
88 br->range = split; 77 #define PT pt
89 v = value_to_sign;
90 } else {
91 br->range = br->range - split;
92 br->value = br->value - bigsplit;
93 v = -value_to_sign;
94 }
95 br->range += br->range;
96 br->value += br->value;
97 --br->count;
98
99 return v;
100 }
101
102 #define INCREMENT_COUNT(token) \ 78 #define INCREMENT_COUNT(token) \
103 do { \ 79 do { \
104 coef_counts[coef_bands[c]][pt][token]++; \ 80 coef_counts[type][coef_bands[c]][pt][token]++; \
105 pt = vp9_prev_token_class[token]; \ 81 pt = vp9_prev_token_class[token]; \
106 } while (0) 82 } while (0)
83 #endif /* CONFIG_NEWCOEFCONTEXT */
107 84
108 #define WRITE_COEF_CONTINUE(val, token) \ 85 #define WRITE_COEF_CONTINUE(val, token) \
109 { \ 86 { \
110 qcoeff_ptr[scan[c]] = (INT16) get_signed(br, val); \ 87 qcoeff_ptr[scan[c]] = (int16_t) get_signed(br, val); \
111 INCREMENT_COUNT(token); \ 88 INCREMENT_COUNT(token); \
112 c++; \ 89 c++; \
113 continue; \ 90 continue; \
114 } 91 }
115 92
116 #define ADJUST_COEF(prob, bits_count) \ 93 #define ADJUST_COEF(prob, bits_count) \
117 do { \ 94 do { \
118 if (vp9_read(br, prob)) \ 95 if (vp9_read(br, prob)) \
119 val += (UINT16)(1 << bits_count);\ 96 val += (uint16_t)(1 << bits_count);\
120 } while (0); 97 } while (0);
121 98
122 static int decode_coefs(VP9D_COMP *dx, const MACROBLOCKD *xd, 99 static int decode_coefs(VP9D_COMP *dx, const MACROBLOCKD *xd,
123 BOOL_DECODER* const br, 100 BOOL_DECODER* const br,
124 ENTROPY_CONTEXT *a, ENTROPY_CONTEXT *l, 101 ENTROPY_CONTEXT *a, ENTROPY_CONTEXT *l,
125 PLANE_TYPE type, 102 PLANE_TYPE type,
126 TX_TYPE tx_type, 103 TX_TYPE tx_type,
127 int seg_eob, INT16 *qcoeff_ptr, 104 int seg_eob, int16_t *qcoeff_ptr,
128 const int *const scan, TX_SIZE txfm_size, 105 const int *const scan, TX_SIZE txfm_size,
129 const int *coef_bands) { 106 const int *coef_bands) {
130 FRAME_CONTEXT *const fc = &dx->common.fc; 107 FRAME_CONTEXT *const fc = &dx->common.fc;
131 int pt, c = (type == PLANE_TYPE_Y_NO_DC); 108 #if CONFIG_NEWCOEFCONTEXT
132 vp9_prob (*coef_probs)[PREV_COEF_CONTEXTS][ENTROPY_NODES], *prob; 109 const int *neighbors;
133 unsigned int (*coef_counts)[PREV_COEF_CONTEXTS][MAX_ENTROPY_TOKENS]; 110 int pn;
111 #endif
112 int nodc = (type == PLANE_TYPE_Y_NO_DC);
113 int pt, c = nodc;
114 vp9_coeff_probs *coef_probs;
115 vp9_prob *prob;
116 vp9_coeff_count *coef_counts;
134 117
135 switch (txfm_size) { 118 switch (txfm_size) {
136 default: 119 default:
137 case TX_4X4: 120 case TX_4X4:
138 if (tx_type == DCT_DCT) { 121 if (tx_type == DCT_DCT) {
139 coef_probs = fc->coef_probs[type]; 122 coef_probs = fc->coef_probs_4x4;
140 coef_counts = fc->coef_counts[type]; 123 coef_counts = fc->coef_counts_4x4;
141 } else { 124 } else {
142 coef_probs = fc->hybrid_coef_probs[type]; 125 coef_probs = fc->hybrid_coef_probs_4x4;
143 coef_counts = fc->hybrid_coef_counts[type]; 126 coef_counts = fc->hybrid_coef_counts_4x4;
144 } 127 }
145 break; 128 break;
146 case TX_8X8: 129 case TX_8X8:
147 if (tx_type == DCT_DCT) { 130 if (tx_type == DCT_DCT) {
148 coef_probs = fc->coef_probs_8x8[type]; 131 coef_probs = fc->coef_probs_8x8;
149 coef_counts = fc->coef_counts_8x8[type]; 132 coef_counts = fc->coef_counts_8x8;
150 } else { 133 } else {
151 coef_probs = fc->hybrid_coef_probs_8x8[type]; 134 coef_probs = fc->hybrid_coef_probs_8x8;
152 coef_counts = fc->hybrid_coef_counts_8x8[type]; 135 coef_counts = fc->hybrid_coef_counts_8x8;
153 } 136 }
154 break; 137 break;
155 case TX_16X16: 138 case TX_16X16:
156 if (tx_type == DCT_DCT) { 139 if (tx_type == DCT_DCT) {
157 coef_probs = fc->coef_probs_16x16[type]; 140 coef_probs = fc->coef_probs_16x16;
158 coef_counts = fc->coef_counts_16x16[type]; 141 coef_counts = fc->coef_counts_16x16;
159 } else { 142 } else {
160 coef_probs = fc->hybrid_coef_probs_16x16[type]; 143 coef_probs = fc->hybrid_coef_probs_16x16;
161 coef_counts = fc->hybrid_coef_counts_16x16[type]; 144 coef_counts = fc->hybrid_coef_counts_16x16;
162 } 145 }
163 break; 146 break;
147 case TX_32X32:
148 coef_probs = fc->coef_probs_32x32;
149 coef_counts = fc->coef_counts_32x32;
150 break;
164 } 151 }
165 152
166 VP9_COMBINEENTROPYCONTEXTS(pt, *a, *l); 153 VP9_COMBINEENTROPYCONTEXTS(pt, *a, *l);
154 #if CONFIG_NEWCOEFCONTEXT
155 pn = pt;
156 neighbors = vp9_get_coef_neighbors_handle(scan);
157 #endif
167 while (1) { 158 while (1) {
168 int val; 159 int val;
169 const uint8_t *cat6 = cat6_prob; 160 const uint8_t *cat6 = cat6_prob;
170 if (c >= seg_eob) break; 161 if (c >= seg_eob) break;
171 prob = coef_probs[coef_bands[c]][pt]; 162 prob = coef_probs[type][coef_bands[c]][PT];
172 if (!vp9_read(br, prob[EOB_CONTEXT_NODE])) 163 if (!vp9_read(br, prob[EOB_CONTEXT_NODE]))
173 break; 164 break;
174 SKIP_START: 165 SKIP_START:
175 if (c >= seg_eob) break; 166 if (c >= seg_eob) break;
176 if (!vp9_read(br, prob[ZERO_CONTEXT_NODE])) { 167 if (!vp9_read(br, prob[ZERO_CONTEXT_NODE])) {
177 INCREMENT_COUNT(ZERO_TOKEN); 168 INCREMENT_COUNT(ZERO_TOKEN);
178 ++c; 169 ++c;
179 prob = coef_probs[coef_bands[c]][pt]; 170 prob = coef_probs[type][coef_bands[c]][PT];
180 goto SKIP_START; 171 goto SKIP_START;
181 } 172 }
182 // ONE_CONTEXT_NODE_0_ 173 // ONE_CONTEXT_NODE_0_
183 if (!vp9_read(br, prob[ONE_CONTEXT_NODE])) { 174 if (!vp9_read(br, prob[ONE_CONTEXT_NODE])) {
184 WRITE_COEF_CONTINUE(1, ONE_TOKEN); 175 WRITE_COEF_CONTINUE(1, ONE_TOKEN);
185 } 176 }
186 // LOW_VAL_CONTEXT_NODE_0_ 177 // LOW_VAL_CONTEXT_NODE_0_
187 if (!vp9_read(br, prob[LOW_VAL_CONTEXT_NODE])) { 178 if (!vp9_read(br, prob[LOW_VAL_CONTEXT_NODE])) {
188 if (!vp9_read(br, prob[TWO_CONTEXT_NODE])) { 179 if (!vp9_read(br, prob[TWO_CONTEXT_NODE])) {
189 WRITE_COEF_CONTINUE(2, TWO_TOKEN); 180 WRITE_COEF_CONTINUE(2, TWO_TOKEN);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 } 224 }
234 val = 0; 225 val = 0;
235 while (*cat6) { 226 while (*cat6) {
236 val = (val << 1) | vp9_read(br, *cat6++); 227 val = (val << 1) | vp9_read(br, *cat6++);
237 } 228 }
238 val += CAT6_MIN_VAL; 229 val += CAT6_MIN_VAL;
239 WRITE_COEF_CONTINUE(val, DCT_VAL_CATEGORY6); 230 WRITE_COEF_CONTINUE(val, DCT_VAL_CATEGORY6);
240 } 231 }
241 232
242 if (c < seg_eob) 233 if (c < seg_eob)
243 coef_counts[coef_bands[c]][pt][DCT_EOB_TOKEN]++; 234 coef_counts[type][coef_bands[c]][PT][DCT_EOB_TOKEN]++;
244 235
245 a[0] = l[0] = (c > !type); 236 a[0] = l[0] = (c > !type);
246 237
247 return c; 238 return c;
248 } 239 }
249 240
250 static int get_eob(MACROBLOCKD* const xd, int segment_id, int eob_max) { 241 static int get_eob(MACROBLOCKD* const xd, int segment_id, int eob_max) {
251 int active = vp9_segfeature_active(xd, segment_id, SEG_LVL_EOB); 242 int active = vp9_segfeature_active(xd, segment_id, SEG_LVL_EOB);
252 int eob = vp9_get_segdata(xd, segment_id, SEG_LVL_EOB); 243 int eob = vp9_get_segdata(xd, segment_id, SEG_LVL_EOB);
253 244
254 if (!active || eob > eob_max) 245 if (!active || eob > eob_max)
255 eob = eob_max; 246 eob = eob_max;
256 return eob; 247 return eob;
257 } 248 }
258 249
250 int vp9_decode_sb_tokens(VP9D_COMP* const pbi,
251 MACROBLOCKD* const xd,
252 BOOL_DECODER* const bc) {
253 ENTROPY_CONTEXT* const A = (ENTROPY_CONTEXT *)xd->above_context;
254 ENTROPY_CONTEXT* const L = (ENTROPY_CONTEXT *)xd->left_context;
255 ENTROPY_CONTEXT* const A1 = (ENTROPY_CONTEXT *)(&xd->above_context[1]);
256 ENTROPY_CONTEXT* const L1 = (ENTROPY_CONTEXT *)(&xd->left_context[1]);
257 uint16_t *const eobs = xd->eobs;
258 const int segment_id = xd->mode_info_context->mbmi.segment_id;
259 int c, i, eobtotal = 0, seg_eob;
260
261 // Luma block
262 #if CONFIG_CNVCONTEXT
263 ENTROPY_CONTEXT above_ec = (A[0] + A[1] + A[2] + A[3] +
264 A1[0] + A1[1] + A1[2] + A1[3]) != 0;
265 ENTROPY_CONTEXT left_ec = (L[0] + L[1] + L[2] + L[3] +
266 L1[0] + L1[1] + L1[2] + L1[3]) != 0;
267 #else
268 ENTROPY_CONTEXT above_ec = A[0];
269 ENTROPY_CONTEXT left_ec = L[0];
270 #endif
271 eobs[0] = c = decode_coefs(pbi, xd, bc, &above_ec, &left_ec,
272 PLANE_TYPE_Y_WITH_DC,
273 DCT_DCT, get_eob(xd, segment_id, 1024),
274 xd->sb_coeff_data.qcoeff,
275 vp9_default_zig_zag1d_32x32,
276 TX_32X32, vp9_coef_bands_32x32);
277 A[1] = A[2] = A[3] = A[0] = above_ec;
278 L[1] = L[2] = L[3] = L[0] = left_ec;
279 A1[1] = A1[2] = A1[3] = A1[0] = above_ec;
280 L1[1] = L1[2] = L1[3] = L1[0] = left_ec;
281
282 eobtotal += c;
283
284 // 16x16 chroma blocks
285 seg_eob = get_eob(xd, segment_id, 256);
286
287 for (i = 16; i < 24; i += 4) {
288 ENTROPY_CONTEXT* const a = A + vp9_block2above[TX_16X16][i];
289 ENTROPY_CONTEXT* const l = L + vp9_block2left[TX_16X16][i];
290 ENTROPY_CONTEXT* const a1 = A1 + vp9_block2above[TX_16X16][i];
291 ENTROPY_CONTEXT* const l1 = L1 + vp9_block2left[TX_16X16][i];
292 #if CONFIG_CNVCONTEXT
293 above_ec = (a[0] + a[1] + a1[0] + a1[1]) != 0;
294 left_ec = (l[0] + l[1] + l1[0] + l1[1]) != 0;
295 #else
296 above_ec = a[0];
297 left_ec = l[0];
298 #endif
299
300 eobs[i] = c = decode_coefs(pbi, xd, bc,
301 &above_ec, &left_ec,
302 PLANE_TYPE_UV,
303 DCT_DCT, seg_eob,
304 xd->sb_coeff_data.qcoeff + 1024 + (i - 16) * 64,
305 vp9_default_zig_zag1d_16x16,
306 TX_16X16, vp9_coef_bands_16x16);
307
308 a1[1] = a1[0] = a[1] = a[0] = above_ec;
309 l1[1] = l1[0] = l[1] = l[0] = left_ec;
310 eobtotal += c;
311 }
312 // no Y2 block
313 A[8] = L[8] = A1[8] = L1[8] = 0;
314 return eobtotal;
315 }
259 316
260 static int vp9_decode_mb_tokens_16x16(VP9D_COMP* const pbi, 317 static int vp9_decode_mb_tokens_16x16(VP9D_COMP* const pbi,
261 MACROBLOCKD* const xd, 318 MACROBLOCKD* const xd,
262 BOOL_DECODER* const bc) { 319 BOOL_DECODER* const bc) {
263 ENTROPY_CONTEXT* const A = (ENTROPY_CONTEXT *)xd->above_context; 320 ENTROPY_CONTEXT* const A = (ENTROPY_CONTEXT *)xd->above_context;
264 ENTROPY_CONTEXT* const L = (ENTROPY_CONTEXT *)xd->left_context; 321 ENTROPY_CONTEXT* const L = (ENTROPY_CONTEXT *)xd->left_context;
265 unsigned short* const eobs = xd->eobs; 322 uint16_t *const eobs = xd->eobs;
266 const int segment_id = xd->mode_info_context->mbmi.segment_id; 323 const int segment_id = xd->mode_info_context->mbmi.segment_id;
267 int c, i, eobtotal = 0, seg_eob; 324 int c, i, eobtotal = 0, seg_eob;
325 // Luma block
268 326
269 // Luma block 327 #if CONFIG_CNVCONTEXT
270 eobs[0] = c = decode_coefs(pbi, xd, bc, A, L, PLANE_TYPE_Y_WITH_DC, 328 ENTROPY_CONTEXT above_ec = (A[0] + A[1] + A[2] + A[3]) != 0;
329 ENTROPY_CONTEXT left_ec = (L[0] + L[1] + L[2] + L[3]) != 0;
330 #else
331 ENTROPY_CONTEXT above_ec = A[0];
332 ENTROPY_CONTEXT left_ec = L[0];
333 #endif
334 eobs[0] = c = decode_coefs(pbi, xd, bc, &above_ec, &left_ec,
335 PLANE_TYPE_Y_WITH_DC,
271 get_tx_type(xd, &xd->block[0]), 336 get_tx_type(xd, &xd->block[0]),
272 get_eob(xd, segment_id, 256), 337 get_eob(xd, segment_id, 256),
273 xd->qcoeff, vp9_default_zig_zag1d_16x16, 338 xd->qcoeff, vp9_default_zig_zag1d_16x16,
274 TX_16X16, vp9_coef_bands_16x16); 339 TX_16X16, vp9_coef_bands_16x16);
275 A[1] = A[2] = A[3] = A[0]; 340 A[1] = A[2] = A[3] = A[0] = above_ec;
276 L[1] = L[2] = L[3] = L[0]; 341 L[1] = L[2] = L[3] = L[0] = left_ec;
277 eobtotal += c; 342 eobtotal += c;
278 343
279 // 8x8 chroma blocks 344 // 8x8 chroma blocks
280 seg_eob = get_eob(xd, segment_id, 64); 345 seg_eob = get_eob(xd, segment_id, 64);
281 for (i = 16; i < 24; i += 4) { 346 for (i = 16; i < 24; i += 4) {
282 ENTROPY_CONTEXT* const a = A + vp9_block2above_8x8[i]; 347 ENTROPY_CONTEXT* const a = A + vp9_block2above[TX_8X8][i];
283 ENTROPY_CONTEXT* const l = L + vp9_block2left_8x8[i]; 348 ENTROPY_CONTEXT* const l = L + vp9_block2left[TX_8X8][i];
284 349 #if CONFIG_CNVCONTEXT
285 eobs[i] = c = decode_coefs(pbi, xd, bc, a, l, PLANE_TYPE_UV, 350 above_ec = (a[0] + a[1]) != 0;
351 left_ec = (l[0] + l[1]) != 0;
352 #else
353 above_ec = a[0];
354 left_ec = l[0];
355 #endif
356 eobs[i] = c = decode_coefs(pbi, xd, bc,
357 &above_ec, &left_ec,
358 PLANE_TYPE_UV,
286 DCT_DCT, seg_eob, xd->block[i].qcoeff, 359 DCT_DCT, seg_eob, xd->block[i].qcoeff,
287 vp9_default_zig_zag1d_8x8, 360 vp9_default_zig_zag1d_8x8,
288 TX_8X8, vp9_coef_bands_8x8); 361 TX_8X8, vp9_coef_bands_8x8);
289 a[1] = a[0]; 362 a[1] = a[0] = above_ec;
290 l[1] = l[0]; 363 l[1] = l[0] = left_ec;
291 eobtotal += c; 364 eobtotal += c;
292 } 365 }
293 A[8] = 0; 366 A[8] = 0;
294 L[8] = 0; 367 L[8] = 0;
295 return eobtotal; 368 return eobtotal;
296 } 369 }
297 370
298 static int vp9_decode_mb_tokens_8x8(VP9D_COMP* const pbi, 371 static int vp9_decode_mb_tokens_8x8(VP9D_COMP* const pbi,
299 MACROBLOCKD* const xd, 372 MACROBLOCKD* const xd,
300 BOOL_DECODER* const bc) { 373 BOOL_DECODER* const bc) {
301 ENTROPY_CONTEXT *const A = (ENTROPY_CONTEXT *)xd->above_context; 374 ENTROPY_CONTEXT *const A = (ENTROPY_CONTEXT *)xd->above_context;
302 ENTROPY_CONTEXT *const L = (ENTROPY_CONTEXT *)xd->left_context; 375 ENTROPY_CONTEXT *const L = (ENTROPY_CONTEXT *)xd->left_context;
303 unsigned short *const eobs = xd->eobs; 376 uint16_t *const eobs = xd->eobs;
304 PLANE_TYPE type; 377 PLANE_TYPE type;
305 int c, i, eobtotal = 0, seg_eob; 378 int c, i, eobtotal = 0, seg_eob;
306 const int segment_id = xd->mode_info_context->mbmi.segment_id; 379 const int segment_id = xd->mode_info_context->mbmi.segment_id;
307 380
308 int has_2nd_order = get_2nd_order_usage(xd); 381 int has_2nd_order = get_2nd_order_usage(xd);
309 // 2nd order DC block 382 // 2nd order DC block
310 if (has_2nd_order) { 383 if (has_2nd_order) {
311 ENTROPY_CONTEXT *const a = A + vp9_block2above_8x8[24]; 384 ENTROPY_CONTEXT *const a = A + vp9_block2above[TX_8X8][24];
312 ENTROPY_CONTEXT *const l = L + vp9_block2left_8x8[24]; 385 ENTROPY_CONTEXT *const l = L + vp9_block2left[TX_8X8][24];
313 386
314 eobs[24] = c = decode_coefs(pbi, xd, bc, a, l, PLANE_TYPE_Y2, 387 eobs[24] = c = decode_coefs(pbi, xd, bc, a, l, PLANE_TYPE_Y2,
315 DCT_DCT, get_eob(xd, segment_id, 4), 388 DCT_DCT, get_eob(xd, segment_id, 4),
316 xd->block[24].qcoeff, 389 xd->block[24].qcoeff,
317 vp9_default_zig_zag1d, TX_8X8, vp9_coef_bands); 390 vp9_default_zig_zag1d_4x4, TX_8X8,
391 vp9_coef_bands_4x4);
318 eobtotal += c - 4; 392 eobtotal += c - 4;
319 type = PLANE_TYPE_Y_NO_DC; 393 type = PLANE_TYPE_Y_NO_DC;
320 } else { 394 } else {
321 xd->above_context->y2 = 1; 395 xd->above_context->y2 = 0;
322 xd->left_context->y2 = 1; 396 xd->left_context->y2 = 0;
323 eobs[24] = 0; 397 eobs[24] = 0;
324 type = PLANE_TYPE_Y_WITH_DC; 398 type = PLANE_TYPE_Y_WITH_DC;
325 } 399 }
326 400
327 // luma blocks 401 // luma blocks
328 seg_eob = get_eob(xd, segment_id, 64); 402 seg_eob = get_eob(xd, segment_id, 64);
329 for (i = 0; i < 16; i += 4) { 403 for (i = 0; i < 16; i += 4) {
330 ENTROPY_CONTEXT *const a = A + vp9_block2above_8x8[i]; 404 ENTROPY_CONTEXT *const a = A + vp9_block2above[TX_8X8][i];
331 ENTROPY_CONTEXT *const l = L + vp9_block2left_8x8[i]; 405 ENTROPY_CONTEXT *const l = L + vp9_block2left[TX_8X8][i];
332 406 #if CONFIG_CNVCONTEXT
333 eobs[i] = c = decode_coefs(pbi, xd, bc, a, l, type, 407 ENTROPY_CONTEXT above_ec = (a[0] + a[1]) != 0;
408 ENTROPY_CONTEXT left_ec = (l[0] + l[1]) != 0;
409 #else
410 ENTROPY_CONTEXT above_ec = a[0];
411 ENTROPY_CONTEXT left_ec = l[0];
412 #endif
413 eobs[i] = c = decode_coefs(pbi, xd, bc, &above_ec, &left_ec, type,
334 type == PLANE_TYPE_Y_WITH_DC ? 414 type == PLANE_TYPE_Y_WITH_DC ?
335 get_tx_type(xd, xd->block + i) : DCT_DCT, 415 get_tx_type(xd, xd->block + i) : DCT_DCT,
336 seg_eob, xd->block[i].qcoeff, 416 seg_eob, xd->block[i].qcoeff,
337 vp9_default_zig_zag1d_8x8, 417 vp9_default_zig_zag1d_8x8,
338 TX_8X8, vp9_coef_bands_8x8); 418 TX_8X8, vp9_coef_bands_8x8);
339 a[1] = a[0]; 419 a[1] = a[0] = above_ec;
340 l[1] = l[0]; 420 l[1] = l[0] = left_ec;
341 eobtotal += c; 421 eobtotal += c;
342 } 422 }
343 423
344 // chroma blocks 424 // chroma blocks
345 if (xd->mode_info_context->mbmi.mode == I8X8_PRED || 425 if (xd->mode_info_context->mbmi.mode == I8X8_PRED ||
346 xd->mode_info_context->mbmi.mode == SPLITMV) { 426 xd->mode_info_context->mbmi.mode == SPLITMV) {
347 // use 4x4 transform for U, V components in I8X8/splitmv prediction mode 427 // use 4x4 transform for U, V components in I8X8/splitmv prediction mode
348 seg_eob = get_eob(xd, segment_id, 16); 428 seg_eob = get_eob(xd, segment_id, 16);
349 for (i = 16; i < 24; i++) { 429 for (i = 16; i < 24; i++) {
350 ENTROPY_CONTEXT *const a = A + vp9_block2above[i]; 430 ENTROPY_CONTEXT *const a = A + vp9_block2above[TX_4X4][i];
351 ENTROPY_CONTEXT *const l = L + vp9_block2left[i]; 431 ENTROPY_CONTEXT *const l = L + vp9_block2left[TX_4X4][i];
352 432
353 eobs[i] = c = decode_coefs(pbi, xd, bc, a, l, PLANE_TYPE_UV, 433 eobs[i] = c = decode_coefs(pbi, xd, bc, a, l, PLANE_TYPE_UV,
354 DCT_DCT, seg_eob, xd->block[i].qcoeff, 434 DCT_DCT, seg_eob, xd->block[i].qcoeff,
355 vp9_default_zig_zag1d, TX_4X4, vp9_coef_bands); 435 vp9_default_zig_zag1d_4x4, TX_4X4,
436 vp9_coef_bands_4x4);
356 eobtotal += c; 437 eobtotal += c;
357 } 438 }
358 } else { 439 } else {
359 for (i = 16; i < 24; i += 4) { 440 for (i = 16; i < 24; i += 4) {
360 ENTROPY_CONTEXT *const a = A + vp9_block2above_8x8[i]; 441 ENTROPY_CONTEXT *const a = A + vp9_block2above[TX_8X8][i];
361 ENTROPY_CONTEXT *const l = L + vp9_block2left_8x8[i]; 442 ENTROPY_CONTEXT *const l = L + vp9_block2left[TX_8X8][i];
362 443 #if CONFIG_CNVCONTEXT
363 eobs[i] = c = decode_coefs(pbi, xd, bc, a, l, PLANE_TYPE_UV, 444 ENTROPY_CONTEXT above_ec = (a[0] + a[1]) != 0;
445 ENTROPY_CONTEXT left_ec = (l[0] + l[1]) != 0;
446 #else
447 ENTROPY_CONTEXT above_ec = a[0];
448 ENTROPY_CONTEXT left_ec = l[0];
449 #endif
450 eobs[i] = c = decode_coefs(pbi, xd, bc,
451 &above_ec, &left_ec,
452 PLANE_TYPE_UV,
364 DCT_DCT, seg_eob, xd->block[i].qcoeff, 453 DCT_DCT, seg_eob, xd->block[i].qcoeff,
365 vp9_default_zig_zag1d_8x8, 454 vp9_default_zig_zag1d_8x8,
366 TX_8X8, vp9_coef_bands_8x8); 455 TX_8X8, vp9_coef_bands_8x8);
367 a[1] = a[0]; 456 a[1] = a[0] = above_ec;
368 l[1] = l[0]; 457 l[1] = l[0] = left_ec;
369 eobtotal += c; 458 eobtotal += c;
370 } 459 }
371 } 460 }
372 461
373 return eobtotal; 462 return eobtotal;
374 } 463 }
375 464
465 static int decode_coefs_4x4(VP9D_COMP *dx, MACROBLOCKD *xd,
466 BOOL_DECODER* const bc,
467 PLANE_TYPE type, int i, int seg_eob,
468 TX_TYPE tx_type, const int *scan) {
469 ENTROPY_CONTEXT *const A = (ENTROPY_CONTEXT *)xd->above_context;
470 ENTROPY_CONTEXT *const L = (ENTROPY_CONTEXT *)xd->left_context;
471 ENTROPY_CONTEXT *const a = A + vp9_block2above[TX_4X4][i];
472 ENTROPY_CONTEXT *const l = L + vp9_block2left[TX_4X4][i];
473 uint16_t *const eobs = xd->eobs;
474 int c;
475
476 c = decode_coefs(dx, xd, bc, a, l, type, tx_type, seg_eob,
477 xd->block[i].qcoeff, scan, TX_4X4, vp9_coef_bands_4x4);
478 eobs[i] = c;
479
480 return c;
481 }
482
483 static int decode_coefs_4x4_y(VP9D_COMP *dx, MACROBLOCKD *xd,
484 BOOL_DECODER* const bc,
485 PLANE_TYPE type, int i, int seg_eob) {
486 const TX_TYPE tx_type = (type == PLANE_TYPE_Y_WITH_DC) ?
487 get_tx_type(xd, &xd->block[i]) : DCT_DCT;
488 const int *scan;
489
490 switch (tx_type) {
491 case ADST_DCT:
492 scan = vp9_row_scan_4x4;
493 break;
494 case DCT_ADST:
495 scan = vp9_col_scan_4x4;
496 break;
497 default:
498 scan = vp9_default_zig_zag1d_4x4;
499 break;
500 }
501
502 return decode_coefs_4x4(dx, xd, bc, type, i, seg_eob, tx_type, scan);
503 }
504
376 int vp9_decode_coefs_4x4(VP9D_COMP *dx, MACROBLOCKD *xd, 505 int vp9_decode_coefs_4x4(VP9D_COMP *dx, MACROBLOCKD *xd,
377 BOOL_DECODER* const bc, 506 BOOL_DECODER* const bc,
378 PLANE_TYPE type, int i) { 507 PLANE_TYPE type, int i) {
379 ENTROPY_CONTEXT *const A = (ENTROPY_CONTEXT *)xd->above_context; 508 const int segment_id = xd->mode_info_context->mbmi.segment_id;
380 ENTROPY_CONTEXT *const L = (ENTROPY_CONTEXT *)xd->left_context; 509 const int seg_eob = get_eob(xd, segment_id, 16);
381 ENTROPY_CONTEXT *const a = A + vp9_block2above[i];
382 ENTROPY_CONTEXT *const l = L + vp9_block2left[i];
383 INT16 *qcoeff_ptr = &xd->qcoeff[0];
384 const int *scan = vp9_default_zig_zag1d;
385 unsigned short *const eobs = xd->eobs;
386 int segment_id = xd->mode_info_context->mbmi.segment_id;
387 int c, seg_eob = get_eob(xd, segment_id, 16);
388 TX_TYPE tx_type = DCT_DCT;
389 510
390 if (type == PLANE_TYPE_Y_WITH_DC) 511 return decode_coefs_4x4_y(dx, xd, bc, type, i, seg_eob);
391 tx_type = get_tx_type_4x4(xd, &xd->block[i]); 512 }
392 switch (tx_type) {
393 case ADST_DCT :
394 scan = vp9_row_scan;
395 break;
396 513
397 case DCT_ADST : 514 static int decode_mb_tokens_4x4_uv(VP9D_COMP* const dx,
398 scan = vp9_col_scan; 515 MACROBLOCKD* const xd,
399 break; 516 BOOL_DECODER* const bc,
517 int seg_eob) {
518 int eobtotal = 0, i;
400 519
401 default : 520 // chroma blocks
402 scan = vp9_default_zig_zag1d; 521 for (i = 16; i < 24; i++) {
403 break; 522 eobtotal += decode_coefs_4x4(dx, xd, bc, PLANE_TYPE_UV, i, seg_eob,
523 DCT_DCT, vp9_default_zig_zag1d_4x4);
404 } 524 }
405 eobs[i] = c = decode_coefs(dx, xd, bc, a, l, type, 525
406 tx_type, seg_eob, qcoeff_ptr + i * 16, 526 return eobtotal;
407 scan, TX_4X4, vp9_coef_bands);
408 return c;
409 } 527 }
410 528
411 int vp9_decode_mb_tokens_4x4_uv(VP9D_COMP* const dx, 529 int vp9_decode_mb_tokens_4x4_uv(VP9D_COMP* const dx,
412 MACROBLOCKD* const xd, 530 MACROBLOCKD* const xd,
413 BOOL_DECODER* const bc) { 531 BOOL_DECODER* const bc) {
414 int eobtotal = 0, i; 532 const int segment_id = xd->mode_info_context->mbmi.segment_id;
533 const int seg_eob = get_eob(xd, segment_id, 16);
415 534
416 for (i = 16; i < 24; i++) 535 return decode_mb_tokens_4x4_uv(dx, xd, bc, seg_eob);
417 eobtotal += vp9_decode_coefs_4x4(dx, xd, bc, PLANE_TYPE_UV, i);
418
419 return eobtotal;
420 } 536 }
421 537
422 static int vp9_decode_mb_tokens_4x4(VP9D_COMP* const dx, 538 static int vp9_decode_mb_tokens_4x4(VP9D_COMP* const dx,
423 MACROBLOCKD* const xd, 539 MACROBLOCKD* const xd,
424 BOOL_DECODER* const bc) { 540 BOOL_DECODER* const bc) {
425 int i, eobtotal = 0; 541 int i, eobtotal = 0;
426 PLANE_TYPE type; 542 PLANE_TYPE type;
543 const int segment_id = xd->mode_info_context->mbmi.segment_id;
544 const int seg_eob = get_eob(xd, segment_id, 16);
545 const int has_2nd_order = get_2nd_order_usage(xd);
427 546
428 int has_2nd_order = get_2nd_order_usage(xd); 547 // 2nd order DC block
429
430 if (has_2nd_order) { 548 if (has_2nd_order) {
431 eobtotal += vp9_decode_coefs_4x4(dx, xd, bc, PLANE_TYPE_Y2, 24) - 16; 549 eobtotal += decode_coefs_4x4(dx, xd, bc, PLANE_TYPE_Y2, 24, seg_eob,
550 DCT_DCT, vp9_default_zig_zag1d_4x4) - 16;
432 type = PLANE_TYPE_Y_NO_DC; 551 type = PLANE_TYPE_Y_NO_DC;
433 } else { 552 } else {
434 xd->above_context->y2 = 1; 553 xd->above_context->y2 = 0;
435 xd->left_context->y2 = 1; 554 xd->left_context->y2 = 0;
436 xd->eobs[24] = 0; 555 xd->eobs[24] = 0;
437 type = PLANE_TYPE_Y_WITH_DC; 556 type = PLANE_TYPE_Y_WITH_DC;
438 } 557 }
439 558
559 // luma blocks
440 for (i = 0; i < 16; ++i) { 560 for (i = 0; i < 16; ++i) {
441 eobtotal += vp9_decode_coefs_4x4(dx, xd, bc, type, i); 561 eobtotal += decode_coefs_4x4_y(dx, xd, bc, type, i, seg_eob);
442 } 562 }
443 563
444 return eobtotal + vp9_decode_mb_tokens_4x4_uv(dx, xd, bc); 564 // chroma blocks
565 eobtotal += decode_mb_tokens_4x4_uv(dx, xd, bc, seg_eob);
566
567 return eobtotal;
445 } 568 }
446 569
447 int vp9_decode_mb_tokens(VP9D_COMP* const dx, 570 int vp9_decode_mb_tokens(VP9D_COMP* const dx,
448 MACROBLOCKD* const xd, 571 MACROBLOCKD* const xd,
449 BOOL_DECODER* const bc) { 572 BOOL_DECODER* const bc) {
450 const TX_SIZE tx_size = xd->mode_info_context->mbmi.txfm_size; 573 const TX_SIZE tx_size = xd->mode_info_context->mbmi.txfm_size;
451 int eobtotal; 574 int eobtotal;
452 575
453 if (tx_size == TX_16X16) { 576 if (tx_size == TX_16X16) {
454 eobtotal = vp9_decode_mb_tokens_16x16(dx, xd, bc); 577 eobtotal = vp9_decode_mb_tokens_16x16(dx, xd, bc);
455 } else if (tx_size == TX_8X8) { 578 } else if (tx_size == TX_8X8) {
456 eobtotal = vp9_decode_mb_tokens_8x8(dx, xd, bc); 579 eobtotal = vp9_decode_mb_tokens_8x8(dx, xd, bc);
457 } else { 580 } else {
458 assert(tx_size == TX_4X4); 581 assert(tx_size == TX_4X4);
459 eobtotal = vp9_decode_mb_tokens_4x4(dx, xd, bc); 582 eobtotal = vp9_decode_mb_tokens_4x4(dx, xd, bc);
460 } 583 }
461 584
462 return eobtotal; 585 return eobtotal;
463 } 586 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/decoder/vp9_detokenize.h ('k') | source/libvpx/vp9/decoder/vp9_idct_blk.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698