Fix HSV to RGB conversion once and for all

This commit is contained in:
2025-04-22 17:11:24 -04:00
parent 8f49ba5e49
commit fe25751b07
4 changed files with 156 additions and 60 deletions

View File

@@ -3,6 +3,7 @@
#include <cstdint>
#include <string>
#include <format>
#include <Color4.hpp>
// Gets set to whatever your terminal emulator is configured for.
// This means black can be shown as purple if configured that way.

View File

@@ -32,40 +32,40 @@ public:
public:
/// The default constructor does not initialize any members.
constexpr Color4() = default;
Color4() = default;
/// Constructs a new Color4 from a Color3 and an optional alpha value.
constexpr explicit Color4(const Color3& color3, u8 alpha = 255);
explicit Color4(const Color3& color3, u8 alpha = 255);
/// Constructs a new Color4 from red, green, blue channel values, and an optional alpha value.
constexpr Color4(u8 red, u8 green, u8 blue, u8 alpha = 255);
Color4(u8 red, u8 green, u8 blue, u8 alpha = 255);
/// Constructs a new Color4 from an RGB structure and an optional alpha value.
constexpr explicit Color4(const RGB& rgb, u8 alpha = 255);
explicit Color4(const RGB& rgb, u8 alpha = 255);
/// Constructs a new Color4 from an RGBA structure.
constexpr explicit Color4(const RGBA& rgba);
explicit Color4(const RGBA& rgba);
/// Constructs a new Color4 from a floating-point RGB structure and an optional alpha value.
/// @note: Normalizes the color values from ranges [0, 1] to [0, 255].
constexpr explicit Color4(const RGBf& rgb, float alpha = 1.0f);
explicit Color4(const RGBf& rgb, float alpha = 1.0f);
/// Constructs a new Color4 from a floating-point RGBA structure.
/// /// @note: Normalizes the color values from ranges [0, 1] to [0, 255].
constexpr explicit Color4(const RGBAf& rgba);
explicit Color4(const RGBAf& rgba);
/// Constructs a new Color4 from an HSV structure.
constexpr explicit Color4(const HSV& hsv, float alpha = 1.f);
explicit Color4(const HSV& hsv, float alpha = 1.f);
/// Constructs a new Color4 from an HSVA structure.
constexpr explicit Color4(const HSVA& hsva);
explicit Color4(const HSVA& hsva);
/// TODO: HSL to RGB constructor
constexpr explicit Color4(const HSL& hsl, float alpha = 1.f);
explicit Color4(const HSL& hsl, float alpha = 1.f);
// TODO: LCH to RGB constructor
constexpr explicit Color4(const LCH& lch, float alpha = 1.f);
explicit Color4(const LCH& lch, float alpha = 1.f);
// TODO: LCHA to RGB constructor
constexpr explicit Color4(const LCHA& lcha);
explicit Color4(const LCHA& lcha);
static Color4 FromColor3(const Color3& color3, u8 alpha = 255);
@@ -73,10 +73,11 @@ public:
static Color4 FromHexA(const std::string& hexACode);
static Color4 FromHSV(float hue, float saturation, float value, float alpha = 1.f) {
// TODO: implement
return {};
}
static Color4 FromHSV(const HSV& hsv, float alpha = 1.f);
/// @param hue The hue value represented in degrees [0-360]
static Color4 FromHSV(float hue, float saturation, float value, float alpha = 1.f);
static Color4 FromHSL(float hue, float saturation, float lightness, float alpha = 1.f);
static Color4 FromNormalized(float red, float green, float blue, float alpha = 1.f);
static Color4 FromLCH(float l, float c, float h, float alpha = 1.f);