brotli 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitmodules +1 -1
- data/.travis.yml +2 -1
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/ext/brotli/brotli.cc +1 -1
- data/ext/brotli/extconf.rb +72 -14
- data/lib/brotli/version.rb +1 -1
- data/vendor/brotli/LICENSE +19 -202
- data/vendor/brotli/dec/Makefile +1 -1
- data/vendor/brotli/dec/bit_reader.c +23 -30
- data/vendor/brotli/dec/bit_reader.h +270 -141
- data/vendor/brotli/dec/context.h +3 -12
- data/vendor/brotli/dec/decode.c +1813 -1048
- data/vendor/brotli/dec/decode.h +22 -16
- data/vendor/brotli/dec/dictionary.c +9466 -0
- data/vendor/brotli/dec/dictionary.h +6 -9461
- data/vendor/brotli/dec/huffman.c +104 -71
- data/vendor/brotli/dec/huffman.h +19 -28
- data/vendor/brotli/dec/port.h +124 -32
- data/vendor/brotli/dec/prefix.h +4 -13
- data/vendor/brotli/dec/state.c +93 -56
- data/vendor/brotli/dec/state.h +124 -53
- data/vendor/brotli/dec/streams.c +14 -11
- data/vendor/brotli/dec/streams.h +6 -11
- data/vendor/brotli/dec/transform.h +2 -11
- data/vendor/brotli/dec/types.h +21 -19
- data/vendor/brotli/enc/Makefile +4 -1
- data/vendor/brotli/enc/backward_references.cc +87 -94
- data/vendor/brotli/enc/backward_references.h +8 -18
- data/vendor/brotli/enc/bit_cost.h +11 -19
- data/vendor/brotli/enc/block_splitter.cc +43 -48
- data/vendor/brotli/enc/block_splitter.h +7 -16
- data/vendor/brotli/enc/brotli_bit_stream.cc +48 -50
- data/vendor/brotli/enc/brotli_bit_stream.h +7 -16
- data/vendor/brotli/enc/cluster.h +24 -25
- data/vendor/brotli/enc/command.h +34 -41
- data/vendor/brotli/enc/context.h +11 -18
- data/vendor/brotli/enc/dictionary.cc +9466 -0
- data/vendor/brotli/enc/dictionary.h +20 -9464
- data/vendor/brotli/enc/dictionary_hash.h +7 -15
- data/vendor/brotli/enc/encode.cc +80 -148
- data/vendor/brotli/enc/encode.h +19 -29
- data/vendor/brotli/enc/encode_parallel.cc +35 -108
- data/vendor/brotli/enc/encode_parallel.h +7 -16
- data/vendor/brotli/enc/entropy_encode.cc +33 -42
- data/vendor/brotli/enc/entropy_encode.h +8 -16
- data/vendor/brotli/enc/fast_log.h +8 -15
- data/vendor/brotli/enc/find_match_length.h +7 -17
- data/vendor/brotli/enc/hash.h +130 -150
- data/vendor/brotli/enc/histogram.cc +7 -16
- data/vendor/brotli/enc/histogram.h +11 -17
- data/vendor/brotli/enc/literal_cost.cc +28 -35
- data/vendor/brotli/enc/literal_cost.h +9 -23
- data/vendor/brotli/enc/metablock.cc +18 -26
- data/vendor/brotli/enc/metablock.h +6 -14
- data/vendor/brotli/enc/port.h +14 -14
- data/vendor/brotli/enc/prefix.h +11 -18
- data/vendor/brotli/enc/ringbuffer.h +18 -27
- data/vendor/brotli/enc/static_dict.cc +7 -1
- data/vendor/brotli/enc/static_dict.h +7 -15
- data/vendor/brotli/enc/static_dict_lut.h +7 -15
- data/vendor/brotli/enc/streams.cc +15 -28
- data/vendor/brotli/enc/streams.h +27 -35
- data/vendor/brotli/enc/transform.h +9 -16
- data/vendor/brotli/enc/types.h +27 -0
- data/vendor/brotli/enc/utf8_util.cc +82 -0
- data/vendor/brotli/enc/utf8_util.h +25 -0
- data/vendor/brotli/enc/write_bits.h +11 -18
- metadata +7 -2
@@ -1,17 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
//
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
// See the License for the specific language governing permissions and
|
13
|
-
// limitations under the License.
|
14
|
-
//
|
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
|
+
|
15
7
|
// Implementation of parallel Brotli compressor.
|
16
8
|
|
17
9
|
#include "./encode_parallel.h"
|
@@ -31,84 +23,23 @@
|
|
31
23
|
#include "./fast_log.h"
|
32
24
|
#include "./hash.h"
|
33
25
|
#include "./histogram.h"
|
34
|
-
#include "./literal_cost.h"
|
35
26
|
#include "./prefix.h"
|
27
|
+
#include "./utf8_util.h"
|
36
28
|
#include "./write_bits.h"
|
37
29
|
|
38
30
|
namespace brotli {
|
39
31
|
|
40
32
|
namespace {
|
41
33
|
|
42
|
-
|
43
|
-
// ASCII
|
44
|
-
if ((input[0] & 0x80) == 0) {
|
45
|
-
*symbol = input[0];
|
46
|
-
if (*symbol > 0) {
|
47
|
-
return 1;
|
48
|
-
}
|
49
|
-
}
|
50
|
-
// 2-byte UTF8
|
51
|
-
if (size > 1 &&
|
52
|
-
(input[0] & 0xe0) == 0xc0 &&
|
53
|
-
(input[1] & 0xc0) == 0x80) {
|
54
|
-
*symbol = (((input[0] & 0x1f) << 6) |
|
55
|
-
(input[1] & 0x3f));
|
56
|
-
if (*symbol > 0x7f) {
|
57
|
-
return 2;
|
58
|
-
}
|
59
|
-
}
|
60
|
-
// 3-byte UFT8
|
61
|
-
if (size > 2 &&
|
62
|
-
(input[0] & 0xf0) == 0xe0 &&
|
63
|
-
(input[1] & 0xc0) == 0x80 &&
|
64
|
-
(input[2] & 0xc0) == 0x80) {
|
65
|
-
*symbol = (((input[0] & 0x0f) << 12) |
|
66
|
-
((input[1] & 0x3f) << 6) |
|
67
|
-
(input[2] & 0x3f));
|
68
|
-
if (*symbol > 0x7ff) {
|
69
|
-
return 3;
|
70
|
-
}
|
71
|
-
}
|
72
|
-
// 4-byte UFT8
|
73
|
-
if (size > 3 &&
|
74
|
-
(input[0] & 0xf8) == 0xf0 &&
|
75
|
-
(input[1] & 0xc0) == 0x80 &&
|
76
|
-
(input[2] & 0xc0) == 0x80 &&
|
77
|
-
(input[3] & 0xc0) == 0x80) {
|
78
|
-
*symbol = (((input[0] & 0x07) << 18) |
|
79
|
-
((input[1] & 0x3f) << 12) |
|
80
|
-
((input[2] & 0x3f) << 6) |
|
81
|
-
(input[3] & 0x3f));
|
82
|
-
if (*symbol > 0xffff && *symbol <= 0x10ffff) {
|
83
|
-
return 4;
|
84
|
-
}
|
85
|
-
}
|
86
|
-
// Not UTF8, emit a special symbol above the UTF8-code space
|
87
|
-
*symbol = 0x110000 | input[0];
|
88
|
-
return 1;
|
89
|
-
}
|
90
|
-
|
91
|
-
// Returns true if at least min_fraction of the data is UTF8-encoded.
|
92
|
-
bool IsMostlyUTF8(const uint8_t* data, size_t length, double min_fraction) {
|
93
|
-
size_t size_utf8 = 0;
|
94
|
-
for (size_t pos = 0; pos < length; ) {
|
95
|
-
int symbol;
|
96
|
-
int bytes_read = ParseAsUTF8(&symbol, data + pos, length - pos);
|
97
|
-
pos += bytes_read;
|
98
|
-
if (symbol < 0x110000) size_utf8 += bytes_read;
|
99
|
-
}
|
100
|
-
return size_utf8 > min_fraction * length;
|
101
|
-
}
|
102
|
-
|
103
|
-
void RecomputeDistancePrefixes(std::vector<Command>* cmds,
|
34
|
+
void RecomputeDistancePrefixes(Command* cmds, size_t num_commands,
|
104
35
|
int num_direct_distance_codes,
|
105
36
|
int distance_postfix_bits) {
|
106
37
|
if (num_direct_distance_codes == 0 &&
|
107
38
|
distance_postfix_bits == 0) {
|
108
39
|
return;
|
109
40
|
}
|
110
|
-
for (
|
111
|
-
Command* cmd = &
|
41
|
+
for (size_t i = 0; i < num_commands; ++i) {
|
42
|
+
Command* cmd = &cmds[i];
|
112
43
|
if (cmd->copy_len_ > 0 && cmd->cmd_prefix_ >= 128) {
|
113
44
|
PrefixEncodeCopyDistance(cmd->DistanceCode(),
|
114
45
|
num_direct_distance_codes,
|
@@ -151,50 +82,44 @@ bool WriteMetaBlockParallel(const BrotliParams& params,
|
|
151
82
|
|
152
83
|
// Decide about UTF8 mode.
|
153
84
|
static const double kMinUTF8Ratio = 0.75;
|
154
|
-
bool utf8_mode = IsMostlyUTF8(&input[
|
155
|
-
|
156
|
-
// Compute literal costs. The 4 bytes at the end are there to cover for an
|
157
|
-
// over-read past the end of input, but not past the mask, in
|
158
|
-
// CreateBackwardReferences.
|
159
|
-
std::vector<float> literal_cost(prefix_size + input_size + 4);
|
160
|
-
if (utf8_mode) {
|
161
|
-
EstimateBitCostsForLiteralsUTF8(input_pos, input_size, mask, mask,
|
162
|
-
&input[0], &literal_cost[0]);
|
163
|
-
} else {
|
164
|
-
EstimateBitCostsForLiterals(input_pos, input_size, mask, mask,
|
165
|
-
&input[0], &literal_cost[0]);
|
166
|
-
}
|
85
|
+
bool utf8_mode = IsMostlyUTF8(&input[0], input_pos, mask, input_size,
|
86
|
+
kMinUTF8Ratio);
|
167
87
|
|
168
88
|
// Initialize hashers.
|
169
89
|
int hash_type = std::min(9, params.quality);
|
170
|
-
|
90
|
+
Hashers* hashers = new Hashers();
|
171
91
|
hashers->Init(hash_type);
|
172
92
|
|
173
93
|
// Compute backward references.
|
174
94
|
int last_insert_len = 0;
|
175
|
-
|
95
|
+
size_t num_commands = 0;
|
176
96
|
int num_literals = 0;
|
177
97
|
int max_backward_distance = (1 << params.lgwin) - 16;
|
178
98
|
int dist_cache[4] = { -4, -4, -4, -4 };
|
179
|
-
|
99
|
+
Command* commands = static_cast<Command*>(
|
100
|
+
malloc(sizeof(Command) * ((input_size + 1) >> 1)));
|
101
|
+
if (commands == 0) {
|
102
|
+
delete hashers;
|
103
|
+
return false;
|
104
|
+
}
|
180
105
|
CreateBackwardReferences(
|
181
106
|
input_size, input_pos,
|
182
107
|
&input[0], mask,
|
183
|
-
&literal_cost[0], mask,
|
184
108
|
max_backward_distance,
|
185
109
|
params.quality,
|
186
|
-
hashers
|
110
|
+
hashers,
|
187
111
|
hash_type,
|
188
112
|
dist_cache,
|
189
113
|
&last_insert_len,
|
190
|
-
|
114
|
+
commands,
|
191
115
|
&num_commands,
|
192
116
|
&num_literals);
|
193
|
-
|
117
|
+
delete hashers;
|
194
118
|
if (last_insert_len > 0) {
|
195
|
-
commands
|
119
|
+
commands[num_commands++] = Command(last_insert_len);
|
196
120
|
num_literals += last_insert_len;
|
197
121
|
}
|
122
|
+
assert(num_commands != 0);
|
198
123
|
|
199
124
|
// Build the meta-block.
|
200
125
|
MetaBlockSplit mb;
|
@@ -202,17 +127,17 @@ bool WriteMetaBlockParallel(const BrotliParams& params,
|
|
202
127
|
params.mode == BrotliParams::MODE_FONT ? 12 : 0;
|
203
128
|
int distance_postfix_bits = params.mode == BrotliParams::MODE_FONT ? 1 : 0;
|
204
129
|
int literal_context_mode = utf8_mode ? CONTEXT_UTF8 : CONTEXT_SIGNED;
|
205
|
-
RecomputeDistancePrefixes(
|
130
|
+
RecomputeDistancePrefixes(commands, num_commands,
|
206
131
|
num_direct_distance_codes,
|
207
132
|
distance_postfix_bits);
|
208
133
|
if (params.quality <= 9) {
|
209
134
|
BuildMetaBlockGreedy(&input[0], input_pos, mask,
|
210
|
-
commands
|
135
|
+
commands, num_commands,
|
211
136
|
&mb);
|
212
137
|
} else {
|
213
138
|
BuildMetaBlock(&input[0], input_pos, mask,
|
214
139
|
prev_byte, prev_byte2,
|
215
|
-
commands
|
140
|
+
commands, num_commands,
|
216
141
|
literal_context_mode,
|
217
142
|
&mb);
|
218
143
|
}
|
@@ -234,7 +159,7 @@ bool WriteMetaBlockParallel(const BrotliParams& params,
|
|
234
159
|
first_byte_bits = 4;
|
235
160
|
}
|
236
161
|
}
|
237
|
-
storage[0] = first_byte;
|
162
|
+
storage[0] = static_cast<uint8_t>(first_byte);
|
238
163
|
int storage_ix = first_byte_bits;
|
239
164
|
|
240
165
|
// Store the meta-block to the temporary output.
|
@@ -244,11 +169,13 @@ bool WriteMetaBlockParallel(const BrotliParams& params,
|
|
244
169
|
num_direct_distance_codes,
|
245
170
|
distance_postfix_bits,
|
246
171
|
literal_context_mode,
|
247
|
-
commands
|
172
|
+
commands, num_commands,
|
248
173
|
mb,
|
249
174
|
&storage_ix, &storage[0])) {
|
175
|
+
free(commands);
|
250
176
|
return false;
|
251
177
|
}
|
178
|
+
free(commands);
|
252
179
|
|
253
180
|
// If this is not the last meta-block, store an empty metadata
|
254
181
|
// meta-block so that the meta-block will end at a byte boundary.
|
@@ -260,7 +187,7 @@ bool WriteMetaBlockParallel(const BrotliParams& params,
|
|
260
187
|
// meta-block.
|
261
188
|
size_t output_size = storage_ix >> 3;
|
262
189
|
if (input_size + 4 < output_size) {
|
263
|
-
storage[0] = first_byte;
|
190
|
+
storage[0] = static_cast<uint8_t>(first_byte);
|
264
191
|
storage_ix = first_byte_bits;
|
265
192
|
if (!StoreUncompressedMetaBlock(is_last, &input[0], input_pos, mask,
|
266
193
|
input_size,
|
@@ -318,7 +245,7 @@ int BrotliCompressBufferParallel(BrotliParams params,
|
|
318
245
|
// Compress block-by-block independently.
|
319
246
|
for (size_t pos = 0; pos < input_size; ) {
|
320
247
|
size_t input_block_size = std::min(max_input_block_size, input_size - pos);
|
321
|
-
size_t out_size =
|
248
|
+
size_t out_size = input_block_size + (input_block_size >> 3) + 1024;
|
322
249
|
std::vector<uint8_t> out(out_size);
|
323
250
|
if (!WriteMetaBlockParallel(params,
|
324
251
|
input_block_size,
|
@@ -338,7 +265,7 @@ int BrotliCompressBufferParallel(BrotliParams params,
|
|
338
265
|
|
339
266
|
// Piece together the output.
|
340
267
|
size_t out_pos = 0;
|
341
|
-
for (
|
268
|
+
for (size_t i = 0; i < compressed_pieces.size(); ++i) {
|
342
269
|
const std::vector<uint8_t>& out = compressed_pieces[i];
|
343
270
|
if (out_pos + out.size() > *encoded_size) {
|
344
271
|
return false;
|
@@ -1,17 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
//
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
// See the License for the specific language governing permissions and
|
13
|
-
// limitations under the License.
|
14
|
-
//
|
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
|
+
|
15
7
|
// API for parallel Brotli compression
|
16
8
|
// Note that this is only a proof of concept currently and not part of the
|
17
9
|
// final API yet.
|
@@ -19,10 +11,9 @@
|
|
19
11
|
#ifndef BROTLI_ENC_ENCODE_PARALLEL_H_
|
20
12
|
#define BROTLI_ENC_ENCODE_PARALLEL_H_
|
21
13
|
|
22
|
-
#include <stddef.h>
|
23
|
-
#include <stdint.h>
|
24
14
|
|
25
15
|
#include "./encode.h"
|
16
|
+
#include "./types.h"
|
26
17
|
|
27
18
|
namespace brotli {
|
28
19
|
|
@@ -1,35 +1,27 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
//
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
// See the License for the specific language governing permissions and
|
13
|
-
// limitations under the License.
|
14
|
-
//
|
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
|
+
|
15
7
|
// Entropy encoding (Huffman) utilities.
|
16
8
|
|
17
9
|
#include "./entropy_encode.h"
|
18
10
|
|
19
|
-
#include <stdint.h>
|
20
11
|
#include <algorithm>
|
21
12
|
#include <limits>
|
22
13
|
#include <vector>
|
23
14
|
#include <cstdlib>
|
24
15
|
|
25
16
|
#include "./histogram.h"
|
17
|
+
#include "./port.h"
|
18
|
+
#include "./types.h"
|
26
19
|
|
27
20
|
namespace brotli {
|
28
21
|
|
29
22
|
namespace {
|
30
23
|
|
31
24
|
struct HuffmanTree {
|
32
|
-
HuffmanTree();
|
33
25
|
HuffmanTree(int count, int16_t left, int16_t right)
|
34
26
|
: total_count_(count),
|
35
27
|
index_left_(left),
|
@@ -40,8 +32,6 @@ struct HuffmanTree {
|
|
40
32
|
int16_t index_right_or_value_;
|
41
33
|
};
|
42
34
|
|
43
|
-
HuffmanTree::HuffmanTree() {}
|
44
|
-
|
45
35
|
// Sort the root nodes, least popular first.
|
46
36
|
bool SortHuffmanTree(const HuffmanTree &v0, const HuffmanTree &v1) {
|
47
37
|
return v0.total_count_ < v1.total_count_;
|
@@ -50,7 +40,7 @@ bool SortHuffmanTree(const HuffmanTree &v0, const HuffmanTree &v1) {
|
|
50
40
|
void SetDepth(const HuffmanTree &p,
|
51
41
|
HuffmanTree *pool,
|
52
42
|
uint8_t *depth,
|
53
|
-
|
43
|
+
uint8_t level) {
|
54
44
|
if (p.index_left_ >= 0) {
|
55
45
|
++level;
|
56
46
|
SetDepth(pool[p.index_left_], pool, depth, level);
|
@@ -92,11 +82,11 @@ void CreateHuffmanTree(const int *data,
|
|
92
82
|
for (int i = length - 1; i >= 0; --i) {
|
93
83
|
if (data[i]) {
|
94
84
|
const int count = std::max(data[i], count_limit);
|
95
|
-
tree.push_back(HuffmanTree(count, -1, i));
|
85
|
+
tree.push_back(HuffmanTree(count, -1, static_cast<int16_t>(i)));
|
96
86
|
}
|
97
87
|
}
|
98
88
|
|
99
|
-
const int n = tree.size();
|
89
|
+
const int n = static_cast<int>(tree.size());
|
100
90
|
if (n == 1) {
|
101
91
|
depth[tree[0].index_right_or_value_] = 1; // Only one element.
|
102
92
|
break;
|
@@ -135,15 +125,16 @@ void CreateHuffmanTree(const int *data,
|
|
135
125
|
}
|
136
126
|
|
137
127
|
// The sentinel node becomes the parent node.
|
138
|
-
int j_end = tree.size() - 1;
|
128
|
+
int j_end = static_cast<int>(tree.size()) - 1;
|
139
129
|
tree[j_end].total_count_ =
|
140
130
|
tree[left].total_count_ + tree[right].total_count_;
|
141
|
-
tree[j_end].index_left_ = left;
|
142
|
-
tree[j_end].index_right_or_value_ = right;
|
131
|
+
tree[j_end].index_left_ = static_cast<int16_t>(left);
|
132
|
+
tree[j_end].index_right_or_value_ = static_cast<int16_t>(right);
|
143
133
|
|
144
134
|
// Add back the last sentinel node.
|
145
135
|
tree.push_back(sentinel);
|
146
136
|
}
|
137
|
+
BROTLI_DCHECK(tree.size() == 2 * n + 1);
|
147
138
|
SetDepth(tree[2 * n - 1], &tree[0], depth, 0);
|
148
139
|
|
149
140
|
// We need to pack the Huffman tree in tree_limit bits.
|
@@ -158,7 +149,7 @@ void CreateHuffmanTree(const int *data,
|
|
158
149
|
void Reverse(std::vector<uint8_t>* v, int start, int end) {
|
159
150
|
--end;
|
160
151
|
while (start < end) {
|
161
|
-
|
152
|
+
uint8_t tmp = (*v)[start];
|
162
153
|
(*v)[start] = (*v)[end];
|
163
154
|
(*v)[end] = tmp;
|
164
155
|
++start;
|
@@ -167,8 +158,8 @@ void Reverse(std::vector<uint8_t>* v, int start, int end) {
|
|
167
158
|
}
|
168
159
|
|
169
160
|
void WriteHuffmanTreeRepetitions(
|
170
|
-
const
|
171
|
-
const
|
161
|
+
const uint8_t previous_value,
|
162
|
+
const uint8_t value,
|
172
163
|
int repetitions,
|
173
164
|
std::vector<uint8_t> *tree,
|
174
165
|
std::vector<uint8_t> *extra_bits_data) {
|
@@ -189,15 +180,15 @@ void WriteHuffmanTreeRepetitions(
|
|
189
180
|
}
|
190
181
|
} else {
|
191
182
|
repetitions -= 3;
|
192
|
-
int start = tree->size();
|
183
|
+
int start = static_cast<int>(tree->size());
|
193
184
|
while (repetitions >= 0) {
|
194
185
|
tree->push_back(16);
|
195
186
|
extra_bits_data->push_back(repetitions & 0x3);
|
196
187
|
repetitions >>= 2;
|
197
188
|
--repetitions;
|
198
189
|
}
|
199
|
-
Reverse(tree, start, tree->size());
|
200
|
-
Reverse(extra_bits_data, start, tree->size());
|
190
|
+
Reverse(tree, start, static_cast<int>(tree->size()));
|
191
|
+
Reverse(extra_bits_data, start, static_cast<int>(tree->size()));
|
201
192
|
}
|
202
193
|
}
|
203
194
|
|
@@ -217,15 +208,15 @@ void WriteHuffmanTreeRepetitionsZeros(
|
|
217
208
|
}
|
218
209
|
} else {
|
219
210
|
repetitions -= 3;
|
220
|
-
int start = tree->size();
|
211
|
+
int start = static_cast<int>(tree->size());
|
221
212
|
while (repetitions >= 0) {
|
222
213
|
tree->push_back(17);
|
223
214
|
extra_bits_data->push_back(repetitions & 0x7);
|
224
215
|
repetitions >>= 3;
|
225
216
|
--repetitions;
|
226
217
|
}
|
227
|
-
Reverse(tree, start, tree->size());
|
228
|
-
Reverse(extra_bits_data, start, tree->size());
|
218
|
+
Reverse(tree, start, static_cast<int>(tree->size()));
|
219
|
+
Reverse(extra_bits_data, start, static_cast<int>(tree->size()));
|
229
220
|
}
|
230
221
|
}
|
231
222
|
|
@@ -374,10 +365,10 @@ static void DecideOverRleUse(const uint8_t* depth, const int length,
|
|
374
365
|
int total_reps_non_zero = 0;
|
375
366
|
int count_reps_zero = 0;
|
376
367
|
int count_reps_non_zero = 0;
|
377
|
-
for (
|
368
|
+
for (int i = 0; i < length;) {
|
378
369
|
const int value = depth[i];
|
379
370
|
int reps = 1;
|
380
|
-
for (
|
371
|
+
for (int k = i + 1; k < length && depth[k] == value; ++k) {
|
381
372
|
++reps;
|
382
373
|
}
|
383
374
|
if (reps >= 3 && value == 0) {
|
@@ -400,11 +391,11 @@ void WriteHuffmanTree(const uint8_t* depth,
|
|
400
391
|
uint32_t length,
|
401
392
|
std::vector<uint8_t> *tree,
|
402
393
|
std::vector<uint8_t> *extra_bits_data) {
|
403
|
-
|
394
|
+
uint8_t previous_value = 8;
|
404
395
|
|
405
396
|
// Throw away trailing zeros.
|
406
|
-
|
407
|
-
for (
|
397
|
+
uint32_t new_length = length;
|
398
|
+
for (uint32_t i = 0; i < length; ++i) {
|
408
399
|
if (depth[length - i - 1] == 0) {
|
409
400
|
--new_length;
|
410
401
|
} else {
|
@@ -424,7 +415,7 @@ void WriteHuffmanTree(const uint8_t* depth,
|
|
424
415
|
|
425
416
|
// Actual rle coding.
|
426
417
|
for (uint32_t i = 0; i < new_length;) {
|
427
|
-
const
|
418
|
+
const uint8_t value = depth[i];
|
428
419
|
int reps = 1;
|
429
420
|
if ((value != 0 && use_rle_for_non_zero) ||
|
430
421
|
(value == 0 && use_rle_for_zero)) {
|
@@ -453,11 +444,11 @@ uint16_t ReverseBits(int num_bits, uint16_t bits) {
|
|
453
444
|
size_t retval = kLut[bits & 0xf];
|
454
445
|
for (int i = 4; i < num_bits; i += 4) {
|
455
446
|
retval <<= 4;
|
456
|
-
bits
|
447
|
+
bits = static_cast<uint16_t>(bits >> 4);
|
457
448
|
retval |= kLut[bits & 0xf];
|
458
449
|
}
|
459
450
|
retval >>= (-num_bits & 0x3);
|
460
|
-
return retval;
|
451
|
+
return static_cast<uint16_t>(retval);
|
461
452
|
}
|
462
453
|
|
463
454
|
} // namespace
|
@@ -479,7 +470,7 @@ void ConvertBitDepthsToSymbols(const uint8_t *depth, int len, uint16_t *bits) {
|
|
479
470
|
int code = 0;
|
480
471
|
for (int bits = 1; bits < kMaxBits; ++bits) {
|
481
472
|
code = (code + bl_count[bits - 1]) << 1;
|
482
|
-
next_code[bits] = code;
|
473
|
+
next_code[bits] = static_cast<uint16_t>(code);
|
483
474
|
}
|
484
475
|
}
|
485
476
|
for (int i = 0; i < len; ++i) {
|
@@ -1,27 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
//
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
// See the License for the specific language governing permissions and
|
13
|
-
// limitations under the License.
|
14
|
-
//
|
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
|
+
|
15
7
|
// Entropy encoding (Huffman) utilities.
|
16
8
|
|
17
9
|
#ifndef BROTLI_ENC_ENTROPY_ENCODE_H_
|
18
10
|
#define BROTLI_ENC_ENTROPY_ENCODE_H_
|
19
11
|
|
20
|
-
#include <stdint.h>
|
21
12
|
#include <string.h>
|
22
13
|
#include <vector>
|
23
14
|
#include "./histogram.h"
|
24
15
|
#include "./prefix.h"
|
16
|
+
#include "./types.h"
|
25
17
|
|
26
18
|
namespace brotli {
|
27
19
|
|
@@ -47,7 +39,7 @@ void CreateHuffmanTree(const int *data,
|
|
47
39
|
// counts contains the population counts.
|
48
40
|
int OptimizeHuffmanCountsForRle(int length, int* counts);
|
49
41
|
|
50
|
-
// Write a
|
42
|
+
// Write a Huffman tree from bit depths into the bitstream representation
|
51
43
|
// of a Huffman tree. The generated Huffman tree is to be compressed once
|
52
44
|
// more using a Huffman tree
|
53
45
|
void WriteHuffmanTree(const uint8_t* depth,
|
@@ -1,17 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
//
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
// See the License for the specific language governing permissions and
|
13
|
-
// limitations under the License.
|
14
|
-
//
|
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
|
+
|
15
7
|
// Utilities for fast computation of logarithms.
|
16
8
|
|
17
9
|
#ifndef BROTLI_ENC_FAST_LOG_H_
|
@@ -19,7 +11,8 @@
|
|
19
11
|
|
20
12
|
#include <assert.h>
|
21
13
|
#include <math.h>
|
22
|
-
|
14
|
+
|
15
|
+
#include "./types.h"
|
23
16
|
|
24
17
|
namespace brotli {
|
25
18
|
|
@@ -1,27 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
8
|
-
//
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
-
// See the License for the specific language governing permissions and
|
13
|
-
// limitations under the License.
|
14
|
-
//
|
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
|
+
|
15
7
|
// Function to find maximal matching prefixes of strings.
|
16
8
|
|
17
9
|
#ifndef BROTLI_ENC_FIND_MATCH_LENGTH_H_
|
18
10
|
#define BROTLI_ENC_FIND_MATCH_LENGTH_H_
|
19
11
|
|
20
|
-
#include <stdint.h>
|
21
|
-
|
22
|
-
#include <stddef.h>
|
23
12
|
|
24
13
|
#include "./port.h"
|
14
|
+
#include "./types.h"
|
25
15
|
|
26
16
|
namespace brotli {
|
27
17
|
|