Parolin 0.7.9 6796
Console (soon DLLs) to do a tar like job
Loading...
Searching...
No Matches
entropy_encode.h
Go to the documentation of this file.
1/* Copyright 2010 Google Inc. All Rights Reserved.
2
3 Distributed under MIT license.
4 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5*/
6
7/* Entropy encoding (Huffman) utilities. */
8
9#ifndef BROTLI_ENC_ENTROPY_ENCODE_H_
10#define BROTLI_ENC_ENTROPY_ENCODE_H_
11
12#include <brotli/types.h>
13
14#include "../common/platform.h"
15
16#if defined(__cplusplus) || defined(c_plusplus)
17extern "C" {
18#endif
19
20/* A node of a Huffman tree. */
21typedef struct HuffmanTree {
22 uint32_t total_count_;
23 int16_t index_left_;
26
27static BROTLI_INLINE void InitHuffmanTree(HuffmanTree* self, uint32_t count,
28 int16_t left, int16_t right) {
29 self->total_count_ = count;
30 self->index_left_ = left;
31 self->index_right_or_value_ = right;
32}
33
34/* Returns 1 is assignment of depths succeeded, otherwise 0. */
36 int p, HuffmanTree* pool, uint8_t* depth, int max_depth);
37
38/* This function will create a Huffman tree.
39
40 The (data,length) contains the population counts.
41 The tree_limit is the maximum bit depth of the Huffman codes.
42
43 The depth contains the tree, i.e., how many bits are used for
44 the symbol.
45
46 The actual Huffman tree is constructed in the tree[] array, which has to
47 be at least 2 * length + 1 long.
48
49 See http://en.wikipedia.org/wiki/Huffman_coding */
51 const size_t length,
52 const int tree_limit,
53 HuffmanTree* tree,
54 uint8_t* depth);
55
56/* Change the population counts in a way that the consequent
57 Huffman tree compression, especially its RLE-part will be more
58 likely to compress this data more efficiently.
59
60 length contains the size of the histogram.
61 counts contains the population counts.
62 good_for_rle is a buffer of at least length size */
64 size_t length, uint32_t* counts, uint8_t* good_for_rle);
65
66/* Write a Huffman tree from bit depths into the bit-stream representation
67 of a Huffman tree. The generated Huffman tree is to be compressed once
68 more using a Huffman tree */
69BROTLI_INTERNAL void BrotliWriteHuffmanTree(const uint8_t* depth,
70 size_t num,
71 size_t* tree_size,
72 uint8_t* tree,
73 uint8_t* extra_bits_data);
74
75/* Get the actual bit values for a tree of bit depths. */
76BROTLI_INTERNAL void BrotliConvertBitDepthsToSymbols(const uint8_t* depth,
77 size_t len,
78 uint16_t* bits);
79
80BROTLI_INTERNAL extern const size_t kBrotliShellGaps[6];
81/* Input size optimized Shell sort. */
83 const HuffmanTree*, const HuffmanTree*);
84static BROTLI_INLINE void SortHuffmanTreeItems(HuffmanTree* items,
85 const size_t n, HuffmanTreeComparator comparator) {
86 if (n < 13) {
87 /* Insertion sort. */
88 size_t i;
89 for (i = 1; i < n; ++i) {
90 HuffmanTree tmp = items[i];
91 size_t k = i;
92 size_t j = i - 1;
93 while (comparator(&tmp, &items[j])) {
94 items[k] = items[j];
95 k = j;
96 if (!j--) break;
97 }
98 items[k] = tmp;
99 }
100 return;
101 } else {
102 /* Shell sort. */
103 int g = n < 57 ? 2 : 0;
104 for (; g < 6; ++g) {
105 size_t gap = kBrotliShellGaps[g];
106 size_t i;
107 for (i = gap; i < n; ++i) {
108 size_t j = i;
109 HuffmanTree tmp = items[i];
110 for (; j >= gap && comparator(&tmp, &items[j - gap]); j -= gap) {
111 items[j] = items[j - gap];
112 }
113 items[j] = tmp;
114 }
115 }
116 }
117}
118
119#if defined(__cplusplus) || defined(c_plusplus)
120} /* extern "C" */
121#endif
122
123#endif /* BROTLI_ENC_ENTROPY_ENCODE_H_ */
struct HuffmanTree HuffmanTree
BROTLI_INTERNAL BROTLI_BOOL BrotliSetDepth(int p, HuffmanTree *pool, uint8_t *depth, int max_depth)
Definition entropy_encode.c:23
BROTLI_INTERNAL void BrotliWriteHuffmanTree(const uint8_t *depth, size_t num, size_t *tree_size, uint8_t *tree, uint8_t *extra_bits_data)
Definition entropy_encode.c:405
BROTLI_BOOL(* HuffmanTreeComparator)(const HuffmanTree *, const HuffmanTree *)
Definition entropy_encode.h:81
BROTLI_INTERNAL void BrotliOptimizeHuffmanCountsForRle(size_t length, uint32_t *counts, uint8_t *good_for_rle)
Definition entropy_encode.c:244
BROTLI_INTERNAL const size_t kBrotliShellGaps[6]
Definition entropy_encode.c:21
BROTLI_INTERNAL void BrotliCreateHuffmanTree(const uint32_t *data, const size_t length, const int tree_limit, HuffmanTree *tree, uint8_t *depth)
Definition entropy_encode.c:71
BROTLI_INTERNAL void BrotliConvertBitDepthsToSymbols(const uint8_t *depth, size_t len, uint16_t *bits)
Definition entropy_encode.c:476
Definition entropy_encode.h:20
uint32_t total_count_
Definition entropy_encode.h:21
int16_t index_left_
Definition entropy_encode.h:22
int16_t index_right_or_value_
Definition entropy_encode.h:23
Definition poolTests.c:28
#define BROTLI_INTERNAL
Definition platform.h:173
#define BROTLI_INLINE
Definition platform.h:136
#define BROTLI_BOOL
Definition types.h:49
#define g(i)
Definition sha256.c:47
size_t * left
Definition util.h:104
lzma_index ** i
Definition index.h:629
static uint32_t const uint8_t uint32_t len
Definition memcmplen.h:44