mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibGfx: Implement SaturateFilter
This implements the saturate operation as defined in the SVG filter specification. (https://drafts.fxtf.org/filter-effects-1/#feColorMatrixElement)
This commit is contained in:
parent
97f66562cc
commit
f77a84a5f6
Notes:
sideshowbarker
2024-07-17 06:11:07 +09:00
Author: https://github.com/MacDue Commit: https://github.com/SerenityOS/serenity/commit/f77a84a5f6 Pull-request: https://github.com/SerenityOS/serenity/pull/15463 Reviewed-by: https://github.com/AtkinsSJ ✅ Reviewed-by: https://github.com/awesomekling
1 changed files with 40 additions and 0 deletions
40
Userland/Libraries/LibGfx/Filters/SaturateFilter.h
Normal file
40
Userland/Libraries/LibGfx/Filters/SaturateFilter.h
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2022, MacDue <macdue@dueutil.tech>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <LibGfx/Filters/MatrixFilter.h>
|
||||||
|
|
||||||
|
namespace Gfx {
|
||||||
|
|
||||||
|
class SaturateFilter : public MatrixFilter {
|
||||||
|
public:
|
||||||
|
SaturateFilter(float amount)
|
||||||
|
: MatrixFilter(calculate_saturate_matrix(amount))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool amount_handled_in_filter() const override
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual StringView class_name() const override { return "SaturateFilter"sv; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
static FloatMatrix3x3 calculate_saturate_matrix(float amount)
|
||||||
|
{
|
||||||
|
// The matrix is taken directly from the SVG filter specification:
|
||||||
|
// https://drafts.fxtf.org/filter-effects-1/#feColorMatrixElement
|
||||||
|
return FloatMatrix3x3 {
|
||||||
|
0.213f + 0.787f * amount, 0.715f - 0.715f * amount, 0.072f - 0.072f * amount,
|
||||||
|
0.213f - 0.213f * amount, 0.715f + 0.285f * amount, 0.072f - 0.072f * amount,
|
||||||
|
0.213f - 0.213f * amount, 0.715f - 0.715f * amount, 0.072f + 0.928f * amount
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue