summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorMacDue <macdue@dueutil.tech>2022-06-28 11:17:12 +0100
committerAndreas Kling <kling@serenityos.org>2022-06-30 11:16:22 +0200
commitcb010fd1f8576a6c04dcffc602d31bf5a057e9df (patch)
tree1b9e3a43950bc00adcf398b7d638d7c6bcfd56e6 /Userland
parenteb3bbb1ddf0ea2a94afaf74c0a7f7faa149596c3 (diff)
downloadserenity-cb010fd1f8576a6c04dcffc602d31bf5a057e9df.zip
LibWeb+LibGfx: Fix 'halo' effect around the fringes of shadows
This now allows passing a 'fill_color' to the blur, any fully transparent pixels will be replaced with this color (with the alpha set to 0). For box-shadows, if this color is set to the same as the shadow, the issues around the fringes are fixed. This also fixes some places where dark shadows appeared light / the wrong color.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibGfx/Filters/StackBlurFilter.cpp10
-rw-r--r--Userland/Libraries/LibGfx/Filters/StackBlurFilter.h2
-rw-r--r--Userland/Libraries/LibWeb/Painting/ShadowPainting.cpp4
3 files changed, 8 insertions, 8 deletions
diff --git a/Userland/Libraries/LibGfx/Filters/StackBlurFilter.cpp b/Userland/Libraries/LibGfx/Filters/StackBlurFilter.cpp
index 785b9dc134..c7ff7885cd 100644
--- a/Userland/Libraries/LibGfx/Filters/StackBlurFilter.cpp
+++ b/Userland/Libraries/LibGfx/Filters/StackBlurFilter.cpp
@@ -96,14 +96,14 @@ private:
// This is an implementation of StackBlur by Mario Klingemann (https://observablehq.com/@jobleonard/mario-klingemans-stackblur)
// (Link is to a secondary source as the original site is now down)
-FLATTEN void StackBlurFilter::process_rgba(u8 radius)
+FLATTEN void StackBlurFilter::process_rgba(u8 radius, Color fill_color)
{
// TODO: Implement a plain RGB version of this (if required)
if (radius == 0)
return;
- constexpr auto transparent_white = Color(Color::White).with_alpha(0);
+ fill_color = fill_color.with_alpha(0);
uint width = m_bitmap.width();
uint height = m_bitmap.height();
@@ -115,7 +115,7 @@ FLATTEN void StackBlurFilter::process_rgba(u8 radius)
auto get_pixel = [&](int x, int y) {
auto color = m_bitmap.get_pixel<StorageFormat::BGRA8888>(x, y);
if (color.alpha() == 0)
- return transparent_white;
+ return fill_color;
return color;
};
@@ -179,7 +179,7 @@ FLATTEN void StackBlurFilter::process_rgba(u8 radius)
if (alpha != 0)
set_pixel(x, y, Color((red_sum * sum_mult) >> sum_shift, (green_sum * sum_mult) >> sum_shift, (blue_sum * sum_mult) >> sum_shift, alpha));
else
- set_pixel(x, y, transparent_white);
+ set_pixel(x, y, fill_color);
red_sum -= red_out_sum;
green_sum -= green_out_sum;
@@ -266,7 +266,7 @@ FLATTEN void StackBlurFilter::process_rgba(u8 radius)
if (alpha != 0)
set_pixel(x, y, Color((red_sum * sum_mult) >> sum_shift, (green_sum * sum_mult) >> sum_shift, (blue_sum * sum_mult) >> sum_shift, alpha));
else
- set_pixel(x, y, transparent_white);
+ set_pixel(x, y, fill_color);
red_sum -= red_out_sum;
green_sum -= green_out_sum;
diff --git a/Userland/Libraries/LibGfx/Filters/StackBlurFilter.h b/Userland/Libraries/LibGfx/Filters/StackBlurFilter.h
index 12381d3809..d6cedbbb1c 100644
--- a/Userland/Libraries/LibGfx/Filters/StackBlurFilter.h
+++ b/Userland/Libraries/LibGfx/Filters/StackBlurFilter.h
@@ -18,7 +18,7 @@ public:
}
// Note: The radius is a u8 for reason! This implementation can only handle radii from 0 to 255.
- void process_rgba(u8 radius);
+ void process_rgba(u8 radius, Color fill_color = Color::NamedColor::White);
private:
Bitmap& m_bitmap;
diff --git a/Userland/Libraries/LibWeb/Painting/ShadowPainting.cpp b/Userland/Libraries/LibWeb/Painting/ShadowPainting.cpp
index b4bc87d257..ad3b91f07b 100644
--- a/Userland/Libraries/LibWeb/Painting/ShadowPainting.cpp
+++ b/Userland/Libraries/LibWeb/Painting/ShadowPainting.cpp
@@ -147,7 +147,7 @@ void paint_box_shadow(PaintContext& context, Gfx::IntRect const& content_rect, B
aa_corner_painter.fill_rect_with_rounded_corners(shadow_bitmap_rect.shrunken(double_radius, double_radius, double_radius, double_radius), box_shadow_data.color, top_left_shadow_corner, top_right_shadow_corner, bottom_right_shadow_corner, bottom_left_shadow_corner);
Gfx::StackBlurFilter filter(*shadow_bitmap);
- filter.process_rgba(box_shadow_data.blur_radius);
+ filter.process_rgba(box_shadow_data.blur_radius, box_shadow_data.color);
auto paint_shadow_infill = [&] {
if (!border_radii.has_any_radius())
@@ -342,7 +342,7 @@ void paint_text_shadow(PaintContext& context, Layout::LineBoxFragment const& fra
// Blur
Gfx::StackBlurFilter filter(*shadow_bitmap);
- filter.process_rgba(layer.blur_radius);
+ filter.process_rgba(layer.blur_radius, layer.color);
auto draw_rect = Gfx::enclosing_int_rect(fragment.absolute_rect());
Gfx::IntPoint draw_location {