diff options
author | Matt A. Tobin <email@mattatobin.com> | 2019-11-14 21:08:43 -0500 |
---|---|---|
committer | Matt A. Tobin <email@mattatobin.com> | 2019-11-14 21:08:43 -0500 |
commit | 1d30f6fa8413746ddc408f93710d701493af273d (patch) | |
tree | abe84e83d704e13c60c90db7ac4b9e363d8a81fc /modules/brotli/dec/state.h | |
parent | 9308ec68e863e4c6e650680370a5d7baa9f0d1f3 (diff) | |
parent | 00573571a226a0c59dd744da67483864a22911aa (diff) | |
download | UXP-1d30f6fa8413746ddc408f93710d701493af273d.tar UXP-1d30f6fa8413746ddc408f93710d701493af273d.tar.gz UXP-1d30f6fa8413746ddc408f93710d701493af273d.tar.lz UXP-1d30f6fa8413746ddc408f93710d701493af273d.tar.xz UXP-1d30f6fa8413746ddc408f93710d701493af273d.zip |
Merge branch 'master' into mailnews-work
Diffstat (limited to 'modules/brotli/dec/state.h')
-rw-r--r-- | modules/brotli/dec/state.h | 98 |
1 files changed, 57 insertions, 41 deletions
diff --git a/modules/brotli/dec/state.h b/modules/brotli/dec/state.h index 63647ef2b..d28b63920 100644 --- a/modules/brotli/dec/state.h +++ b/modules/brotli/dec/state.h @@ -9,10 +9,13 @@ #ifndef BROTLI_DEC_STATE_H_ #define BROTLI_DEC_STATE_H_ +#include "../common/constants.h" +#include "../common/dictionary.h" +#include "../common/platform.h" +#include "../common/transform.h" +#include <brotli/types.h> #include "./bit_reader.h" #include "./huffman.h" -#include "./types.h" -#include "./port.h" #if defined(__cplusplus) || defined(c_plusplus) extern "C" { @@ -20,6 +23,8 @@ extern "C" { typedef enum { BROTLI_STATE_UNINITED, + BROTLI_STATE_LARGE_WINDOW_BITS, + BROTLI_STATE_INITIALIZE, BROTLI_STATE_METABLOCK_BEGIN, BROTLI_STATE_METABLOCK_HEADER, BROTLI_STATE_METABLOCK_HEADER_2, @@ -93,7 +98,7 @@ typedef enum { BROTLI_STATE_READ_BLOCK_LENGTH_SUFFIX } BrotliRunningReadBlockLengthState; -struct BrotliStateStruct { +struct BrotliDecoderStateStruct { BrotliRunningState state; /* This counter is reused for several disjoint loops. */ @@ -114,7 +119,6 @@ struct BrotliStateStruct { int pos; int max_backward_distance; - int max_backward_distance_minus_custom_dict_size; int max_distance; int ringbuffer_size; int ringbuffer_mask; @@ -125,21 +129,22 @@ struct BrotliStateStruct { uint8_t* ringbuffer; uint8_t* ringbuffer_end; HuffmanCode* htree_command; - const uint8_t* context_lookup1; - const uint8_t* context_lookup2; + const uint8_t* context_lookup; uint8_t* context_map_slice; uint8_t* dist_context_map_slice; - /* This ring buffer holds a few past copy distances that will be used by */ - /* some special distance codes. */ + /* This ring buffer holds a few past copy distances that will be used by + some special distance codes. */ HuffmanTreeGroup literal_hgroup; HuffmanTreeGroup insert_copy_hgroup; HuffmanTreeGroup distance_hgroup; HuffmanCode* block_type_trees; HuffmanCode* block_len_trees; /* This is true if the literal context map histogram type always matches the - block type. It is then not needed to keep the context (faster decoding). */ + block type. It is then not needed to keep the context (faster decoding). */ int trivial_literal_context; + /* Distance context is actual after command is decoded and before distance is + computed. After distance computation it is used as a temporary variable. */ int distance_context; int meta_block_remaining_len; uint32_t block_length_index; @@ -159,47 +164,44 @@ struct BrotliStateStruct { int copy_length; int distance_code; - /* For partial write operations */ - size_t rb_roundtrips; /* How many times we went around the ringbuffer */ - size_t partial_pos_out; /* How much output to the user in total (<= rb) */ + /* For partial write operations. */ + size_t rb_roundtrips; /* how many times we went around the ring-buffer */ + size_t partial_pos_out; /* how much output to the user in total */ - /* For ReadHuffmanCode */ + /* For ReadHuffmanCode. */ uint32_t symbol; uint32_t repeat; uint32_t space; HuffmanCode table[32]; - /* List of of symbol chains. */ + /* List of heads of symbol chains. */ uint16_t* symbol_lists; /* Storage from symbol_lists. */ uint16_t symbols_lists_array[BROTLI_HUFFMAN_MAX_CODE_LENGTH + 1 + - BROTLI_HUFFMAN_MAX_CODE_LENGTHS_SIZE]; + BROTLI_NUM_COMMAND_SYMBOLS]; /* Tails of symbol chains. */ int next_symbol[32]; - uint8_t code_length_code_lengths[18]; - /* Population counts for the code lengths */ + uint8_t code_length_code_lengths[BROTLI_CODE_LENGTH_CODES]; + /* Population counts for the code lengths. */ uint16_t code_length_histo[16]; - /* For HuffmanTreeGroupDecode */ + /* For HuffmanTreeGroupDecode. */ int htree_index; HuffmanCode* next; - /* For DecodeContextMap */ + /* For DecodeContextMap. */ uint32_t context_index; uint32_t max_run_length_prefix; uint32_t code; HuffmanCode context_map_table[BROTLI_HUFFMAN_MAX_SIZE_272]; - /* For InverseMoveToFrontTransform */ + /* For InverseMoveToFrontTransform. */ uint32_t mtf_upper_bound; - uint8_t mtf[256 + 4]; + uint32_t mtf[64 + 1]; - /* For custom dictionaries */ - const uint8_t* custom_dict; - int custom_dict_size; + /* Less used attributes are at the end of this struct. */ - /* less used attributes are in the end of this struct */ - /* States inside function calls */ + /* States inside function calls. */ BrotliRunningMetablockHeaderState substate_metablock_header; BrotliRunningTreeGroupState substate_tree_group; BrotliRunningContextMapState substate_context_map; @@ -208,32 +210,46 @@ struct BrotliStateStruct { BrotliRunningDecodeUint8State substate_decode_uint8; BrotliRunningReadBlockLengthState substate_read_block_length; - uint8_t is_last_metablock; - uint8_t is_uncompressed; - uint8_t is_metadata; - uint8_t size_nibbles; + unsigned int is_last_metablock : 1; + unsigned int is_uncompressed : 1; + unsigned int is_metadata : 1; + unsigned int should_wrap_ringbuffer : 1; + unsigned int canny_ringbuffer_allocation : 1; + unsigned int large_window : 1; + unsigned int size_nibbles : 8; uint32_t window_bits; + int new_ringbuffer_size; + uint32_t num_literal_htrees; uint8_t* context_map; uint8_t* context_modes; + const BrotliDictionary* dictionary; + const BrotliTransforms* transforms; + uint32_t trivial_literal_contexts[8]; /* 256 bits */ }; -typedef struct BrotliStateStruct BrotliStateInternal; -#define BrotliState BrotliStateInternal +typedef struct BrotliDecoderStateStruct BrotliDecoderStateInternal; +#define BrotliDecoderState BrotliDecoderStateInternal -BROTLI_INTERNAL void BrotliStateInit(BrotliState* s); -BROTLI_INTERNAL void BrotliStateInitWithCustomAllocators(BrotliState* s, +BROTLI_INTERNAL BROTLI_BOOL BrotliDecoderStateInit(BrotliDecoderState* s, brotli_alloc_func alloc_func, brotli_free_func free_func, void* opaque); -BROTLI_INTERNAL void BrotliStateCleanup(BrotliState* s); -BROTLI_INTERNAL void BrotliStateMetablockBegin(BrotliState* s); -BROTLI_INTERNAL void BrotliStateCleanupAfterMetablock(BrotliState* s); -BROTLI_INTERNAL void BrotliHuffmanTreeGroupInit(BrotliState* s, - HuffmanTreeGroup* group, uint32_t alphabet_size, uint32_t ntrees); -BROTLI_INTERNAL void BrotliHuffmanTreeGroupRelease(BrotliState* s, - HuffmanTreeGroup* group); +BROTLI_INTERNAL void BrotliDecoderStateCleanup(BrotliDecoderState* s); +BROTLI_INTERNAL void BrotliDecoderStateMetablockBegin(BrotliDecoderState* s); +BROTLI_INTERNAL void BrotliDecoderStateCleanupAfterMetablock( + BrotliDecoderState* s); +BROTLI_INTERNAL BROTLI_BOOL BrotliDecoderHuffmanTreeGroupInit( + BrotliDecoderState* s, HuffmanTreeGroup* group, uint32_t alphabet_size, + uint32_t max_symbol, uint32_t ntrees); + +#define BROTLI_DECODER_ALLOC(S, L) S->alloc_func(S->memory_manager_opaque, L) + +#define BROTLI_DECODER_FREE(S, X) { \ + S->free_func(S->memory_manager_opaque, X); \ + X = NULL; \ +} #if defined(__cplusplus) || defined(c_plusplus) } /* extern "C" */ |