mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 18:20:43 +09:00
PixelPaint: Change repeated code into a loop for Wand Select Tool
This commit is contained in:
parent
a0ef00cab2
commit
f2da577e77
Notes:
sideshowbarker
2024-07-17 07:35:19 +09:00
Author: https://github.com/tslater2006
Commit: f2da577e77
Pull-request: https://github.com/SerenityOS/serenity/pull/15088
Reviewed-by: https://github.com/linusg
1 changed files with 9 additions and 31 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue