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: August 14, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Data protection has long been considered "overhead" by many organizations in the past, many chalking it up to an insurance policy or an extended warranty you may never use. The realities of today make data protection a must-have, as we live in a data driven society. The digital assets we create, share, and collaborate with others on must be managed and protected for many purposes. Check out this upcoming eSeminar and join eVault Chief Technology …

  • As a result of corporate expansions, mergers, and acquisitions, the teams and technologies that support an organization's IT service management (ITSM) practices can over time become somewhat dispersed. Supporting an organization's strategic objectives, and providing consistent and quality IT support is essential, but this can be challenging where disconnected support environments exist. While physically centralizing support is not always possible, nor is it always desirable, delivering a consistent and …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds