refactored filtering logic

This commit is contained in:
Eric Rowell
2012-08-19 13:09:27 -07:00
parent e19dae3402
commit e99312ece2
5 changed files with 23 additions and 26 deletions

20
dist/kinetic-core.js vendored
View File

@@ -3,7 +3,7 @@
* http://www.kineticjs.com/
* Copyright 2012, Eric Rowell
* Licensed under the MIT or GPL Version 2 licenses.
* Date: Aug 18 2012
* Date: Aug 19 2012
*
* Copyright (C) 2011 - 2012 by Eric Rowell
*
@@ -181,8 +181,8 @@ Kinetic.Transition.prototype = {
}
};
Kinetic.Filters.Grayscale = function() {
var data = this.imageData.data;
Kinetic.Filters.Grayscale = function(imageData) {
var data = imageData.data;
for(var i = 0; i < data.length; i += 4) {
var brightness = 0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2];
// red
@@ -4545,14 +4545,14 @@ Kinetic.Image = Kinetic.Shape.extend({
* filter has been applied
*/
applyFilter: function(config) {
try {
var trans = this._clearTransform();
this.saveImageData(this.getWidth(), this.getHeight());
this._setTransform(trans);
config.filter.call(this, config);
var canvas = new Kinetic.Canvas(this.attrs.width, this.attrs.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);
var that = this;
Kinetic.Type._getImage(this.getImageData(), function(imageObj) {
Kinetic.Type._getImage(imageData, function(imageObj) {
that.setImage(imageObj);
if(config.callback) {

File diff suppressed because one or more lines are too long

View File

@@ -1,5 +1,5 @@
Kinetic.Filters.Grayscale = function() {
var data = this.imageData.data;
Kinetic.Filters.Grayscale = function(imageData) {
var data = imageData.data;
for(var i = 0; i < data.length; i += 4) {
var brightness = 0.34 * data[i] + 0.5 * data[i + 1] + 0.16 * data[i + 2];
// red

View File

@@ -80,14 +80,14 @@ Kinetic.Image = Kinetic.Shape.extend({
* filter has been applied
*/
applyFilter: function(config) {
try {
var trans = this._clearTransform();
this.saveImageData(this.getWidth(), this.getHeight());
this._setTransform(trans);
config.filter.call(this, config);
var canvas = new Kinetic.Canvas(this.attrs.width, this.attrs.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);
var that = this;
Kinetic.Type._getImage(this.getImageData(), function(imageObj) {
Kinetic.Type._getImage(imageData, function(imageObj) {
that.setImage(imageObj);
if(config.callback) {

View File

@@ -1610,8 +1610,7 @@ Test.prototype.tests = {
x: 10,
y: 10,
image: imageObj,
draggable: true,
stroke: 'red'
draggable: true
});
layer.add(darth);
@@ -1649,8 +1648,6 @@ Test.prototype.tests = {
//height: 300,
image: imageObj,
draggable: true,
stroke: 'red',
strokeWidth: 5,
rotationDeg: 10,
scale: 0.3
});