diff --git a/Thorfile b/Thorfile index 3ca46f35..e55766df 100644 --- a/Thorfile +++ b/Thorfile @@ -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" ] diff --git a/src/filters/Invert.js b/src/filters/Invert.js new file mode 100644 index 00000000..cfb4c4df --- /dev/null +++ b/src/filters/Invert.js @@ -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]; + } +}; diff --git a/tests/js/unitTests.js b/tests/js/unitTests.js index 4c091ca8..34a66e34 100644 --- a/tests/js/unitTests.js +++ b/tests/js/unitTests.js @@ -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() {