added Invert filter which inverts image colors

This commit is contained in:
Eric Rowell 2012-11-04 11:30:40 -08:00
parent b76cc09742
commit 656a7a63e4
3 changed files with 54 additions and 1 deletions

View File

@ -4,7 +4,8 @@ require 'uglifier'
class Build < Thor
# This is the list of files to concatenate. The first file will appear at the top of the final file. All files are relative to the lib directory.
FILES = [
"src/Global.js", "src/filters/Grayscale.js", "src/filters/Brighten.js", "src/util/Type.js", "src/util/Canvas.js", "src/util/Tween.js", "src/util/Transform.js", "src/util/Collection.js",
"src/Global.js", "src/util/Type.js", "src/util/Canvas.js", "src/util/Tween.js", "src/util/Transform.js", "src/util/Collection.js",
"src/filters/Grayscale.js", "src/filters/Brighten.js", "src/filters/Invert.js",
"src/Animation.js", "src/Node.js", "src/DragAndDrop.js", "src/Transition.js", "src/Container.js", "src/Stage.js", "src/Layer.js", "src/Group.js", "src/Shape.js",
"src/shapes/Rect.js", "src/shapes/Circle.js", "src/shapes/Ellipse.js", "src/shapes/Image.js", "src/shapes/Polygon.js", "src/shapes/Text.js", "src/shapes/Line.js", "src/shapes/Sprite.js", "src/shapes/Star.js", "src/shapes/RegularPolygon.js", "src/shapes/Path.js", "src/shapes/TextPath.js"
]

16
src/filters/Invert.js Normal file
View File

@ -0,0 +1,16 @@
/**
* Invert Filter
* @function Invert
* @methodOf Kinetic.Filters
*/
Kinetic.Filters.Invert = function(imageData, config) {
var data = imageData.data;
for(var i = 0; i < data.length; i += 4) {
// red
data[i] = 255 - data[i];
// green
data[i + 1] = 255 - data[i + 1];
// blue
data[i + 2] = 255 - data[i + 2];
}
};

View File

@ -1616,6 +1616,42 @@ Test.prototype.tests = {
};
imageObj.src = '../assets/darth-vader.jpg';
},
'Filters - invert image': function(containerId) {
var imageObj = new Image();
imageObj.onload = function() {
var stage = new Kinetic.Stage({
container: containerId,
width: 578,
height: 200
});
var layer = new Kinetic.Layer({
throttle: 999
});
darth = new Kinetic.Image({
x: 10,
y: 10,
image: imageObj,
draggable: true
});
layer.add(darth);
stage.add(layer);
test(darth.getWidth() === 438, 'image width should be 438');
test(darth.getHeight() === 300, 'image height should be 300');
darth.applyFilter({
filter: Kinetic.Filters.Invert,
callback: function() {
layer.draw();
var dataUrl = layer.toDataURL();
//console.log(dataUrl);
//warn(dataUrl === dataUrls['Filters - invert image'], 'problem with Invert filter.');
}
});
};
imageObj.src = '../assets/darth-vader.jpg';
},
'Filters - adjust image brightness': function(containerId) {
var imageObj = new Image();
imageObj.onload = function() {