ref

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 4 Imported by: ? modules, 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 ref is a CPU PyroWave encoder and decoder in float32, the reference the GPU kernels are tested against. It follows the same steps as the shaders, in the same order, so their outputs agree up to floating point rounding.

Index

Constants

View Source
const (
	// MaxDrop is the most bit-planes rate control drops from a block; a drop
	// of MaxDrop removes the block.
	MaxDrop    = 16
	NumBuckets = 128
)

Rate control constants shared with the shaders.

Variables

View Source
var (
	BT709  = Matrix{0.2126, 0.0722}
	BT2020 = Matrix{0.2627, 0.0593}
)

Functions

func Bucket

func Bucket(dd float32, saving int) int

Bucket maps the distortion added per word saved to a log-scale bucket, about 1.5 dB apart.

func PSNR

func PSNR(a, b []byte) float64

PSNR compares two BGRA8 pictures over their colour channels, in dB.

func Threshold

func Threshold(hist []int, required int) (bucket, remaining int)

Threshold finds the bucket where cumulative savings first cover required words and how much of that bucket is still needed; -1 when nothing must be dropped.

Types

type Decoder

type Decoder struct {
	L *pyrowave.Layout

	// Header is the sequence header of the last frame decoded.
	Header pyrowave.SequenceHeader
	// contains filtered or unexported fields
}

Decoder is the CPU reference decoder.

func NewDecoder

func NewDecoder(w, h int, chroma420 bool, chunkLen int) (*Decoder, error)

func (*Decoder) Decode

func (d *Decoder) Decode(au []byte) (*Image, error)

Decode decodes one chunked frame.

func (*Decoder) DecodeRecords

func (d *Decoder) DecodeRecords(records []byte) *Image

DecodeRecords decodes block records laid end to end, as Encoder.Encode returns them, without chunk framing.

func (*Decoder) Parser

func (d *Decoder) Parser() *pyrowave.Parser

Parser exposes the record parser, for its counters.

type Encoder

type Encoder struct {
	L      *pyrowave.Layout
	Matrix Matrix
	Header pyrowave.SequenceHeader
	// Coefs[c][level][kind] holds every band, LL of each level included.
	Coefs [3][pyrowave.Levels][4][]float32

	// Drops is each block's dropped plane count from the last Encode.
	Drops []int
	// contains filtered or unexported fields
}

Encoder is the CPU reference encoder.

func NewEncoder

func NewEncoder(w, h int, chroma420 bool) (*Encoder, error)

func (*Encoder) Encode

func (e *Encoder) Encode(img *Image, budget int) []byte

Encode codes img in about budget bytes of records and returns the block records, in block order.

func (*Encoder) Transform

func (e *Encoder) Transform(img *Image)

Transform fills Coefs from img: clamp-to-edge padding to the aligned size, DC shift by -0.5, then the forward DWT.

type Image

type Image struct {
	Width, Height int
	Chroma420     bool
	Planes        [3][]float32
}

Image is a picture as three planes of samples in [0,1], each the size of the visible picture (chroma at half size under 4:2:0).

func FromBGRA8

func FromBGRA8(px []byte, w, h int, chroma420 bool, m Matrix) *Image

FromBGRA8 converts a tightly packed BGRA8 picture.

func FromRGB

func FromRGB(w, h int, chroma420 bool, m Matrix, rgb func(x, y int) (r, g, b float32)) *Image

FromRGB builds an image from a full-range RGB sampler; 4:2:0 chroma is the mean of each 2x2 quad (centre siting).

func (*Image) BGRA8

func (img *Image) BGRA8(m Matrix) []byte

BGRA8 renders the image to tightly packed BGRA8.

func (*Image) PlaneSize

func (img *Image) PlaneSize(c int) (int, int)

func (*Image) RGB

func (img *Image) RGB(x, y int, m Matrix) (r, g, b float32)

RGB returns the full-range RGB of pixel (x, y), upsampling 4:2:0 chroma bilinearly with centre siting.

type Matrix

type Matrix struct{ Kr, Kb float32 }

Matrix holds a YCbCr transform's luma weights.

func MatrixOf

func MatrixOf(code uint8) Matrix

func (Matrix) ToRGB

func (m Matrix) ToRGB(y, cb, cr float32) (r, g, b float32)

ToRGB is the inverse of ToYCbCr.

func (Matrix) ToYCbCr

func (m Matrix) ToYCbCr(r, g, b float32) (y, cb, cr float32)

ToYCbCr converts full-range RGB in [0,1] to Y, Cb, Cr in [0,1].

Jump to

Keyboard shortcuts

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