V210 issue fix + correct packing
This commit is contained in:
@@ -1,16 +1,43 @@
|
||||
package generator
|
||||
|
||||
import "encoding/binary"
|
||||
import (
|
||||
"encoding/binary"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestV210Sizes(t *testing.T) {
|
||||
tests := []struct {
|
||||
width int
|
||||
activeLine int
|
||||
line int
|
||||
}{
|
||||
{width: 1920, activeLine: 5120, line: 5120},
|
||||
{width: 1280, activeLine: 3424, line: 3456},
|
||||
{width: 100, activeLine: 272, line: 384},
|
||||
{width: 54, activeLine: 144, line: 256},
|
||||
{width: 48, activeLine: 128, line: 128},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
if got := V210ActiveLineSize(tc.width); got != tc.activeLine {
|
||||
t.Errorf("V210ActiveLineSize(%d) = %d, want %d", tc.width, got, tc.activeLine)
|
||||
}
|
||||
if got := V210LineSize(tc.width); got != tc.line {
|
||||
t.Errorf("V210LineSize(%d) = %d, want %d", tc.width, got, tc.line)
|
||||
}
|
||||
if got := V210FrameSize(tc.width, 2); got != tc.line*2 {
|
||||
t.Errorf("V210FrameSize(%d, 2) = %d, want %d", tc.width, got, tc.line*2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func sampleV210(buf []byte, width, x, y int) (yc, cb, cr uint32) {
|
||||
pixel := y*width + x
|
||||
offset := (pixel / 6) * 16
|
||||
offset := y*V210LineSize(width) + x/6*16
|
||||
w0 := binary.LittleEndian.Uint32(buf[offset:])
|
||||
w1 := binary.LittleEndian.Uint32(buf[offset+4:])
|
||||
w2 := binary.LittleEndian.Uint32(buf[offset+8:])
|
||||
w3 := binary.LittleEndian.Uint32(buf[offset+12:])
|
||||
|
||||
switch pixel % 6 {
|
||||
switch x % 6 {
|
||||
case 0:
|
||||
return (w0 >> 10) & 0x3FF, w0 & 0x3FF, (w0 >> 20) & 0x3FF
|
||||
case 1:
|
||||
|
||||
Reference in New Issue
Block a user