mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
internal/ui, internal/mipmap: refactoring: replace At with ReadPixels
Updates #1995
This commit is contained in:
parent
6c22f3f1a8
commit
6d87be7169
4
image.go
4
image.go
@ -819,7 +819,9 @@ func (i *Image) at(x, y int) (r, g, b, a byte) {
|
|||||||
if c, ok := i.setVerticesCache[[2]int{x, y}]; ok {
|
if c, ok := i.setVerticesCache[[2]int{x, y}]; ok {
|
||||||
return c[0], c[1], c[2], c[3]
|
return c[0], c[1], c[2], c[3]
|
||||||
}
|
}
|
||||||
return i.image.At(x, y)
|
var pix [4]byte
|
||||||
|
i.image.ReadPixels(pix[:], x, y, 1, 1)
|
||||||
|
return pix[0], pix[1], pix[2], pix[3]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set sets the color at (x, y).
|
// Set sets the color at (x, y).
|
||||||
|
@ -54,12 +54,8 @@ func (m *Mipmap) ReplacePixels(pix []byte, x, y, width, height int) {
|
|||||||
m.disposeMipmaps()
|
m.disposeMipmaps()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Mipmap) At(graphicsDriver graphicsdriver.Graphics, x, y int) (r, g, b, a byte, err error) {
|
func (m *Mipmap) ReadPixels(graphicsDriver graphicsdriver.Graphics, pixels []byte, x, y, width, height int) error {
|
||||||
var pix [4]byte
|
return m.orig.ReadPixels(graphicsDriver, pixels, x, y, width, height)
|
||||||
if err := m.orig.ReadPixels(graphicsDriver, pix[:], x, y, 1, 1); err != nil {
|
|
||||||
return 0, 0, 0, 0, err
|
|
||||||
}
|
|
||||||
return pix[0], pix[1], pix[2], pix[3], nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Mipmap) DrawTriangles(srcs [graphics.ShaderImageCount]*Mipmap, vertices []float32, indices []uint16, colorm affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, subimageOffsets [graphics.ShaderImageCount - 1][2]float32, shader *Shader, uniforms [][]float32, evenOdd bool, canSkipMipmap bool) {
|
func (m *Mipmap) DrawTriangles(srcs [graphics.ShaderImageCount]*Mipmap, vertices []float32, indices []uint16, colorm affine.ColorM, mode graphicsdriver.CompositeMode, filter graphicsdriver.Filter, address graphicsdriver.Address, dstRegion, srcRegion graphicsdriver.Region, subimageOffsets [graphics.ShaderImageCount - 1][2]float32, shader *Shader, uniforms [][]float32, evenOdd bool, canSkipMipmap bool) {
|
||||||
|
@ -75,21 +75,21 @@ func (i *Image) ReplacePixels(pix []byte, x, y, width, height int) {
|
|||||||
i.mipmap.ReplacePixels(pix, x, y, width, height)
|
i.mipmap.ReplacePixels(pix, x, y, width, height)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) At(x, y int) (r, g, b, a byte) {
|
func (i *Image) ReadPixels(pixels []byte, x, y, width, height int) {
|
||||||
// Check the error existence and avoid unnecessary calls.
|
// Check the error existence and avoid unnecessary calls.
|
||||||
if theGlobalState.error() != nil {
|
if theGlobalState.error() != nil {
|
||||||
return 0, 0, 0, 0
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
r, g, b, a, err := theUI.imageAt(i.mipmap, x, y)
|
if err := theUI.readPixels(i.mipmap, pixels, x, y, width, height); err != nil {
|
||||||
if err != nil {
|
|
||||||
if panicOnErrorOnReadingPixels {
|
if panicOnErrorOnReadingPixels {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
theGlobalState.setError(err)
|
theGlobalState.setError(err)
|
||||||
return 0, 0, 0, 0
|
for i := range pixels {
|
||||||
|
pixels[i] = 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return r, g, b, a
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) DumpScreenshot(name string, blackbg bool) error {
|
func (i *Image) DumpScreenshot(name string, blackbg bool) error {
|
||||||
|
@ -91,8 +91,8 @@ func Get() *UserInterface {
|
|||||||
return theUI
|
return theUI
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserInterface) imageAt(mipmap *mipmap.Mipmap, x, y int) (r, g, b, a byte, err error) {
|
func (u *UserInterface) readPixels(mipmap *mipmap.Mipmap, pixels []byte, x, y, width, height int) error {
|
||||||
return mipmap.At(u.graphicsDriver, x, y)
|
return mipmap.ReadPixels(u.graphicsDriver, pixels, x, y, width, height)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserInterface) dumpScreenshot(mipmap *mipmap.Mipmap, name string, blackbg bool) error {
|
func (u *UserInterface) dumpScreenshot(mipmap *mipmap.Mipmap, name string, blackbg bool) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user