topical media & game development
#graphic-flex-image-effects-02-Flex-BlendModeFunctions.ax
#graphic-flex-image-effects-02-Flex-BlendModeFunctions.ax
[swf]
[flash]
flex
package {
import flash.display.Sprite;
Class for testing blend mode pixel equations.
The output of this file are trace statements, so nothing will appear in SWF.
public class @ax-graphic-flex-image-effects-02-Flex-BlendModeFunctions extends Sprite {
Constructor. Sends two pseudo-pixels to functions to determine
how pixels interact with each blend mode.
public function @ax-graphic-flex-image-effects-02-Flex-BlendModeFunctions() {
// the colors of the top and bottom pixel to test
var topPixel:Object = {red:0xFF, green:0x33, blue:0x99};
var bottomPixel:Object = {red:0x00, green:0x00, blue:0x99};
// the method to apply
var method:String = "difference";
// finds the new value for each channel based on the top and bottom
// pixels and blend mode that was applied
var red:Number = this[method](topPixel.red, bottomPixel.red);
var green:Number = this[method](topPixel.green, bottomPixel.green);
var blue:Number = this[method](topPixel.blue, bottomPixel.blue);
// traces out the resulting pixel value
var resultPixel:uint = (red << 16) | (green << 8) | (blue);
trace(resultPixel.toString(16));
}
public function normal(topPixel:uint, bottomPixel:uint):uint {
return topPixel;
}
public function multiply(topPixel:uint, bottomPixel:uint):uint {
return (bottomPixel * topPixel)/255;
}
public function screen(topPixel:uint, bottomPixel:uint):uint {
return (255 - ((255 - topPixel) * (255 - bottomPixel))/255);
}
public function hardlight(topPixel:uint, bottomPixel:uint):uint {
var color:uint;
if (topPixel > 127.5) {
color = screen(bottomPixel, 2 * topPixel - 255);
} else {
color = multiply(bottomPixel, 2 * topPixel);
}
return color;
}
public function overlay(topPixel:uint, bottomPixel:uint):uint {
return hardlight(bottomPixel, topPixel);
}
public function add(topPixel:uint, bottomPixel:uint):uint {
return Math.min(255, bottomPixel + topPixel);
}
public function subtract(topPixel:uint, bottomPixel:uint):uint {
return Math.max(0, bottomPixel - topPixel);
}
public function lighten(topPixel:uint, bottomPixel:uint):uint {
return Math.max(topPixel, bottomPixel);
}
public function darken(topPixel:uint, bottomPixel:uint):uint {
return Math.min(topPixel, bottomPixel);
}
public function difference(topPixel:uint, bottomPixel:uint):uint {
return Math.abs(topPixel - bottomPixel);
}
public function invert(topPixel:uint, bottomPixel:uint):uint {
return (255 - bottomPixel);
}
}
}
(C) Æliens
04/09/2009
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.