mirror of
https://github.com/asticode/go-astiav.git
synced 2025-10-06 16:46:52 +08:00
Added display matrix
This commit is contained in:
30
display_matrix.go
Normal file
30
display_matrix.go
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package astiav
|
||||||
|
|
||||||
|
//#cgo pkg-config: libavutil
|
||||||
|
//#include <libavutil/display.h>
|
||||||
|
import "C"
|
||||||
|
import (
|
||||||
|
"encoding/binary"
|
||||||
|
"fmt"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DisplayMatrix [9]uint32
|
||||||
|
|
||||||
|
func NewDisplayMatrixFromBytes(b []byte) (m DisplayMatrix, err error) {
|
||||||
|
// Check length
|
||||||
|
if len(b) < 36 {
|
||||||
|
err = fmt.Errorf("astiav: invalid length %d < 36", len(b))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Loop
|
||||||
|
for idx := 0; idx < 9; idx++ {
|
||||||
|
m[idx] = binary.BigEndian.Uint32(b[idx*4 : (idx+1)*4])
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m DisplayMatrix) Rotation() float64 {
|
||||||
|
return float64(C.av_display_rotation_get((*C.int32_t)(unsafe.Pointer(&m[0]))))
|
||||||
|
}
|
16
display_matrix_test.go
Normal file
16
display_matrix_test.go
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package astiav
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDisplayMatrix(t *testing.T) {
|
||||||
|
_, err := NewDisplayMatrixFromBytes([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})
|
||||||
|
require.Error(t, err)
|
||||||
|
dm, err := NewDisplayMatrixFromBytes([]byte{0, 0, 0, 0, 0, 0, 255, 255, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64})
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, DisplayMatrix{0x0, 0xffff, 0x0, 0x100, 0x0, 0x0, 0x0, 0x0, 0x40}, dm)
|
||||||
|
require.Equal(t, float64(-90), dm.Rotation())
|
||||||
|
}
|
Reference in New Issue
Block a user