From: Laurent MAZET Date: Mon, 16 Sep 2024 08:04:00 +0000 (+0200) Subject: add a minimal colormap X-Git-Tag: v2.0~17 X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=55f9a840892eeb2939d61e7fb323e45ad65c9e84;p=display.git add a minimal colormap --- diff --git a/color.c b/color.c index 448f495..f66d365 100644 --- a/color.c +++ b/color.c @@ -2,9 +2,21 @@ #include "color.h" -#define nbcolors 16 +#define nbcolors0 8 +#define nbcolors1 16 -color_t colors[nbcolors] = { +color_t colors0[nbcolors0] = { + { 40, 0.0, 0.0, 0.0 }, + { 41, 0.7, 0.1, 0.1 }, + { 42, 0.1, 0.7, 0.1 }, + { 43, 0.7, 0.4, 0.1 }, + { 44, 0.1, 0.1, 0.7 }, + { 45, 0.7, 0.1, 0.7 }, + { 46, 0.1, 0.7, 0.7 }, + { 47, 0.7, 0.7, 0.7 }, +}; + +color_t colors1[nbcolors1] = { { 40, 0.0, 0.0, 0.0 }, { 41, 0.7, 0.1, 0.1 }, { 42, 0.1, 0.7, 0.1 }, @@ -23,11 +35,24 @@ color_t colors[nbcolors] = { { 107, 1.0, 1.0, 1.0 }, }; -color_t *findcolor (float red, float green, float blue) +color_t *findcolor (float red, float green, float blue, int colormap) { color_t *color = NULL; int i; float dist = 3; + int nbcolors; + color_t *colors; + switch (colormap) { + case 0: + nbcolors = nbcolors0; + colors = colors0; + break; + case 1: + default: + nbcolors = nbcolors1; + colors = colors1; + break; + } for (i = 0; i < nbcolors; i++) { float r = (colors + i)->red - red; float g = (colors + i)->green - green; diff --git a/color.h b/color.h index 65be10e..235253f 100644 --- a/color.h +++ b/color.h @@ -8,7 +8,7 @@ typedef struct { float blue; } color_t; -color_t *findcolor (float red, float green, float blue); +color_t *findcolor (float red, float green, float blue, int colormap); void cprint (color_t *color, char *str); diff --git a/display.c b/display.c index 428015f..28c88ac 100644 --- a/display.c +++ b/display.c @@ -17,6 +17,7 @@ char *progname = NULL; char *version = "1.0"; +int colormap = 1; float gf[3] = { 1.0f, 1.0f, 1.0f }; int mode = 0; @@ -24,7 +25,8 @@ int mode = 0; int usage (int ret) { FILE *fd = ret ? stderr : stdout; - fprintf (fd, "usage: %s [-g gamma] [-h] [-t|-w] [-v int] \n", progname); + fprintf (fd, "usage: %s [-c int] [-g gamma] [-h] [-t|-w] [-v int] \n", progname); + fprintf (fd, " -c: color map [0..2] (%d)\n", colormap); fprintf (fd, " -g: gamma correction (%.1f:%.1f:%.1f)\n", gf[0], gf[1], gf[2]); fprintf (fd, " -h: help message\n"); fprintf (fd, " -t: thin mode (%s)\n", (mode == 0) ? "on" : "off"); @@ -64,6 +66,14 @@ int main (int argc, char *argv[]) } char c = arg[1]; switch (c) { + case 'c': + arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL; + if (arg == NULL) { + VERBOSE (ERROR, fprintf (stderr, "%s: missing color map\n", progname)); + return usage (1); + } + colormap = atoi (arg); + break; case 'g': arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL; if (arg == NULL) { @@ -125,7 +135,7 @@ 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])); + 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) ? " " : " "); } printf ("\n"); @@ -137,6 +147,7 @@ int main (int argc, char *argv[]) } /* test: display.exe 2>&1 | grep 'no file specified' */ +/* test: display.exe -c 2>&1 | grep missing */ /* test: display.exe -g 2>&1 | grep 'no gamma specified' */ /* test: display.exe -g -1.0 2>&1 | grep 'incorrect gamma' */ /* test: display.exe -g 1.1:0:1.1 2>&1 | grep 'incorrect gamma' */