3.1.8.1.5.1 Zero Run-Length Encoding
Runs of zeros are encoded using the same techniques as RLGR. The KP state value defines the likelihood of encountering long runs of zeros.
The initial value of KP is 8.
K is defined as KP / 8 (rounded down) and indicates the number of bits that MUST be used to encode the number of zeros (nz).
If nz >= (1 << K) then:
One "0" bit is written
nz = nz - (1 << K)
KP = KP + 4; if KP > 80 then KP = 80
K = KP / 8
Repeat until nz < (1 << K)
Otherwise,
One "1" bit is written
The count of zeros is written using K bits
KP = KP - 6; if KP < 0 then KP = 0
K = KP / 8
Note that, contrary to RLGR, it is possible to encode a run of zeros with K = 0. If the length of the run is zero, a single "1" bit is written.