diff options
-rw-r--r-- | Userland/Libraries/LibGfx/Filters/ColorFilter.h | 15 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/Filters/GrayscaleFilter.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/Filters/InvertFilter.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/Filters/SepiaFilter.h | 13 |
4 files changed, 20 insertions, 12 deletions
diff --git a/Userland/Libraries/LibGfx/Filters/ColorFilter.h b/Userland/Libraries/LibGfx/Filters/ColorFilter.h index 248eb8113c..9a5623fb45 100644 --- a/Userland/Libraries/LibGfx/Filters/ColorFilter.h +++ b/Userland/Libraries/LibGfx/Filters/ColorFilter.h @@ -12,8 +12,18 @@ namespace Gfx { class ColorFilter : public Filter { public: + ColorFilter(float amount = 1.0f) + : m_amount(amount) + { + } + virtual ~ColorFilter() = default; + virtual bool amount_handled_in_filter() const + { + return false; + } + virtual void apply(Bitmap& target_bitmap, IntRect const& target_rect, Bitmap const& source_bitmap, IntRect const& source_rect) override { VERIFY(source_rect.size() == target_rect.size()); @@ -30,15 +40,14 @@ public: auto source_pixel = source_bitmap.get_pixel(source_x, source_y); auto target_color = convert_color(source_pixel); - target_bitmap.set_pixel(target_x, target_y, target_color); + target_bitmap.set_pixel(target_x, target_y, m_amount < 1.0f && !amount_handled_in_filter() ? source_pixel.mixed_with(target_color, m_amount) : target_color); } } } protected: - ColorFilter() = default; - virtual Color convert_color(Color) = 0; + float m_amount { 1.0f }; }; } diff --git a/Userland/Libraries/LibGfx/Filters/GrayscaleFilter.h b/Userland/Libraries/LibGfx/Filters/GrayscaleFilter.h index 59c32f04f3..64050b2578 100644 --- a/Userland/Libraries/LibGfx/Filters/GrayscaleFilter.h +++ b/Userland/Libraries/LibGfx/Filters/GrayscaleFilter.h @@ -13,7 +13,7 @@ namespace Gfx { class GrayscaleFilter : public ColorFilter { public: - GrayscaleFilter() = default; + using ColorFilter::ColorFilter; virtual ~GrayscaleFilter() = default; virtual StringView class_name() const override { return "GrayscaleFilter"sv; } diff --git a/Userland/Libraries/LibGfx/Filters/InvertFilter.h b/Userland/Libraries/LibGfx/Filters/InvertFilter.h index d0b2251bb7..991070fac7 100644 --- a/Userland/Libraries/LibGfx/Filters/InvertFilter.h +++ b/Userland/Libraries/LibGfx/Filters/InvertFilter.h @@ -13,7 +13,7 @@ namespace Gfx { class InvertFilter : public ColorFilter { public: - InvertFilter() = default; + using ColorFilter::ColorFilter; virtual ~InvertFilter() = default; virtual StringView class_name() const override { return "InvertFilter"sv; } diff --git a/Userland/Libraries/LibGfx/Filters/SepiaFilter.h b/Userland/Libraries/LibGfx/Filters/SepiaFilter.h index 9b94a9e8e0..86ca152cd0 100644 --- a/Userland/Libraries/LibGfx/Filters/SepiaFilter.h +++ b/Userland/Libraries/LibGfx/Filters/SepiaFilter.h @@ -15,19 +15,18 @@ namespace Gfx { class SepiaFilter : public ColorFilter { public: - SepiaFilter(float amount = 1.0f) - : m_amount(amount) - { - } + using ColorFilter::ColorFilter; virtual ~SepiaFilter() = default; virtual StringView class_name() const override { return "SepiaFilter"sv; } + virtual bool amount_handled_in_filter() const override + { + return true; + } + protected: Color convert_color(Color original) override { return original.sepia(m_amount); }; - -private: - float m_amount; }; } |