Updates to Brotli compression format, decoder and encoder
This commit contains a batch of changes that were made to the Brotli compression algorithm in the last month. Most important changes: * Format change: don't push distances representing static dictionary words to the distance cache. * Fix decoder invalid memory access bug caused by building a non-complete Huffman tree. * Add a mode parameter to the encoder interface. * Use different hashers for text and font mode. * Add a heuristics to the hasher for skipping non-compressible data. * Exhaustive search of static dictionary during backward reference search.
This commit is contained in:
+18
-3
@@ -23,12 +23,23 @@
|
||||
#include <vector>
|
||||
#include "./hash.h"
|
||||
#include "./ringbuffer.h"
|
||||
#include "./static_dict.h"
|
||||
|
||||
namespace brotli {
|
||||
|
||||
struct BrotliParams {
|
||||
enum Mode {
|
||||
MODE_TEXT = 0,
|
||||
MODE_FONT = 1,
|
||||
};
|
||||
Mode mode;
|
||||
|
||||
BrotliParams() : mode(MODE_TEXT) {}
|
||||
};
|
||||
|
||||
class BrotliCompressor {
|
||||
public:
|
||||
BrotliCompressor();
|
||||
explicit BrotliCompressor(BrotliParams params);
|
||||
~BrotliCompressor();
|
||||
|
||||
// Writes the stream header into the internal output buffer.
|
||||
@@ -53,8 +64,10 @@ class BrotliCompressor {
|
||||
// Initializes the hasher with the hashes of dictionary words.
|
||||
void StoreDictionaryWordHashes();
|
||||
|
||||
BrotliParams params_;
|
||||
int window_bits_;
|
||||
Hasher* hasher_;
|
||||
std::unique_ptr<Hashers> hashers_;
|
||||
Hashers::Type hash_type_;
|
||||
int dist_ringbuffer_[4];
|
||||
size_t dist_ringbuffer_idx_;
|
||||
size_t input_pos_;
|
||||
@@ -62,12 +75,14 @@ class BrotliCompressor {
|
||||
std::vector<float> literal_cost_;
|
||||
int storage_ix_;
|
||||
uint8_t* storage_;
|
||||
static StaticDictionary *static_dictionary_;
|
||||
};
|
||||
|
||||
// Compresses the data in input_buffer into encoded_buffer, and sets
|
||||
// *encoded_size to the compressed length.
|
||||
// Returns 0 if there was an error and 1 otherwise.
|
||||
int BrotliCompressBuffer(size_t input_size,
|
||||
int BrotliCompressBuffer(BrotliParams params,
|
||||
size_t input_size,
|
||||
const uint8_t* input_buffer,
|
||||
size_t* encoded_size,
|
||||
uint8_t* encoded_buffer);
|
||||
|
||||
Reference in New Issue
Block a user