mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 17:07:46 +00:00
LibGfx: Implement flood fill algorithm in Bitmap class
This change implements a flood fill algorithm for the Bitmap class. This will be leveraged by various Tools in PixelPaint. Moving the code into Bitmap reduces the duplication of the algorithm throughout the PixelPaint Tools (currently Bucket Tool and Wand Select). The flood fill function requires you to pass in a threshold value (0 - 100) as well as a lambda for what to do when a pixel gets reached. The lambda is provided an IntPoint representing the coordinates of the pixel that was just reached. The genericized lambda approach allows for a variety of things to be done as the flood algorithm progresses. For example, the Bucket Tool will paint each pixel that gets reached with the fill_color. The Wand Select tool wont actually alter the bitmap itself, instead it uses the reached pixels to alter a selection mask.
This commit is contained in:
parent
6933644b2e
commit
eec881ea34
3 changed files with 62 additions and 0 deletions
|
@ -255,6 +255,15 @@ public:
|
|||
alpha() * other.alpha() / 255);
|
||||
}
|
||||
|
||||
constexpr float distance_squared_to(Color const& other) const
|
||||
{
|
||||
int a = other.red() - red();
|
||||
int b = other.green() - green();
|
||||
int c = other.blue() - blue();
|
||||
int d = other.alpha() - alpha();
|
||||
return (a * a + b * b + c * c + d * d) / (4.0f * 255.0f * 255.0f);
|
||||
}
|
||||
|
||||
constexpr u8 luminosity() const
|
||||
{
|
||||
return (red() * 0.2126f + green() * 0.7152f + blue() * 0.0722f);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue