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/context.h" |
20 | #include "../common/platform.h" |
21 | #include <brotli/types.h> |
22 | #include "./command.h" |
23 | #include "./entropy_encode.h" |
24 | #include "./memory.h" |
25 | #include "./metablock.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, size_t start_pos, size_t length, size_t mask, |
46 | uint8_t prev_byte, uint8_t prev_byte2, BROTLI_BOOL is_last, |
47 | const BrotliEncoderParams* params, ContextType literal_context_mode, |
48 | const Command* commands, size_t n_commands, const MetaBlockSplit* mb, |
49 | size_t* storage_ix, uint8_t* storage); |
50 | |
51 | /* Stores the meta-block without doing any block splitting, just collects |
52 | one histogram per block category and uses that for entropy coding. |
53 | REQUIRES: length > 0 |
54 | REQUIRES: length <= (1 << 24) */ |
55 | BROTLI_INTERNAL void BrotliStoreMetaBlockTrivial(MemoryManager* m, |
56 | const uint8_t* input, size_t start_pos, size_t length, size_t mask, |
57 | BROTLI_BOOL is_last, const BrotliEncoderParams* params, |
58 | const Command* commands, size_t n_commands, |
59 | size_t* storage_ix, uint8_t* storage); |
60 | |
61 | /* Same as above, but uses static prefix codes for histograms with a only a few |
62 | symbols, and uses static code length prefix codes for all other histograms. |
63 | REQUIRES: length > 0 |
64 | REQUIRES: length <= (1 << 24) */ |
65 | BROTLI_INTERNAL void BrotliStoreMetaBlockFast(MemoryManager* m, |
66 | const uint8_t* input, size_t start_pos, size_t length, size_t mask, |
67 | BROTLI_BOOL is_last, const BrotliEncoderParams* params, |
68 | const Command* commands, size_t n_commands, |
69 | size_t* storage_ix, uint8_t* storage); |
70 | |
71 | /* This is for storing uncompressed blocks (simple raw storage of |
72 | bytes-as-bytes). |
73 | REQUIRES: length > 0 |
74 | REQUIRES: length <= (1 << 24) */ |
75 | BROTLI_INTERNAL void BrotliStoreUncompressedMetaBlock( |
76 | BROTLI_BOOL is_final_block, const uint8_t* BROTLI_RESTRICT input, |
77 | size_t position, size_t mask, size_t len, |
78 | size_t* BROTLI_RESTRICT storage_ix, uint8_t* BROTLI_RESTRICT storage); |
79 | |
80 | #if defined(__cplusplus) || defined(c_plusplus) |
81 | } /* extern "C" */ |
82 | #endif |
83 | |
84 | #endif /* BROTLI_ENC_BROTLI_BIT_STREAM_H_ */ |
85 | |