mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
graphics: Fill the screenshot in black when the screen is not transparent
Fixes #997
This commit is contained in:
parent
67b166f732
commit
46601bb516
@ -52,7 +52,8 @@ func takeScreenshot(screen *Image) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := screen.buffered.Dump(newname); err != nil {
|
||||
blackbg := !IsScreenTransparent()
|
||||
if err := screen.buffered.Dump(newname, blackbg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -170,13 +170,13 @@ func (img *Image) set(x, y int, r, g, b, a byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *Image) Dump(name string) error {
|
||||
func (i *Image) Dump(name string, blackbg bool) error {
|
||||
delayedCommandsM.Lock()
|
||||
defer delayedCommandsM.Unlock()
|
||||
if needsToDelayCommands {
|
||||
panic("buffered: the command queue is not available yet at Dump")
|
||||
}
|
||||
return i.img.Dump(name)
|
||||
return i.img.Dump(name, blackbg)
|
||||
}
|
||||
|
||||
func (i *Image) Fill(clr color.RGBA) {
|
||||
|
@ -209,8 +209,10 @@ func (i *Image) IsInvalidated() bool {
|
||||
// Dump dumps the image to the specified path.
|
||||
// In the path, '*' is replaced with the image's ID.
|
||||
//
|
||||
// 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) error {
|
||||
func (i *Image) Dump(path string, blackbg bool) error {
|
||||
// Screen image cannot be dumped.
|
||||
if i.screen {
|
||||
return nil
|
||||
@ -227,6 +229,13 @@ func (i *Image) Dump(path string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if blackbg {
|
||||
for i := 0; i < len(pix)/4; i++ {
|
||||
pix[4*i+3] = 0xff
|
||||
}
|
||||
}
|
||||
|
||||
if err := png.Encode(f, &image.RGBA{
|
||||
Pix: pix,
|
||||
Stride: 4 * i.width,
|
||||
|
@ -78,8 +78,8 @@ func NewScreenFramebufferMipmap(width, height int) *Mipmap {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Mipmap) Dump(name string) error {
|
||||
return m.orig.Dump(name)
|
||||
func (m *Mipmap) Dump(name string, blackbg bool) error {
|
||||
return m.orig.Dump(name, blackbg)
|
||||
}
|
||||
|
||||
func (m *Mipmap) Fill(clr color.RGBA) {
|
||||
|
@ -577,6 +577,6 @@ func (i *Image) isInvalidated() (bool, error) {
|
||||
return i.image.IsInvalidated(), nil
|
||||
}
|
||||
|
||||
func (i *Image) Dump(path string) error {
|
||||
return i.image.Dump(path)
|
||||
func (i *Image) Dump(path string, blackbg bool) error {
|
||||
return i.image.Dump(path, blackbg)
|
||||
}
|
||||
|
@ -101,7 +101,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")); err != nil {
|
||||
if err := img.Dump(filepath.Join(dir, "*.png"), false); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -529,11 +529,11 @@ func (i *Image) allocate(shareable bool) {
|
||||
i.node = n
|
||||
}
|
||||
|
||||
func (i *Image) Dump(path string) error {
|
||||
func (i *Image) Dump(path string, blackbg bool) error {
|
||||
backendsM.Lock()
|
||||
defer backendsM.Unlock()
|
||||
|
||||
return i.backend.restorable.Dump(path)
|
||||
return i.backend.restorable.Dump(path, blackbg)
|
||||
}
|
||||
|
||||
func NewScreenFramebufferImage(width, height int) *Image {
|
||||
|
Loading…
Reference in New Issue
Block a user