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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 else if (z < CLASS0_SIZE * 1024) c = MV_CLASS_7; | 107 else if (z < CLASS0_SIZE * 1024) c = MV_CLASS_7; |
108 else if (z < CLASS0_SIZE * 2048) c = MV_CLASS_8; | 108 else if (z < CLASS0_SIZE * 2048) c = MV_CLASS_8; |
109 else if (z < CLASS0_SIZE * 4096) c = MV_CLASS_9; | 109 else if (z < CLASS0_SIZE * 4096) c = MV_CLASS_9; |
110 else if (z < CLASS0_SIZE * 8192) c = MV_CLASS_10; | 110 else if (z < CLASS0_SIZE * 8192) c = MV_CLASS_10; |
111 else assert(0); | 111 else assert(0); |
112 if (offset) | 112 if (offset) |
113 *offset = z - mv_class_base(c); | 113 *offset = z - mv_class_base(c); |
114 return c; | 114 return c; |
115 } | 115 } |
116 | 116 |
117 int vp9_use_nmv_hp(const MV *ref) { | 117 int vp9_use_mv_hp(const MV *ref) { |
118 return (abs(ref->row) >> 3) < COMPANDED_MVREF_THRESH && | 118 return (abs(ref->row) >> 3) < COMPANDED_MVREF_THRESH && |
119 (abs(ref->col) >> 3) < COMPANDED_MVREF_THRESH; | 119 (abs(ref->col) >> 3) < COMPANDED_MVREF_THRESH; |
120 } | 120 } |
121 | 121 |
122 int vp9_get_mv_mag(MV_CLASS_TYPE c, int offset) { | 122 int vp9_get_mv_mag(MV_CLASS_TYPE c, int offset) { |
123 return mv_class_base(c) + offset; | 123 return mv_class_base(c) + offset; |
124 } | 124 } |
125 | 125 |
126 static void increment_nmv_component_count(int v, | 126 static void inc_mv_component_count(int v, nmv_component_counts *comp_counts, |
127 nmv_component_counts *mvcomp, | 127 int incr) { |
128 int incr, | 128 assert (v != 0); |
129 int usehp) { | 129 comp_counts->mvcount[MV_MAX + v] += incr; |
130 assert (v != 0); /* should not be zero */ | |
131 mvcomp->mvcount[MV_MAX + v] += incr; | |
132 } | 130 } |
133 | 131 |
134 static void increment_nmv_component(int v, | 132 static void inc_mv_component(int v, nmv_component_counts *comp_counts, |
135 nmv_component_counts *mvcomp, | 133 int incr, int usehp) { |
136 int incr, | |
137 int usehp) { | |
138 int s, z, c, o, d, e, f; | 134 int s, z, c, o, d, e, f; |
139 if (!incr) | 135 if (!incr) |
140 return; | 136 return; |
141 assert (v != 0); /* should not be zero */ | 137 assert (v != 0); /* should not be zero */ |
142 s = v < 0; | 138 s = v < 0; |
143 mvcomp->sign[s] += incr; | 139 comp_counts->sign[s] += incr; |
144 z = (s ? -v : v) - 1; /* magnitude - 1 */ | 140 z = (s ? -v : v) - 1; /* magnitude - 1 */ |
145 | 141 |
146 c = vp9_get_mv_class(z, &o); | 142 c = vp9_get_mv_class(z, &o); |
147 mvcomp->classes[c] += incr; | 143 comp_counts->classes[c] += incr; |
148 | 144 |
149 d = (o >> 3); /* int mv data */ | 145 d = (o >> 3); /* int mv data */ |
150 f = (o >> 1) & 3; /* fractional pel mv data */ | 146 f = (o >> 1) & 3; /* fractional pel mv data */ |
151 e = (o & 1); /* high precision mv data */ | 147 e = (o & 1); /* high precision mv data */ |
152 if (c == MV_CLASS_0) { | 148 if (c == MV_CLASS_0) { |
153 mvcomp->class0[d] += incr; | 149 comp_counts->class0[d] += incr; |
154 } else { | 150 } else { |
155 int i; | 151 int i; |
156 int b = c + CLASS0_BITS - 1; // number of bits | 152 int b = c + CLASS0_BITS - 1; // number of bits |
157 for (i = 0; i < b; ++i) | 153 for (i = 0; i < b; ++i) |
158 mvcomp->bits[i][((d >> i) & 1)] += incr; | 154 comp_counts->bits[i][((d >> i) & 1)] += incr; |
159 } | 155 } |
160 | 156 |
161 /* Code the fractional pel bits */ | 157 /* Code the fractional pel bits */ |
162 if (c == MV_CLASS_0) { | 158 if (c == MV_CLASS_0) { |
163 mvcomp->class0_fp[d][f] += incr; | 159 comp_counts->class0_fp[d][f] += incr; |
164 } else { | 160 } else { |
165 mvcomp->fp[f] += incr; | 161 comp_counts->fp[f] += incr; |
166 } | 162 } |
167 | 163 |
168 /* Code the high precision bit */ | 164 /* Code the high precision bit */ |
169 if (usehp) { | 165 if (usehp) { |
170 if (c == MV_CLASS_0) { | 166 if (c == MV_CLASS_0) { |
171 mvcomp->class0_hp[e] += incr; | 167 comp_counts->class0_hp[e] += incr; |
172 } else { | 168 } else { |
173 mvcomp->hp[e] += incr; | 169 comp_counts->hp[e] += incr; |
174 } | 170 } |
175 } | 171 } |
176 } | 172 } |
177 | 173 |
178 #ifdef SMOOTH_MV_COUNTS | 174 #ifdef SMOOTH_MV_COUNTS |
179 static void smooth_counts(nmv_component_counts *mvcomp) { | 175 static void smooth_counts(nmv_component_counts *mvcomp) { |
180 static const int flen = 3; // (filter_length + 1) / 2 | 176 static const int flen = 3; // (filter_length + 1) / 2 |
181 static const int fval[] = {8, 3, 1}; | 177 static const int fval[] = {8, 3, 1}; |
182 static const int fvalbits = 4; | 178 static const int fvalbits = 4; |
183 int i; | 179 int i; |
184 unsigned int smvcount[MV_VALS]; | 180 unsigned int smvcount[MV_VALS]; |
185 vpx_memcpy(smvcount, mvcomp->mvcount, sizeof(smvcount)); | 181 vpx_memcpy(smvcount, mvcomp->mvcount, sizeof(smvcount)); |
186 smvcount[MV_MAX] = (smvcount[MV_MAX - 1] + smvcount[MV_MAX + 1]) >> 1; | 182 smvcount[MV_MAX] = (smvcount[MV_MAX - 1] + smvcount[MV_MAX + 1]) >> 1; |
187 for (i = flen - 1; i <= MV_VALS - flen; ++i) { | 183 for (i = flen - 1; i <= MV_VALS - flen; ++i) { |
188 int j, s = smvcount[i] * fval[0]; | 184 int j, s = smvcount[i] * fval[0]; |
189 for (j = 1; j < flen; ++j) | 185 for (j = 1; j < flen; ++j) |
190 s += (smvcount[i - j] + smvcount[i + j]) * fval[j]; | 186 s += (smvcount[i - j] + smvcount[i + j]) * fval[j]; |
191 mvcomp->mvcount[i] = (s + (1 << (fvalbits - 1))) >> fvalbits; | 187 mvcomp->mvcount[i] = (s + (1 << (fvalbits - 1))) >> fvalbits; |
192 } | 188 } |
193 } | 189 } |
194 #endif | 190 #endif |
195 | 191 |
196 static void counts_to_context(nmv_component_counts *mvcomp, int usehp) { | 192 static void counts_to_context(nmv_component_counts *mvcomp, int usehp) { |
197 int v; | 193 int v; |
198 vpx_memset(mvcomp->sign, 0, sizeof(nmv_component_counts) - sizeof(mvcomp->mvco
unt)); | 194 vpx_memset(mvcomp->sign, 0, sizeof(nmv_component_counts) - sizeof(mvcomp->mvco
unt)); |
199 for (v = 1; v <= MV_MAX; v++) { | 195 for (v = 1; v <= MV_MAX; v++) { |
200 increment_nmv_component(-v, mvcomp, mvcomp->mvcount[MV_MAX - v], usehp); | 196 inc_mv_component(-v, mvcomp, mvcomp->mvcount[MV_MAX - v], usehp); |
201 increment_nmv_component( v, mvcomp, mvcomp->mvcount[MV_MAX + v], usehp); | 197 inc_mv_component( v, mvcomp, mvcomp->mvcount[MV_MAX + v], usehp); |
202 } | 198 } |
203 } | 199 } |
204 | 200 |
205 void vp9_increment_nmv(const MV *mv, const MV *ref, nmv_context_counts *mvctx, | 201 void vp9_increment_nmv(const MV *mv, const MV *ref, nmv_context_counts *mvctx, |
206 int usehp) { | 202 int usehp) { |
207 const MV_JOINT_TYPE j = vp9_get_mv_joint(mv); | 203 const MV_JOINT_TYPE j = vp9_get_mv_joint(mv); |
208 mvctx->joints[j]++; | 204 mvctx->joints[j]++; |
209 usehp = usehp && vp9_use_nmv_hp(ref); | 205 usehp = usehp && vp9_use_mv_hp(ref); |
210 if (mv_joint_vertical(j)) | 206 if (mv_joint_vertical(j)) |
211 increment_nmv_component_count(mv->row, &mvctx->comps[0], 1, usehp); | 207 inc_mv_component_count(mv->row, &mvctx->comps[0], 1); |
212 | 208 |
213 if (mv_joint_horizontal(j)) | 209 if (mv_joint_horizontal(j)) |
214 increment_nmv_component_count(mv->col, &mvctx->comps[1], 1, usehp); | 210 inc_mv_component_count(mv->col, &mvctx->comps[1], 1); |
215 } | 211 } |
216 | 212 |
217 static void adapt_prob(vp9_prob *dest, vp9_prob prep, unsigned int ct[2]) { | 213 static void adapt_prob(vp9_prob *dest, vp9_prob prep, unsigned int ct[2]) { |
218 const int count = MIN(ct[0] + ct[1], MV_COUNT_SAT); | 214 const int count = MIN(ct[0] + ct[1], MV_COUNT_SAT); |
219 if (count) { | 215 if (count) { |
220 const vp9_prob newp = get_binary_prob(ct[0], ct[1]); | 216 const vp9_prob newp = get_binary_prob(ct[0], ct[1]); |
221 const int factor = MV_MAX_UPDATE_FACTOR * count / MV_COUNT_SAT; | 217 const int factor = MV_MAX_UPDATE_FACTOR * count / MV_COUNT_SAT; |
222 *dest = weighted_prob(prep, newp, factor); | 218 *dest = weighted_prob(prep, newp, factor); |
223 } else { | 219 } else { |
224 *dest = prep; | 220 *dest = prep; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 this_prob = weighted_prob(last_probs[i >> 1], this_prob, | 321 this_prob = weighted_prob(last_probs[i >> 1], this_prob, |
326 MV_MAX_UPDATE_FACTOR * weight / MV_COUNT_SAT); | 322 MV_MAX_UPDATE_FACTOR * weight / MV_COUNT_SAT); |
327 } else { | 323 } else { |
328 this_prob = last_probs[i >> 1]; | 324 this_prob = last_probs[i >> 1]; |
329 } | 325 } |
330 this_probs[i >> 1] = this_prob; | 326 this_probs[i >> 1] = this_prob; |
331 return left + right; | 327 return left + right; |
332 } | 328 } |
333 | 329 |
334 | 330 |
335 void vp9_adapt_nmv_probs(VP9_COMMON *cm, int usehp) { | 331 void vp9_adapt_mv_probs(VP9_COMMON *cm, int usehp) { |
336 int i, j; | 332 int i, j; |
337 #ifdef MV_COUNT_TESTING | 333 #ifdef MV_COUNT_TESTING |
338 printf("joints count: "); | 334 printf("joints count: "); |
339 for (j = 0; j < MV_JOINTS; ++j) printf("%d ", cm->fc.NMVcount.joints[j]); | 335 for (j = 0; j < MV_JOINTS; ++j) printf("%d ", cm->fc.NMVcount.joints[j]); |
340 printf("\n"); fflush(stdout); | 336 printf("\n"); fflush(stdout); |
341 printf("signs count:\n"); | 337 printf("signs count:\n"); |
342 for (i = 0; i < 2; ++i) | 338 for (i = 0; i < 2; ++i) |
343 printf("%d/%d ", cm->fc.NMVcount.comps[i].sign[0], cm->fc.NMVcount.comps[i].
sign[1]); | 339 printf("%d/%d ", cm->fc.NMVcount.comps[i].sign[0], cm->fc.NMVcount.comps[i].
sign[1]); |
344 printf("\n"); fflush(stdout); | 340 printf("\n"); fflush(stdout); |
345 printf("classes count:\n"); | 341 printf("classes count:\n"); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 void vp9_entropy_mv_init() { | 439 void vp9_entropy_mv_init() { |
444 vp9_tokens_from_tree(vp9_mv_joint_encodings, vp9_mv_joint_tree); | 440 vp9_tokens_from_tree(vp9_mv_joint_encodings, vp9_mv_joint_tree); |
445 vp9_tokens_from_tree(vp9_mv_class_encodings, vp9_mv_class_tree); | 441 vp9_tokens_from_tree(vp9_mv_class_encodings, vp9_mv_class_tree); |
446 vp9_tokens_from_tree(vp9_mv_class0_encodings, vp9_mv_class0_tree); | 442 vp9_tokens_from_tree(vp9_mv_class0_encodings, vp9_mv_class0_tree); |
447 vp9_tokens_from_tree(vp9_mv_fp_encodings, vp9_mv_fp_tree); | 443 vp9_tokens_from_tree(vp9_mv_fp_encodings, vp9_mv_fp_tree); |
448 } | 444 } |
449 | 445 |
450 void vp9_init_mv_probs(VP9_COMMON *cm) { | 446 void vp9_init_mv_probs(VP9_COMMON *cm) { |
451 vpx_memcpy(&cm->fc.nmvc, &vp9_default_nmv_context, sizeof(nmv_context)); | 447 vpx_memcpy(&cm->fc.nmvc, &vp9_default_nmv_context, sizeof(nmv_context)); |
452 } | 448 } |
OLD | NEW |