views:

117

answers:

2

Hi, My application present a (raster) moving map. I need to be able to show the map rotated base on any given angle. The program is currently in VC++/MFC but the problem is generic. I have a source bitmap (CBitmap or HBITMAP) and draw it to the device context (CDC) using StretchBlt. While this works fast and smooth for angle=0 (and the user can grab the map smoothly with the mouse), this is not the case if I try to rotate the bitmap and then present it (the rotation of the bitmap using SetWorldTransform() or so takes hundreds of miliseconds and this is too slow).

I think that the solution is to be able to relate only to the pixels that currently on the screen and not rotating the original source bitmap - and this is the key.

If someone has experience with similar implementation then it might save me lots of trial and error efforts. Thanks! Avi.

A: 

It looks like SetWorldTransform is extremely slow: http://www.codeguru.com/Cpp/G-M/bitmap/specialeffects/article.php/c1743

And while the other options presented in that article are faster, there are of course other better solutions like this: http://www.codeguru.com/cpp/g-m/gdi/article.php/c3693/ (check the comments for fixes and improvements as well)

Also here are some non-Windows centric fast rotation algorithms: http://www.ddj.com/windows/184416337?pgno=11

Note that if you guarantee power of 2 dimensions you can get significant speed improvements.

jestro
In the first article they say: "GetRotatedBitmapNT() This function is specific to NT and will not work on Windows95. It's the simplest and probably the fastest of the three functions listed in this topic. "So as I understand it they claim that GetRotatedBitmapNT() is maybe the fastest.But I'll review the other links and update back if I find a breakthrough.Thanks so far...Avi.
Avi
A: 

As follow up to my question and provided answer, let me summarize the following:

  1. I used the algorithm mentioned at http://www.codeguru.com/cpp/g-m/gdi/article.php/c3693/.

  2. It works and provide pretty good performance and smooth display.

  3. There were some bugs in it that I needed to fix as well as simplify the formulas and code in some cases.

  4. I will examine the algorithm mentioned at http://www.ddj.com/windows/184416337?pgno=11 to see if it provides some break through performance that worth adapting it.

  5. My implementation required using a large source bitmap, so I needed to modify the code so I will not rotate the whole bitmap each time but only the relevant portion that will be displayed at the screen (otherwise performance would be unacceptable).

Avi.

Avi