Click here to Skip to main content
Click here to Skip to main content

Anti Aliased Image Rotation

, 11 Nov 2005
Rate this:
Please Sign up or sign in to vote.
Perfect image rotation using geometry.

Introduction

(Written by Mark Gordon.) Aarot (Anti Aliased Image Rotation Algorithm) can rotate images by any angle. Unlike most image rotation algorithms, Aarot uses geometry to decide how much representation each pixel deserves. It does this by overlapping the source bitmap onto the destination bitmap at an angle and calculating for every source pixel the area of overlap over each destination pixel. With this value, Aarot can weigh how much of each source pixel should be represented in each destination pixel, thus creating the best rotation possible.

The following image demonstrates how Aarot works. On the left is the un-rotated source image. In the middle, the rotated source image has been overlaid on top of the destination image at a 40 degree angle. Then Aarot finds the area of overlap of each of the source pixel in each destination pixel. It uses these values to weigh how much color information of each source pixel belongs in each destination pixel.

Unfortunately, quality comes at a price. On my computer (1.81 GHz, AMD Athlon 64 Processor) it took just under 15 seconds to rotate a 1152 x 864 image by 61 degrees.

Implementation

HBITMAP aarot::rotate(HBITMAP src, double rotation,
                      aar_callback callbackfunc, int bgcolor,
                      bool autoblend)
  • Src: The handle to the Bitmap to be rotated.
  • Rotation: The degree by which the image should be rotated counter-clockwise.
  • callbackfunc: A pointer to the callback function. This function will be notified about the percentage of rotation completed as well as gives the opportunity to stop the rotation. This parameter may be NULL. See Using the Callback Function for more information.
  • BgColor: The color of the background where the rotated bitmap does not overlap the destination bitmap.
  • AutoBlend: Decides if the edges of the rotated image should be blended with the background color defined by BgColor. If false, the rgbReserved byte of each pixel will be set to the appropriate alpha values so that the rotated image can be blended onto another image later without a harsh edge.
  • Return: A handle to the rotated Bitmap object. Returns NULL if there are errors or if the function was told to quit by the callback function.

Using the Callback Function

The callback function should share the following signature:

bool AarotCallbackFunc(double percentdone)
{
   ...
}

The double passed to the callback function is a number ranging from 0 to 1, representing how close the main algorithm is to completion. (0 = 0%, .5 = 50%, 1 = 100%) If the callback function returns true, the main algorithm will exit and return a NULL bitmap. In this way, the user is given the opportunity to stop the rotation.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

msg555

United States United States
No Biography provided

Comments and Discussions

 
GeneralAaform Pinmembermsg5558-Mar-06 5:36 
Questionaarot fills more and more memory and finally crashes Pinmembermephistho7-Mar-06 2:19 
AnswerRe: aarot fills more and more memory and finally crashes Pinmembermsg5557-Mar-06 10:45 
QuestionRe: aarot fills more and more memory and finally crashes Pinmembermephistho7-Mar-06 20:35 
AnswerRe: aarot fills more and more memory and finally crashes Pinmembermsg5558-Mar-06 5:31 
GeneralRe: aarot fills more and more memory and finally crashes Pinmembermephistho8-Mar-06 20:47 
GeneralNew Aarot Pinmembermsg55516-Nov-05 15:35 
GeneralHard work but useful. PinmemberIain Clarke14-Nov-05 9:20 
GeneralInteresting. Pinmemberjkoorr114-Nov-05 3:52 
GeneralSorry but I don't see it the same PinmemberTeashirt213-Nov-05 15:14 
GeneralRe: Sorry but I don't see it the same Pinmembermsg55513-Nov-05 16:35 
GeneralPerhaps too complicate! PinmemberLuca Piccarreta12-Nov-05 3:20 
GeneralRe: Perhaps too complicate! Pinmembermsg55512-Nov-05 5:25 
GeneralRe: Perhaps too complicate! PinmemberLuca Piccarreta12-Nov-05 6:44 
GeneralRe: Perhaps too complicate! Pinmembermaihem13-Nov-05 0:21 
GeneralRe: Perhaps too complicate! PinmemberLuca Piccarreta13-Nov-05 0:43 
GeneralRe: Perhaps too complicate! Pinmembermaihem13-Nov-05 1:17 
GeneralRe: Perhaps too complicate! PinmemberCraig Muller21-Nov-05 11:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 11 Nov 2005
Article Copyright 2005 by msg555
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid