Help us shape the future of Go! Take the 2026 Go Developer Survey

boolcoder

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2026 License: BSD-3-Clause Imports: 1 Imported by: 1

README

boolcoder

Pure-Go (CGO=0) boolean arithmetic decoder shared by VP8 and VP9

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

View Source
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

func NewDecoder(data []byte) *Decoder

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

func (d *Decoder) Bool(probability uint8) uint32

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

func (d *Decoder) Err() error

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.

func (*Decoder) Literal

func (d *Decoder) Literal(n int) uint32

Literal reads n raw bits, most significant first: n even chances in a row.

func (*Decoder) Signed

func (d *Decoder) Signed(n int) int32

Signed reads n raw bits and then a sign, which is how these formats state a value that can be negative.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL