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

Side by Side Diff: source/libvpx/vp9/common/vp9_entropymv.c

Issue 111463005: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 7 years 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/common/vp9_entropymv.h ('k') | source/libvpx/vp9/common/vp9_enums.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 "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[TREE_SIZE(MV_JOINTS)] = { 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];
27 26
28 const vp9_tree_index vp9_mv_class_tree[TREE_SIZE(MV_CLASSES)] = { 27 const vp9_tree_index vp9_mv_class_tree[TREE_SIZE(MV_CLASSES)] = {
29 -MV_CLASS_0, 2, 28 -MV_CLASS_0, 2,
30 -MV_CLASS_1, 4, 29 -MV_CLASS_1, 4,
31 6, 8, 30 6, 8,
32 -MV_CLASS_2, -MV_CLASS_3, 31 -MV_CLASS_2, -MV_CLASS_3,
33 10, 12, 32 10, 12,
34 -MV_CLASS_4, -MV_CLASS_5, 33 -MV_CLASS_4, -MV_CLASS_5,
35 -MV_CLASS_6, 14, 34 -MV_CLASS_6, 14,
36 16, 18, 35 16, 18,
37 -MV_CLASS_7, -MV_CLASS_8, 36 -MV_CLASS_7, -MV_CLASS_8,
38 -MV_CLASS_9, -MV_CLASS_10, 37 -MV_CLASS_9, -MV_CLASS_10,
39 }; 38 };
40 struct vp9_token vp9_mv_class_encodings[MV_CLASSES];
41 39
42 const vp9_tree_index vp9_mv_class0_tree[TREE_SIZE(CLASS0_SIZE)] = { 40 const vp9_tree_index vp9_mv_class0_tree[TREE_SIZE(CLASS0_SIZE)] = {
43 -0, -1, 41 -0, -1,
44 }; 42 };
45 struct vp9_token vp9_mv_class0_encodings[CLASS0_SIZE];
46 43
47 const vp9_tree_index vp9_mv_fp_tree[TREE_SIZE(4)] = { 44 const vp9_tree_index vp9_mv_fp_tree[TREE_SIZE(MV_FP_SIZE)] = {
48 -0, 2, 45 -0, 2,
49 -1, 4, 46 -1, 4,
50 -2, -3 47 -2, -3
51 }; 48 };
52 struct vp9_token vp9_mv_fp_encodings[4];
53 49
54 static const nmv_context default_nmv_context = { 50 static const nmv_context default_nmv_context = {
55 {32, 64, 96}, 51 {32, 64, 96},
56 { // NOLINT 52 { // NOLINT
57 { /* vert component */ // NOLINT 53 { /* vert component */ // NOLINT
58 128, /* sign */ 54 128, /* sign */
59 {224, 144, 192, 168, 192, 176, 192, 198, 198, 245}, /* class */ 55 {224, 144, 192, 168, 192, 176, 192, 198, 198, 245}, /* class */
60 {216}, /* class0 */ 56 {216}, /* class0 */
61 {136, 140, 148, 160, 176, 192, 224, 234, 234, 240}, /* bits */ 57 {136, 140, 148, 160, 176, 192, 224, 234, 234, 240}, /* bits */
62 {{128, 128, 64}, {96, 112, 64}}, /* class0_fp */ 58 {{128, 128, 64}, {96, 112, 64}}, /* class0_fp */
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 inc_mv_component(mv->row, &counts->comps[0], 1, 1); 180 inc_mv_component(mv->row, &counts->comps[0], 1, 1);
185 } 181 }
186 182
187 if (mv_joint_horizontal(j)) { 183 if (mv_joint_horizontal(j)) {
188 inc_mv_component(mv->col, &counts->comps[1], 1, 1); 184 inc_mv_component(mv->col, &counts->comps[1], 1, 1);
189 } 185 }
190 } 186 }
191 } 187 }
192 188
193 static vp9_prob adapt_prob(vp9_prob prep, const unsigned int ct[2]) { 189 static vp9_prob adapt_prob(vp9_prob prep, const unsigned int ct[2]) {
194 return merge_probs2(prep, ct, MV_COUNT_SAT, MV_MAX_UPDATE_FACTOR); 190 return merge_probs(prep, ct, MV_COUNT_SAT, MV_MAX_UPDATE_FACTOR);
195 } 191 }
196 192
197 static unsigned int adapt_probs(unsigned int i, 193 static void adapt_probs(const vp9_tree_index *tree, const vp9_prob *pre_probs,
198 vp9_tree tree, 194 const unsigned int *counts, vp9_prob *probs) {
199 vp9_prob this_probs[], 195 tree_merge_probs(tree, pre_probs, counts, MV_COUNT_SAT, MV_MAX_UPDATE_FACTOR,
200 const vp9_prob last_probs[], 196 probs);
201 const unsigned int num_events[]) {
202 const unsigned int left = tree[i] <= 0
203 ? num_events[-tree[i]]
204 : adapt_probs(tree[i], tree, this_probs, last_probs, num_events);
205
206 const unsigned int right = tree[i + 1] <= 0
207 ? num_events[-tree[i + 1]]
208 : adapt_probs(tree[i + 1], tree, this_probs, last_probs, num_events);
209 const unsigned int ct[2] = { left, right };
210 this_probs[i >> 1] = adapt_prob(last_probs[i >> 1], ct);
211 return left + right;
212 } 197 }
213 198
214
215 void vp9_adapt_mv_probs(VP9_COMMON *cm, int allow_hp) { 199 void vp9_adapt_mv_probs(VP9_COMMON *cm, int allow_hp) {
216 int i, j; 200 int i, j;
217 201
218 const FRAME_CONTEXT *pre_fc = &cm->frame_contexts[cm->frame_context_idx]; 202 nmv_context *fc = &cm->fc.nmvc;
203 const nmv_context *pre_fc = &cm->frame_contexts[cm->frame_context_idx].nmvc;
204 const nmv_context_counts *counts = &cm->counts.mv;
219 205
220 nmv_context *ctx = &cm->fc.nmvc; 206 adapt_probs(vp9_mv_joint_tree, pre_fc->joints, counts->joints, fc->joints);
221 const nmv_context *pre_ctx = &pre_fc->nmvc;
222 const nmv_context_counts *cts = &cm->counts.mv;
223
224 adapt_probs(0, vp9_mv_joint_tree, ctx->joints, pre_ctx->joints, cts->joints);
225 207
226 for (i = 0; i < 2; ++i) { 208 for (i = 0; i < 2; ++i) {
227 ctx->comps[i].sign = adapt_prob(pre_ctx->comps[i].sign, cts->comps[i].sign); 209 nmv_component *comp = &fc->comps[i];
228 adapt_probs(0, vp9_mv_class_tree, ctx->comps[i].classes, 210 const nmv_component *pre_comp = &pre_fc->comps[i];
229 pre_ctx->comps[i].classes, cts->comps[i].classes); 211 const nmv_component_counts *c = &counts->comps[i];
230 adapt_probs(0, vp9_mv_class0_tree, ctx->comps[i].class0, 212
231 pre_ctx->comps[i].class0, cts->comps[i].class0); 213 comp->sign = adapt_prob(pre_comp->sign, c->sign);
214 adapt_probs(vp9_mv_class_tree, pre_comp->classes, c->classes,
215 comp->classes);
216 adapt_probs(vp9_mv_class0_tree, pre_comp->class0, c->class0, comp->class0);
232 217
233 for (j = 0; j < MV_OFFSET_BITS; ++j) 218 for (j = 0; j < MV_OFFSET_BITS; ++j)
234 ctx->comps[i].bits[j] = adapt_prob(pre_ctx->comps[i].bits[j], 219 comp->bits[j] = adapt_prob(pre_comp->bits[j], c->bits[j]);
235 cts->comps[i].bits[j]);
236 220
237 for (j = 0; j < CLASS0_SIZE; ++j) 221 for (j = 0; j < CLASS0_SIZE; ++j)
238 adapt_probs(0, vp9_mv_fp_tree, ctx->comps[i].class0_fp[j], 222 adapt_probs(vp9_mv_fp_tree, pre_comp->class0_fp[j], c->class0_fp[j],
239 pre_ctx->comps[i].class0_fp[j], cts->comps[i].class0_fp[j]); 223 comp->class0_fp[j]);
240 224
241 adapt_probs(0, vp9_mv_fp_tree, ctx->comps[i].fp, pre_ctx->comps[i].fp, 225 adapt_probs(vp9_mv_fp_tree, pre_comp->fp, c->fp, comp->fp);
242 cts->comps[i].fp);
243 226
244 if (allow_hp) { 227 if (allow_hp) {
245 ctx->comps[i].class0_hp = adapt_prob(pre_ctx->comps[i].class0_hp, 228 comp->class0_hp = adapt_prob(pre_comp->class0_hp, c->class0_hp);
246 cts->comps[i].class0_hp); 229 comp->hp = adapt_prob(pre_comp->hp, c->hp);
247 ctx->comps[i].hp = adapt_prob(pre_ctx->comps[i].hp, cts->comps[i].hp);
248 } 230 }
249 } 231 }
250 } 232 }
251 233
252 void vp9_entropy_mv_init() {
253 vp9_tokens_from_tree(vp9_mv_joint_encodings, vp9_mv_joint_tree);
254 vp9_tokens_from_tree(vp9_mv_class_encodings, vp9_mv_class_tree);
255 vp9_tokens_from_tree(vp9_mv_class0_encodings, vp9_mv_class0_tree);
256 vp9_tokens_from_tree(vp9_mv_fp_encodings, vp9_mv_fp_tree);
257 }
258
259 void vp9_init_mv_probs(VP9_COMMON *cm) { 234 void vp9_init_mv_probs(VP9_COMMON *cm) {
260 cm->fc.nmvc = default_nmv_context; 235 cm->fc.nmvc = default_nmv_context;
261 } 236 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/common/vp9_entropymv.h ('k') | source/libvpx/vp9/common/vp9_enums.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698