#include "brotli_bit_stream.h"
#include <string.h>
#include "../common/constants.h"
#include "../common/context.h"
#include "../common/platform.h"
#include <brotli/types.h>
#include "entropy_encode.h"
#include "entropy_encode_static.h"
#include "fast_log.h"
#include "histogram.h"
#include "memory.h"
#include "write_bits.h"
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif
#define MAX_HUFFMAN_TREE_SIZE …
#define MAX_SIMPLE_DISTANCE_ALPHABET_SIZE …
static BROTLI_INLINE uint32_t BlockLengthPrefixCode(uint32_t len) { … }
static BROTLI_INLINE void GetBlockLengthPrefixCode(uint32_t len, size_t* code,
uint32_t* n_extra, uint32_t* extra) { … }
BlockTypeCodeCalculator;
static void InitBlockTypeCodeCalculator(BlockTypeCodeCalculator* self) { … }
static BROTLI_INLINE size_t NextBlockTypeCode(
BlockTypeCodeCalculator* calculator, uint8_t type) { … }
static void BrotliEncodeMlen(size_t length, uint64_t* bits,
size_t* numbits, uint64_t* nibblesbits) { … }
static BROTLI_INLINE void StoreCommandExtra(
const Command* cmd, size_t* storage_ix, uint8_t* storage) { … }
BlockSplitCode;
static void StoreVarLenUint8(size_t n, size_t* storage_ix, uint8_t* storage) { … }
static void StoreCompressedMetaBlockHeader(BROTLI_BOOL is_final_block,
size_t length,
size_t* storage_ix,
uint8_t* storage) { … }
static void BrotliStoreUncompressedMetaBlockHeader(size_t length,
size_t* storage_ix,
uint8_t* storage) { … }
static void BrotliStoreHuffmanTreeOfHuffmanTreeToBitMask(
const int num_codes, const uint8_t* code_length_bitdepth,
size_t* storage_ix, uint8_t* storage) { … }
static void BrotliStoreHuffmanTreeToBitMask(
const size_t huffman_tree_size, const uint8_t* huffman_tree,
const uint8_t* huffman_tree_extra_bits, const uint8_t* code_length_bitdepth,
const uint16_t* code_length_bitdepth_symbols,
size_t* BROTLI_RESTRICT storage_ix, uint8_t* BROTLI_RESTRICT storage) { … }
static void StoreSimpleHuffmanTree(const uint8_t* depths,
size_t symbols[4],
size_t num_symbols,
size_t max_bits,
size_t* storage_ix, uint8_t* storage) { … }
void BrotliStoreHuffmanTree(const uint8_t* depths, size_t num,
HuffmanTree* tree,
size_t* storage_ix, uint8_t* storage) { … }
static void BuildAndStoreHuffmanTree(const uint32_t* histogram,
const size_t histogram_length,
const size_t alphabet_size,
HuffmanTree* tree,
uint8_t* depth,
uint16_t* bits,
size_t* storage_ix,
uint8_t* storage) { … }
static BROTLI_INLINE BROTLI_BOOL SortHuffmanTree(
const HuffmanTree* v0, const HuffmanTree* v1) { … }
void BrotliBuildAndStoreHuffmanTreeFast(HuffmanTree* tree,
const uint32_t* histogram,
const size_t histogram_total,
const size_t max_bits,
uint8_t* depth, uint16_t* bits,
size_t* storage_ix,
uint8_t* storage) { … }
static size_t IndexOf(const uint8_t* v, size_t v_size, uint8_t value) { … }
static void MoveToFront(uint8_t* v, size_t index) { … }
static void MoveToFrontTransform(const uint32_t* BROTLI_RESTRICT v_in,
const size_t v_size,
uint32_t* v_out) { … }
static void RunLengthCodeZeros(const size_t in_size,
uint32_t* BROTLI_RESTRICT v, size_t* BROTLI_RESTRICT out_size,
uint32_t* BROTLI_RESTRICT max_run_length_prefix) { … }
#define SYMBOL_BITS …
EncodeContextMapArena;
static void EncodeContextMap(MemoryManager* m,
EncodeContextMapArena* arena,
const uint32_t* context_map,
size_t context_map_size,
size_t num_clusters,
HuffmanTree* tree,
size_t* storage_ix, uint8_t* storage) { … }
static BROTLI_INLINE void StoreBlockSwitch(BlockSplitCode* code,
const uint32_t block_len,
const uint8_t block_type,
BROTLI_BOOL is_first_block,
size_t* storage_ix,
uint8_t* storage) { … }
static void BuildAndStoreBlockSplitCode(const uint8_t* types,
const uint32_t* lengths,
const size_t num_blocks,
const size_t num_types,
HuffmanTree* tree,
BlockSplitCode* code,
size_t* storage_ix,
uint8_t* storage) { … }
static void StoreTrivialContextMap(EncodeContextMapArena* arena,
size_t num_types,
size_t context_bits,
HuffmanTree* tree,
size_t* storage_ix,
uint8_t* storage) { … }
BlockEncoder;
static void InitBlockEncoder(BlockEncoder* self, size_t histogram_length,
size_t num_block_types, const uint8_t* block_types,
const uint32_t* block_lengths, const size_t num_blocks) { … }
static void CleanupBlockEncoder(MemoryManager* m, BlockEncoder* self) { … }
static void BuildAndStoreBlockSwitchEntropyCodes(BlockEncoder* self,
HuffmanTree* tree, size_t* storage_ix, uint8_t* storage) { … }
static void StoreSymbol(BlockEncoder* self, size_t symbol, size_t* storage_ix,
uint8_t* storage) { … }
static void StoreSymbolWithContext(BlockEncoder* self, size_t symbol,
size_t context, const uint32_t* context_map, size_t* storage_ix,
uint8_t* storage, const size_t context_bits) { … }
#define FN …
#include "block_encoder_inc.h"
#undef FN
#define FN …
#include "block_encoder_inc.h"
#undef FN
#define FN …
#include "block_encoder_inc.h"
#undef FN
static void JumpToByteBoundary(size_t* storage_ix, uint8_t* storage) { … }
StoreMetablockArena;
void BrotliStoreMetaBlock(MemoryManager* m,
const uint8_t* input, size_t start_pos, size_t length, size_t mask,
uint8_t prev_byte, uint8_t prev_byte2, BROTLI_BOOL is_last,
const BrotliEncoderParams* params, ContextType literal_context_mode,
const Command* commands, size_t n_commands, const MetaBlockSplit* mb,
size_t* storage_ix, uint8_t* storage) { … }
static void BuildHistograms(const uint8_t* input,
size_t start_pos,
size_t mask,
const Command* commands,
size_t n_commands,
HistogramLiteral* lit_histo,
HistogramCommand* cmd_histo,
HistogramDistance* dist_histo) { … }
static void StoreDataWithHuffmanCodes(const uint8_t* input,
size_t start_pos,
size_t mask,
const Command* commands,
size_t n_commands,
const uint8_t* lit_depth,
const uint16_t* lit_bits,
const uint8_t* cmd_depth,
const uint16_t* cmd_bits,
const uint8_t* dist_depth,
const uint16_t* dist_bits,
size_t* storage_ix,
uint8_t* storage) { … }
MetablockArena;
void BrotliStoreMetaBlockTrivial(MemoryManager* m,
const uint8_t* input, size_t start_pos, size_t length, size_t mask,
BROTLI_BOOL is_last, const BrotliEncoderParams* params,
const Command* commands, size_t n_commands,
size_t* storage_ix, uint8_t* storage) { … }
void BrotliStoreMetaBlockFast(MemoryManager* m,
const uint8_t* input, size_t start_pos, size_t length, size_t mask,
BROTLI_BOOL is_last, const BrotliEncoderParams* params,
const Command* commands, size_t n_commands,
size_t* storage_ix, uint8_t* storage) { … }
void BrotliStoreUncompressedMetaBlock(BROTLI_BOOL is_final_block,
const uint8_t* BROTLI_RESTRICT input,
size_t position, size_t mask,
size_t len,
size_t* BROTLI_RESTRICT storage_ix,
uint8_t* BROTLI_RESTRICT storage) { … }
#if defined(BROTLI_TEST)
void GetBlockLengthPrefixCodeForTest(uint32_t len, size_t* code,
uint32_t* n_extra, uint32_t* extra) {
GetBlockLengthPrefixCode(len, code, n_extra, extra);
}
#endif
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif