Fix ColorSwap and Bucket tool

This commit is contained in:
Dávid Szabó 2016-08-30 14:48:25 +02:00 committed by Julian Descottes
parent ac3e43bf61
commit fa716d7a6c
2 changed files with 9 additions and 4 deletions

View File

@ -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);
}
});

View File

@ -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;
}