pixelfxtest

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0, MIT Imports: 12 Imported by: 0 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 pixelfxtest checks the Go port of pixelfx against pixelfx itself: it renders an effect the way tools/pixelfxref renders it with pixelfx at the pinned commit, and compares the frames with the reference PNGs that tool wrote. Every category's tests call CheckEffect for each of its effects.

The cases and frames, the same on both sides:

  • "default": the effect with its default options, as a sprite sheet renders it (pixelfx.EachFrame), at the frames 25%, 50% and 75% of the way through it.
  • "flip": the same with Flip set.
  • "act", for an effect a character acts out: the performance (pixelfx.EachActFrame, 60 fps), at the first frame whose time reaches 25%, 50% and 75% of the way from the first pose to the end (two loops for a loop).

A reference is <case>-<frame>.png in the effect's testdata/ref/<name> directory, frame the 0-based frame index in three digits.

Index

Constants

View Source
const (
	MaxChannelDelta   = 2
	MaxDifferingShare = 0.005
)

The one tolerance every parity test uses. A pixel matches its reference when each of its RGBA channels is within MaxChannelDelta of the reference's; a frame matches when at most MaxDifferingShare of its pixels do not. JavaScript and Go compute the same float64 operations in the same order, but their sin, cos, atan2, exp and pow may differ in the last bit, and arm64 may fuse a multiply and an add; such a difference moves the odd pixel across a rounding edge, never a whole shape.

View Source
const ActFPS = 60

ActFPS is the frame rate the act case is rendered at.

Variables

View Source
var Samples = []float64{0.25, 0.5, 0.75}

Samples are the share of the way through an effect each sampled frame is.

Functions

func BenchmarkActFrames

func BenchmarkActFrames(b *testing.B, e *pixelfx.Effect)

BenchmarkActFrames measures performing e at ActFPS with the stock character and its target: each iteration updates the performance by one frame and draws it, so the allocations reported are per frame. It starts over when the performance ends, with the timer stopped, so starting a performance is not counted.

func BenchmarkFrames

func BenchmarkFrames(b *testing.B, e *pixelfx.Effect)

BenchmarkFrames measures playing e at its frame rate: each iteration updates it by one frame and draws the frame, so the allocations reported are per frame. It starts over when a one-shot ends, with the timer stopped, so starting a player is not counted.

func CheckDeterministic

func CheckDeterministic(t *testing.T, e *pixelfx.Effect)

CheckDeterministic renders every frame of e twice for each of its cases and fails t unless the two passes are the same to the byte. The cases are its default options, Flip, and, when its meta has them, a seed other than the default's and its palette reversed; an effect a character acts out is also performed twice with the default options and with that seed and palette.

func CheckEffect

func CheckEffect(t *testing.T, e *pixelfx.Effect, refDir string)

CheckEffect renders e and compares every frame with its reference in refDir (testdata/ref/<name>), failing t when a reference is missing, the wrong size, or differs beyond the tolerance, or when refDir holds a reference no case renders. Set PIXELFXTEST_OUT to a directory to have the frames that differ written there.

func ReadPNG

func ReadPNG(path string) (w, h int, pix []byte, err error)

ReadPNG reads a reference PNG as straight-alpha RGBA bytes.

func SheetSamples

func SheetSamples(n int) []int

SheetSamples returns the frames sampled from an effect's n sheet frames.

Types

type Diff

type Diff struct {
	Differing, Total int
	MaxDelta         int
	FirstX, FirstY   int
}

Diff is how a frame differs from its reference: how many pixels differ by more than MaxChannelDelta, out of how many, the largest channel difference, and where the first differing pixel is.

func Compare

func Compare(got, want []byte, w, h int) Diff

Compare returns how got differs from want, both RGBA bytes of a w x h frame.

func (Diff) OK

func (d Diff) OK() bool

OK reports whether the difference is within the tolerance.

type Frame

type Frame struct {
	Case  string
	Index int
	W, H  int
	Pix   []byte
}

Frame is one rendered frame: its case and index, its size, and its RGBA bytes (straight alpha).

func Render

func Render(e *pixelfx.Effect) []Frame

Render renders the frames of e that CheckEffect compares, in case order.

func (Frame) Name

func (f Frame) Name() string

Name returns the frame's reference file name.

Jump to

Keyboard shortcuts

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