mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 19:22:49 +01:00
restorable: Rename NewImageFromImage to Extend
This commit is contained in:
parent
91a4329f0d
commit
353d81fd58
@ -127,22 +127,29 @@ func NewImage(width, height int) *Image {
|
|||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewImageFromImage creates a new image and copies the pixels of the given source image.
|
// Extend extends the image by the given size.
|
||||||
|
// Extend creates a new image with the given size and copies the pixels of the given source image.
|
||||||
|
// Extend disposes itself after its call.
|
||||||
//
|
//
|
||||||
// The given size (width and height) doesn't have to match with the source image's size.
|
// If the given size (width and height) is smaller than the source image, ExtendImage panics.
|
||||||
// The image is copied at the left-upper corner of the new image.
|
func (i *Image) Extend(width, height int) *Image {
|
||||||
func NewImageFromImage(width, height int, src *Image) *Image {
|
if w, h := i.Size(); w > width || h > height {
|
||||||
i := NewImage(width, height)
|
panic(fmt.Sprintf("restorable: the original size (%d, %d) cannot be extended to (%d, %d)", w, h, width, height))
|
||||||
|
}
|
||||||
|
|
||||||
|
newImg := NewImage(width, height)
|
||||||
|
|
||||||
// Do not use DrawTriangles here. ReplacePixels will be called on a part of newImg later, and it looked like
|
// Do not use DrawTriangles here. ReplacePixels will be called on a part of newImg later, and it looked like
|
||||||
// ReplacePixels on a part of image deletes other region that are rendered by DrawTriangles (#593, #758).
|
// ReplacePixels on a part of image deletes other region that are rendered by DrawTriangles (#593, #758).
|
||||||
i.image.CopyPixels(src.image)
|
newImg.image.CopyPixels(i.image)
|
||||||
|
|
||||||
// As pixels should not be obtained here, making the image stale is inevitable.
|
// As pixels should not be obtained here, making the image stale is inevitable.
|
||||||
// TODO: Copy pixel data from the source instead of making this stale (#897).
|
// TODO: Copy pixel data from the source instead of making this stale (#897).
|
||||||
i.makeStale()
|
newImg.makeStale()
|
||||||
|
|
||||||
return i
|
i.Dispose()
|
||||||
|
|
||||||
|
return newImg
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) MakeVolatile() {
|
func (i *Image) MakeVolatile() {
|
||||||
|
@ -121,9 +121,7 @@ func (b *backend) TryAlloc(width, height int) (*packing.Node, bool) {
|
|||||||
b.page.Extend()
|
b.page.Extend()
|
||||||
}
|
}
|
||||||
s := b.page.Size()
|
s := b.page.Size()
|
||||||
newImg := restorable.NewImageFromImage(s, s, b.restorable)
|
b.restorable = b.restorable.Extend(s, s)
|
||||||
b.restorable.Dispose()
|
|
||||||
b.restorable = newImg
|
|
||||||
|
|
||||||
n := b.page.Alloc(width, height)
|
n := b.page.Alloc(width, height)
|
||||||
if n == nil {
|
if n == nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user