[perl-gtk3: 1/2] Avoid using deprecated gdk_pixbuf_new_from_inline() with gdk-pixbuf >= 2.32
- From: Torsten Schönfeld <tsch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [perl-gtk3: 1/2] Avoid using deprecated gdk_pixbuf_new_from_inline() with gdk-pixbuf >= 2.32
- Date: Mon, 5 Aug 2019 18:59:12 +0000 (UTC)
commit 900960af2f89cae579024092d9f46c7a04bfb545
Author: intrigeri <intrigeri boum org>
Date: Tue Jul 16 14:03:51 2019 +0000
Avoid using deprecated gdk_pixbuf_new_from_inline() with gdk-pixbuf >= 2.32
Bug-Debian: https://bugs.debian.org/908745
Closes: https://bugzilla.gnome.org/show_bug.cgi?id=797137
As reported by Simon McVittie <smcv debian org>:
"
[…] 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
[…]
[1] on https://gitlab.gnome.org/GNOME/gdk-pixbuf/merge_requests/17
"
This code is based by the one @smcv suggested, edited by myself to support the
case when $data is an array ref that contains unpacked bytes, like the previous
implementation did.
lib/Gtk3.pm | 47 +++++++++++++++++++++++++++++------------------
1 file changed, 29 insertions(+), 18 deletions(-)
---
diff --git a/lib/Gtk3.pm b/lib/Gtk3.pm
index f90af7e..89fb2b2 100644
--- a/lib/Gtk3.pm
+++ b/lib/Gtk3.pm
@@ -2121,30 +2121,41 @@ sub Gtk3::Gdk::Pixbuf::get_pixels {
}
=item * C<Gtk3::Gdk::Pixbuf::new_from_data> is reimplemented in terms of
-C<new_from_inline> for correct memory management. No C<destroy_fn> and
+C<new_from_bytes> (with gdk-pixbuf >= 2.32) or C<new_from_inline> (with
+gtk-pixbuf < 2.32) for correct memory management. No C<destroy_fn> and
C<destroy_fn_data> arguments are needed.
=cut
sub Gtk3::Gdk::Pixbuf::new_from_data {
my ($class, $data, $colorspace, $has_alpha, $bits_per_sample, $width, $height, $rowstride) = @_;
- die 'Only RGB is currently supported' unless $colorspace eq 'rgb';
- die 'Only 8 bits per pixel are currently supported' unless $bits_per_sample == 8;
- my $length = Gtk3::Gdk::PIXDATA_HEADER_LENGTH () +
- $rowstride*$height;
- my $type = Gtk3::Gdk::PixdataType->new ([qw/sample_width_8 encoding_raw/]);
- $type |= $has_alpha ? 'color_type_rgba' : 'color_type_rgb';
- my @header_numbers = (0x47646b50,
- $length,
- $$type, # FIXME: This kind of breaks encapsulation.
- $rowstride,
- $width,
- $height);
- # Convert to 8 bit unsigned chars, padding to 32 bit little-endian first.
- my @header = map { unpack ("C*", pack ("N", $_)) } @header_numbers;
- my $inline_data = _unpack_unless_array_ref ($data);
- unshift @$inline_data, @header;
- return Gtk3::Gdk::Pixbuf->new_from_inline ($inline_data);
+ if (Gtk3::Gdk::Pixbuf::CHECK_VERSION (2, 32, 0)) {
+ my $packed_data = ref($data) eq 'ARRAY' ? pack 'C*', @$data : $data;
+ return Gtk3::Gdk::Pixbuf->new_from_bytes(
+ Glib::Bytes->new($packed_data),
+ $colorspace, $has_alpha,
+ $bits_per_sample, $width,
+ $height, $rowstride);
+ } else {
+ die 'Only RGB is currently supported' unless $colorspace eq 'rgb';
+ die 'Only 8 bits per pixel are currently supported'
+ unless $bits_per_sample == 8;
+ my $length = Gtk3::Gdk::PIXDATA_HEADER_LENGTH () +
+ $rowstride*$height;
+ my $type = Gtk3::Gdk::PixdataType->new ([qw/sample_width_8 encoding_raw/]);
+ $type |= $has_alpha ? 'color_type_rgba' : 'color_type_rgb';
+ my @header_numbers = (0x47646b50,
+ $length,
+ $$type, # FIXME: This kind of breaks encapsulation.
+ $rowstride,
+ $width,
+ $height);
+ # Convert to 8 bit unsigned chars, padding to 32 bit little-endian first.
+ my @header = map { unpack ("C*", pack ("N", $_)) } @header_numbers;
+ my $inline_data = _unpack_unless_array_ref ($data);
+ unshift @$inline_data, @header;
+ return Gtk3::Gdk::Pixbuf->new_from_inline ($inline_data);
+ }
}
=item * C<Gtk3::Gdk::Pixbuf::new_from_inline> does not take a C<copy_pixels>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]