Adding PNG support to CreateFromFile ?

Started by Monsieur OUXX, Sat 30/03/2019 19:09:35

Previous topic - Next topic

Monsieur OUXX

I'm pondering the creation of a branch off "develop" to add PNG support for DynamicSprite.CreateFromFile. It shouldn't be too hard I believe. It's just a matter of adding a call to this (library "loadpng") where the native Allegro call would normally be done.

Is there any licensing issues though? I mean with libpng and zlib.


For the record, the interesting code is here:
Code: ags

Function "LoadImageFile" in /Engine/ac/global_dynamicsprite.cpp
Function "LoadFromFile" in /Common/gfx/bitmap.cpp
Function "LoadFromFile" in /Common/gfx/allegrobitmap.cpp


 

Crimson Wizard

#1
AFAIK zlib license is very permissive. Could not find a license for loadpng itself, but I think AGS already uses something of same author (Peter Wang).
https://opensource.org/licenses/Zlib

Not sure where it should be added, whether to Bitmap class or BitmapHelpers namespace. Bitmap class is very old and its design may not be ideal (it has some utility functions as members), but it all depends on how loadpng works and what does it return. E.g. if it returns Allegro's BITMAP pointer, then you can create new Bitmap object using WrapAllegroBitmap function or constructor Bitmap(BITMAP *al_bmp, bool shared_data); shared_data = false in this case.


PS.
Quote from: Monsieur OUXX on Sat 30/03/2019 19:09:35
I'm pondering the creation of a branch off "develop" to add PNG support for DynamicSprite.CreateFromFile.

"develop" is an old branch no longer found in current repository. Current WIP version is in "ags3" branch.

Monsieur OUXX

#2
Quote from: Crimson Wizard on Sat 30/03/2019 19:47:40
Quote from: Monsieur OUXX on Sat 30/03/2019 19:09:35
I'm pondering the creation of a branch off "develop" to add PNG
"develop" is an old branch no longer found in current repository. Current WIP version is in "ags3" branch.

I've forked from the main repository (on GitHub) but I'm slightly confused: I had done a fork already in the past, and now it's reusing the same fork instead of creating a new one (one single fork per project per user???). The files in my fork are from a billion years ago. But a fork is not a branch (or is it?) so I don't know how to rebase it on master or "ags3". Should I try that or should I just clone the "regular repo" (not my fork) and create a branch there directly? I've read the guidelines in the sticky thread and they definitely recommend to fork first.
 

Crimson Wizard

#3
Quote from: Monsieur OUXX on Sun 31/03/2019 18:03:22
I've forked from the main repository (on GitHub) but I'm slightly confused: I had done a fork already in the past, and now it's reusing the same fork instead of creating a new one (one single fork per project per user???). The files in my fork are from a billion years ago. But a fork is not a branch (or is it?) so I don't know how to rebase it on master or "ags3". Should I try that or should I just clone the "regular repo" (not my fork) and create a branch there directly? I've read the guidelines in the sticky thread and they definitely recommend to fork first.

"Fork" is a clone of all repository with all the branches.

Alright, so first of all you need to sync your existing fork with main repository, or at least few active branches (ags3, master)
IMPORANT NOTE: no rebase is necessary, and that will actually be a wrong thing to do (screw many things up).

Here's usual process.

1) Your local repository should have references to both **your** own remote, and **our** remote. It may be in sync with your remote, but you need to also update it to know what has changed in ours.
I don't know which Git UI you are using, if any, but from command line this is done as:

    git fetch <our remote name>

Here "our remote name" depends on how did you configure it. It does not necessarily match what we use. By default it's often called "upstream", but you may need to check your local settings.

After you did that you should be able to see our remote's state and checkout new branches (such as ags3) in your local place.

2) Checkout branch ags3:

    git checkout ags3 <our remote name>/ags3

This will create local branch "ags3" synced with our remote one.

3) Then push this branch to *your* remote:

    git push origin ags3

You may want to configure your repository to bind "ags3" branch with yours remote (otherwise you will be trying to push to ours everytime if you forget to explicitly tell "push origin").
I don't remember how to do this by hand, maybe if you're using some git UI there are easier ways.

Monsieur OUXX

 

Monsieur OUXX

I've built the branch "allegro-4.4.2-agspatch" that I got from https://github.com/adventuregamestudio/lib-allegro, but all it builds is "alleg-debug-static.lib".
It does not generate"alleg.lib" that alfont demands when trying to build it from branch alfont-1.9.1-agspatch.
 

Crimson Wizard

#6
Quote from: Monsieur OUXX on Wed 10/04/2019 23:06:50
I've built the branch "allegro-4.4.2-agspatch" that I got from https://github.com/adventuregamestudio/lib-allegro, but all it builds is "alleg-debug-static.lib".
It does not generate"alleg.lib" that alfont demands when trying to build it from branch alfont-1.9.1-agspatch.

1) How did you built it, did you use MSVS project or something else? MSVS project contains all 4 configuration which you may build either by switching manually or using "Batch Build" command.

2) You need to build static alfont library, that should not demand allegro at all if I remember correctly. You may ignore alfont_dll project.

Also, all libraries are already prebuilt and packaged here: https://www.dropbox.com/s/4p6nw6waqwat6co/ags-prebuilt-libs.zip?dl=0
This link is given in the first section of Windows/README.md, but lot of people seem to miss it.

PS. We are currently moving towards embedding alfont/freetype library source in the engine for some reasons, so next 3.5.0 release may not require alfont.lib to build at all.

Monsieur OUXX

#7
Quote from: Crimson Wizard on Thu 11/04/2019 11:22:39
This link is given in the first section of Windows/README.md, but lot of people seem to miss it.

Yes, I do miss it every time. And this time, believe it or not, I was specifically looking for it. I was like "I seem to remember that the built libraries were here somewhere. Oh, I must jave dreamt it".

I'm building with VS2017, and I tried the 2 build configurations (MD and the other one), both in static and dynamic (which means I tried 4 build configurations).
They produce files named like "allegro-debug-static.lib", so each time I tried to rename the file to "alleg.lib", for alfont to be happy. But I knew that the debug static one should have been the correct one. Yet the linker failed to find the proper functions when building alfont.
But as you said, maybe I picked the wrong build configuration for alfont itself. For my personal education: How do I make sure I'm trying to build the configuration for the static version?

That said, it doesn-t really matter now, as I'll use the pre-built ones.
 

Crimson Wizard

#8
Hm, I was not clear regarding this, what I mean - there are two projects in alfont solution, one makes DLL, another makes static lib. You only need to build 1 project - a static alfont lib - for AGS, and that does not require to have allegro libs on its own.

Baguettator

Hi there !

I found this thread, and I was asking : is there any way to use PNG files with the CreatFromFile function ? I use AGS 3.5

I hope so :)

Let me know !

Many thanks !

Crimson Wizard

Quote from: Baguettator on Mon 31/05/2021 09:38:05
I found this thread, and I was asking : is there any way to use PNG files with the CreatFromFile function ? I use AGS 3.5

Not now, perhaps if there were a plugin that would convert a PNG into bitmap and create dynamic sprite with that.

Baguettator

Ow, sad...

Because a BMP can't have any transparency attribute, isn't it ?

My goal is to let the player choose an image for a character. For a better experience, it could be nice that this image can show the character without any blank background or something else.

Any idea to avoid that with the actual functions in AGS ?

Crimson Wizard

Quote from: Baguettator on Mon 31/05/2021 15:09:04
Because a BMP can't have any transparency attribute, isn't it ?

32-bit bitmaps have an alpha channel. I don't remember ever testing how it works with CreateFromFile though.

Another way is probably to use "magic pink" colour which is default for transparent mask in AGS (255,0,255).

SMF spam blocked by CleanTalk