From 0abd779348f420d2d75267057ff9ecc91249a505 Mon Sep 17 00:00:00 2001 From: juliandescottes Date: Fri, 13 Jan 2017 02:59:59 +0100 Subject: [PATCH] fix #602 : shape selection fails with some colors --- src/js/utils/PixelUtils.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/js/utils/PixelUtils.js b/src/js/utils/PixelUtils.js index b6d2d3a0..c3d54df5 100644 --- a/src/js/utils/PixelUtils.js +++ b/src/js/utils/PixelUtils.js @@ -60,14 +60,25 @@ * @return an array of the pixel coordinates paint with the replacement color */ getSimilarConnectedPixelsFromFrame: function(frame, col, row) { - // To get the list of connected (eg the same color) pixels, we will use the paintbucket algorithm - // in a fake cloned frame. The returned pixels by the paintbucket algo are the painted pixels - // and are as well connected. - var fakeFrame = frame.clone(); // We just want to - var fakeFillColor = 'sdfsdfsdf'; // A fake color that will never match a real color. - var paintedPixels = this.paintSimilarConnectedPixelsFromFrame(fakeFrame, col, row, fakeFillColor); + var targetColor = frame.getPixel(col, row); + if (targetColor === null) { + return; + } - return paintedPixels; + var startPixel = { + col : col, + row : row + }; + + var visited = {}; + return pskl.PixelUtils.visitConnectedPixels(startPixel, frame, function (pixel) { + var key = pixel.col + '-' + pixel.row; + if (visited[key]) { + return false; + } + visited[key] = true; + return frame.getPixel(pixel.col, pixel.row) == targetColor; + }); }, /**