Dmitry Kovalev | b5c9261 | 2013-12-16 12:53:09 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 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 | |
Yaowu Xu | 87d2c3c | 2015-07-17 14:09:05 -0700 | [diff] [blame] | 11 | #include "./prob.h" |
Dmitry Kovalev | b5c9261 | 2013-12-16 12:53:09 -0800 | [diff] [blame] | 12 | |
Yaowu Xu | 70ad668 | 2015-07-20 14:04:21 -0700 | [diff] [blame] | 13 | const uint8_t vpx_norm[256] = { |
Dmitry Kovalev | b5c9261 | 2013-12-16 12:53:09 -0800 | [diff] [blame] | 14 | 0, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, |
| 15 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, |
| 16 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 17 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, |
| 18 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 19 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 20 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 21 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 22 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 23 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 24 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 25 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 26 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 27 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 28 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 29 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
| 30 | }; |
Jim Bankoski | 69f58b4 | 2014-02-10 07:39:12 -0800 | [diff] [blame] | 31 | |
Jim Bankoski | 69f58b4 | 2014-02-10 07:39:12 -0800 | [diff] [blame] | 32 | static unsigned int tree_merge_probs_impl(unsigned int i, |
Yaowu Xu | 70ad668 | 2015-07-20 14:04:21 -0700 | [diff] [blame] | 33 | const vpx_tree_index *tree, |
Yaowu Xu | bf82514 | 2015-07-20 13:49:15 -0700 | [diff] [blame] | 34 | const vpx_prob *pre_probs, |
Jim Bankoski | 69f58b4 | 2014-02-10 07:39:12 -0800 | [diff] [blame] | 35 | const unsigned int *counts, |
Yaowu Xu | bf82514 | 2015-07-20 13:49:15 -0700 | [diff] [blame] | 36 | vpx_prob *probs) { |
Jim Bankoski | 69f58b4 | 2014-02-10 07:39:12 -0800 | [diff] [blame] | 37 | const int l = tree[i]; |
| 38 | const unsigned int left_count = (l <= 0) |
| 39 | ? counts[-l] |
Yaowu Xu | eda1797 | 2015-01-22 15:27:43 -0800 | [diff] [blame] | 40 | : tree_merge_probs_impl(l, tree, pre_probs, counts, probs); |
Jim Bankoski | 69f58b4 | 2014-02-10 07:39:12 -0800 | [diff] [blame] | 41 | const int r = tree[i + 1]; |
| 42 | const unsigned int right_count = (r <= 0) |
| 43 | ? counts[-r] |
Yaowu Xu | eda1797 | 2015-01-22 15:27:43 -0800 | [diff] [blame] | 44 | : tree_merge_probs_impl(r, tree, pre_probs, counts, probs); |
Jim Bankoski | 69f58b4 | 2014-02-10 07:39:12 -0800 | [diff] [blame] | 45 | const unsigned int ct[2] = { left_count, right_count }; |
Yaowu Xu | eda1797 | 2015-01-22 15:27:43 -0800 | [diff] [blame] | 46 | probs[i >> 1] = mode_mv_merge_probs(pre_probs[i >> 1], ct); |
Jim Bankoski | 69f58b4 | 2014-02-10 07:39:12 -0800 | [diff] [blame] | 47 | return left_count + right_count; |
| 48 | } |
| 49 | |
Yaowu Xu | 70ad668 | 2015-07-20 14:04:21 -0700 | [diff] [blame] | 50 | void vpx_tree_merge_probs(const vpx_tree_index *tree, const vpx_prob *pre_probs, |
Yaowu Xu | bf82514 | 2015-07-20 13:49:15 -0700 | [diff] [blame] | 51 | const unsigned int *counts, vpx_prob *probs) { |
Yaowu Xu | eda1797 | 2015-01-22 15:27:43 -0800 | [diff] [blame] | 52 | tree_merge_probs_impl(0, tree, pre_probs, counts, probs); |
Jim Bankoski | 69f58b4 | 2014-02-10 07:39:12 -0800 | [diff] [blame] | 53 | } |