• 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 /* "Large Window Brotli" */
32 #define BROTLI_LARGE_MAX_DISTANCE_BITS 62U
33 #define BROTLI_LARGE_MIN_WBITS 10
34 #define BROTLI_LARGE_MAX_WBITS 30
35 
36 /* Specification: 4. Encoding of distances */
37 #define BROTLI_NUM_DISTANCE_SHORT_CODES 16
38 #define BROTLI_MAX_NPOSTFIX 3
39 #define BROTLI_MAX_NDIRECT 120
40 #define BROTLI_MAX_DISTANCE_BITS 24U
41 #define BROTLI_DISTANCE_ALPHABET_SIZE(NPOSTFIX, NDIRECT, MAXNBITS) ( \
42     BROTLI_NUM_DISTANCE_SHORT_CODES + (NDIRECT) +                    \
43     ((MAXNBITS) << ((NPOSTFIX) + 1)))
44 /* BROTLI_NUM_DISTANCE_SYMBOLS == 1128 */
45 #define BROTLI_NUM_DISTANCE_SYMBOLS \
46     BROTLI_DISTANCE_ALPHABET_SIZE(  \
47         BROTLI_MAX_NDIRECT, BROTLI_MAX_NPOSTFIX, BROTLI_LARGE_MAX_DISTANCE_BITS)
48 #define BROTLI_MAX_DISTANCE 0x3FFFFFC
49 #define BROTLI_MAX_ALLOWED_DISTANCE 0x7FFFFFFC
50 
51 /* 7.1. Context modes and context ID lookup for literals */
52 /* "context IDs for literals are in the range of 0..63" */
53 #define BROTLI_LITERAL_CONTEXT_BITS 6
54 
55 /* 7.2. Context ID for distances */
56 #define BROTLI_DISTANCE_CONTEXT_BITS 2
57 
58 /* 9.1. Format of the Stream Header */
59 /* Number of slack bytes for window size. Don't confuse
60    with BROTLI_NUM_DISTANCE_SHORT_CODES. */
61 #define BROTLI_WINDOW_GAP 16
62 #define BROTLI_MAX_BACKWARD_LIMIT(W) (((size_t)1 << (W)) - BROTLI_WINDOW_GAP)
63 
64 #endif  /* BROTLI_COMMON_CONSTANTS_H_ */
65