topical media & game development

talk show tell print

#graphic-flex-image-effects-10-Flex-IsolateColorEffect.ax

#graphic-flex-image-effects-10-Flex-IsolateColorEffect.ax [swf] [flash] flex


  package {
  
          import aether.effects.shaders.ShaderEffect;
          import aether.utils.MathUtil;
  
          
Custom shader effect that allows you to isolate a single color in an image, setting a hue and luminance threshold for the isolation. Pixels that do not fall within these thresholds will either be hidden (no opacity) or made grayscale.

  
          public class @ax-graphic-flex-image-effects-10-Flex-IsolateColorEffect extends ShaderEffect {
  
                  // update if the name of embedded class (if used) is changed
                  public static var shaderClass:String = "IsolateColorKernel";
                  // update if the name of the file (if loaded) is changed
                  public static var shaderFile:String = "isolateColor.pbj";
  
                  private var _red:uint;
                  private var _green:uint;
                  private var _blue:uint;
                  private var _hueThreshold:uint;
                  private var _luminanceThreshold:uint;
                  private var _hideNonIsolated:uint;
  
                  
Constructor. Sets initial properties.
parameter: color The color to isolate in the image.
parameter: hueThreshold The variance from the color's hue that will still be considered a match.
parameter: luminanceThreshold The variance from the color's luminance that will still be considered a match.
parameter: hideNonIsolated True to set non-isolated pixels to be transparent, false to make pixels grayscale.
parameter: blendMode The blend mode to use when applying the effect.
parameter: alpha The alpha to use when applying the effect.

  
                  public function @ax-graphic-flex-image-effects-10-Flex-IsolateColorEffect(
                          color:uint=0xFF0000,
                          hueThreshold:uint=10,
                          luminanceThreshold:uint=60,
                          hideNonIsolated:Boolean=false,
                          blendMode:String=null,
                          alpha:Number=1
                  ) {
                          _shaderClass = shaderClass;
                          _shaderFile = shaderFile;
                          this.color = color;
                          this.hueThreshold = hueThreshold;
                          this.luminanceThreshold = luminanceThreshold;
                          this.hideNonIsolated = hideNonIsolated;
                          init(blendMode, alpha);
                  }
  
                  
Configures the shader data with this instance's property values. @para data The data for the shader on which parameters can be set.

  
                  override protected function configureShader(data:Object):void {
                          data.color.value = [_red, _green, _blue];
                          data.hueThreshold.value =  [hueThreshold];
                          data.luminanceThreshold.value =  [luminanceThreshold];
                          data.hideNonIsolated.value =  [hideNonIsolated];
                  }
  
                  
Sets the color to isolate in the image. This splits up the color into component channel values.
parameter: color The numeric value of the color to isolate.

  
                  public function set color(color:uint):void {
                          color = MathUtil.clamp(color, 0, 0xFFFFFF);
                          _red = color >> 16 & 0xFF;
                          _green = color >> 8 & 0xFF;
                          _blue = color & 0xFF;
                  }
  
                  
Sets the threshold in which a pixel's hue is considered a match to the set color. This ensures a value between 0 and 360.
parameter: threshold The amount that a pixel's hue can vary from the color's hue and still be a match.

  
                  public function set hueThreshold(threshold:uint):void {
                          _hueThreshold = MathUtil.clamp(threshold, 0, 360);
                  }
  
                  
Sets the threshold in which a pixel's luminance is considered a match to the set color. This ensures a value between 0 and 255.
parameter: threshold The amount that a pixel's luminance can vary from the color's luminance and still be a match.

  
                  public function set luminanceThreshold(threshold:uint):void {
                          _luminanceThreshold = MathUtil.clamp(threshold, 0, 255);
                  }
  
                  
Sets whether non-isolated colors should be hidden or made grayscale. This transforms the Boolean value to a 0 or 1 as used by the shader.
parameter: hide True to set non-isolated pixels to be transparent, false to make pixels grayscale.

  
                  public function set hideNonIsolated(hide:Boolean):void {
                          _hideNonIsolated = hide ? 1 : 0;
                  }
  
          }
  
  }
  


(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.