mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
Revert "internal/restorable: integrate Image.WritePixels into internal/atlas"
This reverts commit 6cc8150185
.
Updates #3083
This commit is contained in:
parent
104cc18477
commit
d733308eb1
@ -94,9 +94,6 @@ type backend struct {
|
||||
// restorable is an atlas on which there might be multiple images.
|
||||
restorable *restorable.Image
|
||||
|
||||
width int
|
||||
height int
|
||||
|
||||
// page is an atlas map. Each part is called a node.
|
||||
// If page is nil, the backend's image is isolated and not on an atlas.
|
||||
page *packing.Page
|
||||
@ -124,8 +121,6 @@ func (b *backend) tryAlloc(width, height int) (*packing.Node, bool) {
|
||||
|
||||
w, h := b.page.Size()
|
||||
b.restorable = b.restorable.Extend(w, h)
|
||||
b.width = w
|
||||
b.height = h
|
||||
|
||||
return n, true
|
||||
}
|
||||
@ -522,7 +517,7 @@ func (i *Image) writePixels(pix []byte, region image.Rectangle) {
|
||||
pix2 := graphics.NewManagedBytes(len(pix), func(bs []byte) {
|
||||
copy(bs, pix)
|
||||
})
|
||||
i.backend.writePixels(pix2, region)
|
||||
i.backend.restorable.WritePixels(pix2, region)
|
||||
return
|
||||
}
|
||||
|
||||
@ -551,17 +546,7 @@ func (i *Image) writePixels(pix []byte, region image.Rectangle) {
|
||||
copy(bs[4*j*r.Dx():], pix[4*j*region.Dx():4*(j+1)*region.Dx()])
|
||||
}
|
||||
})
|
||||
i.backend.writePixels(pixb, r)
|
||||
}
|
||||
|
||||
func (b *backend) writePixels(pixels *graphics.ManagedBytes, region image.Rectangle) {
|
||||
if region.Dx() <= 0 || region.Dy() <= 0 {
|
||||
panic("atlas: width/height must be positive")
|
||||
}
|
||||
if !region.In(image.Rect(0, 0, b.width, b.height)) {
|
||||
panic(fmt.Sprintf("atlas: out of range %v", region))
|
||||
}
|
||||
b.restorable.Image.WritePixels(pixels, region)
|
||||
i.backend.restorable.WritePixels(pixb, r)
|
||||
}
|
||||
|
||||
func (i *Image) ReadPixels(graphicsDriver graphicsdriver.Graphics, pixels []byte, region image.Rectangle) (ok bool, err error) {
|
||||
@ -699,8 +684,6 @@ func (i *Image) allocate(forbiddenBackends []*backend, asSource bool) {
|
||||
// A screen image doesn't have a padding.
|
||||
i.backend = &backend{
|
||||
restorable: restorable.NewImage(i.width, i.height, true),
|
||||
width: i.width,
|
||||
height: i.height,
|
||||
}
|
||||
theBackends = append(theBackends, i.backend)
|
||||
return
|
||||
@ -716,8 +699,6 @@ func (i *Image) allocate(forbiddenBackends []*backend, asSource bool) {
|
||||
|
||||
i.backend = &backend{
|
||||
restorable: restorable.NewImage(wp, hp, false),
|
||||
width: wp,
|
||||
height: hp,
|
||||
source: asSource && i.imageType == ImageTypeRegular,
|
||||
}
|
||||
theBackends = append(theBackends, i.backend)
|
||||
@ -764,8 +745,6 @@ loop:
|
||||
|
||||
b := &backend{
|
||||
restorable: restorable.NewImage(width, height, false),
|
||||
width: width,
|
||||
height: height,
|
||||
page: packing.NewPage(width, height, maxSize),
|
||||
source: asSource,
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
package restorable
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||
@ -92,3 +93,18 @@ func (i *Image) ClearPixels(region image.Rectangle) {
|
||||
}
|
||||
clearImage(i.Image, region.Intersect(image.Rect(0, 0, i.width, i.height)))
|
||||
}
|
||||
|
||||
// WritePixels replaces the image pixels with the given pixels slice.
|
||||
//
|
||||
// The specified region must not be overlapped with other regions by WritePixels.
|
||||
func (i *Image) WritePixels(pixels *graphics.ManagedBytes, region image.Rectangle) {
|
||||
if region.Dx() <= 0 || region.Dy() <= 0 {
|
||||
panic("restorable: width/height must be positive")
|
||||
}
|
||||
w, h := i.width, i.height
|
||||
if !region.In(image.Rect(0, 0, w, h)) {
|
||||
panic(fmt.Sprintf("restorable: out of range %v", region))
|
||||
}
|
||||
|
||||
i.Image.WritePixels(pixels, region)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user