[babl] tools: add html variant of path matrix



commit 2468538da26132dd7342872851de9210accb5de6
Author: Øyvind Kolås <pippin gimp org>
Date:   Sun Apr 8 13:05:10 2018 +0200

    tools: add html variant of path matrix

 tools/babl_fish_path_fitness.c |   87 ++++++++++++++++++++++++++++++++--------
 1 files changed, 70 insertions(+), 17 deletions(-)
---
diff --git a/tools/babl_fish_path_fitness.c b/tools/babl_fish_path_fitness.c
index 93e1287..d56ca05 100644
--- a/tools/babl_fish_path_fitness.c
+++ b/tools/babl_fish_path_fitness.c
@@ -11,26 +11,45 @@
 #define random  rand
 #endif
 
-#define pixels    1024
 int           total_length = 0;
 int           total_cost   = 0;
 int           total        = 0;
 int           ok           = 0;
 
-static double test[pixels * 4];
-
-static void
-test_init (void)
-{
-  int i;
+static int   qux = 0;
 
-  for (i = 0; i < pixels * 4; i++)
-    test [i] = (double) random () / RAND_MAX;
-}
+#define UTF8
 
-static int   qux = 0;
+#ifdef UTF8
 
 static char *utf8_bar[] = { " ", "·", "▁", "▂", "▃", "▄", "▅", "▆", "▇", "█" };
+#define      DIRECT " "
+#define      SELF   " "
+#define      EMPTY  " "
+#define      SL     ""
+#define      NL     "\n"
+
+#else
+
+
+static char *utf8_bar[] = { " ",
+                            "<span class='direct'> </span>",
+                            "<span class='path2'> </span>",
+                            "<span class='path3'> </span>",
+                            "<span class='path4'> </span>",
+                            "<span class='path5'> </span>",
+                            "<span class='path6'> </span>",
+                            "<span class='path7'> </span>",
+                            "<span class='path8'> </span>"};
+#define      SL     "<div>"
+#define      SELF   "<span class='self'> </span>"
+#define      EMPTY  "<span class='empty'> </span>"
+#define      NL     "</div>\n"
+
+#endif
+
+
+
 /*
 static char *utf8_bar[]=  {"!","▁","▃","▅","▇","█","!","!","!"};
 static char *utf8_bar[]={"·", "█", "▇", "▆", "▅", "▄", "▃", "▂", "▁", };
@@ -43,9 +62,8 @@ static int destination_each (Babl *babl,
   Babl *source      = userdata;
   Babl *destination = babl;
 
-  qux++;
   if (qux % babl_formats_count () == qux / babl_formats_count ())
-    printf (" ");
+    printf (SELF);
   else
     {
       Babl *temp = babl_fish_path (source, destination);
@@ -60,10 +78,11 @@ static int destination_each (Babl *babl,
         }
       else
         {
-          printf (" ");
+          printf (EMPTY);
           total++;
         }
     }
+  qux++;
   return 0;
 }
 
@@ -72,19 +91,51 @@ static int source_no = 0;
 static int source_each (Babl *babl,
                         void *userdata)
 {
+  printf (SL);
   babl_format_class_for_each (destination_each, babl);
-  printf ("──%2i %s\n", source_no++, babl->instance.name);
+#ifdef UTF8
+  printf ("──%2i %s%s", source_no++, babl->instance.name, NL);
+#else
+  printf ("<span>%2i:%s</span>%s", source_no++, babl->instance.name, NL);
+#endif
   return 0;
 }
 
 int main (void)
 {
   babl_init ();
-  test_init ();
 
   babl_set_extender (babl_extension_quiet_log ());
+
+#ifndef UTF8
+  printf ("<html><head>\n");
+   printf ("<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/>\n");
+
+  printf ("<style>\n"
+
+".empty, .direct, .self, .path1, .path2, .path3, .path4, .path5 { float:left; width: 1em; height: 1em; }"
+"body { background: black; padding: 2em; line-height: 1em; }"
+".empty  { background: black; }"
+".self   { background: yellow; }"
+".direct { background: blue; }"
+".path1  { background: green; }"
+".path2  { background: #8ff; }"
+".path3  { background: #8f8; }"
+".path4  { background: #2f2; }"
+".path5  { background: #0a0; }"
+".path6  { background: #082; }"
+".path7  { background: #050; }"
+".path8  { background: #020; }"
+
+
+"</style>\n");
+  printf ("</head><body>\n");
+
+#endif
+
   babl_format_class_for_each (source_each, NULL);
 
+#ifdef UTF8
   {
     int i;
 
@@ -112,7 +163,6 @@ int main (void)
       }
 
     printf ("\n");
-
     /*
     for (i = 0; i < babl_formats_count (); i++)
       printf ("│");
@@ -140,6 +190,9 @@ int main (void)
   printf ("total cost  : %i\n", total_cost);
   /*printf ("ok / total : %i %i %f\n", ok, total, (1.0*ok) / total);
    */
+#else
+  printf ("</body></html>\n");
+#endif
 
   babl_exit ();
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]