From 941fdb7e464a43567bbebc09930120fc37123afd Mon Sep 17 00:00:00 2001 From: Cameron White Date: Mon, 24 Jan 2022 23:02:34 -0500 Subject: [PATCH] Implement Gdk.Pixbuf.SaveToStream() and SaveToStreamv() This matches the other saving-related methods for Gdk.Pixbuf - `gdk_pixbuf_save_to_stream` was skipped for the auto-generated bindings (with the warning "Ellipsis parameter: hide and bind manually") - `gdk_pixbuf_save_to_streamv` was in the generated bindings, but incorrect: the `option_keys` and `option_values` arguments had type `string` rather than `string[]` --- Source/Libs/GdkSharp/GdkSharp.metadata | 2 ++ Source/Libs/GdkSharp/Pixbuf.cs | 38 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/Source/Libs/GdkSharp/GdkSharp.metadata b/Source/Libs/GdkSharp/GdkSharp.metadata index 8d937d577..cf9a428eb 100644 --- a/Source/Libs/GdkSharp/GdkSharp.metadata +++ b/Source/Libs/GdkSharp/GdkSharp.metadata @@ -109,6 +109,8 @@ 1 1 1 + 1 + 1 1 true 1 diff --git a/Source/Libs/GdkSharp/Pixbuf.cs b/Source/Libs/GdkSharp/Pixbuf.cs index cba3df10a..7ca4b9f7a 100644 --- a/Source/Libs/GdkSharp/Pixbuf.cs +++ b/Source/Libs/GdkSharp/Pixbuf.cs @@ -374,5 +374,43 @@ namespace Gdk { throw new GLib.GException (error); return saved; } + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + delegate bool d_gdk_pixbuf_save_to_stream(IntPtr raw, IntPtr stream, IntPtr type, IntPtr cancellable, out IntPtr error, IntPtr dummy); + static d_gdk_pixbuf_save_to_stream gdk_pixbuf_save_to_stream = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GdkPixbuf), "gdk_pixbuf_save_to_stream")); + + public unsafe bool SaveToStream(GLib.OutputStream stream, string type, GLib.Cancellable cancellable) + { + IntPtr error = IntPtr.Zero; + IntPtr native_type = GLib.Marshaller.StringToPtrGStrdup(type); + bool ret = gdk_pixbuf_save_to_stream(Handle, stream == null ? IntPtr.Zero : stream.Handle, native_type, cancellable == null ? IntPtr.Zero : cancellable.Handle, out error, IntPtr.Zero); + GLib.Marshaller.Free(native_type); + + if (error != IntPtr.Zero) + throw new GLib.GException(error); + + return ret; + } + + [UnmanagedFunctionPointer (CallingConvention.Cdecl)] + delegate bool d_gdk_pixbuf_save_to_streamv(IntPtr raw, IntPtr stream, IntPtr type, IntPtr[] option_keys, IntPtr[] option_values, IntPtr cancellable, out IntPtr error); + static d_gdk_pixbuf_save_to_streamv gdk_pixbuf_save_to_streamv = FuncLoader.LoadFunction(FuncLoader.GetProcAddress(GLibrary.Load(Library.GdkPixbuf), "gdk_pixbuf_save_to_streamv")); + + public unsafe bool SaveToStreamv(GLib.OutputStream stream, string type, string[] option_keys, string[] option_values, GLib.Cancellable cancellable) + { + IntPtr error = IntPtr.Zero; + IntPtr native_type = GLib.Marshaller.StringToPtrGStrdup(type); + IntPtr[] native_option_keys = NullTerm (option_keys); + IntPtr[] native_option_values = NullTerm (option_values); + bool ret = gdk_pixbuf_save_to_streamv(Handle, stream == null ? IntPtr.Zero : stream.Handle, native_type, native_option_keys, native_option_values, cancellable == null ? IntPtr.Zero : cancellable.Handle, out error); + GLib.Marshaller.Free (native_type); + ReleaseArray (native_option_keys); + ReleaseArray (native_option_values); + + if (error != IntPtr.Zero) + throw new GLib.GException (error); + + return ret; + } } }