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