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

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

Issue 592203002: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 2 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_decoder.c ('k') | source/libvpx/vp9/decoder/vp9_dthread.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 #include "vpx_mem/vpx_mem.h" 11 #include "vpx_mem/vpx_mem.h"
12 #include "vpx_ports/mem.h" 12 #include "vpx_ports/mem.h"
13 13
14 #include "vp9/common/vp9_blockd.h" 14 #include "vp9/common/vp9_blockd.h"
15 #include "vp9/common/vp9_common.h" 15 #include "vp9/common/vp9_common.h"
16 #include "vp9/common/vp9_entropy.h"
16 17
17 #include "vp9/decoder/vp9_detokenize.h" 18 #include "vp9/decoder/vp9_detokenize.h"
18 19
19 #define EOB_CONTEXT_NODE 0 20 #define EOB_CONTEXT_NODE 0
20 #define ZERO_CONTEXT_NODE 1 21 #define ZERO_CONTEXT_NODE 1
21 #define ONE_CONTEXT_NODE 2 22 #define ONE_CONTEXT_NODE 2
22 #define LOW_VAL_CONTEXT_NODE 0 23 #define LOW_VAL_CONTEXT_NODE 0
23 #define TWO_CONTEXT_NODE 1 24 #define TWO_CONTEXT_NODE 1
24 #define THREE_CONTEXT_NODE 2 25 #define THREE_CONTEXT_NODE 2
25 #define HIGH_LOW_CONTEXT_NODE 3 26 #define HIGH_LOW_CONTEXT_NODE 3
26 #define CAT_ONE_CONTEXT_NODE 4 27 #define CAT_ONE_CONTEXT_NODE 4
27 #define CAT_THREEFOUR_CONTEXT_NODE 5 28 #define CAT_THREEFOUR_CONTEXT_NODE 5
28 #define CAT_THREE_CONTEXT_NODE 6 29 #define CAT_THREE_CONTEXT_NODE 6
29 #define CAT_FIVE_CONTEXT_NODE 7 30 #define CAT_FIVE_CONTEXT_NODE 7
30 31
31 #define INCREMENT_COUNT(token) \ 32 #define INCREMENT_COUNT(token) \
32 do { \ 33 do { \
33 if (!cm->frame_parallel_decoding_mode) \ 34 if (!cm->frame_parallel_decoding_mode) \
34 ++coef_counts[band][ctx][token]; \ 35 ++coef_counts[band][ctx][token]; \
35 } while (0) 36 } while (0)
36 37
37 #define WRITE_COEF_CONTINUE(val, token) \ 38 static INLINE int read_coeff(const vp9_prob *probs, int n, vp9_reader *r) {
38 { \ 39 int i, val = 0;
39 v = (val * dqv) >> dq_shift; \ 40 for (i = 0; i < n; ++i)
40 dqcoeff[scan[c]] = vp9_read_bit(r) ? -v : v; \ 41 val = (val << 1) | vp9_read(r, probs[i]);
41 token_cache[scan[c]] = vp9_pt_energy_class[token]; \ 42 return val;
42 ++c; \ 43 }
43 ctx = get_coef_context(nb, token_cache, c); \
44 dqv = dq[1]; \
45 continue; \
46 }
47 44
48 #define ADJUST_COEF(prob, bits_count) \ 45 static const vp9_tree_index coeff_subtree_high[TREE_SIZE(ENTROPY_TOKENS)] = {
49 do { \ 46 2, 6, /* 0 = LOW_VAL */
50 val += (vp9_read(r, prob) << bits_count); \ 47 -TWO_TOKEN, 4, /* 1 = TWO */
51 } while (0) 48 -THREE_TOKEN, -FOUR_TOKEN, /* 2 = THREE */
49 8, 10, /* 3 = HIGH_LOW */
50 -CATEGORY1_TOKEN, -CATEGORY2_TOKEN, /* 4 = CAT_ONE */
51 12, 14, /* 5 = CAT_THREEFOUR */
52 -CATEGORY3_TOKEN, -CATEGORY4_TOKEN, /* 6 = CAT_THREE */
53 -CATEGORY5_TOKEN, -CATEGORY6_TOKEN /* 7 = CAT_FIVE */
54 };
52 55
53 static int decode_coefs(VP9_COMMON *cm, const MACROBLOCKD *xd, PLANE_TYPE type, 56 static int decode_coefs(VP9_COMMON *cm, const MACROBLOCKD *xd, PLANE_TYPE type,
54 int16_t *dqcoeff, TX_SIZE tx_size, const int16_t *dq, 57 tran_low_t *dqcoeff, TX_SIZE tx_size, const int16_t *dq,
55 int ctx, const int16_t *scan, const int16_t *nb, 58 int ctx, const int16_t *scan, const int16_t *nb,
56 vp9_reader *r) { 59 vp9_reader *r) {
57 const int max_eob = 16 << (tx_size << 1); 60 const int max_eob = 16 << (tx_size << 1);
58 const FRAME_CONTEXT *const fc = &cm->fc; 61 const FRAME_CONTEXT *const fc = &cm->fc;
59 FRAME_COUNTS *const counts = &cm->counts; 62 FRAME_COUNTS *const counts = &cm->counts;
60 const int ref = is_inter_block(&xd->mi[0]->mbmi); 63 const int ref = is_inter_block(&xd->mi[0].src_mi->mbmi);
61 int band, c = 0; 64 int band, c = 0;
62 const vp9_prob (*coef_probs)[COEFF_CONTEXTS][UNCONSTRAINED_NODES] = 65 const vp9_prob (*coef_probs)[COEFF_CONTEXTS][UNCONSTRAINED_NODES] =
63 fc->coef_probs[tx_size][type][ref]; 66 fc->coef_probs[tx_size][type][ref];
64 const vp9_prob *prob; 67 const vp9_prob *prob;
65 unsigned int (*coef_counts)[COEFF_CONTEXTS][UNCONSTRAINED_NODES + 1] = 68 unsigned int (*coef_counts)[COEFF_CONTEXTS][UNCONSTRAINED_NODES + 1] =
66 counts->coef[tx_size][type][ref]; 69 counts->coef[tx_size][type][ref];
67 unsigned int (*eob_branch_count)[COEFF_CONTEXTS] = 70 unsigned int (*eob_branch_count)[COEFF_CONTEXTS] =
68 counts->eob_branch[tx_size][type][ref]; 71 counts->eob_branch[tx_size][type][ref];
69 uint8_t token_cache[32 * 32]; 72 uint8_t token_cache[32 * 32];
70 const uint8_t *band_translate = get_band_translate(tx_size); 73 const uint8_t *band_translate = get_band_translate(tx_size);
71 const int dq_shift = (tx_size == TX_32X32); 74 const int dq_shift = (tx_size == TX_32X32);
72 int v; 75 int v, token;
73 int16_t dqv = dq[0]; 76 int16_t dqv = dq[0];
77 const uint8_t *cat1_prob;
78 const uint8_t *cat2_prob;
79 const uint8_t *cat3_prob;
80 const uint8_t *cat4_prob;
81 const uint8_t *cat5_prob;
82 const uint8_t *cat6_prob;
83
84 #if CONFIG_VP9_HIGHBITDEPTH
85 if (cm->use_highbitdepth) {
86 if (cm->bit_depth == VPX_BITS_10) {
87 cat1_prob = vp9_cat1_prob_high10;
88 cat2_prob = vp9_cat2_prob_high10;
89 cat3_prob = vp9_cat3_prob_high10;
90 cat4_prob = vp9_cat4_prob_high10;
91 cat5_prob = vp9_cat5_prob_high10;
92 cat6_prob = vp9_cat6_prob_high10;
93 } else {
94 cat1_prob = vp9_cat1_prob_high12;
95 cat2_prob = vp9_cat2_prob_high12;
96 cat3_prob = vp9_cat3_prob_high12;
97 cat4_prob = vp9_cat4_prob_high12;
98 cat5_prob = vp9_cat5_prob_high12;
99 cat6_prob = vp9_cat6_prob_high12;
100 }
101 } else {
102 cat1_prob = vp9_cat1_prob;
103 cat2_prob = vp9_cat2_prob;
104 cat3_prob = vp9_cat3_prob;
105 cat4_prob = vp9_cat4_prob;
106 cat5_prob = vp9_cat5_prob;
107 cat6_prob = vp9_cat6_prob;
108 }
109 #else
110 cat1_prob = vp9_cat1_prob;
111 cat2_prob = vp9_cat2_prob;
112 cat3_prob = vp9_cat3_prob;
113 cat4_prob = vp9_cat4_prob;
114 cat5_prob = vp9_cat5_prob;
115 cat6_prob = vp9_cat6_prob;
116 #endif
74 117
75 while (c < max_eob) { 118 while (c < max_eob) {
76 int val; 119 int val = -1;
77 band = *band_translate++; 120 band = *band_translate++;
78 prob = coef_probs[band][ctx]; 121 prob = coef_probs[band][ctx];
79 if (!cm->frame_parallel_decoding_mode) 122 if (!cm->frame_parallel_decoding_mode)
80 ++eob_branch_count[band][ctx]; 123 ++eob_branch_count[band][ctx];
81 if (!vp9_read(r, prob[EOB_CONTEXT_NODE])) { 124 if (!vp9_read(r, prob[EOB_CONTEXT_NODE])) {
82 INCREMENT_COUNT(EOB_MODEL_TOKEN); 125 INCREMENT_COUNT(EOB_MODEL_TOKEN);
83 break; 126 break;
84 } 127 }
85 128
86 while (!vp9_read(r, prob[ZERO_CONTEXT_NODE])) { 129 while (!vp9_read(r, prob[ZERO_CONTEXT_NODE])) {
87 INCREMENT_COUNT(ZERO_TOKEN); 130 INCREMENT_COUNT(ZERO_TOKEN);
88 dqv = dq[1]; 131 dqv = dq[1];
89 token_cache[scan[c]] = 0; 132 token_cache[scan[c]] = 0;
90 ++c; 133 ++c;
91 if (c >= max_eob) 134 if (c >= max_eob)
92 return c; // zero tokens at the end (no eob token) 135 return c; // zero tokens at the end (no eob token)
93 ctx = get_coef_context(nb, token_cache, c); 136 ctx = get_coef_context(nb, token_cache, c);
94 band = *band_translate++; 137 band = *band_translate++;
95 prob = coef_probs[band][ctx]; 138 prob = coef_probs[band][ctx];
96 } 139 }
97 140
98 // ONE_CONTEXT_NODE_0_
99 if (!vp9_read(r, prob[ONE_CONTEXT_NODE])) { 141 if (!vp9_read(r, prob[ONE_CONTEXT_NODE])) {
100 INCREMENT_COUNT(ONE_TOKEN); 142 INCREMENT_COUNT(ONE_TOKEN);
101 WRITE_COEF_CONTINUE(1, ONE_TOKEN); 143 token = ONE_TOKEN;
144 val = 1;
145 } else {
146 INCREMENT_COUNT(TWO_TOKEN);
147 token = vp9_read_tree(r, coeff_subtree_high,
148 vp9_pareto8_full[prob[PIVOT_NODE] - 1]);
149 switch (token) {
150 case TWO_TOKEN:
151 case THREE_TOKEN:
152 case FOUR_TOKEN:
153 val = token;
154 break;
155 case CATEGORY1_TOKEN:
156 val = CAT1_MIN_VAL + read_coeff(cat1_prob, 1, r);
157 break;
158 case CATEGORY2_TOKEN:
159 val = CAT2_MIN_VAL + read_coeff(cat2_prob, 2, r);
160 break;
161 case CATEGORY3_TOKEN:
162 val = CAT3_MIN_VAL + read_coeff(cat3_prob, 3, r);
163 break;
164 case CATEGORY4_TOKEN:
165 val = CAT4_MIN_VAL + read_coeff(cat4_prob, 4, r);
166 break;
167 case CATEGORY5_TOKEN:
168 val = CAT5_MIN_VAL + read_coeff(cat5_prob, 5, r);
169 break;
170 case CATEGORY6_TOKEN:
171 #if CONFIG_VP9_HIGHBITDEPTH
172 switch (cm->bit_depth) {
173 case VPX_BITS_8:
174 val = CAT6_MIN_VAL + read_coeff(cat6_prob, 14, r);
175 break;
176 case VPX_BITS_10:
177 val = CAT6_MIN_VAL + read_coeff(cat6_prob, 16, r);
178 break;
179 case VPX_BITS_12:
180 val = CAT6_MIN_VAL + read_coeff(cat6_prob, 18, r);
181 break;
182 default:
183 assert(0);
184 return -1;
185 }
186 #else
187 val = CAT6_MIN_VAL + read_coeff(cat6_prob, 14, r);
188 #endif
189 break;
190 }
102 } 191 }
103 192 v = (val * dqv) >> dq_shift;
104 INCREMENT_COUNT(TWO_TOKEN); 193 dqcoeff[scan[c]] = vp9_read_bit(r) ? -v : v;
105 194 token_cache[scan[c]] = vp9_pt_energy_class[token];
106 prob = vp9_pareto8_full[prob[PIVOT_NODE] - 1]; 195 ++c;
107 196 ctx = get_coef_context(nb, token_cache, c);
108 if (!vp9_read(r, prob[LOW_VAL_CONTEXT_NODE])) { 197 dqv = dq[1];
109 if (!vp9_read(r, prob[TWO_CONTEXT_NODE])) {
110 WRITE_COEF_CONTINUE(2, TWO_TOKEN);
111 }
112 if (!vp9_read(r, prob[THREE_CONTEXT_NODE])) {
113 WRITE_COEF_CONTINUE(3, THREE_TOKEN);
114 }
115 WRITE_COEF_CONTINUE(4, FOUR_TOKEN);
116 }
117
118 if (!vp9_read(r, prob[HIGH_LOW_CONTEXT_NODE])) {
119 if (!vp9_read(r, prob[CAT_ONE_CONTEXT_NODE])) {
120 val = CAT1_MIN_VAL;
121 ADJUST_COEF(vp9_cat1_prob[0], 0);
122 WRITE_COEF_CONTINUE(val, CATEGORY1_TOKEN);
123 }
124 val = CAT2_MIN_VAL;
125 ADJUST_COEF(vp9_cat2_prob[0], 1);
126 ADJUST_COEF(vp9_cat2_prob[1], 0);
127 WRITE_COEF_CONTINUE(val, CATEGORY2_TOKEN);
128 }
129
130 if (!vp9_read(r, prob[CAT_THREEFOUR_CONTEXT_NODE])) {
131 if (!vp9_read(r, prob[CAT_THREE_CONTEXT_NODE])) {
132 val = CAT3_MIN_VAL;
133 ADJUST_COEF(vp9_cat3_prob[0], 2);
134 ADJUST_COEF(vp9_cat3_prob[1], 1);
135 ADJUST_COEF(vp9_cat3_prob[2], 0);
136 WRITE_COEF_CONTINUE(val, CATEGORY3_TOKEN);
137 }
138 val = CAT4_MIN_VAL;
139 ADJUST_COEF(vp9_cat4_prob[0], 3);
140 ADJUST_COEF(vp9_cat4_prob[1], 2);
141 ADJUST_COEF(vp9_cat4_prob[2], 1);
142 ADJUST_COEF(vp9_cat4_prob[3], 0);
143 WRITE_COEF_CONTINUE(val, CATEGORY4_TOKEN);
144 }
145
146 if (!vp9_read(r, prob[CAT_FIVE_CONTEXT_NODE])) {
147 val = CAT5_MIN_VAL;
148 ADJUST_COEF(vp9_cat5_prob[0], 4);
149 ADJUST_COEF(vp9_cat5_prob[1], 3);
150 ADJUST_COEF(vp9_cat5_prob[2], 2);
151 ADJUST_COEF(vp9_cat5_prob[3], 1);
152 ADJUST_COEF(vp9_cat5_prob[4], 0);
153 WRITE_COEF_CONTINUE(val, CATEGORY5_TOKEN);
154 }
155 val = 0;
156 val = (val << 1) | vp9_read(r, vp9_cat6_prob[0]);
157 val = (val << 1) | vp9_read(r, vp9_cat6_prob[1]);
158 val = (val << 1) | vp9_read(r, vp9_cat6_prob[2]);
159 val = (val << 1) | vp9_read(r, vp9_cat6_prob[3]);
160 val = (val << 1) | vp9_read(r, vp9_cat6_prob[4]);
161 val = (val << 1) | vp9_read(r, vp9_cat6_prob[5]);
162 val = (val << 1) | vp9_read(r, vp9_cat6_prob[6]);
163 val = (val << 1) | vp9_read(r, vp9_cat6_prob[7]);
164 val = (val << 1) | vp9_read(r, vp9_cat6_prob[8]);
165 val = (val << 1) | vp9_read(r, vp9_cat6_prob[9]);
166 val = (val << 1) | vp9_read(r, vp9_cat6_prob[10]);
167 val = (val << 1) | vp9_read(r, vp9_cat6_prob[11]);
168 val = (val << 1) | vp9_read(r, vp9_cat6_prob[12]);
169 val = (val << 1) | vp9_read(r, vp9_cat6_prob[13]);
170 val += CAT6_MIN_VAL;
171
172 WRITE_COEF_CONTINUE(val, CATEGORY6_TOKEN);
173 } 198 }
174 199
175 return c; 200 return c;
176 } 201 }
177 202
178 int vp9_decode_block_tokens(VP9_COMMON *cm, MACROBLOCKD *xd, 203 int vp9_decode_block_tokens(VP9_COMMON *cm, MACROBLOCKD *xd,
179 int plane, int block, BLOCK_SIZE plane_bsize, 204 int plane, int block, BLOCK_SIZE plane_bsize,
180 int x, int y, TX_SIZE tx_size, vp9_reader *r) { 205 int x, int y, TX_SIZE tx_size, vp9_reader *r) {
181 struct macroblockd_plane *const pd = &xd->plane[plane]; 206 struct macroblockd_plane *const pd = &xd->plane[plane];
182 const int ctx = get_entropy_context(tx_size, pd->above_context + x, 207 const int ctx = get_entropy_context(tx_size, pd->above_context + x,
183 pd->left_context + y); 208 pd->left_context + y);
184 const scan_order *so = get_scan(xd, tx_size, pd->plane_type, block); 209 const scan_order *so = get_scan(xd, tx_size, pd->plane_type, block);
185 const int eob = decode_coefs(cm, xd, pd->plane_type, 210 const int eob = decode_coefs(cm, xd, pd->plane_type,
186 BLOCK_OFFSET(pd->dqcoeff, block), tx_size, 211 BLOCK_OFFSET(pd->dqcoeff, block), tx_size,
187 pd->dequant, ctx, so->scan, so->neighbors, r); 212 pd->dequant, ctx, so->scan, so->neighbors, r);
188 vp9_set_contexts(xd, pd, plane_bsize, tx_size, eob > 0, x, y); 213 vp9_set_contexts(xd, pd, plane_bsize, tx_size, eob > 0, x, y);
189 return eob; 214 return eob;
190 } 215 }
191 216
192 217
OLDNEW
« no previous file with comments | « source/libvpx/vp9/decoder/vp9_decoder.c ('k') | source/libvpx/vp9/decoder/vp9_dthread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698