mirror of
https://github.com/konvajs/konva.git
synced 2025-04-05 20:48:28 +08:00
changed Levels filter to Posterize
This commit is contained in:
parent
cfe3091833
commit
7f0dc2085b
@ -19,7 +19,7 @@ module.exports = function(grunt) {
|
||||
'src/filters/HSV.js',
|
||||
'src/filters/ConvolvePack.js',
|
||||
'src/filters/Enhance.js',
|
||||
'src/filters/Levels.js',
|
||||
'src/filters/Posterize.js',
|
||||
'src/filters/Noise.js',
|
||||
'src/filters/Pixelate.js',
|
||||
'src/filters/Polar.js',
|
||||
|
@ -1,36 +1,36 @@
|
||||
(function () {
|
||||
|
||||
/**
|
||||
* Levels Filter. Adjusts the channels so that there are no more
|
||||
* than n different values for that channel. This is also applied
|
||||
* to the alpha channel.
|
||||
* @function
|
||||
* @author ippo615
|
||||
* @memberof Kinetic.Filters
|
||||
* @param {Object} imageData
|
||||
*/
|
||||
|
||||
Kinetic.Filters.Levels = function (imageData) {
|
||||
// level must be between 1 and 255
|
||||
var level = Math.round(this.level() * 254) + 1,
|
||||
data = imageData.data,
|
||||
len = data.length,
|
||||
scale = (255 / level),
|
||||
i;
|
||||
|
||||
for (i = 0; i < len; i += 1) {
|
||||
data[i] = Math.floor(data[i] / scale) * scale;
|
||||
}
|
||||
};
|
||||
|
||||
Kinetic.Factory.addFilterGetterSetter(Kinetic.Node, 'level', 0.5);
|
||||
|
||||
/**
|
||||
* get/set levels. Must be a number between 0 and 1
|
||||
* @name level
|
||||
* @method
|
||||
* @memberof Kinetic.Node.prototype
|
||||
* @param {Number} level between 0 and 1
|
||||
* @returns {Number}
|
||||
*/
|
||||
(function () {
|
||||
|
||||
/**
|
||||
* Posterize Filter. Adjusts the channels so that there are no more
|
||||
* than n different values for that channel. This is also applied
|
||||
* to the alpha channel.
|
||||
* @function
|
||||
* @author ippo615
|
||||
* @memberof Kinetic.Filters
|
||||
* @param {Object} imageData
|
||||
*/
|
||||
|
||||
Kinetic.Filters.Posterize = function (imageData) {
|
||||
// level must be between 1 and 255
|
||||
var levels = Math.round(this.levels() * 254) + 1,
|
||||
data = imageData.data,
|
||||
len = data.length,
|
||||
scale = (255 / levels),
|
||||
i;
|
||||
|
||||
for (i = 0; i < len; i += 1) {
|
||||
data[i] = Math.floor(data[i] / scale) * scale;
|
||||
}
|
||||
};
|
||||
|
||||
Kinetic.Factory.addFilterGetterSetter(Kinetic.Node, 'levels', 0.5);
|
||||
|
||||
/**
|
||||
* get/set levels. Must be a number between 0 and 1
|
||||
* @name levels
|
||||
* @method
|
||||
* @memberof Kinetic.Node.prototype
|
||||
* @param {Number} level between 0 and 1
|
||||
* @returns {Number}
|
||||
*/
|
||||
})();
|
@ -94,7 +94,7 @@
|
||||
<script src="unit/filters/Pixelate-test.js"></script>
|
||||
<script src="unit/filters/Noise-test.js"></script>
|
||||
<script src="unit/filters/Threshold-test.js"></script>
|
||||
<script src="unit/filters/Levels-test.js"></script>
|
||||
<script src="unit/filters/Posterize-test.js"></script>
|
||||
|
||||
<script src="unit/filters/Sepia-test.js"></script>
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
suite('Levels', function () {
|
||||
suite('Posterize', function () {
|
||||
|
||||
// ======================================================
|
||||
test('on image tween', function(done) {
|
||||
@ -19,14 +19,14 @@ suite('Levels', function () {
|
||||
stage.add(layer);
|
||||
|
||||
darth.cache();
|
||||
darth.filters([Kinetic.Filters.Levels]);
|
||||
darth.level(0.2);
|
||||
darth.filters([Kinetic.Filters.Posterize]);
|
||||
darth.levels(0.2);
|
||||
layer.draw();
|
||||
|
||||
var tween = new Kinetic.Tween({
|
||||
node: darth,
|
||||
duration: 1.0,
|
||||
level: 0,
|
||||
levels: 0,
|
||||
easing: Kinetic.Easings.Linear
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user