/src/libvpx/vp9/common/vp9_entropymv.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
3 | | * |
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 |
6 | | * tree. An additional intellectual property rights grant can be found |
7 | | * in the file PATENTS. All contributing project authors may |
8 | | * be found in the AUTHORS file in the root of the source tree. |
9 | | */ |
10 | | |
11 | | #include "vp9/common/vp9_onyxc_int.h" |
12 | | #include "vp9/common/vp9_entropymv.h" |
13 | | |
14 | | const vpx_tree_index vp9_mv_joint_tree[TREE_SIZE(MV_JOINTS)] = { |
15 | | -MV_JOINT_ZERO, 2, -MV_JOINT_HNZVZ, 4, -MV_JOINT_HZVNZ, -MV_JOINT_HNZVNZ |
16 | | }; |
17 | | |
18 | | const vpx_tree_index vp9_mv_class_tree[TREE_SIZE(MV_CLASSES)] = { |
19 | | -MV_CLASS_0, 2, -MV_CLASS_1, 4, 6, |
20 | | 8, -MV_CLASS_2, -MV_CLASS_3, 10, 12, |
21 | | -MV_CLASS_4, -MV_CLASS_5, -MV_CLASS_6, 14, 16, |
22 | | 18, -MV_CLASS_7, -MV_CLASS_8, -MV_CLASS_9, -MV_CLASS_10, |
23 | | }; |
24 | | |
25 | | const vpx_tree_index vp9_mv_class0_tree[TREE_SIZE(CLASS0_SIZE)] = { -0, -1 }; |
26 | | |
27 | | const vpx_tree_index vp9_mv_fp_tree[TREE_SIZE(MV_FP_SIZE)] = { -0, 2, -1, |
28 | | 4, -2, -3 }; |
29 | | |
30 | | static const nmv_context default_nmv_context = { |
31 | | { 32, 64, 96 }, |
32 | | { { |
33 | | // Vertical component |
34 | | 128, // sign |
35 | | { 224, 144, 192, 168, 192, 176, 192, 198, 198, 245 }, // class |
36 | | { 216 }, // class0 |
37 | | { 136, 140, 148, 160, 176, 192, 224, 234, 234, 240 }, // bits |
38 | | { { 128, 128, 64 }, { 96, 112, 64 } }, // class0_fp |
39 | | { 64, 96, 64 }, // fp |
40 | | 160, // class0_hp bit |
41 | | 128, // hp |
42 | | }, |
43 | | { |
44 | | // Horizontal component |
45 | | 128, // sign |
46 | | { 216, 128, 176, 160, 176, 176, 192, 198, 198, 208 }, // class |
47 | | { 208 }, // class0 |
48 | | { 136, 140, 148, 160, 176, 192, 224, 234, 234, 240 }, // bits |
49 | | { { 128, 128, 64 }, { 96, 112, 64 } }, // class0_fp |
50 | | { 64, 96, 64 }, // fp |
51 | | 160, // class0_hp bit |
52 | | 128, // hp |
53 | | } }, |
54 | | }; |
55 | | |
56 | | static const uint8_t log_in_base_2[] = { |
57 | | 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, |
58 | | 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
59 | | 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, |
60 | | 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, |
61 | | 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, |
62 | | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, |
63 | | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, |
64 | | 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, |
65 | | 7, 7, 7, 7, 7, 7, 7, 7, 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 9, 9, 9, 9, 9, 9, 9, |
90 | | 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
91 | | 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
92 | | 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
93 | | 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
94 | | 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
95 | | 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
96 | | 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10 |
97 | | }; |
98 | | |
99 | 853k | static INLINE int mv_class_base(MV_CLASS_TYPE c) { |
100 | 853k | return c ? CLASS0_SIZE << (c + 2) : 0; |
101 | 853k | } |
102 | | |
103 | 853k | MV_CLASS_TYPE vp9_get_mv_class(int z, int *offset) { |
104 | 853k | const MV_CLASS_TYPE c = (z >= CLASS0_SIZE * 4096) |
105 | 853k | ? MV_CLASS_10 |
106 | 853k | : (MV_CLASS_TYPE)log_in_base_2[z >> 3]; |
107 | 853k | if (offset) *offset = z - mv_class_base(c); |
108 | 853k | return c; |
109 | 853k | } |
110 | | |
111 | | static void inc_mv_component(int v, nmv_component_counts *comp_counts, int incr, |
112 | 426k | int usehp) { |
113 | 426k | int s, z, c, o, d, e, f; |
114 | 426k | assert(v != 0); /* should not be zero */ |
115 | 426k | s = v < 0; |
116 | 426k | comp_counts->sign[s] += incr; |
117 | 426k | z = (s ? -v : v) - 1; /* magnitude - 1 */ |
118 | | |
119 | 426k | c = vp9_get_mv_class(z, &o); |
120 | 426k | comp_counts->classes[c] += incr; |
121 | | |
122 | 426k | d = (o >> 3); /* int mv data */ |
123 | 426k | f = (o >> 1) & 3; /* fractional pel mv data */ |
124 | 426k | e = (o & 1); /* high precision mv data */ |
125 | | |
126 | 426k | if (c == MV_CLASS_0) { |
127 | 88.2k | comp_counts->class0[d] += incr; |
128 | 88.2k | comp_counts->class0_fp[d][f] += incr; |
129 | 88.2k | comp_counts->class0_hp[e] += usehp * incr; |
130 | 338k | } else { |
131 | 338k | int i; |
132 | 338k | int b = c + CLASS0_BITS - 1; // number of bits |
133 | 1.22M | for (i = 0; i < b; ++i) comp_counts->bits[i][((d >> i) & 1)] += incr; |
134 | 338k | comp_counts->fp[f] += incr; |
135 | 338k | comp_counts->hp[e] += usehp * incr; |
136 | 338k | } |
137 | 426k | } |
138 | | |
139 | 250k | void vp9_inc_mv(const MV *mv, nmv_context_counts *counts) { |
140 | 250k | if (counts != NULL) { |
141 | 250k | const MV_JOINT_TYPE j = vp9_get_mv_joint(mv); |
142 | 250k | ++counts->joints[j]; |
143 | | |
144 | 250k | if (mv_joint_vertical(j)) { |
145 | 212k | inc_mv_component(mv->row, &counts->comps[0], 1, 1); |
146 | 212k | } |
147 | | |
148 | 250k | if (mv_joint_horizontal(j)) { |
149 | 213k | inc_mv_component(mv->col, &counts->comps[1], 1, 1); |
150 | 213k | } |
151 | 250k | } |
152 | 250k | } |
153 | | |
154 | 0 | void vp9_adapt_mv_probs(VP9_COMMON *cm, int allow_hp) { |
155 | 0 | int i, j; |
156 | |
|
157 | 0 | nmv_context *fc = &cm->fc->nmvc; |
158 | 0 | const nmv_context *pre_fc = &cm->frame_contexts[cm->frame_context_idx].nmvc; |
159 | 0 | const nmv_context_counts *counts = &cm->counts.mv; |
160 | |
|
161 | 0 | vpx_tree_merge_probs(vp9_mv_joint_tree, pre_fc->joints, counts->joints, |
162 | 0 | fc->joints); |
163 | |
|
164 | 0 | for (i = 0; i < 2; ++i) { |
165 | 0 | nmv_component *comp = &fc->comps[i]; |
166 | 0 | const nmv_component *pre_comp = &pre_fc->comps[i]; |
167 | 0 | const nmv_component_counts *c = &counts->comps[i]; |
168 | |
|
169 | 0 | comp->sign = mode_mv_merge_probs(pre_comp->sign, c->sign); |
170 | 0 | vpx_tree_merge_probs(vp9_mv_class_tree, pre_comp->classes, c->classes, |
171 | 0 | comp->classes); |
172 | 0 | vpx_tree_merge_probs(vp9_mv_class0_tree, pre_comp->class0, c->class0, |
173 | 0 | comp->class0); |
174 | |
|
175 | 0 | for (j = 0; j < MV_OFFSET_BITS; ++j) |
176 | 0 | comp->bits[j] = mode_mv_merge_probs(pre_comp->bits[j], c->bits[j]); |
177 | |
|
178 | 0 | for (j = 0; j < CLASS0_SIZE; ++j) |
179 | 0 | vpx_tree_merge_probs(vp9_mv_fp_tree, pre_comp->class0_fp[j], |
180 | 0 | c->class0_fp[j], comp->class0_fp[j]); |
181 | |
|
182 | 0 | vpx_tree_merge_probs(vp9_mv_fp_tree, pre_comp->fp, c->fp, comp->fp); |
183 | |
|
184 | 0 | if (allow_hp) { |
185 | 0 | comp->class0_hp = mode_mv_merge_probs(pre_comp->class0_hp, c->class0_hp); |
186 | 0 | comp->hp = mode_mv_merge_probs(pre_comp->hp, c->hp); |
187 | 0 | } |
188 | 0 | } |
189 | 0 | } |
190 | | |
191 | 7.75k | void vp9_init_mv_probs(VP9_COMMON *cm) { cm->fc->nmvc = default_nmv_context; } |