From e697a72c995643e45389c79a6283027c767b197d Mon Sep 17 00:00:00 2001 From: MacDue Date: Sat, 1 Oct 2022 22:45:36 +0100 Subject: [PATCH] LibWeb: Support painting the hue-rotate() filter effect --- Userland/Libraries/LibWeb/Painting/FilterPainting.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibWeb/Painting/FilterPainting.cpp b/Userland/Libraries/LibWeb/Painting/FilterPainting.cpp index 639349d433..ef54070962 100644 --- a/Userland/Libraries/LibWeb/Painting/FilterPainting.cpp +++ b/Userland/Libraries/LibWeb/Painting/FilterPainting.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -19,6 +20,9 @@ namespace Web::Painting { void apply_filter_list(Gfx::Bitmap& target_bitmap, Layout::Node const& node, Span filter_list) { + auto apply_color_filter = [&](Gfx::ColorFilter const& filter) { + const_cast(filter).apply(target_bitmap, target_bitmap.rect(), target_bitmap, target_bitmap.rect()); + }; for (auto& filter_function : filter_list) { // See: https://drafts.fxtf.org/filter-effects-1/#supported-filter-functions filter_function.visit( @@ -31,9 +35,6 @@ void apply_filter_list(Gfx::Bitmap& target_bitmap, Layout::Node const& node, Spa [&](CSS::Filter::Color const& color) { auto amount = color.resolved_amount(); auto amount_clamped = clamp(amount, 0.0f, 1.0f); - auto apply_color_filter = [&](Gfx::ColorFilter const& filter) { - const_cast(filter).apply(target_bitmap, target_bitmap.rect(), target_bitmap, target_bitmap.rect()); - }; switch (color.operation) { case CSS::Filter::Color::Operation::Grayscale: { // Converts the input image to grayscale. The passed parameter defines the proportion of the conversion. @@ -80,8 +81,8 @@ void apply_filter_list(Gfx::Bitmap& target_bitmap, Layout::Node const& node, Spa break; } }, - [&](CSS::Filter::HueRotate const&) { - dbgln("TODO: Implement hue-rotate() filter function!"); + [&](CSS::Filter::HueRotate const& hue_rotate) { + apply_color_filter(Gfx::HueRotateFilter { hue_rotate.angle_degrees() }); }, [&](CSS::Filter::DropShadow const&) { dbgln("TODO: Implement drop-shadow() filter function!");