20
Aug/08
3

Bitmap skewing class

Finally, after two days of trial and error, I got my bitmap skewing class working. The class is based upon Flash and Math’s work, especially the algorithm for ‘triangulating’ (I know this is not the right word) distorted quadrilaterals. The class is quite complete there might be another function for simply rendering textures onto triangles instead of quadrilaterals. See the class in action below, adjust the “AA” level (I know it’s not really the same, but couldn’t think of a nicer term) to increase or decrease the level of precision. The higher the AA level the better it looks. Lower AA levels increase performance. The same counts for the noise reduction, which decreases the performance when turned on.

Download the skew.as class

The usage is fairly simple;

[sourcecode language='actionscript']import com.skew;
// First boolean is for noise reduction the second for debug mode
var sk:skew = new skew(false,false);
// For skews with a greater precision than 1
sk.AASkew(a,b,c,d,bitmap,sp,AAh,AAv);
// For skews with a precision of 1
sk.transformer(a,b,c,d,bitmap,sp,AAh,AAv);
// With a,b,c,d being arrays containing 2 dimensional points e.g. a = [10,10];
// And bitmap being a bitmapData object
// sp being a sprite or shape
// AAh and AAv respectively being the horizontal and vertical “AA” levels[/sourcecode]

The sk.transformer function is quite an increase in performance from the sk.AASkew function because it doesn’t require mapping the non distorted bitmap.

EDIT: Updated the skew class with a better variable name for the smoothing parameter and corrected the skew functions to smooth both halves. Thanks to Banana.

Comments (3) Trackbacks (0)
  1. admin
    5:26 pm on August 20th, 2008

    I use arrays instead of points because I think I’ve read somewhere they improve performance.

  2. Banana
    2:58 pm on September 28th, 2008

    Heys, could you go into some detail about the noise reduction? i looked at your .as and your above usage code, but i fail to see where it actually reduces noise, any chance you can make that a seperate function? thanks in advance, and cool skewing tho yea, i only need the noise reduction part :)

  3. admin
    5:08 pm on September 28th, 2008

    Sure, the noise reduction or the ‘AA’ (variable names are a bit confusing in the class) variable in the AS class is simply a parameter in the beginBitmapFill() method of flash’s graphics class. The parameter according to the AS3 manual controls the following;

    “If false, upscaled bitmap images are rendered by using a nearest-neighbor algorithm and look pixelated. If true, upscaled bitmap images are rendered by using a bilinear algorithm. Rendering by using the nearest neighbor algorithm is usually faster. ” – AS3 Documentation

    However, I think this will only work when the bitmap has been skewed and is thus not in it’s original proportions.

    And thanks to you too, because I found a bug/mistake in my class where only half of the image’s smoothing is controlled by the AA variable.

Leave a comment

No trackbacks yet.