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

Side by Side Diff: source/libvpx/vp9/encoder/vp9_tokenize.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/encoder/vp9_tokenize.h ('k') | source/libvpx/vp9/encoder/vp9_treewriter.h » ('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 <math.h> 12 #include <math.h>
13 #include <stdio.h> 13 #include <stdio.h>
14 #include <string.h> 14 #include <string.h>
15 #include <assert.h> 15 #include <assert.h>
16 #include "vp9/encoder/vp9_onyx_int.h" 16 #include "vp9/encoder/vp9_onyx_int.h"
17 #include "vp9/encoder/vp9_tokenize.h" 17 #include "vp9/encoder/vp9_tokenize.h"
18 #include "vpx_mem/vpx_mem.h" 18 #include "vpx_mem/vpx_mem.h"
19 19
20 #include "vp9/common/vp9_pred_common.h" 20 #include "vp9/common/vp9_pred_common.h"
21 #include "vp9/common/vp9_seg_common.h" 21 #include "vp9/common/vp9_seg_common.h"
22 #include "vp9/common/vp9_entropy.h" 22 #include "vp9/common/vp9_entropy.h"
23 23
24 /* Global event counters used for accumulating statistics across several 24 /* Global event counters used for accumulating statistics across several
25 compressions, then generating vp9_context.c = initial stats. */ 25 compressions, then generating vp9_context.c = initial stats. */
26 26
27 #ifdef ENTROPY_STATS 27 #ifdef ENTROPY_STATS
28 INT64 context_counters[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENTRO PY_TOKENS]; 28 vp9_coeff_accum context_counters_4x4[BLOCK_TYPES_4X4];
29 INT64 hybrid_context_counters[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MA X_ENTROPY_TOKENS]; 29 vp9_coeff_accum hybrid_context_counters_4x4[BLOCK_TYPES_4X4];
30 vp9_coeff_accum context_counters_8x8[BLOCK_TYPES_8X8];
31 vp9_coeff_accum hybrid_context_counters_8x8[BLOCK_TYPES_8X8];
32 vp9_coeff_accum context_counters_16x16[BLOCK_TYPES_16X16];
33 vp9_coeff_accum hybrid_context_counters_16x16[BLOCK_TYPES_16X16];
34 vp9_coeff_accum context_counters_32x32[BLOCK_TYPES_32X32];
30 35
31 INT64 context_counters_8x8[BLOCK_TYPES_8X8] [COEF_BANDS] [PREV_COEF_CONTEXTS] [M AX_ENTROPY_TOKENS]; 36 extern vp9_coeff_stats tree_update_hist_4x4[BLOCK_TYPES_4X4];
32 INT64 hybrid_context_counters_8x8[BLOCK_TYPES_8X8] [COEF_BANDS] [PREV_COEF_CONTE XTS] [MAX_ENTROPY_TOKENS]; 37 extern vp9_coeff_stats hybrid_tree_update_hist_4x4[BLOCK_TYPES_4X4];
33 38 extern vp9_coeff_stats tree_update_hist_8x8[BLOCK_TYPES_8X8];
34 INT64 context_counters_16x16[BLOCK_TYPES_16X16] [COEF_BANDS] [PREV_COEF_CONTEXTS ] [MAX_ENTROPY_TOKENS]; 39 extern vp9_coeff_stats hybrid_tree_update_hist_8x8[BLOCK_TYPES_8X8];
35 INT64 hybrid_context_counters_16x16[BLOCK_TYPES_16X16] [COEF_BANDS] [PREV_COEF_C ONTEXTS] [MAX_ENTROPY_TOKENS]; 40 extern vp9_coeff_stats tree_update_hist_16x16[BLOCK_TYPES_16X16];
36 41 extern vp9_coeff_stats hybrid_tree_update_hist_16x16[BLOCK_TYPES_16X16];
37 extern unsigned int tree_update_hist[BLOCK_TYPES][COEF_BANDS] 42 extern vp9_coeff_stats tree_update_hist_32x32[BLOCK_TYPES_32X32];
38 [PREV_COEF_CONTEXTS][ENTROPY_NODES][2];
39 extern unsigned int hybrid_tree_update_hist[BLOCK_TYPES][COEF_BANDS]
40 [PREV_COEF_CONTEXTS][ENTROPY_NODES][2];
41 extern unsigned int tree_update_hist_8x8[BLOCK_TYPES_8X8][COEF_BANDS]
42 [PREV_COEF_CONTEXTS][ENTROPY_NODES] [2];
43 extern unsigned int hybrid_tree_update_hist_8x8[BLOCK_TYPES_8X8][COEF_BANDS]
44 [PREV_COEF_CONTEXTS][ENTROPY_NODES] [2];
45 extern unsigned int tree_update_hist_16x16[BLOCK_TYPES_16X16][COEF_BANDS]
46 [PREV_COEF_CONTEXTS][ENTROPY_NODES] [2];
47 extern unsigned int hybrid_tree_update_hist_16x16[BLOCK_TYPES_16X16][COEF_BANDS]
48 [PREV_COEF_CONTEXTS][ENTROPY_NODES] [2];
49 #endif /* ENTROPY_STATS */ 43 #endif /* ENTROPY_STATS */
50 44
51 static TOKENVALUE dct_value_tokens[DCT_MAX_VALUE * 2]; 45 static TOKENVALUE dct_value_tokens[DCT_MAX_VALUE * 2];
52 const TOKENVALUE *vp9_dct_value_tokens_ptr; 46 const TOKENVALUE *vp9_dct_value_tokens_ptr;
53 static int dct_value_cost[DCT_MAX_VALUE * 2]; 47 static int dct_value_cost[DCT_MAX_VALUE * 2];
54 const int *vp9_dct_value_cost_ptr; 48 const int *vp9_dct_value_cost_ptr;
55 49
56 static void fill_value_tokens() { 50 static void fill_value_tokens() {
57 51
58 TOKENVALUE *const t = dct_value_tokens + DCT_MAX_VALUE; 52 TOKENVALUE *const t = dct_value_tokens + DCT_MAX_VALUE;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 } 93 }
100 94
101 } 95 }
102 96
103 } while (++i < DCT_MAX_VALUE); 97 } while (++i < DCT_MAX_VALUE);
104 98
105 vp9_dct_value_tokens_ptr = dct_value_tokens + DCT_MAX_VALUE; 99 vp9_dct_value_tokens_ptr = dct_value_tokens + DCT_MAX_VALUE;
106 vp9_dct_value_cost_ptr = dct_value_cost + DCT_MAX_VALUE; 100 vp9_dct_value_cost_ptr = dct_value_cost + DCT_MAX_VALUE;
107 } 101 }
108 102
103 #if CONFIG_NEWCOEFCONTEXT
104 #define PT pn
105 #else
106 #define PT pt
107 #endif
108
109 static void tokenize_b(VP9_COMP *cpi, 109 static void tokenize_b(VP9_COMP *cpi,
110 MACROBLOCKD *xd, 110 MACROBLOCKD *xd,
111 const BLOCKD * const b, 111 const int ib,
112 TOKENEXTRA **tp, 112 TOKENEXTRA **tp,
113 PLANE_TYPE type, 113 PLANE_TYPE type,
114 ENTROPY_CONTEXT *a,
115 ENTROPY_CONTEXT *l,
116 TX_SIZE tx_size, 114 TX_SIZE tx_size,
117 int dry_run) { 115 int dry_run) {
118 int pt; /* near block/prev token context index */ 116 int pt; /* near block/prev token context index */
119 int c = (type == PLANE_TYPE_Y_NO_DC) ? 1 : 0; 117 int c = (type == PLANE_TYPE_Y_NO_DC) ? 1 : 0;
118 const BLOCKD * const b = xd->block + ib;
120 const int eob = b->eob; /* one beyond last nonzero coeff */ 119 const int eob = b->eob; /* one beyond last nonzero coeff */
121 TOKENEXTRA *t = *tp; /* store tokens starting here */ 120 TOKENEXTRA *t = *tp; /* store tokens starting here */
122 const short *qcoeff_ptr = b->qcoeff; 121 int16_t *qcoeff_ptr = b->qcoeff;
123 int seg_eob; 122 int seg_eob;
124 int segment_id = xd->mode_info_context->mbmi.segment_id; 123 const int segment_id = xd->mode_info_context->mbmi.segment_id;
125 const int *bands, *scan; 124 const int *bands, *scan;
126 unsigned int (*counts)[COEF_BANDS][PREV_COEF_CONTEXTS][MAX_ENTROPY_TOKENS]; 125 vp9_coeff_count *counts;
127 vp9_prob (*probs)[COEF_BANDS][PREV_COEF_CONTEXTS][ENTROPY_NODES]; 126 vp9_coeff_probs *probs;
128 const TX_TYPE tx_type = (type == PLANE_TYPE_Y_WITH_DC) ? 127 const TX_TYPE tx_type = (type == PLANE_TYPE_Y_WITH_DC) ?
129 get_tx_type(xd, b) : DCT_DCT; 128 get_tx_type(xd, b) : DCT_DCT;
129 #if CONFIG_NEWCOEFCONTEXT
130 const int *neighbors;
131 int pn;
132 #endif
130 133
131 VP9_COMBINEENTROPYCONTEXTS(pt, *a, *l); 134 ENTROPY_CONTEXT *const a = (ENTROPY_CONTEXT *)xd->above_context +
135 vp9_block2above[tx_size][ib];
136 ENTROPY_CONTEXT *const l = (ENTROPY_CONTEXT *)xd->left_context +
137 vp9_block2left[tx_size][ib];
138 ENTROPY_CONTEXT a_ec = *a, l_ec = *l;
139
140 ENTROPY_CONTEXT *const a1 = (ENTROPY_CONTEXT *)(&xd->above_context[1]) +
141 vp9_block2above[tx_size][ib];
142 ENTROPY_CONTEXT *const l1 = (ENTROPY_CONTEXT *)(&xd->left_context[1]) +
143 vp9_block2left[tx_size][ib];
144
145
132 switch (tx_size) { 146 switch (tx_size) {
133 default: 147 default:
134 case TX_4X4: 148 case TX_4X4:
135 seg_eob = 16; 149 seg_eob = 16;
136 bands = vp9_coef_bands; 150 bands = vp9_coef_bands_4x4;
137 scan = vp9_default_zig_zag1d; 151 scan = vp9_default_zig_zag1d_4x4;
138 if (tx_type != DCT_DCT) { 152 if (tx_type != DCT_DCT) {
139 counts = cpi->hybrid_coef_counts; 153 counts = cpi->hybrid_coef_counts_4x4;
140 probs = cpi->common.fc.hybrid_coef_probs; 154 probs = cpi->common.fc.hybrid_coef_probs_4x4;
141 if (tx_type == ADST_DCT) { 155 if (tx_type == ADST_DCT) {
142 scan = vp9_row_scan; 156 scan = vp9_row_scan_4x4;
143 } else if (tx_type == DCT_ADST) { 157 } else if (tx_type == DCT_ADST) {
144 scan = vp9_col_scan; 158 scan = vp9_col_scan_4x4;
145 } 159 }
146 } else { 160 } else {
147 counts = cpi->coef_counts; 161 counts = cpi->coef_counts_4x4;
148 probs = cpi->common.fc.coef_probs; 162 probs = cpi->common.fc.coef_probs_4x4;
149 } 163 }
150 break; 164 break;
151 case TX_8X8: 165 case TX_8X8:
152 if (type == PLANE_TYPE_Y2) { 166 if (type == PLANE_TYPE_Y2) {
153 seg_eob = 4; 167 seg_eob = 4;
154 bands = vp9_coef_bands; 168 bands = vp9_coef_bands_4x4;
155 scan = vp9_default_zig_zag1d; 169 scan = vp9_default_zig_zag1d_4x4;
156 } else { 170 } else {
171 #if CONFIG_CNVCONTEXT
172 a_ec = (a[0] + a[1]) != 0;
173 l_ec = (l[0] + l[1]) != 0;
174 #endif
157 seg_eob = 64; 175 seg_eob = 64;
158 bands = vp9_coef_bands_8x8; 176 bands = vp9_coef_bands_8x8;
159 scan = vp9_default_zig_zag1d_8x8; 177 scan = vp9_default_zig_zag1d_8x8;
160 } 178 }
161 if (tx_type != DCT_DCT) { 179 if (tx_type != DCT_DCT) {
162 counts = cpi->hybrid_coef_counts_8x8; 180 counts = cpi->hybrid_coef_counts_8x8;
163 probs = cpi->common.fc.hybrid_coef_probs_8x8; 181 probs = cpi->common.fc.hybrid_coef_probs_8x8;
164 } else { 182 } else {
165 counts = cpi->coef_counts_8x8; 183 counts = cpi->coef_counts_8x8;
166 probs = cpi->common.fc.coef_probs_8x8; 184 probs = cpi->common.fc.coef_probs_8x8;
167 } 185 }
168 break; 186 break;
169 case TX_16X16: 187 case TX_16X16:
188 #if CONFIG_CNVCONTEXT
189 if (type != PLANE_TYPE_UV) {
190 a_ec = (a[0] + a[1] + a[2] + a[3]) != 0;
191 l_ec = (l[0] + l[1] + l[2] + l[3]) != 0;
192 } else {
193 a_ec = (a[0] + a[1] + a1[0] + a1[1]) != 0;
194 l_ec = (l[0] + l[1] + l1[0] + l1[1]) != 0;
195 }
196 #endif
170 seg_eob = 256; 197 seg_eob = 256;
171 bands = vp9_coef_bands_16x16; 198 bands = vp9_coef_bands_16x16;
172 scan = vp9_default_zig_zag1d_16x16; 199 scan = vp9_default_zig_zag1d_16x16;
173 if (tx_type != DCT_DCT) { 200 if (tx_type != DCT_DCT) {
174 counts = cpi->hybrid_coef_counts_16x16; 201 counts = cpi->hybrid_coef_counts_16x16;
175 probs = cpi->common.fc.hybrid_coef_probs_16x16; 202 probs = cpi->common.fc.hybrid_coef_probs_16x16;
176 } else { 203 } else {
177 counts = cpi->coef_counts_16x16; 204 counts = cpi->coef_counts_16x16;
178 probs = cpi->common.fc.coef_probs_16x16; 205 probs = cpi->common.fc.coef_probs_16x16;
179 } 206 }
207 if (type == PLANE_TYPE_UV) {
208 int uv_idx = (ib - 16) >> 2;
209 qcoeff_ptr = xd->sb_coeff_data.qcoeff + 1024 + 256 * uv_idx;
210 }
211 break;
212 case TX_32X32:
213 #if CONFIG_CNVCONTEXT
214 a_ec = a[0] + a[1] + a[2] + a[3] +
215 a1[0] + a1[1] + a1[2] + a1[3];
216 l_ec = l[0] + l[1] + l[2] + l[3] +
217 l1[0] + l1[1] + l1[2] + l1[3];
218 a_ec = a_ec != 0;
219 l_ec = l_ec != 0;
220 #endif
221 seg_eob = 1024;
222 bands = vp9_coef_bands_32x32;
223 scan = vp9_default_zig_zag1d_32x32;
224 counts = cpi->coef_counts_32x32;
225 probs = cpi->common.fc.coef_probs_32x32;
226 qcoeff_ptr = xd->sb_coeff_data.qcoeff;
180 break; 227 break;
181 } 228 }
182 229
230 VP9_COMBINEENTROPYCONTEXTS(pt, a_ec, l_ec);
231 #if CONFIG_NEWCOEFCONTEXT
232 neighbors = vp9_get_coef_neighbors_handle(scan);
233 pn = pt;
234 #endif
235
183 if (vp9_segfeature_active(xd, segment_id, SEG_LVL_EOB)) 236 if (vp9_segfeature_active(xd, segment_id, SEG_LVL_EOB))
184 seg_eob = vp9_get_segdata(xd, segment_id, SEG_LVL_EOB); 237 seg_eob = vp9_get_segdata(xd, segment_id, SEG_LVL_EOB);
185 238
186 do { 239 do {
187 const int band = bands[c]; 240 const int band = bands[c];
188 int token; 241 int token;
189 242
190 if (c < eob) { 243 if (c < eob) {
191 const int rc = scan[c]; 244 const int rc = scan[c];
192 const int v = qcoeff_ptr[rc]; 245 const int v = qcoeff_ptr[rc];
193
194 assert(-DCT_MAX_VALUE <= v && v < DCT_MAX_VALUE); 246 assert(-DCT_MAX_VALUE <= v && v < DCT_MAX_VALUE);
195 247
196 t->Extra = vp9_dct_value_tokens_ptr[v].Extra; 248 t->Extra = vp9_dct_value_tokens_ptr[v].Extra;
197 token = vp9_dct_value_tokens_ptr[v].Token; 249 token = vp9_dct_value_tokens_ptr[v].Token;
198 } else { 250 } else {
199 token = DCT_EOB_TOKEN; 251 token = DCT_EOB_TOKEN;
200 } 252 }
201 253
202 t->Token = token; 254 t->Token = token;
203 t->context_tree = probs[type][band][pt]; 255 t->context_tree = probs[type][band][PT];
204 t->skip_eob_node = (pt == 0) && ((band > 0 && type != PLANE_TYPE_Y_NO_DC) || 256 t->skip_eob_node = (pt == 0) && ((band > 0 && type != PLANE_TYPE_Y_NO_DC) ||
205 (band > 1 && type == PLANE_TYPE_Y_NO_DC)); 257 (band > 1 && type == PLANE_TYPE_Y_NO_DC));
206 assert(vp9_coef_encodings[t->Token].Len - t->skip_eob_node > 0); 258 assert(vp9_coef_encodings[t->Token].Len - t->skip_eob_node > 0);
207 if (!dry_run) { 259 if (!dry_run) {
208 ++counts[type][band][pt][token]; 260 ++counts[type][band][PT][token];
209 } 261 }
210 pt = vp9_prev_token_class[token]; 262 pt = vp9_prev_token_class[token];
263 #if CONFIG_NEWCOEFCONTEXT
264 if (c < seg_eob - 1 && NEWCOEFCONTEXT_BAND_COND(bands[c + 1]))
265 pn = vp9_get_coef_neighbor_context(
266 qcoeff_ptr, (type == PLANE_TYPE_Y_NO_DC), neighbors, scan[c + 1]);
267 else
268 pn = pt;
269 #endif
211 ++t; 270 ++t;
212 } while (c < eob && ++c < seg_eob); 271 } while (c < eob && ++c < seg_eob);
213 272
214 *tp = t; 273 *tp = t;
215 *a = *l = (c > !type); /* 0 <-> all coeff data is zero */ 274 a_ec = l_ec = (c > !type); /* 0 <-> all coeff data is zero */
275 a[0] = a_ec;
276 l[0] = l_ec;
277
278 if (tx_size == TX_8X8 && type != PLANE_TYPE_Y2) {
279 a[1] = a_ec;
280 l[1] = l_ec;
281 } else if (tx_size == TX_16X16) {
282 if (type != PLANE_TYPE_UV) {
283 a[1] = a[2] = a[3] = a_ec;
284 l[1] = l[2] = l[3] = l_ec;
285 } else {
286 a1[0] = a1[1] = a[1] = a_ec;
287 l1[0] = l1[1] = l[1] = l_ec;
288 }
289 } else if (tx_size == TX_32X32) {
290 a[1] = a[2] = a[3] = a_ec;
291 l[1] = l[2] = l[3] = l_ec;
292 a1[0] = a1[1] = a1[2] = a1[3] = a_ec;
293 l1[0] = l1[1] = l1[2] = l1[3] = l_ec;
294 }
216 } 295 }
217 296
218 int vp9_mby_is_skippable_4x4(MACROBLOCKD *xd, int has_2nd_order) { 297 int vp9_mby_is_skippable_4x4(MACROBLOCKD *xd, int has_2nd_order) {
219 int skip = 1; 298 int skip = 1;
220 int i = 0; 299 int i = 0;
221 300
222 if (has_2nd_order) { 301 if (has_2nd_order) {
223 for (i = 0; i < 16; i++) 302 for (i = 0; i < 16; i++)
224 skip &= (xd->block[i].eob < 2); 303 skip &= (xd->block[i].eob < 2);
225 skip &= (!xd->block[24].eob); 304 skip &= (!xd->block[24].eob);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 int vp9_mby_is_skippable_16x16(MACROBLOCKD *xd) { 355 int vp9_mby_is_skippable_16x16(MACROBLOCKD *xd) {
277 int skip = 1; 356 int skip = 1;
278 skip &= !xd->block[0].eob; 357 skip &= !xd->block[0].eob;
279 return skip; 358 return skip;
280 } 359 }
281 360
282 static int mb_is_skippable_16x16(MACROBLOCKD *xd) { 361 static int mb_is_skippable_16x16(MACROBLOCKD *xd) {
283 return (vp9_mby_is_skippable_16x16(xd) & vp9_mbuv_is_skippable_8x8(xd)); 362 return (vp9_mby_is_skippable_16x16(xd) & vp9_mbuv_is_skippable_8x8(xd));
284 } 363 }
285 364
365 int vp9_sby_is_skippable_32x32(MACROBLOCKD *xd) {
366 int skip = 1;
367 skip &= !xd->block[0].eob;
368 return skip;
369 }
370
371 int vp9_sbuv_is_skippable_16x16(MACROBLOCKD *xd) {
372 return (!xd->block[16].eob) & (!xd->block[20].eob);
373 }
374
375 static int sb_is_skippable_32x32(MACROBLOCKD *xd) {
376 return vp9_sby_is_skippable_32x32(xd) &&
377 vp9_sbuv_is_skippable_16x16(xd);
378 }
379
380 void vp9_tokenize_sb(VP9_COMP *cpi,
381 MACROBLOCKD *xd,
382 TOKENEXTRA **t,
383 int dry_run) {
384 VP9_COMMON * const cm = &cpi->common;
385 MB_MODE_INFO * const mbmi = &xd->mode_info_context->mbmi;
386 TOKENEXTRA *t_backup = *t;
387 ENTROPY_CONTEXT *A[2] = { (ENTROPY_CONTEXT *) (xd->above_context + 0),
388 (ENTROPY_CONTEXT *) (xd->above_context + 1), };
389 ENTROPY_CONTEXT *L[2] = { (ENTROPY_CONTEXT *) (xd->left_context + 0),
390 (ENTROPY_CONTEXT *) (xd->left_context + 1), };
391 const int mb_skip_context = vp9_get_pred_context(cm, xd, PRED_MBSKIP);
392 const int segment_id = mbmi->segment_id;
393 const int skip_inc = !vp9_segfeature_active(xd, segment_id, SEG_LVL_EOB) ||
394 (vp9_get_segdata(xd, segment_id, SEG_LVL_EOB) != 0);
395 int b;
396
397 mbmi->mb_skip_coeff = sb_is_skippable_32x32(xd);
398
399 if (mbmi->mb_skip_coeff) {
400 if (!dry_run)
401 cpi->skip_true_count[mb_skip_context] += skip_inc;
402 if (!cm->mb_no_coeff_skip) {
403 vp9_stuff_sb(cpi, xd, t, dry_run);
404 } else {
405 vp9_fix_contexts_sb(xd);
406 }
407 if (dry_run)
408 *t = t_backup;
409 return;
410 }
411
412 if (!dry_run)
413 cpi->skip_false_count[mb_skip_context] += skip_inc;
414
415 tokenize_b(cpi, xd, 0, t, PLANE_TYPE_Y_WITH_DC,
416 TX_32X32, dry_run);
417
418 for (b = 16; b < 24; b += 4) {
419 tokenize_b(cpi, xd, b, t, PLANE_TYPE_UV,
420 TX_16X16, dry_run);
421 }
422 A[0][8] = L[0][8] = A[1][8] = L[1][8] = 0;
423 if (dry_run)
424 *t = t_backup;
425 }
426
286 void vp9_tokenize_mb(VP9_COMP *cpi, 427 void vp9_tokenize_mb(VP9_COMP *cpi,
287 MACROBLOCKD *xd, 428 MACROBLOCKD *xd,
288 TOKENEXTRA **t, 429 TOKENEXTRA **t,
289 int dry_run) { 430 int dry_run) {
290 PLANE_TYPE plane_type; 431 PLANE_TYPE plane_type;
291 int has_2nd_order; 432 int has_2nd_order;
292 int b; 433 int b;
293 int tx_size = xd->mode_info_context->mbmi.txfm_size; 434 int tx_size = xd->mode_info_context->mbmi.txfm_size;
294 int mb_skip_context = vp9_get_pred_context(&cpi->common, xd, PRED_MBSKIP); 435 int mb_skip_context = vp9_get_pred_context(&cpi->common, xd, PRED_MBSKIP);
295 TOKENEXTRA *t_backup = *t; 436 TOKENEXTRA *t_backup = *t;
296 ENTROPY_CONTEXT * A = (ENTROPY_CONTEXT *) xd->above_context;
297 ENTROPY_CONTEXT * L = (ENTROPY_CONTEXT *) xd->left_context;
298 437
299 // If the MB is going to be skipped because of a segment level flag 438 // If the MB is going to be skipped because of a segment level flag
300 // exclude this from the skip count stats used to calculate the 439 // exclude this from the skip count stats used to calculate the
301 // transmitted skip probability; 440 // transmitted skip probability;
302 int skip_inc; 441 int skip_inc;
303 int segment_id = xd->mode_info_context->mbmi.segment_id; 442 int segment_id = xd->mode_info_context->mbmi.segment_id;
304 443
305 if (!vp9_segfeature_active(xd, segment_id, SEG_LVL_EOB) || 444 if (!vp9_segfeature_active(xd, segment_id, SEG_LVL_EOB) ||
306 (vp9_get_segdata(xd, segment_id, SEG_LVL_EOB) != 0)) { 445 (vp9_get_segdata(xd, segment_id, SEG_LVL_EOB) != 0)) {
307 skip_inc = 1; 446 skip_inc = 1;
308 } else 447 } else
309 skip_inc = 0; 448 skip_inc = 0;
310 449
311 has_2nd_order = get_2nd_order_usage(xd); 450 has_2nd_order = get_2nd_order_usage(xd);
312 451
313 switch (tx_size) { 452 switch (tx_size) {
314 case TX_16X16: 453 case TX_16X16:
454
315 xd->mode_info_context->mbmi.mb_skip_coeff = mb_is_skippable_16x16(xd); 455 xd->mode_info_context->mbmi.mb_skip_coeff = mb_is_skippable_16x16(xd);
316 break; 456 break;
317 case TX_8X8: 457 case TX_8X8:
318 if (xd->mode_info_context->mbmi.mode == I8X8_PRED || 458 if (xd->mode_info_context->mbmi.mode == I8X8_PRED ||
319 xd->mode_info_context->mbmi.mode == SPLITMV) 459 xd->mode_info_context->mbmi.mode == SPLITMV)
320 xd->mode_info_context->mbmi.mb_skip_coeff = 460 xd->mode_info_context->mbmi.mb_skip_coeff =
321 mb_is_skippable_8x8_4x4uv(xd, 0); 461 mb_is_skippable_8x8_4x4uv(xd, 0);
322 else 462 else
323 xd->mode_info_context->mbmi.mb_skip_coeff = 463 xd->mode_info_context->mbmi.mb_skip_coeff =
324 mb_is_skippable_8x8(xd, has_2nd_order); 464 mb_is_skippable_8x8(xd, has_2nd_order);
325 break; 465 break;
326 466
327 default: 467 default:
328 xd->mode_info_context->mbmi.mb_skip_coeff = 468 xd->mode_info_context->mbmi.mb_skip_coeff =
329 mb_is_skippable_4x4(xd, has_2nd_order); 469 mb_is_skippable_4x4(xd, has_2nd_order);
330 break; 470 break;
331 } 471 }
332 472
333 if (xd->mode_info_context->mbmi.mb_skip_coeff) { 473 if (xd->mode_info_context->mbmi.mb_skip_coeff) {
334 if (!dry_run) 474 if (!dry_run)
335 cpi->skip_true_count[mb_skip_context] += skip_inc; 475 cpi->skip_true_count[mb_skip_context] += skip_inc;
336 if (!cpi->common.mb_no_coeff_skip) { 476 if (!cpi->common.mb_no_coeff_skip) {
337 vp9_stuff_mb(cpi, xd, t, dry_run); 477 vp9_stuff_mb(cpi, xd, t, dry_run);
338 } else { 478 } else {
339 vp9_fix_contexts(xd); 479 vp9_reset_mb_tokens_context(xd);
340 } 480 }
481
341 if (dry_run) 482 if (dry_run)
342 *t = t_backup; 483 *t = t_backup;
343 return; 484 return;
344 } 485 }
345 486
346 if (!dry_run) 487 if (!dry_run)
347 cpi->skip_false_count[mb_skip_context] += skip_inc; 488 cpi->skip_false_count[mb_skip_context] += skip_inc;
348 489
349 if (has_2nd_order) { 490 if (has_2nd_order) {
350 if (tx_size == TX_8X8) { 491 tokenize_b(cpi, xd, 24, t, PLANE_TYPE_Y2, tx_size, dry_run);
351 tokenize_b(cpi, xd, xd->block + 24, t, PLANE_TYPE_Y2,
352 A + vp9_block2above_8x8[24], L + vp9_block2left_8x8[24],
353 TX_8X8, dry_run);
354 } else {
355 tokenize_b(cpi, xd, xd->block + 24, t, PLANE_TYPE_Y2,
356 A + vp9_block2above[24], L + vp9_block2left[24],
357 TX_4X4, dry_run);
358 }
359
360 plane_type = PLANE_TYPE_Y_NO_DC; 492 plane_type = PLANE_TYPE_Y_NO_DC;
361 } else { 493 } else {
362 xd->above_context->y2 = 1; 494 xd->above_context->y2 = 0;
363 xd->left_context->y2 = 1; 495 xd->left_context->y2 = 0;
364 plane_type = PLANE_TYPE_Y_WITH_DC; 496 plane_type = PLANE_TYPE_Y_WITH_DC;
365 } 497 }
366 498
367 if (tx_size == TX_16X16) { 499 if (tx_size == TX_16X16) {
368 tokenize_b(cpi, xd, xd->block, t, PLANE_TYPE_Y_WITH_DC, 500 tokenize_b(cpi, xd, 0, t, PLANE_TYPE_Y_WITH_DC, TX_16X16, dry_run);
369 A, L, TX_16X16, dry_run);
370 A[1] = A[2] = A[3] = A[0];
371 L[1] = L[2] = L[3] = L[0];
372
373 for (b = 16; b < 24; b += 4) { 501 for (b = 16; b < 24; b += 4) {
374 tokenize_b(cpi, xd, xd->block + b, t, PLANE_TYPE_UV, 502 tokenize_b(cpi, xd, b, t, PLANE_TYPE_UV, TX_8X8, dry_run);
375 A + vp9_block2above_8x8[b], L + vp9_block2left_8x8[b],
376 TX_8X8, dry_run);
377 A[vp9_block2above_8x8[b] + 1] = A[vp9_block2above_8x8[b]];
378 L[vp9_block2left_8x8[b] + 1] = L[vp9_block2left_8x8[b]];
379 } 503 }
380 A[8] = 0;
381 L[8] = 0;
382 } else if (tx_size == TX_8X8) { 504 } else if (tx_size == TX_8X8) {
383 for (b = 0; b < 16; b += 4) { 505 for (b = 0; b < 16; b += 4) {
384 tokenize_b(cpi, xd, xd->block + b, t, plane_type, 506 tokenize_b(cpi, xd, b, t, plane_type, TX_8X8, dry_run);
385 A + vp9_block2above_8x8[b], L + vp9_block2left_8x8[b],
386 TX_8X8, dry_run);
387 A[vp9_block2above_8x8[b] + 1] = A[vp9_block2above_8x8[b]];
388 L[vp9_block2left_8x8[b] + 1] = L[vp9_block2left_8x8[b]];
389 } 507 }
390 if (xd->mode_info_context->mbmi.mode == I8X8_PRED || 508 if (xd->mode_info_context->mbmi.mode == I8X8_PRED ||
391 xd->mode_info_context->mbmi.mode == SPLITMV) { 509 xd->mode_info_context->mbmi.mode == SPLITMV) {
392 for (b = 16; b < 24; b++) { 510 for (b = 16; b < 24; b++) {
393 tokenize_b(cpi, xd, xd->block + b, t, PLANE_TYPE_UV, 511 tokenize_b(cpi, xd, b, t, PLANE_TYPE_UV, TX_4X4, dry_run);
394 A + vp9_block2above[b], L + vp9_block2left[b],
395 TX_4X4, dry_run);
396 } 512 }
397 } else { 513 } else {
398 for (b = 16; b < 24; b += 4) { 514 for (b = 16; b < 24; b += 4) {
399 tokenize_b(cpi, xd, xd->block + b, t, PLANE_TYPE_UV, 515 tokenize_b(cpi, xd, b, t, PLANE_TYPE_UV, TX_8X8, dry_run);
400 A + vp9_block2above_8x8[b], L + vp9_block2left_8x8[b],
401 TX_8X8, dry_run);
402 A[vp9_block2above_8x8[b] + 1] = A[vp9_block2above_8x8[b]];
403 L[vp9_block2left_8x8[b] + 1] = L[vp9_block2left_8x8[b]];
404 } 516 }
405 } 517 }
406 } else { 518 } else {
407 for (b = 0; b < 16; b++) { 519 for (b = 0; b < 24; b++) {
408 tokenize_b(cpi, xd, xd->block + b, t, plane_type, 520 if (b >= 16)
409 A + vp9_block2above[b], L + vp9_block2left[b], 521 plane_type = PLANE_TYPE_UV;
410 TX_4X4, dry_run); 522 tokenize_b(cpi, xd, b, t, plane_type, TX_4X4, dry_run);
411 }
412
413 for (b = 16; b < 24; b++) {
414 tokenize_b(cpi, xd, xd->block + b, t, PLANE_TYPE_UV,
415 A + vp9_block2above[b], L + vp9_block2left[b],
416 TX_4X4, dry_run);
417 } 523 }
418 } 524 }
419 if (dry_run) 525 if (dry_run)
420 *t = t_backup; 526 *t = t_backup;
421 } 527 }
422 528
423
424 #ifdef ENTROPY_STATS 529 #ifdef ENTROPY_STATS
425 void init_context_counters(void) { 530 void init_context_counters(void) {
426 FILE *f = fopen("context.bin", "rb"); 531 FILE *f = fopen("context.bin", "rb");
427 if (!f) { 532 if (!f) {
428 vpx_memset(context_counters, 0, sizeof(context_counters)); 533 vpx_memset(context_counters_4x4, 0, sizeof(context_counters_4x4));
534 vpx_memset(hybrid_context_counters_4x4, 0,
535 sizeof(hybrid_context_counters_4x4));
429 vpx_memset(context_counters_8x8, 0, sizeof(context_counters_8x8)); 536 vpx_memset(context_counters_8x8, 0, sizeof(context_counters_8x8));
537 vpx_memset(hybrid_context_counters_8x8, 0,
538 sizeof(hybrid_context_counters_8x8));
430 vpx_memset(context_counters_16x16, 0, sizeof(context_counters_16x16)); 539 vpx_memset(context_counters_16x16, 0, sizeof(context_counters_16x16));
540 vpx_memset(hybrid_context_counters_16x16, 0,
541 sizeof(hybrid_context_counters_16x16));
542 vpx_memset(context_counters_32x32, 0, sizeof(context_counters_32x32));
431 } else { 543 } else {
432 fread(context_counters, sizeof(context_counters), 1, f); 544 fread(context_counters_4x4, sizeof(context_counters_4x4), 1, f);
545 fread(hybrid_context_counters_4x4,
546 sizeof(hybrid_context_counters_4x4), 1, f);
433 fread(context_counters_8x8, sizeof(context_counters_8x8), 1, f); 547 fread(context_counters_8x8, sizeof(context_counters_8x8), 1, f);
548 fread(hybrid_context_counters_8x8,
549 sizeof(hybrid_context_counters_8x8), 1, f);
434 fread(context_counters_16x16, sizeof(context_counters_16x16), 1, f); 550 fread(context_counters_16x16, sizeof(context_counters_16x16), 1, f);
551 fread(hybrid_context_counters_16x16,
552 sizeof(hybrid_context_counters_16x16), 1, f);
553 fread(context_counters_32x32, sizeof(context_counters_32x32), 1, f);
435 fclose(f); 554 fclose(f);
436 } 555 }
437 556
438 f = fopen("treeupdate.bin", "rb"); 557 f = fopen("treeupdate.bin", "rb");
439 if (!f) { 558 if (!f) {
440 vpx_memset(tree_update_hist, 0, sizeof(tree_update_hist)); 559 vpx_memset(tree_update_hist_4x4, 0, sizeof(tree_update_hist_4x4));
560 vpx_memset(hybrid_tree_update_hist_4x4, 0,
561 sizeof(hybrid_tree_update_hist_4x4));
441 vpx_memset(tree_update_hist_8x8, 0, sizeof(tree_update_hist_8x8)); 562 vpx_memset(tree_update_hist_8x8, 0, sizeof(tree_update_hist_8x8));
563 vpx_memset(hybrid_tree_update_hist_8x8, 0,
564 sizeof(hybrid_tree_update_hist_8x8));
442 vpx_memset(tree_update_hist_16x16, 0, sizeof(tree_update_hist_16x16)); 565 vpx_memset(tree_update_hist_16x16, 0, sizeof(tree_update_hist_16x16));
566 vpx_memset(hybrid_tree_update_hist_16x16, 0,
567 sizeof(hybrid_tree_update_hist_16x16));
568 vpx_memset(tree_update_hist_32x32, 0, sizeof(tree_update_hist_32x32));
443 } else { 569 } else {
444 fread(tree_update_hist, sizeof(tree_update_hist), 1, f); 570 fread(tree_update_hist_4x4, sizeof(tree_update_hist_4x4), 1, f);
571 fread(hybrid_tree_update_hist_4x4,
572 sizeof(hybrid_tree_update_hist_4x4), 1, f);
445 fread(tree_update_hist_8x8, sizeof(tree_update_hist_8x8), 1, f); 573 fread(tree_update_hist_8x8, sizeof(tree_update_hist_8x8), 1, f);
574 fread(hybrid_tree_update_hist_8x8,
575 sizeof(hybrid_tree_update_hist_8x8), 1, f);
446 fread(tree_update_hist_16x16, sizeof(tree_update_hist_16x16), 1, f); 576 fread(tree_update_hist_16x16, sizeof(tree_update_hist_16x16), 1, f);
577 fread(hybrid_tree_update_hist_16x16,
578 sizeof(hybrid_tree_update_hist_16x16), 1, f);
579 fread(tree_update_hist_32x32, sizeof(tree_update_hist_32x32), 1, f);
447 fclose(f); 580 fclose(f);
448 } 581 }
449 } 582 }
450 583
451 void print_context_counters() { 584 static void print_counter(FILE *f, vp9_coeff_accum *context_counters,
585 int block_types, const char *header) {
452 int type, band, pt, t; 586 int type, band, pt, t;
453 FILE *f = fopen("vp9_context.c", "w");
454 587
455 fprintf(f, "#include \"vp9_entropy.h\"\n"); 588 fprintf(f, "static const vp9_coeff_count %s = {\n", header);
456 fprintf(f, "\n/* *** GENERATED FILE: DO NOT EDIT *** */\n\n");
457 fprintf(f, "static const unsigned int\n"
458 "vp9_default_coef_counts[BLOCK_TYPES]\n"
459 " [COEF_BANDS]\n"
460 " [PREV_COEF_CONTEXTS]\n"
461 " [MAX_ENTROPY_TOKENS]={\n");
462 589
463 # define Comma( X) (X? ",":"") 590 #define Comma(X) (X ? "," : "")
464 type = 0; 591 type = 0;
465 do { 592 do {
466 fprintf(f, "%s\n { /* block Type %d */", Comma(type), type); 593 fprintf(f, "%s\n { /* block Type %d */", Comma(type), type);
467 band = 0; 594 band = 0;
468 do { 595 do {
469 fprintf(f, "%s\n { /* Coeff Band %d */", Comma(band), band); 596 fprintf(f, "%s\n { /* Coeff Band %d */", Comma(band), band);
470 pt = 0; 597 pt = 0;
471 do { 598 do {
472 fprintf(f, "%s\n {", Comma(pt)); 599 fprintf(f, "%s\n {", Comma(pt));
473 600
474 t = 0; 601 t = 0;
475 do { 602 do {
476 const INT64 x = context_counters [type] [band] [pt] [t]; 603 const int64_t x = context_counters[type][band][pt][t];
477 const int y = (int) x; 604 const int y = (int) x;
478 assert(x == (INT64) y); /* no overflow handling yet */ 605
606 assert(x == (int64_t) y); /* no overflow handling yet */
479 fprintf(f, "%s %d", Comma(t), y); 607 fprintf(f, "%s %d", Comma(t), y);
480 } while (++t < MAX_ENTROPY_TOKENS); 608 } while (++t < MAX_ENTROPY_TOKENS);
481 fprintf(f, "}"); 609 fprintf(f, "}");
482 } while (++pt < PREV_COEF_CONTEXTS); 610 } while (++pt < PREV_COEF_CONTEXTS);
483 fprintf(f, "\n }"); 611 fprintf(f, "\n }");
484 } while (++band < COEF_BANDS); 612 } while (++band < COEF_BANDS);
485 fprintf(f, "\n }"); 613 fprintf(f, "\n }");
486 } while (++type < BLOCK_TYPES); 614 } while (++type < block_types);
487 fprintf(f, "\n};\n"); 615 fprintf(f, "\n};\n");
616 }
488 617
489 fprintf(f, "static const unsigned int\nvp9_default_coef_counts_8x8" 618 static void print_probs(FILE *f, vp9_coeff_accum *context_counters,
490 "[BLOCK_TYPES_8X8] [COEF_BANDS]" 619 int block_types, const char *header) {
491 "[PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS] = {"); 620 int type, band, pt, t;
621
622 fprintf(f, "static const vp9_coeff_probs %s = {", header);
623
492 type = 0; 624 type = 0;
625 #define Newline(x, spaces) (x ? " " : "\n" spaces)
493 do { 626 do {
494 fprintf(f, "%s\n { /* block Type %d */", Comma(type), type); 627 fprintf(f, "%s%s{ /* block Type %d */",
628 Comma(type), Newline(type, " "), type);
495 band = 0; 629 band = 0;
496 do { 630 do {
497 fprintf(f, "%s\n { /* Coeff Band %d */", Comma(band), band); 631 fprintf(f, "%s%s{ /* Coeff Band %d */",
632 Comma(band), Newline(band, " "), band);
498 pt = 0; 633 pt = 0;
499 do { 634 do {
500 fprintf(f, "%s\n {", Comma(pt)); 635 unsigned int branch_ct[ENTROPY_NODES][2];
501 t = 0;
502 do {
503 const INT64 x = context_counters_8x8 [type] [band] [pt] [t];
504 const int y = (int) x;
505
506 assert(x == (INT64) y); /* no overflow handling yet */
507 fprintf(f, "%s %d", Comma(t), y);
508
509 } while (++t < MAX_ENTROPY_TOKENS);
510
511 fprintf(f, "}");
512 } while (++pt < PREV_COEF_CONTEXTS);
513
514 fprintf(f, "\n }");
515
516 } while (++band < COEF_BANDS);
517
518 fprintf(f, "\n }");
519 } while (++type < BLOCK_TYPES_8X8);
520 fprintf(f, "\n};\n");
521
522 fprintf(f, "static const unsigned int\nvp9_default_coef_counts_16x16"
523 "[BLOCK_TYPES_16X16] [COEF_BANDS]"
524 "[PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS] = {");
525 type = 0;
526 do {
527 fprintf(f, "%s\n { /* block Type %d */", Comma(type), type);
528 band = 0;
529 do {
530 fprintf(f, "%s\n { /* Coeff Band %d */", Comma(band), band);
531 pt = 0;
532 do {
533 fprintf(f, "%s\n {", Comma(pt));
534 t = 0;
535 do {
536 const INT64 x = context_counters_16x16 [type] [band] [pt] [t];
537 const int y = (int) x;
538
539 assert(x == (INT64) y); /* no overflow handling yet */
540 fprintf(f, "%s %d", Comma(t), y);
541
542 } while (++t < MAX_ENTROPY_TOKENS);
543
544 fprintf(f, "}");
545 } while (++pt < PREV_COEF_CONTEXTS);
546
547 fprintf(f, "\n }");
548
549 } while (++band < COEF_BANDS);
550
551 fprintf(f, "\n }");
552 } while (++type < BLOCK_TYPES_16X16);
553 fprintf(f, "\n};\n");
554
555 fprintf(f, "static const vp9_prob\n"
556 "vp9_default_coef_probs[BLOCK_TYPES] [COEF_BANDS] \n"
557 "[PREV_COEF_CONTEXTS] [ENTROPY_NODES] = {");
558 type = 0;
559 do {
560 fprintf(f, "%s\n { /* block Type %d */", Comma(type), type);
561 band = 0;
562 do {
563 fprintf(f, "%s\n { /* Coeff Band %d */", Comma(band), band);
564 pt = 0;
565 do {
566 unsigned int branch_ct [ENTROPY_NODES] [2];
567 unsigned int coef_counts[MAX_ENTROPY_TOKENS]; 636 unsigned int coef_counts[MAX_ENTROPY_TOKENS];
568 vp9_prob coef_probs[ENTROPY_NODES]; 637 vp9_prob coef_probs[ENTROPY_NODES];
638
569 for (t = 0; t < MAX_ENTROPY_TOKENS; ++t) 639 for (t = 0; t < MAX_ENTROPY_TOKENS; ++t)
570 coef_counts[t] = context_counters [type] [band] [pt] [t]; 640 coef_counts[t] = context_counters[type][band][pt][t];
571 vp9_tree_probs_from_distribution( 641 vp9_tree_probs_from_distribution(MAX_ENTROPY_TOKENS,
572 MAX_ENTROPY_TOKENS, vp9_coef_encodings, vp9_coef_tree, 642 vp9_coef_encodings, vp9_coef_tree,
573 coef_probs, branch_ct, coef_counts, 256, 1); 643 coef_probs, branch_ct, coef_counts);
574 fprintf(f, "%s\n {", Comma(pt)); 644 fprintf(f, "%s\n {", Comma(pt));
575 645
576 t = 0; 646 t = 0;
577 do { 647 do {
578 fprintf(f, "%s %d", Comma(t), coef_probs[t]); 648 fprintf(f, "%s %3d", Comma(t), coef_probs[t]);
579
580 } while (++t < ENTROPY_NODES); 649 } while (++t < ENTROPY_NODES);
581 650
582 fprintf(f, "}"); 651 fprintf(f, " }");
583 } while (++pt < PREV_COEF_CONTEXTS); 652 } while (++pt < PREV_COEF_CONTEXTS);
584 fprintf(f, "\n }"); 653 fprintf(f, "\n }");
585 } while (++band < COEF_BANDS); 654 } while (++band < COEF_BANDS);
586 fprintf(f, "\n }"); 655 fprintf(f, "\n }");
587 } while (++type < BLOCK_TYPES); 656 } while (++type < block_types);
588 fprintf(f, "\n};\n"); 657 fprintf(f, "\n};\n");
658 }
589 659
590 fprintf(f, "static const vp9_prob\n" 660 void print_context_counters() {
591 "vp9_default_coef_probs_8x8[BLOCK_TYPES_8X8] [COEF_BANDS]\n" 661 FILE *f = fopen("vp9_context.c", "w");
592 "[PREV_COEF_CONTEXTS] [ENTROPY_NODES] = {");
593 type = 0;
594 do {
595 fprintf(f, "%s\n { /* block Type %d */", Comma(type), type);
596 band = 0;
597 do {
598 fprintf(f, "%s\n { /* Coeff Band %d */", Comma(band), band);
599 pt = 0;
600 do {
601 unsigned int branch_ct [ENTROPY_NODES] [2];
602 unsigned int coef_counts[MAX_ENTROPY_TOKENS];
603 vp9_prob coef_probs[ENTROPY_NODES];
604 for (t = 0; t < MAX_ENTROPY_TOKENS; ++t)
605 coef_counts[t] = context_counters_8x8[type] [band] [pt] [t];
606 vp9_tree_probs_from_distribution(
607 MAX_ENTROPY_TOKENS, vp9_coef_encodings, vp9_coef_tree,
608 coef_probs, branch_ct, coef_counts, 256, 1);
609 fprintf(f, "%s\n {", Comma(pt));
610 662
611 t = 0; 663 fprintf(f, "#include \"vp9_entropy.h\"\n");
612 do { 664 fprintf(f, "\n/* *** GENERATED FILE: DO NOT EDIT *** */\n\n");
613 fprintf(f, "%s %d", Comma(t), coef_probs[t]);
614 } while (++t < ENTROPY_NODES);
615 fprintf(f, "}");
616 } while (++pt < PREV_COEF_CONTEXTS);
617 fprintf(f, "\n }");
618 } while (++band < COEF_BANDS);
619 fprintf(f, "\n }");
620 } while (++type < BLOCK_TYPES_8X8);
621 fprintf(f, "\n};\n");
622 665
623 fprintf(f, "static const vp9_prob\n" 666 /* print counts */
624 "vp9_default_coef_probs_16x16[BLOCK_TYPES_16X16] [COEF_BANDS]\n" 667 print_counter(f, context_counters_4x4, BLOCK_TYPES_4X4,
625 "[PREV_COEF_CONTEXTS] [ENTROPY_NODES] = {"); 668 "vp9_default_coef_counts_4x4[BLOCK_TYPES_4X4]");
626 type = 0; 669 print_counter(f, hybrid_context_counters_4x4, BLOCK_TYPES_4X4,
627 do { 670 "vp9_default_hybrid_coef_counts_4x4[BLOCK_TYPES_4X4]");
628 fprintf(f, "%s\n { /* block Type %d */", Comma(type), type); 671 print_counter(f, context_counters_8x8, BLOCK_TYPES_8X8,
629 band = 0; 672 "vp9_default_coef_counts_8x8[BLOCK_TYPES_8X8]");
630 do { 673 print_counter(f, hybrid_context_counters_8x8, BLOCK_TYPES_8X8,
631 fprintf(f, "%s\n { /* Coeff Band %d */", Comma(band), band); 674 "vp9_default_hybrid_coef_counts_8x8[BLOCK_TYPES_8X8]");
632 pt = 0; 675 print_counter(f, context_counters_16x16, BLOCK_TYPES_16X16,
633 do { 676 "vp9_default_coef_counts_16x16[BLOCK_TYPES_16X16]");
634 unsigned int branch_ct [ENTROPY_NODES] [2]; 677 print_counter(f, hybrid_context_counters_16x16, BLOCK_TYPES_16X16,
635 unsigned int coef_counts[MAX_ENTROPY_TOKENS]; 678 "vp9_default_hybrid_coef_counts_16x16[BLOCK_TYPES_16X16]");
636 vp9_prob coef_probs[ENTROPY_NODES]; 679 print_counter(f, context_counters_32x32, BLOCK_TYPES_32X32,
637 for (t = 0; t < MAX_ENTROPY_TOKENS; ++t) 680 "vp9_default_coef_counts_32x32[BLOCK_TYPES_32X32]");
638 coef_counts[t] = context_counters_16x16[type] [band] [pt] [t];
639 vp9_tree_probs_from_distribution(
640 MAX_ENTROPY_TOKENS, vp9_coef_encodings, vp9_coef_tree,
641 coef_probs, branch_ct, coef_counts, 256, 1);
642 fprintf(f, "%s\n {", Comma(pt));
643 681
644 t = 0; 682 /* print coefficient probabilities */
645 do { 683 print_probs(f, context_counters_4x4, BLOCK_TYPES_4X4,
646 fprintf(f, "%s %d", Comma(t), coef_probs[t]); 684 "default_coef_probs_4x4[BLOCK_TYPES_4X4]");
647 } while (++t < ENTROPY_NODES); 685 print_probs(f, hybrid_context_counters_4x4, BLOCK_TYPES_4X4,
648 fprintf(f, "}"); 686 "default_hybrid_coef_probs_4x4[BLOCK_TYPES_4X4]");
649 } while (++pt < PREV_COEF_CONTEXTS); 687 print_probs(f, context_counters_8x8, BLOCK_TYPES_8X8,
650 fprintf(f, "\n }"); 688 "default_coef_probs_8x8[BLOCK_TYPES_8X8]");
651 } while (++band < COEF_BANDS); 689 print_probs(f, hybrid_context_counters_8x8, BLOCK_TYPES_8X8,
652 fprintf(f, "\n }"); 690 "default_hybrid_coef_probs_8x8[BLOCK_TYPES_8X8]");
653 } while (++type < BLOCK_TYPES_16X16); 691 print_probs(f, context_counters_16x16, BLOCK_TYPES_16X16,
654 fprintf(f, "\n};\n"); 692 "default_coef_probs_16x16[BLOCK_TYPES_16X16]");
693 print_probs(f, hybrid_context_counters_16x16, BLOCK_TYPES_16X16,
694 "default_hybrid_coef_probs_16x16[BLOCK_TYPES_16X16]");
695 print_probs(f, context_counters_32x32, BLOCK_TYPES_32X32,
696 "default_coef_probs_32x32[BLOCK_TYPES_32X32]");
655 697
656 fclose(f); 698 fclose(f);
657 699
658 f = fopen("context.bin", "wb"); 700 f = fopen("context.bin", "wb");
659 fwrite(context_counters, sizeof(context_counters), 1, f); 701 fwrite(context_counters_4x4, sizeof(context_counters_4x4), 1, f);
702 fwrite(hybrid_context_counters_4x4,
703 sizeof(hybrid_context_counters_4x4), 1, f);
660 fwrite(context_counters_8x8, sizeof(context_counters_8x8), 1, f); 704 fwrite(context_counters_8x8, sizeof(context_counters_8x8), 1, f);
705 fwrite(hybrid_context_counters_8x8,
706 sizeof(hybrid_context_counters_8x8), 1, f);
661 fwrite(context_counters_16x16, sizeof(context_counters_16x16), 1, f); 707 fwrite(context_counters_16x16, sizeof(context_counters_16x16), 1, f);
708 fwrite(hybrid_context_counters_16x16,
709 sizeof(hybrid_context_counters_16x16), 1, f);
710 fwrite(context_counters_32x32, sizeof(context_counters_32x32), 1, f);
662 fclose(f); 711 fclose(f);
663 } 712 }
664 #endif 713 #endif
665 714
666 void vp9_tokenize_initialize() { 715 void vp9_tokenize_initialize() {
667 fill_value_tokens(); 716 fill_value_tokens();
668 } 717 }
669 718
670 static __inline void stuff_b(VP9_COMP *cpi, 719 static __inline void stuff_b(VP9_COMP *cpi,
671 MACROBLOCKD *xd, 720 MACROBLOCKD *xd,
672 const BLOCKD * const b, 721 const int ib,
673 TOKENEXTRA **tp, 722 TOKENEXTRA **tp,
674 PLANE_TYPE type, 723 PLANE_TYPE type,
675 ENTROPY_CONTEXT *a,
676 ENTROPY_CONTEXT *l,
677 TX_SIZE tx_size, 724 TX_SIZE tx_size,
678 int dry_run) { 725 int dry_run) {
726 const BLOCKD * const b = xd->block + ib;
679 const int *bands; 727 const int *bands;
680 unsigned int (*counts)[COEF_BANDS][PREV_COEF_CONTEXTS][MAX_ENTROPY_TOKENS]; 728 vp9_coeff_count *counts;
681 vp9_prob (*probs)[COEF_BANDS][PREV_COEF_CONTEXTS][ENTROPY_NODES]; 729 vp9_coeff_probs *probs;
682 int pt, band; 730 int pt, band;
683 TOKENEXTRA *t = *tp; 731 TOKENEXTRA *t = *tp;
684 const TX_TYPE tx_type = (type == PLANE_TYPE_Y_WITH_DC) ? 732 const TX_TYPE tx_type = (type == PLANE_TYPE_Y_WITH_DC) ?
685 get_tx_type(xd, b) : DCT_DCT; 733 get_tx_type(xd, b) : DCT_DCT;
686 VP9_COMBINEENTROPYCONTEXTS(pt, *a, *l); 734 ENTROPY_CONTEXT *const a = (ENTROPY_CONTEXT *)xd->above_context +
735 vp9_block2above[tx_size][ib];
736 ENTROPY_CONTEXT *const l = (ENTROPY_CONTEXT *)xd->left_context +
737 vp9_block2left[tx_size][ib];
738 ENTROPY_CONTEXT a_ec = *a, l_ec = *l;
739 ENTROPY_CONTEXT *const a1 = (ENTROPY_CONTEXT *)(&xd->above_context[1]) +
740 vp9_block2above[tx_size][ib];
741 ENTROPY_CONTEXT *const l1 = (ENTROPY_CONTEXT *)(&xd->left_context[1]) +
742 vp9_block2left[tx_size][ib];
687 743
688 switch (tx_size) { 744 switch (tx_size) {
689 default: 745 default:
690 case TX_4X4: 746 case TX_4X4:
691 bands = vp9_coef_bands; 747 bands = vp9_coef_bands_4x4;
692 if (tx_type != DCT_DCT) { 748 if (tx_type != DCT_DCT) {
693 counts = cpi->hybrid_coef_counts; 749 counts = cpi->hybrid_coef_counts_4x4;
694 probs = cpi->common.fc.hybrid_coef_probs; 750 probs = cpi->common.fc.hybrid_coef_probs_4x4;
695 } else { 751 } else {
696 counts = cpi->coef_counts; 752 counts = cpi->coef_counts_4x4;
697 probs = cpi->common.fc.coef_probs; 753 probs = cpi->common.fc.coef_probs_4x4;
698 } 754 }
699 break; 755 break;
700 case TX_8X8: 756 case TX_8X8:
757 #if CONFIG_CNVCONTEXT
758 if (type != PLANE_TYPE_Y2) {
759 a_ec = (a[0] + a[1]) != 0;
760 l_ec = (l[0] + l[1]) != 0;
761 }
762 #endif
701 bands = vp9_coef_bands_8x8; 763 bands = vp9_coef_bands_8x8;
702 if (tx_type != DCT_DCT) { 764 if (tx_type != DCT_DCT) {
703 counts = cpi->hybrid_coef_counts_8x8; 765 counts = cpi->hybrid_coef_counts_8x8;
704 probs = cpi->common.fc.hybrid_coef_probs_8x8; 766 probs = cpi->common.fc.hybrid_coef_probs_8x8;
705 } else { 767 } else {
706 counts = cpi->coef_counts_8x8; 768 counts = cpi->coef_counts_8x8;
707 probs = cpi->common.fc.coef_probs_8x8; 769 probs = cpi->common.fc.coef_probs_8x8;
708 } 770 }
709 break; 771 break;
710 case TX_16X16: 772 case TX_16X16:
773 #if CONFIG_CNVCONTEXT
774 if (type != PLANE_TYPE_UV) {
775 a_ec = (a[0] + a[1] + a[2] + a[3]) != 0;
776 l_ec = (l[0] + l[1] + l[2] + l[3]) != 0;
777 } else {
778 a_ec = (a[0] + a[1] + a1[0] + a1[1]) != 0;
779 l_ec = (l[0] + l[1] + l1[0] + l1[1]) != 0;
780 }
781 #endif
711 bands = vp9_coef_bands_16x16; 782 bands = vp9_coef_bands_16x16;
712 if (tx_type != DCT_DCT) { 783 if (tx_type != DCT_DCT) {
713 counts = cpi->hybrid_coef_counts_16x16; 784 counts = cpi->hybrid_coef_counts_16x16;
714 probs = cpi->common.fc.hybrid_coef_probs_16x16; 785 probs = cpi->common.fc.hybrid_coef_probs_16x16;
715 } else { 786 } else {
716 counts = cpi->coef_counts_16x16; 787 counts = cpi->coef_counts_16x16;
717 probs = cpi->common.fc.coef_probs_16x16; 788 probs = cpi->common.fc.coef_probs_16x16;
718 } 789 }
719 break; 790 break;
791 case TX_32X32:
792 #if CONFIG_CNVCONTEXT
793 a_ec = a[0] + a[1] + a[2] + a[3] +
794 a1[0] + a1[1] + a1[2] + a1[3];
795 l_ec = l[0] + l[1] + l[2] + l[3] +
796 l1[0] + l1[1] + l1[2] + l1[3];
797 a_ec = a_ec != 0;
798 l_ec = l_ec != 0;
799 #endif
800 bands = vp9_coef_bands_32x32;
801 counts = cpi->coef_counts_32x32;
802 probs = cpi->common.fc.coef_probs_32x32;
803 break;
720 } 804 }
805
806 VP9_COMBINEENTROPYCONTEXTS(pt, a_ec, l_ec);
807
721 band = bands[(type == PLANE_TYPE_Y_NO_DC) ? 1 : 0]; 808 band = bands[(type == PLANE_TYPE_Y_NO_DC) ? 1 : 0];
722 t->Token = DCT_EOB_TOKEN; 809 t->Token = DCT_EOB_TOKEN;
723 t->context_tree = probs[type][band][pt]; 810 t->context_tree = probs[type][band][pt];
724 t->skip_eob_node = 0; 811 t->skip_eob_node = 0;
725 ++t; 812 ++t;
726 *tp = t; 813 *tp = t;
727 *a = *l = 0; 814 *a = *l = 0;
815 if (tx_size == TX_8X8 && type != PLANE_TYPE_Y2) {
816 a[1] = 0;
817 l[1] = 0;
818 } else if (tx_size == TX_16X16) {
819 if (type != PLANE_TYPE_UV) {
820 a[1] = a[2] = a[3] = 0;
821 l[1] = l[2] = l[3] = 0;
822 } else {
823 a1[0] = a1[1] = a[1] = a_ec;
824 l1[0] = l1[1] = l[1] = l_ec;
825 }
826 } else if (tx_size == TX_32X32) {
827 a[1] = a[2] = a[3] = a_ec;
828 l[1] = l[2] = l[3] = l_ec;
829 a1[0] = a1[1] = a1[2] = a1[3] = a_ec;
830 l1[0] = l1[1] = l1[2] = l1[3] = l_ec;
831 }
832
728 if (!dry_run) { 833 if (!dry_run) {
729 ++counts[type][band][pt][DCT_EOB_TOKEN]; 834 ++counts[type][band][pt][DCT_EOB_TOKEN];
730 } 835 }
731 } 836 }
732 837
733 static void stuff_mb_8x8(VP9_COMP *cpi, MACROBLOCKD *xd, 838 static void stuff_mb_8x8(VP9_COMP *cpi, MACROBLOCKD *xd,
734 TOKENEXTRA **t, int dry_run) { 839 TOKENEXTRA **t, int dry_run) {
735 ENTROPY_CONTEXT *A = (ENTROPY_CONTEXT *)xd->above_context;
736 ENTROPY_CONTEXT *L = (ENTROPY_CONTEXT *)xd->left_context;
737 PLANE_TYPE plane_type; 840 PLANE_TYPE plane_type;
738 int b; 841 int b;
739 int has_2nd_order = get_2nd_order_usage(xd); 842 int has_2nd_order = get_2nd_order_usage(xd);
740 843
741 if (has_2nd_order) { 844 if (has_2nd_order) {
742 stuff_b(cpi, xd, xd->block + 24, t, PLANE_TYPE_Y2, 845 stuff_b(cpi, xd, 24, t, PLANE_TYPE_Y2, TX_8X8, dry_run);
743 A + vp9_block2above_8x8[24], L + vp9_block2left_8x8[24],
744 TX_8X8, dry_run);
745 plane_type = PLANE_TYPE_Y_NO_DC; 846 plane_type = PLANE_TYPE_Y_NO_DC;
746 } else { 847 } else {
747 xd->above_context->y2 = 1; 848 #if CONFIG_CNVCONTEXT
748 xd->left_context->y2 = 1; 849 xd->above_context->y2 = 0;
850 xd->left_context->y2 = 0;
851 #endif
749 plane_type = PLANE_TYPE_Y_WITH_DC; 852 plane_type = PLANE_TYPE_Y_WITH_DC;
750 } 853 }
751 854
752 for (b = 0; b < 16; b += 4) { 855 for (b = 0; b < 24; b += 4) {
753 stuff_b(cpi, xd, xd->block + b, t, plane_type, A + vp9_block2above_8x8[b], 856 if (b >= 16)
754 L + vp9_block2left_8x8[b], TX_8X8, dry_run); 857 plane_type = PLANE_TYPE_UV;
755 A[vp9_block2above_8x8[b] + 1] = A[vp9_block2above_8x8[b]]; 858 stuff_b(cpi, xd, b, t, plane_type, TX_8X8, dry_run);
756 L[vp9_block2left_8x8[b] + 1] = L[vp9_block2left_8x8[b]];
757 }
758
759 for (b = 16; b < 24; b += 4) {
760 stuff_b(cpi, xd, xd->block + b, t, PLANE_TYPE_UV,
761 A + vp9_block2above_8x8[b], L + vp9_block2left_8x8[b],
762 TX_8X8, dry_run);
763 A[vp9_block2above_8x8[b] + 1] = A[vp9_block2above_8x8[b]];
764 L[vp9_block2left_8x8[b] + 1] = L[vp9_block2left_8x8[b]];
765 } 859 }
766 } 860 }
767 861
768 static void stuff_mb_16x16(VP9_COMP *cpi, MACROBLOCKD *xd, 862 static void stuff_mb_16x16(VP9_COMP *cpi, MACROBLOCKD *xd,
769 TOKENEXTRA **t, int dry_run) { 863 TOKENEXTRA **t, int dry_run) {
770 ENTROPY_CONTEXT * A = (ENTROPY_CONTEXT *)xd->above_context;
771 ENTROPY_CONTEXT * L = (ENTROPY_CONTEXT *)xd->left_context;
772 int b; 864 int b;
865 stuff_b(cpi, xd, 0, t, PLANE_TYPE_Y_WITH_DC, TX_16X16, dry_run);
773 866
774 stuff_b(cpi, xd, xd->block, t, PLANE_TYPE_Y_WITH_DC, A, L, TX_16X16, dry_run);
775 A[1] = A[2] = A[3] = A[0];
776 L[1] = L[2] = L[3] = L[0];
777 for (b = 16; b < 24; b += 4) { 867 for (b = 16; b < 24; b += 4) {
778 stuff_b(cpi, xd, xd->block + b, t, PLANE_TYPE_UV, A + vp9_block2above[b], 868 stuff_b(cpi, xd, b, t, PLANE_TYPE_UV, TX_8X8, dry_run);
779 L + vp9_block2above_8x8[b], TX_8X8, dry_run);
780 A[vp9_block2above_8x8[b] + 1] = A[vp9_block2above_8x8[b]];
781 L[vp9_block2left_8x8[b] + 1] = L[vp9_block2left_8x8[b]];
782 } 869 }
783 vpx_memset(&A[8], 0, sizeof(A[8])); 870 #if CONFIG_CNVCONTEXT
784 vpx_memset(&L[8], 0, sizeof(L[8])); 871 xd->above_context->y2 = 0;
872 xd->left_context->y2 = 0;
873 #endif
785 } 874 }
786 875
787 static void stuff_mb_4x4(VP9_COMP *cpi, MACROBLOCKD *xd, 876 static void stuff_mb_4x4(VP9_COMP *cpi, MACROBLOCKD *xd,
788 TOKENEXTRA **t, int dry_run) { 877 TOKENEXTRA **t, int dry_run) {
789 ENTROPY_CONTEXT *A = (ENTROPY_CONTEXT *)xd->above_context;
790 ENTROPY_CONTEXT *L = (ENTROPY_CONTEXT *)xd->left_context;
791 int b; 878 int b;
792 PLANE_TYPE plane_type; 879 PLANE_TYPE plane_type;
793 int has_2nd_order = (xd->mode_info_context->mbmi.mode != B_PRED && 880 int has_2nd_order = get_2nd_order_usage(xd);
794 xd->mode_info_context->mbmi.mode != I8X8_PRED &&
795 xd->mode_info_context->mbmi.mode != SPLITMV);
796 if (has_2nd_order && get_tx_type(xd, &xd->block[0]) != DCT_DCT)
797 has_2nd_order = 0;
798 881
799 if (has_2nd_order) { 882 if (has_2nd_order) {
800 stuff_b(cpi, xd, xd->block + 24, t, PLANE_TYPE_Y2, A + vp9_block2above[24], 883 stuff_b(cpi, xd, 24, t, PLANE_TYPE_Y2, TX_4X4, dry_run);
801 L + vp9_block2left[24], TX_4X4, dry_run);
802 plane_type = PLANE_TYPE_Y_NO_DC; 884 plane_type = PLANE_TYPE_Y_NO_DC;
803 } else { 885 } else {
804 xd->above_context->y2 = 1; 886 xd->above_context->y2 = 0;
805 xd->left_context->y2 = 1; 887 xd->left_context->y2 = 0;
806 plane_type = PLANE_TYPE_Y_WITH_DC; 888 plane_type = PLANE_TYPE_Y_WITH_DC;
807 } 889 }
808 890
809 for (b = 0; b < 16; b++) 891 for (b = 0; b < 24; b++) {
810 stuff_b(cpi, xd, xd->block + b, t, plane_type, A + vp9_block2above[b], 892 if (b >= 16)
811 L + vp9_block2left[b], TX_4X4, dry_run); 893 plane_type = PLANE_TYPE_UV;
812 894 stuff_b(cpi, xd, b, t, plane_type, TX_4X4, dry_run);
813 for (b = 16; b < 24; b++) 895 }
814 stuff_b(cpi, xd, xd->block + b, t, PLANE_TYPE_UV, A + vp9_block2above[b],
815 L + vp9_block2left[b], TX_4X4, dry_run);
816 } 896 }
817 897
818 static void stuff_mb_8x8_4x4uv(VP9_COMP *cpi, MACROBLOCKD *xd, 898 static void stuff_mb_8x8_4x4uv(VP9_COMP *cpi, MACROBLOCKD *xd,
819 TOKENEXTRA **t, int dry_run) { 899 TOKENEXTRA **t, int dry_run) {
820 ENTROPY_CONTEXT *A = (ENTROPY_CONTEXT *)xd->above_context;
821 ENTROPY_CONTEXT *L = (ENTROPY_CONTEXT *)xd->left_context;
822 PLANE_TYPE plane_type; 900 PLANE_TYPE plane_type;
823 int b; 901 int b;
824 902
825 int has_2nd_order = get_2nd_order_usage(xd); 903 int has_2nd_order = get_2nd_order_usage(xd);
826 if (has_2nd_order) { 904 if (has_2nd_order) {
827 stuff_b(cpi, xd, xd->block + 24, t, PLANE_TYPE_Y2, 905 stuff_b(cpi, xd, 24, t, PLANE_TYPE_Y2, TX_8X8, dry_run);
828 A + vp9_block2above_8x8[24], L + vp9_block2left_8x8[24],
829 TX_8X8, dry_run);
830 plane_type = PLANE_TYPE_Y_NO_DC; 906 plane_type = PLANE_TYPE_Y_NO_DC;
831 } else { 907 } else {
908 xd->above_context->y2 = 0;
909 xd->left_context->y2 = 0;
832 plane_type = PLANE_TYPE_Y_WITH_DC; 910 plane_type = PLANE_TYPE_Y_WITH_DC;
833 } 911 }
834 912
835 for (b = 0; b < 16; b += 4) { 913 for (b = 0; b < 16; b += 4) {
836 stuff_b(cpi, xd, xd->block + b, t, plane_type, 914 stuff_b(cpi, xd, b, t, plane_type, TX_8X8, dry_run);
837 A + vp9_block2above_8x8[b], L + vp9_block2left_8x8[b],
838 TX_8X8, dry_run);
839 A[vp9_block2above_8x8[b] + 1] = A[vp9_block2above_8x8[b]];
840 L[vp9_block2left_8x8[b] + 1] = L[vp9_block2left_8x8[b]];
841 } 915 }
842 916
843 for (b = 16; b < 24; b++) 917 for (b = 16; b < 24; b++) {
844 stuff_b(cpi, xd, xd->block + b, t, PLANE_TYPE_UV, A + vp9_block2above[b], 918 stuff_b(cpi, xd, b, t, PLANE_TYPE_UV, TX_4X4, dry_run);
845 L + vp9_block2left[b], TX_4X4, dry_run); 919 }
846 xd->above_context->y2 = 1;
847 xd->left_context->y2 = 1;
848 } 920 }
849 921
850 void vp9_stuff_mb(VP9_COMP *cpi, MACROBLOCKD *xd, TOKENEXTRA **t, int dry_run) { 922 void vp9_stuff_mb(VP9_COMP *cpi, MACROBLOCKD *xd, TOKENEXTRA **t, int dry_run) {
851 TX_SIZE tx_size = xd->mode_info_context->mbmi.txfm_size; 923 TX_SIZE tx_size = xd->mode_info_context->mbmi.txfm_size;
852 TOKENEXTRA * const t_backup = *t; 924 TOKENEXTRA * const t_backup = *t;
853 925
854 if (tx_size == TX_16X16) { 926 if (tx_size == TX_16X16) {
855 stuff_mb_16x16(cpi, xd, t, dry_run); 927 stuff_mb_16x16(cpi, xd, t, dry_run);
856 } else if (tx_size == TX_8X8) { 928 } else if (tx_size == TX_8X8) {
857 if (xd->mode_info_context->mbmi.mode == I8X8_PRED || 929 if (xd->mode_info_context->mbmi.mode == I8X8_PRED ||
858 xd->mode_info_context->mbmi.mode == SPLITMV) { 930 xd->mode_info_context->mbmi.mode == SPLITMV) {
859 stuff_mb_8x8_4x4uv(cpi, xd, t, dry_run); 931 stuff_mb_8x8_4x4uv(cpi, xd, t, dry_run);
860 } else { 932 } else {
861 stuff_mb_8x8(cpi, xd, t, dry_run); 933 stuff_mb_8x8(cpi, xd, t, dry_run);
862 } 934 }
863 } else { 935 } else {
864 stuff_mb_4x4(cpi, xd, t, dry_run); 936 stuff_mb_4x4(cpi, xd, t, dry_run);
865 } 937 }
866 938
867 if (dry_run) { 939 if (dry_run) {
868 *t = t_backup; 940 *t = t_backup;
869 } 941 }
870 } 942 }
871 943
872 void vp9_fix_contexts(MACROBLOCKD *xd) { 944 static void stuff_sb_32x32(VP9_COMP *cpi, MACROBLOCKD *xd,
873 /* Clear entropy contexts for blocks */ 945 TOKENEXTRA **t, int dry_run) {
874 if ((xd->mode_info_context->mbmi.mode != B_PRED 946 int b;
875 && xd->mode_info_context->mbmi.mode != I8X8_PRED 947
876 && xd->mode_info_context->mbmi.mode != SPLITMV) 948 stuff_b(cpi, xd, 0, t, PLANE_TYPE_Y_WITH_DC, TX_32X32, dry_run);
877 || xd->mode_info_context->mbmi.txfm_size == TX_16X16 949 for (b = 16; b < 24; b += 4) {
878 ) { 950 stuff_b(cpi, xd, b, t, PLANE_TYPE_UV, TX_16X16, dry_run);
879 vpx_memset(xd->above_context, 0, sizeof(ENTROPY_CONTEXT_PLANES));
880 vpx_memset(xd->left_context, 0, sizeof(ENTROPY_CONTEXT_PLANES));
881 } else {
882 vpx_memset(xd->above_context, 0, sizeof(ENTROPY_CONTEXT_PLANES) - 1);
883 vpx_memset(xd->left_context, 0, sizeof(ENTROPY_CONTEXT_PLANES) - 1);
884 xd->above_context->y2 = 1;
885 xd->left_context->y2 = 1;
886 } 951 }
887 } 952 }
953
954 void vp9_stuff_sb(VP9_COMP *cpi, MACROBLOCKD *xd, TOKENEXTRA **t, int dry_run) {
955 TOKENEXTRA * const t_backup = *t;
956
957 stuff_sb_32x32(cpi, xd, t, dry_run);
958
959 if (dry_run) {
960 *t = t_backup;
961 }
962 }
963
964 void vp9_fix_contexts_sb(MACROBLOCKD *xd) {
965 vpx_memset(xd->above_context, 0, sizeof(ENTROPY_CONTEXT_PLANES) * 2);
966 vpx_memset(xd->left_context, 0, sizeof(ENTROPY_CONTEXT_PLANES) * 2);
967 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_tokenize.h ('k') | source/libvpx/vp9/encoder/vp9_treewriter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698