New HSL filter. HSV and HSL want values between -1.0 and +1.0 (was 0.5 to 2.0)

This commit is contained in:
ippo615
2014-01-31 16:49:11 -05:00
parent 774f50007c
commit da5055cf28
6 changed files with 267 additions and 135 deletions

View File

@@ -11,8 +11,8 @@
Kinetic.Filters.HSV = function (imageData) {
var data = imageData.data,
nPixels = data.length,
v = this.value(),
s = this.saturation(),
v = Math.pow(2,this.value()),
s = Math.pow(2,this.saturation()),
h = Math.abs((this.hue()) + 360) % 360,
i;
@@ -67,60 +67,24 @@
* @returns {Number}
*/
Kinetic.Factory.addGetterSetter(Kinetic.Node, 'saturation', 1, null, Kinetic.Factory.afterSetFilter);
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 1 is no change, 0.5 halves the saturation, 2.0 doubles, etc..
* @param {Number} saturation 0 is no change, -1.0 halves the saturation, 1.0 doubles, etc..
* @returns {Number}
*/
Kinetic.Factory.addGetterSetter(Kinetic.Node, 'value', 1, null, Kinetic.Factory.afterSetFilter);
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 1 is no change, 0.5 halves the value, 2.0 doubles, etc..
* @param {Number} value 0 is no change, -1.0 halves the value, 1.0 doubles, etc..
* @returns {Number}
*/
Kinetic.Factory.addGetterSetter(Kinetic.Node, 'luminance', 1, null, Kinetic.Factory.afterSetFilter);
/**
* get/set hsl luminance
* @name value
* @method
* @memberof Kinetic.Node.prototype
* @param {Number} value 1 is no change, 0.5 halves the value, 2.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*oldSaturation);
this.brightness(0.5*(this.luminance()-1));
this.value(1.0);
Kinetic.Filters.HSV.call(this,imageData);
Kinetic.Filters.Brighten.call(this,imageData);
this.saturation(oldSaturation);
this.brightness(oldBrightness);
this.value(oldValue);
};
})();