From f5e326d087b9feae14878028de3988a2863ca2d3 Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Wed, 18 Sep 2024 07:27:53 +0200 Subject: [PATCH] define a character per block --- display.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/display.c b/display.c index cc03fbc..05db9b6 100644 --- a/display.c +++ b/display.c @@ -17,6 +17,7 @@ char *progname = NULL; char *version = "1.0"; +char block[3] = { ' ', 0, 0 }; int colormap = 1; float gf[3] = { 1.0f, 1.0f, 1.0f }; int mode = 0; @@ -25,7 +26,8 @@ int mode = 0; int usage (int ret) { FILE *fd = ret ? stderr : stdout; - fprintf (fd, "usage: %s [-c int] [-g gamma] [-h] [-t|-w] [-v int] \n", progname); + fprintf (fd, "usage: %s [-b char] [-c int] [-g gamma] [-h] [-t|-w] [-v int] \n", progname); + fprintf (fd, " -b: block caracter (%c)\n", block[0]); fprintf (fd, " -c: color map [0..4] (%d)\n", colormap); fprintf (fd, " -g: gamma correction (%.1f:%.1f:%.1f)\n", gf[0], gf[1], gf[2]); fprintf (fd, " -h: help message\n"); @@ -66,6 +68,14 @@ int main (int argc, char *argv[]) } char c = arg[1]; switch (c) { + case 'b': + arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL; + if (arg == NULL) { + VERBOSE (ERROR, fprintf (stderr, "%s: missing character block\n", progname)); + return usage (1); + } + block[0] = arg[0]; + break; case 'c': arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL; if (arg == NULL) { @@ -128,6 +138,11 @@ int main (int argc, char *argv[]) return 1; } + /* configure block */ + if (mode == 1) { + block[1] = block[0]; + } + /* main process */ image_t *image = readpnm (filename); if (!image) { @@ -143,13 +158,13 @@ int main (int argc, char *argv[]) switch (colormap) { case 0: case 1: - cprint (color, (mode == 0) ? " " : " "); + cprint (color, block); break; case 2: - cprint8 (color, (mode == 0) ? " " : " "); + cprint8 (color, block); break; case 3: - cprint24 (color, (mode == 0) ? " " : " "); + cprint24 (color, block); } } printf ("\n"); @@ -161,6 +176,7 @@ int main (int argc, char *argv[]) } /* test: display.exe 2>&1 | grep 'no file specified' */ +/* test: display.exe -b 2>&1 | grep missing */ /* test: display.exe -c 2>&1 | grep missing */ /* test: display.exe -c -1 2>&1 | grep 'incorrect colormap' */ /* test: display.exe -c 4 2>&1 | grep 'incorrect colormap' */ @@ -193,6 +209,7 @@ int main (int argc, char *argv[]) /* test: display.exe image/laurent4.ppm -c 3 */ /* test: display.exe image/debian.ppm -v 3 */ /* test: display.exe image/debian.ppm -g 4 */ +/* test: display.exe image/python3.ppm -b x */ /* test: display.exe image/python3.ppm -t */ /* test: display.exe image/python3.ppm -w */ -- 2.30.2