[gtk/wip/otte/color-profiles: 96/111] png: Add private formats for weird PNG stuff
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/color-profiles: 96/111] png: Add private formats for weird PNG stuff
- Date: Sat, 2 Oct 2021 02:53:26 +0000 (UTC)
commit e8e44e3ea7a37484f59dfc2c81d0a9b23199b3f8
Author: Benjamin Otte <otte redhat com>
Date: Sun Sep 26 16:47:34 2021 +0200
png: Add private formats for weird PNG stuff
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 f7d0c97978..d5725bd88a 100644
--- a/gdk/gdkmemoryformat.c
+++ b/gdk/gdkmemoryformat.c
@@ -343,6 +343,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] = {
+ "R16G16B16A16",
+ GDK_MEMORY_ALPHA_STRAIGHT,
+ 8,
+ G_ALIGNOF (guint16),
+ TRUE,
+ { GL_RGBA16, GL_RGBA, GL_UNSIGNED_SHORT },
+ r16g16b16a16_to_float,
+ r16g16b16a16_from_float,
+ },
+ [GDK_MEMORY_R16G16B16A16_FLOAT] = {
+ "R16G16B16A16_FLOAT",
+ GDK_MEMORY_ALPHA_STRAIGHT,
+ 8,
+ G_ALIGNOF (guint16),
+ TRUE,
+ { GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT },
+ r16g16b16a16_float_to_float,
+ r16g16b16a16_float_from_float,
+ },
+ [GDK_MEMORY_R32G32B32A32_FLOAT] = {
+ "R32G32B32A32_FLOAT",
+ GDK_MEMORY_ALPHA_STRAIGHT,
+ 16,
+ G_ALIGNOF (float),
+ 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 f5f0198991..f93b098ed7 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 19efdcffe5..7130620af8 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]