brotli/constants.go

78 lines
1.9 KiB
Go
Raw Normal View History

package brotli
/* Copyright 2016 Google Inc. All Rights Reserved.
Distributed under MIT license.
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
*/
/* Specification: 7.3. Encoding of the context map */
2019-03-15 22:05:31 +03:00
const contextMapMaxRle = 16
/* Specification: 2. Compressed representation overview */
2019-03-15 22:05:31 +03:00
const maxNumberOfBlockTypes = 256
/* Specification: 3.3. Alphabet sizes: insert-and-copy length */
2019-03-15 22:05:31 +03:00
const numLiteralSymbols = 256
2019-03-15 22:05:31 +03:00
const numCommandSymbols = 704
2019-03-15 22:05:31 +03:00
const numBlockLenSymbols = 26
2019-03-15 22:05:31 +03:00
const maxContextMapSymbols = (maxNumberOfBlockTypes + contextMapMaxRle)
2019-03-15 22:05:31 +03:00
const maxBlockTypeSymbols = (maxNumberOfBlockTypes + 2)
/* Specification: 3.5. Complex prefix codes */
2019-03-15 22:05:31 +03:00
const repeatPreviousCodeLength = 16
2019-03-15 22:05:31 +03:00
const repeatZeroCodeLength = 17
2019-03-15 22:05:31 +03:00
const codeLengthCodes = (repeatZeroCodeLength + 1)
/* "code length of 8 is repeated" */
2019-03-15 22:05:31 +03:00
const initialRepeatedCodeLength = 8
/* "Large Window Brotli" */
2019-03-15 22:05:31 +03:00
const largeMaxDistanceBits = 62
2019-03-15 22:05:31 +03:00
const largeMinWbits = 10
2019-03-15 22:05:31 +03:00
const largeMaxWbits = 30
/* Specification: 4. Encoding of distances */
2019-03-15 22:05:31 +03:00
const numDistanceShortCodes = 16
2019-03-15 22:05:31 +03:00
const maxNpostfix = 3
2019-03-15 22:05:31 +03:00
const maxNdirect = 120
2019-03-15 22:05:31 +03:00
const maxDistanceBits = 24
2019-03-15 22:05:31 +03:00
func distanceAlphabetSize(NPOSTFIX uint, NDIRECT uint, MAXNBITS uint) uint {
return numDistanceShortCodes + NDIRECT + uint(MAXNBITS<<(NPOSTFIX+1))
}
2019-03-15 22:05:31 +03:00
/* numDistanceSymbols == 1128 */
const numDistanceSymbols = 1128
2019-03-16 03:24:40 +03:00
const maxDistance = 0x3FFFFFC
2019-03-16 03:24:40 +03:00
const maxAllowedDistance = 0x7FFFFFFC
/* 7.1. Context modes and context ID lookup for literals */
/* "context IDs for literals are in the range of 0..63" */
2019-03-16 03:24:40 +03:00
const literalContextBits = 6
/* 7.2. Context ID for distances */
2019-03-16 03:24:40 +03:00
const distanceContextBits = 2
/* 9.1. Format of the Stream Header */
/* Number of slack bytes for window size. Don't confuse
with BROTLI_NUM_DISTANCE_SHORT_CODES. */
2019-03-16 03:24:40 +03:00
const windowGap = 16
2019-03-16 03:24:40 +03:00
func maxBackwardLimit(W uint) uint {
return (uint(1) << W) - windowGap
}