[gtk/gamma-shenanigans: 1/2] Add gdk_texture_save_to_file




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

    Add gdk_texture_save_to_file
    
    This is a new API which avoids encoding the file format
    into the function name, so we can change the format we
    save textures in down the road without having to change
    API.

 gdk/gdktexture.c | 39 +++++++++++++++++++++++++++++++++++++++
 gdk/gdktexture.h |  4 ++++
 2 files changed, 43 insertions(+)
---
diff --git a/gdk/gdktexture.c b/gdk/gdktexture.c
index d12c5af02b..38ea922a9f 100644
--- a/gdk/gdktexture.c
+++ b/gdk/gdktexture.c
@@ -677,3 +677,42 @@ gdk_texture_save_to_png (GdkTexture *texture,
 
   return result;
 }
+
+/**
+ * gdk_texture_save_to_file:
+ * @texture: a `GdkTexture`
+ * @filename: (type filename): the filename to store to
+ * @error: Return location for an error
+ *
+ * Store the given @texture to the @filename.
+ *
+ * GTK will choose a suitable file format to save the data in
+ * depending on the format of the texture.
+ *
+ * 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_file (GdkTexture  *texture,
+                          const char  *filename,
+                          GError     **error)
+{
+  g_return_val_if_fail (GDK_IS_TEXTURE (texture), FALSE);
+  g_return_val_if_fail (filename != NULL, FALSE);
+
+  if (!gdk_texture_save_to_png (texture, filename))
+    {
+      g_set_error_literal (error,
+                           G_IO_ERROR, G_IO_ERROR_FAILED,
+                           "Failed to save to png");
+      return FALSE;
+    }
+
+  return TRUE;
+}
diff --git a/gdk/gdktexture.h b/gdk/gdktexture.h
index f3d0bc9765..2e49705b65 100644
--- a/gdk/gdktexture.h
+++ b/gdk/gdktexture.h
@@ -62,6 +62,10 @@ void                    gdk_texture_download                   (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_file               (GdkTexture      *texture,
+                                                                const char      *filename,
+                                                                GError         **error);
 
 G_END_DECLS
 


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