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 "../common/platform.h"
13#include <brotli/types.h>
14
15#if defined(__cplusplus) || defined(c_plusplus)
16extern "C" {
17#endif
18
19/* A node of a Huffman tree. */
25
26static BROTLI_INLINE void InitHuffmanTree(HuffmanTree* self, uint32_t count,
27 int16_t left, int16_t right) {
28 self->total_count_ = count;
29 self->index_left_ = left;
30 self->index_right_or_value_ = right;
31}
32
33/* Returns 1 is assignment of depths succeeded, otherwise 0. */
35 int p, HuffmanTree* pool, uint8_t* depth, int max_depth);
36
37/* This function will create a Huffman tree.
38
39 The (data,length) contains the population counts.
40 The tree_limit is the maximum bit depth of the Huffman codes.
41
42 The depth contains the tree, i.e., how many bits are used for
43 the symbol.
44
45 The actual Huffman tree is constructed in the tree[] array, which has to
46 be at least 2 * length + 1 long.
47
48 See http://en.wikipedia.org/wiki/Huffman_coding */
50 const size_t length,
51 const int tree_limit,
52 HuffmanTree* tree,
53 uint8_t* depth);
54
55/* Change the population counts in a way that the consequent
56 Huffman tree compression, especially its RLE-part will be more
57 likely to compress this data more efficiently.
58
59 length contains the size of the histogram.
60 counts contains the population counts.
61 good_for_rle is a buffer of at least length size */
63 size_t length, uint32_t* counts, uint8_t* good_for_rle);
64
65/* Write a Huffman tree from bit depths into the bit-stream representation
66 of a Huffman tree. The generated Huffman tree is to be compressed once
67 more using a Huffman tree */
68BROTLI_INTERNAL void BrotliWriteHuffmanTree(const uint8_t* depth,
69 size_t num,
70 size_t* tree_size,
71 uint8_t* tree,
72 uint8_t* extra_bits_data);
73
74/* Get the actual bit values for a tree of bit depths. */
75BROTLI_INTERNAL void BrotliConvertBitDepthsToSymbols(const uint8_t* depth,
76 size_t len,
77 uint16_t* bits);
78
79BROTLI_INTERNAL extern const size_t kBrotliShellGaps[6];
80/* Input size optimized Shell sort. */
82 const HuffmanTree*, const HuffmanTree*);
83static BROTLI_INLINE void SortHuffmanTreeItems(HuffmanTree* items,
84 const size_t n, HuffmanTreeComparator comparator) {
85 if (n < 13) {
86 /* Insertion sort. */
87 size_t i;
88 for (i = 1; i < n; ++i) {
89 HuffmanTree tmp = items[i];
90 size_t k = i;
91 size_t j = i - 1;
92 while (comparator(&tmp, &items[j])) {
93 items[k] = items[j];
94 k = j;
95 if (!j--) break;
96 }
97 items[k] = tmp;
98 }
99 return;
100 } else {
101 /* Shell sort. */
102 int g = n < 57 ? 2 : 0;
103 for (; g < 6; ++g) {
104 size_t gap = kBrotliShellGaps[g];
105 size_t i;
106 for (i = gap; i < n; ++i) {
107 size_t j = i;
108 HuffmanTree tmp = items[i];
109 for (; j >= gap && comparator(&tmp, &items[j - gap]); j -= gap) {
110 items[j] = items[j - gap];
111 }
112 items[j] = tmp;
113 }
114 }
115 }
116}
117
118#if defined(__cplusplus) || defined(c_plusplus)
119} /* extern "C" */
120#endif
121
122#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