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

  • Java developers know that testing code changes can be a huge pain, and waiting for an application to redeploy after a code fix can take an eternity. Wouldn't it be great if you could see your code changes immediately, fine-tune, debug, explore and deploy code without waiting for ages? In this white paper, find out how that's possible with a Java plugin that drastically changes the way you develop, test and run Java applications. Discover the advantages of this plugin, and the changes you can expect to see …

  • Hybrid cloud platforms need to think in terms of sweet spots when it comes to application platform interface (API) integration. Cloud Velocity has taken a unique approach to tight integration with the API sweet spot; enough to support the agility of physical and virtual apps, including multi-tier environments and databases, while reducing capital and operating costs. Read this case study to learn how a global-level Fortune 1000 company was able to deploy an entire 6+ TB Oracle eCommerce stack in Amazon Web …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds