mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
internal/atlas: Bug fix: Unexpected padding in screenshots
Closes #1736
This commit is contained in:
parent
6c54fac018
commit
18903db1c6
@ -52,7 +52,7 @@ func takeScreenshot(screen *Image) error {
|
||||
}
|
||||
|
||||
blackbg := !IsScreenTransparent()
|
||||
if err := screen.mipmap.Dump(newname, blackbg); err != nil {
|
||||
if err := screen.mipmap.DumpScreenshot(newname, blackbg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ package atlas
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
"runtime"
|
||||
"sync"
|
||||
|
||||
@ -725,11 +726,11 @@ func (i *Image) allocate(putOnAtlas bool) {
|
||||
i.node = n
|
||||
}
|
||||
|
||||
func (i *Image) Dump(path string, blackbg bool) error {
|
||||
func (i *Image) DumpScreenshot(path string, blackbg bool) error {
|
||||
backendsM.Lock()
|
||||
defer backendsM.Unlock()
|
||||
|
||||
return i.backend.restorable.Dump(path, blackbg)
|
||||
return i.backend.restorable.Dump(path, blackbg, image.Rect(paddingSize, paddingSize, i.width-2*paddingSize, i.height-2*paddingSize))
|
||||
}
|
||||
|
||||
func NewScreenFramebufferImage(width, height int) *Image {
|
||||
|
@ -149,9 +149,9 @@ func (img *Image) Pixels(x, y, width, height int) (pix []byte, err error) {
|
||||
return pix, nil
|
||||
}
|
||||
|
||||
func (i *Image) Dump(name string, blackbg bool) error {
|
||||
func (i *Image) DumpScreenshot(name string, blackbg bool) error {
|
||||
checkDelayedCommandsFlushed("Dump")
|
||||
return i.img.Dump(name, blackbg)
|
||||
return i.img.DumpScreenshot(name, blackbg)
|
||||
}
|
||||
|
||||
func (i *Image) ReplacePixels(pix []byte, x, y, width, height int) error {
|
||||
|
@ -207,7 +207,7 @@ func (i *Image) IsInvalidated() bool {
|
||||
// If blackbg is true, any alpha values in the dumped image will be 255.
|
||||
//
|
||||
// This is for testing usage.
|
||||
func (i *Image) Dump(path string, blackbg bool) error {
|
||||
func (i *Image) Dump(path string, blackbg bool, rect image.Rectangle) error {
|
||||
// Screen image cannot be dumped.
|
||||
if i.screen {
|
||||
return nil
|
||||
@ -231,11 +231,11 @@ func (i *Image) Dump(path string, blackbg bool) error {
|
||||
}
|
||||
}
|
||||
|
||||
if err := png.Encode(f, &image.RGBA{
|
||||
if err := png.Encode(f, (&image.RGBA{
|
||||
Pix: pix,
|
||||
Stride: 4 * i.width,
|
||||
Rect: image.Rect(0, 0, i.width, i.height),
|
||||
}); err != nil {
|
||||
}).SubImage(rect)); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
@ -69,8 +69,8 @@ func (m *Mipmap) SetVolatile(volatile bool) {
|
||||
m.orig.SetVolatile(volatile)
|
||||
}
|
||||
|
||||
func (m *Mipmap) Dump(name string, blackbg bool) error {
|
||||
return m.orig.Dump(name, blackbg)
|
||||
func (m *Mipmap) DumpScreenshot(name string, blackbg bool) error {
|
||||
return m.orig.DumpScreenshot(name, blackbg)
|
||||
}
|
||||
|
||||
func (m *Mipmap) ReplacePixels(pix []byte, x, y, width, height int) error {
|
||||
|
@ -16,6 +16,7 @@ package restorable
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/affine"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
@ -648,6 +649,6 @@ func (i *Image) isInvalidated() (bool, error) {
|
||||
return i.image.IsInvalidated(), nil
|
||||
}
|
||||
|
||||
func (i *Image) Dump(path string, blackbg bool) error {
|
||||
return i.image.Dump(path, blackbg)
|
||||
func (i *Image) Dump(path string, blackbg bool, rect image.Rectangle) error {
|
||||
return i.image.Dump(path, blackbg, rect)
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
package restorable
|
||||
|
||||
import (
|
||||
"image"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/driver"
|
||||
@ -115,7 +116,7 @@ func RestoreIfNeeded() error {
|
||||
// This is for testing usage.
|
||||
func DumpImages(dir string) error {
|
||||
for img := range theImages.images {
|
||||
if err := img.Dump(filepath.Join(dir, "*.png"), false); err != nil {
|
||||
if err := img.Dump(filepath.Join(dir, "*.png"), false, image.Rect(0, 0, img.width, img.height)); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user