Documentation
¶
Overview ¶
Package boolcoder implements the VP9 boolean arithmetic coder — the entropy layer underneath every VP9 syntax element. This is the decoder (Reader) plus a matching encoder (Writer, see encoder.go) so the two can be roundtrip-tested bit-exactly without an external reference.
Probabilities are 8-bit: prob = P(bit == 0) scaled to 256 (so 128 ≈ 50/50). Original implementation of the standard range/probability arithmetic decoding described in the public VP9 specification (§9.2).
Index ¶
- type Reader
- func (r *Reader) BitPos() int
- func (r *Reader) Overread() bool
- func (r *Reader) ReadBit() int
- func (r *Reader) ReadBool(prob uint8) int
- func (r *Reader) ReadBoolT(prob uint8, label string) int
- func (r *Reader) ReadLiteral(n int) uint32
- func (r *Reader) ReadSigned(n int) int32
- func (r *Reader) ReadTree(tree []int8, probs []uint8) int
- func (r *Reader) ReadTreeCount(tree []int8, probs []uint8, counts [][2]uint32) int
- func (r *Reader) SetLabel(s string)
- func (r *Reader) State() (rng uint32, topByte uint8)
- func (r *Reader) TraceN(n int, fn TraceFunc)
- type TraceFunc
- type Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader decodes booleans from a VP9-coded byte slice.
func NewReaderVP9 ¶ added in v0.2.0
NewReaderVP9 initialises a boolean decoder over a real VP9 bitstream partition (the compressed header or a tile). VP9's init_bool consumes one leading marker bit after loading the value window (libvpx vpx_reader_init ends with vpx_read_bit) — this constructor reads and discards it so subsequent reads align with the stream. Use NewReader (no marker) for the encoder roundtrip.
func (*Reader) BitPos ¶ added in v0.2.0
BitPos returns the number of bits consumed from the buffer so far.
func (*Reader) Overread ¶ added in v0.2.0
Overread reports whether the decoder has consumed more bits than the buffer contained — i.e. the bool window has drained past the end of the partition. In a valid stream the trailing padding keeps bitsAvl >= 0 through the final symbol, so a negative value means an entropy desync (or a truncated tile). Callers use this after a tile/partition to reject a corrupt frame instead of reconstructing garbage pixels.
func (*Reader) ReadBoolT ¶ added in v0.2.0
ReadBoolT is ReadBool with mandatory tracing (for explicit call sites).
func (*Reader) ReadLiteral ¶
ReadLiteral decodes an n-bit unsigned value MSB-first (equiprobable bits).
func (*Reader) ReadSigned ¶
ReadSigned decodes an n-bit magnitude followed by a sign bit (1 = negative).
func (*Reader) ReadTree ¶
ReadTree walks a VP9 token tree: tree is the flattened left/right index array, probs are the per-node probabilities. Returns the decoded (negated-leaf) token.
func (*Reader) ReadTreeCount ¶
ReadTreeCount is ReadTree with per-node binary count accumulation. counts[nodeIdx][bit]++ for each tree node visited. Pass nil counts to skip counting (identical to ReadTree).
func (*Reader) SetLabel ¶ added in v0.2.0
traceLabel is the next-op label (set by SetLabel, consumed on ReadBool).
type TraceFunc ¶ added in v0.2.0
TraceFunc is called for each ReadBool when tracing is active. label: caller-supplied context; prob: boolean prob; rng: range before read; top: value[63:56] before read; split: threshold; bit: decoded bit (0 or 1).
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer is a VP9 boolean arithmetic encoder. It exists so the decoder can be roundtrip-tested bit-exactly (encode a sequence, decode it back, compare) with no external dependency. It implements the same split/renormalise arithmetic as the decoder, with standard carry-propagating byte emission.
func (*Writer) WriteLiteral ¶
WriteLiteral encodes an n-bit value MSB-first (equiprobable bits).