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 /* Distance that is guaranteed to be representable in any stream. */ 42 #define BROTLI_MAX_DISTANCE 0x3FFFFFC 43 44 /* 7.1. Context modes and context ID lookup for literals */ 45 /* "context IDs for literals are in the range of 0..63" */ 46 #define BROTLI_LITERAL_CONTEXT_BITS 6 47 48 /* 7.2. Context ID for distances */ 49 #define BROTLI_DISTANCE_CONTEXT_BITS 2 50 51 /* 9.1. Format of the Stream Header */ 52 /* Number of slack bytes for window size. Don't confuse 53 with BROTLI_NUM_DISTANCE_SHORT_CODES. */ 54 #define BROTLI_WINDOW_GAP 16 55 #define BROTLI_MAX_BACKWARD_LIMIT(W) (((size_t)1 << (W)) - BROTLI_WINDOW_GAP) 56 57 #endif /* BROTLI_COMMON_CONSTANTS_H_ */ 58