13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Filtering display objects<br />

Color matrix filter<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

The ColorMatrixFilter class is used to manipulate the color and alpha values of the filtered object. This allows you to<br />

create saturation changes, hue rotation (shifting a palette from one range of colors to another), luminance-to-alpha<br />

changes, and other color manipulation effects using values from one color channel and pot<strong>en</strong>tially applying them to<br />

other channels.<br />

Conceptually, the filter goes through the pixels in the source image one by one and separates each pixel into its red,<br />

gre<strong>en</strong>, blue, and alpha compon<strong>en</strong>ts. It th<strong>en</strong> multiplies values provided in the color matrix by each of these values,<br />

adding the results together to determine the resulting color value that will be displayed on the scre<strong>en</strong> for that pixel. The<br />

matrix property of the filter is an array of 20 numbers that are used in calculating the final color. For details of the<br />

specific algorithm used to calculate the color values, see the <strong>en</strong>try describing the ColorMatrixFilter class’s matrix<br />

property in the ActionScript 3.0 Refer<strong>en</strong>ce for the Adobe Flash Platform.<br />

Convolution filter<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

The ConvolutionFilter class can be used to apply a wide range of imaging transformations to BitmapData objects or<br />

display objects, such as blurring, edge detection, sharp<strong>en</strong>ing, embossing, and beveling.<br />

The convolution filter conceptually goes through each pixel in the source image one by one and determines the final<br />

color of that pixel using the value of the pixel and its surrounding pixels. A matrix, specified as an array of numeric<br />

values, indicates to what degree the value of each particular neighboring pixel affects the final resulting value.<br />

Consider the most commonly used type of matrix, which is a three by three matrix. The matrix includes nine values:<br />

N N N<br />

N P N<br />

N N N<br />

Wh<strong>en</strong> the convolution filter is applied to a certain pixel, it will look at the color value of the pixel itself (“P” in the<br />

example), as well as the values of the surrounding pixels (labeled “N” in the example). However, by setting values in<br />

the matrix, you specify how much priority certain pixels have in affecting the resulting image.<br />

For example, the following matrix, applied using a convolution filter, will leave an image exactly as it was:<br />

0 0 0<br />

0 1 0<br />

0 0 0<br />

The reason the image is unchanged is because the original pixel’s value has a relative str<strong>en</strong>gth of 1 in determining the<br />

final pixel color, while the surrounding pixels’ values have relative str<strong>en</strong>gth of 0—meaning their colors don’t affect the<br />

final image.<br />

Similarly, this matrix will cause the pixels of an image to shift one pixel to the left:<br />

0 0 0<br />

0 0 1<br />

0 0 0<br />

Notice that in this case, the pixel itself has no effect on the final value of the pixel displayed in that location on the final<br />

image—only the value of the pixel to the right is used to determine the pixel’s resulting value.<br />

Last updated 6/6/2012<br />

284

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!