[babl] babl: LUTs for 16byte destination encodings



commit 48a6294c33f35f8c21299cb04db365b0f6faa1ac
Author: Øyvind Kolås <pippin gimp org>
Date:   Tue Jan 25 12:13:44 2022 +0100

    babl: LUTs for 16byte destination encodings

 babl/babl-fish-path.c | 50 ++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 42 insertions(+), 8 deletions(-)
---
diff --git a/babl/babl-fish-path.c b/babl/babl-fish-path.c
index ec4082154..e49dcfd29 100644
--- a/babl/babl-fish-path.c
+++ b/babl/babl-fish-path.c
@@ -656,9 +656,10 @@ babl_fish_path2 (const Babl *source,
     }
 
   _babl_fish_prepare_bpp (babl);
-  if (source->format.space != destination->format.space &&
+  if (//source->format.space != destination->format.space &&
      (
-        (babl->fish_path.source_bpp == 4 && babl->fish_path.dest_bpp == 4)
+        (babl->fish_path.source_bpp == 4 && babl->fish_path.dest_bpp == 16)
+      ||(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)
@@ -670,8 +671,9 @@ 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 (babl->conversion.source->format.type[0]->bits < 32 &&
-         babl->fish_path.source_bpp < 4 || (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;
   }
 
@@ -736,7 +738,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 1
+#if 0
         fprintf (stderr, "freeing LUT %s to %s unused for >5 minutes\n",
                         babl_get_name (babl->conversion.source),
                         babl_get_name (babl->conversion.destination));
@@ -773,12 +775,12 @@ static int babl_fish_lut_process_maybe (const Babl *babl,
 
      if (BABL_UNLIKELY(!lut && babl->fish.pixels >= 128 * 256))
      {
-#if 1
+#if 0
        fprintf (stderr, "building LUT for %s to %s\n",
                         babl_get_name (babl->conversion.source),
                         babl_get_name (babl->conversion.destination));
 #endif
-       if (source_bpp ==4)
+       if (source_bpp ==4 && dest_bpp == 4)
        {
          lut = malloc (256 * 256 * 256 * 4);
          for (int o = 0; o < 256 * 256 * 256; o++)
@@ -790,6 +792,18 @@ 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 == 4 && dest_bpp == 16)
+       {
+         uint32_t *temp_lut = malloc (256 * 256 * 256 * 4);
+         lut = malloc (256 * 256 * 256 * 16);
+         for (int o = 0; o < 256 * 256 * 256; o++)
+           temp_lut[o] = o;
+         process_conversion_path (babl->fish_path.conversion_list,
+                                  temp_lut, 4,
+                                  lut, 16,
+                                  256*256*256);
+         free (temp_lut);
+       }
        else if (source_bpp == 3 && dest_bpp == 3)
        {
          lut = malloc (256 * 256 * 256 * 4);
@@ -855,7 +869,7 @@ static int babl_fish_lut_process_maybe (const Babl *babl,
        else if (source_bpp == 1 && dest_bpp == 4)
        {
          lut = malloc (256 * 4);
-         uint16_t *temp_lut = malloc (256);
+         uint8_t *temp_lut = malloc (256);
          for (int o = 0; o < 256; o++)
          {
            temp_lut[o]=o;
@@ -887,6 +901,26 @@ static int babl_fish_lut_process_maybe (const Babl *babl,
      }
      if (lut)
      {
+        if (source_bpp == 4 && dest_bpp == 16)
+        {
+          uint32_t *src = (uint32_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--)
+          {
+             uint32_t col = *src++;
+             uint32_t lut_offset = col & 0xffffff;
+             float alpha = (col>>24)/255.0;
+
+             *dst++ = lut[lut_offset*4+0];
+             *dst++ = lut[lut_offset*4+1];
+             *dst++ = lut[lut_offset*4+2];
+             ((float*)(dst))[0] = alpha;
+             dst++;
+          }
+          return 1;
+        }
         if (source_bpp == 4 && dest_bpp == 4)
         {
           uint32_t *src = (uint32_t*)source;


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