1 /* Copyright 2014 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 /* 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.
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. */
16 #ifndef BROTLI_ENC_BROTLI_BIT_STREAM_H_
17 #define BROTLI_ENC_BROTLI_BIT_STREAM_H_
19 #include "../common/types.h"
20 #include "./command.h"
21 #include "./context.h"
22 #include "./entropy_encode.h"
24 #include "./metablock.h"
27 #if defined(__cplusplus) || defined(c_plusplus)
31 /* All Store functions here will use a storage_ix, which is always the bit
32 position for the current storage. */
34 BROTLI_INTERNAL
void BrotliStoreHuffmanTree(const uint8_t* depths
, size_t num
,
35 HuffmanTree
* tree
, size_t *storage_ix
, uint8_t *storage
);
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
,
42 /* REQUIRES: length > 0 */
43 /* REQUIRES: length <= (1 << 24) */
44 BROTLI_INTERNAL
void BrotliStoreMetaBlock(MemoryManager
* m
,
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
,
57 const MetaBlockSplit
* mb
,
61 /* Stores the meta-block without doing any block splitting, just collects
62 one histogram per block category and uses that for entropy coding.
64 REQUIRES: length <= (1 << 24) */
65 BROTLI_INTERNAL
void BrotliStoreMetaBlockTrivial(MemoryManager
* m
,
71 const Command
*commands
,
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.
79 REQUIRES: length <= (1 << 24) */
80 BROTLI_INTERNAL
void BrotliStoreMetaBlockFast(MemoryManager
* m
,
86 const Command
*commands
,
91 /* This is for storing uncompressed blocks (simple raw storage of
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
);
99 /* Stores an empty metadata meta-block and syncs to a byte boundary. */
100 BROTLI_INTERNAL
void BrotliStoreSyncMetaBlock(size_t* storage_ix
,
103 #if defined(__cplusplus) || defined(c_plusplus)
107 #endif /* BROTLI_ENC_BROTLI_BIT_STREAM_H_ */