Author Topic: Adding PNG support to CreateFromFile ?  (Read 743 times)

Monsieur OUXX

  • Mittens Half Initiate
    • I can help with proof reading
    • I can help with translating
    • I can help with voice acting
    • Monsieur OUXX worked on one or more games that won an AGS Award!
    •  
    • Monsieur OUXX worked on one or more games that was nominated for an AGS Award!
Adding PNG support to CreateFromFile ?
« on: 30 Mar 2019, 19:09 »
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: Adventure Game Studio
  1. Function "LoadImageFile" in /Engine/ac/global_dynamicsprite.cpp
  2. Function "LoadFromFile" in /Common/gfx/bitmap.cpp
  3. Function "LoadFromFile" in /Common/gfx/allegrobitmap.cpp
  4.  

« Last Edit: 30 Mar 2019, 19:11 by Monsieur OUXX »
 

Crimson Wizard

  • Local Moderator
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    • Lifetime Achievement Award Winner
    • Crimson Wizard worked on one or more games that won an AGS Award!
    •  
    • Crimson Wizard worked on one or more games that was nominated for an AGS Award!
Re: Adding PNG support to CreateFromFile ?
« Reply #1 on: 30 Mar 2019, 19:47 »
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.
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.
« Last Edit: 30 Mar 2019, 20:08 by Crimson Wizard »

Monsieur OUXX

  • Mittens Half Initiate
    • I can help with proof reading
    • I can help with translating
    • I can help with voice acting
    • Monsieur OUXX worked on one or more games that won an AGS Award!
    •  
    • Monsieur OUXX worked on one or more games that was nominated for an AGS Award!
Re: Adding PNG support to CreateFromFile ?
« Reply #2 on: 31 Mar 2019, 18:03 »
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.
« Last Edit: 31 Mar 2019, 18:40 by Monsieur OUXX »
 

Crimson Wizard

  • Local Moderator
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    • Lifetime Achievement Award Winner
    • Crimson Wizard worked on one or more games that won an AGS Award!
    •  
    • Crimson Wizard worked on one or more games that was nominated for an AGS Award!
Re: Adding PNG support to CreateFromFile ?
« Reply #3 on: 31 Mar 2019, 19:17 »
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.
« Last Edit: 31 Mar 2019, 19:25 by Crimson Wizard »

Monsieur OUXX

  • Mittens Half Initiate
    • I can help with proof reading
    • I can help with translating
    • I can help with voice acting
    • Monsieur OUXX worked on one or more games that won an AGS Award!
    •  
    • Monsieur OUXX worked on one or more games that was nominated for an AGS Award!
Re: Adding PNG support to CreateFromFile ?
« Reply #4 on: 01 Apr 2019, 08:04 »
You're a life saver.

 

Monsieur OUXX

  • Mittens Half Initiate
    • I can help with proof reading
    • I can help with translating
    • I can help with voice acting
    • Monsieur OUXX worked on one or more games that won an AGS Award!
    •  
    • Monsieur OUXX worked on one or more games that was nominated for an AGS Award!
Re: Adding PNG support to CreateFromFile ?
« Reply #5 on: 10 Apr 2019, 23:06 »
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

  • Local Moderator
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    • Lifetime Achievement Award Winner
    • Crimson Wizard worked on one or more games that won an AGS Award!
    •  
    • Crimson Wizard worked on one or more games that was nominated for an AGS Award!
Re: Adding PNG support to CreateFromFile ?
« Reply #6 on: 11 Apr 2019, 11:22 »
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.
« Last Edit: 11 Apr 2019, 11:47 by Crimson Wizard »

Monsieur OUXX

  • Mittens Half Initiate
    • I can help with proof reading
    • I can help with translating
    • I can help with voice acting
    • Monsieur OUXX worked on one or more games that won an AGS Award!
    •  
    • Monsieur OUXX worked on one or more games that was nominated for an AGS Award!
Re: Adding PNG support to CreateFromFile ?
« Reply #7 on: 12 Apr 2019, 13:12 »
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.
« Last Edit: 12 Apr 2019, 13:19 by Monsieur OUXX »
 

Crimson Wizard

  • Local Moderator
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    • Lifetime Achievement Award Winner
    • Crimson Wizard worked on one or more games that won an AGS Award!
    •  
    • Crimson Wizard worked on one or more games that was nominated for an AGS Award!
Re: Adding PNG support to CreateFromFile ?
« Reply #8 on: 12 Apr 2019, 13:21 »
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.
« Last Edit: 12 Apr 2019, 13:23 by Crimson Wizard »