Ignite/decoder/y4m/y4m_test.go

82 lines
1.9 KiB
Go

package y4m
import (
"git.gammaspectra.live/S.O.N.G/Ignite/frame"
"git.gammaspectra.live/S.O.N.G/Ignite/testdata"
"testing"
)
func testDecode(sample testdata.TestSample, t *testing.T) {
reader, err := sample.Open(t)
if err != nil {
t.Fatal(err)
}
defer reader.Close()
var y4m *Decoder
switch sample.Type {
case "y4m":
y4m, err = NewDecoder(reader, nil)
case "y4m.xz":
y4m, err = NewXZCompressedDecoder(reader, nil)
default:
t.Fatal("unsupported sample type")
}
if err != nil {
t.Fatal(err)
} else {
defer y4m.Close()
decoded := 0
var frameProperties frame.Properties
for decodedFrame := range y4m.DecodeStream().Channel() {
if decoded == 0 {
frameProperties = decodedFrame.Properties()
}
//ingest
decoded++
if decoded%50 == 0 {
t.Logf("%d/%d", decoded, sample.Frames)
}
}
if decoded != sample.Frames {
t.Fatalf("expected %d frames, got %d", sample.Frames, decoded)
}
if frameProperties.Width != sample.Width {
t.Fatalf("expected %d width, got %d", sample.Width, frameProperties.Width)
}
if frameProperties.Height != sample.Height {
t.Fatalf("expected %d height, got %d", sample.Height, frameProperties.Height)
}
if frameProperties.ColorSpace.String() != sample.ColorSpace.String() {
t.Fatalf("expected %s color space, got %s", sample.ColorSpace.String(), frameProperties.ColorSpace.String())
}
}
}
func TestDecode_YUV420_720p24_8bit(t *testing.T) {
testDecode(testdata.Y4M_Sintel_Trailer_720p24_YUV420_8bit, t)
}
func TestDecode_YUV444_720p50_8bit(t *testing.T) {
testDecode(testdata.Y4M_Ducks_Take_Off_720p50_YUV444_8bit, t)
}
func TestDecode_YUV422_720p50_8bit(t *testing.T) {
testDecode(testdata.Y4M_Ducks_Take_Off_720p50_YUV422_8bit, t)
}
func TestDecode_YUV420_2160p60_10bit(t *testing.T) {
testDecode(testdata.Y4M_Netflix_FoodMarket_2160p60_YUV420_10bit, t)
}
func TestDecode_YUV420_360p24_8bit_xz(t *testing.T) {
testDecode(testdata.Y4M_Big_Buck_Bunny_360p24_YUV420_8bit, t)
}