I am working on a Flood Fill Algorithm. Unfortunately I have been having performance issues with said algorithm. It hammers the CPU. It's constantly at 100%(or at least one of the cores is, since the app is single threaded). This is what I have come up with so far:
sf::Image BucketTool::rgbFill(sf::Image& canvas_image, sf::Vector2f origin, sf::Color discriminator)
{
if(origin.x < 0 || origin.x >= canvas_image.getSize().x || origin.y < 0 || origin.y >= canvas_image.getSize().y)
{
return canvas_image;
}
if(canvas_image.getPixel(origin.x, origin.y) != discriminator)
{
return canvas_image;
}
canvas_image.setPixel(origin.x, origin.y, sf::Color::Black);
///std::cout<<origin.x<<" "<<origin.y<<std::endl;
rgbFill(canvas_image, sf::Vector2f(origin.x + 1, origin.y), discriminator);
rgbFill(canvas_image, sf::Vector2f(origin.x - 1, origin.y), discriminator);
rgbFill(canvas_image, sf::Vector2f(origin.x, origin.y + 1), discriminator);
rgbFill(canvas_image, sf::Vector2f(origin.x, origin.y - 1), discriminator);
canvas_image.setPixel(origin.x, origin.y, sf::Color::Black);
canvas_image.saveToFile("example.png");
return canvas_image;
}