brotli_bit_stream.h (3338B)
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 "command.h" 22 #include "entropy_encode.h" 23 #include "memory.h" 24 #include "metablock.h" 25 26 #if defined(__cplusplus) || defined(c_plusplus) 27 extern "C" { 28 #endif 29 30 /* All Store functions here will use a storage_ix, which is always the bit 31 position for the current storage. */ 32 33 BROTLI_INTERNAL void BrotliStoreHuffmanTree(const uint8_t* depths, size_t num, 34 HuffmanTree* tree, size_t* storage_ix, uint8_t* storage); 35 36 BROTLI_INTERNAL void BrotliBuildAndStoreHuffmanTreeFast( 37 HuffmanTree* tree, const uint32_t* histogram, const size_t histogram_total, 38 const size_t max_bits, uint8_t* depth, uint16_t* bits, size_t* storage_ix, 39 uint8_t* storage); 40 41 /* REQUIRES: length > 0 */ 42 /* REQUIRES: length <= (1 << 24) */ 43 BROTLI_INTERNAL void BrotliStoreMetaBlock(MemoryManager* m, 44 const uint8_t* input, size_t start_pos, size_t length, size_t mask, 45 uint8_t prev_byte, uint8_t prev_byte2, BROTLI_BOOL is_last, 46 const BrotliEncoderParams* params, ContextType literal_context_mode, 47 const Command* commands, size_t n_commands, const MetaBlockSplit* mb, 48 size_t* storage_ix, uint8_t* storage); 49 50 /* Stores the meta-block without doing any block splitting, just collects 51 one histogram per block category and uses that for entropy coding. 52 REQUIRES: length > 0 53 REQUIRES: length <= (1 << 24) */ 54 BROTLI_INTERNAL void BrotliStoreMetaBlockTrivial(MemoryManager* m, 55 const uint8_t* input, size_t start_pos, size_t length, size_t mask, 56 BROTLI_BOOL is_last, const BrotliEncoderParams* params, 57 const Command* commands, size_t n_commands, 58 size_t* storage_ix, uint8_t* storage); 59 60 /* Same as above, but uses static prefix codes for histograms with a only a few 61 symbols, and uses static code length prefix codes for all other histograms. 62 REQUIRES: length > 0 63 REQUIRES: length <= (1 << 24) */ 64 BROTLI_INTERNAL void BrotliStoreMetaBlockFast(MemoryManager* m, 65 const uint8_t* input, size_t start_pos, size_t length, size_t mask, 66 BROTLI_BOOL is_last, const BrotliEncoderParams* params, 67 const Command* commands, size_t n_commands, 68 size_t* storage_ix, uint8_t* storage); 69 70 /* This is for storing uncompressed blocks (simple raw storage of 71 bytes-as-bytes). 72 REQUIRES: length > 0 73 REQUIRES: length <= (1 << 24) */ 74 BROTLI_INTERNAL void BrotliStoreUncompressedMetaBlock( 75 BROTLI_BOOL is_final_block, const uint8_t* BROTLI_RESTRICT input, 76 size_t position, size_t mask, size_t len, 77 size_t* BROTLI_RESTRICT storage_ix, uint8_t* BROTLI_RESTRICT storage); 78 79 #if defined(__cplusplus) || defined(c_plusplus) 80 } /* extern "C" */ 81 #endif 82 83 #endif /* BROTLI_ENC_BROTLI_BIT_STREAM_H_ */