Add color helpers

This commit is contained in:
Jean Pierre Cimalando 2021-02-23 06:03:58 +01:00
parent 0cfe4b8c7c
commit 535b332982
3 changed files with 81 additions and 0 deletions

View file

@ -36,6 +36,8 @@ add_library(sfizz_editor STATIC EXCLUDE_FROM_ALL
src/editor/GUIComponents.cpp
src/editor/GUIPiano.h
src/editor/GUIPiano.cpp
src/editor/ColorHelpers.h
src/editor/ColorHelpers.cpp
src/editor/NativeHelpers.h
src/editor/NativeHelpers.cpp
src/editor/layout/main.hpp

View file

@ -0,0 +1,46 @@
// SPDX-License-Identifier: BSD-2-Clause
// This code is part of the sfizz library and is licensed under a BSD 2-clause
// license. You should have receive a LICENSE.md file along with the code.
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
#include "ColorHelpers.h"
#include <ColorSpaces.h>
SColorRGB::SColorRGB(const CColor &cc)
{
r = cc.normRed<float>();
g = cc.normGreen<float>();
b = cc.normBlue<float>();
a = cc.normAlpha<float>();
}
SColorRGB::SColorRGB(const SColorHCY &hcy)
{
ColorSpaces::vec3 vhcy{{hcy.h, hcy.c, hcy.y}};
ColorSpaces::vec3 vrgb = ColorSpaces::hcy_to_rgb(vhcy);
r = vrgb[0];
g = vrgb[1];
b = vrgb[2];
a = hcy.a;
}
CColor SColorRGB::toColor() const
{
CColor cc;
cc.setNormRed(r);
cc.setNormGreen(g);
cc.setNormBlue(b);
cc.setNormAlpha(a);
return cc;
}
SColorHCY::SColorHCY(const SColorRGB &rgb)
{
ColorSpaces::vec3 vrgb{{rgb.r, rgb.g, rgb.b}};
ColorSpaces::vec3 vhcy = ColorSpaces::rgb_to_hcy(vrgb);
h = vhcy[0];
c = vhcy[1];
y = vhcy[2];
a = rgb.a;
}

View file

@ -0,0 +1,33 @@
// SPDX-License-Identifier: BSD-2-Clause
// This code is part of the sfizz library and is licensed under a BSD 2-clause
// license. You should have receive a LICENSE.md file along with the code.
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
#pragma once
#include "vstgui/lib/ccolor.h"
using namespace VSTGUI;
struct SColorRGB;
struct SColorHCY;
struct SColorRGB {
SColorRGB() = default;
explicit SColorRGB(const CColor &cc);
explicit SColorRGB(const SColorHCY &hcy);
SColorRGB(float r, float g, float b, float a = 1.0) : r(r), g(g), b(b), a(a) {}
CColor toColor() const;
float r {}, g {}, b {}, a { 1.0 };
};
struct SColorHCY {
SColorHCY() = default;
explicit SColorHCY(const CColor &cc) : SColorHCY(SColorRGB(cc)) {}
explicit SColorHCY(const SColorRGB &rgb);
SColorHCY(float h, float c, float y, float a = 1.0) : h(h), c(c), y(y), a(a) {}
CColor toColor() const { return SColorRGB(*this).toColor(); }
float h {}, c {}, y {}, a { 1.0 };
};