From 0506f4eef89c3679698ed11f8d4af4b9a3a36ba9 Mon Sep 17 00:00:00 2001 From: Timothy Slater Date: Sat, 27 Aug 2022 07:50:37 -0500 Subject: [PATCH] PixelPaint: Account for alpha in color distance calculation This fixes an issue where BucketTool would consider "black" and "transparent" the same color. --- Userland/Applications/PixelPaint/Tools/BucketTool.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Userland/Applications/PixelPaint/Tools/BucketTool.cpp b/Userland/Applications/PixelPaint/Tools/BucketTool.cpp index 58255f3f5d..9c04c972e9 100644 --- a/Userland/Applications/PixelPaint/Tools/BucketTool.cpp +++ b/Userland/Applications/PixelPaint/Tools/BucketTool.cpp @@ -2,6 +2,7 @@ * Copyright (c) 2018-2020, Andreas Kling * Copyright (c) 2022, Aaron Yoder * Copyright (c) 2022, the SerenityOS developers. + * Copyright (c) 2022, Timothy Slater . * * SPDX-License-Identifier: BSD-2-Clause */ @@ -30,7 +31,8 @@ static float color_distance_squared(Gfx::Color const& lhs, Gfx::Color const& rhs int a = rhs.red() - lhs.red(); int b = rhs.green() - lhs.green(); int c = rhs.blue() - lhs.blue(); - return (a * a + b * b + c * c) / (3.0f * 255.0f * 255.0f); + int d = rhs.alpha() - lhs.alpha(); + return (a * a + b * b + c * c + d * d) / (4.0f * 255.0f * 255.0f); } static bool can_paint(int x, int y, Gfx::Bitmap& bitmap, Gfx::Color const& target_color, float threshold_normalized_squared)