diff --git a/src/filters/HSL.js b/src/filters/HSL.js index 9d70057a..062db1ef 100644 --- a/src/filters/HSL.js +++ b/src/filters/HSL.js @@ -1,11 +1,50 @@ (function () { - HSV = function (imageData) { + Kinetic.Factory.addGetterSetter(Kinetic.Node, 'hue', 0, null, Kinetic.Factory.afterSetFilter); + /** + * get/set hsv hue in degrees + * @name hue + * @method + * @memberof Kinetic.Node.prototype + * @param {Number} hue value between 0 and 359 + * @returns {Number} + */ + + Kinetic.Factory.addGetterSetter(Kinetic.Node, 'saturation', 0, null, Kinetic.Factory.afterSetFilter); + /** + * get/set hsv saturation + * @name saturation + * @method + * @memberof Kinetic.Node.prototype + * @param {Number} saturation 0 is no change, -1.0 halves the saturation, 1.0 doubles, etc.. + * @returns {Number} + */ + + Kinetic.Factory.addGetterSetter(Kinetic.Node, 'luminance', 0, null, Kinetic.Factory.afterSetFilter); + /** + * get/set hsl luminance + * @name value + * @method + * @memberof Kinetic.Node.prototype + * @param {Number} value 0 is no change, -1.0 halves the value, 1.0 doubles, etc.. + * @returns {Number} + */ + + /** + * HSL Filter. Adjusts the hue, saturation and luminance (or lightness) + * @function + * @memberof Kinetic.Filters + * @param {Object} imageData + * @author ippo615 + */ + + Kinetic.Filters.HSL = function (imageData) { var data = imageData.data, nPixels = data.length, - v = Math.pow(2,this.value()), + v = 1, s = Math.pow(2,this.saturation()), h = Math.abs((this.hue()) + 360) % 360, + l = this.luminance()*127, i; // Basis for the technique used: @@ -41,78 +80,10 @@ b = data[i+2]; a = data[i+3]; - data[i+0] = rr*r + rg*g + rb*b; - data[i+1] = gr*r + gg*g + gb*b; - data[i+2] = br*r + bg*g + bb*b; + data[i+0] = rr*r + rg*g + rb*b + l; + data[i+1] = gr*r + gg*g + gb*b + l; + data[i+2] = br*r + bg*g + bb*b + l; data[i+3] = a; // alpha } - - }; - - Kinetic.Factory.addGetterSetter(Kinetic.Node, 'hue', 0, null, Kinetic.Factory.afterSetFilter); - /** - * get/set hsv hue in degrees - * @name hue - * @method - * @memberof Kinetic.Node.prototype - * @param {Number} hue value between 0 and 359 - * @returns {Number} - */ - - Kinetic.Factory.addGetterSetter(Kinetic.Node, 'saturation', 0, null, Kinetic.Factory.afterSetFilter); - /** - * get/set hsv saturation - * @name saturation - * @method - * @memberof Kinetic.Node.prototype - * @param {Number} saturation 0 is no change, -1.0 halves the saturation, 1.0 doubles, etc.. - * @returns {Number} - */ - - Kinetic.Factory.addGetterSetter(Kinetic.Node, 'value', 0, null, Kinetic.Factory.afterSetFilter); - /** - * get/set hsv value - * @name value - * @method - * @memberof Kinetic.Node.prototype - * @param {Number} value 0 is no change, -1.0 halves the value, 1.0 doubles, etc.. - * @returns {Number} - */ - - Kinetic.Factory.addGetterSetter(Kinetic.Node, 'luminance', 0, null, Kinetic.Factory.afterSetFilter); - /** - * get/set hsl luminance - * @name value - * @method - * @memberof Kinetic.Node.prototype - * @param {Number} value 0 is no change, -1.0 halves the value, 1.0 doubles, etc.. - * @returns {Number} - */ - - /** - * HSL Filter. Adjusts the hue, saturation and luminance (or lightness) - * @function - * @memberof Kinetic.Filters - * @param {Object} imageData - * @author ippo615 - */ - - Kinetic.Filters.HSL = function (imageData) { - // Hue stays the same but saturation, value and brightness will be - // adjusted to match common photo-editing software's extreme values - var oldSaturation = this.saturation(), - oldBrightness = this.brightness(), - oldValue = this.value(); - - this.saturation(oldSaturation); - this.brightness(0.5*this.luminance()); - this.value(0.0); - - HSV.call(this,imageData); - Kinetic.Filters.Brighten.call(this,imageData); - - this.saturation(oldSaturation); - this.brightness(oldBrightness); - this.value(oldValue); }; })();