Al_save_bitmap problem
alex glez

Hi, I would like to comment on a problem. When saving a bmp of 25 mb with al_save_bitmap it takes me 20 seconds even saving it in a ramdisk. What can I do to solve it? Thank you.

Chris Katko

- What file format are you using?
- What resolution? Color depth?
- What operating system?
- What version of Allegro 5?


(You could also run a profile to see where it's lagging the most on your system if you know how.)

alex glez

Hi. Use bmp, 2432 * 3648, color depth I have not configured anything, windows 10, visual studio, alllegro
In the HDD are 21 seconds.


How long does it take if you save it as .png instead? Just as a test.

If the .png saves in 0.1 seconds, then the problem is likely the .bmp encoding.

If the .png also saves in 21 seconds, then the problem is likely not the encoding but either reading the input bitmap or writing the encoded data to file.

Once we know which it is we can investigate further.

alex glez

about 25 seconds my program is a group photo processor, mini type "adobe lightroom". There is no problem in reading files and processing them. Only when exporting

I make a program just with this ..

al_draw_text(font, al_map_rgb(255, 100, 255), 400, 345,
ALLEGRO_ALIGN_LEFT, "INICIO............."); al_flip_display();
PRUEBA = al_load_bitmap("d:\AAA.bmp");
al_save_bitmap("d:\BBB.bmp", PRUEBA);
return 0;

...20 seconds in BMP...

24 bits (color) 2432*3648 - 25.3 mb


What if you use BBB.png instead of BBB.bmp? Or is that what you did and BBB.png takes 25 seconds and BBB.bmp takes 20 seconds?

alex glez

bmp takes 20 seconds and png 25 seconds. I do not understand why it takes so long.
al_load_bitmap is fast

Edgar Reynaldo

You have to 'download' the texture off of the gpu first, which takes a bunch of time. But 20-25 seconds is still too long.


I tried it out with the attached C program on Linux, with a 24 bit bitmap of 2000x2000, and it takes about 2 seconds to load and save. So, no, what you are seeing isn't normal. Could you try out my attached program and see if it works for you? The input bitmap must be named input.bmp and be in the same folder as the executable.

It might be that it takes a long time for the Allegro shared libraries to be loaded, but otherwise I can't see why it would be so slow unless your system is seriously underpowered. If you know how to use a debugger, you could interrupt your program with it during saving and see where it is getting stuck.

alex glez

hi beoran, my cpu is an amd athlon 64 x2 4200+, i have 4 gb ram ddr2, nvidia gforce 210 graphics card with 1024 mb. I ran my program on an Intel i3 and it takes 9 seconds. Where can I see your program attached?

Chris Katko

It's to the right of the "posted on" text, the second icon.

Looks like this:

That image size sounds incredibly big for a computer that slow. But there could still be Allegro-related issues going on.

alex glez said:

nvidia gforce 210 graphics card with 1024 mb

What's the maximum texture size for that card? You may be accidentally falling back into a system bitmap (read: no graphics card acceleration).

[edit] Looks like you're fine on texture size.


Max Texture Size: 8192 x 8192 pixels


How long does it take to save the bitmap with an image editor on your system? The bottleneck is likely to be the hard disk. If an image editor is comparably slow, it might be your system really is underpowered.

Now, however it may be, let's talk mitigation. If you want to save such a large image "live", without interrupting your program, you will need to do it in a worker thread. Allegro5 has threads to help you achieve this.

alex glez

Hi. Beoran compiled your code adapted to "visual studio" but it takes the same.
With Photoshop, the same image from jpg to bmp takes 1 second.
I have used a RAMDISK and it does not improve. I think the problem may be that
al_save_bitmap needs a very fast cpu.
I've tried everything Chris, I'll keep trying ...

Chris Katko

The big one to try is a profiler.

Visual Studio has one. Google for "basic profiler tutorial visual studio [my year version]" and run one for your program.

A profiler tells you how long each section of code takes to run (including the ALLEGRO function). So it'll show you the exact lines that are pausing for 30 seconds.

This video might be perfect and it's a minute long:


alex glez

Thanks for the input. I measure the time in the following way ...
I print on the screen the word "start", then I put the command al_save_bitmap and print "end" on the screen ... I execute and measure with an
time between one word and another. I know it's a very basic method, but I've measured it
with the own visual study (counter time) and it is the same ..
Everything else in allegro is very fast, I can load 120 photos (2432x3648) in less than 3 minutes converting them from jpg to bmp (djpeg.exe) (external call) and reducing them to 333x500 .. but al_save_bitmap is a problem and that I have given my program maximum priority (cpu) ..
I thank everyone for your help, thank you


One other thing you could try is save as .tga... I didn't check the code but maybe both .bmp and .png use some slow windows function. TGA is always handled internally I believe.


No, i checked the code, and saving a bmp bitmap seems to be handled internally. However , it locks the bitmap in 8888 format, which might be slow. Could you try to call al_lock_bitmap(bmp, ALLEGRO_PIXEL_FORMAT_ABGR_8888_LE,
ALLEGRO_LOCK_READONLY) on your loaded bitmap and time that? Maybe that is causing the slowdown.

Edit, I should have read a bit more because I was wrong, there is a windows specific image loader and saver for bmp. So yes, also try the tfa file format.


If you run it in the debugger you can just press F12 a few times to pause it, that should tell you which functions are taking so long.

alex glez

I will try all these ideas, to see if I accelerate it. if it could be compiled in 64 bits I guess it would improve a lot but I think it's not possible. It is possible that it could be compiled for some reason. Everything else with allegro works perfect.
Another option would be to create a program that generates a bmp from a 24 bit bitmap to not use this function. I have seen when I run it that it uses 30% cpu from the visual studio. thanks to all.

I have already tried the solutions. saving in TGA format takes 33 seconds.

  al_lock_bitmap (original_photo, ALLEGRO_PIXEL_FORMAT_ABGR_8888_LE, ALLEGRO_LOCK_READONLY);
generates a read access violation error.

using the f12 key gives me the error of source code not available ..

Thread #617122. Printed from