1 /* Copyright 2015 Google Inc. All Rights Reserved.
3 Distributed under MIT license.
4 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
7 /* Algorithms for distributing the literals and commands of a metablock between
8 block types and contexts. */
10 #ifndef BROTLI_ENC_METABLOCK_H_
11 #define BROTLI_ENC_METABLOCK_H_
13 #include "../common/types.h"
14 #include "./block_splitter.h"
15 #include "./command.h"
16 #include "./context.h"
17 #include "./histogram.h"
20 #include "./quality.h"
22 #if defined(__cplusplus) || defined(c_plusplus)
26 typedef struct MetaBlockSplit
{
27 BlockSplit literal_split
;
28 BlockSplit command_split
;
29 BlockSplit distance_split
;
30 uint32_t* literal_context_map
;
31 size_t literal_context_map_size
;
32 uint32_t* distance_context_map
;
33 size_t distance_context_map_size
;
34 HistogramLiteral
* literal_histograms
;
35 size_t literal_histograms_size
;
36 HistogramCommand
* command_histograms
;
37 size_t command_histograms_size
;
38 HistogramDistance
* distance_histograms
;
39 size_t distance_histograms_size
;
42 static BROTLI_INLINE
void InitMetaBlockSplit(MetaBlockSplit
* mb
) {
43 BrotliInitBlockSplit(&mb
->literal_split
);
44 BrotliInitBlockSplit(&mb
->command_split
);
45 BrotliInitBlockSplit(&mb
->distance_split
);
46 mb
->literal_context_map
= 0;
47 mb
->literal_context_map_size
= 0;
48 mb
->distance_context_map
= 0;
49 mb
->distance_context_map_size
= 0;
50 mb
->literal_histograms
= 0;
51 mb
->literal_histograms_size
= 0;
52 mb
->command_histograms
= 0;
53 mb
->command_histograms_size
= 0;
54 mb
->distance_histograms
= 0;
55 mb
->distance_histograms_size
= 0;
58 static BROTLI_INLINE
void DestroyMetaBlockSplit(
59 MemoryManager
* m
, MetaBlockSplit
* mb
) {
60 BrotliDestroyBlockSplit(m
, &mb
->literal_split
);
61 BrotliDestroyBlockSplit(m
, &mb
->command_split
);
62 BrotliDestroyBlockSplit(m
, &mb
->distance_split
);
63 BROTLI_FREE(m
, mb
->literal_context_map
);
64 BROTLI_FREE(m
, mb
->distance_context_map
);
65 BROTLI_FREE(m
, mb
->literal_histograms
);
66 BROTLI_FREE(m
, mb
->command_histograms
);
67 BROTLI_FREE(m
, mb
->distance_histograms
);
70 /* Uses the slow shortest-path block splitter and does context clustering. */
71 BROTLI_INTERNAL
void BrotliBuildMetaBlock(MemoryManager
* m
,
72 const uint8_t* ringbuffer
,
75 const BrotliEncoderParams
* params
,
80 ContextType literal_context_mode
,
83 /* Uses a fast greedy block splitter that tries to merge current block with the
84 last or the second last block and does not do any context modeling. */
85 BROTLI_INTERNAL
void BrotliBuildMetaBlockGreedy(MemoryManager
* m
,
86 const uint8_t* ringbuffer
,
89 const Command
* commands
,
93 /* Uses a fast greedy block splitter that tries to merge current block with the
94 last or the second last block and uses a static context clustering which
95 is the same for all block types. */
96 BROTLI_INTERNAL
void BrotliBuildMetaBlockGreedyWithContexts(
97 MemoryManager
* m
, const uint8_t* ringbuffer
, size_t pos
, size_t mask
,
98 uint8_t prev_byte
, uint8_t prev_byte2
, ContextType literal_context_mode
,
99 size_t num_contexts
, const uint32_t* static_context_map
,
100 const Command
* commands
, size_t n_commands
, MetaBlockSplit
* mb
);
102 BROTLI_INTERNAL
void BrotliOptimizeHistograms(size_t num_direct_distance_codes
,
103 size_t distance_postfix_bits
,
106 #if defined(__cplusplus) || defined(c_plusplus)
110 #endif /* BROTLI_ENC_METABLOCK_H_ */