diff --git a/src/js/tools/drawing/ColorSwap.js b/src/js/tools/drawing/ColorSwap.js index 20184500..fa853172 100644 --- a/src/js/tools/drawing/ColorSwap.js +++ b/src/js/tools/drawing/ColorSwap.js @@ -28,7 +28,6 @@ var allLayers = pskl.utils.UserAgent.isMac ? event.metaKey : event.ctrlKey; var allFrames = event.shiftKey; - this.swapColors_(oldColor, newColor, allLayers, allFrames); this.raiseSaveStateEvent({ @@ -56,8 +55,10 @@ }; ns.ColorSwap.prototype.applyToolOnFrame_ = function (frame, oldColor, newColor) { + oldColor = pskl.utils.colorToInt(oldColor); + newColor = pskl.utils.colorToInt(newColor); frame.forEachPixel(function (color, col, row) { - if (color && color == oldColor) { + if (color !== null && color == oldColor) { frame.setPixel(col, row, newColor); } }); diff --git a/src/js/utils/PixelUtils.js b/src/js/utils/PixelUtils.js index c67c5d49..667d7a48 100644 --- a/src/js/utils/PixelUtils.js +++ b/src/js/utils/PixelUtils.js @@ -146,6 +146,10 @@ * 13. Continue looping until Q is exhausted. * 14. Return. */ + if (typeof replacementColor == 'string') { + replacementColor = pskl.utils.colorToInt(replacementColor); + } + var targetColor; try { targetColor = frame.getPixel(col, row); @@ -153,7 +157,7 @@ // Frame out of bound exception. } - if (targetColor == replacementColor) { + if (targetColor === null || targetColor == replacementColor) { return; } @@ -162,7 +166,7 @@ row : row }; var paintedPixels = pskl.PixelUtils.visitConnectedPixels(startPixel, frame, function (pixel) { - if (frame.containsPixel(pixel.col, pixel.row) && frame.getPixel(pixel.col, pixel.row) == targetColor) { + if (frame.getPixel(pixel.col, pixel.row) == targetColor) { frame.setPixel(pixel.col, pixel.row, replacementColor); return true; }