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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 if (j == MV_JOINT_HZVNZ || j == MV_JOINT_HNZVNZ) { | 206 if (j == MV_JOINT_HZVNZ || j == MV_JOINT_HNZVNZ) { |
207 increment_nmv_component_count(mv->row, &mvctx->comps[0], 1, usehp); | 207 increment_nmv_component_count(mv->row, &mvctx->comps[0], 1, usehp); |
208 } | 208 } |
209 if (j == MV_JOINT_HNZVZ || j == MV_JOINT_HNZVNZ) { | 209 if (j == MV_JOINT_HNZVZ || j == MV_JOINT_HNZVNZ) { |
210 increment_nmv_component_count(mv->col, &mvctx->comps[1], 1, usehp); | 210 increment_nmv_component_count(mv->col, &mvctx->comps[1], 1, usehp); |
211 } | 211 } |
212 } | 212 } |
213 | 213 |
214 static void adapt_prob(vp9_prob *dest, vp9_prob prep, vp9_prob newp, | 214 static void adapt_prob(vp9_prob *dest, vp9_prob prep, vp9_prob newp, |
215 unsigned int ct[2]) { | 215 unsigned int ct[2]) { |
216 int factor; | |
217 int prob; | |
218 int count = ct[0] + ct[1]; | 216 int count = ct[0] + ct[1]; |
| 217 |
219 if (count) { | 218 if (count) { |
220 count = count > MV_COUNT_SAT ? MV_COUNT_SAT : count; | 219 count = count > MV_COUNT_SAT ? MV_COUNT_SAT : count; |
221 factor = (MV_MAX_UPDATE_FACTOR * count / MV_COUNT_SAT); | 220 *dest = weighted_prob(prep, newp, |
222 prob = ((int)prep * (256 - factor) + (int)(newp) * factor + 128) >> 8; | 221 MV_MAX_UPDATE_FACTOR * count / MV_COUNT_SAT); |
223 prob += !prob; | |
224 prob = (prob > 255 ? 255 : prob); | |
225 *dest = prob; | |
226 } | 222 } |
227 } | 223 } |
228 | 224 |
229 void vp9_counts_process(nmv_context_counts *NMVcount, int usehp) { | 225 void vp9_counts_process(nmv_context_counts *NMVcount, int usehp) { |
230 counts_to_context(&NMVcount->comps[0], usehp); | 226 counts_to_context(&NMVcount->comps[0], usehp); |
231 counts_to_context(&NMVcount->comps[1], usehp); | 227 counts_to_context(&NMVcount->comps[1], usehp); |
232 } | 228 } |
233 | 229 |
234 void vp9_counts_to_nmv_context( | 230 void vp9_counts_to_nmv_context( |
235 nmv_context_counts *NMVcount, | 231 nmv_context_counts *NMVcount, |
236 nmv_context *prob, | 232 nmv_context *prob, |
237 int usehp, | 233 int usehp, |
238 unsigned int (*branch_ct_joint)[2], | 234 unsigned int (*branch_ct_joint)[2], |
239 unsigned int (*branch_ct_sign)[2], | 235 unsigned int (*branch_ct_sign)[2], |
240 unsigned int (*branch_ct_classes)[MV_CLASSES - 1][2], | 236 unsigned int (*branch_ct_classes)[MV_CLASSES - 1][2], |
241 unsigned int (*branch_ct_class0)[CLASS0_SIZE - 1][2], | 237 unsigned int (*branch_ct_class0)[CLASS0_SIZE - 1][2], |
242 unsigned int (*branch_ct_bits)[MV_OFFSET_BITS][2], | 238 unsigned int (*branch_ct_bits)[MV_OFFSET_BITS][2], |
243 unsigned int (*branch_ct_class0_fp)[CLASS0_SIZE][4 - 1][2], | 239 unsigned int (*branch_ct_class0_fp)[CLASS0_SIZE][4 - 1][2], |
244 unsigned int (*branch_ct_fp)[4 - 1][2], | 240 unsigned int (*branch_ct_fp)[4 - 1][2], |
245 unsigned int (*branch_ct_class0_hp)[2], | 241 unsigned int (*branch_ct_class0_hp)[2], |
246 unsigned int (*branch_ct_hp)[2]) { | 242 unsigned int (*branch_ct_hp)[2]) { |
247 int i, j, k; | 243 int i, j, k; |
248 vp9_counts_process(NMVcount, usehp); | 244 vp9_counts_process(NMVcount, usehp); |
249 vp9_tree_probs_from_distribution(MV_JOINTS, | 245 vp9_tree_probs_from_distribution(MV_JOINTS, |
250 vp9_mv_joint_encodings, | 246 vp9_mv_joint_encodings, |
251 vp9_mv_joint_tree, | 247 vp9_mv_joint_tree, |
252 prob->joints, | 248 prob->joints, |
253 branch_ct_joint, | 249 branch_ct_joint, |
254 NMVcount->joints, | 250 NMVcount->joints); |
255 256, 1); | |
256 for (i = 0; i < 2; ++i) { | 251 for (i = 0; i < 2; ++i) { |
257 prob->comps[i].sign = | 252 prob->comps[i].sign = get_binary_prob(NMVcount->comps[i].sign[0], |
258 vp9_bin_prob_from_distribution(NMVcount->comps[i].sign); | 253 NMVcount->comps[i].sign[1]); |
259 branch_ct_sign[i][0] = NMVcount->comps[i].sign[0]; | 254 branch_ct_sign[i][0] = NMVcount->comps[i].sign[0]; |
260 branch_ct_sign[i][1] = NMVcount->comps[i].sign[1]; | 255 branch_ct_sign[i][1] = NMVcount->comps[i].sign[1]; |
261 vp9_tree_probs_from_distribution(MV_CLASSES, | 256 vp9_tree_probs_from_distribution(MV_CLASSES, |
262 vp9_mv_class_encodings, | 257 vp9_mv_class_encodings, |
263 vp9_mv_class_tree, | 258 vp9_mv_class_tree, |
264 prob->comps[i].classes, | 259 prob->comps[i].classes, |
265 branch_ct_classes[i], | 260 branch_ct_classes[i], |
266 NMVcount->comps[i].classes, | 261 NMVcount->comps[i].classes); |
267 256, 1); | |
268 vp9_tree_probs_from_distribution(CLASS0_SIZE, | 262 vp9_tree_probs_from_distribution(CLASS0_SIZE, |
269 vp9_mv_class0_encodings, | 263 vp9_mv_class0_encodings, |
270 vp9_mv_class0_tree, | 264 vp9_mv_class0_tree, |
271 prob->comps[i].class0, | 265 prob->comps[i].class0, |
272 branch_ct_class0[i], | 266 branch_ct_class0[i], |
273 NMVcount->comps[i].class0, | 267 NMVcount->comps[i].class0); |
274 256, 1); | |
275 for (j = 0; j < MV_OFFSET_BITS; ++j) { | 268 for (j = 0; j < MV_OFFSET_BITS; ++j) { |
276 prob->comps[i].bits[j] = vp9_bin_prob_from_distribution( | 269 prob->comps[i].bits[j] = get_binary_prob(NMVcount->comps[i].bits[j][0], |
277 NMVcount->comps[i].bits[j]); | 270 NMVcount->comps[i].bits[j][1]); |
278 branch_ct_bits[i][j][0] = NMVcount->comps[i].bits[j][0]; | 271 branch_ct_bits[i][j][0] = NMVcount->comps[i].bits[j][0]; |
279 branch_ct_bits[i][j][1] = NMVcount->comps[i].bits[j][1]; | 272 branch_ct_bits[i][j][1] = NMVcount->comps[i].bits[j][1]; |
280 } | 273 } |
281 } | 274 } |
282 for (i = 0; i < 2; ++i) { | 275 for (i = 0; i < 2; ++i) { |
283 for (k = 0; k < CLASS0_SIZE; ++k) { | 276 for (k = 0; k < CLASS0_SIZE; ++k) { |
284 vp9_tree_probs_from_distribution(4, | 277 vp9_tree_probs_from_distribution(4, |
285 vp9_mv_fp_encodings, | 278 vp9_mv_fp_encodings, |
286 vp9_mv_fp_tree, | 279 vp9_mv_fp_tree, |
287 prob->comps[i].class0_fp[k], | 280 prob->comps[i].class0_fp[k], |
288 branch_ct_class0_fp[i][k], | 281 branch_ct_class0_fp[i][k], |
289 NMVcount->comps[i].class0_fp[k], | 282 NMVcount->comps[i].class0_fp[k]); |
290 256, 1); | |
291 } | 283 } |
292 vp9_tree_probs_from_distribution(4, | 284 vp9_tree_probs_from_distribution(4, |
293 vp9_mv_fp_encodings, | 285 vp9_mv_fp_encodings, |
294 vp9_mv_fp_tree, | 286 vp9_mv_fp_tree, |
295 prob->comps[i].fp, | 287 prob->comps[i].fp, |
296 branch_ct_fp[i], | 288 branch_ct_fp[i], |
297 NMVcount->comps[i].fp, | 289 NMVcount->comps[i].fp); |
298 256, 1); | |
299 } | 290 } |
300 if (usehp) { | 291 if (usehp) { |
301 for (i = 0; i < 2; ++i) { | 292 for (i = 0; i < 2; ++i) { |
302 prob->comps[i].class0_hp = vp9_bin_prob_from_distribution( | 293 prob->comps[i].class0_hp = |
303 NMVcount->comps[i].class0_hp); | 294 get_binary_prob(NMVcount->comps[i].class0_hp[0], |
| 295 NMVcount->comps[i].class0_hp[1]); |
304 branch_ct_class0_hp[i][0] = NMVcount->comps[i].class0_hp[0]; | 296 branch_ct_class0_hp[i][0] = NMVcount->comps[i].class0_hp[0]; |
305 branch_ct_class0_hp[i][1] = NMVcount->comps[i].class0_hp[1]; | 297 branch_ct_class0_hp[i][1] = NMVcount->comps[i].class0_hp[1]; |
306 | 298 |
307 prob->comps[i].hp = | 299 prob->comps[i].hp = get_binary_prob(NMVcount->comps[i].hp[0], |
308 vp9_bin_prob_from_distribution(NMVcount->comps[i].hp); | 300 NMVcount->comps[i].hp[1]); |
309 branch_ct_hp[i][0] = NMVcount->comps[i].hp[0]; | 301 branch_ct_hp[i][0] = NMVcount->comps[i].hp[0]; |
310 branch_ct_hp[i][1] = NMVcount->comps[i].hp[1]; | 302 branch_ct_hp[i][1] = NMVcount->comps[i].hp[1]; |
311 } | 303 } |
312 } | 304 } |
313 } | 305 } |
314 | 306 |
315 void vp9_adapt_nmv_probs(VP9_COMMON *cm, int usehp) { | 307 void vp9_adapt_nmv_probs(VP9_COMMON *cm, int usehp) { |
316 int i, j, k; | 308 int i, j, k; |
317 nmv_context prob; | 309 nmv_context prob; |
318 unsigned int branch_ct_joint[MV_JOINTS - 1][2]; | 310 unsigned int branch_ct_joint[MV_JOINTS - 1][2]; |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 void vp9_entropy_mv_init() { | 452 void vp9_entropy_mv_init() { |
461 vp9_tokens_from_tree(vp9_mv_joint_encodings, vp9_mv_joint_tree); | 453 vp9_tokens_from_tree(vp9_mv_joint_encodings, vp9_mv_joint_tree); |
462 vp9_tokens_from_tree(vp9_mv_class_encodings, vp9_mv_class_tree); | 454 vp9_tokens_from_tree(vp9_mv_class_encodings, vp9_mv_class_tree); |
463 vp9_tokens_from_tree(vp9_mv_class0_encodings, vp9_mv_class0_tree); | 455 vp9_tokens_from_tree(vp9_mv_class0_encodings, vp9_mv_class0_tree); |
464 vp9_tokens_from_tree(vp9_mv_fp_encodings, vp9_mv_fp_tree); | 456 vp9_tokens_from_tree(vp9_mv_fp_encodings, vp9_mv_fp_tree); |
465 } | 457 } |
466 | 458 |
467 void vp9_init_mv_probs(VP9_COMMON *cm) { | 459 void vp9_init_mv_probs(VP9_COMMON *cm) { |
468 vpx_memcpy(&cm->fc.nmvc, &vp9_default_nmv_context, sizeof(nmv_context)); | 460 vpx_memcpy(&cm->fc.nmvc, &vp9_default_nmv_context, sizeof(nmv_context)); |
469 } | 461 } |
OLD | NEW |