Optimize decoding slices
This commit is contained in:
parent
6722babcac
commit
49f274e0f9
|
@ -160,57 +160,35 @@ func (d *Decoder) pictureToFrame() (frame.Frame, error) {
|
|||
|
||||
if bitDepth > 8 { //16-bit
|
||||
|
||||
//TODO: check reserve
|
||||
buf := make([]byte, 0, height*width*2+chromaHeight*chromaWidth*2*2)
|
||||
|
||||
yData := unsafe.Slice((*byte)(d.picture.data[planeY]), height*width*2)
|
||||
for y := 0; y < height; y++ {
|
||||
buf = append(buf, yData[:width*2]...)
|
||||
yData = yData[d.picture.stride[0]:]
|
||||
}
|
||||
var uData, vData []byte
|
||||
|
||||
if d.picture.p.layout != C.DAV1D_PIXEL_LAYOUT_I400 {
|
||||
uData := unsafe.Slice((*byte)(d.picture.data[planeU]), chromaHeight*chromaWidth*2)
|
||||
vData := unsafe.Slice((*byte)(d.picture.data[planeV]), chromaHeight*chromaWidth*2)
|
||||
uData = unsafe.Slice((*byte)(d.picture.data[planeU]), chromaHeight*chromaWidth*2)
|
||||
vData = unsafe.Slice((*byte)(d.picture.data[planeV]), chromaHeight*chromaWidth*2)
|
||||
|
||||
//TODO: check sizes!
|
||||
for y := 0; y < chromaHeight; y++ {
|
||||
buf = append(buf, uData[:chromaWidth*2]...)
|
||||
uData = uData[d.picture.stride[1]:]
|
||||
}
|
||||
for y := 0; y < chromaHeight; y++ {
|
||||
buf = append(buf, vData[:chromaWidth*2]...)
|
||||
vData = vData[d.picture.stride[1]:]
|
||||
}
|
||||
}
|
||||
|
||||
buf := make([]byte, len(yData)+len(uData)+len(vData))
|
||||
copy(buf, yData)
|
||||
copy(buf[len(yData):], uData)
|
||||
copy(buf[len(yData)+len(uData):], vData)
|
||||
|
||||
return frame.NewUint16FrameFromBytes(colorFormat, width, height, buf)
|
||||
} else {
|
||||
|
||||
//TODO: check reserve
|
||||
buf := make([]byte, 0, height*width+chromaHeight*chromaWidth*2)
|
||||
|
||||
yData := unsafe.Slice((*byte)(d.picture.data[planeY]), height*width)
|
||||
for y := 0; y < height; y++ {
|
||||
buf = append(buf, yData[:width]...)
|
||||
yData = yData[d.picture.stride[0]:]
|
||||
}
|
||||
var uData, vData []byte
|
||||
|
||||
if d.picture.p.layout != C.DAV1D_PIXEL_LAYOUT_I400 {
|
||||
uData := unsafe.Slice((*byte)(d.picture.data[planeU]), chromaHeight*chromaWidth)
|
||||
vData := unsafe.Slice((*byte)(d.picture.data[planeV]), chromaHeight*chromaWidth)
|
||||
|
||||
//TODO: check sizes!
|
||||
for y := 0; y < chromaHeight; y++ {
|
||||
buf = append(buf, uData[:chromaWidth]...)
|
||||
uData = uData[d.picture.stride[1]:]
|
||||
}
|
||||
for y := 0; y < chromaHeight; y++ {
|
||||
buf = append(buf, vData[:chromaWidth]...)
|
||||
vData = vData[d.picture.stride[1]:]
|
||||
}
|
||||
uData = unsafe.Slice((*byte)(d.picture.data[planeU]), chromaHeight*chromaWidth)
|
||||
vData = unsafe.Slice((*byte)(d.picture.data[planeV]), chromaHeight*chromaWidth)
|
||||
}
|
||||
|
||||
buf := make([]byte, len(yData)+len(uData)+len(vData))
|
||||
copy(buf, yData)
|
||||
copy(buf[len(yData):], uData)
|
||||
copy(buf[len(yData)+len(uData):], vData)
|
||||
|
||||
return frame.NewUint8FrameFromBytes(colorFormat, width, height, buf)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue