[gtk/image-loading: 3/14] Save pngs without gdk-pixbuf




commit 1e6df991d95e891ceb17073f02eb63082bbda963
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Sep 12 09:24:59 2021 -0400

    Save pngs without gdk-pixbuf
    
    Use our own loader for pngs, which will allow
    us to save e.g. 16-bit data in the future.

 gdk/gdktexture.c | 36 ++++++++++++------------------------
 1 file changed, 12 insertions(+), 24 deletions(-)
---
diff --git a/gdk/gdktexture.c b/gdk/gdktexture.c
index 4da14d1e98..578d521cb3 100644
--- a/gdk/gdktexture.c
+++ b/gdk/gdktexture.c
@@ -630,30 +630,18 @@ gboolean
 gdk_texture_save_to_png (GdkTexture *texture,
                          const char *filename)
 {
-  cairo_surface_t *surface;
-  cairo_status_t status;
-  gboolean result;
-
-  g_return_val_if_fail (GDK_IS_TEXTURE (texture), FALSE);
-  g_return_val_if_fail (filename != NULL, FALSE);
-
-  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
-                                        gdk_texture_get_width (texture),
-                                        gdk_texture_get_height (texture));
-  gdk_texture_download (texture,
-                        cairo_image_surface_get_data (surface),
-                        cairo_image_surface_get_stride (surface));
-  cairo_surface_mark_dirty (surface);
-
-  status = cairo_surface_write_to_png (surface, filename);
-
-  if (status != CAIRO_STATUS_SUCCESS ||
-      cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS)
-    result = FALSE;
-  else
-    result = TRUE;
+  GBytes *bytes;
+  gboolean result = FALSE;
 
-  cairo_surface_destroy (surface);
+  bytes = gdk_save_png (texture);
+  if (bytes)
+    {
+      result = g_file_set_contents (filename,
+                                    g_bytes_get_data (bytes, NULL),
+                                    g_bytes_get_size (bytes),
+                                    NULL);
+      g_bytes_unref (bytes);
+    }
 
-  return result;
+   return result;
 }


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