From aee2e67242824e6edebd0e7dc82ff34eb1acac6f Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 15 Jun 2022 11:54:49 +0900 Subject: [PATCH] ebiten: refactoring --- image.go | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/image.go b/image.go index d397b7bd7..2abdf78b1 100644 --- a/image.go +++ b/image.go @@ -865,30 +865,16 @@ func NewImageFromImage(source image.Image) *Image { panic(fmt.Sprintf("ebiten: NewImage cannot be called after RunGame finishes")) } + size := source.Bounds().Size() + i := NewImage(size.X, size.Y) + // If the given image is an Ebitengine image, use DrawImage instead of reading pixels from the source. // This works even before the game loop runs. if source, ok := source.(*Image); ok { - size := source.Bounds().Size() - i := NewImage(size.X, size.Y) i.DrawImage(source, nil) return i } - size := source.Bounds().Size() - width, height := size.X, size.Y - if width <= 0 { - panic(fmt.Sprintf("ebiten: source width at NewImageFromImage must be positive but %d", width)) - } - if height <= 0 { - panic(fmt.Sprintf("ebiten: source height at NewImageFromImage must be positive but %d", height)) - } - - i := &Image{ - image: ui.NewImage(width, height, atlas.ImageTypeRegular), - bounds: image.Rect(0, 0, width, height), - } - i.addr = i - i.ReplacePixels(imageToBytes(source)) return i }