2012-04-10 17:23:38 -07:00
|
|
|
// Copyright 2012 Google Inc. All Rights Reserved.
|
|
|
|
//
|
2013-06-06 23:05:58 -07:00
|
|
|
// 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.
|
2012-04-10 17:23:38 -07:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
//
|
2012-04-23 07:19:02 +00:00
|
|
|
// Utilities for building and looking up Huffman trees.
|
2012-04-10 17:23:38 -07:00
|
|
|
//
|
2012-07-19 16:09:47 -07:00
|
|
|
// Author: Urvang Joshi (urvang@google.com)
|
2012-04-10 17:23:38 -07:00
|
|
|
|
|
|
|
#ifndef WEBP_UTILS_HUFFMAN_H_
|
|
|
|
#define WEBP_UTILS_HUFFMAN_H_
|
|
|
|
|
|
|
|
#include <assert.h>
|
2014-04-30 21:41:32 +00:00
|
|
|
#include "../webp/format_constants.h"
|
2012-04-10 17:23:38 -07:00
|
|
|
#include "../webp/types.h"
|
|
|
|
|
2013-11-25 14:43:12 -08:00
|
|
|
#ifdef __cplusplus
|
2012-04-10 17:23:38 -07:00
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2014-08-28 08:35:19 -07:00
|
|
|
#define HUFFMAN_TABLE_BITS 8
|
|
|
|
#define HUFFMAN_TABLE_MASK ((1 << HUFFMAN_TABLE_BITS) - 1)
|
|
|
|
|
|
|
|
#define LENGTHS_TABLE_BITS 7
|
|
|
|
#define LENGTHS_TABLE_MASK ((1 << LENGTHS_TABLE_BITS) - 1)
|
2012-04-10 17:23:38 -07:00
|
|
|
|
|
|
|
|
2014-08-28 08:35:19 -07:00
|
|
|
// Huffman lookup table entry
|
|
|
|
typedef struct {
|
|
|
|
uint8_t bits; // number of bits used for this symbol
|
|
|
|
uint16_t value; // symbol value or table offset
|
|
|
|
} HuffmanCode;
|
|
|
|
|
|
|
|
// Huffman table group.
|
2014-04-30 21:41:32 +00:00
|
|
|
typedef struct HTreeGroup HTreeGroup;
|
|
|
|
struct HTreeGroup {
|
2014-08-28 08:35:19 -07:00
|
|
|
HuffmanCode* htrees[HUFFMAN_CODES_PER_META_CODE];
|
2014-04-30 21:41:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Creates the instance of HTreeGroup with specified number of tree-groups.
|
|
|
|
HTreeGroup* VP8LHtreeGroupsNew(int num_htree_groups);
|
|
|
|
|
|
|
|
// Releases the memory allocated for HTreeGroup.
|
2014-08-28 08:35:19 -07:00
|
|
|
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).
|
|
|
|
int VP8LBuildHuffmanTable(HuffmanCode* const root_table, int root_bits,
|
2014-08-28 18:08:00 -07:00
|
|
|
const int code_lengths[], int code_lengths_size);
|
2012-04-10 17:23:38 -07:00
|
|
|
|
2013-11-25 14:43:12 -08:00
|
|
|
#ifdef __cplusplus
|
2012-04-10 17:23:38 -07:00
|
|
|
} // extern "C"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif // WEBP_UTILS_HUFFMAN_H_
|