Ignite/frame/frame_uint16.go
DataHoarder 6ea3e971bb
All checks were successful
continuous-integration/drone/push Build is passing
Improved libaom/libx264, proper pool, frame stats
2023-10-31 23:00:37 +01:00

109 lines
2.5 KiB
Go

package frame
import (
"unsafe"
)
type fUint16 struct {
properties Properties
ret func(f Frame)
Pts int64
NextPts int64
Y []uint16
Cb []uint16
Cr []uint16
}
func (i *fUint16) Get16(x, y int) (Y uint16, Cb uint16, Cr uint16) {
cy, cb, cr := i.GetNative(x, y)
return cy << (16 - i.properties.ColorSpace.BitDepth), cb << (16 - i.properties.ColorSpace.BitDepth), cr << (16 - i.properties.ColorSpace.BitDepth)
}
func (i *fUint16) Get8(x, y int) (Y uint8, Cb uint8, Cr uint8) {
cy, cb, cr := i.GetNative(x, y)
return uint8(cy >> (i.properties.ColorSpace.BitDepth - 8)), uint8(cb >> (i.properties.ColorSpace.BitDepth - 8)), uint8(cr >> (i.properties.ColorSpace.BitDepth - 8))
}
func (i *fUint16) Properties() Properties {
return i.properties
}
func (i *fUint16) PTS() int64 {
return i.Pts
}
func (i *fUint16) NextPTS() int64 {
return i.NextPts
}
func (i *fUint16) GetNative(x, y int) (Y uint16, Cb uint16, Cr uint16) {
Yindex := x + y*i.properties.Width
Cwidth := (i.properties.Width * int(i.properties.ColorSpace.ChromaSampling.A)) / int(i.properties.ColorSpace.ChromaSampling.J)
if i.properties.ColorSpace.ChromaSampling.B == 0 {
y /= 2
}
Cindex := (x*int(i.properties.ColorSpace.ChromaSampling.A))/int(i.properties.ColorSpace.ChromaSampling.J) + y*Cwidth
Y = i.Y[Yindex]
Cb = i.Cb[Cindex]
Cr = i.Cr[Cindex]
return
}
func (i *fUint16) FillNativeLuma(buf []uint16) {
copy(i.Y, buf)
}
func (i *fUint16) FillNativeCb(buf []uint16) {
copy(i.Cb, buf)
}
func (i *fUint16) FillNativeCr(buf []uint16) {
copy(i.Cr, buf)
}
func (i *fUint16) GetNativeJoint() []uint16 {
// Component slices are allocated as a single buffer
return i.Y[:len(i.Y)+len(i.Cb)+len(i.Cr)]
}
func (i *fUint16) GetJoint() []byte {
buf := i.GetNativeJoint()
return unsafe.Slice((*byte)(unsafe.Pointer(unsafe.SliceData(buf))), len(buf)*2)
}
func (i *fUint16) GetLuma() []byte {
buf := i.GetNativeLuma()
return unsafe.Slice((*byte)(unsafe.Pointer(unsafe.SliceData(buf))), len(buf)*2)
}
func (i *fUint16) GetCb() []byte {
buf := i.GetNativeCb()
return unsafe.Slice((*byte)(unsafe.Pointer(unsafe.SliceData(buf))), len(buf)*2)
}
func (i *fUint16) GetCr() []byte {
buf := i.GetNativeCr()
return unsafe.Slice((*byte)(unsafe.Pointer(unsafe.SliceData(buf))), len(buf)*2)
}
func (i *fUint16) GetNativeLuma() []uint16 {
return i.Y
}
func (i *fUint16) GetNativeCb() []uint16 {
return i.Cb
}
func (i *fUint16) GetNativeCr() []uint16 {
return i.Cr
}
func (i *fUint16) Return() {
if i.ret != nil {
i.ret(i)
}
}