View comments | RSS feed

DisplacementMapFilter (flash.filters.DisplacementMapFilter)


Object
    |
    +-flash.filters.BitmapFilter
        |
        +-flash.filters.DisplacementMapFilter

public class DisplacementMapFilter
extends BitmapFilter

The DisplacementMapFilter class uses the pixel values from the specified BitmapData object (called the displacement map image) to perform a displacement of an object on the Stage, such as a MovieClip instance. You can use this filter to achieve a warped or mottled effect on a BitmapData or MovieClip instance.

The use of filters depends on the object to which you apply the filter.

To apply filters to movie clips at runtime, use the filters property. Setting the filters property of an object does not modify the object and can be undone by clearing the filters property.

To apply filters to BitmapData instances, use the BitmapData.applyFilter() method. Calling applyFilter() on a BitmapData object modifies that BitmapData object and cannot be undone.

You can also apply filter effects to images and video at authoring time. For more information, see your authoring documentation.

If you apply a filter to a movie clip or button, the cacheAsBitmap property of the movie clip or button is set to true. If you clear all filters, the original value of cacheAsBitmap is restored.

The filter uses the following formula:

dstPixel[x, y] = srcPixel[x + ((componentX(x, y) - 128) * scaleX) / 256, y + ((componentY(x, y) - 128) * scaleY) / 256]

where componentX(x, y) gets the componentX color value from the mapBitmap property at (x - mapPoint.x ,y - mapPoint.y).

The map image used by the filter is scaled to match the Stage scaling. It is not scaled in any way when the object itself is scaled.

This filter supports Stage scaling, but not general scaling, rotation, or skewing. If the object itself is scaled (if x-scale and y-scale are not 100%), the filter effect is not scaled. It is scaled only when the Stage is zoomed in.

Here is how the DisplacementMapFilter class works. For each pixel (x,y) in the destination bitmap, the DisplacementMapFilter class does the following:

A filter is not applied if the resulting image would exceed 2880 pixels in width or height. For example, if you zoom in on a large movie clip with a filter applied, the filter is turned off if the resulting image reaches the 2880-pixel limit.

Availability: ActionScript 1.0; Flash Player 8

See also

applyFilter (BitmapData.applyFilter method), filters (MovieClip.filters property), cacheAsBitmap (MovieClip.cacheAsBitmap property)

Property summary

Modifiers

Property

Description

 

alpha:Number

Specifies the alpha transparency value to use for out-of-bounds displacements.

 

color:Number

Specifies what color to use for out-of-bounds displacements.

 

componentX:Number

Describes which color channel to use in the map image to displace the x result.

 

componentY:Number

Describes which color channel to use in the map image to displace the y result.

 

mapBitmap:BitmapData

A BitmapData object containing the displacement map data.

 

mapPoint:Point

A flash.geom.Point value that contains the offset of the upper-left corner of the target movie clip from the upper-left corner of the map image.

 

mode:String

The mode for the filter.

 

scaleX:Number

The multiplier to use to scale the x displacement result from the map calculation.

 

scaleY:Number

The multiplier to use to scale the y displacement result from the map calculation.

Properties inherited from class Object

constructor, __proto__, prototype, __resolve


Constructor summary

Signature

Description

DisplacementMapFilter(mapBitmap:BitmapData, mapPoint:Point, componentX:Number, componentY:Number, scaleX:Number, scaleY:Number, [mode:String], [color:Number], [alpha:Number])

Initializes a DisplacementMapFilter instance with the specified parameters.

Method summary

Modifiers

Signature

Description

 

clone() : DisplacementMapFilter

Returns a copy of this filter object.

Methods inherited from class BitmapFilter

clone


Methods inherited from class Object

addProperty, hasOwnProperty, isPropertyEnumerable, isPrototypeOf, registerClass, toString, unwatch, valueOf, watch



Version 8

Comments


BukuMartian said on Dec 14, 2005 at 12:38 PM :
"Gets the color from (x,y) in the map bitmap
Calculates an offset based on that color
Looks up that offset location (x+dx,y+dy) in the source bitmap
Writes that pixel to the destination(x,y), if boundary conditions permit"

Which is the 'source bitmap'
which is the ''destination bitmap''
soulhab said on Nov 1, 2006 at 2:11 PM :
I been working with DisplacementMapFilter on a BitmapData and I realize that there is a restriction in displacement.

here is the formula:
dstPixel[x, y] = srcPixel[x + ((componentX(x, y) - 128) * scaleX) / 256, y + (componentY(x, y) - 128) * scaleY) / 256]

The componentX(x, y) returns a Number from 0 to 255 because is limited by the 8 bits of the color component.

a.e: the scaleX is [b]256[/b], the componentX return 255 so the displacement will be:

srcPixel[x + ((255 - 128) * 256) / 256, .....]
wich is: x + 127 // here I can only get a half of the total displacement (127 of 256)

in the other hand if the componentX return 0 the displacement will be:

srcPixel[x + ((0 - 128) * 256) / 256, ....]
wich is: x - 127 // here I only can get the half of the displacement also

Now my question: Can I get a full displacement:confused;?

How can I do a faster displacement like: destPixel[x1, y1] = srcPixel[x2, y2]

Thanks in advance .
No screen name said on May 8, 2007 at 9:04 AM :
Just like to echo BukuMartian's comments - map, source, destination!

Obviously a feature non-technies would like to use but the help material seems to be written by techies for techies.

It is great to have the code examples (thank you) but a little diagram here and there in the help material would be just fantastic!

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00002169.html