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: #ifndef __INC_TREECODER_H michael@0: #define __INC_TREECODER_H michael@0: michael@0: typedef unsigned char vp8bc_index_t; /* probability index */ michael@0: michael@0: michael@0: typedef unsigned char vp8_prob; michael@0: michael@0: #define vp8_prob_half ( (vp8_prob) 128) michael@0: michael@0: typedef signed char vp8_tree_index; michael@0: struct bool_coder_spec; michael@0: michael@0: typedef struct bool_coder_spec bool_coder_spec; michael@0: typedef struct bool_writer bool_writer; michael@0: typedef struct bool_reader bool_reader; michael@0: michael@0: typedef const bool_coder_spec c_bool_coder_spec; michael@0: typedef const bool_writer c_bool_writer; michael@0: typedef const bool_reader c_bool_reader; michael@0: michael@0: michael@0: michael@0: # define vp8_complement( x) (255 - x) michael@0: michael@0: michael@0: /* We build coding trees compactly in arrays. michael@0: Each node of the tree is a pair of vp8_tree_indices. michael@0: Array index often references a corresponding probability table. michael@0: Index <= 0 means done encoding/decoding and value = -Index, michael@0: Index > 0 means need another bit, specification at index. michael@0: Nonnegative indices are always even; processing begins at node 0. */ michael@0: michael@0: typedef const vp8_tree_index vp8_tree[], *vp8_tree_p; michael@0: michael@0: michael@0: typedef const struct vp8_token_struct michael@0: { michael@0: int value; michael@0: int Len; michael@0: } vp8_token; michael@0: michael@0: /* Construct encoding array from tree. */ michael@0: michael@0: void vp8_tokens_from_tree(struct vp8_token_struct *, vp8_tree); michael@0: void vp8_tokens_from_tree_offset(struct vp8_token_struct *, vp8_tree, michael@0: int offset); michael@0: michael@0: michael@0: /* Convert array of token occurrence counts into a table of probabilities michael@0: for the associated binary encoding tree. Also writes count of branches michael@0: taken for each node on the tree; this facilitiates decisions as to michael@0: probability updates. */ michael@0: michael@0: void vp8_tree_probs_from_distribution( michael@0: int n, /* n = size of alphabet */ michael@0: vp8_token tok [ /* n */ ], michael@0: vp8_tree tree, michael@0: vp8_prob probs [ /* n-1 */ ], michael@0: unsigned int branch_ct [ /* n-1 */ ] [2], michael@0: const unsigned int num_events[ /* n */ ], michael@0: unsigned int Pfactor, michael@0: int Round michael@0: ); michael@0: michael@0: /* Variant of above using coder spec rather than hardwired 8-bit probs. */ michael@0: michael@0: void vp8bc_tree_probs_from_distribution( michael@0: int n, /* n = size of alphabet */ michael@0: vp8_token tok [ /* n */ ], michael@0: vp8_tree tree, michael@0: vp8_prob probs [ /* n-1 */ ], michael@0: unsigned int branch_ct [ /* n-1 */ ] [2], michael@0: const unsigned int num_events[ /* n */ ], michael@0: c_bool_coder_spec *s michael@0: ); michael@0: michael@0: michael@0: #endif