babl: make LUT from 2bpp to 4bpp totally generic.
authorJehan <jehan@girinstud.io>
Fri, 17 Feb 2023 21:45:11 +0000 (22:45 +0100)
committerJehan <jehan@girinstud.io>
Fri, 17 Feb 2023 22:36:42 +0000 (23:36 +0100)
The deleting of the first byte when creating the LUT, then copying the
first byte from source to destination, worked for cases such as "YA u8" to
"RGBA u8" but it would not work for say:

* "Y half" to anything: in such a case, deleting the first byte in LUT's
  content, when creating it, we are basically deleting source's color
  information!
* "YA u8" to "Y float": in such a case, when copying the first byte, at
  conversion time, we are destroying the result color (which didn't need
  any copying of alpha channel as there is no alpha channel in the
  result).
* And so on.

In such cases, it's just better to include everything in the LUT, in a
totally model-agnostic way. In some cases, the alpha channel will be
stored in the LUT, in others, not. But it's not really a problem. It
doesn't even make the LUT bigger; if anything, it makes the LUT creation
and the conversion calculus simpler, hence faster.

babl/babl-fish-path.c

index bda0c7baa88184b659c2a6535c1a7d6a77c6ac7e..15bf65f31d9ba57fe9bbaa3558fbebc12a44d487 100644 (file)
@@ -199,8 +199,7 @@ static inline int _do_lut (uint32_t *lut,
           uint32_t *dst = (uint32_t*)destination;
           while (n--)
           {
-            uint16_t col = *src++;
-            *dst = lut[col & 0xff] | (((uint32_t) (col & 0xff00)) << 16);
+            *dst = lut[*src++];
             dst++;
           }
         }
@@ -455,8 +454,6 @@ static inline int babl_fish_lut_process_maybe (const Babl *babl,
                                   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 == 2 && dest_bpp == 16)