OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
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 vp9_coeff_accum context_counters[TX_SIZES][BLOCK_TYPES]; | 28 vp9_coeff_accum context_counters[TX_SIZES][BLOCK_TYPES]; |
29 extern vp9_coeff_stats tree_update_hist[TX_SIZES][BLOCK_TYPES]; | 29 extern vp9_coeff_stats tree_update_hist[TX_SIZES][BLOCK_TYPES]; |
30 #endif /* ENTROPY_STATS */ | 30 #endif /* ENTROPY_STATS */ |
31 | 31 |
32 DECLARE_ALIGNED(16, extern const uint8_t, | |
33 vp9_pt_energy_class[MAX_ENTROPY_TOKENS]); | |
34 | |
35 static TOKENVALUE dct_value_tokens[DCT_MAX_VALUE * 2]; | 32 static TOKENVALUE dct_value_tokens[DCT_MAX_VALUE * 2]; |
36 const TOKENVALUE *vp9_dct_value_tokens_ptr; | 33 const TOKENVALUE *vp9_dct_value_tokens_ptr; |
37 static int dct_value_cost[DCT_MAX_VALUE * 2]; | 34 static int dct_value_cost[DCT_MAX_VALUE * 2]; |
38 const int *vp9_dct_value_cost_ptr; | 35 const int *vp9_dct_value_cost_ptr; |
39 | 36 |
40 static void fill_value_tokens() { | 37 static void fill_value_tokens() { |
41 | |
42 TOKENVALUE *const t = dct_value_tokens + DCT_MAX_VALUE; | 38 TOKENVALUE *const t = dct_value_tokens + DCT_MAX_VALUE; |
43 const vp9_extra_bit *const e = vp9_extra_bits; | 39 const vp9_extra_bit *const e = vp9_extra_bits; |
44 | 40 |
45 int i = -DCT_MAX_VALUE; | 41 int i = -DCT_MAX_VALUE; |
46 int sign = 1; | 42 int sign = 1; |
47 | 43 |
48 do { | 44 do { |
49 if (!i) | 45 if (!i) |
50 sign = 0; | 46 sign = 0; |
51 | 47 |
52 { | 48 { |
53 const int a = sign ? -i : i; | 49 const int a = sign ? -i : i; |
54 int eb = sign; | 50 int eb = sign; |
55 | 51 |
56 if (a > 4) { | 52 if (a > 4) { |
57 int j = 4; | 53 int j = 4; |
58 | 54 |
59 while (++j < 11 && e[j].base_val <= a) {} | 55 while (++j < 11 && e[j].base_val <= a) {} |
60 | 56 |
61 t[i].token = --j; | 57 t[i].token = --j; |
62 eb |= (a - e[j].base_val) << 1; | 58 eb |= (a - e[j].base_val) << 1; |
63 } else | 59 } else { |
64 t[i].token = a; | 60 t[i].token = a; |
65 | 61 } |
66 t[i].extra = eb; | 62 t[i].extra = eb; |
67 } | 63 } |
68 | 64 |
69 // initialize the cost for extra bits for all possible coefficient value. | 65 // initialize the cost for extra bits for all possible coefficient value. |
70 { | 66 { |
71 int cost = 0; | 67 int cost = 0; |
72 const vp9_extra_bit *p = vp9_extra_bits + t[i].token; | 68 const vp9_extra_bit *p = vp9_extra_bits + t[i].token; |
73 | 69 |
74 if (p->base_val) { | 70 if (p->base_val) { |
75 const int extra = t[i].extra; | 71 const int extra = t[i].extra; |
76 const int length = p->len; | 72 const int length = p->len; |
77 | 73 |
78 if (length) | 74 if (length) |
79 cost += treed_cost(p->tree, p->prob, extra >> 1, length); | 75 cost += treed_cost(p->tree, p->prob, extra >> 1, length); |
80 | 76 |
81 cost += vp9_cost_bit(vp9_prob_half, extra & 1); /* sign */ | 77 cost += vp9_cost_bit(vp9_prob_half, extra & 1); /* sign */ |
82 dct_value_cost[i + DCT_MAX_VALUE] = cost; | 78 dct_value_cost[i + DCT_MAX_VALUE] = cost; |
83 } | 79 } |
84 | |
85 } | 80 } |
86 | |
87 } while (++i < DCT_MAX_VALUE); | 81 } while (++i < DCT_MAX_VALUE); |
88 | 82 |
89 vp9_dct_value_tokens_ptr = dct_value_tokens + DCT_MAX_VALUE; | 83 vp9_dct_value_tokens_ptr = dct_value_tokens + DCT_MAX_VALUE; |
90 vp9_dct_value_cost_ptr = dct_value_cost + DCT_MAX_VALUE; | 84 vp9_dct_value_cost_ptr = dct_value_cost + DCT_MAX_VALUE; |
91 } | 85 } |
92 | 86 |
93 struct tokenize_b_args { | 87 struct tokenize_b_args { |
94 VP9_COMP *cpi; | 88 VP9_COMP *cpi; |
95 MACROBLOCKD *xd; | 89 MACROBLOCKD *xd; |
96 TOKENEXTRA **tp; | 90 TOKENEXTRA **tp; |
(...skipping 10 matching lines...) Expand all Loading... |
107 set_contexts(xd, pd, plane_bsize, tx_size, pd->eobs[block] > 0, aoff, loff); | 101 set_contexts(xd, pd, plane_bsize, tx_size, pd->eobs[block] > 0, aoff, loff); |
108 } | 102 } |
109 | 103 |
110 static void tokenize_b(int plane, int block, BLOCK_SIZE plane_bsize, | 104 static void tokenize_b(int plane, int block, BLOCK_SIZE plane_bsize, |
111 TX_SIZE tx_size, void *arg) { | 105 TX_SIZE tx_size, void *arg) { |
112 struct tokenize_b_args* const args = arg; | 106 struct tokenize_b_args* const args = arg; |
113 VP9_COMP *cpi = args->cpi; | 107 VP9_COMP *cpi = args->cpi; |
114 MACROBLOCKD *xd = args->xd; | 108 MACROBLOCKD *xd = args->xd; |
115 TOKENEXTRA **tp = args->tp; | 109 TOKENEXTRA **tp = args->tp; |
116 struct macroblockd_plane *pd = &xd->plane[plane]; | 110 struct macroblockd_plane *pd = &xd->plane[plane]; |
117 MB_MODE_INFO *mbmi = &xd->this_mi->mbmi; | 111 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi; |
118 int pt; /* near block/prev token context index */ | 112 int pt; /* near block/prev token context index */ |
119 int c = 0, rc = 0; | 113 int c = 0, rc = 0; |
120 TOKENEXTRA *t = *tp; /* store tokens starting here */ | 114 TOKENEXTRA *t = *tp; /* store tokens starting here */ |
121 const int eob = pd->eobs[block]; | 115 const int eob = pd->eobs[block]; |
122 const PLANE_TYPE type = pd->plane_type; | 116 const PLANE_TYPE type = pd->plane_type; |
123 const int16_t *qcoeff_ptr = BLOCK_OFFSET(pd->qcoeff, block); | 117 const int16_t *qcoeff_ptr = BLOCK_OFFSET(pd->qcoeff, block); |
124 | 118 |
125 const int segment_id = mbmi->segment_id; | 119 const int segment_id = mbmi->segment_id; |
126 const int16_t *scan, *nb; | 120 const int16_t *scan, *nb; |
127 vp9_coeff_count *const counts = cpi->coef_counts[tx_size]; | 121 vp9_coeff_count *const counts = cpi->coef_counts[tx_size]; |
128 vp9_coeff_probs_model *const coef_probs = cpi->common.fc.coef_probs[tx_size]; | 122 vp9_coeff_probs_model *const coef_probs = cpi->common.fc.coef_probs[tx_size]; |
129 const int ref = is_inter_block(mbmi); | 123 const int ref = is_inter_block(mbmi); |
130 uint8_t token_cache[1024]; | 124 uint8_t token_cache[1024]; |
131 const uint8_t *band_translate; | 125 const uint8_t *const band_translate = get_band_translate(tx_size); |
132 ENTROPY_CONTEXT *A, *L; | |
133 const int seg_eob = get_tx_eob(&cpi->common.seg, segment_id, tx_size); | 126 const int seg_eob = get_tx_eob(&cpi->common.seg, segment_id, tx_size); |
134 int aoff, loff; | 127 int aoff, loff; |
135 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &aoff, &loff); | 128 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &aoff, &loff); |
136 | 129 |
137 A = pd->above_context + aoff; | |
138 L = pd->left_context + loff; | |
139 | |
140 assert((!type && !plane) || (type && plane)); | 130 assert((!type && !plane) || (type && plane)); |
141 | 131 |
142 pt = get_entropy_context(xd, tx_size, type, block, A, L, | 132 pt = get_entropy_context(tx_size, pd->above_context + aoff, |
143 &scan, &band_translate); | 133 pd->left_context + loff); |
144 nb = vp9_get_coef_neighbors_handle(scan); | 134 get_scan(xd, tx_size, type, block, &scan, &nb); |
145 c = 0; | 135 c = 0; |
146 do { | 136 do { |
147 const int band = get_coef_band(band_translate, c); | 137 const int band = get_coef_band(band_translate, c); |
148 int token; | 138 int token; |
149 int v = 0; | 139 int v = 0; |
150 rc = scan[c]; | 140 rc = scan[c]; |
151 if (c) | 141 if (c) |
152 pt = get_coef_context(nb, token_cache, c); | 142 pt = get_coef_context(nb, token_cache, c); |
153 if (c < eob) { | 143 if (c < eob) { |
154 v = qcoeff_ptr[rc]; | 144 v = qcoeff_ptr[rc]; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 int result = 1; | 193 int result = 1; |
204 struct is_skippable_args args = {xd, &result}; | 194 struct is_skippable_args args = {xd, &result}; |
205 foreach_transformed_block_in_plane(xd, bsize, plane, is_skippable, &args); | 195 foreach_transformed_block_in_plane(xd, bsize, plane, is_skippable, &args); |
206 return result; | 196 return result; |
207 } | 197 } |
208 | 198 |
209 void vp9_tokenize_sb(VP9_COMP *cpi, TOKENEXTRA **t, int dry_run, | 199 void vp9_tokenize_sb(VP9_COMP *cpi, TOKENEXTRA **t, int dry_run, |
210 BLOCK_SIZE bsize) { | 200 BLOCK_SIZE bsize) { |
211 VP9_COMMON *const cm = &cpi->common; | 201 VP9_COMMON *const cm = &cpi->common; |
212 MACROBLOCKD *const xd = &cpi->mb.e_mbd; | 202 MACROBLOCKD *const xd = &cpi->mb.e_mbd; |
213 MB_MODE_INFO *const mbmi = &xd->this_mi->mbmi; | 203 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; |
214 TOKENEXTRA *t_backup = *t; | 204 TOKENEXTRA *t_backup = *t; |
215 const int mb_skip_context = vp9_get_pred_context_mbskip(xd); | 205 const int mb_skip_context = vp9_get_pred_context_mbskip(xd); |
216 const int skip_inc = !vp9_segfeature_active(&cm->seg, mbmi->segment_id, | 206 const int skip_inc = !vp9_segfeature_active(&cm->seg, mbmi->segment_id, |
217 SEG_LVL_SKIP); | 207 SEG_LVL_SKIP); |
218 struct tokenize_b_args arg = {cpi, xd, t, mbmi->tx_size}; | 208 struct tokenize_b_args arg = {cpi, xd, t, mbmi->tx_size}; |
219 | 209 |
220 mbmi->skip_coeff = vp9_sb_is_skippable(xd, bsize); | 210 mbmi->skip_coeff = vp9_sb_is_skippable(xd, bsize); |
221 if (mbmi->skip_coeff) { | 211 if (mbmi->skip_coeff) { |
222 if (!dry_run) | 212 if (!dry_run) |
223 cm->counts.mbskip[mb_skip_context][1] += skip_inc; | 213 cm->counts.mbskip[mb_skip_context][1] += skip_inc; |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 | 365 |
376 f = fopen("context.bin", "wb"); | 366 f = fopen("context.bin", "wb"); |
377 fwrite(context_counters, sizeof(context_counters), 1, f); | 367 fwrite(context_counters, sizeof(context_counters), 1, f); |
378 fclose(f); | 368 fclose(f); |
379 } | 369 } |
380 #endif | 370 #endif |
381 | 371 |
382 void vp9_tokenize_initialize() { | 372 void vp9_tokenize_initialize() { |
383 fill_value_tokens(); | 373 fill_value_tokens(); |
384 } | 374 } |
OLD | NEW |