define a character per block charcblock
authorLaurent Mazet <mazet@softndesign.org>
Wed, 18 Sep 2024 05:27:53 +0000 (07:27 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Wed, 18 Sep 2024 05:27:53 +0000 (07:27 +0200)
display.c

index cc03fbc07f093bd2ed09bb7e2bc52be7019eadd9..05db9b6ade552b694b45b62af05fb50958a09c06 100644 (file)
--- 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] <file>\n", progname);
+    fprintf (fd, "usage: %s [-b char] [-c int] [-g gamma] [-h] [-t|-w] [-v int] <file>\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 */