michael@0: /* michael@0: * Copyright (c) 2010 The WebM project authors. All Rights Reserved. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license michael@0: * that can be found in the LICENSE file in the root of the source michael@0: * tree. An additional intellectual property rights grant can be found michael@0: * in the file PATENTS. All contributing project authors may michael@0: * be found in the AUTHORS file in the root of the source tree. michael@0: */ michael@0: michael@0: michael@0: #include michael@0: michael@0: #include "./vpx_config.h" michael@0: #include "vp9/common/vp9_treecoder.h" michael@0: michael@0: static void tree2tok(struct vp9_token *const p, vp9_tree t, michael@0: int i, int v, int l) { michael@0: v += v; michael@0: ++l; michael@0: michael@0: do { michael@0: const vp9_tree_index j = t[i++]; michael@0: michael@0: if (j <= 0) { michael@0: p[-j].value = v; michael@0: p[-j].len = l; michael@0: } else { michael@0: tree2tok(p, t, j, v, l); michael@0: } michael@0: } while (++v & 1); michael@0: } michael@0: michael@0: void vp9_tokens_from_tree(struct vp9_token *p, vp9_tree t) { michael@0: tree2tok(p, t, 0, 0, 0); michael@0: } michael@0: michael@0: static unsigned int convert_distribution(unsigned int i, vp9_tree tree, michael@0: unsigned int branch_ct[][2], michael@0: const unsigned int num_events[]) { michael@0: unsigned int left, right; michael@0: michael@0: if (tree[i] <= 0) michael@0: left = num_events[-tree[i]]; michael@0: else michael@0: left = convert_distribution(tree[i], tree, branch_ct, num_events); michael@0: michael@0: if (tree[i + 1] <= 0) michael@0: right = num_events[-tree[i + 1]]; michael@0: else michael@0: right = convert_distribution(tree[i + 1], tree, branch_ct, num_events); michael@0: michael@0: branch_ct[i >> 1][0] = left; michael@0: branch_ct[i >> 1][1] = right; michael@0: return left + right; michael@0: } michael@0: michael@0: void vp9_tree_probs_from_distribution(vp9_tree tree, michael@0: unsigned int branch_ct[/* n-1 */][2], michael@0: const unsigned int num_events[/* n */]) { michael@0: convert_distribution(0, tree, branch_ct, num_events); michael@0: } michael@0: michael@0: