mirror of
https://github.com/konvajs/konva.git
synced 2026-01-09 11:34:38 +08:00
Made filters (Levels, Noise, Threshold) tweenable
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
var Levels = function (src, dst, opt) {
|
||||
var nLevels = opt.quantizationLevels || 2;
|
||||
var nLevels = Math.round(opt.quantizationLevels || 2);
|
||||
var srcPixels = src.data,
|
||||
dstPixels = dst.data,
|
||||
nPixels = srcPixels.length,
|
||||
@@ -27,5 +27,31 @@
|
||||
}
|
||||
};
|
||||
|
||||
Kinetic.Filters.Levels = Kinetic.Util._FilterWrapSingleBuffer(Levels);
|
||||
Kinetic.Filters.Levels = function(src,dst,opt){
|
||||
if( this === Kinetic.Filters ){
|
||||
Levels(src, dst||src, opt );
|
||||
}else{
|
||||
Levels.call(this, src, dst||src, {
|
||||
quantizationLevels: this.getQuantizationLevels()
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Kinetic.Factory.addFilterGetterSetter(Kinetic.Image, 'quantizationLevels', 4);
|
||||
|
||||
/**
|
||||
* get quantization levels. Returns the number of unique levels for each color
|
||||
* channel. 2 is the minimum, 255 is the maximum. For Kinetic.Filters.Levels
|
||||
* @name getQuantizationLevels
|
||||
* @method
|
||||
* @memberof Kinetic.Image.prototype
|
||||
*/
|
||||
|
||||
/**
|
||||
* get quantization levels. Sets the number of unique levels for each color
|
||||
* channel. 2 is the minimum, 255 is the maximum. For Kinetic.Filters.Levels
|
||||
* @name setQuantizationLevels
|
||||
* @method
|
||||
* @memberof Kinetic.Image.prototype
|
||||
*/
|
||||
})();
|
||||
@@ -73,7 +73,20 @@
|
||||
}
|
||||
};
|
||||
|
||||
Kinetic.Filters.MirrorX = Kinetic.Util._FilterWrapSingleBuffer(MirrorX);
|
||||
Kinetic.Filters.MirrorY = Kinetic.Util._FilterWrapSingleBuffer(MirrorY);
|
||||
Kinetic.Filters.MirrorX = function(src,dst,opt){
|
||||
if( this === Kinetic.Filters ){
|
||||
MirrorX(src, dst||src, opt );
|
||||
}else{
|
||||
MirrorX.call(this, src, dst||src, opt);
|
||||
}
|
||||
};
|
||||
|
||||
Kinetic.Filters.MirrorY = function(src,dst,opt){
|
||||
if( this === Kinetic.Filters ){
|
||||
MirrorY(src, dst||src, opt );
|
||||
}else{
|
||||
MirrorY.call(this, src, dst||src, opt);
|
||||
}
|
||||
};
|
||||
|
||||
})();
|
||||
|
||||
@@ -11,12 +11,12 @@
|
||||
* @param {Object} opt
|
||||
* @param {Number} [opt.noiseAmount] The amount of noise to add. Between 0 and 255.
|
||||
* Each channel of each pixel will change by a random amount
|
||||
* between +- amount/2. Default is 32.
|
||||
* between +- amount/2. Default is 0.
|
||||
* @param {Number} [opt.affectAlpha] 1 to add noise to the alpha channel.
|
||||
* Default is 0.
|
||||
*/
|
||||
var Noise = function (src, dst, opt) {
|
||||
var amount = opt.noiseAmount || 32,
|
||||
var amount = opt.noiseAmount || 0,
|
||||
affectAlpha = opt.affectAlpha || 0;
|
||||
var srcPixels = src.data,
|
||||
dstPixels = dst.data,
|
||||
@@ -40,5 +40,30 @@
|
||||
}
|
||||
};
|
||||
|
||||
Kinetic.Filters.Noise = Kinetic.Util._FilterWrapSingleBuffer(Noise);
|
||||
Kinetic.Factory.addFilterGetterSetter(Kinetic.Image, 'noiseAmount', 32);
|
||||
|
||||
Kinetic.Filters.Noise = function(src,dst,opt){
|
||||
if( this === Kinetic.Filters ){
|
||||
Noise(src, dst||src, opt );
|
||||
}else{
|
||||
Noise.call(this, src, dst||src, opt || {
|
||||
noiseAmount: this.getNoiseAmount()
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* get noise amount. Returns the amount of noise. Between 0 and 255.
|
||||
* @name getNoiseAmount
|
||||
* @method
|
||||
* @memberof Kinetic.Image.prototype
|
||||
*/
|
||||
|
||||
/**
|
||||
* set noise amount. Sets the amount of noise. Between 0 and 255.
|
||||
* @name setNoiseAmount
|
||||
* @method
|
||||
* @memberof Kinetic.Image.prototype
|
||||
*/
|
||||
|
||||
})();
|
||||
|
||||
@@ -16,7 +16,10 @@
|
||||
*/
|
||||
|
||||
var Threshold = function (src, dst, opt) {
|
||||
var level = opt.thresholdLevel || 128;
|
||||
var level = 128;
|
||||
if( opt.hasOwnProperty ){
|
||||
level = opt.thresholdLevel;
|
||||
}
|
||||
var srcPixels = src.data,
|
||||
dstPixels = dst.data,
|
||||
nPixels = srcPixels.length,
|
||||
@@ -30,5 +33,29 @@
|
||||
}
|
||||
};
|
||||
|
||||
Kinetic.Filters.Threshold = Kinetic.Util._FilterWrapSingleBuffer(Threshold);
|
||||
Kinetic.Factory.addFilterGetterSetter(Kinetic.Image, 'thresholdLevel', 128);
|
||||
|
||||
Kinetic.Filters.Threshold = function(src,dst,opt){
|
||||
if( this === Kinetic.Filters ){
|
||||
Threshold(src, dst||src, opt );
|
||||
}else{
|
||||
Threshold.call(this, src, dst||src, opt || {
|
||||
thresholdLevel: this.getThresholdLevel()
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* get threshold level. Returns the level which divides the color channel (0-255).
|
||||
* @name getThresholdLevel
|
||||
* @method
|
||||
* @memberof Kinetic.Image.prototype
|
||||
*/
|
||||
|
||||
/**
|
||||
* set threshold level. Sets the level which divides the color channel (0-255).
|
||||
* @name setThresholdLevel
|
||||
* @method
|
||||
* @memberof Kinetic.Image.prototype
|
||||
*/
|
||||
})();
|
||||
Reference in New Issue
Block a user