mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibGfx: Add Bitmap::solid_color()
This function returns an Optional<Color> and is given an alpha_threshold. If all pixels above that alpha threshold are the same color, it returns the color, otherwise it returns an empty optional.
This commit is contained in:
parent
48d3db3c3d
commit
8e441d402b
Notes:
sideshowbarker
2024-07-18 00:54:03 +09:00
Author: https://github.com/MacDue Commit: https://github.com/SerenityOS/serenity/commit/8e441d402b Pull-request: https://github.com/SerenityOS/serenity/pull/13989 Issue: https://github.com/SerenityOS/serenity/issues/13978 Reviewed-by: https://github.com/Hendiadyoin1 Reviewed-by: https://github.com/linusg
2 changed files with 19 additions and 0 deletions
|
@ -608,4 +608,21 @@ bool Bitmap::visually_equals(Bitmap const& other) const
|
|||
return true;
|
||||
}
|
||||
|
||||
Optional<Color> Bitmap::solid_color(u8 alpha_threshold) const
|
||||
{
|
||||
Optional<Color> color;
|
||||
for (auto y = 0; y < height(); ++y) {
|
||||
for (auto x = 0; x < width(); ++x) {
|
||||
auto const& pixel = get_pixel(x, y);
|
||||
if (has_alpha_channel() && pixel.alpha() <= alpha_threshold)
|
||||
continue;
|
||||
if (!color.has_value())
|
||||
color = pixel;
|
||||
else if (pixel != color)
|
||||
return {};
|
||||
}
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -240,6 +240,8 @@ public:
|
|||
|
||||
[[nodiscard]] bool visually_equals(Bitmap const&) const;
|
||||
|
||||
[[nodiscard]] Optional<Color> solid_color(u8 alpha_threshold = 0) const;
|
||||
|
||||
private:
|
||||
Bitmap(BitmapFormat, IntSize const&, int, BackingStore const&);
|
||||
Bitmap(BitmapFormat, IntSize const&, int, size_t pitch, void*);
|
||||
|
|
Loading…
Reference in a new issue