mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 11:12:44 +01:00
ebiten: refactoring
This commit is contained in:
parent
922784f574
commit
aee2e67242
20
image.go
20
image.go
@ -865,30 +865,16 @@ func NewImageFromImage(source image.Image) *Image {
|
|||||||
panic(fmt.Sprintf("ebiten: NewImage cannot be called after RunGame finishes"))
|
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.
|
// 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.
|
// This works even before the game loop runs.
|
||||||
if source, ok := source.(*Image); ok {
|
if source, ok := source.(*Image); ok {
|
||||||
size := source.Bounds().Size()
|
|
||||||
i := NewImage(size.X, size.Y)
|
|
||||||
i.DrawImage(source, nil)
|
i.DrawImage(source, nil)
|
||||||
return i
|
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))
|
i.ReplacePixels(imageToBytes(source))
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user