Flash 8 Documentation |
|||
| ActionScript 2.0 Language Reference > ActionScript classes > BitmapData (flash.display.BitmapData) > paletteMap (BitmapData.paletteMap method) | |||
public paletteMap(sourceBitmap:BitmapData, sourceRect:Rectangle, destPoint:Point, [redArray:Array], [greenArray:Array], [blueArray:Array], [alphaArray:Array]) : Void
Remaps the color channel values in an image that has up to four arrays of color palette data, one for each channel.
Flash Player uses the following formula to generate the resulting image.
After the red, green, blue, and alpha values are computed, they are added together using standard 32-bit-integer arithmetic. The red, green, blue, and alpha channel values of each pixel are is extracted into a separate 0 to 255 value. These values are used to look up new color values in the appropriate array: redArray, greenArray, blueArray, and alphaArray. Each of these four arrays should contain 256 values. After all four of the new channel values are retrieved, they are combined into a standard ARGB value, which is applied to the pixel.
Cross-channel effects can be supported with this method. Each input array can contain full 32-bit values, and there is no shifting when the values are added together. This routine does not support per-channel clamping.
If no array is specified for a channel, the color channel is simply copied from the source image to the destination image.
You can use this method for a variety of effects such as general palette mapping (taking one channel and converting it to a false color image). You can also use this method for a variety of advanced color manipulation algorithms, such as gamma, curves, levels, and quantizing.
Availability: ActionScript 1.0; Flash Player 8
sourceBitmap:flash.display.BitmapData - The input bitmap image to use. The source image can be a different BitmapData object, or it can refer to the current BitmapData object.
sourceRect:flash.geom.Rectangle - A rectangle that defines the area of the source image to use as input.
destPoint:flash.geom.Point - The point within the destination image (the current BitmapData object) that corresponds to upper-left corner of the source rectangle.
redArray:Array [optional] - If redArray is not null, red = redArray[source red value] else red = source rect value.
greenArray:Array [optional] - If greenArray is not null, green = greenArray[source green value] else green = source green value.
blueArray:Array [optional] - If blueArray is not null, blue = blueArray[source blue value] else blue = source blue value.
alphaArray:Array [optional] - If alphaArray is not null, alpha = alphaArray[source alpha value] else alpha = source alpha value.
The following example shows how to use a palette map to convert solid red to green, and solid green to red in a single BitmapData object.
import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Point;
var myBitmapData:BitmapData = new BitmapData(100, 80, false, 0x00FF0000);
var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth()); mc.attachBitmap(myBitmapData, this.getNextHighestDepth());
myBitmapData.fillRect(new Rectangle(51, 0, 50, 80), 0x0000FF00);
mc.onPress = function() {
var redArray:Array = new Array(256);
var greenArray:Array = new Array(256);
for(var i = 0; i < 255; i++) {
redArray[i] = 0x00000000;
greenArray[i] = 0x00000000;
}
redArray[0xFF] = 0x0000FF00;
greenArray[0xFF] = 0x00FF0000;
myBitmapData.paletteMap(myBitmapData, new Rectangle(0, 0, 100, 40), new Point(0, 0), redArray, greenArray, null, null);
}
Version 8
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/00001962.html
Comments
Roks-1 said on Sep 25, 2005 at 8:36 PM : pan69 said on Oct 9, 2005 at 12:10 AM : Mario Klingemann said on Mar 19, 2006 at 5:34 AM : Dan Zen said on Nov 4, 2006 at 10:21 PM : motorro said on Nov 21, 2006 at 12:28 AM :