constants.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* Copyright 2016 Google Inc. All Rights Reserved.
  2. Distributed under MIT license.
  3. See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
  4. */
  5. #ifndef BROTLI_COMMON_CONSTANTS_H_
  6. #define BROTLI_COMMON_CONSTANTS_H_
  7. /* Specification: 7.3. Encoding of the context map */
  8. #define BROTLI_CONTEXT_MAP_MAX_RLE 16
  9. /* Specification: 2. Compressed representation overview */
  10. #define BROTLI_MAX_NUMBER_OF_BLOCK_TYPES 256
  11. /* Specification: 3.3. Alphabet sizes: insert-and-copy length */
  12. #define BROTLI_NUM_LITERAL_SYMBOLS 256
  13. #define BROTLI_NUM_COMMAND_SYMBOLS 704
  14. #define BROTLI_NUM_BLOCK_LEN_SYMBOLS 26
  15. #define BROTLI_MAX_CONTEXT_MAP_SYMBOLS (BROTLI_MAX_NUMBER_OF_BLOCK_TYPES + \
  16. BROTLI_CONTEXT_MAP_MAX_RLE)
  17. #define BROTLI_MAX_BLOCK_TYPE_SYMBOLS (BROTLI_MAX_NUMBER_OF_BLOCK_TYPES + 2)
  18. /* Specification: 3.5. Complex prefix codes */
  19. #define BROTLI_REPEAT_PREVIOUS_CODE_LENGTH 16
  20. #define BROTLI_REPEAT_ZERO_CODE_LENGTH 17
  21. #define BROTLI_CODE_LENGTH_CODES (BROTLI_REPEAT_ZERO_CODE_LENGTH + 1)
  22. /* "code length of 8 is repeated" */
  23. #define BROTLI_INITIAL_REPEATED_CODE_LENGTH 8
  24. /* "Large Window Brotli" */
  25. #define BROTLI_LARGE_MAX_DISTANCE_BITS 62U
  26. #define BROTLI_LARGE_MIN_WBITS 10
  27. #define BROTLI_LARGE_MAX_WBITS 30
  28. /* Specification: 4. Encoding of distances */
  29. #define BROTLI_NUM_DISTANCE_SHORT_CODES 16
  30. #define BROTLI_MAX_NPOSTFIX 3
  31. #define BROTLI_MAX_NDIRECT 120
  32. #define BROTLI_MAX_DISTANCE_BITS 24U
  33. #define BROTLI_DISTANCE_ALPHABET_SIZE(NPOSTFIX, NDIRECT, MAXNBITS) ( \
  34. BROTLI_NUM_DISTANCE_SHORT_CODES + (NDIRECT) + \
  35. ((MAXNBITS) << ((NPOSTFIX) + 1)))
  36. /* BROTLI_NUM_DISTANCE_SYMBOLS == 1128 */
  37. #define BROTLI_NUM_DISTANCE_SYMBOLS \
  38. BROTLI_DISTANCE_ALPHABET_SIZE( \
  39. BROTLI_MAX_NDIRECT, BROTLI_MAX_NPOSTFIX, BROTLI_LARGE_MAX_DISTANCE_BITS)
  40. #define BROTLI_MAX_DISTANCE 0x3FFFFFC
  41. #define BROTLI_MAX_ALLOWED_DISTANCE 0x7FFFFFFC
  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. /* 7.2. Context ID for distances */
  46. #define BROTLI_DISTANCE_CONTEXT_BITS 2
  47. /* 9.1. Format of the Stream Header */
  48. /* Number of slack bytes for window size. Don't confuse
  49. with BROTLI_NUM_DISTANCE_SHORT_CODES. */
  50. #define BROTLI_WINDOW_GAP 16
  51. #define BROTLI_MAX_BACKWARD_LIMIT(W) (((size_t)1 << (W)) - BROTLI_WINDOW_GAP)
  52. #endif /* BROTLI_COMMON_CONSTANTS_H_ */