Documentation
¶
Overview ¶
Package boolcoder decodes the boolean arithmetic coding that VP8 and VP9 carry everything but their frame headers in, in pure Go.
It is to the VPx family what a bit reader is to the H.26x family: the one mechanism every part above it goes through, shared so that neither codec has to own it and neither depends on the other.
⛔ One engine serves both, and that is measured rather than assumed. The two specifications state the split point differently --
VP8: 1 + (((range-1) * probability) >> 8) VP9: (range * probability + (256 - probability)) >> 8
-- and they are the same expression: adding 256 before a shift of eight is adding one after it, so the two agree for every one of the 32768 pairs of range and probability that can occur. A test asserts that over all of them, because a shared engine resting on an unchecked equivalence would be a shared defect.
AV1 is NOT served by this. Its coder carries probabilities on fifteen bits and normalises differently; it belongs beside this rather than inside it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrExhausted = errors.New("boolcoder: read past the end of the partition")
ErrExhausted means the decoder read past the end of its data.
It is reported rather than hidden because a bitstream that ends early is a bitstream that was cut, and a decoder handed zeros past the end would go on producing plausible symbols from nothing.
Functions ¶
This section is empty.
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder reads symbols from one arithmetic-coded partition.
func NewDecoder ¶
NewDecoder starts reading data.
The state it begins in is what the format states: a range of the whole byte, an empty window, and a count that makes the first read fill it.
func (*Decoder) Bool ¶
Bool reads one bit whose chance of being zero is probability out of 256.
The probability is what the model above this supplies; a probability of 128 is an even chance and makes this read a raw bit.
func (*Decoder) Err ¶
Err reports whether any symbol read so far came from past the end of the data.
It is asked at the END of a partition rather than after each symbol: the arithmetic cannot stop mid-symbol, so the question is whether the partition was long enough for everything that was read from it, and that is only answerable once the reading is done.