[gtk/gamma-shenanigans: 6/8] Redo the conversion setup for memory formats
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/gamma-shenanigans: 6/8] Redo the conversion setup for memory formats
- Date: Thu, 9 Sep 2021 20:29:13 +0000 (UTC)
commit 11dc025db5217e68bab94e0104049c8ae24f26ca
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 | 109 +++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 91 insertions(+), 18 deletions(-)
---
diff --git a/gdk/gdkmemorytexture.c b/gdk/gdkmemorytexture.c
index c04d18e7da..2c67f5686e 100644
--- a/gdk/gdkmemorytexture.c
+++ b/gdk/gdkmemorytexture.c
@@ -198,8 +198,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)
{
@@ -213,8 +215,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) \
{ \
@@ -244,8 +248,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) \
{ \
@@ -277,8 +283,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) \
{ \
@@ -316,8 +324,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) \
{ \
@@ -347,8 +357,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) \
{ \
@@ -380,8 +392,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) \
{ \
@@ -413,8 +427,10 @@ SWIZZLE_FP16(3,0,1,2)
static void \
convert_fp16_swizzle_premultiply_ ## 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) \
{ \
@@ -483,8 +499,10 @@ convert_fp16_premultiply (guchar *dest_data,
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) \
{ \
@@ -514,8 +532,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) \
{ \
@@ -545,8 +565,10 @@ SWIZZLE_FLOAT(3,0,1,2)
static void \
convert_float_swizzle_premultiply_ ## 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) \
{ \
@@ -604,29 +626,78 @@ static void convert_float_premultiply (guchar *dest_data,
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_premultiply_3210, convert_fp16_swizzle_premultiply_0123,
convert_fp16_swizzle_premultiply_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_premultiply_3210, convert_float_swizzle_premultiply_0123,
convert_float_swizzle_premultiply_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_premultiply_3210,
+ convert_fp16_swizzle_3210,
+ convert_float_swizzle_opaque_3210,
+ convert_float_swizzle_premultiply_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_premultiply_0123,
+ convert_fp16_swizzle_0123,
+ convert_float_swizzle_opaque_0123,
+ convert_float_swizzle_premultiply_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_premultiply_3012,
+ convert_fp16_swizzle_3012,
+ convert_float_swizzle_opaque_3012,
+ convert_float_swizzle_premultiply_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
@@ -649,5 +720,7 @@ gdk_memory_convert (guchar *dest_data,
dest_format == GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED)
convert_float_premultiply (dest_data, dest_stride, src_data, src_stride, width, height);
else
- converters[src_format][dest_format] (dest_data, dest_stride, src_data, src_stride, width, height);
+ converters[dest_format][src_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]