add 24bits bitmap
authorLaurent MAZET <laurent.mazet@thalesgroup.com>
Mon, 16 Sep 2024 09:25:53 +0000 (11:25 +0200)
committerLaurent MAZET <laurent.mazet@thalesgroup.com>
Mon, 16 Sep 2024 09:29:27 +0000 (11:29 +0200)
color.c
color.h
display.c

diff --git a/color.c b/color.c
index f66d365bfaa9e2e5b70882cb04857947dcd7b8c3..dc56dd7f2e8cf0237ce329eaf7d09d66b2b9d2ca 100644 (file)
--- 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 235253f6520cd5874c3ccb7b1732bde7e0e4f902..8fe0f2e203f016d011da8dbe29646d0bf2ca65e1 100644 (file)
--- 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: */
index 28c88accf000616f30450a5ba3eccac155a9ab1f..9cd4ad17a09fab564cf85074bb9605f1d9eceffa 100644 (file)
--- 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");
     }