GNOME Bugzilla – Bug 74291
Feature request: gdk_pixbuf_new_from_raw_data ()
Last modified: 2013-12-19 03:29:30 UTC
Like to have convenience function that behaves like gdk_pixbuf_new_from_file(), except uses in-memory buffer. GdkPixbufLoader can do this, but I'm the third idiot who missed that in the docs, and Havoc suggests maybe a convenience function do to this. Alternative is better documentation around gdk_pixbuf_new_from_file(), except that things will fall apart in function index. So maybe a function is indeed the way to go..
How about GdkPixbuf * gdk_pixbuf_new_from_io_channel (GIOChannel *channel, GError **error); together with GIOChannel * g_io_channel_new_from_memory (gchar *mem, gsize size, gchar *mode); This would even allow us to deprecate gdk_pixbuf_new_from_file in the long run.
Even with new_from_io_channel I'd keep new_from_file and add new_from_memory, as the io_channel thing is fairly inconvenient.
Why are io channels inconvenient ? One argument for keeping new_from_file is that some image libs only accept a FILE *, e.g. libtiff.
pixbuf = pixbuf_new_from_file() is just easier to learn and use than: iochannel = iochannel_new_from_file() pixbuf = pixbuf_new_from_iochannel() iochannel_unref ()
Shoving this one off; I think we have sufficient API work for gdk-pixbuf for this release already.
Created attachment 98727 [details] [review] A possible initial implementation. I too think that a function like this would be practical and useful, so here is my incarnation. Feel free to add to your programs or to GTK+ maybe.
Created attachment 120921 [details] [review] Implement pixbuf_new_from_buffer in gdk-pixbuf I actually had a use for this code recently and now happen to find this bug while doing BugTriaging. So I implemented gdk_pixbuf_new_from_buffer in GdkPixbuf proper based on the example implementation. I added a mime_type argument, since if you for instance need to load ICO files GdkPixbuf is likely to reject them as "unknown format", which would make the function only half as good without the argument. If others would prefer a _new_with_buffer_and_mime_type instead, I can modify the patch appropriately but I'm not sure if that's needed. The current function accepts a NULL mime type which practicely means it will ignore it.
we have grown a variety of new api in this area in the meantime: gdk_pixbuf_new_from_stream and variants. So I think this need has been addressed.