boolcoder

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: BSD-2-Clause Imports: 0 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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 NewReader

func NewReader(buf []byte) *Reader

NewReader initialises a boolean decoder over buf.

func (*Reader) ReadBit

func (r *Reader) ReadBit() int

ReadBit decodes one equiprobable bit (prob 128).

func (*Reader) ReadBool

func (r *Reader) ReadBool(prob uint8) int

ReadBool decodes one boolean with probability prob (1..255 = P(0)*256).

func (*Reader) ReadLiteral

func (r *Reader) ReadLiteral(n int) uint32

ReadLiteral decodes an n-bit unsigned value MSB-first (equiprobable bits).

func (*Reader) ReadSigned

func (r *Reader) ReadSigned(n int) int32

ReadSigned decodes an n-bit magnitude followed by a sign bit (1 = negative).

func (*Reader) ReadTree

func (r *Reader) ReadTree(tree []int8, probs []uint8) int

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

func (r *Reader) ReadTreeCount(tree []int8, probs []uint8, counts [][2]uint32) int

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).

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 NewWriter

func NewWriter() *Writer

NewWriter returns an empty encoder.

func (*Writer) Bytes

func (w *Writer) Bytes() []byte

Bytes flushes the coder and returns the encoded buffer.

func (*Writer) WriteBit

func (w *Writer) WriteBit(bit int)

WriteBit encodes one equiprobable bit.

func (*Writer) WriteBool

func (w *Writer) WriteBool(prob uint8, bit int)

WriteBool encodes one boolean with probability prob (1..255 = P(0)*256).

func (*Writer) WriteLiteral

func (w *Writer) WriteLiteral(v uint32, n int)

WriteLiteral encodes an n-bit value MSB-first (equiprobable bits).

Jump to

Keyboard shortcuts

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