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