SDL2 save Surface as PNG

I’ve surfed the web for a couple of hours by now, and haven’t find any good solution for this issue yet. I’ve managed to come across some code using SDL 1.2, but they do not work with the SDL2_image library. Is there such a thing exists already?------------------------
Runic Girls - a hexa match3 game with girls created using SDL 2.0:
http://www.facebook.com/RunicGirls

Gameplay trailer:

I submitted a patch for this several years ago.? AFAIK it never got integrated into SDL_Image.? I’ve maintained it on my end, and it was trivial to make work with the SDL2 version of SDL_Image.? We really ought to get it integrated officially.

Mason________________________________
From: LBandy
To: sdl at lists.libsdl.org
Sent: Friday, May 3, 2013 1:00 PM
Subject: [SDL] SDL2 save Surface as PNG

I’ve surfed the web for a couple of hours by now, and haven’t find any good solution for this issue yet. I’ve managed to come across some code using SDL 1.2, but they do not work with the SDL2_image library. Is there such a thing exists already?


Runic Girls - a hexa match3 game with girls created using SDL 2.0:
http://www.facebook.com/RunicGirls

Gameplay trailer:


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Thanks for the reply, Mason. Do you think it is possible for me to use your extension? I would gladly give you the credit for it!------------------------
Runic Girls - a hexa match3 game with girls created using SDL 2.0:
http://www.facebook.com/RunicGirls

Gameplay trailer:

Pretty sure anything Mason wrote is leagues ahead of my code, but I do
too have a version I maintain

It works with SDL2 as of recently.On Fri, 03 May 2013 13:00:54 -0700 “LBandy” wrote:

I’ve surfed the web for a couple of hours by now, and haven’t find
any good solution for this issue yet. I’ve managed to come across
some code using SDL 1.2, but they do not work with the SDL2_image
library. Is there such a thing exists already?


Runic Girls - a hexa match3 game with girls created using SDL 2.0:
http://www.facebook.com/RunicGirls

Gameplay trailer:
http://www.youtube.com/watch?v=yMGdfNHGhIU&hd=1


driedfruit

shrug That’s actually pretty similar to what I’ve got. Saving to a PNG is pretty straightforward, really.________________________________
From: Driedfruit
To: sdl at lists.libsdl.org
Sent: Saturday, May 4, 2013 5:42 AM
Subject: Re: [SDL] SDL2 save Surface as PNG

Pretty sure anything Mason wrote is leagues ahead of my code, but I do
too have a version I maintain

It works with SDL2 as of recently.

On Fri, 03 May 2013 13:00:54 -0700 “LBandy” wrote:

I’ve surfed the web for a couple of hours by now, and haven’t find
any good solution for this issue yet. I’ve managed to come across
some code using SDL 1.2, but they do not work with the SDL2_image
library. Is there such a thing exists already?


Runic Girls - a hexa match3 game with girls created using SDL 2.0:
http://www.facebook.com/RunicGirls

Gameplay trailer:
http://www.youtube.com/watch?v=yMGdfNHGhIU&hd=1


driedfruit


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

lol, there is also a version in the pygame sources to save png. Probably
implemented in 17 other places too… hehe.

Where is the bugzilla bug for it? We can collaborate there :slight_smile:

ps. so excited about SDL 2!!!On Sat, May 4, 2013 at 6:39 PM, Mason Wheeler wrote:

shrug That’s actually pretty similar to what I’ve got. Saving to a PNG
is pretty straightforward, really.


From: Driedfruit
To: sdl at lists.libsdl.org
Sent: Saturday, May 4, 2013 5:42 AM
Subject: Re: [SDL] SDL2 save Surface as PNG

Pretty sure anything Mason wrote is leagues ahead of my code, but I do
too have a version I maintain

https://github.com/driedfruit/SDL_SavePNG

It works with SDL2 as of recently.

On Fri, 03 May 2013 13:00:54 -0700 “LBandy” wrote:

I’ve surfed the web for a couple of hours by now, and haven’t find
any good solution for this issue yet. I’ve managed to come across
some code using SDL 1.2, but they do not work with the SDL2_image
library. Is there such a thing exists already?


Runic Girls - a hexa match3 game with girls created using SDL 2.0:
http://www.facebook.com/RunicGirls

Gameplay trailer:
http://www.youtube.com/watch?v=yMGdfNHGhIU&hd=1


driedfruit


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I agree with Mason on this, lets get this functionality mainlined.

  • Swyped from my droid.

lol, there is also a version in the pygame sources to save png. Probably
implemented in 17 other places too… hehe.

Where is the bugzilla bug for it? We can collaborate there :slight_smile:

ps. so excited about SDL 2!!!On May 6, 2013 6:29 AM, “Ren? Dudfield” wrote:

On Sat, May 4, 2013 at 6:39 PM, Mason Wheeler wrote:

shrug That’s …


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Here is the bug for save png… with old patch…

http://bugzilla.libsdl.org/show_bug.cgi?id=751

http://lodev.org/lodepng/

Me personally I use lodepng for all my png loading and saving needs. It removes my reliance on libpng entirely and the API is super simple.

lodepng_encode_file(filename, (const char*)imageData, width, height, LCT_RGBA, 8);On May 6, 2013, at 10:32 , Ren? Dudfield wrote:

Here is the bug for save png… with old patch…

http://bugzilla.libsdl.org/show_bug.cgi?id=751


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Edward Rudd
OutOfOrder.cc
Skype: outoforder_cc
317-674-3296

Sam? Would a save png patch for 2.0 be accepted?

(also what about jpeg and TGA?)

cheers,On Mon, May 6, 2013 at 4:32 PM, Ren? Dudfield <@Rene_Dudfield> wrote:

Here is the bug for save png… with old patch…

http://bugzilla.libsdl.org/show_bug.cgi?id=751

Load and save of PNG would be accepted if they were small and didn’t
introduce a dependency on libpng or libz. If they did, it would be more
acceptable in SDL_image, but I’ve hesitated to add save functionality
because then everyone would want a save function for every single format
supported by SDL_image.On Fri, May 10, 2013 at 3:40 AM, Ren? Dudfield wrote:

Sam? Would a save png patch for 2.0 be accepted?

(also what about jpeg and TGA?)

cheers,

On Mon, May 6, 2013 at 4:32 PM, Ren? Dudfield wrote:

Here is the bug for save png… with old patch…

http://bugzilla.libsdl.org/show_bug.cgi?id=751


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

AFAIK, SDL_SavePNG exists in SDL2 already. So you should probably
use that. Actually, I’m surprised there aren’t any name collisions.
Hmm.

As for the bugs, I can take a look, but could you provide more info?
(We can take it off-list). What surface are you saving (bpp,
pixelformat), are you using the SDL_PNGFormatAlpha function, what do
you mean by colors being turned to blue, etc?

Second one sounds like there’s something painfully stupid going on,
I’ll double-check.On Sun, 27 Oct 2013 20:00:40 +0000 “LBandy” wrote:

I’m trying to use the SavePNG written by Driedfruit. Right now I’m
facing two problems:

  • upon saving a surface, all colors are turned to blue on the output
    png
  • the saved png file is only accessable after closing the application

Any advices how to solve these?


Runic Girls - a hexa match3 game with girls created using SDL 2.0:
http://www.facebook.com/RunicGirls

Gameplay trailer:
http://www.youtube.com/watch?v=yMGdfNHGhIU&hd=1


driedfruit

I’m trying to use the SavePNG written by Driedfruit. Right now I’m facing two problems:

  • upon saving a surface, all colors are turned to blue on the output png
  • the saved png file is only accessable after closing the application

Any advices how to solve these?------------------------
Runic Girls - a hexa match3 game with girls created using SDL 2.0:
http://www.facebook.com/RunicGirls

Gameplay trailer:

2013/10/27 LBandy

**
I’m trying to use the SavePNG written by Driedfruit. Right now I’m facing
two problems:

  • upon saving a surface, all colors are turned to blue on the output png
  • the saved png file is only accessable after closing the application

Any advices how to solve these?

I can confirm the second issue, seems like a file descriptor isn’t properly
flushed/closed
after the call. By the way, although it doesn’t appear to be documented, I
have spotted
’IMG_SavePNG(_RW)’ functions in my SDL_image.h header from latest
mercurial; if you’re
already using this library you might want to try out those too.

SDL_SavePNG doesn’t exist in SDL. You’re thinking SDL_image perhaps?

It does have SDL_LoadBMP/SDL_SaveBMP, just because, well, it kinda
needed something. :slight_smile: Plus, BMP is a simple format with low code
overhead, and it’s a lot more common than PCX or Targa. It has some
"unique" features, but so does anything else you’re going to come up
with.

JosephOn Sat, Oct 26, 2013 at 08:11:24PM +0400, Driedfruit wrote:

AFAIK, SDL_SavePNG exists in SDL2 already. So you should probably
use that. Actually, I’m surprised there aren’t any name collisions.
Hmm.

Driedfruit wrote:

As for the bugs, I can take a look, but could you provide more info?
(We can take it off-list). What surface are you saving (bpp,
pixelformat), are you using the SDL_PNGFormatAlpha function, what do
you mean by colors being turned to blue, etc?

Thanks for the reply, I will give it a go with the SDL_image version. In the meantime, I’ve uploaded two pictures to see for yourself:
I load the first one, when converting it to texture and showing it in the program it looks nice, then I call SDL_PNGFormatAlpha() and SDL_SavePNG_RW() functions. The resulted image file is the 1_.png.


My email address is lbandy3 at gmail dot com. Thank you for your help in advance. :)------------------------
Runic Girls - a hexa match3 game with girls created using SDL 2.0:
http://www.facebook.com/RunicGirls

Gameplay trailer:

Your red and blue channels appear to be swapped. Just an observance. I
don’t know why.On Mon, Oct 28, 2013 at 2:28 AM, LBandy wrote:

**

Driedfruit wrote:

As for the bugs, I can take a look, but could you provide more info?
(We can take it off-list). What surface are you saving (bpp,
pixelformat), are you using the SDL_PNGFormatAlpha function, what do
you mean by colors being turned to blue, etc?

Thanks for the reply, I will give it a go with the SDL_image version. In
the meantime, I’ve uploaded two pictures to see for yourself:
I load the first one, when converting it to texture and showing it in the
program it looks nice, then I call SDL_PNGFormatAlpha() and
SDL_SavePNG_RW() functions. The resulted image file is the 1_.png.

http://bondorandras.com/sdl/1.png
http://bondorandras.com/sdl/1_.png

My email address is lbandy3 at gmail dot com. Thank you for your help in
advance. [image: Smile]


Runic Girls - a hexa match3 game with girls created using SDL 2.0:
http://www.facebook.com/RunicGirls

Gameplay trailer:
http://www.youtube.com/watch?v=yMGdfNHGhIU&hd=1


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

You guys are right, it’s the SDL2_image, that has the new png-saving
ability. I knew it existed :slight_smile: So, for all the SDL2 apps, I’d definitly
recommend using that.

And I believe I’ve fixed the bugs you reported, both the BGR channel
swap and the file descriptor one. Thanks!On Mon, 28 Oct 2013 06:28:10 +0000 “LBandy” wrote:


driedfruit