1 /* Copyright 2015 Google Inc. All Rights Reserved.
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
7 http://www.apache.org/licenses/LICENSE-2.0
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
16 /* Brotli state for partial streaming decoding. */
18 #ifndef BROTLI_DEC_STATE_H_
19 #define BROTLI_DEC_STATE_H_
22 #include "./bit_reader.h"
23 #include "./huffman.h"
24 #include "./streams.h"
27 #if defined(__cplusplus) || defined(c_plusplus)
32 BROTLI_STATE_UNINITED
= 0,
33 BROTLI_STATE_BITREADER_WARMUP
= 1,
34 BROTLI_STATE_METABLOCK_BEGIN
= 10,
35 BROTLI_STATE_METABLOCK_HEADER_1
= 11,
36 BROTLI_STATE_METABLOCK_HEADER_2
= 12,
37 BROTLI_STATE_BLOCK_BEGIN
= 13,
38 BROTLI_STATE_BLOCK_INNER
= 14,
39 BROTLI_STATE_BLOCK_DISTANCE
= 15,
40 BROTLI_STATE_BLOCK_POST
= 16,
41 BROTLI_STATE_UNCOMPRESSED
= 17,
42 BROTLI_STATE_METABLOCK_DONE
= 20,
43 BROTLI_STATE_HUFFMAN_CODE_0
= 30,
44 BROTLI_STATE_HUFFMAN_CODE_1
= 31,
45 BROTLI_STATE_HUFFMAN_CODE_2
= 32,
46 BROTLI_STATE_CONTEXT_MAP_1
= 33,
47 BROTLI_STATE_CONTEXT_MAP_2
= 34,
48 BROTLI_STATE_TREE_GROUP
= 35,
49 BROTLI_STATE_SUB_NONE
= 50,
50 BROTLI_STATE_SUB_UNCOMPRESSED_SHORT
= 51,
51 BROTLI_STATE_SUB_UNCOMPRESSED_FILL
= 52,
52 BROTLI_STATE_SUB_UNCOMPRESSED_COPY
= 53,
53 BROTLI_STATE_SUB_UNCOMPRESSED_WARMUP
= 54,
54 BROTLI_STATE_SUB_HUFFMAN_LENGTH_BEGIN
= 60,
55 BROTLI_STATE_SUB_HUFFMAN_LENGTH_SYMBOLS
= 61,
56 BROTLI_STATE_SUB_HUFFMAN_DONE
= 62,
57 BROTLI_STATE_SUB_TREE_GROUP
= 70,
58 BROTLI_STATE_SUB_CONTEXT_MAP_HUFFMAN
= 80,
59 BROTLI_STATE_SUB_CONTEXT_MAPS
= 81,
60 BROTLI_STATE_DONE
= 100
64 BrotliRunningState state
;
65 BrotliRunningState sub_state
[2]; /* State inside function call */
70 int max_backward_distance
;
75 uint8_t* ringbuffer_end
;
76 /* This ring buffer holds a few past copy distances that will be used by */
77 /* some special distance codes. */
80 /* The previous 2 bytes used for context. */
83 HuffmanTreeGroup hgroup
[3];
84 HuffmanCode
* block_type_trees
;
85 HuffmanCode
* block_len_trees
;
87 /* This counter is reused for several disjoint loops. */
89 /* This is true if the literal context map histogram type always matches the
90 block type. It is then not needed to keep the context (faster decoding). */
91 int trivial_literal_context
;
93 int meta_block_remaining_len
;
97 int num_block_types
[3];
99 int block_type_rb_index
[3];
100 int distance_postfix_bits
;
101 int num_direct_distance_codes
;
102 int distance_postfix_mask
;
103 int num_distance_codes
;
104 uint8_t* context_map
;
105 uint8_t* context_modes
;
106 int num_literal_htrees
;
107 uint8_t* dist_context_map
;
110 uint8_t* context_map_slice
;
111 uint8_t literal_htree_index
;
112 int dist_context_offset
;
113 uint8_t* dist_context_map_slice
;
114 uint8_t dist_htree_index
;
115 int context_lookup_offset1
;
116 int context_lookup_offset2
;
117 uint8_t context_mode
;
118 HuffmanCode
* htree_command
;
128 const uint8_t* copy_src
;
131 /* For CopyUncompressedBlockToOutput */
134 /* For HuffmanTreeGroupDecode */
137 /* For ReadHuffmanCodeLengths */
139 uint8_t prev_code_len
;
141 uint8_t repeat_code_len
;
143 HuffmanCode table
[32];
144 uint8_t code_length_code_lengths
[18];
146 /* For ReadHuffmanCode */
147 int simple_code_or_skip
;
148 uint8_t* code_lengths
;
150 /* For HuffmanTreeGroupDecode */
154 /* For DecodeContextMap */
156 int max_run_length_prefix
;
157 HuffmanCode
* context_map_table
;
160 void BrotliStateInit(BrotliState
* s
);
161 void BrotliStateCleanup(BrotliState
* s
);
163 #if defined(__cplusplus) || defined(c_plusplus)
167 #endif /* BROTLI_DEC_STATE_H_ */