babl: register gray and gray alpha shortcuts between spaces
authorØyvind Kolås <pippin@gimp.org>
Tue, 20 Aug 2019 00:54:51 +0000 (02:54 +0200)
committerØyvind Kolås <pippin@gimp.org>
Tue, 20 Aug 2019 00:54:51 +0000 (02:54 +0200)
The formats "Y float", "YA float" and "YaA float" between different RGB
and gray spaces are all exactly the same. This registers memcpy shortcuts
for these combinations for all spaces. This avoids temporarily expand
into RGBA for many babl path fishes.

babl/babl-space.c

index c05796ca88bb70cc015f5b68a01eb347e51b9d24..90c0a50f9a7377b37c587b389bc0a8ca22e28960 100644 (file)
@@ -883,6 +883,27 @@ universal_rgb_converter (const Babl    *conversion,
 }
 
 
+static inline void
+universal_ya_converter (const Babl    *conversion,
+                        unsigned char *src_char,
+                        unsigned char *dst_char,
+                        long           samples,
+                        void          *data)
+{
+  memcpy (dst_char, src_char, samples * 4 * 2);
+}
+
+static inline void
+universal_y_converter (const Babl    *conversion,
+                       unsigned char *src_char,
+                       unsigned char *dst_char,
+                       long           samples,
+                       void          *data)
+{
+  memcpy (dst_char, src_char, samples * 4);
+}
+
+
 static inline void
 universal_nonlinear_rgb_u8_converter (const Babl    *conversion,
                                       unsigned char *src_char,
@@ -1268,6 +1289,22 @@ add_rgb_adapter (Babl *babl,
                     babl_format_with_space("RGB float", space),
                     "linear", universal_rgb_converter,
                     NULL));
+
+    prep_conversion(babl_conversion_new(
+                    babl_format_with_space("Y float", space),
+                    babl_format_with_space("Y float", babl),
+                    "linear", universal_y_converter,
+                    NULL));
+    prep_conversion(babl_conversion_new(
+                    babl_format_with_space("YaA float", babl),
+                    babl_format_with_space("YaA float", space),
+                    "linear", universal_ya_converter,
+                    NULL));
+    prep_conversion(babl_conversion_new(
+                    babl_format_with_space("YA float", babl),
+                    babl_format_with_space("YA float", space),
+                    "linear", universal_ya_converter,
+                    NULL));
   }
   return 0;
 }