Path: blob/master/thirdparty/libwebp/src/utils/huffman_encode_utils.h
9912 views
// Copyright 2011 Google Inc. All Rights Reserved.1//2// Use of this source code is governed by a BSD-style license3// that can be found in the COPYING file in the root of the source4// tree. An additional intellectual property rights grant can be found5// in the file PATENTS. All contributing project authors may6// be found in the AUTHORS file in the root of the source tree.7// -----------------------------------------------------------------------------8//9// Author: Jyrki Alakuijala ([email protected])10//11// Entropy encoding (Huffman) for webp lossless1213#ifndef WEBP_UTILS_HUFFMAN_ENCODE_UTILS_H_14#define WEBP_UTILS_HUFFMAN_ENCODE_UTILS_H_1516#include "src/webp/types.h"1718#ifdef __cplusplus19extern "C" {20#endif2122// Struct for holding the tree header in coded form.23typedef struct {24uint8_t code; // value (0..15) or escape code (16,17,18)25uint8_t extra_bits; // extra bits for escape codes26} HuffmanTreeToken;2728// Struct to represent the tree codes (depth and bits array).29typedef struct {30int num_symbols; // Number of symbols.31uint8_t* code_lengths; // Code lengths of the symbols.32uint16_t* codes; // Symbol Codes.33} HuffmanTreeCode;3435// Struct to represent the Huffman tree.36typedef struct {37uint32_t total_count_; // Symbol frequency.38int value_; // Symbol value.39int pool_index_left_; // Index for the left sub-tree.40int pool_index_right_; // Index for the right sub-tree.41} HuffmanTree;4243// Turn the Huffman tree into a token sequence.44// Returns the number of tokens used.45int VP8LCreateCompressedHuffmanTree(const HuffmanTreeCode* const tree,46HuffmanTreeToken* tokens, int max_tokens);4748// Create an optimized tree, and tokenize it.49// 'buf_rle' and 'huff_tree' are pre-allocated and the 'tree' is the constructed50// huffman code tree.51void VP8LCreateHuffmanTree(uint32_t* const histogram, int tree_depth_limit,52uint8_t* const buf_rle, HuffmanTree* const huff_tree,53HuffmanTreeCode* const huff_code);5455#ifdef __cplusplus56}57#endif5859#endif // WEBP_UTILS_HUFFMAN_ENCODE_UTILS_H_606162