Add ICU message format support
[chromium-blink-merge.git] / third_party / brotli / dec / state.h
blobe5d6b5a5d0a52fa02298fa8cc47e7abf10ab3eef
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_
21 #include <stdio.h>
22 #include "./bit_reader.h"
23 #include "./huffman.h"
24 #include "./streams.h"
25 #include "./types.h"
27 #if defined(__cplusplus) || defined(c_plusplus)
28 extern "C" {
29 #endif
31 typedef enum {
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
69 } BrotliRunningState;
71 typedef struct {
72 BrotliRunningState state;
73 BrotliRunningState sub_state[2]; /* State inside function call */
75 int pos;
76 int input_end;
77 int window_bits;
78 int max_backward_distance;
79 int max_distance;
80 int ringbuffer_size;
81 int ringbuffer_mask;
82 uint8_t* ringbuffer;
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. */
86 int dist_rb[4];
87 int dist_rb_idx;
88 /* The previous 2 bytes used for context. */
89 uint8_t prev_byte1;
90 uint8_t prev_byte2;
91 HuffmanTreeGroup hgroup[3];
92 HuffmanCode* block_type_trees;
93 HuffmanCode* block_len_trees;
94 BrotliBitReader br;
95 /* This counter is reused for several disjoint loops. */
96 int loop_counter;
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;
102 int is_metadata;
103 int is_uncompressed;
104 int block_length[3];
105 int block_type[3];
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;
117 int num_dist_htrees;
118 int context_offset;
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;
129 int cmd_code;
130 int range_idx;
131 int insert_code;
132 int copy_code;
133 int insert_length;
134 int copy_length;
135 int distance_code;
136 int distance;
137 const uint8_t* copy_src;
138 uint8_t* copy_dst;
140 /* For CopyUncompressedBlockToOutput */
141 int nbytes;
143 /* For partial write operations */
144 int partially_written;
146 /* For HuffmanTreeGroupDecode */
147 int htrees_decoded;
149 /* For ReadHuffmanCodeLengths */
150 int symbol;
151 uint8_t prev_code_len;
152 int repeat;
153 uint8_t repeat_code_len;
154 int space;
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 */
163 int htree_index;
164 HuffmanCode* next;
166 /* For DecodeContextMap */
167 int context_index;
168 int max_run_length_prefix;
169 HuffmanCode* context_map_table;
170 } BrotliState;
172 void BrotliStateInit(BrotliState* s);
173 void BrotliStateCleanup(BrotliState* s);
175 #if defined(__cplusplus) || defined(c_plusplus)
176 } /* extern "C" */
177 #endif
179 #endif /* BROTLI_DEC_STATE_H_ */