After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 797137 - avoid using deprecated gdk_pixbuf_new_from_inline()
avoid using deprecated gdk_pixbuf_new_from_inline()
Status: RESOLVED FIXED
Product: gnome-perl
Classification: Bindings
Component: Gtk3
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: gtk2-perl-bugs
gtk2-perl-bugs
Depends on:
Blocks:
 
 
Reported: 2018-09-13 11:57 UTC by Simon McVittie
Modified: 2019-09-13 08:54 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Simon McVittie 2018-09-13 11:57:28 UTC
libgtk3-perl currently uses gdk_pixbuf_new_from_inline() to implement Gtk3::Gdk::Pixbuf::new_from_data, because using gdk_pixbuf_new_from_data() would require being able to hand over ownership of a buffer to gdk-pixbuf, whereas gdk_pixbuf_new_from_inline() copies the input. However, gdk_pixbuf_new_from_inline() is deprecated.

A gdk-pixbuf maintainer recommends[1] using GBytes and new_from_bytes(), which is also what pygobject does in its own overrides:

> # /usr/lib/python3/dist-packages/gi/overrides/GdkPixbuf.py
> @override
> class Pixbuf(GdkPixbuf.Pixbuf):
> 
>     @classmethod
>     def new_from_data(
>             cls, data, colorspace, has_alpha, bits_per_sample,
>             width, height, rowstride,
>             destroy_fn=None, *destroy_fn_data):
> 
>         if destroy_fn is not None:
>             w = PyGIDeprecationWarning("destroy_fn argument deprecated")
>             warnings.warn(w)
>         if destroy_fn_data:
>             w = PyGIDeprecationWarning("destroy_fn_data argument deprecated")
>             warnings.warn(w)
> 
>         data = GLib.Bytes.new(data)
>         return cls.new_from_bytes(
>             data, colorspace, has_alpha, bits_per_sample,
>             width, height, rowstride)

In Perl I think that would be spelled something like:

sub Gtk3::Gdk::Pixbuf::new_from_data {
  my ($class, $data, $colorspace, $has_alpha, $bits_per_sample, $width, $height, $rowstride) = @_;
  return Gtk3::Gdk::Pixbuf->new_from_bytes(GLib::Bytes->new($data),
                                           $colorspace, $has_alpha,
                                           $bits_per_sample, $width,
                                           $height, $rowstride);
}

(but please note that I have not tested that at all.)

It looks as though this might even add support for bits per sample != 8
and non-RGB colour spaces as a side effect, if the underlying library
ever supports them (but it currently doesn't, and that probably won't
change).

[1] on https://gitlab.gnome.org/GNOME/gdk-pixbuf/merge_requests/17
Comment 1 intrigeri 2019-07-16 14:39:57 UTC
https://gitlab.gnome.org/GNOME/perl-gtk3/merge_requests/2 implements what Simon suggested.