Re: Pixbuf to Cairo and vice versa
- From: Mario Kemper <mario kemper googlemail com>
- To: gtk-perl-list gnome org
- Subject: Re: Pixbuf to Cairo and vice versa
- Date: Thu, 14 Jul 2011 11:12:46 +0200 (MESZ)
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?
Regards
Mario
----- UrsprÃngliche Mail -----
Von: "Mario Kemper" <mario kemper googlemail com>
An: gtk-perl-list gnome org
Gesendet: Mittwoch, 13. Juli 2011 15:41:23
Betreff: Pixbuf to Cairo and vice versa
Hi,
I was benchmarking one of my applications today and one of the
slowest operations I detected is related to the Cairo > Pixbuf
conversion.
This is what the code is currently doing:
1) Get the current screen content as a pixbuf
my $clean_pixbuf = Gtk2::Gdk::Pixbuf->get_from_drawable(
$self->{_root}, undef, 0, 0, 0, 0,
$self->{_root}->{w},
$self->{_root}->{h}
);
2) I want to draw something on the pixbuf with Cairo
my $surface = Cairo::ImageSurface->create( 'argb32',
$self->{_root}->{w}, $self->{_root}->{h} );
my $cr = Cairo::Context->create($surface);
Gtk2::Gdk::Cairo::Context::set_source_pixbuf( $cr, $clean_pixbuf, 0,
0 );
$cr->paint;
<<< more painting goes here >>>
3) Show the final image in a widget, i.e. convert the cairo surface
back to a pixbuf
#write surface to pixbuf
my $loader = Gtk2::Gdk::PixbufLoader->new;
$surface->write_to_png_stream(
sub {
my ( $closure, $data ) = @_;
$loader->write($data);
}
);
$loader->close;
<<< use $loader->get_pixbuf somewhere >>>
Especially the last operation is pretty slow (the root window is big,
dual monitor). My question is: Is this the correct workflow to do
such things? Is there any way to avoid the conversions between
pixbufs and cairo?
Thanks in advance.
Bye
Mario
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]