• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2016 Google Inc. All Rights Reserved.
2 
3    Distributed under MIT license.
4    See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 */
6 
7 #ifndef BROTLI_COMMON_CONSTANTS_H_
8 #define BROTLI_COMMON_CONSTANTS_H_
9 
10 /* Specification: 7.3. Encoding of the context map */
11 #define BROTLI_CONTEXT_MAP_MAX_RLE 16
12 
13 /* Specification: 2. Compressed representation overview */
14 #define BROTLI_MAX_NUMBER_OF_BLOCK_TYPES 256
15 
16 /* Specification: 3.3. Alphabet sizes: insert-and-copy length */
17 #define BROTLI_NUM_LITERAL_SYMBOLS 256
18 #define BROTLI_NUM_COMMAND_SYMBOLS 704
19 #define BROTLI_NUM_BLOCK_LEN_SYMBOLS 26
20 #define BROTLI_MAX_CONTEXT_MAP_SYMBOLS (BROTLI_MAX_NUMBER_OF_BLOCK_TYPES + \
21                                         BROTLI_CONTEXT_MAP_MAX_RLE)
22 #define BROTLI_MAX_BLOCK_TYPE_SYMBOLS (BROTLI_MAX_NUMBER_OF_BLOCK_TYPES + 2)
23 
24 /* Specification: 3.5. Complex prefix codes */
25 #define BROTLI_REPEAT_PREVIOUS_CODE_LENGTH 16
26 #define BROTLI_REPEAT_ZERO_CODE_LENGTH 17
27 #define BROTLI_CODE_LENGTH_CODES (BROTLI_REPEAT_ZERO_CODE_LENGTH + 1)
28 /* "code length of 8 is repeated" */
29 #define BROTLI_INITIAL_REPEATED_CODE_LENGTH 8
30 
31 /* Specification: 4. Encoding of distances */
32 #define BROTLI_NUM_DISTANCE_SHORT_CODES 16
33 #define BROTLI_MAX_NPOSTFIX 3
34 #define BROTLI_MAX_NDIRECT 120
35 #define BROTLI_MAX_DISTANCE_BITS 24U
36 /* BROTLI_NUM_DISTANCE_SYMBOLS == 520 */
37 #define BROTLI_NUM_DISTANCE_SYMBOLS (BROTLI_NUM_DISTANCE_SHORT_CODES + \
38                                      BROTLI_MAX_NDIRECT +              \
39                                      (BROTLI_MAX_DISTANCE_BITS <<      \
40                                       (BROTLI_MAX_NPOSTFIX + 1)))
41 
42 /* 7.1. Context modes and context ID lookup for literals */
43 /* "context IDs for literals are in the range of 0..63" */
44 #define BROTLI_LITERAL_CONTEXT_BITS 6
45 
46 /* 7.2. Context ID for distances */
47 #define BROTLI_DISTANCE_CONTEXT_BITS 2
48 
49 /* 9.1. Format of the Stream Header */
50 /* Number of slack bytes for window size. Don't confuse
51    with BROTLI_NUM_DISTANCE_SHORT_CODES. */
52 #define BROTLI_WINDOW_GAP 16
53 #define BROTLI_MAX_BACKWARD_LIMIT(W) (((size_t)1 << (W)) - BROTLI_WINDOW_GAP)
54 
55 #endif  /* BROTLI_COMMON_CONSTANTS_H_ */
56