diff options
author | Tobias Christiansen <tobyase@serenityos.org> | 2022-01-02 16:56:21 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-01-04 14:40:00 +0100 |
commit | 0deadcdb28190540f04bf96f51c73e2c1cb1ebe1 (patch) | |
tree | 6eb76ebcb5850403f8e09e92cf6b68af05421b9b /Userland | |
parent | 5cf0357be16f417389303cc3e89892304dc747d6 (diff) | |
download | serenity-0deadcdb28190540f04bf96f51c73e2c1cb1ebe1.zip |
PixelPaint: Create wrappers for all supported filters
Diffstat (limited to 'Userland')
20 files changed, 438 insertions, 1 deletions
diff --git a/Userland/Applications/PixelPaint/CMakeLists.txt b/Userland/Applications/PixelPaint/CMakeLists.txt index 7b8d44a299..20ee0bd774 100644 --- a/Userland/Applications/PixelPaint/CMakeLists.txt +++ b/Userland/Applications/PixelPaint/CMakeLists.txt @@ -17,7 +17,16 @@ set(SOURCES FilterGallery.cpp FilterGalleryGML.h FilterModel.cpp + Filters/BoxBlur3.cpp + Filters/BoxBlur5.cpp Filters/Filter.cpp + Filters/GaussBlur3.cpp + Filters/GaussBlur5.cpp + Filters/Grayscale.cpp + Filters/Invert.cpp + Filters/LaplaceCardinal.cpp + Filters/LaplaceDiagonal.cpp + Filters/Sharpen.cpp Image.cpp ImageEditor.cpp Layer.cpp diff --git a/Userland/Applications/PixelPaint/Filters/BoxBlur3.cpp b/Userland/Applications/PixelPaint/Filters/BoxBlur3.cpp new file mode 100644 index 0000000000..51aa454110 --- /dev/null +++ b/Userland/Applications/PixelPaint/Filters/BoxBlur3.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "BoxBlur3.h" +#include "../FilterParams.h" + +namespace PixelPaint::Filters { + +void BoxBlur3::apply() const +{ + if (!m_editor) + return; + if (auto* layer = m_editor->active_layer()) { + Gfx::BoxBlurFilter<3> filter; + if (auto parameters = PixelPaint::FilterParameters<Gfx::BoxBlurFilter<3>>::get()) { + filter.apply(layer->bitmap(), layer->rect(), layer->bitmap(), layer->rect(), *parameters); + layer->did_modify_bitmap(layer->rect()); + m_editor->did_complete_action(); + } + } +} + +} diff --git a/Userland/Applications/PixelPaint/Filters/BoxBlur3.h b/Userland/Applications/PixelPaint/Filters/BoxBlur3.h new file mode 100644 index 0000000000..1038a6307c --- /dev/null +++ b/Userland/Applications/PixelPaint/Filters/BoxBlur3.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include "Filter.h" + +namespace PixelPaint::Filters { + +class BoxBlur3 final : public Filter { +public: + virtual void apply() const override; + virtual StringView filter_name() override { return "Box Blur (3x3)"sv; } + + BoxBlur3(ImageEditor* editor) + : Filter(editor) {}; +}; + +} diff --git a/Userland/Applications/PixelPaint/Filters/BoxBlur5.cpp b/Userland/Applications/PixelPaint/Filters/BoxBlur5.cpp new file mode 100644 index 0000000000..e757925cd3 --- /dev/null +++ b/Userland/Applications/PixelPaint/Filters/BoxBlur5.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "BoxBlur5.h" +#include "../FilterParams.h" + +namespace PixelPaint::Filters { + +void BoxBlur5::apply() const +{ + if (!m_editor) + return; + if (auto* layer = m_editor->active_layer()) { + Gfx::BoxBlurFilter<5> filter; + if (auto parameters = PixelPaint::FilterParameters<Gfx::BoxBlurFilter<5>>::get()) { + filter.apply(layer->bitmap(), layer->rect(), layer->bitmap(), layer->rect(), *parameters); + layer->did_modify_bitmap(layer->rect()); + m_editor->did_complete_action(); + } + } +} + +} diff --git a/Userland/Applications/PixelPaint/Filters/BoxBlur5.h b/Userland/Applications/PixelPaint/Filters/BoxBlur5.h new file mode 100644 index 0000000000..f34acdc4f0 --- /dev/null +++ b/Userland/Applications/PixelPaint/Filters/BoxBlur5.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include "Filter.h" + +namespace PixelPaint::Filters { + +class BoxBlur5 final : public Filter { +public: + virtual void apply() const override; + virtual StringView filter_name() override { return "Box Blur (5x5)"sv; } + + BoxBlur5(ImageEditor* editor) + : Filter(editor) {}; +}; + +} diff --git a/Userland/Applications/PixelPaint/Filters/Filter.h b/Userland/Applications/PixelPaint/Filters/Filter.h index 2b03da994e..4add775e68 100644 --- a/Userland/Applications/PixelPaint/Filters/Filter.h +++ b/Userland/Applications/PixelPaint/Filters/Filter.h @@ -26,7 +26,6 @@ public: protected: ImageEditor* m_editor { nullptr }; - StringView m_filter_name; RefPtr<GUI::Widget> m_settings_widget { nullptr }; }; diff --git a/Userland/Applications/PixelPaint/Filters/GaussBlur3.cpp b/Userland/Applications/PixelPaint/Filters/GaussBlur3.cpp new file mode 100644 index 0000000000..5987da3870 --- /dev/null +++ b/Userland/Applications/PixelPaint/Filters/GaussBlur3.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "GaussBlur3.h" +#include "../FilterParams.h" + +namespace PixelPaint::Filters { + +void GaussBlur3::apply() const +{ + if (!m_editor) + return; + if (auto* layer = m_editor->active_layer()) { + Gfx::SpatialGaussianBlurFilter<3> filter; + if (auto parameters = PixelPaint::FilterParameters<Gfx::SpatialGaussianBlurFilter<3>>::get()) { + filter.apply(layer->bitmap(), layer->rect(), layer->bitmap(), layer->rect(), *parameters); + layer->did_modify_bitmap(layer->rect()); + m_editor->did_complete_action(); + } + } +} + +} diff --git a/Userland/Applications/PixelPaint/Filters/GaussBlur3.h b/Userland/Applications/PixelPaint/Filters/GaussBlur3.h new file mode 100644 index 0000000000..d62462b42b --- /dev/null +++ b/Userland/Applications/PixelPaint/Filters/GaussBlur3.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include "Filter.h" + +namespace PixelPaint::Filters { + +// FIXME: Make a generic gaussian blur that does not need the templated radius +class GaussBlur3 final : public Filter { +public: + virtual void apply() const override; + virtual StringView filter_name() override { return "Gaussian Blur (3x3)"sv; } + + GaussBlur3(ImageEditor* editor) + : Filter(editor) {}; +}; + +} diff --git a/Userland/Applications/PixelPaint/Filters/GaussBlur5.cpp b/Userland/Applications/PixelPaint/Filters/GaussBlur5.cpp new file mode 100644 index 0000000000..aac6614eae --- /dev/null +++ b/Userland/Applications/PixelPaint/Filters/GaussBlur5.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "GaussBlur5.h" +#include "../FilterParams.h" + +namespace PixelPaint::Filters { + +void GaussBlur5::apply() const +{ + if (!m_editor) + return; + if (auto* layer = m_editor->active_layer()) { + Gfx::SpatialGaussianBlurFilter<5> filter; + if (auto parameters = PixelPaint::FilterParameters<Gfx::SpatialGaussianBlurFilter<5>>::get()) { + filter.apply(layer->bitmap(), layer->rect(), layer->bitmap(), layer->rect(), *parameters); + layer->did_modify_bitmap(layer->rect()); + m_editor->did_complete_action(); + } + } +} + +} diff --git a/Userland/Applications/PixelPaint/Filters/GaussBlur5.h b/Userland/Applications/PixelPaint/Filters/GaussBlur5.h new file mode 100644 index 0000000000..d30e8845b3 --- /dev/null +++ b/Userland/Applications/PixelPaint/Filters/GaussBlur5.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include "Filter.h" + +namespace PixelPaint::Filters { + +class GaussBlur5 final : public Filter { +public: + virtual void apply() const override; + virtual StringView filter_name() override { return "Gaussian Blur (5x5)"sv; } + + GaussBlur5(ImageEditor* editor) + : Filter(editor) {}; +}; + +} diff --git a/Userland/Applications/PixelPaint/Filters/Grayscale.cpp b/Userland/Applications/PixelPaint/Filters/Grayscale.cpp new file mode 100644 index 0000000000..a7f87d5498 --- /dev/null +++ b/Userland/Applications/PixelPaint/Filters/Grayscale.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "Grayscale.h" +#include "../FilterParams.h" + +namespace PixelPaint::Filters { + +void Grayscale::apply() const +{ + if (!m_editor) + return; + if (auto* layer = m_editor->active_layer()) { + Gfx::GrayscaleFilter filter; + filter.apply(layer->bitmap(), layer->rect(), layer->bitmap(), layer->rect()); + layer->did_modify_bitmap(layer->rect()); + m_editor->did_complete_action(); + } +} + +} diff --git a/Userland/Applications/PixelPaint/Filters/Grayscale.h b/Userland/Applications/PixelPaint/Filters/Grayscale.h new file mode 100644 index 0000000000..873bec04c7 --- /dev/null +++ b/Userland/Applications/PixelPaint/Filters/Grayscale.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include "Filter.h" + +namespace PixelPaint::Filters { + +class Grayscale final : public Filter { +public: + virtual void apply() const override; + virtual StringView filter_name() override { return "Grayscale"sv; } + + Grayscale(ImageEditor* editor) + : Filter(editor) {}; +}; + +} diff --git a/Userland/Applications/PixelPaint/Filters/Invert.cpp b/Userland/Applications/PixelPaint/Filters/Invert.cpp new file mode 100644 index 0000000000..c9db6b7db3 --- /dev/null +++ b/Userland/Applications/PixelPaint/Filters/Invert.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "Invert.h" +#include "../FilterParams.h" + +namespace PixelPaint::Filters { + +void Invert::apply() const +{ + if (!m_editor) + return; + if (auto* layer = m_editor->active_layer()) { + Gfx::InvertFilter filter; + filter.apply(layer->bitmap(), layer->rect(), layer->bitmap(), layer->rect()); + layer->did_modify_bitmap(layer->rect()); + m_editor->did_complete_action(); + } +} + +} diff --git a/Userland/Applications/PixelPaint/Filters/Invert.h b/Userland/Applications/PixelPaint/Filters/Invert.h new file mode 100644 index 0000000000..3adc7b9fe3 --- /dev/null +++ b/Userland/Applications/PixelPaint/Filters/Invert.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include "Filter.h" + +namespace PixelPaint::Filters { + +class Invert final : public Filter { +public: + virtual void apply() const override; + virtual StringView filter_name() override { return "Invert"sv; } + + Invert(ImageEditor* editor) + : Filter(editor) {}; +}; + +} diff --git a/Userland/Applications/PixelPaint/Filters/LaplaceCardinal.cpp b/Userland/Applications/PixelPaint/Filters/LaplaceCardinal.cpp new file mode 100644 index 0000000000..15ae82fb07 --- /dev/null +++ b/Userland/Applications/PixelPaint/Filters/LaplaceCardinal.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "LaplaceCardinal.h" +#include "../FilterParams.h" + +namespace PixelPaint::Filters { + +void LaplaceCardinal::apply() const +{ + if (!m_editor) + return; + if (auto* layer = m_editor->active_layer()) { + Gfx::LaplacianFilter filter; + if (auto parameters = PixelPaint::FilterParameters<Gfx::LaplacianFilter>::get(false)) { + filter.apply(layer->bitmap(), layer->rect(), layer->bitmap(), layer->rect(), *parameters); + layer->did_modify_bitmap(layer->rect()); + m_editor->did_complete_action(); + } + } +} + +} diff --git a/Userland/Applications/PixelPaint/Filters/LaplaceCardinal.h b/Userland/Applications/PixelPaint/Filters/LaplaceCardinal.h new file mode 100644 index 0000000000..a66861e807 --- /dev/null +++ b/Userland/Applications/PixelPaint/Filters/LaplaceCardinal.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include "Filter.h" + +namespace PixelPaint::Filters { + +class LaplaceCardinal final : public Filter { +public: + virtual void apply() const override; + virtual StringView filter_name() override { return "Laplacian Cardinal"sv; } + + LaplaceCardinal(ImageEditor* editor) + : Filter(editor) {}; +}; + +} diff --git a/Userland/Applications/PixelPaint/Filters/LaplaceDiagonal.cpp b/Userland/Applications/PixelPaint/Filters/LaplaceDiagonal.cpp new file mode 100644 index 0000000000..01d4cfd5b3 --- /dev/null +++ b/Userland/Applications/PixelPaint/Filters/LaplaceDiagonal.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "LaplaceDiagonal.h" +#include "../FilterParams.h" + +namespace PixelPaint::Filters { + +void LaplaceDiagonal::apply() const +{ + if (!m_editor) + return; + if (auto* layer = m_editor->active_layer()) { + Gfx::LaplacianFilter filter; + if (auto parameters = PixelPaint::FilterParameters<Gfx::LaplacianFilter>::get(true)) { + filter.apply(layer->bitmap(), layer->rect(), layer->bitmap(), layer->rect(), *parameters); + layer->did_modify_bitmap(layer->rect()); + m_editor->did_complete_action(); + } + } +} + +} diff --git a/Userland/Applications/PixelPaint/Filters/LaplaceDiagonal.h b/Userland/Applications/PixelPaint/Filters/LaplaceDiagonal.h new file mode 100644 index 0000000000..c388a52d36 --- /dev/null +++ b/Userland/Applications/PixelPaint/Filters/LaplaceDiagonal.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include "Filter.h" + +namespace PixelPaint::Filters { + +class LaplaceDiagonal final : public Filter { +public: + virtual void apply() const override; + virtual StringView filter_name() override { return "Laplacian Diagonal"sv; } + + LaplaceDiagonal(ImageEditor* editor) + : Filter(editor) {}; +}; + +} diff --git a/Userland/Applications/PixelPaint/Filters/Sharpen.cpp b/Userland/Applications/PixelPaint/Filters/Sharpen.cpp new file mode 100644 index 0000000000..4a772beb75 --- /dev/null +++ b/Userland/Applications/PixelPaint/Filters/Sharpen.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "Sharpen.h" +#include "../FilterParams.h" + +namespace PixelPaint::Filters { + +void Sharpen::apply() const +{ + if (!m_editor) + return; + if (auto* layer = m_editor->active_layer()) { + Gfx::SharpenFilter filter; + if (auto parameters = PixelPaint::FilterParameters<Gfx::SharpenFilter>::get()) { + filter.apply(layer->bitmap(), layer->rect(), layer->bitmap(), layer->rect(), *parameters); + layer->did_modify_bitmap(layer->rect()); + m_editor->did_complete_action(); + } + } +} + +} diff --git a/Userland/Applications/PixelPaint/Filters/Sharpen.h b/Userland/Applications/PixelPaint/Filters/Sharpen.h new file mode 100644 index 0000000000..76594340be --- /dev/null +++ b/Userland/Applications/PixelPaint/Filters/Sharpen.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022, Tobias Christiansen <tobyase@serenityos.org> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include "Filter.h" + +namespace PixelPaint::Filters { + +class Sharpen final : public Filter { +public: + virtual void apply() const override; + virtual StringView filter_name() override { return "Sharpen"sv; } + + Sharpen(ImageEditor* editor) + : Filter(editor) {}; +}; + +} |