From 95809b6ebb6628c239f0e3b26f00232ea6bbeff8 Mon Sep 17 00:00:00 2001 From: Martin Gerhardy Date: Sat, 21 May 2022 10:17:37 +0200 Subject: [PATCH] CORE: allow to print the color to the console with ansi color codes --- src/modules/core/Color.cpp | 15 +++++++++++++++ src/modules/core/Color.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/src/modules/core/Color.cpp b/src/modules/core/Color.cpp index 3c11264c0..f85fa77e0 100644 --- a/src/modules/core/Color.cpp +++ b/src/modules/core/Color.cpp @@ -201,6 +201,21 @@ float Color::getDistance(const glm::vec4 &color, float hue, float saturation, fl return val; } +core::String Color::print(RGBA rgba) { + String buf = toHex(rgba); + buf.append(" "); + buf.append("\033[38;2;"); + buf.append(rgba.r).append(";"); + buf.append(rgba.g).append(";"); + buf.append(rgba.b).append("m"); + buf.append("\033[48;2;"); + buf.append(rgba.r).append(";"); + buf.append(rgba.g).append(";"); + buf.append(rgba.b).append("m"); + buf.append("\u2587").append("\033[0m"); + return buf; +} + float Color::getDistance(RGBA rgba, RGBA rgba2) { const glm::vec4 &color = core::Color::fromRGBA(rgba); float hue; diff --git a/src/modules/core/Color.h b/src/modules/core/Color.h index 30061d17e..dcde86f98 100644 --- a/src/modules/core/Color.h +++ b/src/modules/core/Color.h @@ -82,6 +82,8 @@ public: return minIndex; } + static core::String print(RGBA rgba); + static int quantize(RGBA* targetBuf, size_t maxTargetBufColors, const RGBA* inputBuf, size_t inputBufColors); static glm::vec4 fromRGBA(const RGBA rgba);