Implement chat rendering and message handling with colored segments

This commit is contained in:
HueByte
2026-02-19 02:53:29 +01:00
parent 1e6ecab583
commit ed1bf13302
9 changed files with 618 additions and 302 deletions
@@ -18,6 +18,9 @@ public class ImageToAsciiService
var sb = new StringBuilder();
byte lastR = 0, lastG = 0, lastB = 0;
bool hasLastColor = false;
for (int y = 0; y < image.Height; y++)
{
for (int x = 0; x < image.Width; x++)
@@ -25,11 +28,26 @@ public class ImageToAsciiService
var pixel = image[x, y];
var brightness = 0.299 * pixel.R + 0.587 * pixel.G + 0.114 * pixel.B;
// Map brightness (0-255) to ASCII char index (inverted: dark pixels get dense chars)
// Map brightness (0-255) to ASCII char index
var index = (int)((brightness / 255.0) * (AsciiChars.Length - 1));
// Emit ANSI 24-bit color only when it changes
if (!hasLastColor || pixel.R != lastR || pixel.G != lastG || pixel.B != lastB)
{
sb.Append($"\x1b[38;2;{pixel.R};{pixel.G};{pixel.B}m");
lastR = pixel.R;
lastG = pixel.G;
lastB = pixel.B;
hasLastColor = true;
}
sb.Append(AsciiChars[index]);
}
// Reset color at end of line
sb.Append("\x1b[0m");
hasLastColor = false;
if (y < image.Height - 1)
{
sb.AppendLine();