alpha patterns
This commit is contained in:
@@ -2,6 +2,7 @@ package generator
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -30,6 +31,46 @@ func TestV210Sizes(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAlphaSizes(t *testing.T) {
|
||||
tests := []struct {
|
||||
width int
|
||||
height int
|
||||
lineSize int
|
||||
frameSize int
|
||||
v210aSize int
|
||||
}{
|
||||
{
|
||||
width: 1920, height: 1080,
|
||||
lineSize: 2560, frameSize: 2_764_800, v210aSize: 8_294_400,
|
||||
},
|
||||
{
|
||||
width: 1280, height: 720,
|
||||
lineSize: 1708, frameSize: 1_229_760, v210aSize: 3_718_080,
|
||||
},
|
||||
{
|
||||
width: 100, height: 2,
|
||||
lineSize: 136, frameSize: 272, v210aSize: 1040,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(fmt.Sprintf("%dx%d", tc.width, tc.height), func(t *testing.T) {
|
||||
if got := AlphaLineSize(tc.width); got != tc.lineSize {
|
||||
t.Errorf("AlphaLineSize(%d) = %d, want %d", tc.width, got, tc.lineSize)
|
||||
}
|
||||
if got := AlphaFrameSize(tc.width, tc.height); got != tc.frameSize {
|
||||
t.Errorf("AlphaFrameSize(%d, %d) = %d, want %d", tc.width, tc.height, got, tc.frameSize)
|
||||
}
|
||||
if got := V210AFrameSize(tc.width, tc.height); got != tc.v210aSize {
|
||||
t.Errorf("V210AFrameSize(%d, %d) = %d, want %d", tc.width, tc.height, got, tc.v210aSize)
|
||||
}
|
||||
if got := V210AFrameSize(tc.width, tc.height) - AlphaFrameSize(tc.width, tc.height); got != V210FrameSize(tc.width, tc.height) {
|
||||
t.Errorf("alpha plane starts at byte %d, want %d", got, V210FrameSize(tc.width, tc.height))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func sampleV210(buf []byte, width, x, y int) (yc, cb, cr uint32) {
|
||||
offset := y*V210LineSize(width) + x/6*16
|
||||
w0 := binary.LittleEndian.Uint32(buf[offset:])
|
||||
|
||||
Reference in New Issue
Block a user