Click here to Skip to main content
Licence 
First Posted 11 Nov 2005
Views 65,398
Downloads 1,871
Bookmarked 44 times

Anti Aliased Image Rotation

By | 11 Nov 2005 | Article
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

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralAaform Pinmembermsg5555:36 8 Mar '06  
Questionaarot fills more and more memory and finally crashes Pinmembermephistho2:19 7 Mar '06  
AnswerRe: aarot fills more and more memory and finally crashes Pinmembermsg55510:45 7 Mar '06  
QuestionRe: aarot fills more and more memory and finally crashes Pinmembermephistho20:35 7 Mar '06  
AnswerRe: aarot fills more and more memory and finally crashes Pinmembermsg5555:31 8 Mar '06  
GeneralRe: aarot fills more and more memory and finally crashes Pinmembermephistho20:47 8 Mar '06  
GeneralNew Aarot Pinmembermsg55515:35 16 Nov '05  
GeneralHard work but useful. PinmemberIain Clarke9:20 14 Nov '05  
GeneralInteresting. Pinmemberjkoorr13:52 14 Nov '05  
GeneralSorry but I don't see it the same PinmemberTeashirt215:14 13 Nov '05  
GeneralRe: Sorry but I don't see it the same Pinmembermsg55516:35 13 Nov '05  
GeneralPerhaps too complicate! PinmemberLuca Piccarreta3:20 12 Nov '05  
GeneralRe: Perhaps too complicate! Pinmembermsg5555:25 12 Nov '05  
GeneralRe: Perhaps too complicate! PinmemberLuca Piccarreta6:44 12 Nov '05  
GeneralRe: Perhaps too complicate! Pinmembermaihem0:21 13 Nov '05  
GeneralRe: Perhaps too complicate! PinmemberLuca Piccarreta0:43 13 Nov '05  
GeneralRe: Perhaps too complicate! Pinmembermaihem1:17 13 Nov '05  
GeneralRe: Perhaps too complicate! PinmemberCraig Muller11:28 21 Nov '05  

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.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 11 Nov 2005
Article Copyright 2005 by msg555
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid