- Online Community Forums » Programming Questions » Increasing the speed of transitioning from one image into another?

This thread is locked; no one can reply to it. rss feed Print
Increasing the speed of transitioning from one image into another?
Member #7,304
June 2006

What I'm doing right now is fading one menu screen into another when a menu item is selected. Problem is, it's really slow. The images are 800x600. I know it's the images that are the problem because when I do fade in/out from/to black, the speed is just fine. It's only when the image has something in it that the slowdown occurs.

Here's the function I'm using:

1void objGfx::TransitionFade(BITMAP* endImage, int fadeSpeed)
3 BITMAP* startImage = create_bitmap(SCREEN_W, SCREEN_H);
4 blit(Screen->Buffer(), startImage, FULL_SCREEN, SCREEN_W, SCREEN_H);
6 COLOR_MAP transTable;
7 color_map = &transTable;
9 if (fadeSpeed <= 0)
10 {
11 fadeSpeed = 16;
12 }
14 install_int(TickTimer, FADE_TIMER);
16 int i = 0;
18 while (i < 256)
19 {
20 if (tick == true)
21 {
22 tick = false;
24 set_trans_blender(0, 0, 0, i);
25 blit(startImage, Screen->Buffer(), FULL_SCREEN, SCREEN_W, SCREEN_H);
26 draw_trans_sprite(Screen->Buffer(), endImage, 0, 0);
28 Screen->Update();
30 i += fadeSpeed;
31 }
32 }
34 blit(endImage, Screen->Buffer(), FULL_SCREEN, SCREEN_W, SCREEN_H);
36 remove_int(TickTimer);
38 destroy_bitmap(startImage);
39 destroy_bitmap(endImage);

Any tips to speed things up?

Simon Parzer
Member #3,330
March 2003

Your problem is obviously draw_trans_sprite. It's an Allegro function and therefore uses software rendering. That means that it has to check every pixel of your image and manually blend it with the correspondending pixel from the new image (800x600 => 480000 pixels).
To speed things up, you should use hardware rendering (through OpenLayer or OpenGL?), which makes use of your graphic card instead of the CPU. This is much faster, but it requires some kind of 3D hardware.

Member #4,534
April 2004

First and probably the simpliest speedup is to create startImage and endImage once, not in every frame. Also a lot of speed can be gained if you don't use video bitmaps with blending. That means you first do all the drawin in memory bitmaps and blit the result to screen.

If you need ~30-250% faster blending you might want to try compiling Allegro using plain-c functions. I've seen that draw_trans_sprite can be much faster in c-mode:

Another thing that can speed things up is to use draw_trans_rle_sprite() but that only works good for read-only images.

In Linux you can compile Allegro in C mode with ./configure --enable-asm=no. I don't know how you can do it in windows.

In theory, there is no difference between theory and practice. But, in practice, there is - Jan L.A. van de Snepscheut
MMORPG's...Many Men Online Role Playing Girls - Radagar
"Is Java REALLY slower? Does STL really bloat your exes? Find out with your friendly host, HoHo, and his benchmarking machine!" - Jakub Wasilewski

Member #3,858
September 2003

Or use fblend.

But switching to allegrogl or openlayer is probably the best choice.

Layers are good, all good things have layers, like onions. Good things also stink. - Trezker
I now have a page and a blog!

Member #3,025
December 2002

or do as i did, and write a blender in SSE2, works awesomely fast!
but not as fast as hardware acceleration, which you should be trying.

The more you talk, the more AJ is right. - ML

Go to: