applyFilter() method now takes in a required filter function, and an optional config and callback function, rather than a config object

This commit is contained in:
Eric Rowell
2012-11-15 21:51:33 -08:00
parent 0db40018af
commit 383a039def
2 changed files with 31 additions and 40 deletions

View File

@@ -72,23 +72,24 @@ Kinetic.Image.prototype = {
* @name applyFilter
* @methodOf Kinetic.Image.prototype
* @param {Object} config
* @param {Function} config.filter filter function
* @param {Function} [config.callback] callback function to be called once
* @param {Function} filter filter function
* @param {Object} [config] optional config object used to configure filter
* @param {Function} [callback] callback function to be called once
* filter has been applied
*/
applyFilter: function(config) {
applyFilter: function(filter, config, callback) {
var canvas = new Kinetic.Canvas(this.attrs.image.width, this.attrs.image.height);
var context = canvas.getContext();
context.drawImage(this.attrs.image, 0, 0);
try {
var imageData = context.getImageData(0, 0, canvas.getWidth(), canvas.getHeight());
config.filter(imageData, config.config);
filter(imageData, config);
var that = this;
Kinetic.Type._getImage(imageData, function(imageObj) {
that.setImage(imageObj);
if(config.callback) {
config.callback();
if(callback) {
callback();
}
});
}