// Copyright 2012 Google Inc. All Rights Reserved. // // Use of this source code is governed by a BSD-style license // that can be found in the COPYING file in the root of the source // tree. An additional intellectual property rights grant can be found // in the file PATENTS. All contributing project authors may // be found in the AUTHORS file in the root of the source tree. // ----------------------------------------------------------------------------- // // Utilities for building and looking up Huffman trees. // // Author: Urvang Joshi ([email protected]) #ifndef WEBP_UTILS_HUFFMAN_UTILS_H_ #define WEBP_UTILS_HUFFMAN_UTILS_H_ #include <assert.h> #include "src/webp/format_constants.h" #include "src/webp/types.h" #ifdef __cplusplus extern "C" { #endif #define HUFFMAN_TABLE_BITS … #define HUFFMAN_TABLE_MASK … #define LENGTHS_TABLE_BITS … #define LENGTHS_TABLE_MASK … // Huffman lookup table entry HuffmanCode; // long version for holding 32b values HuffmanCode32; // Contiguous memory segment of HuffmanCodes. HuffmanTablesSegment; // Chained memory segments of HuffmanCodes. HuffmanTables; // Allocates a HuffmanTables with 'size' contiguous HuffmanCodes. Returns 0 on // memory allocation error, 1 otherwise. WEBP_NODISCARD int VP8LHuffmanTablesAllocate(int size, HuffmanTables* huffman_tables); void VP8LHuffmanTablesDeallocate(HuffmanTables* const huffman_tables); #define HUFFMAN_PACKED_BITS … #define HUFFMAN_PACKED_TABLE_SIZE … // Huffman table group. // Includes special handling for the following cases: // - is_trivial_literal: one common literal base for RED/BLUE/ALPHA (not GREEN) // - is_trivial_code: only 1 code (no bit is read from bitstream) // - use_packed_table: few enough literal symbols, so all the bit codes // can fit into a small look-up table packed_table[] // The common literal base, if applicable, is stored in 'literal_arb'. HTreeGroup; struct HTreeGroup { … }; // Creates the instance of HTreeGroup with specified number of tree-groups. WEBP_NODISCARD HTreeGroup* VP8LHtreeGroupsNew(int num_htree_groups); // Releases the memory allocated for HTreeGroup. void VP8LHtreeGroupsFree(HTreeGroup* const htree_groups); // Builds Huffman lookup table assuming code lengths are in symbol order. // The 'code_lengths' is pre-allocated temporary memory buffer used for creating // the huffman table. // Returns built table size or 0 in case of error (invalid tree or // memory error). WEBP_NODISCARD int VP8LBuildHuffmanTable(HuffmanTables* const root_table, int root_bits, const int code_lengths[], int code_lengths_size); #ifdef __cplusplus } // extern "C" #endif #endif // WEBP_UTILS_HUFFMAN_UTILS_H_