rendering tests fixed
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
package generator
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestWGPUGenerator(t *testing.T) {
|
||||
func TestWGPUSMPTEPattern(t *testing.T) {
|
||||
const width, height = 1920, 1080
|
||||
g, err := NewWGPUGenerator(width, height, filepath.Join("..", "..", "kernels", "static", "smpteBars.wgsl"))
|
||||
if err != nil {
|
||||
@@ -22,46 +21,31 @@ func TestWGPUGenerator(t *testing.T) {
|
||||
t.Fatalf("GenerateFrame 2: %v", err)
|
||||
}
|
||||
|
||||
want := [7][3]uint32{
|
||||
{721, 512, 512}, {674, 176, 543}, {581, 589, 176},
|
||||
{534, 253, 207}, {251, 771, 817}, {204, 435, 848}, {111, 848, 481},
|
||||
tests := []struct {
|
||||
name string
|
||||
x, y int
|
||||
wantY, wantCb, wantCr uint32
|
||||
}{
|
||||
{"top left gray flank", 100, 100, 414, 512, 512},
|
||||
{"top white bar", 300, 100, 721, 512, 512},
|
||||
{"top green bar", 960, 100, 534, 253, 207},
|
||||
{"top right gray flank", 1800, 100, 414, 512, 512},
|
||||
{"section 2 cyan flank", 100, 650, 754, 615, 64},
|
||||
{"section 2 minus I", 300, 650, 244, 612, 395},
|
||||
{"section 2 white", 600, 650, 721, 512, 512},
|
||||
{"section 2 blue flank", 1800, 650, 127, 960, 471},
|
||||
{"section 3 yellow flank", 100, 750, 877, 64, 553},
|
||||
{"section 3 plus Q", 300, 750, 141, 697, 606},
|
||||
{"section 3 red flank", 1800, 750, 250, 409, 960},
|
||||
{"bottom gray flank", 100, 900, 195, 512, 512},
|
||||
}
|
||||
barOf := func(x int) int {
|
||||
if b := x * 7 / width; b < 7 {
|
||||
return b
|
||||
}
|
||||
return 6
|
||||
}
|
||||
for y := 0; y < height; y++ {
|
||||
for x := 0; x < width; x++ {
|
||||
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:])
|
||||
var yv, cb, cr uint32
|
||||
switch p % 6 {
|
||||
case 0:
|
||||
yv, cb, cr = (w0>>10)&0x3FF, w0&0x3FF, (w0>>20)&0x3FF
|
||||
case 1:
|
||||
yv = w1 & 0x3FF
|
||||
case 2:
|
||||
yv, cb, cr = (w1>>20)&0x3FF, (w1>>10)&0x3FF, w2&0x3FF
|
||||
case 3:
|
||||
yv = (w2 >> 10) & 0x3FF
|
||||
case 4:
|
||||
yv, cb, cr = w3&0x3FF, (w2>>20)&0x3FF, (w3>>10)&0x3FF
|
||||
case 5:
|
||||
yv = (w3 >> 20) & 0x3FF
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
y, cb, cr := sampleV210(buf, width, tt.x, tt.y)
|
||||
if y != tt.wantY || cb != tt.wantCb || cr != tt.wantCr {
|
||||
t.Fatalf("pixel (%d,%d): got %d/%d/%d, want %d/%d/%d",
|
||||
tt.x, tt.y, y, cb, cr, tt.wantY, tt.wantCb, tt.wantCr)
|
||||
}
|
||||
b := want[barOf(x)]
|
||||
if yv != b[0] {
|
||||
t.Fatalf("pixel (%d,%d): Y=%d want %d", x, y, yv, b[0])
|
||||
}
|
||||
if x%2 == 0 && (cb != b[1] || cr != b[2]) {
|
||||
t.Fatalf("pixel (%d,%d): Cb=%d Cr=%d want %d/%d", x, y, cb, cr, b[1], b[2])
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user