rendering tests fixed

This commit is contained in:
Dmitry Sergeev
2026-09-16 23:58:45 +03:00
parent 6fa3dea391
commit eeb13c3bd4
6 changed files with 159 additions and 120 deletions
+10 -33
View File
@@ -1,7 +1,6 @@
package generator
import (
"encoding/binary"
"path/filepath"
"testing"
)
@@ -15,28 +14,6 @@ func TestWGPUMoveSquare(t *testing.T) {
defer g.Close()
buf := make([]byte, width*height*8/3)
sample := func(x, y int) (yc, cb, cr uint32) {
p := y*width + x
off := (p / 6) * 16
w0 := binary.LittleEndian.Uint32(buf[off:])
w1 := binary.LittleEndian.Uint32(buf[off+4:])
w2 := binary.LittleEndian.Uint32(buf[off+8:])
w3 := binary.LittleEndian.Uint32(buf[off+12:])
switch p % 6 {
case 0:
return (w0 >> 10) & 0x3FF, w0 & 0x3FF, (w0 >> 20) & 0x3FF
case 1:
return w1 & 0x3FF, w0 & 0x3FF, (w0 >> 20) & 0x3FF
case 2:
return (w1 >> 20) & 0x3FF, (w1 >> 10) & 0x3FF, w2 & 0x3FF
case 3:
return (w2 >> 10) & 0x3FF, (w1 >> 10) & 0x3FF, w2 & 0x3FF
case 4:
return w3 & 0x3FF, (w2 >> 20) & 0x3FF, (w3 >> 10) & 0x3FF
default:
return (w3 >> 20) & 0x3FF, (w2 >> 20) & 0x3FF, (w3 >> 10) & 0x3FF
}
}
// square center x=960 sits on the green bar (534/253/207):
// inverted -> Y=1004-534=470, Cb=1024-253=771, Cr=1024-207=817
@@ -47,28 +24,28 @@ func TestWGPUMoveSquare(t *testing.T) {
if err := g.GenerateFrame(buf, 0); err != nil {
t.Fatalf("tick 0: %v", err)
}
if y, cb, cr := sample(960, 540); y != invY || cb != invCb || cr != invCr {
if y, cb, cr := sampleV210(buf, width, 960, 540); y != invY || cb != invCb || cr != invCr {
t.Fatalf("tick 0 center: got %d/%d/%d, want inverted green 470/771/817", y, cb, cr)
}
if y, _, _ := sample(860, 540); y != greenY {
if y, _, _ := sampleV210(buf, width, 860, 540); y != greenY {
t.Fatalf("tick 0 left of square: Y=%d, want green %d", y, greenY)
}
// amplitude = centerX - half = 885: tick 79 (sin~1) puts the square at
// the far right, x in [1770,1920), over the blue bar (111/848/481):
// inverted -> Y=1004-111=893, Cb=1024-848=176, Cr=1024-481=543
const invBlueY, invBlueCb, invBlueCr = 893, 176, 543
// the far right, x in [1770,1920), over the gray side panel
// (414/512/512): inverted -> 590/512/512.
const invFlankY, invFlankCb, invFlankCr = 590, 512, 512
if err := g.GenerateFrame(buf, 79); err != nil {
t.Fatalf("tick 79: %v", err)
}
if y, cb, cr := sample(1840, 540); y != invBlueY || cb != invBlueCb || cr != invBlueCr {
t.Fatalf("tick 79 shifted center: got %d/%d/%d, want inverted blue 893/176/543", y, cb, cr)
if y, cb, cr := sampleV210(buf, width, 1840, 540); y != invFlankY || cb != invFlankCb || cr != invFlankCr {
t.Fatalf("tick 79 shifted center: got %d/%d/%d, want inverted gray 590/512/512", y, cb, cr)
}
if y, _, _ := sample(960, 540); y != greenY {
if y, _, _ := sampleV210(buf, width, 960, 540); y != greenY {
t.Fatalf("tick 79 old center: Y=%d, want green %d (square moved away)", y, greenY)
}
// bars untouched far from the square
if y, _, _ := sample(100, 100); y != 721 {
t.Fatalf("tick 79 bars: Y=%d, want white 721", y)
if y, _, _ := sampleV210(buf, width, 100, 100); y != 414 {
t.Fatalf("tick 79 bars: Y=%d, want gray flank 414", y)
}
}