#define BROTLI_DEC_STATE_H_\r
\r
#include "../common/constants.h"\r
-#include "../common/types.h"\r
+#include "../common/dictionary.h"\r
+#include "../common/platform.h"\r
+#include "../common/transform.h"\r
+#include <brotli/types.h>\r
#include "./bit_reader.h"\r
#include "./huffman.h"\r
-#include "./port.h"\r
\r
#if defined(__cplusplus) || defined(c_plusplus)\r
extern "C" {\r
\r
typedef enum {\r
BROTLI_STATE_UNINITED,\r
+ BROTLI_STATE_LARGE_WINDOW_BITS,\r
+ BROTLI_STATE_INITIALIZE,\r
BROTLI_STATE_METABLOCK_BEGIN,\r
BROTLI_STATE_METABLOCK_HEADER,\r
BROTLI_STATE_METABLOCK_HEADER_2,\r
\r
int pos;\r
int max_backward_distance;\r
- int max_backward_distance_minus_custom_dict_size;\r
int max_distance;\r
int ringbuffer_size;\r
int ringbuffer_mask;\r
uint8_t* ringbuffer;\r
uint8_t* ringbuffer_end;\r
HuffmanCode* htree_command;\r
- const uint8_t* context_lookup1;\r
- const uint8_t* context_lookup2;\r
+ const uint8_t* context_lookup;\r
uint8_t* context_map_slice;\r
uint8_t* dist_context_map_slice;\r
\r
- /* This ring buffer holds a few past copy distances that will be used by */\r
- /* some special distance codes. */\r
+ /* This ring buffer holds a few past copy distances that will be used by\r
+ some special distance codes. */\r
HuffmanTreeGroup literal_hgroup;\r
HuffmanTreeGroup insert_copy_hgroup;\r
HuffmanTreeGroup distance_hgroup;\r
HuffmanCode* block_type_trees;\r
HuffmanCode* block_len_trees;\r
/* This is true if the literal context map histogram type always matches the\r
- block type. It is then not needed to keep the context (faster decoding). */\r
+ block type. It is then not needed to keep the context (faster decoding). */\r
int trivial_literal_context;\r
+ /* Distance context is actual after command is decoded and before distance is\r
+ computed. After distance computation it is used as a temporary variable. */\r
int distance_context;\r
int meta_block_remaining_len;\r
uint32_t block_length_index;\r
int copy_length;\r
int distance_code;\r
\r
- /* For partial write operations */\r
- size_t rb_roundtrips; /* How many times we went around the ringbuffer */\r
- size_t partial_pos_out; /* How much output to the user in total (<= rb) */\r
+ /* For partial write operations. */\r
+ size_t rb_roundtrips; /* how many times we went around the ring-buffer */\r
+ size_t partial_pos_out; /* how much output to the user in total */\r
\r
- /* For ReadHuffmanCode */\r
+ /* For ReadHuffmanCode. */\r
uint32_t symbol;\r
uint32_t repeat;\r
uint32_t space;\r
\r
HuffmanCode table[32];\r
- /* List of of symbol chains. */\r
+ /* List of heads of symbol chains. */\r
uint16_t* symbol_lists;\r
/* Storage from symbol_lists. */\r
uint16_t symbols_lists_array[BROTLI_HUFFMAN_MAX_CODE_LENGTH + 1 +\r
/* Tails of symbol chains. */\r
int next_symbol[32];\r
uint8_t code_length_code_lengths[BROTLI_CODE_LENGTH_CODES];\r
- /* Population counts for the code lengths */\r
+ /* Population counts for the code lengths. */\r
uint16_t code_length_histo[16];\r
\r
- /* For HuffmanTreeGroupDecode */\r
+ /* For HuffmanTreeGroupDecode. */\r
int htree_index;\r
HuffmanCode* next;\r
\r
- /* For DecodeContextMap */\r
+ /* For DecodeContextMap. */\r
uint32_t context_index;\r
uint32_t max_run_length_prefix;\r
uint32_t code;\r
HuffmanCode context_map_table[BROTLI_HUFFMAN_MAX_SIZE_272];\r
\r
- /* For InverseMoveToFrontTransform */\r
+ /* For InverseMoveToFrontTransform. */\r
uint32_t mtf_upper_bound;\r
- uint8_t mtf[256 + 4];\r
+ uint32_t mtf[64 + 1];\r
\r
- /* For custom dictionaries */\r
- const uint8_t* custom_dict;\r
- int custom_dict_size;\r
+ /* Less used attributes are at the end of this struct. */\r
\r
- /* less used attributes are in the end of this struct */\r
- /* States inside function calls */\r
+ /* States inside function calls. */\r
BrotliRunningMetablockHeaderState substate_metablock_header;\r
BrotliRunningTreeGroupState substate_tree_group;\r
BrotliRunningContextMapState substate_context_map;\r
BrotliRunningDecodeUint8State substate_decode_uint8;\r
BrotliRunningReadBlockLengthState substate_read_block_length;\r
\r
- uint8_t is_last_metablock;\r
- uint8_t is_uncompressed;\r
- uint8_t is_metadata;\r
- uint8_t size_nibbles;\r
+ unsigned int is_last_metablock : 1;\r
+ unsigned int is_uncompressed : 1;\r
+ unsigned int is_metadata : 1;\r
+ unsigned int should_wrap_ringbuffer : 1;\r
+ unsigned int canny_ringbuffer_allocation : 1;\r
+ unsigned int large_window : 1;\r
+ unsigned int size_nibbles : 8;\r
uint32_t window_bits;\r
\r
+ int new_ringbuffer_size;\r
+\r
uint32_t num_literal_htrees;\r
uint8_t* context_map;\r
uint8_t* context_modes;\r
\r
+ const BrotliDictionary* dictionary;\r
+ const BrotliTransforms* transforms;\r
+\r
uint32_t trivial_literal_contexts[8]; /* 256 bits */\r
};\r
\r
typedef struct BrotliDecoderStateStruct BrotliDecoderStateInternal;\r
#define BrotliDecoderState BrotliDecoderStateInternal\r
\r
-BROTLI_INTERNAL void BrotliDecoderStateInit(BrotliDecoderState* s);\r
-BROTLI_INTERNAL void BrotliDecoderStateInitWithCustomAllocators(\r
- BrotliDecoderState* s, brotli_alloc_func alloc_func,\r
- brotli_free_func free_func, void* opaque);\r
+BROTLI_INTERNAL BROTLI_BOOL BrotliDecoderStateInit(BrotliDecoderState* s,\r
+ brotli_alloc_func alloc_func, brotli_free_func free_func, void* opaque);\r
BROTLI_INTERNAL void BrotliDecoderStateCleanup(BrotliDecoderState* s);\r
BROTLI_INTERNAL void BrotliDecoderStateMetablockBegin(BrotliDecoderState* s);\r
BROTLI_INTERNAL void BrotliDecoderStateCleanupAfterMetablock(\r
BrotliDecoderState* s);\r
-BROTLI_INTERNAL void BrotliDecoderHuffmanTreeGroupInit(\r
+BROTLI_INTERNAL BROTLI_BOOL BrotliDecoderHuffmanTreeGroupInit(\r
BrotliDecoderState* s, HuffmanTreeGroup* group, uint32_t alphabet_size,\r
- uint32_t ntrees);\r
-BROTLI_INTERNAL void BrotliDecoderHuffmanTreeGroupRelease(\r
- BrotliDecoderState* s, HuffmanTreeGroup* group);\r
+ uint32_t max_symbol, uint32_t ntrees);\r
+\r
+#define BROTLI_DECODER_ALLOC(S, L) S->alloc_func(S->memory_manager_opaque, L)\r
+\r
+#define BROTLI_DECODER_FREE(S, X) { \\r
+ S->free_func(S->memory_manager_opaque, X); \\r
+ X = NULL; \\r
+}\r
\r
#if defined(__cplusplus) || defined(c_plusplus)\r
} /* extern "C" */\r