diff options
author | Torstennator <engelTorsten@gmx.de> | 2022-10-09 20:12:23 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-11-07 20:58:02 +0000 |
commit | a66dbef1ed7c4159207e0f28fa85d5f305f08582 (patch) | |
tree | 41afe456d96635fca1899d9bab5ca0d082a9511d | |
parent | e520b9c3a388e7703dc7ae4ca72290f71398a1fb (diff) | |
download | serenity-a66dbef1ed7c4159207e0f28fa85d5f305f08582.zip |
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.
-rw-r--r-- | Userland/Applications/PixelPaint/Tools/BrushTool.cpp | 10 |
1 files 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)); } } |