mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 17:10:23 +00:00
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:
parent
467565e3d4
commit
71fb1ed226
Notes:
sideshowbarker
2024-07-17 06:35:16 +09:00
Author: https://github.com/MacDue Commit: https://github.com/SerenityOS/serenity/commit/71fb1ed226 Pull-request: https://github.com/SerenityOS/serenity/pull/15524
3 changed files with 37 additions and 12 deletions
|
@ -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) {
|
||||
|
|
|
@ -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 };
|
||||
|
|
32
Userland/Applications/PixelPaint/Filters/InplaceFilter.h
Normal file
32
Userland/Applications/PixelPaint/Filters/InplaceFilter.h
Normal 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);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in a new issue