mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 11:48:55 +01:00
restorable: Refactoring: Remove arguments from NewImageFromImage
This commit is contained in:
parent
ca4a2d8209
commit
ccddf3c4ac
6
image.go
6
image.go
@ -266,10 +266,8 @@ func newVolatileImage(width, height int, filter Filter) *Image {
|
|||||||
// Error returned by NewImageFromImage is always nil as of 1.5.0-alpha.
|
// Error returned by NewImageFromImage is always nil as of 1.5.0-alpha.
|
||||||
func NewImageFromImage(source image.Image, filter Filter) (*Image, error) {
|
func NewImageFromImage(source image.Image, filter Filter) (*Image, error) {
|
||||||
size := source.Bounds().Size()
|
size := source.Bounds().Size()
|
||||||
w, h := size.X, size.Y
|
checkSize(size.X, size.Y)
|
||||||
checkSize(w, h)
|
r := restorable.NewImageFromImage(source, glFilter(filter))
|
||||||
rgbaImg := restorable.CopyImage(source)
|
|
||||||
r := restorable.NewImageFromImage(rgbaImg, w, h, glFilter(filter))
|
|
||||||
i := &Image{r}
|
i := &Image{r}
|
||||||
runtime.SetFinalizer(i, (*Image).Dispose)
|
runtime.SetFinalizer(i, (*Image).Dispose)
|
||||||
return i, nil
|
return i, nil
|
||||||
|
@ -28,8 +28,7 @@ import (
|
|||||||
// Basically CopyImage just calls draw.Draw.
|
// Basically CopyImage just calls draw.Draw.
|
||||||
// If origImg is a paletted image, an optimized copying method is used.
|
// If origImg is a paletted image, an optimized copying method is used.
|
||||||
//
|
//
|
||||||
// CopyImage is used only from ebiten package but defined in restorable package
|
// CopyImage is used only internally but it is exposed for testing.
|
||||||
// because this function needs to be tested but cannot be exposed to Ebiten users.
|
|
||||||
func CopyImage(origImg image.Image) *image.RGBA {
|
func CopyImage(origImg image.Image) *image.RGBA {
|
||||||
size := origImg.Bounds().Size()
|
size := origImg.Bounds().Size()
|
||||||
w, h := size.X, size.Y
|
w, h := size.X, size.Y
|
||||||
|
@ -93,16 +93,17 @@ func NewImage(width, height int, filter opengl.Filter, volatile bool) *Image {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewImageFromImage creates an image with source image.
|
// NewImageFromImage creates an image with source image.
|
||||||
//
|
func NewImageFromImage(source image.Image, filter opengl.Filter) *Image {
|
||||||
// width/height might be different from source's size.
|
size := source.Bounds().Size()
|
||||||
func NewImageFromImage(source *image.RGBA, width, height int, filter opengl.Filter) *Image {
|
width, height := size.X, size.Y
|
||||||
|
rgbaImg := CopyImage(source)
|
||||||
w2, h2 := math.NextPowerOf2Int(width), math.NextPowerOf2Int(height)
|
w2, h2 := math.NextPowerOf2Int(width), math.NextPowerOf2Int(height)
|
||||||
p := make([]uint8, 4*w2*h2)
|
p := make([]uint8, 4*w2*h2)
|
||||||
for j := 0; j < height; j++ {
|
for j := 0; j < height; j++ {
|
||||||
copy(p[j*w2*4:(j+1)*w2*4], source.Pix[j*source.Stride:])
|
copy(p[j*w2*4:(j+1)*w2*4], rgbaImg.Pix[j*rgbaImg.Stride:])
|
||||||
}
|
}
|
||||||
i := &Image{
|
i := &Image{
|
||||||
image: graphics.NewImageFromImage(source, width, height, filter),
|
image: graphics.NewImageFromImage(rgbaImg, width, height, filter),
|
||||||
basePixels: p,
|
basePixels: p,
|
||||||
filter: filter,
|
filter: filter,
|
||||||
}
|
}
|
||||||
|
@ -192,9 +192,9 @@ func TestRestoreComplexGraph(t *testing.T) {
|
|||||||
base.Pix[1] = 0xff
|
base.Pix[1] = 0xff
|
||||||
base.Pix[2] = 0xff
|
base.Pix[2] = 0xff
|
||||||
base.Pix[3] = 0xff
|
base.Pix[3] = 0xff
|
||||||
img0 := NewImageFromImage(base, 4, 1, opengl.Nearest)
|
img0 := NewImageFromImage(base, opengl.Nearest)
|
||||||
img1 := NewImageFromImage(base, 4, 1, opengl.Nearest)
|
img1 := NewImageFromImage(base, opengl.Nearest)
|
||||||
img2 := NewImageFromImage(base, 4, 1, opengl.Nearest)
|
img2 := NewImageFromImage(base, opengl.Nearest)
|
||||||
img3 := NewImage(4, 1, opengl.Nearest, false)
|
img3 := NewImage(4, 1, opengl.Nearest, false)
|
||||||
img3.Fill(0, 0, 0, 0)
|
img3.Fill(0, 0, 0, 0)
|
||||||
img4 := NewImage(4, 1, opengl.Nearest, false)
|
img4 := NewImage(4, 1, opengl.Nearest, false)
|
||||||
@ -296,7 +296,7 @@ func TestRestoreRecursive(t *testing.T) {
|
|||||||
base.Pix[1] = 0xff
|
base.Pix[1] = 0xff
|
||||||
base.Pix[2] = 0xff
|
base.Pix[2] = 0xff
|
||||||
base.Pix[3] = 0xff
|
base.Pix[3] = 0xff
|
||||||
img0 := NewImageFromImage(base, 4, 1, opengl.Nearest)
|
img0 := NewImageFromImage(base, opengl.Nearest)
|
||||||
img1 := NewImage(4, 1, opengl.Nearest, false)
|
img1 := NewImage(4, 1, opengl.Nearest, false)
|
||||||
img1.Fill(0, 0, 0, 0)
|
img1.Fill(0, 0, 0, 0)
|
||||||
defer func() {
|
defer func() {
|
||||||
|
Loading…
Reference in New Issue
Block a user