2012-04-03 14:24:25 +00:00
|
|
|
// Copyright 2011 Google Inc. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// This code is licensed under the same terms as WebM:
|
|
|
|
// Software License Agreement: http://www.webmproject.org/license/software/
|
|
|
|
// Additional IP Rights Grant: http://www.webmproject.org/license/additional/
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Author: jyrki@google.com (Jyrki Alakuijala)
|
|
|
|
//
|
2012-05-10 09:11:47 -07:00
|
|
|
// Flate-like entropy encoding (Huffman) for webp lossless
|
2012-04-03 14:24:25 +00:00
|
|
|
|
2012-04-04 08:24:29 +00:00
|
|
|
#ifndef WEBP_UTILS_HUFFMAN_ENCODE_H_
|
|
|
|
#define WEBP_UTILS_HUFFMAN_ENCODE_H_
|
2012-04-03 14:24:25 +00:00
|
|
|
|
2012-04-11 09:52:13 +00:00
|
|
|
#ifdef USE_LOSSLESS_ENCODER
|
|
|
|
|
2012-04-03 14:24:25 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2012-05-10 09:11:47 -07:00
|
|
|
// Create a Huffman tree.
|
2012-04-03 14:24:25 +00:00
|
|
|
//
|
2012-05-10 09:11:47 -07:00
|
|
|
// (data,length): population counts.
|
|
|
|
// tree_limit: maximum bit depth (inclusive) of the codes.
|
|
|
|
// bit_depths[]: how many bits are used for the symbol.
|
|
|
|
//
|
2012-05-11 01:16:34 -07:00
|
|
|
// Returns 0 when an error has occurred.
|
2012-05-10 09:11:47 -07:00
|
|
|
int VP8LCreateHuffmanTree(const int* data, const int length,
|
|
|
|
const int tree_limit, uint8_t* bit_depths);
|
|
|
|
|
|
|
|
// Turn the Huffman tree into a token sequence.
|
|
|
|
// Returns the number of tokens used.
|
|
|
|
typedef struct {
|
|
|
|
uint8_t code; // value (0..15) or escape code (16,17,18)
|
|
|
|
uint8_t extra_bits; // extra bits for escape codes
|
|
|
|
} HuffmanTreeToken;
|
|
|
|
|
|
|
|
int VP8LCreateCompressedHuffmanTree(const uint8_t* const depth, int len,
|
|
|
|
HuffmanTreeToken* tokens, int max_tokens);
|
2012-04-03 14:24:25 +00:00
|
|
|
|
2012-05-14 13:49:45 +05:30
|
|
|
// Struct to represent the tree codes (depth and bits array).
|
|
|
|
typedef struct {
|
|
|
|
int num_symbols; // Number of symbols.
|
|
|
|
uint8_t* code_lengths; // Code lengths of the symbols.
|
|
|
|
uint16_t* codes; // Symbol Codes.
|
|
|
|
} HuffmanTreeCode;
|
|
|
|
|
2012-04-03 14:24:25 +00:00
|
|
|
// Get the actual bit values for a tree of bit depths.
|
2012-05-14 13:49:45 +05:30
|
|
|
void VP8LConvertBitDepthsToSymbols(HuffmanTreeCode* const tree);
|
2012-04-03 14:24:25 +00:00
|
|
|
|
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-04-11 09:52:13 +00:00
|
|
|
#endif
|
|
|
|
|
2012-04-04 08:24:29 +00:00
|
|
|
#endif // WEBP_UTILS_HUFFMAN_ENCODE_H_
|