[gtk/gamma-shenanigans] Redo the conversion setup for memory formats



commit e21ac7f91f724658f53eb3c8b78c777955432aa0
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Sep 8 08:54:42 2021 -0400

    Redo the conversion setup for memory formats
    
    The two changes have to goal of limiting the
    amount of conversion functions we have to write
    and to keep the matrix from growing too big.
    
    The first change is to pass the formats to the
    conversion functions, which will let them 'chain'
    internally (which is not very efficient, but
    can be of use).
    
    The second change is to make the matrix sparse,
    since we are only interested in fully supporting
    a few target formats.

 gdk/gdkmemorytexture.c | 97 +++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 81 insertions(+), 16 deletions(-)
---
diff --git a/gdk/gdkmemorytexture.c b/gdk/gdkmemorytexture.c
index a614cf2d81..e750eeef01 100644
--- a/gdk/gdkmemorytexture.c
+++ b/gdk/gdkmemorytexture.c
@@ -196,8 +196,10 @@ gdk_memory_texture_get_stride (GdkMemoryTexture *self)
 static void
 convert_memcpy (guchar       *dest_data,
                 gsize         dest_stride,
+                GdkMemoryFormat dest_format,
                 const guchar *src_data,
                 gsize         src_stride,
+                GdkMemoryFormat src_format,
                 gsize         width,
                 gsize         height)
 {
@@ -211,8 +213,10 @@ convert_memcpy (guchar       *dest_data,
 static void \
 convert_swizzle ## A ## R ## G ## B (guchar       *dest_data, \
                                      gsize         dest_stride, \
+                                     GdkMemoryFormat dest_format, \
                                      const guchar *src_data, \
                                      gsize         src_stride, \
+                                     GdkMemoryFormat src_format, \
                                      gsize         width, \
                                      gsize         height) \
 { \
@@ -242,8 +246,10 @@ SWIZZLE(1,2,3,0)
 static void \
 convert_swizzle_opaque_## A ## R ## G ## B (guchar       *dest_data, \
                                             gsize         dest_stride, \
+                                            GdkMemoryFormat dest_format, \
                                             const guchar *src_data, \
                                             gsize         src_stride, \
+                                            GdkMemoryFormat src_format, \
                                             gsize         width, \
                                             gsize         height) \
 { \
@@ -275,8 +281,10 @@ static void \
 convert_swizzle_premultiply_ ## A ## R ## G ## B ## _ ## A2 ## R2 ## G2 ## B2 \
                                     (guchar       *dest_data, \
                                      gsize         dest_stride, \
+                                     GdkMemoryFormat dest_format, \
                                      const guchar *src_data, \
                                      gsize         src_stride, \
+                                     GdkMemoryFormat src_format, \
                                      gsize         width, \
                                      gsize         height) \
 { \
@@ -314,8 +322,10 @@ SWIZZLE_PREMULTIPLY (3,0,1,2, 0,3,2,1)
 static void \
 convert_16to8_swizzle_ ## A ## R ## G ## B (guchar       *dest_data, \
                                             gsize         dest_stride, \
+                                            GdkMemoryFormat dest_format, \
                                             const guchar *src_data, \
                                             gsize         src_stride, \
+                                            GdkMemoryFormat src_format, \
                                             gsize         width, \
                                             gsize         height) \
 { \
@@ -345,8 +355,10 @@ SWIZZLE_16TO8(1,2,3,0)
 static void \
 convert_fp16_swizzle_opaque_ ## A ## R ## G ## B (guchar       *dest_data, \
                                                   gsize         dest_stride, \
+                                                  GdkMemoryFormat dest_format, \
                                                   const guchar *src_data, \
                                                   gsize         src_stride, \
+                                                  GdkMemoryFormat src_format, \
                                                   gsize         width, \
                                                   gsize         height) \
 { \
@@ -378,8 +390,10 @@ SWIZZLE_FP16_OPAQUE(3,0,1,2)
 static void \
 convert_fp16_swizzle_ ## A ## R ## G ## B (guchar       *dest_data, \
                                            gsize         dest_stride, \
+                                           GdkMemoryFormat dest_format, \
                                            const guchar *src_data, \
                                            gsize         src_stride, \
+                                           GdkMemoryFormat src_format, \
                                            gsize         width, \
                                            gsize         height) \
 { \
@@ -411,8 +425,10 @@ SWIZZLE_FP16(3,0,1,2)
 static void \
 convert_float_swizzle_opaque_ ## A ## R ## G ## B (guchar       *dest_data, \
                                                    gsize         dest_stride, \
+                                                   GdkMemoryFormat dest_format, \
                                                    const guchar *src_data, \
                                                    gsize         src_stride, \
+                                                   GdkMemoryFormat src_format, \
                                                    gsize         width, \
                                                    gsize         height) \
 { \
@@ -442,8 +458,10 @@ SWIZZLE_FLOAT_OPAQUE(3,0,1,2)
 static void \
 convert_float_swizzle_ ## A ## R ## G ## B (guchar       *dest_data, \
                                             gsize         dest_stride, \
+                                            GdkMemoryFormat dest_format, \
                                             const guchar *src_data, \
                                             gsize         src_stride, \
+                                            GdkMemoryFormat src_format, \
                                             gsize         width, \
                                             gsize         height) \
 { \
@@ -471,27 +489,72 @@ SWIZZLE_FLOAT(3,0,1,2)
 
 typedef void (* ConversionFunc) (guchar       *dest_data,
                                  gsize         dest_stride,
+                                 GdkMemoryFormat  dest_format,
                                  const guchar *src_data,
                                  gsize         src_stride,
+                                 GdkMemoryFormat  src_format,
                                  gsize         width,
                                  gsize         height);
 
-static ConversionFunc converters[GDK_MEMORY_N_FORMATS][3] =
+static ConversionFunc converters_to_bgra[GDK_MEMORY_N_FORMATS] =
 {
-  { convert_memcpy, convert_swizzle3210, convert_swizzle2103 },
-  { convert_swizzle3210, convert_memcpy, convert_swizzle3012 },
-  { convert_swizzle2103, convert_swizzle1230, convert_memcpy },
-  { convert_swizzle_premultiply_3210_3210, convert_swizzle_premultiply_0123_3210, 
convert_swizzle_premultiply_3012_3210,  },
-  { convert_swizzle_premultiply_3210_0123, convert_swizzle_premultiply_0123_0123, 
convert_swizzle_premultiply_3012_0123 },
-  { convert_swizzle_premultiply_3210_3012, convert_swizzle_premultiply_0123_3012, 
convert_swizzle_premultiply_3012_3012 },
-  { convert_swizzle_premultiply_3210_0321, convert_swizzle_premultiply_0123_0321, 
convert_swizzle_premultiply_3012_0321 },
-  { convert_swizzle_opaque_3210, convert_swizzle_opaque_0123, convert_swizzle_opaque_3012 },
-  { convert_swizzle_opaque_3012, convert_swizzle_opaque_0321, convert_swizzle_opaque_3210 },
-  { convert_16to8_swizzle_2103, convert_16to8_swizzle_1230, convert_16to8_swizzle_0123 },
-  { convert_fp16_swizzle_opaque_3210, convert_fp16_swizzle_opaque_0123, convert_fp16_swizzle_opaque_3012 },
-  { convert_fp16_swizzle_3210, convert_fp16_swizzle_0123, convert_fp16_swizzle_3012 },
-  { convert_float_swizzle_opaque_3210, convert_float_swizzle_opaque_0123, convert_float_swizzle_opaque_3012 
},
-  { convert_float_swizzle_3210, convert_float_swizzle_0123, convert_float_swizzle_3012 }
+  convert_memcpy,
+  convert_swizzle3210,
+  convert_swizzle2103,
+  convert_swizzle_premultiply_3210_3210,
+  convert_swizzle_premultiply_3210_0123,
+  convert_swizzle_premultiply_3210_3012,
+  convert_swizzle_premultiply_3210_0321,
+  convert_swizzle_opaque_3210,
+  convert_swizzle_opaque_3012,
+  convert_16to8_swizzle_2103,
+  convert_fp16_swizzle_opaque_3210,
+  convert_fp16_swizzle_3210,
+  convert_float_swizzle_opaque_3210,
+  convert_float_swizzle_3210,
+};
+
+static ConversionFunc converters_to_argb[GDK_MEMORY_N_FORMATS] =
+{
+  convert_swizzle3210,
+  convert_memcpy,
+  convert_swizzle1230,
+  convert_swizzle_premultiply_0123_3210,
+  convert_swizzle_premultiply_0123_0123,
+  convert_swizzle_premultiply_0123_3012,
+  convert_swizzle_premultiply_0123_0321,
+  convert_swizzle_opaque_0123,
+  convert_swizzle_opaque_0321,
+  convert_16to8_swizzle_1230,
+  convert_fp16_swizzle_opaque_0123,
+  convert_fp16_swizzle_0123,
+  convert_float_swizzle_opaque_0123,
+  convert_float_swizzle_0123,
+};
+
+static ConversionFunc converters_to_rgba[GDK_MEMORY_N_FORMATS] =
+{
+  convert_swizzle2103,
+  convert_swizzle3012,
+  convert_memcpy,
+  convert_swizzle_premultiply_3012_3210,
+  convert_swizzle_premultiply_3012_0123,
+  convert_swizzle_premultiply_3012_3012,
+  convert_swizzle_premultiply_3012_0321,
+  convert_swizzle_opaque_3012,
+  convert_swizzle_opaque_3210,
+  convert_16to8_swizzle_0123,
+  convert_fp16_swizzle_opaque_3012,
+  convert_fp16_swizzle_3012,
+  convert_float_swizzle_opaque_3012,
+  convert_float_swizzle_3012
+};
+
+static ConversionFunc* converters[GDK_MEMORY_N_FORMATS] = {
+  converters_to_bgra, converters_to_argb, converters_to_rgba,
+  NULL, NULL, NULL, NULL, NULL, NULL,
+  NULL, NULL, NULL, NULL,
+  NULL
 };
 
 void
@@ -507,5 +570,7 @@ gdk_memory_convert (guchar          *dest_data,
   g_assert (dest_format < 3);
   g_assert (src_format < GDK_MEMORY_N_FORMATS);
 
-  converters[src_format][dest_format] (dest_data, dest_stride, src_data, src_stride, width, height);
+  converters[src_format][dest_format] (dest_data, dest_stride, dest_format,
+                                       src_data, src_stride, src_format,
+                                       width, height);
 }


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