/* Copyright 2016 Google Inc. All Rights Reserved. Distributed under MIT license. See file LICENSE for detail or copy at https://opensource.org/licenses/MIT */ /** * @file * Common constants used in decoder and encoder API. */ #ifndef BROTLI_COMMON_CONSTANTS_H_ #define BROTLI_COMMON_CONSTANTS_H_ #include <brotli/port.h> #include <brotli/types.h> #include "platform.h" /* Specification: 7.3. Encoding of the context map */ #define BROTLI_CONTEXT_MAP_MAX_RLE … /* Specification: 2. Compressed representation overview */ #define BROTLI_MAX_NUMBER_OF_BLOCK_TYPES … /* Specification: 3.3. Alphabet sizes: insert-and-copy length */ #define BROTLI_NUM_LITERAL_SYMBOLS … #define BROTLI_NUM_COMMAND_SYMBOLS … #define BROTLI_NUM_BLOCK_LEN_SYMBOLS … #define BROTLI_MAX_CONTEXT_MAP_SYMBOLS … #define BROTLI_MAX_BLOCK_TYPE_SYMBOLS … /* Specification: 3.5. Complex prefix codes */ #define BROTLI_REPEAT_PREVIOUS_CODE_LENGTH … #define BROTLI_REPEAT_ZERO_CODE_LENGTH … #define BROTLI_CODE_LENGTH_CODES … /* "code length of 8 is repeated" */ #define BROTLI_INITIAL_REPEATED_CODE_LENGTH … /* "Large Window Brotli" */ /** * The theoretical maximum number of distance bits specified for large window * brotli, for 64-bit encoders and decoders. Even when in practice 32-bit * encoders and decoders only support up to 30 max distance bits, the value is * set to 62 because it affects the large window brotli file format. * Specifically, it affects the encoding of simple huffman tree for distances, * see Specification RFC 7932 chapter 3.4. */ #define BROTLI_LARGE_MAX_DISTANCE_BITS … #define BROTLI_LARGE_MIN_WBITS … /** * The maximum supported large brotli window bits by the encoder and decoder. * Large window brotli allows up to 62 bits, however the current encoder and * decoder, designed for 32-bit integers, only support up to 30 bits maximum. */ #define BROTLI_LARGE_MAX_WBITS … /* Specification: 4. Encoding of distances */ #define BROTLI_NUM_DISTANCE_SHORT_CODES … /** * Maximal number of "postfix" bits. * * Number of "postfix" bits is stored as 2 bits in meta-block header. */ #define BROTLI_MAX_NPOSTFIX … #define BROTLI_MAX_NDIRECT … #define BROTLI_MAX_DISTANCE_BITS … #define BROTLI_DISTANCE_ALPHABET_SIZE(NPOSTFIX, NDIRECT, MAXNBITS) … /* BROTLI_NUM_DISTANCE_SYMBOLS == 1128 */ #define BROTLI_NUM_DISTANCE_SYMBOLS … /* ((1 << 26) - 4) is the maximal distance that can be expressed in RFC 7932 brotli stream using NPOSTFIX = 0 and NDIRECT = 0. With other NPOSTFIX and NDIRECT values distances up to ((1 << 29) + 88) could be expressed. */ #define BROTLI_MAX_DISTANCE … /* ((1 << 31) - 4) is the safe distance limit. Using this number as a limit allows safe distance calculation without overflows, given the distance alphabet size is limited to corresponding size (see kLargeWindowDistanceCodeLimits). */ #define BROTLI_MAX_ALLOWED_DISTANCE … /* Specification: 4. Encoding of Literal Insertion Lengths and Copy Lengths */ #define BROTLI_NUM_INS_COPY_CODES … /* 7.1. Context modes and context ID lookup for literals */ /* "context IDs for literals are in the range of 0..63" */ #define BROTLI_LITERAL_CONTEXT_BITS … /* 7.2. Context ID for distances */ #define BROTLI_DISTANCE_CONTEXT_BITS … /* 9.1. Format of the Stream Header */ /* Number of slack bytes for window size. Don't confuse with BROTLI_NUM_DISTANCE_SHORT_CODES. */ #define BROTLI_WINDOW_GAP … #define BROTLI_MAX_BACKWARD_LIMIT(W) … BrotliDistanceCodeLimit; /* This function calculates maximal size of distance alphabet, such that the distances greater than the given values can not be represented. This limits are designed to support fast and safe 32-bit decoders. "32-bit" means that signed integer values up to ((1 << 31) - 1) could be safely expressed. Brotli distance alphabet symbols do not represent consecutive distance ranges. Each distance alphabet symbol (excluding direct distances and short codes), represent interleaved (for NPOSTFIX > 0) range of distances. A "group" of consecutive (1 << NPOSTFIX) symbols represent non-interleaved range. Two consecutive groups require the same amount of "extra bits". It is important that distance alphabet represents complete "groups". To avoid complex logic on encoder side about interleaved ranges it was decided to restrict both sides to complete distance code "groups". */ BROTLI_UNUSED_FUNCTION BrotliDistanceCodeLimit BrotliCalculateDistanceCodeLimit( uint32_t max_distance, uint32_t npostfix, uint32_t ndirect) { … } /* Represents the range of values belonging to a prefix code: [offset, offset + 2^nbits) */ BrotliPrefixCodeRange; /* "Soft-private", it is exported, but not "advertised" as API. */ BROTLI_COMMON_API extern const BrotliPrefixCodeRange _kBrotliPrefixCodeRanges[BROTLI_NUM_BLOCK_LEN_SYMBOLS]; #endif /* BROTLI_COMMON_CONSTANTS_H_ */