Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » load compressed bmp in Allegro 4.22

This thread is locked; no one can reply to it. rss feed Print
load compressed bmp in Allegro 4.22
Striker
Member #10,701
February 2009
avatar

Hello all!

i am heavily involved with allegro programming these days. For some reasons i still use 4.22 with K&R C and it works fine. i did some good code with loading bitmaps and animate them. The results were quick and clean, better then expected. With JPGalleg i load JPG. With AGUP i build a menu and window system.

But now i am at a point where i need to load compressed .bmp files. They are a few thousands, every few in single directories. The files are correct, because i can load them converted to tga or pcx. (With JPG i always have the problem that the pink pixels values for transparency are not 255,0,255 anymore after conversion, another question to be asked). But obviously allegro 4.22 can load only uncompressed bmp.

The next step will be to save the arrays and/or linked lists together with the produced rle sprites in packfiles. The first is easy, the second too, i suppose, if one knows how to do it.

An optional feature of my game could be to load 3d files like .3ds and to render series of 2d bitmaps from it. But with 3ds it seems to be not so easy to find the loader code. But that is only optional, as i already have thousands of bitmaps.

Does anybody knows a solution to load compressed bmp in 4.22 without need to upgrade? You will get a download link of the ready game as a thanx.

Striker

Johan Halmén
Member #1,550
September 2001

What is compressed .bmp? I tried to save with Gimp, but the RLE compression option was dimmed out. Lots of other formats have RLE compression, but not .bmp! At least not in Gimp.

I usually save sprites as .tga to be able to include alpha transparency. And the compression works in Gimp, and in Grabber, where I create the data file.

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

Timorg
Member #2,028
March 2002

It most likely only does RLE in indexed mode.

____________________________________________________________________________________________
"c is much better than c++ if you don't need OOP simply because it's smaller and requires less load time." - alethiophile
OMG my sides are hurting from laughing so hard... :D

mystiscool
Member #4,441
March 2004
avatar

I found a class that loads BMPs on the Game Programming Wiki, and it says that it loads 8-bit RLE BMPs:

http://gpwiki.org/index.php/LoadBMPCpp

It's a fairly small class, and you could always write a wrapper function to load the BMP and create a bitmap out of it.

About the 3D stuff: if you haven't done anything with 3D before, keep in mind that it's probably going to be more complicated than it seems. If you want to write a simple 3D object loader, I think that the Wavefront OBJ format is one of the simplest. If you still want to go with 3DS, here's a description of the file format:

http://www.martinreddy.net/gfx/3d/3DS.spec

Rejoice, glory is ours - our young men have not died in vain. Their graves need no flowers, the tapes have recorded their names.
ELP's lyrics about the evils of tape backup systems

Striker
Member #10,701
February 2009
avatar

@mystiscool + the others,

Graphic workshop says to one of these strange bmp files:

Colours : 16.777.216
Packed size : 654 bytes
Unpacked size : 1200 bytes
Filetype : BMP Windows bitmap
Compression : 46%

and it handles it just like normal BMP. It can be converted to TGA, PCX and all other operations can be done. It seems this compressed BMP format is only a subformat of BMP and in many cases one will not even notice that it is compressed, as most professionell programs can handle it. But allegro 4.22 can`t.

in the mentioned routine there is an unpacking algorithm, but it is for 8bit(256) colours. Other packed formats are detected but not handled.

3d: the obj format is easy and works in most cases, thats true, but it has no texture information in it as far as i know. Without texture it is useless, because i need the real view of the objects to render series of bitmaps around them and later ingame to animate them by simply displaying the pictures.

Audric
Member #907
January 2001

BMP_file_format
Note the values for "compression method":

BI_RGB
No compression

BI_RLE8
BI_RLE4
RLE compression on indexed-color images (16 and 256 colors)

BI_BITFIELDS
RLE compression on hi/true-color images

BI_JPEG
BI_PNG
embedded formats

For BI_BITFIELDS, I found a relevant blog entry:
http://www.virtualdub.org/blog/pivot/entry.php?id=177

Tobias Dammers
Member #2,604
August 2002
avatar

Quote:

With JPG i always have the problem that the pink pixels values for transparency are not 255,0,255 anymore after conversion, another question to be asked

JPG is a lossy compression algorithm, which means that when you compress the image, and then decompress, the result is not guaranteed to be an exact copy of the original, but rather just 'similar' - how similar exactly, depends on the image in question, and the chosen compression.
I suggest you don't use JPG for pixel art; PNG offers loss-less compression for all kinds of color depths, and can be loaded using libpng.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

Striker
Member #10,701
February 2009
avatar

Thanks Audric, thats completely right. Now we know that packed bmp is part of the original specification. But how can we load the packed formats in allegro?

Yes, Tobias, JPG is lossy. I have made a little function with 3 sliders for r, g and b. There one can set the values which pixels should be made 255,0,255 to get the pink pixels (which are not exactly 255,0,255 anymore and now appear unwanted) away and make them transparent. But you have to pull the sliders very far to get all pink out of view... JPG changes them in a wide range. I called it "depinkize" ( i sometimes create my own english because it is not my motherlanguage, be patient, but i suppose you will guess what i mean).

BTW the bmp compression is loss-less too. When i loaded the from the packed bmp converted PCX and TGA there were none of these annoying pink pixels.

Audric
Member #907
January 2001

Wait, after some more search it seems BI_BITFIELDS isn't compressed either.

> But how can we load the packed formats in allegro?
In allegro, you can't since load_bitmap() doesn't handle some of these exotic formats.
It's possible to create a custom loader function, all it needs is standard binary file operations for the input, and create_bitmap() and putpixel() for the output. However it can only be done if you have exact and precise information on the way this compressed format works.

What is the program you're using, that creates those "compressed" BMP? Which other formats can it read and write ?

gnolam
Member #2,030
March 2002
avatar

Striker said:

3d: the obj format is easy and works in most cases, thats true, but it has no texture information in it as far as i know.

Yes it has. It's got texture coordinates for 1D, 2D and 3D textures. It just doesn't embed the texture into the file, which is a questionable practice anyway.

And just go with PNG already. :P

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

Striker
Member #10,701
February 2009
avatar

"What is the program you're using, that creates those "compressed" BMP? Which other formats can it read and write ?"

Thats the point, Audric. This program "rs2manager" produces only that bmps as output. It saves soldier bitmaps from a special rs2 file into a directory structure with 80 directorys where each movement has its own directory. I want to catch either the output of this program or i load the rs2 files directly. But then i need to get information of this rs2 format, which is seldom used too.

Gnolam, thats good, maybe i use obj or another format if there is an easy way to get it into my program.

Neil Walker
Member #210
April 2000
avatar

why not just use pcx?

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

Striker
Member #10,701
February 2009
avatar

Thanks, Neil, it seems our posts came simultaneously. If it would be only for a few bitmaps i easily could simply convert the bitmaps. But i want to import the output from a program. They are hundreds of soldiers (and maybe new ones in future) , each soldier exported from rs2manager to about 1000 bitmaps in 80 directories, all in this packed bmp format!

Neil Walker
Member #210
April 2000
avatar

Well, if you can't get a 'compressed bitmap' loader then make use of one of the many bulk conversion programs that will do the directories in minutes. Unless, of course, you can't find any other program that will read this file type ;)

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

Audric
Member #907
January 2001

Apparently you're talking of RS2 files from Sudden strike, and you export them to bitmaps with Mzach's rs2manager. I downloaded it (only available on some russian site) and tried to export individual frames or "everything" in target directory.
In both cases, the bitmaps are normal 32bit bitmaps, nothing special... Allegro's grabber can read them fine, so your program should, too.
I attached one of the tested bitmaps to this post.
Can you check if you can read this one, and the ones you created, in Allegro's grabber?
If the ones you got are different (maybe we use different rs2manager version), please attach one to your post.

Striker
Member #10,701
February 2009
avatar

I haven`t tried with grabber. Only direct loading with load_bitmap. All other formats worked fine only these files appeared as black. But with graphic workshop and photo impact they can be loaded. Lets see if this one works, maybe there are different versions.

They are very small bitmaps. One person is approximately only 20 pixel high! It cant be much smaller. The advantage of this is : one can display many units at once on screen. A few hundreds or even thousands depending on hardware, and overview an whole battlefield.

(few minutes later)
Audric, you have won the download link! It works! There really is a new version of rs2manager. So you can see i am not talking nonsense i have attached one of the old.

Graphic Workshop says yours is compressed too, but this one works. Mine is only black. Now it can go on.

Go to: