Last active
September 24, 2015 23:07
-
-
Save justindujardin/9747de1acca7e631f420 to your computer and use it in GitHub Desktop.
Actionscript HSL Color blend texture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static function hslColorBlendMaterial(target:BitmapData,colorMask:BitmapData,color:uint,darkLuminance:Number=0.0):void | |
{ | |
Profiler.enter("BitmapFeatureRenderer.colorBlendMaterial"); | |
var hslColorMask:HSL = new HSL(); | |
var hslTarget:HSL = new HSL(); | |
if(colorMask != null && !colorMask.rect.equals(target.rect)) | |
throw new Error("only supports color blending same size textures"); | |
// Calculate a single HSL color for the mask. | |
HSL.convertRGBToHSL(color,hslColorMask); | |
var isDark:Boolean = (hslColorMask.luminance < darkLuminance); | |
for(var x:int = 0; x < target.width; x++) | |
{ | |
for (var y:int = 0; y < target.height; y++) | |
{ | |
var maskPixel:uint = (colorMask != null) ? colorMask.getPixel(x,y) : 0xFFFFFF; | |
if(maskPixel != 0) | |
{ | |
HSL.convertRGBToHSL(target.getPixel(x,y),hslTarget); | |
hslTarget.hue = hslColorMask.hue; | |
hslTarget.saturation = hslColorMask.saturation; | |
hslTarget.luminance = Math.pow(hslTarget.luminance,2.1); | |
target.setPixel(x,y,HSL.convertHSLToRGB(hslTarget)); | |
} | |
} | |
} | |
Profiler.exit("BitmapFeatureRenderer.colorBlendMaterial"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment