mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := screen.buffered.Dump(newname); err != nil {
|
blackbg := !IsScreenTransparent()
|
||||||
|
if err := screen.buffered.Dump(newname, blackbg); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,13 +170,13 @@ func (img *Image) set(x, y int, r, g, b, a byte) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) Dump(name string) error {
|
func (i *Image) Dump(name string, blackbg bool) error {
|
||||||
delayedCommandsM.Lock()
|
delayedCommandsM.Lock()
|
||||||
defer delayedCommandsM.Unlock()
|
defer delayedCommandsM.Unlock()
|
||||||
if needsToDelayCommands {
|
if needsToDelayCommands {
|
||||||
panic("buffered: the command queue is not available yet at Dump")
|
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) {
|
func (i *Image) Fill(clr color.RGBA) {
|
||||||
|
@ -209,8 +209,10 @@ func (i *Image) IsInvalidated() bool {
|
|||||||
// Dump dumps the image to the specified path.
|
// Dump dumps the image to the specified path.
|
||||||
// In the path, '*' is replaced with the image's ID.
|
// 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.
|
// 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.
|
// Screen image cannot be dumped.
|
||||||
if i.screen {
|
if i.screen {
|
||||||
return nil
|
return nil
|
||||||
@ -227,6 +229,13 @@ func (i *Image) Dump(path string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if blackbg {
|
||||||
|
for i := 0; i < len(pix)/4; i++ {
|
||||||
|
pix[4*i+3] = 0xff
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err := png.Encode(f, &image.RGBA{
|
if err := png.Encode(f, &image.RGBA{
|
||||||
Pix: pix,
|
Pix: pix,
|
||||||
Stride: 4 * i.width,
|
Stride: 4 * i.width,
|
||||||
|
@ -78,8 +78,8 @@ func NewScreenFramebufferMipmap(width, height int) *Mipmap {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Mipmap) Dump(name string) error {
|
func (m *Mipmap) Dump(name string, blackbg bool) error {
|
||||||
return m.orig.Dump(name)
|
return m.orig.Dump(name, blackbg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Mipmap) Fill(clr color.RGBA) {
|
func (m *Mipmap) Fill(clr color.RGBA) {
|
||||||
|
@ -577,6 +577,6 @@ func (i *Image) isInvalidated() (bool, error) {
|
|||||||
return i.image.IsInvalidated(), nil
|
return i.image.IsInvalidated(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) Dump(path string) error {
|
func (i *Image) Dump(path string, blackbg bool) error {
|
||||||
return i.image.Dump(path)
|
return i.image.Dump(path, blackbg)
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ func RestoreIfNeeded() error {
|
|||||||
// This is for testing usage.
|
// This is for testing usage.
|
||||||
func DumpImages(dir string) error {
|
func DumpImages(dir string) error {
|
||||||
for img := range theImages.images {
|
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
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -529,11 +529,11 @@ func (i *Image) allocate(shareable bool) {
|
|||||||
i.node = n
|
i.node = n
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) Dump(path string) error {
|
func (i *Image) Dump(path string, blackbg bool) error {
|
||||||
backendsM.Lock()
|
backendsM.Lock()
|
||||||
defer backendsM.Unlock()
|
defer backendsM.Unlock()
|
||||||
|
|
||||||
return i.backend.restorable.Dump(path)
|
return i.backend.restorable.Dump(path, blackbg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewScreenFramebufferImage(width, height int) *Image {
|
func NewScreenFramebufferImage(width, height int) *Image {
|
||||||
|
Loading…
Reference in New Issue
Block a user