Clarify Section 7.3

* Acknowledge the fact that the context map is conceptually really a
two-dimensional matrix with 2 different keys, but in reality stored
as a one-dimensional array.

* Remove mention of how NTREES is encoded. It becomes very obvious
later on, and doesn't really fit what the subsequent text is about.

* Mention that InverseMoveToFrontTransform will not cause the
context map to have invalid indexes. This gives someone implementing
a decoder sanity that they do not have to go through the context
map again and check that all values are less than NTREES.
This commit is contained in:
Joe Tsai
2015-10-28 20:04:55 -07:00
parent f9f173cde1
commit 4d375a2f4e

View File

@@ -1224,11 +1224,18 @@ context map is an integer between 0 and 255, indicating the index
of the prefix code to be used when encoding the next literal or
distance.
The context map is encoded as a one-dimensional array,
CMAPL[0..(64 * NBLTYPESL - 1)] and CMAPD[0..(4 * NBLTYPESD - 1)].
The context maps are conceptually two-dimensional matrices, mapping
a block type and a context ID to the index of the prefix code.
However, in reality, the context maps are encoded as
one-dimensional arrays:
.nf
CMAPL[0..(64 * NBLTYPESL - 1)]
CMAPD[0..(4 * NBLTYPESD - 1)]
.fi
The index of the prefix code for encoding a literal or distance
code with context ID, CIDx, and block type, BTYPE_x, is:
code with block type, BTYPE_x, and context ID, CIDx, is:
.nf
index of literal prefix code = CMAPL[64 * BTYPE_L + CIDL]
@@ -1282,9 +1289,8 @@ for literal and distance context maps):
Note that RLEMAX may be larger than the value necessary to represent
the longest sequence of zero values.
For the encoding of NTREES see Section 9.2. We define the
inverse move-to-front transform used in this specification by the
following C language function:
We define the inverse move-to-front transform used in this specification
by the following C language function:
.nf
void InverseMoveToFrontTransform(uint8_t* v, int v_len) {
@@ -1305,6 +1311,15 @@ following C language function:
}
.fi
Let max(v) be the largest value in the input array, v. Prior to calling
the inverse move-to-front transform, we can be assured that max(v) will
be less than NTREES since the prefix code above can only fill the map
with values 0..(NTREES - 1). Also, the inverse move-to-front transform
is guaranteed to produce new values in the array, v, that are less than
or equal to the original max(v). Thus, we can conclude that calling
InverseMoveToFrontTransform will not produce an invalid index to a
literal or distance prefix code.
.ti 0
8. Static dictionary