summaryrefslogtreecommitdiff
path: root/Userland/Applications
diff options
context:
space:
mode:
authorTimothy Slater <tslater2006@gmail.com>2022-08-31 11:29:56 -0500
committerLinus Groh <mail@linusgroh.de>2022-08-31 18:19:46 +0100
commitf2da577e7739b4203df4d1321993f33f4b16bc4f (patch)
tree4c81800e9e46a296381be04e638ca20cc665ea4b /Userland/Applications
parenta0ef00cab2e239d2c1853cf13ca850c9c1111915 (diff)
downloadserenity-f2da577e7739b4203df4d1321993f33f4b16bc4f.zip
PixelPaint: Change repeated code into a loop for Wand Select Tool
Diffstat (limited to 'Userland/Applications')
-rw-r--r--Userland/Applications/PixelPaint/Tools/WandSelectTool.cpp40
1 files changed, 9 insertions, 31 deletions
diff --git a/Userland/Applications/PixelPaint/Tools/WandSelectTool.cpp b/Userland/Applications/PixelPaint/Tools/WandSelectTool.cpp
index 180b7b8c57..f0e5b22dc5 100644
--- a/Userland/Applications/PixelPaint/Tools/WandSelectTool.cpp
+++ b/Userland/Applications/PixelPaint/Tools/WandSelectTool.cpp
@@ -56,37 +56,15 @@ static void set_flood_selection(Gfx::Bitmap& bitmap, Image& image, Gfx::IntPoint
// As we find neighbors that are paintable we update their pixel, add them to the queue, and mark them in the mask
while (!points_to_visit.is_empty()) {
auto current_point = points_to_visit.dequeue();
- Gfx::IntPoint candidate_point = {};
-
- if (current_point.x() > 0) {
- candidate_point = current_point.moved_left(1);
- if (flood_mask.get(candidate_point.x(), candidate_point.y()) == 0 && meets_wand_threshold(candidate_point, bitmap, target_color, threshold_normalized_squared)) {
- points_to_visit.enqueue(candidate_point);
- selection_mask.set(candidate_point.x(), candidate_point.y(), 0xFF);
- }
- flood_mask.set(candidate_point.x(), candidate_point.y(), 0xFF);
- }
-
- if (current_point.x() < bitmap.width() - 1) {
- candidate_point = current_point.moved_right(1);
- if (flood_mask.get(candidate_point.x(), candidate_point.y()) == 0 && meets_wand_threshold(candidate_point, bitmap, target_color, threshold_normalized_squared)) {
- points_to_visit.enqueue(candidate_point);
- selection_mask.set(candidate_point.x(), candidate_point.y(), 0xFF);
- }
- flood_mask.set(candidate_point.x(), candidate_point.y(), 0xFF);
- }
-
- if (current_point.y() > 0) {
- candidate_point = current_point.moved_up(1);
- if (flood_mask.get(candidate_point.x(), candidate_point.y()) == 0 && meets_wand_threshold(candidate_point, bitmap, target_color, threshold_normalized_squared)) {
- points_to_visit.enqueue(candidate_point);
- selection_mask.set(candidate_point.x(), candidate_point.y(), 0xFF);
- }
- flood_mask.set(candidate_point.x(), candidate_point.y(), 0xFF);
- }
-
- if (current_point.y() < bitmap.height() - 1) {
- candidate_point = current_point.moved_down(1);
+ auto candidate_points = Array {
+ current_point.moved_left(1),
+ current_point.moved_right(1),
+ current_point.moved_up(1),
+ current_point.moved_down(1)
+ };
+ for (auto candidate_point : candidate_points) {
+ if (!bitmap.rect().contains(candidate_point))
+ continue;
if (flood_mask.get(candidate_point.x(), candidate_point.y()) == 0 && meets_wand_threshold(candidate_point, bitmap, target_color, threshold_normalized_squared)) {
points_to_visit.enqueue(candidate_point);
selection_mask.set(candidate_point.x(), candidate_point.y(), 0xFF);