DataHoarder
6ea3e971bb
All checks were successful
continuous-integration/drone/push Build is passing
99 lines
2 KiB
Go
99 lines
2 KiB
Go
package frame
|
|
|
|
type fUint8 struct {
|
|
properties Properties
|
|
ret func(f Frame)
|
|
Pts int64
|
|
NextPts int64
|
|
Y []uint8
|
|
Cb []uint8
|
|
Cr []uint8
|
|
}
|
|
|
|
func (i *fUint8) Get16(x, y int) (Y uint16, Cb uint16, Cr uint16) {
|
|
cy, cb, cr := i.GetNative(x, y)
|
|
|
|
return uint16(cy) << (16 - i.properties.ColorSpace.BitDepth), uint16(cb) << (16 - i.properties.ColorSpace.BitDepth), uint16(cr) << (16 - i.properties.ColorSpace.BitDepth)
|
|
}
|
|
|
|
func (i *fUint8) Get8(x, y int) (Y uint8, Cb uint8, Cr uint8) {
|
|
return i.GetNative(x, y)
|
|
}
|
|
|
|
func (i *fUint8) Properties() Properties {
|
|
return i.properties
|
|
}
|
|
|
|
func (i *fUint8) PTS() int64 {
|
|
return i.Pts
|
|
}
|
|
|
|
func (i *fUint8) NextPTS() int64 {
|
|
return i.NextPts
|
|
}
|
|
|
|
func (i *fUint8) GetNative(x, y int) (Y uint8, Cb uint8, Cr uint8) {
|
|
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 *fUint8) FillNativeLuma(buf []uint8) {
|
|
copy(i.Y, buf)
|
|
}
|
|
|
|
func (i *fUint8) FillNativeCb(buf []uint8) {
|
|
copy(i.Cb, buf)
|
|
}
|
|
|
|
func (i *fUint8) FillNativeCr(buf []uint8) {
|
|
copy(i.Cr, buf)
|
|
}
|
|
|
|
func (i *fUint8) GetNativeLuma() []uint8 {
|
|
return i.Y
|
|
}
|
|
|
|
func (i *fUint8) GetNativeCb() []uint8 {
|
|
return i.Cb
|
|
}
|
|
|
|
func (i *fUint8) GetNativeCr() []uint8 {
|
|
return i.Cr
|
|
}
|
|
|
|
func (i *fUint8) GetNativeJoint() []uint8 {
|
|
// Component slices are allocated as a single buffer
|
|
return i.Y[:len(i.Y)+len(i.Cb)+len(i.Cr)]
|
|
}
|
|
|
|
func (i *fUint8) GetJoint() []byte {
|
|
return i.GetNativeJoint()
|
|
}
|
|
|
|
func (i *fUint8) GetLuma() []byte {
|
|
return i.GetNativeLuma()
|
|
}
|
|
|
|
func (i *fUint8) GetCb() []byte {
|
|
return i.GetNativeCb()
|
|
}
|
|
|
|
func (i *fUint8) GetCr() []byte {
|
|
return i.GetNativeCr()
|
|
}
|
|
|
|
func (i *fUint8) Return() {
|
|
if i.ret != nil {
|
|
i.ret(i)
|
|
}
|
|
}
|