1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 19:27:35 +00:00

PixelPaint: Add color-masking for editing masks

This patch adds the ability to refine a editing mask by a color-range
based on the pixels of the content image. This is useful for image
editing where mask restirction via luminosity might not fit or just
certain color ranges should be edited.
This commit is contained in:
Torstennator 2023-06-23 12:43:59 +02:00 committed by Jelle Raaijmakers
parent df4904f61d
commit 8c681a1603
6 changed files with 520 additions and 84 deletions

View file

@ -10,29 +10,41 @@
#include "Layer.h"
#include <LibGUI/Dialog.h>
#include <LibGUI/RangeSlider.h>
#include <LibGUI/Slider.h>
#include <LibGUI/Widget.h>
namespace PixelPaint {
class ColorWheelWidget;
class ImageMasking final : public GUI::Dialog {
C_OBJECT(ImageMasking);
public:
void revert_possible_changes();
enum class MaskingType {
Luminosity,
Color,
};
protected:
void on_done(GUI::Dialog::ExecResult) override;
private:
ImageMasking(GUI::Window* parent_window, ImageEditor*);
explicit ImageMasking(GUI::Window* parent_window, ImageEditor*, MaskingType masking_type);
MaskingType m_masking_type;
Layer::EditMode m_previous_edit_mode;
ImageEditor* m_editor { nullptr };
RefPtr<Gfx::Bitmap> m_reference_mask { nullptr };
bool m_did_change = false;
RefPtr<GUI::RangeSlider> m_full_masking_slider = { nullptr };
RefPtr<GUI::RangeSlider> m_edge_masking_slider = { nullptr };
RefPtr<ColorWheelWidget> m_color_wheel_widget = { nullptr };
RefPtr<GUI::RangeSlider> m_saturation_value_masking_slider = { nullptr };
ErrorOr<void> ensure_reference_mask();
void generate_new_mask();
void cleanup_resources();
};
class RangeIllustrationWidget final : public GUI::Widget {
@ -53,4 +65,33 @@ private:
RefPtr<GUI::RangeSlider> m_full_mask_values;
};
class ColorWheelWidget final : public GUI::Widget {
C_OBJECT(ColorWheelWidget)
public:
virtual ~ColorWheelWidget() override = default;
double hue();
void set_hue(double);
double color_range();
void set_color_range(double);
int hardness();
void set_hardness(int);
Function<void(double, double, int)> on_change;
protected:
virtual void paint_event(GUI::PaintEvent&) override;
virtual void mousedown_event(GUI::MouseEvent&) override;
virtual void mousemove_event(GUI::MouseEvent&) override;
virtual void mouseup_event(GUI::MouseEvent&) override;
virtual void mousewheel_event(GUI::MouseEvent&) override;
private:
ColorWheelWidget() = default;
double m_hue = 0;
double m_color_range = 0;
int m_hardness = 0;
bool m_mouse_pressed = false;
void calc_hue(Gfx::IntPoint const&);
};
}