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