Home | History | Annotate | Download | only in common
      1 /*
      2  *  Copyright (c) 2010 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 
     11 
     12 #include <assert.h>
     13 
     14 #include "./vpx_config.h"
     15 #include "vp9/common/vp9_treecoder.h"
     16 
     17 static void tree2tok(struct vp9_token *const p, vp9_tree t,
     18                     int i, int v, int l) {
     19   v += v;
     20   ++l;
     21 
     22   do {
     23     const vp9_tree_index j = t[i++];
     24 
     25     if (j <= 0) {
     26       p[-j].value = v;
     27       p[-j].len = l;
     28     } else {
     29       tree2tok(p, t, j, v, l);
     30     }
     31   } while (++v & 1);
     32 }
     33 
     34 void vp9_tokens_from_tree(struct vp9_token *p, vp9_tree t) {
     35   tree2tok(p, t, 0, 0, 0);
     36 }
     37 
     38 static unsigned int convert_distribution(unsigned int i, vp9_tree tree,
     39                                          unsigned int branch_ct[][2],
     40                                          const unsigned int num_events[]) {
     41   unsigned int left, right;
     42 
     43   if (tree[i] <= 0)
     44     left = num_events[-tree[i]];
     45   else
     46     left = convert_distribution(tree[i], tree, branch_ct, num_events);
     47 
     48   if (tree[i + 1] <= 0)
     49     right = num_events[-tree[i + 1]];
     50   else
     51     right = convert_distribution(tree[i + 1], tree, branch_ct, num_events);
     52 
     53   branch_ct[i >> 1][0] = left;
     54   branch_ct[i >> 1][1] = right;
     55   return left + right;
     56 }
     57 
     58 void vp9_tree_probs_from_distribution(vp9_tree tree,
     59                                       unsigned int branch_ct[/* n-1 */][2],
     60                                       const unsigned int num_events[/* n */]) {
     61   convert_distribution(0, tree, branch_ct, num_events);
     62 }
     63 
     64 
     65