Re: Pixbuf to Cairo and vice versa



On 2011-07-14 at 11:12, Mario Kemper wrote:
Update:

I've found out that Gtk2::Gdk::Pixbuf->new_from_data is much faster than the Gtk2::Gdk::PixbufLoader 
approach. This is how the code looks right now:

my $width = $surface->get_width;
my $height = $surface->get_height;
my $stride = $surface->get_stride;
my $data = $surface->get_data;
my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_data ($data,'rgb',1,8,$width,$height,$stride);


The problem is that the colors of the resulting pixbuf are not correct. I think I am doing something wrong 
here. Are the parameters above correct? The surface is 'argb32' - this might be the problem, right?


Cairo and GdkPixbuf have different ordering for the pixel formats. see
this email threads:

  http://lists.freedesktop.org/archives/cairo/2006-July/007432.html
  https://mail.gnome.org/archives/gtkmm-list/2007-May/msg00111.html

in short: you have to unpremultiply the alpha, and repack the channels
if you want to put the contents of an image surface into a pixbuf.

ciao,
 Emmanuele.

-- 
W: http://www.emmanuelebassi.name
B: http://blogs.gnome.org/ebassi



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