Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Grabber and png

This thread is locked; no one can reply to it. rss feed Print
Grabber and png
APrince
Member #12,698
March 2011

Hi, is there a way to grab png images to a datafile or do I have to convert all of my images to targa first?

LennyLen
Member #5,313
December 2004
avatar

You can add files of any type, even if they're not one that Allegro supports natively (such as PNG).

Just select "Other" as the type of object you want, and then grab as you would normally.

Johan Halmén
Member #1,550
September 2001

Yes. You won't see the image in Grabber, but that's not important, is it? And if it is, I guess you can rebuild Grabber and add png as a known image format. Grabber won't convert it to a BITMAP* object. It comes as a png chunk into your program's DATAFILE* object. And you use load_memory_png() to create the BITMAP* object.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Years of thorough research have revealed that the red "x" that closes a window, really isn't red, but white on red background.

Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest.

APrince
Member #12,698
March 2011

Thank's - I'll try that.

//edit: This load_memory_png is a function from loadpng and I have to download that separately, i take it... Right?

LennyLen
Member #5,313
December 2004
avatar

If you're using loadpng, look at the exdata.c example for the recommended way of loading a PNG from a datafile.

Edgar Reynaldo
Member #8,592
May 2007
avatar

APrince
Member #12,698
March 2011

"loadpng comes with Allegro 4.4, you just have to include its headers and link to it like any other library."

It seemed strange to me, because I didn't have to do anything extra to use png images (AL 5.0.1).

Thank's very much, I'm going to try that.

Thomas Fjellstrom
Member #476
June 2000
avatar

APrince said:

It seemed strange to me, because I didn't have to do anything extra to use png images (AL 5.0.1).

Yeah, allegro 5 is a new API and library. It's image loader addon includes PNG support.

Allegro 4.4 has a png loader addon included, 4.2 and before do not include a png loader addon, but there is an older version of loadpng available for them.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

APrince
Member #12,698
March 2011

Thank's.

I have two more questions...

1) I cannot find loadpng in Allegro 5. In Allegro 4.4 it is in Allegro/addons but I really don't know, where to find it in A5.

2) I need to grab about 100 png images... Is there a way to select them somehow all at once, or do I have to do that manually? The problems is I don't really understand the grabber and documentation doesn't help much. What I do, is that I select Object->new->other then fill in type as PNG and whatever name and then Object->grab and select the corresponding file. I can't imagine doing this for a hundred files...

Thank's a lot.

LennyLen
Member #5,313
December 2004
avatar

APrince said:

1) I cannot find loadpng in Allegro 5. In Allegro 4.4 it is in Allegro/addons but I really don't know, where to find it in A5.

A5 does not use loadpng. Instead, you use the image IO addon routines in conjunction with al_load_bitmap or al_load_bitmap_f

Quote:

2) I need to grab about 100 png images... Is there a way to select them somehow all at once, or do I have to do that manually? The problems is I don't really understand the grabber and documentation doesn't help much. What I do, is that I select Object->new->other then fill in type as PNG and whatever name and then Object->grab and select the corresponding file. I can't imagine doing this for a hundred files...

The datafile format (and therefore the grabber tool) are not supported by A5. If you want to use the grabber, you will need to write your own routines for extracting the data from them.

But to answer the question anyway, to add multiple files like that, don't use the grabber, use the command line dat utility instead.

Luiji99
Member #12,254
September 2010

Does anybody actually want to use Allegro 4 DATAFILEs with Allegro 5, or is everyone comfortable with PhysicsFS's archive formats? (Personally I like a PAK/ZIP mixture.)

Programming should be fun. That's why I hate Java.
http://www.entertainingsoftware.com/

APrince
Member #12,698
March 2011

Well now I'm really confused... If I get this right, I suppose that everything to this point was irrelevant, because somehow everyone assumed I use Allegro 4. Now that there's the knowledge I use Allegro 5, everyrhing changes... Right? I don't really want to bother you, if there is any tutorial on how to solve this thing I would really appreciate it...

Where can I get the tool you mentioned (command line dat utility)? I cannot find it amongst the Allegro utilities.

Audric
Member #907
January 2001

It's the word "datafile" that everybody understands as the specific file format that was supported in Allegro 4.
Allegro 5 cannot read this format (and even the structs stored inside: BITMAP, RLE_SPRITE etc. are different from Allegro 5's AL_BITMAP)
so you shouldn't bother anymore with the grabber.exe and dat.exe, they are all for Allegro 4.

In Allegro 5, if you want to store all resources in a single file, the handy way is to make a zip archive (using any standard tools, the zip can even use sub-directories) and in your program, use the PhysicsFS addon to access the individual items.
The idea is that you call:

PHYSFS_init();
PHYSFS_addToSearchPath("mydata.zip", 1);
al_set_physfs_file_interface();

and then any call to al_load_bitmap() will read items in the zip.

See the complete example ex_physfs.c in the distribution.

APrince
Member #12,698
March 2011

It's not really about storing everything in one file. The point is to prevent a "common user" from overriding those images with something else and thus defacing the program... Common zip will not solve this (niether datafile would, I suppose, but it would surely make it much more difficult). Maybe if the zip archive was password protected...

Thomas Fjellstrom
Member #476
June 2000
avatar

Or just don't use the .zip file ending. call it .dat or something. Most people would be confused. A lot of games do that.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

APrince
Member #12,698
March 2011

Thank's a lot, that may work... :-)

//edit: Thank's to all of you, it works perfectly...

Go to: