1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libvpx/vp9/common/vp9_treecoder.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,64 @@ 1.4 +/* 1.5 + * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license 1.8 + * that can be found in the LICENSE file in the root of the source 1.9 + * tree. An additional intellectual property rights grant can be found 1.10 + * in the file PATENTS. All contributing project authors may 1.11 + * be found in the AUTHORS file in the root of the source tree. 1.12 + */ 1.13 + 1.14 + 1.15 +#include <assert.h> 1.16 + 1.17 +#include "./vpx_config.h" 1.18 +#include "vp9/common/vp9_treecoder.h" 1.19 + 1.20 +static void tree2tok(struct vp9_token *const p, vp9_tree t, 1.21 + int i, int v, int l) { 1.22 + v += v; 1.23 + ++l; 1.24 + 1.25 + do { 1.26 + const vp9_tree_index j = t[i++]; 1.27 + 1.28 + if (j <= 0) { 1.29 + p[-j].value = v; 1.30 + p[-j].len = l; 1.31 + } else { 1.32 + tree2tok(p, t, j, v, l); 1.33 + } 1.34 + } while (++v & 1); 1.35 +} 1.36 + 1.37 +void vp9_tokens_from_tree(struct vp9_token *p, vp9_tree t) { 1.38 + tree2tok(p, t, 0, 0, 0); 1.39 +} 1.40 + 1.41 +static unsigned int convert_distribution(unsigned int i, vp9_tree tree, 1.42 + unsigned int branch_ct[][2], 1.43 + const unsigned int num_events[]) { 1.44 + unsigned int left, right; 1.45 + 1.46 + if (tree[i] <= 0) 1.47 + left = num_events[-tree[i]]; 1.48 + else 1.49 + left = convert_distribution(tree[i], tree, branch_ct, num_events); 1.50 + 1.51 + if (tree[i + 1] <= 0) 1.52 + right = num_events[-tree[i + 1]]; 1.53 + else 1.54 + right = convert_distribution(tree[i + 1], tree, branch_ct, num_events); 1.55 + 1.56 + branch_ct[i >> 1][0] = left; 1.57 + branch_ct[i >> 1][1] = right; 1.58 + return left + right; 1.59 +} 1.60 + 1.61 +void vp9_tree_probs_from_distribution(vp9_tree tree, 1.62 + unsigned int branch_ct[/* n-1 */][2], 1.63 + const unsigned int num_events[/* n */]) { 1.64 + convert_distribution(0, tree, branch_ct, num_events); 1.65 +} 1.66 + 1.67 +