constants.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package brotli
  2. /* Copyright 2016 Google Inc. All Rights Reserved.
  3. Distributed under MIT license.
  4. See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
  5. */
  6. /* Specification: 7.3. Encoding of the context map */
  7. const contextMapMaxRle = 16
  8. /* Specification: 2. Compressed representation overview */
  9. const maxNumberOfBlockTypes = 256
  10. /* Specification: 3.3. Alphabet sizes: insert-and-copy length */
  11. const numLiteralSymbols = 256
  12. const numCommandSymbols = 704
  13. const numBlockLenSymbols = 26
  14. const maxContextMapSymbols = (maxNumberOfBlockTypes + contextMapMaxRle)
  15. const maxBlockTypeSymbols = (maxNumberOfBlockTypes + 2)
  16. /* Specification: 3.5. Complex prefix codes */
  17. const repeatPreviousCodeLength = 16
  18. const repeatZeroCodeLength = 17
  19. const codeLengthCodes = (repeatZeroCodeLength + 1)
  20. /* "code length of 8 is repeated" */
  21. const initialRepeatedCodeLength = 8
  22. /* "Large Window Brotli" */
  23. const largeMaxDistanceBits = 62
  24. const largeMinWbits = 10
  25. const largeMaxWbits = 30
  26. /* Specification: 4. Encoding of distances */
  27. const numDistanceShortCodes = 16
  28. const maxNpostfix = 3
  29. const maxNdirect = 120
  30. const maxDistanceBits = 24
  31. func distanceAlphabetSize(NPOSTFIX uint, NDIRECT uint, MAXNBITS uint) uint {
  32. return numDistanceShortCodes + NDIRECT + uint(MAXNBITS<<(NPOSTFIX+1))
  33. }
  34. /* numDistanceSymbols == 1128 */
  35. const numDistanceSymbols = 1128
  36. const maxDistance = 0x3FFFFFC
  37. const maxAllowedDistance = 0x7FFFFFFC
  38. /* 7.1. Context modes and context ID lookup for literals */
  39. /* "context IDs for literals are in the range of 0..63" */
  40. const literalContextBits = 6
  41. /* 7.2. Context ID for distances */
  42. const distanceContextBits = 2
  43. /* 9.1. Format of the Stream Header */
  44. /* Number of slack bytes for window size. Don't confuse
  45. with BROTLI_NUM_DISTANCE_SHORT_CODES. */
  46. const windowGap = 16
  47. func maxBackwardLimit(W uint) uint {
  48. return (uint(1) << W) - windowGap
  49. }