DPF

DISTRHO Plugin Framework
Log | Files | Refs | Submodules | README | LICENSE

commit 878a183b59f4467118263c1c760f6ccb8efbe0bd
parent 2ba9190f42161f69c12dd5927084a34e82beb7fc
Author: falkTX <falktx@falktx.com>
Date:   Sun, 20 Nov 2022 12:36:49 +0000

Add Color::plus/minus utils

Signed-off-by: falkTX <falktx@falktx.com>

Diffstat:
Mdgl/Color.hpp | 26+++++++++++++++++++++++++-
Mdgl/src/Color.cpp | 42++++++++++++++++++++++++++++++++++++++++++
2 files changed, 67 insertions(+), 1 deletion(-)

diff --git a/dgl/Color.hpp b/dgl/Color.hpp @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com> + * Copyright (C) 2012-2022 Filipe Coelho <falktx@falktx.com> * * Permission to use, copy, modify, and/or distribute this software for any purpose with * or without fee is hereby granted, provided that the above copyright notice and this @@ -71,6 +71,30 @@ struct Color { Color withAlpha(float alpha) const noexcept; /** + Create a new color based on this one but with subtracted numeric value on all elements. + Value must be in [0..255] range. + */ + Color minus(int value) const noexcept; + + /** + Create a new color based on this one but with subtracted floating-point value on all elements. + Value must be in [0..1] range. + */ + Color minus(float value) const noexcept; + + /** + Create a new color based on this one but with added numeric value on all elements. + Value must be in [0..255] range. + */ + Color plus(int value) const noexcept; + + /** + Create a new color based on this one but with added floating-point value on all elements. + Value must be in [0..1] range. + */ + Color plus(float value) const noexcept; + + /** Create a color specified by hue, saturation and lightness. Values must in [0..1] range. */ diff --git a/dgl/src/Color.cpp b/dgl/src/Color.cpp @@ -121,6 +121,48 @@ Color Color::withAlpha(const float alpha2) const noexcept return color; } +Color Color::minus(const int value) const noexcept +{ + const float fvalue = static_cast<float>(value)/255.f; + Color color(*this); + color.red -= fvalue; + color.green -= fvalue; + color.blue -= fvalue; + color.fixBounds(); + return color; +} + +Color Color::minus(const float value) const noexcept +{ + Color color(*this); + color.red -= value; + color.green -= value; + color.blue -= value; + color.fixBounds(); + return color; +} + +Color Color::plus(const int value) const noexcept +{ + const float fvalue = static_cast<float>(value)/255.f; + Color color(*this); + color.red += fvalue; + color.green += fvalue; + color.blue += fvalue; + color.fixBounds(); + return color; +} + +Color Color::plus(const float value) const noexcept +{ + Color color(*this); + color.red += value; + color.green += value; + color.blue += value; + color.fixBounds(); + return color; +} + Color Color::fromHSL(float hue, float saturation, float lightness, float alpha) { float m1, m2;