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.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +1 -1
  3. data/.travis.yml +2 -1
  4. data/README.md +1 -1
  5. data/Rakefile +1 -1
  6. data/ext/brotli/brotli.cc +1 -1
  7. data/ext/brotli/extconf.rb +72 -14
  8. data/lib/brotli/version.rb +1 -1
  9. data/vendor/brotli/LICENSE +19 -202
  10. data/vendor/brotli/dec/Makefile +1 -1
  11. data/vendor/brotli/dec/bit_reader.c +23 -30
  12. data/vendor/brotli/dec/bit_reader.h +270 -141
  13. data/vendor/brotli/dec/context.h +3 -12
  14. data/vendor/brotli/dec/decode.c +1813 -1048
  15. data/vendor/brotli/dec/decode.h +22 -16
  16. data/vendor/brotli/dec/dictionary.c +9466 -0
  17. data/vendor/brotli/dec/dictionary.h +6 -9461
  18. data/vendor/brotli/dec/huffman.c +104 -71
  19. data/vendor/brotli/dec/huffman.h +19 -28
  20. data/vendor/brotli/dec/port.h +124 -32
  21. data/vendor/brotli/dec/prefix.h +4 -13
  22. data/vendor/brotli/dec/state.c +93 -56
  23. data/vendor/brotli/dec/state.h +124 -53
  24. data/vendor/brotli/dec/streams.c +14 -11
  25. data/vendor/brotli/dec/streams.h +6 -11
  26. data/vendor/brotli/dec/transform.h +2 -11
  27. data/vendor/brotli/dec/types.h +21 -19
  28. data/vendor/brotli/enc/Makefile +4 -1
  29. data/vendor/brotli/enc/backward_references.cc +87 -94
  30. data/vendor/brotli/enc/backward_references.h +8 -18
  31. data/vendor/brotli/enc/bit_cost.h +11 -19
  32. data/vendor/brotli/enc/block_splitter.cc +43 -48
  33. data/vendor/brotli/enc/block_splitter.h +7 -16
  34. data/vendor/brotli/enc/brotli_bit_stream.cc +48 -50
  35. data/vendor/brotli/enc/brotli_bit_stream.h +7 -16
  36. data/vendor/brotli/enc/cluster.h +24 -25
  37. data/vendor/brotli/enc/command.h +34 -41
  38. data/vendor/brotli/enc/context.h +11 -18
  39. data/vendor/brotli/enc/dictionary.cc +9466 -0
  40. data/vendor/brotli/enc/dictionary.h +20 -9464
  41. data/vendor/brotli/enc/dictionary_hash.h +7 -15
  42. data/vendor/brotli/enc/encode.cc +80 -148
  43. data/vendor/brotli/enc/encode.h +19 -29
  44. data/vendor/brotli/enc/encode_parallel.cc +35 -108
  45. data/vendor/brotli/enc/encode_parallel.h +7 -16
  46. data/vendor/brotli/enc/entropy_encode.cc +33 -42
  47. data/vendor/brotli/enc/entropy_encode.h +8 -16
  48. data/vendor/brotli/enc/fast_log.h +8 -15
  49. data/vendor/brotli/enc/find_match_length.h +7 -17
  50. data/vendor/brotli/enc/hash.h +130 -150
  51. data/vendor/brotli/enc/histogram.cc +7 -16
  52. data/vendor/brotli/enc/histogram.h +11 -17
  53. data/vendor/brotli/enc/literal_cost.cc +28 -35
  54. data/vendor/brotli/enc/literal_cost.h +9 -23
  55. data/vendor/brotli/enc/metablock.cc +18 -26
  56. data/vendor/brotli/enc/metablock.h +6 -14
  57. data/vendor/brotli/enc/port.h +14 -14
  58. data/vendor/brotli/enc/prefix.h +11 -18
  59. data/vendor/brotli/enc/ringbuffer.h +18 -27
  60. data/vendor/brotli/enc/static_dict.cc +7 -1
  61. data/vendor/brotli/enc/static_dict.h +7 -15
  62. data/vendor/brotli/enc/static_dict_lut.h +7 -15
  63. data/vendor/brotli/enc/streams.cc +15 -28
  64. data/vendor/brotli/enc/streams.h +27 -35
  65. data/vendor/brotli/enc/transform.h +9 -16
  66. data/vendor/brotli/enc/types.h +27 -0
  67. data/vendor/brotli/enc/utf8_util.cc +82 -0
  68. data/vendor/brotli/enc/utf8_util.h +25 -0
  69. data/vendor/brotli/enc/write_bits.h +11 -18
  70. metadata +7 -2
@@ -1,16 +1,7 @@
1
1
  /* Copyright 2015 Google Inc. All Rights Reserved.
2
2
 
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
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.
3
+ Distributed under MIT license.
4
+ See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
14
5
  */
15
6
 
16
7
  #include "./huffman.h"
@@ -23,10 +14,47 @@
23
14
  extern "C" {
24
15
  #endif
25
16
 
17
+ static void* DefaultAllocFunc(void* opaque, size_t size) {
18
+ BROTLI_UNUSED(opaque);
19
+ return malloc(size);
20
+ }
21
+
22
+ static void DefaultFreeFunc(void* opaque, void* address) {
23
+ BROTLI_UNUSED(opaque);
24
+ free(address);
25
+ }
26
+
26
27
  void BrotliStateInit(BrotliState* s) {
28
+ BrotliStateInitWithCustomAllocators(s, 0, 0, 0);
29
+ }
30
+
31
+ void BrotliStateInitWithCustomAllocators(BrotliState* s,
32
+ brotli_alloc_func alloc_func, brotli_free_func free_func, void* opaque) {
33
+ if (!alloc_func) {
34
+ s->alloc_func = DefaultAllocFunc;
35
+ s->free_func = DefaultFreeFunc;
36
+ s->memory_manager_opaque = 0;
37
+ } else {
38
+ s->alloc_func = alloc_func;
39
+ s->free_func = free_func;
40
+ s->memory_manager_opaque = opaque;
41
+ }
42
+
43
+ BrotliInitBitReader(&s->br);
27
44
  s->state = BROTLI_STATE_UNINITED;
28
- s->sub0_state = BROTLI_STATE_SUB0_NONE;
29
- s->sub1_state = BROTLI_STATE_SUB1_NONE;
45
+ s->substate_metablock_header = BROTLI_STATE_METABLOCK_HEADER_NONE;
46
+ s->substate_tree_group = BROTLI_STATE_TREE_GROUP_NONE;
47
+ s->substate_context_map = BROTLI_STATE_CONTEXT_MAP_NONE;
48
+ s->substate_uncompressed = BROTLI_STATE_UNCOMPRESSED_NONE;
49
+ s->substate_huffman = BROTLI_STATE_HUFFMAN_NONE;
50
+ s->substate_decode_uint8 = BROTLI_STATE_DECODE_UINT8_NONE;
51
+ s->substate_read_block_length = BROTLI_STATE_READ_BLOCK_LENGTH_NONE;
52
+
53
+ s->buffer_length = 0;
54
+ s->loop_counter = 0;
55
+ s->pos = 0;
56
+ s->rb_roundtrips = 0;
57
+ s->partial_pos_out = 0;
30
58
 
31
59
  s->block_type_trees = NULL;
32
60
  s->block_len_trees = NULL;
@@ -38,6 +66,8 @@ void BrotliStateInit(BrotliState* s) {
38
66
  s->context_map_slice = NULL;
39
67
  s->dist_context_map_slice = NULL;
40
68
 
69
+ s->sub_loop_counter = 0;
70
+
41
71
  s->literal_hgroup.codes = NULL;
42
72
  s->literal_hgroup.htrees = NULL;
43
73
  s->insert_copy_hgroup.codes = NULL;
@@ -45,10 +75,11 @@ void BrotliStateInit(BrotliState* s) {
45
75
  s->distance_hgroup.codes = NULL;
46
76
  s->distance_hgroup.htrees = NULL;
47
77
 
78
+
48
79
  s->custom_dict = NULL;
49
80
  s->custom_dict_size = 0;
50
81
 
51
- s->input_end = 0;
82
+ s->is_last_metablock = 0;
52
83
  s->window_bits = 0;
53
84
  s->max_distance = 0;
54
85
  s->dist_rb[0] = 16;
@@ -63,13 +94,20 @@ void BrotliStateInit(BrotliState* s) {
63
94
  s->symbol_lists = &s->symbols_lists_array[BROTLI_HUFFMAN_MAX_CODE_LENGTH + 1];
64
95
 
65
96
  s->mtf_upper_bound = 255;
97
+
98
+ s->legacy_input_buffer = 0;
99
+ s->legacy_output_buffer = 0;
100
+ s->legacy_input_len = 0;
101
+ s->legacy_output_len = 0;
102
+ s->legacy_input_pos = 0;
103
+ s->legacy_output_pos = 0;
66
104
  }
67
105
 
68
106
  void BrotliStateMetablockBegin(BrotliState* s) {
69
107
  s->meta_block_remaining_len = 0;
70
- s->block_length[0] = 1 << 28;
71
- s->block_length[1] = 1 << 28;
72
- s->block_length[2] = 1 << 28;
108
+ s->block_length[0] = 1U << 28;
109
+ s->block_length[1] = 1U << 28;
110
+ s->block_length[2] = 1U << 28;
73
111
  s->num_block_types[0] = 1;
74
112
  s->num_block_types[1] = 1;
75
113
  s->num_block_types[2] = 1;
@@ -98,50 +136,49 @@ void BrotliStateMetablockBegin(BrotliState* s) {
98
136
  }
99
137
 
100
138
  void BrotliStateCleanupAfterMetablock(BrotliState* s) {
101
- if (s->context_modes != 0) {
102
- free(s->context_modes);
103
- s->context_modes = NULL;
104
- }
105
- if (s->context_map != 0) {
106
- free(s->context_map);
107
- s->context_map = NULL;
108
- }
109
- if (s->dist_context_map != 0) {
110
- free(s->dist_context_map);
111
- s->dist_context_map = NULL;
112
- }
139
+ BROTLI_FREE(s, s->context_modes);
140
+ BROTLI_FREE(s, s->context_map);
141
+ BROTLI_FREE(s, s->dist_context_map);
113
142
 
114
- BrotliHuffmanTreeGroupRelease(&s->literal_hgroup);
115
- BrotliHuffmanTreeGroupRelease(&s->insert_copy_hgroup);
116
- BrotliHuffmanTreeGroupRelease(&s->distance_hgroup);
117
- s->literal_hgroup.codes = NULL;
118
- s->literal_hgroup.htrees = NULL;
119
- s->insert_copy_hgroup.codes = NULL;
120
- s->insert_copy_hgroup.htrees = NULL;
121
- s->distance_hgroup.codes = NULL;
122
- s->distance_hgroup.htrees = NULL;
143
+ BrotliHuffmanTreeGroupRelease(s, &s->literal_hgroup);
144
+ BrotliHuffmanTreeGroupRelease(s, &s->insert_copy_hgroup);
145
+ BrotliHuffmanTreeGroupRelease(s, &s->distance_hgroup);
123
146
  }
124
147
 
125
148
  void BrotliStateCleanup(BrotliState* s) {
126
- if (s->context_modes != 0) {
127
- free(s->context_modes);
128
- }
129
- if (s->context_map != 0) {
130
- free(s->context_map);
131
- }
132
- if (s->dist_context_map != 0) {
133
- free(s->dist_context_map);
134
- }
135
- BrotliHuffmanTreeGroupRelease(&s->literal_hgroup);
136
- BrotliHuffmanTreeGroupRelease(&s->insert_copy_hgroup);
137
- BrotliHuffmanTreeGroupRelease(&s->distance_hgroup);
149
+ BrotliStateCleanupAfterMetablock(s);
138
150
 
139
- if (s->ringbuffer != 0) {
140
- free(s->ringbuffer);
141
- }
142
- if (s->block_type_trees != 0) {
143
- free(s->block_type_trees);
144
- }
151
+ BROTLI_FREE(s, s->ringbuffer);
152
+ BROTLI_FREE(s, s->block_type_trees);
153
+ BROTLI_FREE(s, s->legacy_input_buffer);
154
+ BROTLI_FREE(s, s->legacy_output_buffer);
155
+ }
156
+
157
+ int BrotliStateIsStreamStart(const BrotliState* s) {
158
+ return (s->state == BROTLI_STATE_UNINITED &&
159
+ BrotliGetAvailableBits(&s->br) == 0);
160
+ }
161
+
162
+ int BrotliStateIsStreamEnd(const BrotliState* s) {
163
+ return s->state == BROTLI_STATE_DONE;
164
+ }
165
+
166
+ void BrotliHuffmanTreeGroupInit(BrotliState* s, HuffmanTreeGroup* group,
167
+ uint32_t alphabet_size, uint32_t ntrees) {
168
+ /* Pack two allocations into one */
169
+ const size_t code_size =
170
+ sizeof(HuffmanCode) * (size_t)(ntrees * BROTLI_HUFFMAN_MAX_TABLE_SIZE);
171
+ const size_t htree_size = sizeof(HuffmanCode*) * (size_t)ntrees;
172
+ char *p = (char*)BROTLI_ALLOC(s, code_size + htree_size);
173
+ group->alphabet_size = (uint16_t)alphabet_size;
174
+ group->num_htrees = (uint16_t)ntrees;
175
+ group->codes = (HuffmanCode*)p;
176
+ group->htrees = (HuffmanCode**)(p + code_size);
177
+ }
178
+
179
+ void BrotliHuffmanTreeGroupRelease(BrotliState* s, HuffmanTreeGroup* group) {
180
+ BROTLI_FREE(s, group->codes);
181
+ group->htrees = NULL;
145
182
  }
146
183
 
147
184
  #if defined(__cplusplus) || defined(c_plusplus)
@@ -1,16 +1,7 @@
1
1
  /* Copyright 2015 Google Inc. All Rights Reserved.
2
2
 
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
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.
3
+ Distributed under MIT license.
4
+ See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
14
5
  */
15
6
 
16
7
  /* Brotli state for partial streaming decoding. */
@@ -21,7 +12,6 @@
21
12
  #include <stdio.h>
22
13
  #include "./bit_reader.h"
23
14
  #include "./huffman.h"
24
- #include "./streams.h"
25
15
  #include "./types.h"
26
16
 
27
17
  #if defined(__cplusplus) || defined(c_plusplus)
@@ -30,22 +20,24 @@ extern "C" {
30
20
 
31
21
  typedef enum {
32
22
  BROTLI_STATE_UNINITED,
33
- BROTLI_STATE_BITREADER_WARMUP,
34
23
  BROTLI_STATE_METABLOCK_BEGIN,
35
- BROTLI_STATE_METABLOCK_HEADER_1,
24
+ BROTLI_STATE_METABLOCK_HEADER,
36
25
  BROTLI_STATE_METABLOCK_HEADER_2,
26
+ BROTLI_STATE_CONTEXT_MODES,
37
27
  BROTLI_STATE_COMMAND_BEGIN,
38
28
  BROTLI_STATE_COMMAND_INNER,
29
+ BROTLI_STATE_COMMAND_POST_DECODE_LITERALS,
30
+ BROTLI_STATE_COMMAND_POST_WRAP_COPY,
39
31
  BROTLI_STATE_UNCOMPRESSED,
40
32
  BROTLI_STATE_METADATA,
41
33
  BROTLI_STATE_COMMAND_INNER_WRITE,
42
34
  BROTLI_STATE_METABLOCK_DONE,
43
35
  BROTLI_STATE_COMMAND_POST_WRITE_1,
44
36
  BROTLI_STATE_COMMAND_POST_WRITE_2,
45
- BROTLI_STATE_COMMAND_POST_WRAP_COPY,
46
37
  BROTLI_STATE_HUFFMAN_CODE_0,
47
38
  BROTLI_STATE_HUFFMAN_CODE_1,
48
39
  BROTLI_STATE_HUFFMAN_CODE_2,
40
+ BROTLI_STATE_HUFFMAN_CODE_3,
49
41
  BROTLI_STATE_CONTEXT_MAP_1,
50
42
  BROTLI_STATE_CONTEXT_MAP_2,
51
43
  BROTLI_STATE_TREE_GROUP,
@@ -53,28 +45,70 @@ typedef enum {
53
45
  } BrotliRunningState;
54
46
 
55
47
  typedef enum {
56
- BROTLI_STATE_SUB0_NONE,
57
- BROTLI_STATE_SUB0_UNCOMPRESSED_SHORT,
58
- BROTLI_STATE_SUB0_UNCOMPRESSED_FILL,
59
- BROTLI_STATE_SUB0_UNCOMPRESSED_COPY,
60
- BROTLI_STATE_SUB0_UNCOMPRESSED_WARMUP,
61
- BROTLI_STATE_SUB0_UNCOMPRESSED_WRITE_1,
62
- BROTLI_STATE_SUB0_UNCOMPRESSED_WRITE_2,
63
- BROTLI_STATE_SUB0_UNCOMPRESSED_WRITE_3,
64
- BROTLI_STATE_SUB0_TREE_GROUP,
65
- BROTLI_STATE_SUB0_CONTEXT_MAP_HUFFMAN,
66
- BROTLI_STATE_SUB0_CONTEXT_MAPS
67
- } BrotliRunningSub0State;
48
+ BROTLI_STATE_METABLOCK_HEADER_NONE,
49
+ BROTLI_STATE_METABLOCK_HEADER_EMPTY,
50
+ BROTLI_STATE_METABLOCK_HEADER_NIBBLES,
51
+ BROTLI_STATE_METABLOCK_HEADER_SIZE,
52
+ BROTLI_STATE_METABLOCK_HEADER_UNCOMPRESSED,
53
+ BROTLI_STATE_METABLOCK_HEADER_RESERVED,
54
+ BROTLI_STATE_METABLOCK_HEADER_BYTES,
55
+ BROTLI_STATE_METABLOCK_HEADER_METADATA
56
+ } BrotliRunningMetablockHeaderState;
57
+
58
+ typedef enum {
59
+ BROTLI_STATE_UNCOMPRESSED_NONE,
60
+ BROTLI_STATE_UNCOMPRESSED_WRITE
61
+ } BrotliRunningUncompressedState;
62
+
63
+ typedef enum {
64
+ BROTLI_STATE_TREE_GROUP_NONE,
65
+ BROTLI_STATE_TREE_GROUP_LOOP
66
+ } BrotliRunningTreeGroupState;
68
67
 
69
68
  typedef enum {
70
- BROTLI_STATE_SUB1_NONE,
71
- BROTLI_STATE_SUB1_HUFFMAN_LENGTH_SYMBOLS
72
- } BrotliRunningSub1State;
69
+ BROTLI_STATE_CONTEXT_MAP_NONE,
70
+ BROTLI_STATE_CONTEXT_MAP_READ_PREFIX,
71
+ BROTLI_STATE_CONTEXT_MAP_HUFFMAN,
72
+ BROTLI_STATE_CONTEXT_MAP_DECODE,
73
+ BROTLI_STATE_CONTEXT_MAP_TRANSFORM
74
+ } BrotliRunningContextMapState;
73
75
 
74
- typedef struct {
76
+ typedef enum {
77
+ BROTLI_STATE_HUFFMAN_NONE,
78
+ BROTLI_STATE_HUFFMAN_SIMPLE_SIZE,
79
+ BROTLI_STATE_HUFFMAN_SIMPLE_READ,
80
+ BROTLI_STATE_HUFFMAN_SIMPLE_BUILD,
81
+ BROTLI_STATE_HUFFMAN_COMPLEX,
82
+ BROTLI_STATE_HUFFMAN_LENGTH_SYMBOLS
83
+ } BrotliRunningHuffmanState;
84
+
85
+ typedef enum {
86
+ BROTLI_STATE_DECODE_UINT8_NONE,
87
+ BROTLI_STATE_DECODE_UINT8_SHORT,
88
+ BROTLI_STATE_DECODE_UINT8_LONG
89
+ } BrotliRunningDecodeUint8State;
90
+
91
+ typedef enum {
92
+ BROTLI_STATE_READ_BLOCK_LENGTH_NONE,
93
+ BROTLI_STATE_READ_BLOCK_LENGTH_SUFFIX
94
+ } BrotliRunningReadBlockLengthState;
95
+
96
+ struct BrotliStateStruct {
75
97
  BrotliRunningState state;
76
- /* This counter is reused for several disjoint loops. */
77
98
  BrotliBitReader br;
99
+
100
+ brotli_alloc_func alloc_func;
101
+ brotli_free_func free_func;
102
+ void* memory_manager_opaque;
103
+
104
+ /* Temporary storage for remaining input. */
105
+ union {
106
+ uint64_t u64;
107
+ uint8_t u8[8];
108
+ } buffer;
109
+ uint32_t buffer_length;
110
+
111
+ /* This counter is reused for several disjoint loops. */
78
112
  int loop_counter;
79
113
  int pos;
80
114
  int max_backward_distance;
@@ -92,6 +126,8 @@ typedef struct {
92
126
  uint8_t* context_map_slice;
93
127
  uint8_t* dist_context_map_slice;
94
128
 
129
+ uint32_t sub_loop_counter;
130
+
95
131
  /* This ring buffer holds a few past copy distances that will be used by */
96
132
  /* some special distance codes. */
97
133
  HuffmanTreeGroup literal_hgroup;
@@ -104,25 +140,28 @@ typedef struct {
104
140
  int trivial_literal_context;
105
141
  int distance_context;
106
142
  int meta_block_remaining_len;
107
- int block_length[3];
108
- int num_block_types[3];
109
- int block_type_rb[6];
110
- int distance_postfix_bits;
111
- int num_direct_distance_codes;
143
+ uint32_t block_length_index;
144
+ uint32_t block_length[3];
145
+ uint32_t num_block_types[3];
146
+ uint32_t block_type_rb[6];
147
+ uint32_t distance_postfix_bits;
148
+ uint32_t num_direct_distance_codes;
112
149
  int distance_postfix_mask;
150
+ uint32_t num_dist_htrees;
113
151
  uint8_t* dist_context_map;
114
- uint8_t literal_htree_index;
115
152
  HuffmanCode *literal_htree;
153
+ uint8_t literal_htree_index;
116
154
  uint8_t dist_htree_index;
117
- uint8_t repeat_code_len;
118
- uint8_t prev_code_len;
155
+ uint32_t repeat_code_len;
156
+ uint32_t prev_code_len;
157
+
119
158
 
120
159
  int copy_length;
121
160
  int distance_code;
122
161
 
123
162
  /* For partial write operations */
124
- int to_write;
125
- int partially_written;
163
+ size_t rb_roundtrips; /* How many times we went around the ringbuffer */
164
+ size_t partial_pos_out; /* How much output to the user in total (<= rb) */
126
165
 
127
166
  /* For ReadHuffmanCode */
128
167
  uint32_t symbol;
@@ -146,12 +185,13 @@ typedef struct {
146
185
  HuffmanCode* next;
147
186
 
148
187
  /* For DecodeContextMap */
149
- int context_index;
150
- int max_run_length_prefix;
188
+ uint32_t context_index;
189
+ uint32_t max_run_length_prefix;
190
+ uint32_t code;
151
191
  HuffmanCode context_map_table[BROTLI_HUFFMAN_MAX_TABLE_SIZE];
152
192
 
153
193
  /* For InverseMoveToFrontTransform */
154
- int mtf_upper_bound;
194
+ uint32_t mtf_upper_bound;
155
195
  uint8_t mtf[256];
156
196
 
157
197
  /* For custom dictionaries */
@@ -159,24 +199,55 @@ typedef struct {
159
199
  int custom_dict_size;
160
200
 
161
201
  /* less used attributes are in the end of this struct */
162
- BrotliRunningSub0State sub0_state; /* State inside function call */
163
- BrotliRunningSub1State sub1_state; /* State inside function call */
202
+ /* States inside function calls */
203
+ BrotliRunningMetablockHeaderState substate_metablock_header;
204
+ BrotliRunningTreeGroupState substate_tree_group;
205
+ BrotliRunningContextMapState substate_context_map;
206
+ BrotliRunningUncompressedState substate_uncompressed;
207
+ BrotliRunningHuffmanState substate_huffman;
208
+ BrotliRunningDecodeUint8State substate_decode_uint8;
209
+ BrotliRunningReadBlockLengthState substate_read_block_length;
164
210
 
165
- int input_end;
211
+ uint8_t is_last_metablock;
212
+ uint8_t is_uncompressed;
213
+ uint8_t is_metadata;
214
+ uint8_t size_nibbles;
166
215
  uint32_t window_bits;
167
216
 
168
- /* For CopyUncompressedBlockToOutput */
169
- int nbytes;
170
-
171
- int num_literal_htrees;
217
+ uint32_t num_literal_htrees;
172
218
  uint8_t* context_map;
173
219
  uint8_t* context_modes;
174
- } BrotliState;
220
+
221
+ uint8_t* legacy_input_buffer;
222
+ uint8_t* legacy_output_buffer;
223
+ size_t legacy_input_len;
224
+ size_t legacy_output_len;
225
+ size_t legacy_input_pos;
226
+ size_t legacy_output_pos;
227
+ };
228
+
229
+ typedef struct BrotliStateStruct BrotliState;
175
230
 
176
231
  void BrotliStateInit(BrotliState* s);
232
+ void BrotliStateInitWithCustomAllocators(BrotliState* s,
233
+ brotli_alloc_func alloc_func,
234
+ brotli_free_func free_func,
235
+ void* opaque);
177
236
  void BrotliStateCleanup(BrotliState* s);
178
237
  void BrotliStateMetablockBegin(BrotliState* s);
179
238
  void BrotliStateCleanupAfterMetablock(BrotliState* s);
239
+ void BrotliHuffmanTreeGroupInit(BrotliState* s, HuffmanTreeGroup* group,
240
+ uint32_t alphabet_size, uint32_t ntrees);
241
+ void BrotliHuffmanTreeGroupRelease(BrotliState* s, HuffmanTreeGroup* group);
242
+
243
+ /* Returns 1, if s is in a state where we have not read any input bytes yet,
244
+ and 0 otherwise */
245
+ int BrotliStateIsStreamStart(const BrotliState* s);
246
+
247
+ /* Returns 1, if s is in a state where we reached the end of the input and
248
+ produced all of the output, and 0 otherwise. */
249
+ int BrotliStateIsStreamEnd(const BrotliState* s);
250
+
180
251
 
181
252
  #if defined(__cplusplus) || defined(c_plusplus)
182
253
  } /* extern "C" */
@@ -1,16 +1,7 @@
1
1
  /* Copyright 2013 Google Inc. All Rights Reserved.
2
2
 
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
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.
3
+ Distributed under MIT license.
4
+ See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
14
5
  */
15
6
 
16
7
  /* Functions for streaming input and output. */
@@ -93,6 +84,18 @@ BrotliOutput BrotliFileOutput(FILE* f) {
93
84
  return out;
94
85
  }
95
86
 
87
+ int BrotliNullOutputFunction(void* data , const uint8_t* buf, size_t count) {
88
+ BROTLI_UNUSED(data);
89
+ BROTLI_UNUSED(buf);
90
+ return (int)count;
91
+ }
92
+
93
+ BrotliOutput BrotliNullOutput(void) {
94
+ BrotliOutput out;
95
+ out.cb_ = BrotliNullOutputFunction;
96
+ out.data_ = NULL;
97
+ return out;
98
+ }
96
99
 
97
100
  #if defined(__cplusplus) || defined(c_plusplus)
98
101
  } /* extern "C" */
@@ -1,16 +1,7 @@
1
1
  /* Copyright 2013 Google Inc. All Rights Reserved.
2
2
 
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
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.
3
+ Distributed under MIT license.
4
+ See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
14
5
  */
15
6
 
16
7
  /* Functions for streaming input and output. */
@@ -93,6 +84,10 @@ BrotliInput BrotliFileInput(FILE* f);
93
84
  int BrotliFileOutputFunction(void* data, const uint8_t* buf, size_t count);
94
85
  BrotliOutput BrotliFileOutput(FILE* f);
95
86
 
87
+ /* Output callback that does nothing, always consumes the whole input. */
88
+ int BrotliNullOutputFunction(void* data, const uint8_t* buf, size_t count);
89
+ BrotliOutput BrotliNullOutput(void);
90
+
96
91
  #if defined(__cplusplus) || defined(c_plusplus)
97
92
  } /* extern "C" */
98
93
  #endif
@@ -1,16 +1,7 @@
1
1
  /* Copyright 2013 Google Inc. All Rights Reserved.
2
2
 
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
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.
3
+ Distributed under MIT license.
4
+ See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
14
5
  */
15
6
 
16
7
  /* Transformations on dictionary words. */
@@ -1,16 +1,7 @@
1
1
  /* Copyright 2013 Google Inc. All Rights Reserved.
2
2
 
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
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.
3
+ Distributed under MIT license.
4
+ See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
14
5
  */
15
6
 
16
7
  /* Common types */
@@ -21,16 +12,27 @@
21
12
  #include <stddef.h> /* for size_t */
22
13
 
23
14
  #if defined(_MSC_VER) && (_MSC_VER < 1600)
24
- typedef signed char int8_t;
25
- typedef unsigned char uint8_t;
26
- typedef signed short int16_t;
27
- typedef unsigned short uint16_t;
28
- typedef signed int int32_t;
29
- typedef unsigned int uint32_t;
30
- typedef unsigned long long int uint64_t;
31
- typedef long long int int64_t;
15
+ typedef __int8 int8_t;
16
+ typedef unsigned __int8 uint8_t;
17
+ typedef __int16 int16_t;
18
+ typedef unsigned __int16 uint16_t;
19
+ typedef __int32 int32_t;
20
+ typedef unsigned __int32 uint32_t;
21
+ typedef unsigned __int64 uint64_t;
22
+ typedef __int64 int64_t;
32
23
  #else
33
24
  #include <stdint.h>
34
25
  #endif /* defined(_MSC_VER) && (_MSC_VER < 1600) */
35
26
 
27
+ /* Allocating function pointer. Function MUST return 0 in the case of failure.
28
+ Otherwise it MUST return a valid pointer to a memory region of at least
29
+ size length. Neither items nor size are allowed to be 0.
30
+ opaque argument is a pointer provided by client and could be used to bind
31
+ function to specific object (memory pool). */
32
+ typedef void* (*brotli_alloc_func) (void* opaque, size_t size);
33
+
34
+ /* Deallocating function pointer. Function SHOULD be no-op in the case the
35
+ address is 0. */
36
+ typedef void (*brotli_free_func) (void* opaque, void* address);
37
+
36
38
  #endif /* BROTLI_DEC_TYPES_H_ */
@@ -2,7 +2,10 @@
2
2
 
3
3
  include ../shared.mk
4
4
 
5
- OBJS = backward_references.o block_splitter.o brotli_bit_stream.o encode.o encode_parallel.o entropy_encode.o histogram.o literal_cost.o metablock.o static_dict.o streams.o
5
+ OBJS_NODICT = backward_references.o block_splitter.o brotli_bit_stream.o encode.o encode_parallel.o entropy_encode.o histogram.o literal_cost.o metablock.o static_dict.o streams.o utf8_util.o
6
+ OBJS = $(OBJS_NODICT) dictionary.o
7
+
8
+ nodict : $(OBJS_NODICT)
6
9
 
7
10
  all : $(OBJS)
8
11