Starting in 1996, Alexa Internet has been donating their crawl data to the Internet Archive. Flowing in every day, these data are added to the Wayback Machine after an embargo period.
Image rotation isn't as straightforward as it may appear, especially when faced with the fact that, although small, a pixel is not a point. In fact, it's a 1 x 1 square, which leads to the question of how best to rotate it. Some algorithms will ingore this idea altogether and treat a pixel like a point. Others will do an artificial zooming on the image to make the smallest unit of color even smaller so the aliasing won't be as evident. However, it is possible to rotate a pixel as a square, and Aarot does it. By treating a pixel like a square, you get the best rotation possible.
Aarot works by rotating each of the 1 x 1 squares from the source bitmap and overlapping them on the destination bitmap. Because pixels can only hold one discrete color, it is necessary to find how much representation each source pixel has in each destination pixel. Aarot does this by finding the area of each source pixel over each destination pixel and adding representation proportional to that area.
See the following image. On the left, you see the unrotated image; the next step shows the rotated image overlapped on the destination bitmap. In the final step, the amount of representation each source pixel should receive in each destination pixel is calculated and added to the destination pixels
Unfortunatly, this algorithm does not complete in real time so it is not useful for games or things of the like. I wrote the algorithm for C++ and VB (C++ is faster) and provided a DLL for implementing the C++ algorithm's speed with VB. (There are sample projects as well.)
I included a comparison between Aarot and Photoshop (CS2) so you can see the difference between the two. Here is an example of Aarot's work:
Rotation: The degrees that the image should be rotated counter-clockwise.
callbackfunc (CallBackPtr): A pointer to the callback function. This function will be notified what percentage of the rotation has completed as well as given the opportunity to stop the rotation. This parameter may be NULL (or 0 in VB). See Using the Callback Function below for information about the Callback structure.
BgColor: The color of the background where the rotated bitmap does not overlap the destination bitmap.
AutoBlend: Should the edges of the rotated image be blended with the background color defined by BgColor? If false, the rgbReserved byte of each pixel will be set to the approriate alpha values so that the rotated image can be blended onto another image later without a harsh edge.
Using the Callback Function
In C++, the callback function should look like this:
On the other hand, if you are using the VB module, your callback should look like this (due to a need to have 16 bytes' worth of parameters to use CallWindowProc):
where Percentage means the same thing, and Numerator and Denominator make up the rationale used to calculate Percentage.
No matter what you're using, if your callback function returns true (anything but 0), the main algorithm will immediatly exit (after clearing the memory) and return a null bitmap.
Downloads
Compare.zip - Comparison between Aarot and Photoshop
aarot.zip - Aarot code and example projects (C++ and Vb 6.0)
Tools:
Add www.codeguru.com to your favorites Add www.codeguru.com to your browser search box IE 7 | Firefox 2.0 | Firefox 1.5.xReceive news via our XML/RSS feed
RATE THIS ARTICLE:
Excellent Very Good Average Below Average Poor
(You must be signed in to rank an article. Not a member? Click here to register)