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

PixelPaint+LibGfx: Add sepia color filter

This commit is contained in:
Xavier Defrang 2022-01-08 10:36:04 +01:00 committed by Andreas Kling
parent 2502a88e49
commit b1a15b02f1
7 changed files with 147 additions and 0 deletions

View file

@ -232,6 +232,33 @@ public:
return Color(gray, gray, gray, alpha());
}
constexpr Color sepia(float amount = 1.0f) const
{
auto blend_factor = 1.0f - amount;
auto r1 = 0.393f + 0.607f * blend_factor;
auto r2 = 0.769f - 0.769f * blend_factor;
auto r3 = 0.189f - 0.189f * blend_factor;
auto g1 = 0.349f - 0.349f * blend_factor;
auto g2 = 0.686f + 0.314f * blend_factor;
auto g3 = 0.168f - 0.168f * blend_factor;
auto b1 = 0.272f - 0.272f * blend_factor;
auto b2 = 0.534f - 0.534f * blend_factor;
auto b3 = 0.131f + 0.869f * blend_factor;
auto r = red();
auto g = green();
auto b = blue();
return Color(
clamp(lroundf(r * r1 + g * r2 + b * r3), 0, 255),
clamp(lroundf(r * g1 + g * g2 + b * g3), 0, 255),
clamp(lroundf(r * b1 + g * b2 + b * b3), 0, 255),
alpha());
}
constexpr Color darkened(float amount = 0.5f) const
{
return Color(red() * amount, green() * amount, blue() * amount, alpha());

View file

@ -0,0 +1,32 @@
/*
* Copyright (c) 2022, Xavier Defrang <xavier.defrang@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/StdLibExtras.h>
#include <LibGfx/Filters/ColorFilter.h>
#include <math.h>
namespace Gfx {
class SepiaFilter : public ColorFilter {
public:
SepiaFilter(float amount = 1.0f)
: m_amount(amount)
{
}
virtual ~SepiaFilter() { }
virtual char const* class_name() const override { return "SepiaFilter"; }
protected:
Color convert_color(Color original) override { return original.sepia(m_amount); };
private:
float m_amount;
};
}