PixelPaint: Add InplaceFilter and convert FastBoxBlur to be one

This is a simple base class for filters that need to work on the image
in-place.
This commit is contained in:
MacDue 2022-10-09 16:30:00 +01:00 committed by Sam Atkins
parent 467565e3d4
commit 71fb1ed226
Notes: sideshowbarker 2024-07-17 06:35:16 +09:00
3 changed files with 37 additions and 12 deletions

View file

@ -14,15 +14,8 @@
namespace PixelPaint::Filters {
void FastBoxBlur::apply(Gfx::Bitmap& target_bitmap, Gfx::Bitmap const& source_bitmap) const
void FastBoxBlur::apply(Gfx::Bitmap& target_bitmap) const
{
// This filter only works in-place, so if we have different target and source, we first copy over
// the source bitmap to the target one.
if (&target_bitmap != &source_bitmap) {
VERIFY(source_bitmap.size_in_bytes() == target_bitmap.size_in_bytes());
memcpy(target_bitmap.scanline(0), source_bitmap.scanline(0), source_bitmap.size_in_bytes());
}
Gfx::FastBoxBlurFilter filter(target_bitmap);
if (m_use_asymmetric_radii) {

View file

@ -6,21 +6,21 @@
#pragma once
#include "Filter.h"
#include "InplaceFilter.h"
#include <LibGUI/CheckBox.h>
#include <LibGUI/ValueSlider.h>
namespace PixelPaint::Filters {
class FastBoxBlur final : public Filter {
class FastBoxBlur final : public InplaceFilter {
public:
virtual void apply(Gfx::Bitmap& target_bitmap, Gfx::Bitmap const& source_bitmap) const override;
virtual void apply(Gfx::Bitmap& target_bitmap) const override;
virtual RefPtr<GUI::Widget> get_settings_widget() override;
virtual StringView filter_name() const override { return "Fast Box Blur (& Gauss)"sv; }
FastBoxBlur(ImageEditor* editor)
: Filter(editor) {};
: InplaceFilter(editor) {};
private:
size_t m_radius { 5 };

View file

@ -0,0 +1,32 @@
/*
* Copyright (c) 2022, MacDue <macdue@dueutil.tech>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include "Filter.h"
namespace PixelPaint {
class InplaceFilter : public Filter {
public:
using Filter::apply;
using Filter::Filter;
virtual void apply(Gfx::Bitmap& target_bitmap) const = 0;
virtual void apply(Gfx::Bitmap& target_bitmap, Gfx::Bitmap const& source_bitmap) const override
{
// This filter only works in-place, so if we have different target and source, we first copy over
// the source bitmap to the target one.
if (&target_bitmap != &source_bitmap) {
VERIFY(source_bitmap.size_in_bytes() == target_bitmap.size_in_bytes());
memcpy(target_bitmap.scanline(0), source_bitmap.scanline(0), source_bitmap.size_in_bytes());
}
apply(target_bitmap);
}
};
}