/* ((1 << 26) - 4) is the maximal distance that can be expressed in RFC 7932 brotlistreamusingNPOSTFIX=0andNDIRECT=0.WithotherNPOSTFIXand
NDIRECT values distances up to ((1 << 29) + 88) could be expressed. */ #define BROTLI_MAX_DISTANCE 0x3FFFFFC
/* ((1 << 31) - 4) is the safe distance limit. Using this number as a limit allowssafedistancecalculationwithoutoverflows,giventhedistance alphabetsizeislimitedtocorrespondingsize
(see kLargeWindowDistanceCodeLimits). */ #define BROTLI_MAX_ALLOWED_DISTANCE 0x7FFFFFFC
/* Specification: 4. Encoding of Literal Insertion Lengths and Copy Lengths */ #define BROTLI_NUM_INS_COPY_CODES 24
/* 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 6
/* 7.2. Context ID for distances */ #define BROTLI_DISTANCE_CONTEXT_BITS 2
/* 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 16 #define BROTLI_MAX_BACKWARD_LIMIT(W) (((size_t)1 << (W)) - BROTLI_WINDOW_GAP)
Itisimportantthatdistancealphabetrepresentscomplete"groups". Toavoidcomplexlogiconencodersideaboutinterleavedranges itwasdecidedtorestrictbothsidestocompletedistancecode"groups".
*/
BROTLI_UNUSED_FUNCTION BrotliDistanceCodeLimit BrotliCalculateDistanceCodeLimit(
uint32_t max_distance, uint32_t npostfix, uint32_t ndirect) {
BrotliDistanceCodeLimit result; /* Marking this function as unused, because not all files
including "constants.h" use it -> compiler warns about that. */
BROTLI_UNUSED(&BrotliCalculateDistanceCodeLimit); if (max_distance <= ndirect) { /* This case never happens / exists only for the sake of completeness. */
result.max_alphabet_size = max_distance + BROTLI_NUM_DISTANCE_SHORT_CODES;
result.max_distance = max_distance; return result;
} else { /* The first prohibited value. */
uint32_t forbidden_distance = max_distance + 1; /* Subtract "directly" encoded region. */
uint32_t offset = forbidden_distance - ndirect - 1;
uint32_t ndistbits = 0;
uint32_t tmp;
uint32_t half;
uint32_t group; /* Postfix for the last dcode in the group. */
uint32_t postfix = (1u << npostfix) - 1;
uint32_t extra;
uint32_t start; /* Remove postfix and "head-start". */
offset = (offset >> npostfix) + 4; /* Calculate the number of distance bits. */
tmp = offset / 2; /* Poor-man's log2floor, to avoid extra dependencies. */ while (tmp != 0) {ndistbits++; tmp = tmp >> 1;} /* One bit is covered with subrange addressing ("half"). */
ndistbits--; /* Find subrange. */
half = (offset >> ndistbits) & 1; /* Calculate the "group" part of dcode. */
group = ((ndistbits - 1) << 1) | half; /* Calculated "group" covers the prohibited distance value. */ if (group == 0) { /* This case is added for correctness; does not occur for limit > 128. */
result.max_alphabet_size = ndirect + BROTLI_NUM_DISTANCE_SHORT_CODES;
result.max_distance = ndirect; return result;
} /* Decrement "group", so it is the last permitted "group". */
group--; /* After group was decremented, ndistbits and half must be recalculated. */
ndistbits = (group >> 1) + 1; /* The last available distance in the subrange has all extra bits set. */
extra = (1u << ndistbits) - 1; /* Calculate region start. NB: ndistbits >= 1. */
start = (1u << (ndistbits + 1)) - 4; /* Move to subregion. */
start += (group & 1) << ndistbits; /* Calculate the alphabet size. */
result.max_alphabet_size = ((group << npostfix) | postfix) + ndirect +
BROTLI_NUM_DISTANCE_SHORT_CODES + 1; /* Calculate the maximal distance representable by alphabet. */
result.max_distance = ((start + extra) << npostfix) + postfix + ndirect + 1; return result;
}
}
/* Represents the range of values belonging to a prefix code:
[offset, offset + 2^nbits) */ typedefstruct {
uint16_t offset;
uint8_t nbits;
} BrotliPrefixCodeRange;
/* "Soft-private", it is exported, but not "advertised" as API. */
BROTLI_COMMON_API externconst BROTLI_MODEL("small")
BrotliPrefixCodeRange _kBrotliPrefixCodeRanges[BROTLI_NUM_BLOCK_LEN_SYMBOLS];
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.