diff --git a/src/js/drawingtools/ColorSwap.js b/src/js/drawingtools/ColorSwap.js index 9b4e430..a63340f 100644 --- a/src/js/drawingtools/ColorSwap.js +++ b/src/js/drawingtools/ColorSwap.js @@ -1,7 +1,6 @@ /** * @provide pskl.drawingtools.ColorSwap * - * @require pskl.utils */ (function() { var ns = $.namespace("pskl.drawingtools"); @@ -19,9 +18,7 @@ ns.ColorSwap.prototype.applyToolAt = function(col, row, color, frame, overlay, event) { if (frame.containsPixel(col, row)) { var sampledColor = frame.getPixel(col, row); - console.time('swapColors'); this.swapColors(sampledColor, color); - console.timeEnd('swapColors'); $.publish(Events.PISKEL_SAVE_STATE, { type : pskl.service.HistoryService.SNAPSHOT @@ -30,14 +27,14 @@ }; ns.ColorSwap.prototype.swapColors = function(oldColor, newColor) { - var swapPixels = function (pixelColor,x,y,frame) { + var swapPixelColor = function (pixelColor,x,y,frame) { if (pixelColor == oldColor) { frame.pixels[x][y] = newColor; } }; pskl.app.piskelController.getPiskel().getLayers().forEach(function (l) { l.getFrames().forEach(function (f) { - f.forEachPixel(swapPixels); + f.forEachPixel(swapPixelColor); f.version++; }); }); diff --git a/src/js/model/Frame.js b/src/js/model/Frame.js index 8de6510..ae417b6 100644 --- a/src/js/model/Frame.js +++ b/src/js/model/Frame.js @@ -96,22 +96,18 @@ ns.Frame.prototype.getPixel = function (x, y) { if (this.containsPixel(x, y)) { - return this._unsafeGetPixel(x,y); + return this.pixels[x][y]; } else { return null; } }; - ns.Frame.prototype._unsafeGetPixel = function (x, y) { - return this.pixels[x][y]; - }; - ns.Frame.prototype.forEachPixel = function (callback) { var width = this.getWidth(); var height = this.getHeight(); - for (var col = 0 ; col < width ; col++) { - for (var row = 0 ; row < height ; row++) { - callback(this._unsafeGetPixel(col, row), col, row, this); + for (var x = 0 ; x < width ; x++) { + for (var y = 0 ; y < height ; y++) { + callback(this.pixels[x][y], x, y, this); } } }; @@ -128,29 +124,6 @@ return col >= 0 && row >= 0 && col < this.width && row < this.height; }; - ns.Frame.prototype.saveState = function () { - // remove all states past current state - this.previousStates.length = this.stateIndex + 1; - // push new state - this.previousStates.push(this.getPixels()); - // set the stateIndex to latest saved state - this.stateIndex = this.previousStates.length - 1; - }; - - ns.Frame.prototype.loadPreviousState = function () { - if (this.stateIndex > 0) { - this.stateIndex--; - this.setPixels(this.previousStates[this.stateIndex]); - } - }; - - ns.Frame.prototype.loadNextState = function () { - if (this.stateIndex < this.previousStates.length - 1) { - this.stateIndex++; - this.setPixels(this.previousStates[this.stateIndex]); - } - }; - ns.Frame.prototype.isSameSize = function (otherFrame) { return this.getHeight() == otherFrame.getHeight() && this.getWidth() == otherFrame.getWidth(); };