2015-11-27 10:27:11 +00:00
|
|
|
/* Copyright 2015 Google Inc. All Rights Reserved.
|
|
|
|
|
2015-12-11 10:11:51 +00:00
|
|
|
Distributed under MIT license.
|
2015-11-27 10:27:11 +00:00
|
|
|
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
|
|
|
|
*/
|
|
|
|
|
2016-06-03 09:19:23 +00:00
|
|
|
/* Algorithms for distributing the literals and commands of a metablock between
|
|
|
|
block types and contexts. */
|
2015-03-27 13:20:35 +00:00
|
|
|
|
|
|
|
#ifndef BROTLI_ENC_METABLOCK_H_
|
|
|
|
#define BROTLI_ENC_METABLOCK_H_
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
2016-06-03 09:19:23 +00:00
|
|
|
#include "../common/types.h"
|
2015-03-27 13:20:35 +00:00
|
|
|
#include "./command.h"
|
|
|
|
#include "./histogram.h"
|
|
|
|
|
|
|
|
namespace brotli {
|
|
|
|
|
|
|
|
struct BlockSplit {
|
2016-02-29 13:41:24 +00:00
|
|
|
BlockSplit(void) : num_types(0) {}
|
2015-03-27 13:20:35 +00:00
|
|
|
|
2016-01-07 15:27:49 +00:00
|
|
|
size_t num_types;
|
|
|
|
std::vector<uint8_t> types;
|
|
|
|
std::vector<uint32_t> lengths;
|
2015-03-27 13:20:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct MetaBlockSplit {
|
|
|
|
BlockSplit literal_split;
|
|
|
|
BlockSplit command_split;
|
|
|
|
BlockSplit distance_split;
|
2016-01-07 15:27:49 +00:00
|
|
|
std::vector<uint32_t> literal_context_map;
|
|
|
|
std::vector<uint32_t> distance_context_map;
|
2015-03-27 13:20:35 +00:00
|
|
|
std::vector<HistogramLiteral> literal_histograms;
|
|
|
|
std::vector<HistogramCommand> command_histograms;
|
|
|
|
std::vector<HistogramDistance> distance_histograms;
|
|
|
|
};
|
|
|
|
|
2016-06-03 09:19:23 +00:00
|
|
|
/* Uses the slow shortest-path block splitter and does context clustering. */
|
2015-03-27 13:20:35 +00:00
|
|
|
void BuildMetaBlock(const uint8_t* ringbuffer,
|
|
|
|
const size_t pos,
|
|
|
|
const size_t mask,
|
2015-04-23 14:20:29 +00:00
|
|
|
uint8_t prev_byte,
|
|
|
|
uint8_t prev_byte2,
|
2015-04-23 11:15:42 +00:00
|
|
|
const Command* cmds,
|
|
|
|
size_t num_commands,
|
2016-01-07 15:27:49 +00:00
|
|
|
ContextType literal_context_mode,
|
2015-03-27 13:20:35 +00:00
|
|
|
MetaBlockSplit* mb);
|
|
|
|
|
2016-06-03 09:19:23 +00:00
|
|
|
/* Uses a fast greedy block splitter that tries to merge current block with the
|
|
|
|
last or the second last block and does not do any context modeling. */
|
2015-03-27 13:20:35 +00:00
|
|
|
void BuildMetaBlockGreedy(const uint8_t* ringbuffer,
|
|
|
|
size_t pos,
|
|
|
|
size_t mask,
|
|
|
|
const Command *commands,
|
|
|
|
size_t n_commands,
|
|
|
|
MetaBlockSplit* mb);
|
|
|
|
|
2016-06-03 09:19:23 +00:00
|
|
|
/* Uses a fast greedy block splitter that tries to merge current block with the
|
|
|
|
last or the second last block and uses a static context clustering which
|
|
|
|
is the same for all block types. */
|
2015-05-07 15:23:07 +00:00
|
|
|
void BuildMetaBlockGreedyWithContexts(const uint8_t* ringbuffer,
|
|
|
|
size_t pos,
|
|
|
|
size_t mask,
|
|
|
|
uint8_t prev_byte,
|
|
|
|
uint8_t prev_byte2,
|
2016-01-07 15:27:49 +00:00
|
|
|
ContextType literal_context_mode,
|
|
|
|
size_t num_contexts,
|
|
|
|
const uint32_t* static_context_map,
|
2015-05-07 15:23:07 +00:00
|
|
|
const Command *commands,
|
|
|
|
size_t n_commands,
|
|
|
|
MetaBlockSplit* mb);
|
|
|
|
|
2016-01-07 15:27:49 +00:00
|
|
|
void OptimizeHistograms(size_t num_direct_distance_codes,
|
|
|
|
size_t distance_postfix_bits,
|
2015-04-23 14:20:29 +00:00
|
|
|
MetaBlockSplit* mb);
|
|
|
|
|
2015-03-27 13:20:35 +00:00
|
|
|
} // namespace brotli
|
|
|
|
|
2016-06-03 09:19:23 +00:00
|
|
|
#endif /* BROTLI_ENC_METABLOCK_H_ */
|