From ddd0441ab35fdbf0cfd443cc12c97649d7326bd5 Mon Sep 17 00:00:00 2001 From: Laurent MAZET Date: Mon, 16 Sep 2024 11:25:53 +0200 Subject: [PATCH] add 24bits bitmap --- color.c | 5 +++++ color.h | 2 ++ display.c | 8 ++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/color.c b/color.c index f66d365..dc56dd7 100644 --- a/color.c +++ b/color.c @@ -72,4 +72,9 @@ void cprint (color_t *color, char *str) printf ("\e[%dm%s\e[0m", (color) ? color->code : 30, str); } +void cprint24 (float red, float green, float blue, char *str) +{ + printf ("\e[48;2;%d;%d;%dm%s\e[0m", (int)(red * 255), (int)(green * 255), (int)(blue * 255), str); +} + /* vim: set ts=4 sw=4 et: */ diff --git a/color.h b/color.h index 235253f..8fe0f2e 100644 --- a/color.h +++ b/color.h @@ -12,6 +12,8 @@ color_t *findcolor (float red, float green, float blue, int colormap); void cprint (color_t *color, char *str); +void cprint24 (float red, float green, float blue, char *str); + #endif /* __COLOR_H__ */ /* vim: set ts=4 sw=4 et: */ diff --git a/display.c b/display.c index 28c88ac..9cd4ad1 100644 --- a/display.c +++ b/display.c @@ -135,8 +135,12 @@ int main (int argc, char *argv[]) for (l = 0; l < image->height; l++) { for (k = 0; k < image->width; k++) { int ind = k + image->width * l; - color_t *color = findcolor (correction (image->red[ind], gf[0]), correction (image->green[ind], gf[1]), correction (image->blue[ind], gf[2]), colormap); - cprint (color, (mode == 0) ? " " : " "); + if (colormap <= 2) { + color_t *color = findcolor (correction (image->red[ind], gf[0]), correction (image->green[ind], gf[1]), correction (image->blue[ind], gf[2]), colormap); + cprint (color, (mode == 0) ? " " : " "); + } else { + cprint24 (correction (image->red[ind], gf[0]), correction (image->green[ind], gf[1]), correction (image->blue[ind], gf[2]), (mode == 0) ? " " : " "); + } } printf ("\n"); } -- 2.30.2