The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
SDL2 save Surface as PNG
LBandy


Joined: 01 Jan 2013
Posts: 38
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?
SDL2 save Surface as PNG
Mason Wheeler
Guest

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:
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:
http://www.youtube.com/watch?v=yMGdfNHGhIU&hd=1



_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
LBandy


Joined: 01 Jan 2013
Posts: 38
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!
SDL2 save Surface as PNG
Driedfruit
Guest

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:

Quote:
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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL2 save Surface as PNG
Mason Wheeler
Guest

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



From: Driedfruit
To:
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:

Quote:
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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL2 save Surface as PNG
René Dudfield
Guest

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 :)

ps. so excited about SDL 2!!!!


On Sat, May 4, 2013 at 6:39 PM, Mason Wheeler wrote:
Quote:
*shrug* That's actually pretty similar to what I've got. Saving to a PNG is pretty straightforward, really.



From: Driedfruit
To:
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:

Quote:
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:




--
driedfruit
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org









_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

SDL2 save Surface as PNG
Jonathan Greig
Guest

I agree with Mason on this, lets get this functionality mainlined.
- Swyped from my droid.
Quote:
On May 6, 2013 6:29 AM, "René Dudfield" wrote:

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 :)

ps. so excited about SDL 2!!!!



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

*shrug* That's ...
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

SDL2 save Surface as PNG
René Dudfield
Guest

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

http://bugzilla.libsdl.org/show_bug.cgi?id=751
SDL2 save Surface as PNG
urkle


Joined: 23 Sep 2012
Posts: 77
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, Cool;




On May 6, 2013, at 10:32 , René Dudfield wrote:
Quote:
Here is the bug for save png... with old patch...

http://bugzilla.libsdl.org/show_bug.cgi?id=751
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Edward Rudd
OutOfOrder.cc
Skype: outoforder_cc
317-674-3296
SDL2 save Surface as PNG
René Dudfield
Guest

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:
Quote:
Here is the bug for save png... with old patch...

http://bugzilla.libsdl.org/show_bug.cgi?id=751
SDL2 save Surface as PNG
Sam Lantinga


Joined: 10 Sep 2009
Posts: 1765
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:
Quote:
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:
Quote:
Here is the bug for save png... with old patch...

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





_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

LBandy


Joined: 01 Jan 2013
Posts: 38
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?
SDL2 save Surface as PNG
Jonas Kulla
Guest

2013/10/27 LBandy
Quote:
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.
SDL2 save Surface as PNG
Driedfruit
Guest

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:

Quote:
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
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
SDL2 save Surface as PNG
Joseph Carter


Joined: 20 Sep 2013
Posts: 279
On Sat, Oct 26, 2013 at 08:11:24PM +0400, Driedfruit wrote:
Quote:
AFAIK, SDL_SavePNG exists in SDL2 already. So you should probably
use that. Actually, I'm surprised there aren't any name collisions.
Hmm.

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. 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.

Joseph

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Re: SDL2 save Surface as PNG
LBandy


Joined: 01 Jan 2013
Posts: 38
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. Smile
SDL2 save Surface as PNG
opcow


Joined: 24 Sep 2013
Posts: 4
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:
Quote:



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.



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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

SDL2 save Surface as PNG
Driedfruit
Guest

On Mon, 28 Oct 2013 06:28:10 +0000
"LBandy" wrote:

You guys are right, it's the SDL2_image, that has the new png-saving
ability. I knew it existed 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!

--
driedfruit
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org