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_
|
|
|
|
|
2022-11-17 13:03:09 +00:00
|
|
|
#include <brotli/types.h>
|
|
|
|
|
2018-02-26 14:04:36 +00:00
|
|
|
#include "../common/context.h"
|
2017-12-12 13:33:12 +00:00
|
|
|
#include "../common/platform.h"
|
2021-09-08 07:18:45 +00:00
|
|
|
#include "block_splitter.h"
|
|
|
|
#include "command.h"
|
|
|
|
#include "histogram.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "quality.h"
|
2015-03-27 13:20:35 +00:00
|
|
|
|
2016-06-13 09:01:04 +00:00
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2015-03-27 13:20:35 +00:00
|
|
|
|
2024-03-13 09:47:07 +00:00
|
|
|
#define BROTLI_MAX_STATIC_CONTEXTS 13
|
|
|
|
|
2016-06-13 09:01:04 +00:00
|
|
|
typedef struct MetaBlockSplit {
|
2015-03-27 13:20:35 +00:00
|
|
|
BlockSplit literal_split;
|
|
|
|
BlockSplit command_split;
|
|
|
|
BlockSplit distance_split;
|
2016-06-13 09:01:04 +00:00
|
|
|
uint32_t* literal_context_map;
|
|
|
|
size_t literal_context_map_size;
|
|
|
|
uint32_t* distance_context_map;
|
|
|
|
size_t distance_context_map_size;
|
|
|
|
HistogramLiteral* literal_histograms;
|
|
|
|
size_t literal_histograms_size;
|
|
|
|
HistogramCommand* command_histograms;
|
|
|
|
size_t command_histograms_size;
|
|
|
|
HistogramDistance* distance_histograms;
|
|
|
|
size_t distance_histograms_size;
|
|
|
|
} MetaBlockSplit;
|
|
|
|
|
|
|
|
static BROTLI_INLINE void InitMetaBlockSplit(MetaBlockSplit* mb) {
|
|
|
|
BrotliInitBlockSplit(&mb->literal_split);
|
|
|
|
BrotliInitBlockSplit(&mb->command_split);
|
|
|
|
BrotliInitBlockSplit(&mb->distance_split);
|
|
|
|
mb->literal_context_map = 0;
|
|
|
|
mb->literal_context_map_size = 0;
|
|
|
|
mb->distance_context_map = 0;
|
|
|
|
mb->distance_context_map_size = 0;
|
|
|
|
mb->literal_histograms = 0;
|
|
|
|
mb->literal_histograms_size = 0;
|
|
|
|
mb->command_histograms = 0;
|
|
|
|
mb->command_histograms_size = 0;
|
|
|
|
mb->distance_histograms = 0;
|
|
|
|
mb->distance_histograms_size = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BROTLI_INLINE void DestroyMetaBlockSplit(
|
|
|
|
MemoryManager* m, MetaBlockSplit* mb) {
|
|
|
|
BrotliDestroyBlockSplit(m, &mb->literal_split);
|
|
|
|
BrotliDestroyBlockSplit(m, &mb->command_split);
|
|
|
|
BrotliDestroyBlockSplit(m, &mb->distance_split);
|
|
|
|
BROTLI_FREE(m, mb->literal_context_map);
|
|
|
|
BROTLI_FREE(m, mb->distance_context_map);
|
|
|
|
BROTLI_FREE(m, mb->literal_histograms);
|
|
|
|
BROTLI_FREE(m, mb->command_histograms);
|
|
|
|
BROTLI_FREE(m, mb->distance_histograms);
|
|
|
|
}
|
2015-03-27 13:20:35 +00:00
|
|
|
|
2018-03-27 20:29:22 +00:00
|
|
|
/* Uses the slow shortest-path block splitter and does context clustering.
|
|
|
|
The distance parameters are dynamically selected based on the commands
|
|
|
|
which get recomputed under the new distance parameters. The new distance
|
|
|
|
parameters are stored into *params. */
|
2016-06-13 09:01:04 +00:00
|
|
|
BROTLI_INTERNAL void BrotliBuildMetaBlock(MemoryManager* m,
|
|
|
|
const uint8_t* ringbuffer,
|
|
|
|
const size_t pos,
|
|
|
|
const size_t mask,
|
2018-03-27 20:29:22 +00:00
|
|
|
BrotliEncoderParams* params,
|
2016-06-13 09:01:04 +00:00
|
|
|
uint8_t prev_byte,
|
|
|
|
uint8_t prev_byte2,
|
2018-03-27 20:29:22 +00:00
|
|
|
Command* cmds,
|
2016-06-13 09:01:04 +00:00
|
|
|
size_t num_commands,
|
|
|
|
ContextType literal_context_mode,
|
|
|
|
MetaBlockSplit* mb);
|
2015-03-27 13:20:35 +00:00
|
|
|
|
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. */
|
2016-12-22 14:55:05 +00:00
|
|
|
BROTLI_INTERNAL void BrotliBuildMetaBlockGreedy(
|
2016-06-13 09:01:04 +00:00
|
|
|
MemoryManager* m, const uint8_t* ringbuffer, size_t pos, size_t mask,
|
2018-02-26 14:04:36 +00:00
|
|
|
uint8_t prev_byte, uint8_t prev_byte2, ContextLut literal_context_lut,
|
2016-06-13 09:01:04 +00:00
|
|
|
size_t num_contexts, const uint32_t* static_context_map,
|
|
|
|
const Command* commands, size_t n_commands, MetaBlockSplit* mb);
|
2015-05-07 15:23:07 +00:00
|
|
|
|
2018-02-26 14:04:36 +00:00
|
|
|
BROTLI_INTERNAL void BrotliOptimizeHistograms(uint32_t num_distance_codes,
|
2016-06-13 09:01:04 +00:00
|
|
|
MetaBlockSplit* mb);
|
2015-04-23 14:20:29 +00:00
|
|
|
|
2021-07-29 20:29:43 +00:00
|
|
|
BROTLI_INTERNAL void BrotliInitDistanceParams(BrotliDistanceParams* params,
|
|
|
|
uint32_t npostfix, uint32_t ndirect, BROTLI_BOOL large_window);
|
2018-03-27 20:29:22 +00:00
|
|
|
|
2016-06-13 09:01:04 +00:00
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
|
|
|
} /* extern "C" */
|
|
|
|
#endif
|
2015-03-27 13:20:35 +00:00
|
|
|
|
2016-06-03 09:19:23 +00:00
|
|
|
#endif /* BROTLI_ENC_METABLOCK_H_ */
|