16fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org/*
26fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
36fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org *
46fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org *  Use of this source code is governed by a BSD-style license
56fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org *  that can be found in the LICENSE file in the root of the source
66fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org *  tree. An additional intellectual property rights grant can be found
76fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org *  in the file PATENTS.  All contributing project authors may
86fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org *  be found in the AUTHORS file in the root of the source tree.
96fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org */
106fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
116fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org#ifndef VP9_ENCODER_VP9_TREEWRITER_H_
126fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org#define VP9_ENCODER_VP9_TREEWRITER_H_
136fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
140e29f91ae7876791fc422e9c7cea72b1866439a6johannkoenig@chromium.org#include "vp9/encoder/vp9_writer.h"
156fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
16dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org#ifdef __cplusplus
17dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.orgextern "C" {
18dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org#endif
19dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org
20d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.orgvoid vp9_tree_probs_from_distribution(vp9_tree tree,
21d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org                                      unsigned int branch_ct[ /* n - 1 */ ][2],
22d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org                                      const unsigned int num_events[ /* n */ ]);
23d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org
24d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.orgstruct vp9_token {
25d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  int value;
26d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  int len;
27d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org};
286fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
29d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.orgvoid vp9_tokens_from_tree(struct vp9_token*, const vp9_tree_index *);
30d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org
31d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.orgstatic INLINE void vp9_write_tree(vp9_writer *w, const vp9_tree_index *tree,
32d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org                                  const vp9_prob *probs, int bits, int len,
33d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org                                  vp9_tree_index i) {
346fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org  do {
3510a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org    const int bit = (bits >> --len) & 1;
36d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org    vp9_write(w, bit, probs[i >> 1]);
3710a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org    i = tree[i + bit];
3810a9a0d835561a7f2300c561c514efcf374554d6fgalligan@chromium.org  } while (len);
396fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org}
406fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
41d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.orgstatic INLINE void vp9_write_token(vp9_writer *w, const vp9_tree_index *tree,
42d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org                                   const vp9_prob *probs,
43d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org                                   const struct vp9_token *token) {
44d851b91d14ef0bd71acdce7b90c9a8f1af1181adjohannkoenig@chromium.org  vp9_write_tree(w, tree, probs, token->value, token->len, 0);
456fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org}
466fefe538d859300e7febe78271828198c10f1b52fgalligan@chromium.org
47dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org#ifdef __cplusplus
48dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org}  // extern "C"
49dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org#endif
50dddee1ec7cedf276305b107429f684539b105276johannkoenig@chromium.org
51d348b8d765c019ee7250075d663a83db00c65c08tomfinegan@chromium.org#endif  // VP9_ENCODER_VP9_TREEWRITER_H_
52