Anti-Aliased Image Transformation (Aaform)

written by Mark Gordon (msg555)

Using the same method as Aarot, Aaform can transform an image into any convex1 quadrilateral. By treating a pixel like a square, I believe the best transformation possible can be achieved.

Aaform begins by creating a grid of the transformed image's pixels. Then, it overlays that grid on top of the destination bitmap and finds the area of overlap for each transformed source pixel on each destination pixel. It then uses that overlap to decide how much of each source pixel's color information belongs in each destination pixel.

This illustrates how Aaform works:

Functions Included

  • Transform: Transforms the source image onto the destination image passed
  • CreateTransform: Creates a new bitmap of appropriate size to fit the transformed source image and passes it to Transform

The following functions all just calculate the corners of the transformed image and pass those on to CreateTransform:

  • Rotate: Rotates an image by the passed degrees
  • Stretch: Stretches an image by the passed ratios
  • SkewHorizontal: Skews the image horizontally by the passed degrees (-90, 90)
  • SkewVerticle: Skews the image vertically by the passed degrees (-90, 90)

For information on each of the methods' uses, see the sample projects attached to this article.

Using the Callback Function

Unfortunately, Aaform does not complete quickly. The average transformation will take several seconds to complete. Because of this, there is a need for a CallBack function to update the client code on Aaform's progress as well as give the client code an opportunity to abort the transformation

In C++, the callback function should look like this:

bool AaformCallbackFunc(double percentdone)
{
   ...
}

Where percentdone is the amount of the image that has processed. 0 is 0%; 1 is 100%.

If you are using the DLL in VB, your callback function should look like this:

Public Function AaformCallbackFunc(ByVal Percentage As Double) As Long
...
End Function

Likewise, if you are using VB.NET, you should pass a CallBack delegate:

Public Delegate Function CallBack(ByVal PercentDone As Double) As Boolean

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):

Public Function AaformCallbackFunc(ByVal Percentage As Double, _
                                   ByVal Numerator As Long, _
                                   ByVal Denominator As Long) As Long
...
End Function

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 immediately exit (after clearing the memory) and return a null bitmap.

End Note

1 Aaform will attempt to transform concave polygons (and it will create a reasonable result), but there is no guarantee it will work due to the way Aaform generates the transformed pixel grid.



Downloads

Comments

  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds