OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 | 11 |
12 #include "vp9/common/vp9_onyxc_int.h" | 12 #include "vp9/common/vp9_onyxc_int.h" |
13 #include "vp9/common/vp9_entropymv.h" | 13 #include "vp9/common/vp9_entropymv.h" |
14 | 14 |
15 #define MV_COUNT_SAT 20 | 15 #define MV_COUNT_SAT 20 |
16 #define MV_MAX_UPDATE_FACTOR 128 | 16 #define MV_MAX_UPDATE_FACTOR 128 |
17 | 17 |
18 /* Integer pel reference mv threshold for use of high-precision 1/8 mv */ | 18 /* Integer pel reference mv threshold for use of high-precision 1/8 mv */ |
19 #define COMPANDED_MVREF_THRESH 8 | 19 #define COMPANDED_MVREF_THRESH 8 |
20 | 20 |
21 const vp9_tree_index vp9_mv_joint_tree[2 * MV_JOINTS - 2] = { | 21 const vp9_tree_index vp9_mv_joint_tree[TREE_SIZE(MV_JOINTS)] = { |
22 -MV_JOINT_ZERO, 2, | 22 -MV_JOINT_ZERO, 2, |
23 -MV_JOINT_HNZVZ, 4, | 23 -MV_JOINT_HNZVZ, 4, |
24 -MV_JOINT_HZVNZ, -MV_JOINT_HNZVNZ | 24 -MV_JOINT_HZVNZ, -MV_JOINT_HNZVNZ |
25 }; | 25 }; |
26 struct vp9_token vp9_mv_joint_encodings[MV_JOINTS]; | 26 struct vp9_token vp9_mv_joint_encodings[MV_JOINTS]; |
27 | 27 |
28 const vp9_tree_index vp9_mv_class_tree[2 * MV_CLASSES - 2] = { | 28 const vp9_tree_index vp9_mv_class_tree[TREE_SIZE(MV_CLASSES)] = { |
29 -MV_CLASS_0, 2, | 29 -MV_CLASS_0, 2, |
30 -MV_CLASS_1, 4, | 30 -MV_CLASS_1, 4, |
31 6, 8, | 31 6, 8, |
32 -MV_CLASS_2, -MV_CLASS_3, | 32 -MV_CLASS_2, -MV_CLASS_3, |
33 10, 12, | 33 10, 12, |
34 -MV_CLASS_4, -MV_CLASS_5, | 34 -MV_CLASS_4, -MV_CLASS_5, |
35 -MV_CLASS_6, 14, | 35 -MV_CLASS_6, 14, |
36 16, 18, | 36 16, 18, |
37 -MV_CLASS_7, -MV_CLASS_8, | 37 -MV_CLASS_7, -MV_CLASS_8, |
38 -MV_CLASS_9, -MV_CLASS_10, | 38 -MV_CLASS_9, -MV_CLASS_10, |
39 }; | 39 }; |
40 struct vp9_token vp9_mv_class_encodings[MV_CLASSES]; | 40 struct vp9_token vp9_mv_class_encodings[MV_CLASSES]; |
41 | 41 |
42 const vp9_tree_index vp9_mv_class0_tree [2 * CLASS0_SIZE - 2] = { | 42 const vp9_tree_index vp9_mv_class0_tree[TREE_SIZE(CLASS0_SIZE)] = { |
43 -0, -1, | 43 -0, -1, |
44 }; | 44 }; |
45 struct vp9_token vp9_mv_class0_encodings[CLASS0_SIZE]; | 45 struct vp9_token vp9_mv_class0_encodings[CLASS0_SIZE]; |
46 | 46 |
47 const vp9_tree_index vp9_mv_fp_tree [2 * 4 - 2] = { | 47 const vp9_tree_index vp9_mv_fp_tree[TREE_SIZE(4)] = { |
48 -0, 2, | 48 -0, 2, |
49 -1, 4, | 49 -1, 4, |
50 -2, -3 | 50 -2, -3 |
51 }; | 51 }; |
52 struct vp9_token vp9_mv_fp_encodings[4]; | 52 struct vp9_token vp9_mv_fp_encodings[4]; |
53 | 53 |
54 static const nmv_context default_nmv_context = { | 54 static const nmv_context default_nmv_context = { |
55 {32, 64, 96}, | 55 {32, 64, 96}, |
56 { | 56 { // NOLINT |
57 { /* vert component */ | 57 { /* vert component */ // NOLINT |
58 128, /* sign */ | 58 128, /* sign */ |
59 {224, 144, 192, 168, 192, 176, 192, 198, 198, 245}, /* class */ | 59 {224, 144, 192, 168, 192, 176, 192, 198, 198, 245}, /* class */ |
60 {216}, /* class0 */ | 60 {216}, /* class0 */ |
61 {136, 140, 148, 160, 176, 192, 224, 234, 234, 240}, /* bits */ | 61 {136, 140, 148, 160, 176, 192, 224, 234, 234, 240}, /* bits */ |
62 {{128, 128, 64}, {96, 112, 64}}, /* class0_fp */ | 62 {{128, 128, 64}, {96, 112, 64}}, /* class0_fp */ |
63 {64, 96, 64}, /* fp */ | 63 {64, 96, 64}, /* fp */ |
64 160, /* class0_hp bit */ | 64 160, /* class0_hp bit */ |
65 128, /* hp */ | 65 128, /* hp */ |
66 }, | 66 }, |
67 { /* hor component */ | 67 { /* hor component */ // NOLINT |
68 128, /* sign */ | 68 128, /* sign */ |
69 {216, 128, 176, 160, 176, 176, 192, 198, 198, 208}, /* class */ | 69 {216, 128, 176, 160, 176, 176, 192, 198, 198, 208}, /* class */ |
70 {208}, /* class0 */ | 70 {208}, /* class0 */ |
71 {136, 140, 148, 160, 176, 192, 224, 234, 234, 240}, /* bits */ | 71 {136, 140, 148, 160, 176, 192, 224, 234, 234, 240}, /* bits */ |
72 {{128, 128, 64}, {96, 112, 64}}, /* class0_fp */ | 72 {{128, 128, 64}, {96, 112, 64}}, /* class0_fp */ |
73 {64, 96, 64}, /* fp */ | 73 {64, 96, 64}, /* fp */ |
74 160, /* class0_hp bit */ | 74 160, /* class0_hp bit */ |
75 128, /* hp */ | 75 128, /* hp */ |
76 } | 76 } |
77 }, | 77 }, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 (abs(ref->col) >> 3) < COMPANDED_MVREF_THRESH; | 142 (abs(ref->col) >> 3) < COMPANDED_MVREF_THRESH; |
143 } | 143 } |
144 | 144 |
145 int vp9_get_mv_mag(MV_CLASS_TYPE c, int offset) { | 145 int vp9_get_mv_mag(MV_CLASS_TYPE c, int offset) { |
146 return mv_class_base(c) + offset; | 146 return mv_class_base(c) + offset; |
147 } | 147 } |
148 | 148 |
149 static void inc_mv_component(int v, nmv_component_counts *comp_counts, | 149 static void inc_mv_component(int v, nmv_component_counts *comp_counts, |
150 int incr, int usehp) { | 150 int incr, int usehp) { |
151 int s, z, c, o, d, e, f; | 151 int s, z, c, o, d, e, f; |
152 assert (v != 0); /* should not be zero */ | 152 assert(v != 0); /* should not be zero */ |
153 s = v < 0; | 153 s = v < 0; |
154 comp_counts->sign[s] += incr; | 154 comp_counts->sign[s] += incr; |
155 z = (s ? -v : v) - 1; /* magnitude - 1 */ | 155 z = (s ? -v : v) - 1; /* magnitude - 1 */ |
156 | 156 |
157 c = vp9_get_mv_class(z, &o); | 157 c = vp9_get_mv_class(z, &o); |
158 comp_counts->classes[c] += incr; | 158 comp_counts->classes[c] += incr; |
159 | 159 |
160 d = (o >> 3); /* int mv data */ | 160 d = (o >> 3); /* int mv data */ |
161 f = (o >> 1) & 3; /* fractional pel mv data */ | 161 f = (o >> 1) & 3; /* fractional pel mv data */ |
162 e = (o & 1); /* high precision mv data */ | 162 e = (o & 1); /* high precision mv data */ |
163 | 163 |
164 if (c == MV_CLASS_0) { | 164 if (c == MV_CLASS_0) { |
165 comp_counts->class0[d] += incr; | 165 comp_counts->class0[d] += incr; |
166 comp_counts->class0_fp[d][f] += incr; | 166 comp_counts->class0_fp[d][f] += incr; |
167 comp_counts->class0_hp[e] += usehp * incr; | 167 comp_counts->class0_hp[e] += usehp * incr; |
168 } else { | 168 } else { |
169 int i; | 169 int i; |
170 int b = c + CLASS0_BITS - 1; // number of bits | 170 int b = c + CLASS0_BITS - 1; // number of bits |
171 for (i = 0; i < b; ++i) | 171 for (i = 0; i < b; ++i) |
172 comp_counts->bits[i][((d >> i) & 1)] += incr; | 172 comp_counts->bits[i][((d >> i) & 1)] += incr; |
173 comp_counts->fp[f] += incr; | 173 comp_counts->fp[f] += incr; |
174 comp_counts->hp[e] += usehp * incr; | 174 comp_counts->hp[e] += usehp * incr; |
175 } | 175 } |
176 } | 176 } |
177 | 177 |
| 178 void vp9_inc_mv(const MV *mv, nmv_context_counts *counts) { |
| 179 if (counts != NULL) { |
| 180 const MV_JOINT_TYPE j = vp9_get_mv_joint(mv); |
| 181 ++counts->joints[j]; |
178 | 182 |
179 void vp9_inc_mv(const MV *mv, nmv_context_counts *counts) { | 183 if (mv_joint_vertical(j)) { |
180 const MV_JOINT_TYPE j = vp9_get_mv_joint(mv); | 184 inc_mv_component(mv->row, &counts->comps[0], 1, 1); |
181 ++counts->joints[j]; | 185 } |
182 | 186 |
183 if (mv_joint_vertical(j)) { | 187 if (mv_joint_horizontal(j)) { |
184 inc_mv_component(mv->row, &counts->comps[0], 1, 1); | 188 inc_mv_component(mv->col, &counts->comps[1], 1, 1); |
185 } | 189 } |
186 | |
187 if (mv_joint_horizontal(j)) { | |
188 inc_mv_component(mv->col, &counts->comps[1], 1, 1); | |
189 } | 190 } |
190 } | 191 } |
191 | 192 |
192 static vp9_prob adapt_prob(vp9_prob prep, const unsigned int ct[2]) { | 193 static vp9_prob adapt_prob(vp9_prob prep, const unsigned int ct[2]) { |
193 return merge_probs2(prep, ct, MV_COUNT_SAT, MV_MAX_UPDATE_FACTOR); | 194 return merge_probs2(prep, ct, MV_COUNT_SAT, MV_MAX_UPDATE_FACTOR); |
194 } | 195 } |
195 | 196 |
196 static unsigned int adapt_probs(unsigned int i, | 197 static unsigned int adapt_probs(unsigned int i, |
197 vp9_tree tree, | 198 vp9_tree tree, |
198 vp9_prob this_probs[], | 199 vp9_prob this_probs[], |
199 const vp9_prob last_probs[], | 200 const vp9_prob last_probs[], |
200 const unsigned int num_events[]) { | 201 const unsigned int num_events[]) { |
201 | |
202 | |
203 const unsigned int left = tree[i] <= 0 | 202 const unsigned int left = tree[i] <= 0 |
204 ? num_events[-tree[i]] | 203 ? num_events[-tree[i]] |
205 : adapt_probs(tree[i], tree, this_probs, last_probs, num_events); | 204 : adapt_probs(tree[i], tree, this_probs, last_probs, num_events); |
206 | 205 |
207 const unsigned int right = tree[i + 1] <= 0 | 206 const unsigned int right = tree[i + 1] <= 0 |
208 ? num_events[-tree[i + 1]] | 207 ? num_events[-tree[i + 1]] |
209 : adapt_probs(tree[i + 1], tree, this_probs, last_probs, num_events); | 208 : adapt_probs(tree[i + 1], tree, this_probs, last_probs, num_events); |
210 const unsigned int ct[2] = { left, right }; | 209 const unsigned int ct[2] = { left, right }; |
211 this_probs[i >> 1] = adapt_prob(last_probs[i >> 1], ct); | 210 this_probs[i >> 1] = adapt_prob(last_probs[i >> 1], ct); |
212 return left + right; | 211 return left + right; |
213 } | 212 } |
214 | 213 |
215 | 214 |
216 void vp9_adapt_mv_probs(VP9_COMMON *cm, int allow_hp) { | 215 void vp9_adapt_mv_probs(VP9_COMMON *cm, int allow_hp) { |
217 int i, j; | 216 int i, j; |
218 | 217 |
219 FRAME_CONTEXT *pre_fc = &cm->frame_contexts[cm->frame_context_idx]; | 218 const FRAME_CONTEXT *pre_fc = &cm->frame_contexts[cm->frame_context_idx]; |
220 | 219 |
221 nmv_context *ctx = &cm->fc.nmvc; | 220 nmv_context *ctx = &cm->fc.nmvc; |
222 nmv_context *pre_ctx = &pre_fc->nmvc; | 221 const nmv_context *pre_ctx = &pre_fc->nmvc; |
223 nmv_context_counts *cts = &cm->counts.mv; | 222 const nmv_context_counts *cts = &cm->counts.mv; |
224 | 223 |
225 adapt_probs(0, vp9_mv_joint_tree, ctx->joints, pre_ctx->joints, cts->joints); | 224 adapt_probs(0, vp9_mv_joint_tree, ctx->joints, pre_ctx->joints, cts->joints); |
226 | 225 |
227 for (i = 0; i < 2; ++i) { | 226 for (i = 0; i < 2; ++i) { |
228 ctx->comps[i].sign = adapt_prob(pre_ctx->comps[i].sign, cts->comps[i].sign); | 227 ctx->comps[i].sign = adapt_prob(pre_ctx->comps[i].sign, cts->comps[i].sign); |
229 adapt_probs(0, vp9_mv_class_tree, ctx->comps[i].classes, | 228 adapt_probs(0, vp9_mv_class_tree, ctx->comps[i].classes, |
230 pre_ctx->comps[i].classes, cts->comps[i].classes); | 229 pre_ctx->comps[i].classes, cts->comps[i].classes); |
231 adapt_probs(0, vp9_mv_class0_tree, ctx->comps[i].class0, | 230 adapt_probs(0, vp9_mv_class0_tree, ctx->comps[i].class0, |
232 pre_ctx->comps[i].class0, cts->comps[i].class0); | 231 pre_ctx->comps[i].class0, cts->comps[i].class0); |
233 | 232 |
(...skipping 19 matching lines...) Expand all Loading... |
253 void vp9_entropy_mv_init() { | 252 void vp9_entropy_mv_init() { |
254 vp9_tokens_from_tree(vp9_mv_joint_encodings, vp9_mv_joint_tree); | 253 vp9_tokens_from_tree(vp9_mv_joint_encodings, vp9_mv_joint_tree); |
255 vp9_tokens_from_tree(vp9_mv_class_encodings, vp9_mv_class_tree); | 254 vp9_tokens_from_tree(vp9_mv_class_encodings, vp9_mv_class_tree); |
256 vp9_tokens_from_tree(vp9_mv_class0_encodings, vp9_mv_class0_tree); | 255 vp9_tokens_from_tree(vp9_mv_class0_encodings, vp9_mv_class0_tree); |
257 vp9_tokens_from_tree(vp9_mv_fp_encodings, vp9_mv_fp_tree); | 256 vp9_tokens_from_tree(vp9_mv_fp_encodings, vp9_mv_fp_tree); |
258 } | 257 } |
259 | 258 |
260 void vp9_init_mv_probs(VP9_COMMON *cm) { | 259 void vp9_init_mv_probs(VP9_COMMON *cm) { |
261 cm->fc.nmvc = default_nmv_context; | 260 cm->fc.nmvc = default_nmv_context; |
262 } | 261 } |
OLD | NEW |