[gtk/gamma-shenanigans: 2/8] Improve half-float memory conversions




commit 504b48fe6d323e60084f4e49c3f6134310ec901b
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Sep 10 07:58:26 2021 -0400

    Improve half-float memory conversions
    
    Convert a row at a time, so we don't do
    a function call for every pixel.

 gdk/gdkmemorytexture.c | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)
---
diff --git a/gdk/gdkmemorytexture.c b/gdk/gdkmemorytexture.c
index 6b711dc257..e45be733a7 100644
--- a/gdk/gdkmemorytexture.c
+++ b/gdk/gdkmemorytexture.c
@@ -399,23 +399,24 @@ convert_fp16_swizzle_opaque_ ## A ## R ## G ## B (guchar       *dest_data, \
                                                   gsize         height) \
 { \
   gsize x, y; \
+  float *c; \
 \
+c = g_malloc (width * sizeof (float)); \
   for (y = 0; y < height; y++) \
     { \
       guint16 *src = (guint16 *)src_data; \
+      half_to_float (src, c, width); \
       for (x = 0; x < width; x++) \
         { \
-          float c[4]; \
-          half_to_float4 (&src[3 * x], c); \
           dest_data[4 * x + A] = 255; \
-          dest_data[4 * x + R] = (guchar)(255 * c[0]); \
-          dest_data[4 * x + G] = (guchar)(255 * c[1]); \
-          dest_data[4 * x + B] = (guchar)(255 * c[2]); \
+          dest_data[4 * x + R] = (guchar)(255 * c[3 * x + 0]); \
+          dest_data[4 * x + G] = (guchar)(255 * c[3 * x + 1]); \
+          dest_data[4 * x + B] = (guchar)(255 * c[3 * x + 2]); \
         } \
-\
       dest_data += dest_stride; \
       src_data += src_stride; \
     } \
+  g_free (c); \
 }
 
 SWIZZLE_FP16_OPAQUE(3,2,1,0)
@@ -434,23 +435,24 @@ convert_fp16_swizzle_ ## A ## R ## G ## B (guchar       *dest_data, \
                                            gsize         height) \
 { \
   gsize x, y; \
+  float *c; \
 \
+  c = g_malloc (width * sizeof (float)); \
   for (y = 0; y < height; y++) \
     { \
       guint16 *src = (guint16 *)src_data; \
+      half_to_float (src, c, width); \
       for (x = 0; x < width; x++) \
         { \
-          float c[4]; \
-          half_to_float4 (&src[3 * x], c); \
-          dest_data[4 * x + A] = (guchar)(255 * c[0]); \
-          dest_data[4 * x + R] = (guchar)(255 * c[1]); \
-          dest_data[4 * x + G] = (guchar)(255 * c[2]); \
-          dest_data[4 * x + B] = (guchar)(255 * c[3]); \
+          dest_data[4 * x + A] = (guchar)(255 * c[4 * x + 0]); \
+          dest_data[4 * x + R] = (guchar)(255 * c[4 * x + 1]); \
+          dest_data[4 * x + G] = (guchar)(255 * c[4 * x + 2]); \
+          dest_data[4 * x + B] = (guchar)(255 * c[4 * x + 3]); \
         } \
-\
       dest_data += dest_stride; \
       src_data += src_stride; \
     } \
+  g_free (c); \
 }
 
 SWIZZLE_FP16(3,2,1,0)


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