PNG file save (Uncompressed and VC++ only)

Monkey Targets Forums/Desktop/PNG file save (Uncompressed and VC++ only)

Fred(Posted 2015) [#1]
Hi, after the very cheap BMP file, here comes the cheap PNG save file. I saw a recent thread about it, and as I need it too (PNG has alpha channel, BMP don't) I gave a try to LibPNG and zlib, then I gave up. I found and easy to implement UNCOMPRESSED PNG source code from Jeff Muizelaar. here it is:
png_file.monkey


and the minpng.cpp




ImmutableOctet(SKNG)(Posted 2015) [#2]
I think you're a little late to the party. I already wrapped libpng, and it compresses properly. Here's my 'imageencoder' module; obviously, this is for C++ targets only. This isn't bad, though. Porting your version to Monkey as a fall-back would probably be the best option. Well, for cross-platform support, anyway. Otherwise, my version works just fine, all you have to do is move the usual lib and header files into your compiler's directories (Compilation may be required; not that doing so is difficult with VS2010). I should probably wrap stb at some point, so people don't need to use 'LoadImageData'.

Also, my version uses 'DataBuffers', so this is definitely still useful.


Fred(Posted 2015) [#3]
Yes ImmutableOctet, I saw your code and wanted to use it but I couldn't find a proper libpng or compiled it. I'll give it another chance as you did it in a better way, but I was on a hurry.


ImmutableOctet(SKNG)(Posted 2015) [#4]
Hey Fred, because MSVC's CRT setup is rather annoying, DLL usage was nearly impossible. This has changed in the newest version. All you should have to do is move the header files ("*.h" files) from libpng to your compiler's "include" directory ("C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include" is probably it). After that, you need to open the Visual Studio (2010) solution provided with libpng, then right-click, and build all of the specific projects you need; libpng and zlib in this case (Or you could build everything). The build mode you choose is your business, but I'd recommend using DLLs now ("Release" should work; probably the default). From there, move the "*.lib" files from your VS-build-folder for libpng (If you used "Release", it should just be called "Release") to your "lib" folder in MSVC ("C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib" is the default; 32-bit Windows doesn't use "Program Files (x86)", but instead, "Program Files", but you get the idea). My code will take care of the rest. All you have to do is either move your compiled DLL from libpng into your Monkey build-folder's MSVC project folder(s) (If you went that route), or you could just leave it in "C:\Windows\SysWOW64" ("C:\Windows\System32" on 32-bit Windows), and it will always link with the DLL on runtime.

If you go the DLL route, just make sure to provide the DLL with the project in question (Assuming you're releasing it / giving it to someone else who doesn't have libpng). The DLL should be perfectly fine to redistribute, at least from what the license says. The "lib" route is different. A "lib" file is compiled and linked to when compiling / linking together your project, so it needs to be built for the configuration you're using ("Release" or "Debug"). This is problematic for Monkey, because you'd need to either edit your own project files in your Monkey build-folder, or the edit the default project from the template for that target. There is one other option, but that's basically switching out "lib" files every configuration change; this is horrible, and it was what I was doing before. Since you can't link with "lib" files as easily as DLLs, and keeping things as DLLs is generally beneficial, I recommend just doing that. Also make sure not to release "Debug" DLLs, they won't run on computers without VS2010.

Anyway, that should clear up your problem. I'm not going to tell you how to get things working with MinGW/GCC, but it's nothing too complicated. I just haven't gotten to it yet.

Well, that was a fun waste of time to go through on my birthday.


Fred(Posted 2015) [#5]
Thank you for the explanations and Happy Birthday!