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,44 +4,39 @@
|
|
4
4
|
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
|
5
5
|
*/
|
6
6
|
|
7
|
-
|
7
|
+
/* Implementation of parallel Brotli compressor. */
|
8
8
|
|
9
9
|
#include "./encode_parallel.h"
|
10
10
|
|
11
|
-
#include <
|
12
|
-
#include <limits>
|
11
|
+
#include <vector>
|
13
12
|
|
14
13
|
#include "./backward_references.h"
|
15
|
-
#include "./bit_cost.h"
|
16
|
-
#include "./block_splitter.h"
|
17
14
|
#include "./brotli_bit_stream.h"
|
18
|
-
#include "./cluster.h"
|
19
15
|
#include "./context.h"
|
20
|
-
#include "./metablock.h"
|
21
|
-
#include "./transform.h"
|
22
16
|
#include "./entropy_encode.h"
|
23
17
|
#include "./fast_log.h"
|
24
18
|
#include "./hash.h"
|
25
|
-
#include "./
|
19
|
+
#include "./metablock.h"
|
20
|
+
#include "./port.h"
|
26
21
|
#include "./prefix.h"
|
22
|
+
#include "./quality.h"
|
27
23
|
#include "./utf8_util.h"
|
28
|
-
#include "./write_bits.h"
|
29
24
|
|
30
25
|
namespace brotli {
|
31
26
|
|
32
27
|
namespace {
|
33
28
|
|
34
|
-
void RecomputeDistancePrefixes(Command* cmds, size_t num_commands,
|
35
|
-
|
36
|
-
|
29
|
+
static void RecomputeDistancePrefixes(Command* cmds, size_t num_commands,
|
30
|
+
uint32_t num_direct_distance_codes,
|
31
|
+
uint32_t distance_postfix_bits) {
|
37
32
|
if (num_direct_distance_codes == 0 &&
|
38
33
|
distance_postfix_bits == 0) {
|
39
34
|
return;
|
40
35
|
}
|
41
36
|
for (size_t i = 0; i < num_commands; ++i) {
|
42
37
|
Command* cmd = &cmds[i];
|
43
|
-
if (cmd
|
44
|
-
PrefixEncodeCopyDistance(cmd
|
38
|
+
if (CommandCopyLen(cmd) && cmd->cmd_prefix_ >= 128) {
|
39
|
+
PrefixEncodeCopyDistance(CommandDistanceCode(cmd),
|
45
40
|
num_direct_distance_codes,
|
46
41
|
distance_postfix_bits,
|
47
42
|
&cmd->dist_prefix_,
|
@@ -50,230 +45,245 @@ void RecomputeDistancePrefixes(Command* cmds, size_t num_commands,
|
|
50
45
|
}
|
51
46
|
}
|
52
47
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
48
|
+
/* Returns 1 on success, otherwise 0. */
|
49
|
+
int WriteMetaBlockParallel(const BrotliEncoderParams* params,
|
50
|
+
const uint32_t input_size,
|
51
|
+
const uint8_t* input_buffer,
|
52
|
+
const uint32_t prefix_size,
|
53
|
+
const uint8_t* prefix_buffer,
|
54
|
+
const int is_first,
|
55
|
+
const int is_last,
|
56
|
+
size_t* encoded_size,
|
57
|
+
uint8_t* encoded_buffer) {
|
62
58
|
if (input_size == 0) {
|
63
|
-
return
|
59
|
+
return 0;
|
64
60
|
}
|
65
61
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
// mask points past the end of input.
|
70
|
-
// FindMatchLengthWithLimit could do another 8 bytes look-forward.
|
71
|
-
std::vector<uint8_t> input(prefix_size + input_size + 4 + 8);
|
72
|
-
memcpy(&input[0], prefix_buffer, prefix_size);
|
73
|
-
memcpy(&input[input_pos], input_buffer, input_size);
|
74
|
-
// Since we don't have a ringbuffer, masking is a no-op.
|
75
|
-
// We use one less bit than the full range because some of the code uses
|
76
|
-
// mask + 1 as the size of the ringbuffer.
|
77
|
-
const uint32_t mask = std::numeric_limits<uint32_t>::max() >> 1;
|
78
|
-
|
79
|
-
uint8_t prev_byte = input_pos > 0 ? input[(input_pos - 1) & mask] : 0;
|
80
|
-
uint8_t prev_byte2 = input_pos > 1 ? input[(input_pos - 2) & mask] : 0;
|
81
|
-
|
82
|
-
// Decide about UTF8 mode.
|
83
|
-
static const double kMinUTF8Ratio = 0.75;
|
84
|
-
bool utf8_mode = IsMostlyUTF8(&input[0], input_pos, mask, input_size,
|
85
|
-
kMinUTF8Ratio);
|
86
|
-
|
87
|
-
// Initialize hashers.
|
88
|
-
int hash_type = std::min(10, params.quality);
|
89
|
-
Hashers* hashers = new Hashers();
|
90
|
-
hashers->Init(hash_type);
|
62
|
+
MemoryManager memory_manager;
|
63
|
+
MemoryManager* m = &memory_manager;
|
64
|
+
BrotliInitMemoryManager(m, 0, 0, 0);
|
91
65
|
|
92
|
-
|
66
|
+
uint8_t* storage;
|
67
|
+
size_t storage_ix;
|
68
|
+
uint8_t first_byte;
|
69
|
+
size_t first_byte_bits;
|
70
|
+
size_t output_size;
|
71
|
+
uint32_t num_direct_distance_codes;
|
72
|
+
uint32_t distance_postfix_bits;
|
73
|
+
ContextType literal_context_mode;
|
93
74
|
size_t last_insert_len = 0;
|
94
75
|
size_t num_commands = 0;
|
95
76
|
size_t num_literals = 0;
|
96
77
|
int dist_cache[4] = { -4, -4, -4, -4 };
|
97
|
-
Command* commands
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
78
|
+
Command* commands;
|
79
|
+
Hashers* hashers;
|
80
|
+
int use_utf8_mode;
|
81
|
+
uint8_t prev_byte;
|
82
|
+
uint8_t prev_byte2;
|
83
|
+
const uint32_t mask = BROTLI_UINT32_MAX >> 1;
|
84
|
+
|
85
|
+
/* Copy prefix + next input block into a continuous area. */
|
86
|
+
uint32_t input_pos = prefix_size;
|
87
|
+
/* CreateBackwardReferences reads up to 3 bytes past the end of input if the
|
88
|
+
mask points past the end of input.
|
89
|
+
FindMatchLengthWithLimit could do another 8 bytes look-forward. */
|
90
|
+
uint8_t* input = BROTLI_ALLOC(m, uint8_t, prefix_size + input_size + 4 + 8);
|
91
|
+
if (BROTLI_IS_OOM(m)) goto oom;
|
92
|
+
memcpy(input, prefix_buffer, prefix_size);
|
93
|
+
memcpy(input + input_pos, input_buffer, input_size);
|
94
|
+
/* Since we don't have a ringbuffer, masking is a no-op.
|
95
|
+
We use one less bit than the full range because some of the code uses
|
96
|
+
mask + 1 as the size of the ringbuffer. */
|
97
|
+
|
98
|
+
prev_byte = input_pos > 0 ? input[(input_pos - 1) & mask] : 0;
|
99
|
+
prev_byte2 = input_pos > 1 ? input[(input_pos - 2) & mask] : 0;
|
100
|
+
|
101
|
+
/* Decide about UTF8 mode. */
|
102
|
+
static const double kMinUTF8Ratio = 0.75;
|
103
|
+
use_utf8_mode = BrotliIsMostlyUTF8(
|
104
|
+
input, input_pos, mask, input_size, kMinUTF8Ratio);
|
105
|
+
|
106
|
+
/* Initialize hashers. */
|
107
|
+
hashers = BROTLI_ALLOC(m, Hashers, 1);
|
108
|
+
if (BROTLI_IS_OOM(m)) goto oom;
|
109
|
+
InitHashers(hashers);
|
110
|
+
HashersSetup(m, hashers, ChooseHasher(params));
|
111
|
+
if (BROTLI_IS_OOM(m)) goto oom;
|
112
|
+
|
113
|
+
/* Compute backward references. */
|
114
|
+
commands = BROTLI_ALLOC(m, Command, ((input_size + 1) >> 1));
|
115
|
+
if (BROTLI_IS_OOM(m)) goto oom;
|
116
|
+
BrotliCreateBackwardReferences(m, input_size, input_pos,
|
117
|
+
TO_BROTLI_BOOL(is_last), input, mask, params,
|
118
|
+
hashers, dist_cache, &last_insert_len, commands, &num_commands,
|
114
119
|
&num_literals);
|
115
|
-
|
120
|
+
if (BROTLI_IS_OOM(m)) goto oom;
|
121
|
+
DestroyHashers(m, hashers);
|
122
|
+
BROTLI_FREE(m, hashers);
|
116
123
|
if (last_insert_len > 0) {
|
117
|
-
commands[num_commands++]
|
124
|
+
InitInsertCommand(&commands[num_commands++], last_insert_len);
|
118
125
|
num_literals += last_insert_len;
|
119
126
|
}
|
120
127
|
assert(num_commands != 0);
|
121
128
|
|
122
|
-
|
129
|
+
/* Build the meta-block. */
|
123
130
|
MetaBlockSplit mb;
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
ContextType literal_context_mode = utf8_mode ? CONTEXT_UTF8 : CONTEXT_SIGNED;
|
131
|
+
InitMetaBlockSplit(&mb);
|
132
|
+
num_direct_distance_codes = params->mode == BROTLI_MODE_FONT ? 12 : 0;
|
133
|
+
distance_postfix_bits = params->mode == BROTLI_MODE_FONT ? 1 : 0;
|
134
|
+
literal_context_mode = use_utf8_mode ? CONTEXT_UTF8 : CONTEXT_SIGNED;
|
129
135
|
RecomputeDistancePrefixes(commands, num_commands,
|
130
136
|
num_direct_distance_codes,
|
131
137
|
distance_postfix_bits);
|
132
|
-
if (params
|
133
|
-
|
138
|
+
if (params->quality < MIN_QUALITY_FOR_HQ_BLOCK_SPLITTING) {
|
139
|
+
BrotliBuildMetaBlockGreedy(m, input, input_pos, mask,
|
140
|
+
commands, num_commands,
|
141
|
+
&mb);
|
142
|
+
if (BROTLI_IS_OOM(m)) goto oom;
|
143
|
+
} else {
|
144
|
+
BrotliBuildMetaBlock(m, input, input_pos, mask, params,
|
145
|
+
prev_byte, prev_byte2,
|
134
146
|
commands, num_commands,
|
147
|
+
literal_context_mode,
|
135
148
|
&mb);
|
136
|
-
|
137
|
-
BuildMetaBlock(&input[0], input_pos, mask,
|
138
|
-
prev_byte, prev_byte2,
|
139
|
-
commands, num_commands,
|
140
|
-
literal_context_mode,
|
141
|
-
&mb);
|
149
|
+
if (BROTLI_IS_OOM(m)) goto oom;
|
142
150
|
}
|
143
151
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
152
|
+
/* Set up the temporary output storage. */
|
153
|
+
storage = BROTLI_ALLOC(m, uint8_t, 2 * input_size + 500);
|
154
|
+
if (BROTLI_IS_OOM(m)) goto oom;
|
155
|
+
first_byte = 0;
|
156
|
+
first_byte_bits = 0;
|
149
157
|
if (is_first) {
|
150
|
-
if (params
|
158
|
+
if (params->lgwin == 16) {
|
151
159
|
first_byte = 0;
|
152
160
|
first_byte_bits = 1;
|
153
|
-
} else if (params
|
161
|
+
} else if (params->lgwin == 17) {
|
154
162
|
first_byte = 1;
|
155
163
|
first_byte_bits = 7;
|
156
164
|
} else {
|
157
|
-
first_byte = static_cast<uint8_t>(((params
|
165
|
+
first_byte = static_cast<uint8_t>(((params->lgwin - 17) << 1) | 1);
|
158
166
|
first_byte_bits = 4;
|
159
167
|
}
|
160
168
|
}
|
161
169
|
storage[0] = static_cast<uint8_t>(first_byte);
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
170
|
+
storage_ix = first_byte_bits;
|
171
|
+
|
172
|
+
/* Store the meta-block to the temporary output. */
|
173
|
+
BrotliStoreMetaBlock(m, input, input_pos, input_size, mask,
|
174
|
+
prev_byte, prev_byte2,
|
175
|
+
TO_BROTLI_BOOL(is_last),
|
176
|
+
num_direct_distance_codes,
|
177
|
+
distance_postfix_bits,
|
178
|
+
literal_context_mode,
|
179
|
+
commands, num_commands,
|
180
|
+
&mb,
|
181
|
+
&storage_ix, storage);
|
182
|
+
if (BROTLI_IS_OOM(m)) goto oom;
|
183
|
+
DestroyMetaBlockSplit(m, &mb);
|
184
|
+
BROTLI_FREE(m, commands);
|
185
|
+
|
186
|
+
/* If this is not the last meta-block, store an empty metadata
|
187
|
+
meta-block so that the meta-block will end at a byte boundary. */
|
178
188
|
if (!is_last) {
|
179
|
-
|
189
|
+
BrotliStoreSyncMetaBlock(&storage_ix, storage);
|
180
190
|
}
|
181
191
|
|
182
|
-
|
183
|
-
|
184
|
-
|
192
|
+
/* If the compressed data is too large, fall back to an uncompressed
|
193
|
+
meta-block. */
|
194
|
+
output_size = storage_ix >> 3;
|
185
195
|
if (input_size + 4 < output_size) {
|
186
196
|
storage[0] = static_cast<uint8_t>(first_byte);
|
187
197
|
storage_ix = first_byte_bits;
|
188
|
-
|
189
|
-
|
190
|
-
|
198
|
+
BrotliStoreUncompressedMetaBlock(
|
199
|
+
TO_BROTLI_BOOL(is_last), input, input_pos, mask, input_size,
|
200
|
+
&storage_ix, storage);
|
191
201
|
output_size = storage_ix >> 3;
|
192
202
|
}
|
193
203
|
|
194
|
-
|
204
|
+
/* Copy the temporary output with size-check to the output. */
|
195
205
|
if (output_size > *encoded_size) {
|
196
|
-
|
206
|
+
BROTLI_FREE(m, storage);
|
207
|
+
BROTLI_FREE(m, input);
|
208
|
+
return 0;
|
197
209
|
}
|
198
|
-
memcpy(encoded_buffer,
|
210
|
+
memcpy(encoded_buffer, storage, output_size);
|
199
211
|
*encoded_size = output_size;
|
200
|
-
|
212
|
+
BROTLI_FREE(m, storage);
|
213
|
+
BROTLI_FREE(m, input);
|
214
|
+
return 1;
|
215
|
+
|
216
|
+
oom:
|
217
|
+
BrotliWipeOutMemoryManager(m);
|
218
|
+
return 0;
|
201
219
|
}
|
202
220
|
|
203
|
-
}
|
221
|
+
} /* namespace */
|
204
222
|
|
205
|
-
int BrotliCompressBufferParallel(BrotliParams
|
223
|
+
int BrotliCompressBufferParallel(BrotliParams compressor_params,
|
206
224
|
size_t input_size,
|
207
225
|
const uint8_t* input_buffer,
|
208
226
|
size_t* encoded_size,
|
209
227
|
uint8_t* encoded_buffer) {
|
210
228
|
if (*encoded_size == 0) {
|
211
|
-
|
229
|
+
/* Output buffer needs at least one byte. */
|
212
230
|
return 0;
|
213
|
-
} else
|
231
|
+
} else if (input_size == 0) {
|
214
232
|
encoded_buffer[0] = 6;
|
215
233
|
*encoded_size = 1;
|
216
234
|
return 1;
|
217
235
|
}
|
218
236
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
if (params.quality >= 9 && params.lgwin > params.lgblock) {
|
228
|
-
params.lgblock = std::min(21, params.lgwin);
|
229
|
-
}
|
230
|
-
} else if (params.lgblock < kMinInputBlockBits) {
|
231
|
-
params.lgblock = kMinInputBlockBits;
|
232
|
-
} else if (params.lgblock > kMaxInputBlockBits) {
|
233
|
-
params.lgblock = kMaxInputBlockBits;
|
234
|
-
}
|
237
|
+
BrotliEncoderParams params;
|
238
|
+
params.mode = (BrotliEncoderMode)compressor_params.mode;
|
239
|
+
params.quality = compressor_params.quality;
|
240
|
+
params.lgwin = compressor_params.lgwin;
|
241
|
+
params.lgblock = compressor_params.lgblock;
|
242
|
+
|
243
|
+
SanitizeParams(¶ms);
|
244
|
+
params.lgblock = ComputeLgBlock(¶ms);
|
235
245
|
size_t max_input_block_size = 1 << params.lgblock;
|
236
246
|
size_t max_prefix_size = 1u << params.lgwin;
|
237
247
|
|
238
248
|
std::vector<std::vector<uint8_t> > compressed_pieces;
|
239
249
|
|
240
|
-
|
250
|
+
/* Compress block-by-block independently. */
|
241
251
|
for (size_t pos = 0; pos < input_size; ) {
|
242
|
-
uint32_t input_block_size =
|
243
|
-
|
252
|
+
uint32_t input_block_size = static_cast<uint32_t>(
|
253
|
+
BROTLI_MIN(size_t, max_input_block_size, input_size - pos));
|
244
254
|
uint32_t prefix_size =
|
245
|
-
static_cast<uint32_t>(
|
255
|
+
static_cast<uint32_t>(BROTLI_MIN(size_t, max_prefix_size, pos));
|
246
256
|
size_t out_size = input_block_size + (input_block_size >> 3) + 1024;
|
247
257
|
std::vector<uint8_t> out(out_size);
|
248
|
-
if (!WriteMetaBlockParallel(params,
|
258
|
+
if (!WriteMetaBlockParallel(¶ms,
|
249
259
|
input_block_size,
|
250
260
|
&input_buffer[pos],
|
251
261
|
prefix_size,
|
252
262
|
&input_buffer[pos - prefix_size],
|
253
|
-
pos == 0,
|
254
|
-
pos + input_block_size == input_size,
|
263
|
+
(pos == 0) ? 1 : 0,
|
264
|
+
(pos + input_block_size == input_size) ? 1 : 0,
|
255
265
|
&out_size,
|
256
266
|
&out[0])) {
|
257
|
-
return
|
267
|
+
return 0;
|
258
268
|
}
|
259
269
|
out.resize(out_size);
|
260
270
|
compressed_pieces.push_back(out);
|
261
271
|
pos += input_block_size;
|
262
272
|
}
|
263
273
|
|
264
|
-
|
274
|
+
/* Piece together the output. */
|
265
275
|
size_t out_pos = 0;
|
266
276
|
for (size_t i = 0; i < compressed_pieces.size(); ++i) {
|
267
277
|
const std::vector<uint8_t>& out = compressed_pieces[i];
|
268
278
|
if (out_pos + out.size() > *encoded_size) {
|
269
|
-
return
|
279
|
+
return 0;
|
270
280
|
}
|
271
281
|
memcpy(&encoded_buffer[out_pos], &out[0], out.size());
|
272
282
|
out_pos += out.size();
|
273
283
|
}
|
274
284
|
*encoded_size = out_pos;
|
275
285
|
|
276
|
-
return
|
286
|
+
return 1;
|
277
287
|
}
|
278
288
|
|
279
|
-
}
|
289
|
+
} /* namespace brotli */
|
@@ -4,16 +4,15 @@
|
|
4
4
|
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
|
5
5
|
*/
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
/* API for parallel Brotli compression
|
8
|
+
Note that this is only a proof of concept currently and not part of the
|
9
|
+
final API yet. */
|
10
10
|
|
11
11
|
#ifndef BROTLI_ENC_ENCODE_PARALLEL_H_
|
12
12
|
#define BROTLI_ENC_ENCODE_PARALLEL_H_
|
13
13
|
|
14
|
-
|
15
|
-
#include "./
|
16
|
-
#include "./types.h"
|
14
|
+
#include "../common/types.h"
|
15
|
+
#include "./compressor.h"
|
17
16
|
|
18
17
|
namespace brotli {
|
19
18
|
|
@@ -23,6 +22,6 @@ int BrotliCompressBufferParallel(BrotliParams params,
|
|
23
22
|
size_t* encoded_size,
|
24
23
|
uint8_t* encoded_buffer);
|
25
24
|
|
26
|
-
}
|
25
|
+
} /* namespace brotli */
|
27
26
|
|
28
|
-
#endif
|
27
|
+
#endif /* BROTLI_ENC_ENCODE_PARALLEL_H_ */
|