[gtk/wip/otte/memoryformat: 27/28] Add private memory formats used by libpng




commit 556699fb2d387d69594e1fb1446f2ca017963e7e
Author: Benjamin Otte <otte redhat com>
Date:   Sun Sep 26 16:47:34 2021 +0200

    Add private memory formats used by libpng

 gdk/gdkmemoryformat.c  | 30 ++++++++++++++++++++++++++++++
 gdk/gdkmemorytexture.h |  5 +++++
 gdk/loaders/gdkpng.c   | 32 ++++----------------------------
 3 files changed, 39 insertions(+), 28 deletions(-)
---
diff --git a/gdk/gdkmemoryformat.c b/gdk/gdkmemoryformat.c
index 5ee530654f..c89eba5bad 100644
--- a/gdk/gdkmemoryformat.c
+++ b/gdk/gdkmemoryformat.c
@@ -347,6 +347,36 @@ static const GdkMemoryFormatDescription memory_formats[GDK_MEMORY_N_FORMATS] = {
     { GL_RGBA32F, GL_RGBA, GL_FLOAT },
     r32g32b32a32_float_to_float,
     r32g32b32a32_float_from_float,
+  },
+  [GDK_MEMORY_R16G16B16A16] = {
+    GDK_MEMORY_ALPHA_STRAIGHT,
+    8,
+    G_ALIGNOF (guint16),
+    TRUE,
+    TRUE,
+    { GL_RGBA16, GL_RGBA, GL_UNSIGNED_SHORT },
+    r16g16b16a16_to_float,
+    r16g16b16a16_from_float,
+  },
+  [GDK_MEMORY_R16G16B16A16_FLOAT] = {
+    GDK_MEMORY_ALPHA_STRAIGHT,
+    8,
+    G_ALIGNOF (guint16),
+    TRUE,
+    TRUE,
+    { GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT },
+    r16g16b16a16_float_to_float,
+    r16g16b16a16_float_from_float,
+  },
+  [GDK_MEMORY_R32G32B32A32_FLOAT] = {
+    GDK_MEMORY_ALPHA_STRAIGHT,
+    16,
+    G_ALIGNOF (float),
+    TRUE,
+    TRUE,
+    { GL_RGBA32F, GL_RGBA, GL_FLOAT },
+    r32g32b32a32_float_to_float,
+    r32g32b32a32_float_from_float,
   }
 };
 
diff --git a/gdk/gdkmemorytexture.h b/gdk/gdkmemorytexture.h
index 114922153e..0769ab44d5 100644
--- a/gdk/gdkmemorytexture.h
+++ b/gdk/gdkmemorytexture.h
@@ -87,6 +87,11 @@ typedef enum {
   GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED,
   GDK_MEMORY_R32G32B32_FLOAT,
   GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED,
+#ifdef GTK_COMPILATION
+  GDK_MEMORY_R16G16B16A16,
+  GDK_MEMORY_R16G16B16A16_FLOAT,
+  GDK_MEMORY_R32G32B32A32_FLOAT,
+#endif
 
   GDK_MEMORY_N_FORMATS
 } GdkMemoryFormat;
diff --git a/gdk/loaders/gdkpng.c b/gdk/loaders/gdkpng.c
index 95e8cf2f66..eb8b392dea 100644
--- a/gdk/loaders/gdkpng.c
+++ b/gdk/loaders/gdkpng.c
@@ -206,30 +206,6 @@ unpremultiply_float_to_16bit (guchar *data,
     }
 }
 
-static void
-premultiply_16bit (guchar *data,
-                   int     width,
-                   int     height,
-                   int     stride)
-{
-  gsize x, y;
-  guint16 *src;
-
-  for (y = 0; y < height; y++)
-    {
-      src = (guint16 *)data;
-      for (x = 0; x < width; x++)
-        {
-          float alpha = src[x * 4 + 3] / 65535.f;
-          src[x * 4    ] = (guint16) CLAMP (src[x * 4    ] * alpha, 0.f, 65535.f);
-          src[x * 4 + 1] = (guint16) CLAMP (src[x * 4 + 1] * alpha, 0.f, 65535.f);
-          src[x * 4 + 2] = (guint16) CLAMP (src[x * 4 + 2] * alpha, 0.f, 65535.f);
-        }
-
-      data += stride;
-    }
-}
-
 /* }}} */
 /* {{{ Public API */ 
 
@@ -333,7 +309,7 @@ gdk_load_png (GBytes  *bytes,
         }
       else
         {
-          format = GDK_MEMORY_R16G16B16A16_PREMULTIPLIED;
+          format = GDK_MEMORY_R16G16B16A16;
         }
       break;
     case PNG_COLOR_TYPE_RGB:
@@ -383,9 +359,6 @@ gdk_load_png (GBytes  *bytes,
   png_read_image (png, row_pointers);
   png_read_end (png, info);
 
-  if (format == GDK_MEMORY_R16G16B16A16_PREMULTIPLIED)
-    premultiply_16bit (buffer, width, height, stride);
-
   out_bytes = g_bytes_new_take (buffer, height * stride);
   texture = gdk_memory_texture_new (width, height, format, out_bytes, stride);
   g_bytes_unref (out_bytes);
@@ -445,10 +418,13 @@ gdk_save_png (GdkTexture *texture)
       break;
 
     case GDK_MEMORY_R16G16B16:
+    case GDK_MEMORY_R16G16B16A16:
     case GDK_MEMORY_R16G16B16A16_PREMULTIPLIED:
     case GDK_MEMORY_R16G16B16_FLOAT:
+    case GDK_MEMORY_R16G16B16A16_FLOAT:
     case GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED:
     case GDK_MEMORY_R32G32B32_FLOAT:
+    case GDK_MEMORY_R32G32B32A32_FLOAT:
     case GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED:
       data = g_malloc_n (width * 16, height);
       gdk_texture_download_float (mtexture, (float *)data, width * 4);


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