brotli 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.travis.yml +11 -3
  4. data/Gemfile +2 -0
  5. data/ext/brotli/brotli.c +279 -0
  6. data/ext/brotli/brotli.h +2 -0
  7. data/ext/brotli/buffer.c +95 -0
  8. data/ext/brotli/buffer.h +19 -0
  9. data/ext/brotli/extconf.rb +21 -81
  10. data/lib/brotli/version.rb +1 -1
  11. data/vendor/brotli/dec/bit_reader.c +5 -5
  12. data/vendor/brotli/dec/bit_reader.h +15 -15
  13. data/vendor/brotli/dec/context.h +1 -1
  14. data/vendor/brotli/dec/decode.c +433 -348
  15. data/vendor/brotli/dec/decode.h +74 -48
  16. data/vendor/brotli/dec/huffman.c +5 -4
  17. data/vendor/brotli/dec/huffman.h +4 -4
  18. data/vendor/brotli/dec/port.h +2 -95
  19. data/vendor/brotli/dec/prefix.h +5 -3
  20. data/vendor/brotli/dec/state.c +15 -27
  21. data/vendor/brotli/dec/state.h +21 -17
  22. data/vendor/brotli/dec/transform.h +1 -1
  23. data/vendor/brotli/enc/backward_references.c +892 -0
  24. data/vendor/brotli/enc/backward_references.h +85 -102
  25. data/vendor/brotli/enc/backward_references_inc.h +147 -0
  26. data/vendor/brotli/enc/bit_cost.c +35 -0
  27. data/vendor/brotli/enc/bit_cost.h +23 -121
  28. data/vendor/brotli/enc/bit_cost_inc.h +127 -0
  29. data/vendor/brotli/enc/block_encoder_inc.h +33 -0
  30. data/vendor/brotli/enc/block_splitter.c +197 -0
  31. data/vendor/brotli/enc/block_splitter.h +40 -50
  32. data/vendor/brotli/enc/block_splitter_inc.h +432 -0
  33. data/vendor/brotli/enc/brotli_bit_stream.c +1334 -0
  34. data/vendor/brotli/enc/brotli_bit_stream.h +95 -167
  35. data/vendor/brotli/enc/cluster.c +56 -0
  36. data/vendor/brotli/enc/cluster.h +23 -305
  37. data/vendor/brotli/enc/cluster_inc.h +315 -0
  38. data/vendor/brotli/enc/command.h +83 -76
  39. data/vendor/brotli/enc/compress_fragment.c +747 -0
  40. data/vendor/brotli/enc/compress_fragment.h +48 -37
  41. data/vendor/brotli/enc/compress_fragment_two_pass.c +557 -0
  42. data/vendor/brotli/enc/compress_fragment_two_pass.h +37 -26
  43. data/vendor/brotli/enc/compressor.cc +139 -0
  44. data/vendor/brotli/enc/compressor.h +146 -0
  45. data/vendor/brotli/enc/context.h +102 -96
  46. data/vendor/brotli/enc/dictionary_hash.h +9 -5
  47. data/vendor/brotli/enc/encode.c +1562 -0
  48. data/vendor/brotli/enc/encode.h +211 -199
  49. data/vendor/brotli/enc/encode_parallel.cc +161 -151
  50. data/vendor/brotli/enc/encode_parallel.h +7 -8
  51. data/vendor/brotli/enc/entropy_encode.c +501 -0
  52. data/vendor/brotli/enc/entropy_encode.h +107 -89
  53. data/vendor/brotli/enc/entropy_encode_static.h +29 -62
  54. data/vendor/brotli/enc/fast_log.h +26 -20
  55. data/vendor/brotli/enc/find_match_length.h +23 -20
  56. data/vendor/brotli/enc/hash.h +614 -871
  57. data/vendor/brotli/enc/hash_forgetful_chain_inc.h +249 -0
  58. data/vendor/brotli/enc/hash_longest_match_inc.h +241 -0
  59. data/vendor/brotli/enc/hash_longest_match_quickly_inc.h +230 -0
  60. data/vendor/brotli/enc/histogram.c +95 -0
  61. data/vendor/brotli/enc/histogram.h +49 -83
  62. data/vendor/brotli/enc/histogram_inc.h +51 -0
  63. data/vendor/brotli/enc/literal_cost.c +178 -0
  64. data/vendor/brotli/enc/literal_cost.h +16 -10
  65. data/vendor/brotli/enc/memory.c +181 -0
  66. data/vendor/brotli/enc/memory.h +62 -0
  67. data/vendor/brotli/enc/metablock.c +515 -0
  68. data/vendor/brotli/enc/metablock.h +87 -57
  69. data/vendor/brotli/enc/metablock_inc.h +183 -0
  70. data/vendor/brotli/enc/port.h +73 -47
  71. data/vendor/brotli/enc/prefix.h +34 -61
  72. data/vendor/brotli/enc/quality.h +130 -0
  73. data/vendor/brotli/enc/ringbuffer.h +137 -122
  74. data/vendor/brotli/enc/{static_dict.cc → static_dict.c} +162 -139
  75. data/vendor/brotli/enc/static_dict.h +23 -18
  76. data/vendor/brotli/enc/static_dict_lut.h +11223 -12037
  77. data/vendor/brotli/enc/streams.cc +7 -7
  78. data/vendor/brotli/enc/streams.h +32 -32
  79. data/vendor/brotli/enc/{utf8_util.cc → utf8_util.c} +22 -20
  80. data/vendor/brotli/enc/utf8_util.h +16 -9
  81. data/vendor/brotli/enc/write_bits.h +49 -43
  82. metadata +34 -25
  83. data/ext/brotli/brotli.cc +0 -181
  84. data/vendor/brotli/dec/Makefile +0 -12
  85. data/vendor/brotli/dec/dictionary.c +0 -9466
  86. data/vendor/brotli/dec/dictionary.h +0 -38
  87. data/vendor/brotli/dec/types.h +0 -38
  88. data/vendor/brotli/enc/Makefile +0 -14
  89. data/vendor/brotli/enc/backward_references.cc +0 -858
  90. data/vendor/brotli/enc/block_splitter.cc +0 -505
  91. data/vendor/brotli/enc/brotli_bit_stream.cc +0 -1181
  92. data/vendor/brotli/enc/compress_fragment.cc +0 -701
  93. data/vendor/brotli/enc/compress_fragment_two_pass.cc +0 -524
  94. data/vendor/brotli/enc/dictionary.cc +0 -9466
  95. data/vendor/brotli/enc/dictionary.h +0 -41
  96. data/vendor/brotli/enc/encode.cc +0 -1180
  97. data/vendor/brotli/enc/entropy_encode.cc +0 -480
  98. data/vendor/brotli/enc/histogram.cc +0 -67
  99. data/vendor/brotli/enc/literal_cost.cc +0 -165
  100. data/vendor/brotli/enc/metablock.cc +0 -539
  101. data/vendor/brotli/enc/transform.h +0 -248
  102. 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
- // 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.
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 <vector>
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 "./types.h"
24
-
25
- namespace brotli {
26
-
27
- // All Store functions here will use a storage_ix, which is always the bit
28
- // position for the current storage.
29
-
30
- // Stores a number between 0 and 255.
31
- void StoreVarLenUint8(size_t n, size_t* storage_ix, uint8_t* storage);
32
-
33
- // Stores the compressed meta-block header.
34
- // REQUIRES: length > 0
35
- // REQUIRES: length <= (1 << 24)
36
- void StoreCompressedMetaBlockHeader(bool final_block,
37
- size_t length,
38
- size_t* storage_ix,
39
- uint8_t* storage);
40
-
41
- // Stores the uncompressed meta-block header.
42
- // REQUIRES: length > 0
43
- // REQUIRES: length <= (1 << 24)
44
- void StoreUncompressedMetaBlockHeader(size_t length,
45
- size_t* storage_ix,
46
- uint8_t* storage);
47
-
48
- // Stores a context map where the histogram type is always the block type.
49
- void StoreTrivialContextMap(size_t num_types,
50
- size_t context_bits,
51
- HuffmanTree* tree,
52
- size_t* storage_ix,
53
- uint8_t* storage);
54
-
55
- void StoreHuffmanTreeOfHuffmanTreeToBitMask(
56
- const int num_codes,
57
- const uint8_t *code_length_bitdepth,
58
- size_t *storage_ix,
59
- uint8_t *storage);
60
-
61
- void StoreHuffmanTree(const uint8_t* depths, size_t num, HuffmanTree* tree,
62
- size_t *storage_ix, uint8_t *storage);
63
-
64
- // Builds a Huffman tree from histogram[0:length] into depth[0:length] and
65
- // bits[0:length] and stores the encoded tree to the bit stream.
66
- void BuildAndStoreHuffmanTree(const uint32_t *histogram,
67
- const size_t length,
68
- HuffmanTree* tree,
69
- uint8_t* depth,
70
- uint16_t* bits,
71
- size_t* storage_ix,
72
- uint8_t* storage);
73
-
74
- void BuildAndStoreHuffmanTreeFast(const uint32_t *histogram,
75
- const size_t histogram_total,
76
- const size_t max_bits,
77
- uint8_t* depth,
78
- uint16_t* bits,
79
- size_t* storage_ix,
80
- uint8_t* storage);
81
-
82
- // Encodes the given context map to the bit stream. The number of different
83
- // histogram ids is given by num_clusters.
84
- void EncodeContextMap(const std::vector<uint32_t>& context_map,
85
- size_t num_clusters,
86
- HuffmanTree* tree,
87
- size_t* storage_ix, uint8_t* storage);
88
-
89
- // Data structure that stores everything that is needed to encode each block
90
- // switch command.
91
- struct BlockSplitCode {
92
- std::vector<uint32_t> type_code;
93
- std::vector<uint32_t> length_prefix;
94
- std::vector<uint32_t> length_nextra;
95
- std::vector<uint32_t> length_extra;
96
- std::vector<uint8_t> type_depths;
97
- std::vector<uint16_t> type_bits;
98
- uint8_t length_depths[kNumBlockLenPrefixes];
99
- uint16_t length_bits[kNumBlockLenPrefixes];
100
- };
101
-
102
- // Builds a BlockSplitCode data structure from the block split given by the
103
- // vector of block types and block lengths and stores it to the bit stream.
104
- void BuildAndStoreBlockSplitCode(const std::vector<uint8_t>& types,
105
- const std::vector<uint32_t>& lengths,
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