summaryrefslogtreecommitdiff
path: root/Userland/Applications/PixelPaint
diff options
context:
space:
mode:
authorXavier Defrang <xavier.defrang@gmail.com>2022-01-08 10:36:04 +0100
committerAndreas Kling <kling@serenityos.org>2022-01-08 12:31:11 +0100
commitb1a15b02f11c8f192493a238ac43673e4f09be3d (patch)
tree6dbf811a5f421fb4bdf184013a7c4f723d5746b3 /Userland/Applications/PixelPaint
parent2502a88e49a886458366145e99d8ac3d0ab0293c (diff)
downloadserenity-b1a15b02f11c8f192493a238ac43673e4f09be3d.zip
PixelPaint+LibGfx: Add sepia color filter
Diffstat (limited to 'Userland/Applications/PixelPaint')
-rw-r--r--Userland/Applications/PixelPaint/CMakeLists.txt1
-rw-r--r--Userland/Applications/PixelPaint/FilterModel.cpp2
-rw-r--r--Userland/Applications/PixelPaint/FilterParams.h1
-rw-r--r--Userland/Applications/PixelPaint/Filters/Sepia.cpp57
-rw-r--r--Userland/Applications/PixelPaint/Filters/Sepia.h27
5 files changed, 88 insertions, 0 deletions
diff --git a/Userland/Applications/PixelPaint/CMakeLists.txt b/Userland/Applications/PixelPaint/CMakeLists.txt
index f9f53a2d24..8919cc3695 100644
--- a/Userland/Applications/PixelPaint/CMakeLists.txt
+++ b/Userland/Applications/PixelPaint/CMakeLists.txt
@@ -28,6 +28,7 @@ set(SOURCES
Filters/Invert.cpp
Filters/LaplaceCardinal.cpp
Filters/LaplaceDiagonal.cpp
+ Filters/Sepia.cpp
Filters/Sharpen.cpp
Image.cpp
ImageEditor.cpp
diff --git a/Userland/Applications/PixelPaint/FilterModel.cpp b/Userland/Applications/PixelPaint/FilterModel.cpp
index a41883e488..025be5b23b 100644
--- a/Userland/Applications/PixelPaint/FilterModel.cpp
+++ b/Userland/Applications/PixelPaint/FilterModel.cpp
@@ -17,6 +17,7 @@
#include "Filters/Invert.h"
#include "Filters/LaplaceCardinal.h"
#include "Filters/LaplaceDiagonal.h"
+#include "Filters/Sepia.h"
#include "Filters/Sharpen.h"
#include "Layer.h"
#include <LibGUI/FileIconProvider.h>
@@ -48,6 +49,7 @@ FilterModel::FilterModel(ImageEditor* editor)
auto color_category = FilterInfo::create_category("Color");
auto grayscale_filter = FilterInfo::create_filter<Filters::Grayscale>(editor, color_category);
auto invert_filter = FilterInfo::create_filter<Filters::Invert>(editor, color_category);
+ auto sepia_filter = FilterInfo::create_filter<Filters::Sepia>(editor, color_category);
m_filters.append(color_category);
diff --git a/Userland/Applications/PixelPaint/FilterParams.h b/Userland/Applications/PixelPaint/FilterParams.h
index 6f97466828..189e11a19b 100644
--- a/Userland/Applications/PixelPaint/FilterParams.h
+++ b/Userland/Applications/PixelPaint/FilterParams.h
@@ -19,6 +19,7 @@
#include <LibGfx/Filters/GrayscaleFilter.h>
#include <LibGfx/Filters/InvertFilter.h>
#include <LibGfx/Filters/LaplacianFilter.h>
+#include <LibGfx/Filters/SepiaFilter.h>
#include <LibGfx/Filters/SharpenFilter.h>
#include <LibGfx/Filters/SpatialGaussianBlurFilter.h>
diff --git a/Userland/Applications/PixelPaint/Filters/Sepia.cpp b/Userland/Applications/PixelPaint/Filters/Sepia.cpp
new file mode 100644
index 0000000000..ba86e6a75e
--- /dev/null
+++ b/Userland/Applications/PixelPaint/Filters/Sepia.cpp
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2022, Xavier Defrang <xavier.defrang@gmail.com>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include "Sepia.h"
+#include "../FilterParams.h"
+#include <LibGUI/Label.h>
+#include <LibGUI/ValueSlider.h>
+
+namespace PixelPaint::Filters {
+
+void Sepia::apply() const
+{
+ if (!m_editor)
+ return;
+ if (auto* layer = m_editor->active_layer()) {
+ Gfx::SepiaFilter filter(m_amount);
+ filter.apply(layer->bitmap(), layer->rect(), layer->bitmap(), layer->rect());
+ layer->did_modify_bitmap(layer->rect());
+ m_editor->did_complete_action();
+ }
+}
+
+RefPtr<GUI::Widget> Sepia::get_settings_widget()
+{
+ if (!m_settings_widget) {
+ m_settings_widget = GUI::Widget::construct();
+ m_settings_widget->set_layout<GUI::VerticalBoxLayout>();
+
+ auto& name_label = m_settings_widget->add<GUI::Label>("Sepia Filter");
+ name_label.set_font_weight(Gfx::FontWeight::Bold);
+ name_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
+ name_label.set_fixed_height(20);
+
+ auto& amount_container = m_settings_widget->add<GUI::Widget>();
+ amount_container.set_fixed_height(20);
+ amount_container.set_layout<GUI::HorizontalBoxLayout>();
+ amount_container.layout()->set_margins({ 4, 0, 4, 0 });
+
+ auto& amount_label = amount_container.add<GUI::Label>("Amount:");
+ amount_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
+ amount_label.set_fixed_size(50, 20);
+
+ auto& amount_slider = amount_container.add<GUI::ValueSlider>(Orientation::Horizontal, "%");
+ amount_slider.set_range(0, 100);
+ amount_slider.set_value(m_amount * 100);
+ amount_slider.on_change = [&](int value) {
+ m_amount = value * 0.01f;
+ };
+ }
+
+ return m_settings_widget;
+}
+
+}
diff --git a/Userland/Applications/PixelPaint/Filters/Sepia.h b/Userland/Applications/PixelPaint/Filters/Sepia.h
new file mode 100644
index 0000000000..a8d1a8a788
--- /dev/null
+++ b/Userland/Applications/PixelPaint/Filters/Sepia.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2022, Xavier Defrang <xavier.defrang@gmail.com>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include "Filter.h"
+
+namespace PixelPaint::Filters {
+
+class Sepia final : public Filter {
+public:
+ virtual void apply() const override;
+ virtual RefPtr<GUI::Widget> get_settings_widget() override;
+
+ virtual StringView filter_name() override { return "Sepia"sv; }
+
+ Sepia(ImageEditor* editor)
+ : Filter(editor) {};
+
+private:
+ float m_amount { 1.0f };
+};
+
+}