Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » [A5] Bitmap loading without extension

This thread is locked; no one can reply to it. rss feed Print
[A5] Bitmap loading without extension
Sebastian Steinhauer
Member #12,449
December 2010
avatar

Hi there.

I just discovered, that A5 won't load a bitmap without a given extension. A short review of the bitmap_io.c confirmed that behavior. My question is here is, why ? Every supported image format has it's file magic, so it should be no problem to try every installed bitmap loader until some had an success. I discovered this problem, when I wrote my own container format, which uses hashes instead of filenames and so I had no information of the suffix, when it comes to load the bitmap. But there's even an A5 builtin scenario, where this image loading procedure will fail. Just think of the usage of PhysFS and let the user choose a WAD archive. As you know the old Doom 1+2 WAD files only support 8 characters per file without any extension. So loading bitmaps from a WAD will fail.

I haven't looked into the audio loading code yet, but I bet there's the same problem with the extension.

So to solve the problem, the image/audio loader should
1) check the extension, and try to load the image as before
2) if no extension, try the whole list of installed loaders

I'm no sure if this forum or the mailing list is the right place for that.

Thanks,
Sebastian

Thomas Fjellstrom
Member #476
June 2000
avatar

If you want to get around that, try using the al_load_bitmap_f function. You'll need to al_fopen the file first.

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

Sebastian Steinhauer
Member #12,449
December 2010
avatar

Hi Thomas,

that's not an good solution. Because you have to provide the extension using the al_load_bitmap_f function. But in my WAD example you have something like IMG001, IMG002, IMG003 etc. and some are PNGs and some are JPGs. So to use the al_load_bitmap_f you have to decide which loader should be used. I can do this by reading the first bytes and decide myself, but I think that should be done in the library. And most loaders I'm aware of (like libpng / libjpg) check the headers before loading the file.

Thomas Fjellstrom
Member #476
June 2000
avatar

You should know what format your images are in. Sure its annoying how it is, but you can deal with it for now.

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

Elias
Member #358
May 2000

Can we have a function al_detect_filetype which would return the extension?

[edit:] Or now that we have the loading flags, just a new loading flag ALLEGRO_AUTODETECT_FILETYPE?

--
"Either help out or stop whining" - Evert

Matthew Leverton
Supreme Loser
January 1999
avatar

Elias said:

Can we have a function al_detect_filetype which would return the extension?
[edit:] Or now that we have the loading flags, just a new loading flag ALLEGRO_AUTODETECT_FILETYPE?

Both would be useful. The latter could use the function to do it. If we are just pragmatic and support the common formats that Allegro uses, it shouldn't be too bad. That could include images, audio, fonts, etc. If you want more than that, then see something like magic_open.

Go to: