CORE: allow to print the color to the console with ansi color codes

master
Martin Gerhardy 2022-05-21 10:17:37 +02:00
parent fb5549aa05
commit 95809b6ebb
2 changed files with 17 additions and 0 deletions

View File

@ -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;

View File

@ -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);