text: /*
  * Tencent is pleased to support the open source community by making Fanvas available.
  * Copyright (C) 2015 THL A29 Limited, a Tencent company. All rights reserved.
  *
  * Licensed under the MIT License (the "License"); you may not use this file except in compliance with the 
  * License. You may obtain a copy of the License at
  * http://opensource.org/licenses/MIT
  *
  * Unless required by applicable law or agreed to in writing, software distributed under the License is 
  * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
  * implied. See the License for the specific language governing permissions and limitations under the 
  * License.
  */
  
  // namespace:
  this.fanvas = this.fanvas||{};
  
  (function() {
  	"use strict";
  
  /**
   * Applies a color transform to DisplayObjects.
   *
   * See {{#crossLink "Filter"}}{{/crossLink}} for an more information on applying filters.
   * @class ColorFilter
   * @param {Number} [redMultiplier=1] The amount to multiply against the red channel. This is a range between 0 and 1.
   * @param {Number} [greenMultiplier=1] The amount to multiply against the green channel. This is a range between 0 and 1.
   * @param {Number} [blueMultiplier=1] The amount to multiply against the blue channel. This is a range between 0 and 1.
   * @param {Number} [alphaMultiplier=1] The amount to multiply against the alpha channel. This is a range between 0 and 1.
   * @param {Number} [redOffset=0] The amount to add to the red channel after it has been multiplied. This is a range
   * between -255 and 255.
   * @param {Number} [greenOffset=0] The amount to add to the green channel after it has been multiplied. This is a range
    * between -255 and 255.
   * @param {Number} [blueOffset=0] The amount to add to the blue channel after it has been multiplied. This is a range
    * between -255 and 255.
   * @param {Number} [alphaOffset=0] The amount to add to the alpha channel after it has been multiplied. This is a range
    * between -255 and 255.
   * @constructor
   * @extends Filter
   **/
  var ColorFilter = function(redMultiplier, greenMultiplier, blueMultiplier, alphaMultiplier, redOffset, greenOffset, blueOffset, alphaOffset) {
    this.initialize(redMultiplier, greenMultiplier, blueMultiplier, alphaMultiplier, redOffset, greenOffset, blueOffset, alphaOffset);
  }
  var p = ColorFilter.prototype = new fanvas.Filter();
  
  // public properties:
  	/**
  	 * Red channel multiplier.
  	 * @property redMultiplier
  	 * @type Number
  	 **/
  	p.redMultiplier = 1;
  
  	/**
  	 * Green channel multiplier.
  	 * @property greenMultiplier
  	 * @type Number
  	 **/
  	p.greenMultiplier = 1;
  
  	/**
  	 * Blue channel multiplier.
  	 * @property blueMultiplier
  	 * @type Number
  	 **/
  	p.blueMultiplier = 1;
  
  	/**
  	 * Alpha channel multiplier.
  	 * @property alphaMultiplier
  	 * @type Number
  	 **/
  	p.alphaMultiplier = 1;
  
  	/**
  	 * Red channel offset (added to value).
  	 * @property redOffset
  	 * @type Number
  	 **/
  	p.redOffset = 0;
  
  	/**
  	 * Green channel offset (added to value).
  	 * @property greenOffset
  	 * @type Number
  	 **/
  	p.greenOffset = 0;
  
  	/**
  	 * Blue channel offset (added to value).
  	 * @property blueOffset
  	 * @type Number
  	 **/
  	p.blueOffset = 0;
  
  	/**
  	 * Alpha channel offset (added to value).
  	 * @property alphaOffset
  	 * @type Number
  	 **/
  	p.alphaOffset = 0;
  
  // constructor:
  	/**
  	 * Initialization method.
  	 * @method initialize
  	 * @param {Number} [redMultiplier=1] The amount to multiply against the red channel. This is a range between 0 and 1.
  	 * @param {Number} [greenMultiplier=1] The amount to multiply against the green channel. This is a range between 0 and 1.
  	 * @param {Number} [blueMultiplier=1] The amount to multiply against the blue channel. This is a range between 0 and 1.
  	 * @param {Number} [alphaMultiplier=1] The amount to multiply against the alpha channel. This is a range between 0 and 1.
  	 * @param {Number} [redOffset=0] The amount to add to the red channel after it has been multiplied. This is a range
  	 * between -255 and 255.
  	 * @param {Number} [greenOffset=0] The amount to add to the green channel after it has been multiplied. This is a range
  	 * between -255 and 255.
  	 * @param {Number} [blueOffset=0] The amount to add to the blue channel after it has been multiplied. This is a range
  	 * between -255 and 255.
  	 * @param {Number} [alphaOffset=0] The amount to add to the alpha channel after it has been multiplied. This is a range
  	 * between -255 and 255.
  	 * @protected
  	 **/
  	p.initialize = function(redMultiplier, greenMultiplier, blueMultiplier, alphaMultiplier, redOffset, greenOffset, blueOffset, alphaOffset) {
  		this.redMultiplier = redMultiplier != null ? redMultiplier : 1;
  		this.greenMultiplier = greenMultiplier != null ? greenMultiplier : 1;
  		this.blueMultiplier = blueMultiplier != null ? blueMultiplier : 1;
  		this.alphaMultiplier = alphaMultiplier != null ? alphaMultiplier : 1;
  		this.redOffset = redOffset || 0;
  		this.greenOffset = greenOffset || 0;
  		this.blueOffset = blueOffset || 0;
  		this.alphaOffset = alphaOffset || 0;
  	}
  
  // public methods:
  	p.applyFilter = function(ctx, x, y, width, height, targetCtx, targetX, targetY) {
  		targetCtx = targetCtx || ctx;
  		if (targetX == null) { targetX = x; }
  		if (targetY == null) { targetY = y; }
  		try {
  			var imageData = ctx.getImageData(x, y, width, height);
  		} catch(e) {
  			//if (!this.suppressCrossDomainErrors) throw new Error("unable to access local image data: " + e);
  			return false;
  		}
  		var data = imageData.data;
  		var l = data.length;
  		for (var i=0; i<l; i+=4) {
  			data[i] = data[i]*this.redMultiplier+this.redOffset;
  			data[i+1] = data[i+1]*this.greenMultiplier+this.greenOffset;
  			data[i+2] = data[i+2]*this.blueMultiplier+this.blueOffset;
  			data[i+3] = data[i+3]*this.alphaMultiplier+this.alphaOffset;
  		}
  		targetCtx.putImageData(imageData, targetX, targetY);
  		return true;
  	}
  
  	fanvas.ColorFilter = ColorFilter;
  
  }());
  