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_METADATA
= 18,
43 BROTLI_STATE_BLOCK_INNER_WRITE
= 19,
44 BROTLI_STATE_METABLOCK_DONE
= 20,
45 BROTLI_STATE_BLOCK_POST_WRITE_1
= 21,
46 BROTLI_STATE_BLOCK_POST_WRITE_2
= 22,
47 BROTLI_STATE_BLOCK_POST_CONTINUE
= 23,
48 BROTLI_STATE_HUFFMAN_CODE_0
= 30,
49 BROTLI_STATE_HUFFMAN_CODE_1
= 31,
50 BROTLI_STATE_HUFFMAN_CODE_2
= 32,
51 BROTLI_STATE_CONTEXT_MAP_1
= 33,
52 BROTLI_STATE_CONTEXT_MAP_2
= 34,
53 BROTLI_STATE_TREE_GROUP
= 35,
54 BROTLI_STATE_SUB_NONE
= 50,
55 BROTLI_STATE_SUB_UNCOMPRESSED_SHORT
= 51,
56 BROTLI_STATE_SUB_UNCOMPRESSED_FILL
= 52,
57 BROTLI_STATE_SUB_UNCOMPRESSED_COPY
= 53,
58 BROTLI_STATE_SUB_UNCOMPRESSED_WARMUP
= 54,
59 BROTLI_STATE_SUB_UNCOMPRESSED_WRITE_1
= 55,
60 BROTLI_STATE_SUB_UNCOMPRESSED_WRITE_2
= 56,
61 BROTLI_STATE_SUB_UNCOMPRESSED_WRITE_3
= 57,
62 BROTLI_STATE_SUB_HUFFMAN_LENGTH_BEGIN
= 60,
63 BROTLI_STATE_SUB_HUFFMAN_LENGTH_SYMBOLS
= 61,
64 BROTLI_STATE_SUB_HUFFMAN_DONE
= 62,
65 BROTLI_STATE_SUB_TREE_GROUP
= 70,
66 BROTLI_STATE_SUB_CONTEXT_MAP_HUFFMAN
= 80,
67 BROTLI_STATE_SUB_CONTEXT_MAPS
= 81,
68 BROTLI_STATE_DONE
= 100
72 BrotliRunningState state
;
73 BrotliRunningState sub_state
[2]; /* State inside function call */
78 int max_backward_distance
;
83 uint8_t* ringbuffer_end
;
84 /* This ring buffer holds a few past copy distances that will be used by */
85 /* some special distance codes. */
88 /* The previous 2 bytes used for context. */
91 HuffmanTreeGroup hgroup
[3];
92 HuffmanCode
* block_type_trees
;
93 HuffmanCode
* block_len_trees
;
95 /* This counter is reused for several disjoint loops. */
97 /* This is true if the literal context map histogram type always matches the
98 block type. It is then not needed to keep the context (faster decoding). */
99 int trivial_literal_context
;
101 int meta_block_remaining_len
;
106 int num_block_types
[3];
107 int block_type_rb
[6];
108 int block_type_rb_index
[3];
109 int distance_postfix_bits
;
110 int num_direct_distance_codes
;
111 int distance_postfix_mask
;
112 int num_distance_codes
;
113 uint8_t* context_map
;
114 uint8_t* context_modes
;
115 int num_literal_htrees
;
116 uint8_t* dist_context_map
;
119 uint8_t* context_map_slice
;
120 uint8_t literal_htree_index
;
121 int dist_context_offset
;
122 uint8_t* dist_context_map_slice
;
123 uint8_t dist_htree_index
;
124 int context_lookup_offset1
;
125 int context_lookup_offset2
;
126 uint8_t context_mode
;
127 HuffmanCode
* htree_command
;
137 const uint8_t* copy_src
;
140 /* For CopyUncompressedBlockToOutput */
143 /* For partial write operations */
144 int partially_written
;
146 /* For HuffmanTreeGroupDecode */
149 /* For ReadHuffmanCodeLengths */
151 uint8_t prev_code_len
;
153 uint8_t repeat_code_len
;
155 HuffmanCode table
[32];
156 uint8_t code_length_code_lengths
[18];
158 /* For ReadHuffmanCode */
159 int simple_code_or_skip
;
160 uint8_t* code_lengths
;
162 /* For HuffmanTreeGroupDecode */
166 /* For DecodeContextMap */
168 int max_run_length_prefix
;
169 HuffmanCode
* context_map_table
;
172 void BrotliStateInit(BrotliState
* s
);
173 void BrotliStateCleanup(BrotliState
* s
);
175 #if defined(__cplusplus) || defined(c_plusplus)
179 #endif /* BROTLI_DEC_STATE_H_ */