From a66dbef1ed7c4159207e0f28fa85d5f305f08582 Mon Sep 17 00:00:00 2001 From: Torstennator Date: Sun, 9 Oct 2022 20:12:23 +0200 Subject: [PATCH] PixelPaint: Improve brushtool gradient for low hardness This patch mitigates a rough gradient for the brush tool with a low hardness. Previously the gradient alpha value was truncated by the type conversion to int. Now the desired alpha value is scaled up to mitigate the information loss due to type conversion which results in a much smoother gradient. --- Userland/Applications/PixelPaint/Tools/BrushTool.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Userland/Applications/PixelPaint/Tools/BrushTool.cpp b/Userland/Applications/PixelPaint/Tools/BrushTool.cpp index a784bdd12e..3873b97ecf 100644 --- a/Userland/Applications/PixelPaint/Tools/BrushTool.cpp +++ b/Userland/Applications/PixelPaint/Tools/BrushTool.cpp @@ -46,10 +46,7 @@ void BrushTool::on_mousedown(Layer* layer, MouseEvent& event) return; } - int const first_draw_opacity = 10; - - for (int i = 0; i < first_draw_opacity; ++i) - draw_point(layer->get_scratch_edited_bitmap(), color_for(layer_event), layer_event.position()); + draw_point(layer->get_scratch_edited_bitmap(), color_for(layer_event), layer_event.position()); layer->did_modify_bitmap(Gfx::IntRect::centered_on(layer_event.position(), Gfx::IntSize { m_size * 2, m_size * 2 })); m_last_position = layer_event.position(); @@ -89,6 +86,7 @@ Color BrushTool::color_for(GUI::MouseEvent const& event) void BrushTool::draw_point(Gfx::Bitmap& bitmap, Gfx::Color const& color, Gfx::IntPoint const& point) { + constexpr auto flow_scale = 10; for (int y = point.y() - size(); y < point.y() + size(); y++) { for (int x = point.x() - size(); x < point.x() + size(); x++) { auto distance = point.distance_from({ x, y }); @@ -97,9 +95,9 @@ void BrushTool::draw_point(Gfx::Bitmap& bitmap, Gfx::Color const& color, Gfx::In if (distance >= size()) continue; - auto falloff = get_falloff(distance); + auto falloff = get_falloff(distance) * flow_scale; auto pixel_color = color; - pixel_color.set_alpha(falloff * 255); + pixel_color.set_alpha(AK::min(falloff * 255, 255)); bitmap.set_pixel(x, y, bitmap.get_pixel(x, y).blend(pixel_color)); } }