]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/C/BrotliCompress/enc/brotli_bit_stream.h
BaseTools: Copy Brotli algorithm 3rd party source code for tool
[mirror_edk2.git] / BaseTools / Source / C / BrotliCompress / enc / brotli_bit_stream.h
1 /* Copyright 2014 Google Inc. All Rights Reserved.
2
3 Distributed under MIT license.
4 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 */
6
7 /* Functions to convert brotli-related data structures into the
8 brotli bit stream. The functions here operate under
9 assumption that there is enough space in the storage, i.e., there are
10 no out-of-range checks anywhere.
11
12 These functions do bit addressing into a byte array. The byte array
13 is called "storage" and the index to the bit is called storage_ix
14 in function arguments. */
15
16 #ifndef BROTLI_ENC_BROTLI_BIT_STREAM_H_
17 #define BROTLI_ENC_BROTLI_BIT_STREAM_H_
18
19 #include "../common/types.h"
20 #include "./command.h"
21 #include "./context.h"
22 #include "./entropy_encode.h"
23 #include "./memory.h"
24 #include "./metablock.h"
25 #include "./port.h"
26
27 #if defined(__cplusplus) || defined(c_plusplus)
28 extern "C" {
29 #endif
30
31 /* All Store functions here will use a storage_ix, which is always the bit
32 position for the current storage. */
33
34 BROTLI_INTERNAL void BrotliStoreHuffmanTree(const uint8_t* depths, size_t num,
35 HuffmanTree* tree, size_t *storage_ix, uint8_t *storage);
36
37 BROTLI_INTERNAL void BrotliBuildAndStoreHuffmanTreeFast(
38 MemoryManager* m, const uint32_t* histogram, const size_t histogram_total,
39 const size_t max_bits, uint8_t* depth, uint16_t* bits, size_t* storage_ix,
40 uint8_t* storage);
41
42 /* REQUIRES: length > 0 */
43 /* REQUIRES: length <= (1 << 24) */
44 BROTLI_INTERNAL void BrotliStoreMetaBlock(MemoryManager* m,
45 const uint8_t* input,
46 size_t start_pos,
47 size_t length,
48 size_t mask,
49 uint8_t prev_byte,
50 uint8_t prev_byte2,
51 BROTLI_BOOL is_final_block,
52 uint32_t num_direct_distance_codes,
53 uint32_t distance_postfix_bits,
54 ContextType literal_context_mode,
55 const Command* commands,
56 size_t n_commands,
57 const MetaBlockSplit* mb,
58 size_t* storage_ix,
59 uint8_t* storage);
60
61 /* Stores the meta-block without doing any block splitting, just collects
62 one histogram per block category and uses that for entropy coding.
63 REQUIRES: length > 0
64 REQUIRES: length <= (1 << 24) */
65 BROTLI_INTERNAL void BrotliStoreMetaBlockTrivial(MemoryManager* m,
66 const uint8_t* input,
67 size_t start_pos,
68 size_t length,
69 size_t mask,
70 BROTLI_BOOL is_last,
71 const Command *commands,
72 size_t n_commands,
73 size_t* storage_ix,
74 uint8_t* storage);
75
76 /* Same as above, but uses static prefix codes for histograms with a only a few
77 symbols, and uses static code length prefix codes for all other histograms.
78 REQUIRES: length > 0
79 REQUIRES: length <= (1 << 24) */
80 BROTLI_INTERNAL void BrotliStoreMetaBlockFast(MemoryManager* m,
81 const uint8_t* input,
82 size_t start_pos,
83 size_t length,
84 size_t mask,
85 BROTLI_BOOL is_last,
86 const Command *commands,
87 size_t n_commands,
88 size_t* storage_ix,
89 uint8_t* storage);
90
91 /* This is for storing uncompressed blocks (simple raw storage of
92 bytes-as-bytes).
93 REQUIRES: length > 0
94 REQUIRES: length <= (1 << 24) */
95 BROTLI_INTERNAL void BrotliStoreUncompressedMetaBlock(
96 BROTLI_BOOL is_final_block, const uint8_t* input, size_t position,
97 size_t mask, size_t len, size_t* storage_ix, uint8_t* storage);
98
99 /* Stores an empty metadata meta-block and syncs to a byte boundary. */
100 BROTLI_INTERNAL void BrotliStoreSyncMetaBlock(size_t* storage_ix,
101 uint8_t* storage);
102
103 #if defined(__cplusplus) || defined(c_plusplus)
104 } /* extern "C" */
105 #endif
106
107 #endif /* BROTLI_ENC_BROTLI_BIT_STREAM_H_ */