brotli 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.travis.yml +11 -3
- data/Gemfile +2 -0
- data/ext/brotli/brotli.c +279 -0
- data/ext/brotli/brotli.h +2 -0
- data/ext/brotli/buffer.c +95 -0
- data/ext/brotli/buffer.h +19 -0
- data/ext/brotli/extconf.rb +21 -81
- data/lib/brotli/version.rb +1 -1
- data/vendor/brotli/dec/bit_reader.c +5 -5
- data/vendor/brotli/dec/bit_reader.h +15 -15
- data/vendor/brotli/dec/context.h +1 -1
- data/vendor/brotli/dec/decode.c +433 -348
- data/vendor/brotli/dec/decode.h +74 -48
- data/vendor/brotli/dec/huffman.c +5 -4
- data/vendor/brotli/dec/huffman.h +4 -4
- data/vendor/brotli/dec/port.h +2 -95
- data/vendor/brotli/dec/prefix.h +5 -3
- data/vendor/brotli/dec/state.c +15 -27
- data/vendor/brotli/dec/state.h +21 -17
- data/vendor/brotli/dec/transform.h +1 -1
- data/vendor/brotli/enc/backward_references.c +892 -0
- data/vendor/brotli/enc/backward_references.h +85 -102
- data/vendor/brotli/enc/backward_references_inc.h +147 -0
- data/vendor/brotli/enc/bit_cost.c +35 -0
- data/vendor/brotli/enc/bit_cost.h +23 -121
- data/vendor/brotli/enc/bit_cost_inc.h +127 -0
- data/vendor/brotli/enc/block_encoder_inc.h +33 -0
- data/vendor/brotli/enc/block_splitter.c +197 -0
- data/vendor/brotli/enc/block_splitter.h +40 -50
- data/vendor/brotli/enc/block_splitter_inc.h +432 -0
- data/vendor/brotli/enc/brotli_bit_stream.c +1334 -0
- data/vendor/brotli/enc/brotli_bit_stream.h +95 -167
- data/vendor/brotli/enc/cluster.c +56 -0
- data/vendor/brotli/enc/cluster.h +23 -305
- data/vendor/brotli/enc/cluster_inc.h +315 -0
- data/vendor/brotli/enc/command.h +83 -76
- data/vendor/brotli/enc/compress_fragment.c +747 -0
- data/vendor/brotli/enc/compress_fragment.h +48 -37
- data/vendor/brotli/enc/compress_fragment_two_pass.c +557 -0
- data/vendor/brotli/enc/compress_fragment_two_pass.h +37 -26
- data/vendor/brotli/enc/compressor.cc +139 -0
- data/vendor/brotli/enc/compressor.h +146 -0
- data/vendor/brotli/enc/context.h +102 -96
- data/vendor/brotli/enc/dictionary_hash.h +9 -5
- data/vendor/brotli/enc/encode.c +1562 -0
- data/vendor/brotli/enc/encode.h +211 -199
- data/vendor/brotli/enc/encode_parallel.cc +161 -151
- data/vendor/brotli/enc/encode_parallel.h +7 -8
- data/vendor/brotli/enc/entropy_encode.c +501 -0
- data/vendor/brotli/enc/entropy_encode.h +107 -89
- data/vendor/brotli/enc/entropy_encode_static.h +29 -62
- data/vendor/brotli/enc/fast_log.h +26 -20
- data/vendor/brotli/enc/find_match_length.h +23 -20
- data/vendor/brotli/enc/hash.h +614 -871
- data/vendor/brotli/enc/hash_forgetful_chain_inc.h +249 -0
- data/vendor/brotli/enc/hash_longest_match_inc.h +241 -0
- data/vendor/brotli/enc/hash_longest_match_quickly_inc.h +230 -0
- data/vendor/brotli/enc/histogram.c +95 -0
- data/vendor/brotli/enc/histogram.h +49 -83
- data/vendor/brotli/enc/histogram_inc.h +51 -0
- data/vendor/brotli/enc/literal_cost.c +178 -0
- data/vendor/brotli/enc/literal_cost.h +16 -10
- data/vendor/brotli/enc/memory.c +181 -0
- data/vendor/brotli/enc/memory.h +62 -0
- data/vendor/brotli/enc/metablock.c +515 -0
- data/vendor/brotli/enc/metablock.h +87 -57
- data/vendor/brotli/enc/metablock_inc.h +183 -0
- data/vendor/brotli/enc/port.h +73 -47
- data/vendor/brotli/enc/prefix.h +34 -61
- data/vendor/brotli/enc/quality.h +130 -0
- data/vendor/brotli/enc/ringbuffer.h +137 -122
- data/vendor/brotli/enc/{static_dict.cc → static_dict.c} +162 -139
- data/vendor/brotli/enc/static_dict.h +23 -18
- data/vendor/brotli/enc/static_dict_lut.h +11223 -12037
- data/vendor/brotli/enc/streams.cc +7 -7
- data/vendor/brotli/enc/streams.h +32 -32
- data/vendor/brotli/enc/{utf8_util.cc → utf8_util.c} +22 -20
- data/vendor/brotli/enc/utf8_util.h +16 -9
- data/vendor/brotli/enc/write_bits.h +49 -43
- metadata +34 -25
- data/ext/brotli/brotli.cc +0 -181
- data/vendor/brotli/dec/Makefile +0 -12
- data/vendor/brotli/dec/dictionary.c +0 -9466
- data/vendor/brotli/dec/dictionary.h +0 -38
- data/vendor/brotli/dec/types.h +0 -38
- data/vendor/brotli/enc/Makefile +0 -14
- data/vendor/brotli/enc/backward_references.cc +0 -858
- data/vendor/brotli/enc/block_splitter.cc +0 -505
- data/vendor/brotli/enc/brotli_bit_stream.cc +0 -1181
- data/vendor/brotli/enc/compress_fragment.cc +0 -701
- data/vendor/brotli/enc/compress_fragment_two_pass.cc +0 -524
- data/vendor/brotli/enc/dictionary.cc +0 -9466
- data/vendor/brotli/enc/dictionary.h +0 -41
- data/vendor/brotli/enc/encode.cc +0 -1180
- data/vendor/brotli/enc/entropy_encode.cc +0 -480
- data/vendor/brotli/enc/histogram.cc +0 -67
- data/vendor/brotli/enc/literal_cost.cc +0 -165
- data/vendor/brotli/enc/metablock.cc +0 -539
- data/vendor/brotli/enc/transform.h +0 -248
- data/vendor/brotli/enc/types.h +0 -29
@@ -4,176 +4,104 @@
|
|
4
4
|
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
|
5
5
|
*/
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
/* Functions to convert brotli-related data structures into the
|
8
|
+
brotli bit stream. The functions here operate under
|
9
|
+
assumption that there is enough space in the storage, i.e., there are
|
10
|
+
no out-of-range checks anywhere.
|
11
|
+
|
12
|
+
These functions do bit addressing into a byte array. The byte array
|
13
|
+
is called "storage" and the index to the bit is called storage_ix
|
14
|
+
in function arguments. */
|
15
15
|
|
16
16
|
#ifndef BROTLI_ENC_BROTLI_BIT_STREAM_H_
|
17
17
|
#define BROTLI_ENC_BROTLI_BIT_STREAM_H_
|
18
18
|
|
19
|
-
#include
|
20
|
-
|
19
|
+
#include "../common/types.h"
|
20
|
+
#include "./command.h"
|
21
|
+
#include "./context.h"
|
21
22
|
#include "./entropy_encode.h"
|
23
|
+
#include "./memory.h"
|
22
24
|
#include "./metablock.h"
|
23
|
-
#include "./
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
const size_t num_types,
|
107
|
-
BlockSplitCode* code,
|
108
|
-
size_t* storage_ix,
|
109
|
-
uint8_t* storage);
|
110
|
-
|
111
|
-
// Stores the block switch command with index block_ix to the bit stream.
|
112
|
-
void StoreBlockSwitch(const BlockSplitCode& code,
|
113
|
-
const size_t block_ix,
|
114
|
-
size_t* storage_ix,
|
115
|
-
uint8_t* storage);
|
116
|
-
|
117
|
-
// REQUIRES: length > 0
|
118
|
-
// REQUIRES: length <= (1 << 24)
|
119
|
-
void StoreMetaBlock(const uint8_t* input,
|
120
|
-
size_t start_pos,
|
121
|
-
size_t length,
|
122
|
-
size_t mask,
|
123
|
-
uint8_t prev_byte,
|
124
|
-
uint8_t prev_byte2,
|
125
|
-
bool final_block,
|
126
|
-
uint32_t num_direct_distance_codes,
|
127
|
-
uint32_t distance_postfix_bits,
|
128
|
-
ContextType literal_context_mode,
|
129
|
-
const brotli::Command *commands,
|
130
|
-
size_t n_commands,
|
131
|
-
const MetaBlockSplit& mb,
|
132
|
-
size_t *storage_ix,
|
133
|
-
uint8_t *storage);
|
134
|
-
|
135
|
-
// Stores the meta-block without doing any block splitting, just collects
|
136
|
-
// one histogram per block category and uses that for entropy coding.
|
137
|
-
// REQUIRES: length > 0
|
138
|
-
// REQUIRES: length <= (1 << 24)
|
139
|
-
void StoreMetaBlockTrivial(const uint8_t* input,
|
140
|
-
size_t start_pos,
|
141
|
-
size_t length,
|
142
|
-
size_t mask,
|
143
|
-
bool is_last,
|
144
|
-
const brotli::Command *commands,
|
145
|
-
size_t n_commands,
|
146
|
-
size_t *storage_ix,
|
147
|
-
uint8_t *storage);
|
148
|
-
|
149
|
-
// Same as above, but uses static prefix codes for histograms with a only a few
|
150
|
-
// symbols, and uses static code length prefix codes for all other histograms.
|
151
|
-
// REQUIRES: length > 0
|
152
|
-
// REQUIRES: length <= (1 << 24)
|
153
|
-
void StoreMetaBlockFast(const uint8_t* input,
|
154
|
-
size_t start_pos,
|
155
|
-
size_t length,
|
156
|
-
size_t mask,
|
157
|
-
bool is_last,
|
158
|
-
const brotli::Command *commands,
|
159
|
-
size_t n_commands,
|
160
|
-
size_t *storage_ix,
|
161
|
-
uint8_t *storage);
|
162
|
-
|
163
|
-
// This is for storing uncompressed blocks (simple raw storage of
|
164
|
-
// bytes-as-bytes).
|
165
|
-
// REQUIRES: length > 0
|
166
|
-
// REQUIRES: length <= (1 << 24)
|
167
|
-
void StoreUncompressedMetaBlock(bool final_block,
|
168
|
-
const uint8_t* input,
|
169
|
-
size_t position, size_t mask,
|
170
|
-
size_t len,
|
171
|
-
size_t* storage_ix,
|
172
|
-
uint8_t* storage);
|
173
|
-
|
174
|
-
// Stores an empty metadata meta-block and syncs to a byte boundary.
|
175
|
-
void StoreSyncMetaBlock(size_t* storage_ix, uint8_t* storage);
|
176
|
-
|
177
|
-
} // namespace brotli
|
178
|
-
|
179
|
-
#endif // BROTLI_ENC_BROTLI_BIT_STREAM_H_
|
25
|
+
#include "./port.h"
|
26
|
+
|
27
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
28
|
+
extern "C" {
|
29
|
+
#endif
|
30
|
+
|
31
|
+
/* All Store functions here will use a storage_ix, which is always the bit
|
32
|
+
position for the current storage. */
|
33
|
+
|
34
|
+
BROTLI_INTERNAL void BrotliStoreHuffmanTree(const uint8_t* depths, size_t num,
|
35
|
+
HuffmanTree* tree, size_t *storage_ix, uint8_t *storage);
|
36
|
+
|
37
|
+
BROTLI_INTERNAL void BrotliBuildAndStoreHuffmanTreeFast(
|
38
|
+
MemoryManager* m, const uint32_t* histogram, const size_t histogram_total,
|
39
|
+
const size_t max_bits, uint8_t* depth, uint16_t* bits, size_t* storage_ix,
|
40
|
+
uint8_t* storage);
|
41
|
+
|
42
|
+
/* REQUIRES: length > 0 */
|
43
|
+
/* REQUIRES: length <= (1 << 24) */
|
44
|
+
BROTLI_INTERNAL void BrotliStoreMetaBlock(MemoryManager* m,
|
45
|
+
const uint8_t* input,
|
46
|
+
size_t start_pos,
|
47
|
+
size_t length,
|
48
|
+
size_t mask,
|
49
|
+
uint8_t prev_byte,
|
50
|
+
uint8_t prev_byte2,
|
51
|
+
BROTLI_BOOL is_final_block,
|
52
|
+
uint32_t num_direct_distance_codes,
|
53
|
+
uint32_t distance_postfix_bits,
|
54
|
+
ContextType literal_context_mode,
|
55
|
+
const Command* commands,
|
56
|
+
size_t n_commands,
|
57
|
+
const MetaBlockSplit* mb,
|
58
|
+
size_t* storage_ix,
|
59
|
+
uint8_t* storage);
|
60
|
+
|
61
|
+
/* Stores the meta-block without doing any block splitting, just collects
|
62
|
+
one histogram per block category and uses that for entropy coding.
|
63
|
+
REQUIRES: length > 0
|
64
|
+
REQUIRES: length <= (1 << 24) */
|
65
|
+
BROTLI_INTERNAL void BrotliStoreMetaBlockTrivial(MemoryManager* m,
|
66
|
+
const uint8_t* input,
|
67
|
+
size_t start_pos,
|
68
|
+
size_t length,
|
69
|
+
size_t mask,
|
70
|
+
BROTLI_BOOL is_last,
|
71
|
+
const Command *commands,
|
72
|
+
size_t n_commands,
|
73
|
+
size_t* storage_ix,
|
74
|
+
uint8_t* storage);
|
75
|
+
|
76
|
+
/* Same as above, but uses static prefix codes for histograms with a only a few
|
77
|
+
symbols, and uses static code length prefix codes for all other histograms.
|
78
|
+
REQUIRES: length > 0
|
79
|
+
REQUIRES: length <= (1 << 24) */
|
80
|
+
BROTLI_INTERNAL void BrotliStoreMetaBlockFast(MemoryManager* m,
|
81
|
+
const uint8_t* input,
|
82
|
+
size_t start_pos,
|
83
|
+
size_t length,
|
84
|
+
size_t mask,
|
85
|
+
BROTLI_BOOL is_last,
|
86
|
+
const Command *commands,
|
87
|
+
size_t n_commands,
|
88
|
+
size_t* storage_ix,
|
89
|
+
uint8_t* storage);
|
90
|
+
|
91
|
+
/* This is for storing uncompressed blocks (simple raw storage of
|
92
|
+
bytes-as-bytes).
|
93
|
+
REQUIRES: length > 0
|
94
|
+
REQUIRES: length <= (1 << 24) */
|
95
|
+
BROTLI_INTERNAL void BrotliStoreUncompressedMetaBlock(
|
96
|
+
BROTLI_BOOL is_final_block, const uint8_t* input, size_t position,
|
97
|
+
size_t mask, size_t len, size_t* storage_ix, uint8_t* storage);
|
98
|
+
|
99
|
+
/* Stores an empty metadata meta-block and syncs to a byte boundary. */
|
100
|
+
BROTLI_INTERNAL void BrotliStoreSyncMetaBlock(size_t* storage_ix,
|
101
|
+
uint8_t* storage);
|
102
|
+
|
103
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
104
|
+
} /* extern "C" */
|
105
|
+
#endif
|
106
|
+
|
107
|
+
#endif /* BROTLI_ENC_BROTLI_BIT_STREAM_H_ */
|
@@ -0,0 +1,56 @@
|
|
1
|
+
/* Copyright 2013 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
|
+
/* Functions for clustering similar histograms together. */
|
8
|
+
|
9
|
+
#include "./cluster.h"
|
10
|
+
|
11
|
+
#include "../common/types.h"
|
12
|
+
#include "./bit_cost.h" /* BrotliPopulationCost */
|
13
|
+
#include "./fast_log.h"
|
14
|
+
#include "./histogram.h"
|
15
|
+
#include "./memory.h"
|
16
|
+
#include "./port.h"
|
17
|
+
|
18
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
19
|
+
extern "C" {
|
20
|
+
#endif
|
21
|
+
|
22
|
+
static BROTLI_INLINE BROTLI_BOOL HistogramPairIsLess(
|
23
|
+
const HistogramPair* p1, const HistogramPair* p2) {
|
24
|
+
if (p1->cost_diff != p2->cost_diff) {
|
25
|
+
return TO_BROTLI_BOOL(p1->cost_diff > p2->cost_diff);
|
26
|
+
}
|
27
|
+
return TO_BROTLI_BOOL((p1->idx2 - p1->idx1) > (p2->idx2 - p2->idx1));
|
28
|
+
}
|
29
|
+
|
30
|
+
/* Returns entropy reduction of the context map when we combine two clusters. */
|
31
|
+
static BROTLI_INLINE double ClusterCostDiff(size_t size_a, size_t size_b) {
|
32
|
+
size_t size_c = size_a + size_b;
|
33
|
+
return (double)size_a * FastLog2(size_a) +
|
34
|
+
(double)size_b * FastLog2(size_b) -
|
35
|
+
(double)size_c * FastLog2(size_c);
|
36
|
+
}
|
37
|
+
|
38
|
+
#define CODE(X) X
|
39
|
+
|
40
|
+
#define FN(X) X ## Literal
|
41
|
+
#include "./cluster_inc.h" /* NOLINT(build/include) */
|
42
|
+
#undef FN
|
43
|
+
|
44
|
+
#define FN(X) X ## Command
|
45
|
+
#include "./cluster_inc.h" /* NOLINT(build/include) */
|
46
|
+
#undef FN
|
47
|
+
|
48
|
+
#define FN(X) X ## Distance
|
49
|
+
#include "./cluster_inc.h" /* NOLINT(build/include) */
|
50
|
+
#undef FN
|
51
|
+
|
52
|
+
#undef CODE
|
53
|
+
|
54
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
55
|
+
} /* extern "C" */
|
56
|
+
#endif
|