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

  • Wednesday, September 24, 2014 8:00 AM - 9:00 AM PDT According to a recent Forrester Research report, many companies are choosing low-code platforms over traditional programming platforms, due to the speed with which low-code apps can be assembled and tested. With customer-facing applications on the rise, traditional programming platforms simply can't keep up with the "short schedules and rapid change cycles" required to develop these applications. Check out this upcoming webinar and join Clay Richardson from …

  • The explosion in mobile devices and applications has generated a great deal of interest in APIs. Today's businesses are under increased pressure to make it easy to build apps, supply tools to help developers work more quickly, and deploy operational analytics so they can track users, developers, application performance, and more. Apigee Edge provides comprehensive API delivery tools and both operational and business-level analytics in an integrated platform. It is available as on-premise software or through …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds