mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
graphics: Reduce original() usage
This commit is contained in:
parent
95bc445fea
commit
504a433540
13
image.go
13
image.go
@ -161,8 +161,7 @@ func (i *Image) Fill(clr color.Color) error {
|
|||||||
|
|
||||||
i.resolvePendingPixels(false)
|
i.resolvePendingPixels(false)
|
||||||
|
|
||||||
i.mipmap.original().Fill(clr)
|
i.mipmap.fill(clr)
|
||||||
i.disposeMipmaps()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -533,7 +532,7 @@ func (i *Image) Bounds() image.Rectangle {
|
|||||||
panic("ebiten: the image is already disposed")
|
panic("ebiten: the image is already disposed")
|
||||||
}
|
}
|
||||||
if !i.isSubImage() {
|
if !i.isSubImage() {
|
||||||
w, h := i.mipmap.original().Size()
|
w, h := i.mipmap.size()
|
||||||
return image.Rect(0, 0, w, h)
|
return image.Rect(0, 0, w, h)
|
||||||
}
|
}
|
||||||
return i.bounds
|
return i.bounds
|
||||||
@ -564,7 +563,7 @@ func (i *Image) At(x, y int) color.Color {
|
|||||||
return color.RGBA{}
|
return color.RGBA{}
|
||||||
}
|
}
|
||||||
i.resolvePendingPixels(true)
|
i.resolvePendingPixels(true)
|
||||||
r, g, b, a := i.mipmap.original().At(x, y)
|
r, g, b, a := i.mipmap.at(x, y)
|
||||||
return color.RGBA{r, g, b, a}
|
return color.RGBA{r, g, b, a}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -595,7 +594,7 @@ func (img *Image) Set(x, y int, clr color.Color) {
|
|||||||
idx := 0
|
idx := 0
|
||||||
for j := 0; j < h; j++ {
|
for j := 0; j < h; j++ {
|
||||||
for i := 0; i < w; i++ {
|
for i := 0; i < w; i++ {
|
||||||
r, g, b, a := img.mipmap.original().At(i, j)
|
r, g, b, a := img.mipmap.at(i, j)
|
||||||
pix[4*idx] = r
|
pix[4*idx] = r
|
||||||
pix[4*idx+1] = g
|
pix[4*idx+1] = g
|
||||||
pix[4*idx+2] = b
|
pix[4*idx+2] = b
|
||||||
@ -697,8 +696,7 @@ func (i *Image) ReplacePixels(p []byte) error {
|
|||||||
if l := 4 * s.X * s.Y; len(p) != l {
|
if l := 4 * s.X * s.Y; len(p) != l {
|
||||||
panic(fmt.Sprintf("ebiten: len(p) was %d but must be %d", len(p), l))
|
panic(fmt.Sprintf("ebiten: len(p) was %d but must be %d", len(p), l))
|
||||||
}
|
}
|
||||||
i.mipmap.original().ReplacePixels(p)
|
i.mipmap.replacePixels(p)
|
||||||
i.disposeMipmaps()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -779,7 +777,6 @@ func (i *Image) makeVolatile() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
i.mipmap.makeVolatile()
|
i.mipmap.makeVolatile()
|
||||||
i.disposeMipmaps()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewImageFromImage creates a new image with the given image (source).
|
// NewImageFromImage creates a new image with the given image (source).
|
||||||
|
21
mipmap.go
21
mipmap.go
@ -17,6 +17,7 @@ package ebiten
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
|
"image/color"
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
"github.com/hajimehoshi/ebiten/internal/driver"
|
||||||
@ -46,17 +47,37 @@ func newScreenFramebufferMipmap(width, height int) *mipmap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *mipmap) original() *shareable.Image {
|
func (m *mipmap) original() *shareable.Image {
|
||||||
|
// TODO: Remove this
|
||||||
return m.orig
|
return m.orig
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mipmap) makeVolatile() {
|
func (m *mipmap) makeVolatile() {
|
||||||
m.orig.MakeVolatile()
|
m.orig.MakeVolatile()
|
||||||
|
m.disposeMipmaps()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mipmap) dump(name string) error {
|
func (m *mipmap) dump(name string) error {
|
||||||
return m.orig.Dump(name)
|
return m.orig.Dump(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *mipmap) fill(clr color.Color) {
|
||||||
|
m.orig.Fill(clr)
|
||||||
|
m.disposeMipmaps()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mipmap) replacePixels(pix []byte) {
|
||||||
|
m.orig.ReplacePixels(pix)
|
||||||
|
m.disposeMipmaps()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mipmap) size() (int, int) {
|
||||||
|
return m.orig.Size()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mipmap) at(x, y int) (r, g, b, a byte) {
|
||||||
|
return m.orig.At(x, y)
|
||||||
|
}
|
||||||
|
|
||||||
func (m *mipmap) level(r image.Rectangle, level int) *shareable.Image {
|
func (m *mipmap) level(r image.Rectangle, level int) *shareable.Image {
|
||||||
if level == 0 {
|
if level == 0 {
|
||||||
panic("ebiten: level must be non-zero at level")
|
panic("ebiten: level must be non-zero at level")
|
||||||
|
Loading…
Reference in New Issue
Block a user