mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
examples/video: performance optimization by encouraging BCE
This commit is contained in:
parent
c105224705
commit
2bd9472d2c
@ -159,13 +159,18 @@ func (p *mpegPlayer) updateFrame() error {
|
|||||||
w, h := p.mpg.Width(), p.mpg.Height()
|
w, h := p.mpg.Width(), p.mpg.Height()
|
||||||
for j := 0; j < h; j++ {
|
for j := 0; j < h; j++ {
|
||||||
yi := j * img.YStride
|
yi := j * img.YStride
|
||||||
ci := j / 2 * img.CStride
|
ci := (j / 2) * img.CStride
|
||||||
|
// Create temporary slices to encourage BCE (boundary-checking elimination).
|
||||||
|
ys := img.Y[yi : yi+w]
|
||||||
|
cbs := img.Cb[ci : ci+w/2]
|
||||||
|
crs := img.Cr[ci : ci+w/2]
|
||||||
for i := 0; i < w; i++ {
|
for i := 0; i < w; i++ {
|
||||||
idx := 4 * (i + j*w)
|
idx := 4 * (j*w + i)
|
||||||
p.yCbCrBytes[idx] = img.Y[yi+i]
|
buf := p.yCbCrBytes[idx : idx+3]
|
||||||
p.yCbCrBytes[idx+1] = img.Cb[ci+i/2]
|
buf[0] = ys[i]
|
||||||
p.yCbCrBytes[idx+2] = img.Cr[ci+i/2]
|
buf[1] = cbs[i/2]
|
||||||
p.yCbCrBytes[idx+3] = 0xff
|
buf[2] = crs[i/2]
|
||||||
|
// p.yCbCrBytes[3] = 0xff is not needed as the shader ignores this part.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,6 +179,7 @@ func (p *mpegPlayer) updateFrame() error {
|
|||||||
// Converting YCbCr to RGB on CPU is slow. Use a shader instead.
|
// Converting YCbCr to RGB on CPU is slow. Use a shader instead.
|
||||||
op := &ebiten.DrawRectShaderOptions{}
|
op := &ebiten.DrawRectShaderOptions{}
|
||||||
op.Images[0] = p.yCbCrImage
|
op.Images[0] = p.yCbCrImage
|
||||||
|
op.Blend = ebiten.BlendCopy
|
||||||
p.frameImage.DrawRectShader(w, h, p.yCbCrShader, op)
|
p.frameImage.DrawRectShader(w, h, p.yCbCrShader, op)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user