[gtk/image-loading: 8/14] Add gdk_texture_save_to_tiff




commit 345bd19b5794b8debf21d54de1c0bf409f399a72
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Sep 7 09:20:05 2021 -0400

    Add gdk_texture_save_to_tiff
    
    This is a companion to gdk_texture_save_to_png, using
    the tiff format, which will let us avoid lossy conversion
    of HDR data, since we can store floating point data.

 gdk/gdktexture.c | 39 +++++++++++++++++++++++++++++++++++++++
 gdk/gdktexture.h |  3 +++
 2 files changed, 42 insertions(+)
---
diff --git a/gdk/gdktexture.c b/gdk/gdktexture.c
index 1b6be445f2..dbe0cd63e0 100644
--- a/gdk/gdktexture.c
+++ b/gdk/gdktexture.c
@@ -648,3 +648,42 @@ gdk_texture_save_to_png (GdkTexture *texture,
 
   return result;
 }
+
+/**
+ * gdk_texture_save_to_tiff:
+ * @texture: a `GdkTexture`
+ * @filename: (type filename): the filename to store to
+ *
+ * Store the given @texture to the @filename as a TIFF file.
+ *
+ * GTK will attempt to store data without loss.
+ *
+ * This is a utility function intended for debugging and testing.
+ * If you want more control over formats, proper error handling or
+ * want to store to a `GFile` or other location, you might want to
+ * look into using the gdk-pixbuf library.
+ *
+ * Returns: %TRUE if saving succeeded, %FALSE on failure.
+ *
+ * Since: 4.6
+ */
+gboolean
+gdk_texture_save_to_tiff (GdkTexture  *texture,
+                          const char  *filename)
+{
+  GBytes *bytes;
+  gboolean result;
+
+  bytes = gdk_save_tiff (texture);
+
+  if (!bytes)
+    return FALSE;
+
+  result = g_file_set_contents (filename,
+                                g_bytes_get_data (bytes, NULL),
+                                g_bytes_get_size (bytes),
+                                NULL);
+  g_bytes_unref (bytes);
+
+  return result;
+}
diff --git a/gdk/gdktexture.h b/gdk/gdktexture.h
index 9e3b7a93fa..dd7480d13b 100644
--- a/gdk/gdktexture.h
+++ b/gdk/gdktexture.h
@@ -66,6 +66,9 @@ void                    gdk_texture_download_float             (GdkTexture
 GDK_AVAILABLE_IN_ALL
 gboolean                gdk_texture_save_to_png                (GdkTexture      *texture,
                                                                 const char      *filename);
+GDK_AVAILABLE_IN_4_6
+gboolean                gdk_texture_save_to_tiff               (GdkTexture      *texture,
+                                                                const char      *filename);
 
 G_END_DECLS
 


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