1
General / Re: Making Flood Fill Algorithm more efficient.
« on: March 01, 2020, 07:55:31 pm »
I have modified the function a bit, and it works(sometimes), but if all recursive directions are enabled is segfaults. If two of them are commented out while the rest are not, it works perfectly fine. Possibly connected with running out of memory?
void BucketTool::rgbFill(sf::Image& canvas_image, sf::Vector2i origin, sf::Color discriminator)
{
if(canvas_image.getPixel(origin.x, origin.y) == discriminator)
{
if(!(origin.x < 0 || origin.x >= canvas_image.getSize().x || origin.y < 0 || origin.y >= canvas_image.getSize().y))
{
//std::cout << origin.x << " " << origin.y << std::endl;
canvas_image.setPixel(origin.x, origin.y, sf::Color::Black);
rgbFill(canvas_image, sf::Vector2i(origin.x + 1, origin.y), discriminator); //if two of there are commented out it works fine
rgbFill(canvas_image, sf::Vector2i(origin.x - 1, origin.y), discriminator);
rgbFill(canvas_image, sf::Vector2i(origin.x, origin.y + 1), discriminator);
rgbFill(canvas_image, sf::Vector2i(origin.x, origin.y - 1), discriminator);
}
}
}
{
if(canvas_image.getPixel(origin.x, origin.y) == discriminator)
{
if(!(origin.x < 0 || origin.x >= canvas_image.getSize().x || origin.y < 0 || origin.y >= canvas_image.getSize().y))
{
//std::cout << origin.x << " " << origin.y << std::endl;
canvas_image.setPixel(origin.x, origin.y, sf::Color::Black);
rgbFill(canvas_image, sf::Vector2i(origin.x + 1, origin.y), discriminator); //if two of there are commented out it works fine
rgbFill(canvas_image, sf::Vector2i(origin.x - 1, origin.y), discriminator);
rgbFill(canvas_image, sf::Vector2i(origin.x, origin.y + 1), discriminator);
rgbFill(canvas_image, sf::Vector2i(origin.x, origin.y - 1), discriminator);
}
}
}