[babl] babl: do LUTs for 1 and 2 byte encodings



commit 5b67a36321d895dd85dea4b3ebd427ab7c5693d8
Author: Øyvind Kolås <pippin gimp org>
Date:   Tue Jan 25 08:22:02 2022 +0100

    babl: do LUTs for 1 and 2 byte encodings

 babl/babl-fish-path.c  | 81 +++++++++++++++++++++++++++++++++++++++++++-------
 tools/babl-benchmark.c | 32 ++++++++++++++++++--
 2 files changed, 100 insertions(+), 13 deletions(-)
---
diff --git a/babl/babl-fish-path.c b/babl/babl-fish-path.c
index f93e010ae..ec4082154 100644
--- a/babl/babl-fish-path.c
+++ b/babl/babl-fish-path.c
@@ -657,14 +657,12 @@ babl_fish_path2 (const Babl *source,
 
   _babl_fish_prepare_bpp (babl);
   if (source->format.space != destination->format.space &&
-     (source->format.model->flags & BABL_MODEL_FLAG_ASSOCIATED)==0  &&
      (
-      (babl->fish_path.source_bpp == 4 && babl->fish_path.dest_bpp == 4)
+        (babl->fish_path.source_bpp == 4 && babl->fish_path.dest_bpp == 4)
       ||(babl->fish_path.source_bpp == 3 && babl->fish_path.dest_bpp == 4)
+      ||(babl->fish_path.source_bpp == 2 && babl->fish_path.dest_bpp == 4)
+      ||(babl->fish_path.source_bpp == 1 && babl->fish_path.dest_bpp == 4)
       ||(babl->fish_path.source_bpp == 3 && babl->fish_path.dest_bpp == 3)
-      // XXX 16bit code paths not enabled yet.
-      //
-      //|| (babl->fish_path.source_bpp == 8 && babl->fish_path.dest_bpp == 4)
       )
      )
   {
@@ -672,7 +670,8 @@ babl_fish_path2 (const Babl *source,
      // (alpha) - and it is not an associated color model. A 24 bit LUT provides
      // exact data. Thus this is valid for instance for "YA half"
 
-     if ((source->format.model->flags & BABL_MODEL_FLAG_ASSOCIATED)==0)
+     if (babl->conversion.source->format.type[0]->bits < 32 &&
+         babl->fish_path.source_bpp < 4 || (source->format.model->flags & BABL_MODEL_FLAG_ASSOCIATED)==0)
        babl->fish_path.is_u8_color_conv = 1;
   }
 
@@ -737,7 +736,7 @@ static int gc_fishes (Babl *babl, void *userdata)
         void *lut =babl->fish_path.u8_lut;
         BABL(babl)->fish_path.u8_lut = NULL;
         free (lut);
-#if 0
+#if 1
         fprintf (stderr, "freeing LUT %s to %s unused for >5 minutes\n",
                         babl_get_name (babl->conversion.source),
                         babl_get_name (babl->conversion.destination));
@@ -774,14 +773,14 @@ static int babl_fish_lut_process_maybe (const Babl *babl,
 
      if (BABL_UNLIKELY(!lut && babl->fish.pixels >= 128 * 256))
      {
-#if 0
+#if 1
        fprintf (stderr, "building LUT for %s to %s\n",
                         babl_get_name (babl->conversion.source),
                         babl_get_name (babl->conversion.destination));
 #endif
-       lut = malloc (256 * 256 * 256 * 4);
        if (source_bpp ==4)
        {
+         lut = malloc (256 * 256 * 256 * 4);
          for (int o = 0; o < 256 * 256 * 256; o++)
            lut[o] = o;
          process_conversion_path (babl->fish_path.conversion_list,
@@ -791,8 +790,9 @@ static int babl_fish_lut_process_maybe (const Babl *babl,
          for (int o = 0; o < 256 * 256 * 256; o++)
            lut[o] = lut[o] & 0x00ffffff;
        }
-       else if (source_bpp = 3 && dest_bpp == 3)
+       else if (source_bpp == 3 && dest_bpp == 3)
        {
+         lut = malloc (256 * 256 * 256 * 4);
          uint8_t *temp_lut = malloc (256 * 256 * 256 * 3);
          uint8_t *temp_lut2 = malloc (256 * 256 * 256 * 3);
          int o = 0;
@@ -815,8 +815,9 @@ static int babl_fish_lut_process_maybe (const Babl *babl,
          free (temp_lut);
          free (temp_lut2);
        }
-       else if (source_bpp = 3 && dest_bpp == 4)
+       else if (source_bpp == 3 && dest_bpp == 4)
        {
+         lut = malloc (256 * 256 * 256 * 4);
          uint8_t *temp_lut = malloc (256 * 256 * 256 * 3);
          int o = 0;
          for (int r = 0; r < 256; r++)
@@ -835,6 +836,38 @@ static int babl_fish_lut_process_maybe (const Babl *babl,
            lut[o] = lut[o] & 0x00ffffff;
          free (temp_lut);
        }
+       else if (source_bpp == 2 && dest_bpp == 4)
+       {
+         lut = malloc (256 * 256 * 4);
+         uint16_t *temp_lut = malloc (256 * 256 * 2);
+         for (int o = 0; o < 256*256; o++)
+         {
+           temp_lut[o]=o;
+         }
+         process_conversion_path (babl->fish_path.conversion_list,
+                                  temp_lut, 2,
+                                  lut, 4,
+                                  256*256);
+         for (int o = 0; o < 256 * 256; o++)
+           lut[o] = lut[o] & 0x00ffffff;
+         free (temp_lut);
+       }
+       else if (source_bpp == 1 && dest_bpp == 4)
+       {
+         lut = malloc (256 * 4);
+         uint16_t *temp_lut = malloc (256);
+         for (int o = 0; o < 256; o++)
+         {
+           temp_lut[o]=o;
+         }
+         process_conversion_path (babl->fish_path.conversion_list,
+                                  temp_lut, 1,
+                                  lut, 4,
+                                  256);
+         for (int o = 0; o < 256; o++)
+           lut[o] = lut[o] & 0x00ffffff;
+         free (temp_lut);
+       }
 
        if (babl->fish_path.u8_lut == NULL)
        {
@@ -869,6 +902,32 @@ static int babl_fish_lut_process_maybe (const Babl *babl,
           }
           return 1;
         }
+        if (source_bpp == 2 && dest_bpp == 4)
+        {
+          uint16_t *src = (uint16_t*)source;
+          uint32_t *dst = (uint32_t*)destination;
+          lut = (uint32_t*)babl->fish_path.u8_lut;
+          BABL(babl)->fish_path.last_lut_use = babl_ticks ();
+          while (n--)
+          {
+             *dst = lut[*src++];
+             dst++;
+          }
+          return 1;
+        }
+        if (source_bpp == 1 && dest_bpp == 4)
+        {
+          uint8_t *src = (uint8_t*)source;
+          uint32_t *dst = (uint32_t*)destination;
+          lut = (uint32_t*)babl->fish_path.u8_lut;
+          BABL(babl)->fish_path.last_lut_use = babl_ticks ();
+          while (n--)
+          {
+             *dst = lut[*src++];
+             dst++;
+          }
+          return 1;
+        }
         else if (source_bpp == 3 && dest_bpp == 3)
         {
           uint8_t *src = (uint8_t*)source;
diff --git a/tools/babl-benchmark.c b/tools/babl-benchmark.c
index 7f5d938d0..7329b4fe0 100644
--- a/tools/babl-benchmark.c
+++ b/tools/babl-benchmark.c
@@ -104,10 +104,18 @@ test (int set_no)
         { babl_format_with_space("Y'A u16", babl_space("sRGB")), default_set("sRGB", "sRGB"), NULL },
         { babl_format_with_space("Y'A half", babl_space("sRGB")), default_set("sRGB", "sRGB"), NULL },
         { babl_format_with_space("Y'A float", babl_space("sRGB")), default_set("sRGB", "sRGB"), NULL },
+        { babl_format_with_space("Y' u8", babl_space("sRGB")), default_set("sRGB", "sRGB"), NULL },
+        { babl_format_with_space("Y' u16", babl_space("sRGB")), default_set("sRGB", "sRGB"), NULL },
+        { babl_format_with_space("Y' half", babl_space("sRGB")), default_set("sRGB", "sRGB"), NULL },
+        { babl_format_with_space("Y' float", babl_space("sRGB")), default_set("sRGB", "sRGB"), NULL },
         { babl_format_with_space("YA u8", babl_space("sRGB")), default_set("sRGB", "sRGB"), NULL },
         { babl_format_with_space("YA u16", babl_space("sRGB")), default_set("sRGB", "sRGB"), NULL },
         { babl_format_with_space("YA half", babl_space("sRGB")), default_set("sRGB", "sRGB"), NULL },
         { babl_format_with_space("YA float", babl_space("sRGB")), default_set("sRGB", "sRGB"), NULL },
+        { babl_format_with_space("Y u8", babl_space("sRGB")), default_set("sRGB", "sRGB"), NULL },
+        { babl_format_with_space("Y u16", babl_space("sRGB")), default_set("sRGB", "sRGB"), NULL },
+        { babl_format_with_space("Y half", babl_space("sRGB")), default_set("sRGB", "sRGB"), NULL },
+        { babl_format_with_space("Y float", babl_space("sRGB")), default_set("sRGB", "sRGB"), NULL },
 
 
         { babl_format_with_space("R'G'B'A u8", babl_space("sRGB")), default_set("sRGB", "ProPhoto"), NULL },
@@ -139,6 +147,16 @@ test (int set_no)
         { babl_format_with_space("YA half", babl_space("sRGB")), default_set("sRGB", "ProPhoto"), NULL },
         { babl_format_with_space("YA float", babl_space("sRGB")), default_set("sRGB", "ProPhoto"), NULL },
 
+        { babl_format_with_space("Y' u8", babl_space("sRGB")), default_set("sRGB", "ProPhoto"), NULL },
+        { babl_format_with_space("Y' u16", babl_space("sRGB")), default_set("sRGB", "ProPhoto"), NULL },
+        { babl_format_with_space("Y' half", babl_space("sRGB")), default_set("sRGB", "ProPhoto"), NULL },
+        { babl_format_with_space("Y' float", babl_space("sRGB")), default_set("sRGB", "ProPhoto"), NULL },
+
+        { babl_format_with_space("Y u8", babl_space("sRGB")), default_set("sRGB", "ProPhoto"), NULL },
+        { babl_format_with_space("Y u16", babl_space("sRGB")), default_set("sRGB", "ProPhoto"), NULL },
+        { babl_format_with_space("Y half", babl_space("sRGB")), default_set("sRGB", "ProPhoto"), NULL },
+        { babl_format_with_space("Y float", babl_space("sRGB")), default_set("sRGB", "ProPhoto"), NULL },
+
         { babl_format_with_space("R'G'B'A u8", babl_space("Apple")), default_set("Apple", "ProPhoto"), NULL 
},
         { babl_format_with_space("R'G'B'A u16", babl_space("Apple")), default_set("Apple", "ProPhoto"), NULL 
},
         { babl_format_with_space("R'G'B'A half", babl_space("Apple")), default_set("Apple", "ProPhoto"), 
NULL },
@@ -163,6 +181,14 @@ test (int set_no)
         { babl_format_with_space("YA u16", babl_space("Apple")), default_set("Apple", "ProPhoto"), NULL },
         { babl_format_with_space("YA half", babl_space("Apple")), default_set("Apple", "ProPhoto"), NULL },
         { babl_format_with_space("YA float", babl_space("Apple")), default_set("Apple", "ProPhoto"), NULL },
+        { babl_format_with_space("Y' u8", babl_space("Apple")), default_set("Apple", "ProPhoto"), NULL },
+        { babl_format_with_space("Y' u16", babl_space("Apple")), default_set("Apple", "ProPhoto"), NULL },
+        { babl_format_with_space("Y' half", babl_space("Apple")), default_set("Apple", "ProPhoto"), NULL },
+        { babl_format_with_space("Y' float", babl_space("Apple")), default_set("Apple", "ProPhoto"), NULL },
+        { babl_format_with_space("Y u8", babl_space("Apple")), default_set("Apple", "ProPhoto"), NULL },
+        { babl_format_with_space("Y u16", babl_space("Apple")), default_set("Apple", "ProPhoto"), NULL },
+        { babl_format_with_space("Y half", babl_space("Apple")), default_set("Apple", "ProPhoto"), NULL },
+        { babl_format_with_space("Y float", babl_space("Apple")), default_set("Apple", "ProPhoto"), NULL },
      };
 
   int n_formats = 0;
@@ -207,7 +233,8 @@ test (int set_no)
  n = 0;
  for (i = 0; formats[i]; i++)
    for (j = 0; formats[j]; j++)
-   if (i != j && i != (n_formats - 1) && (i==0 || j!=n_formats-1))
+   //if (i != j && i != (n_formats - 1) && (i==0 || j!=n_formats-1))
+   if (i != j && i != (n_formats - 1) && (i==0 || j!=n_formats-1) && (j==0 || i==0))
    {
       const Babl *fish = babl_fish (formats[i], formats[j]);
       long end, start;
@@ -257,7 +284,8 @@ test (int set_no)
  n = 0;
  for (i = 0; formats[i]; i++)
    for (j = 0; formats[j]; j++)
-   if (i != j && i != (n_formats - 1) && (i==0 || j!=n_formats-1))
+   //if (i != j && i != (n_formats - 1) && (i==0 || j!=n_formats-1))
+   if (i != j && i != (n_formats - 1) && (i==0 || j!=n_formats-1) && (j==0 || i==0))
    {
       fprintf (stdout, "%s %03.3f m%s/s\t",
                       unicode_hbar(BAR_WIDTH, mbps[n] / max),


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