Re: Correct use of pixbuf, pixmap, and image?



muppet wrote:


1. create pixmap from the initial pixbuf and set the pixmap into the image
2. draw on the pixmap
3. hide the ScrolledWindow
4. show the ScrolledWindow


Why the hide and show?


ok, that _was_ unnecessary, but did not solve the problem


Similarly, image data can be stored in "bitmaps" (1-bit images, or maps of bits) or "pixmaps" (maps of more-than-one-bit pixels, or pixel maps). These are stored on the server, at device bit resolution and bit depth, and this can be manipulated quite quickly.


looking at process info, it seems that X is piling up memory, the code creates a new pixmap every time a new object it selected (a crude way of getting rid of the old selection), but pixmaps should be automatically unref'd since the new pixmap is put into the same place as the old, the code is effectively:

create $self->{pixbuf}
loop: {
   $self->{pixmap} = $self->{pixbuf}->render_pixmap_and_mask;
   $self->{image}->set_from_pixmap($self->{pixmap});

   $self->{pixmap}->draw_line etc.

}




GtkImage provides a way for you to set the source data directly from a pixbuf --- $image->set_from_pixbuf($pixbuf) --- so you could avoid the pixmap/mask stage.


but I can't draw on an image? I need the pixmap for that, I believe.


You can also place a GdkPixbuf into a GnomeCanvas, which gives you more efficient rendering of the changed portions. You could use GnomeCanvasItems for the selected objects text overlays and that sort of stuff, along with scaling and other fun tricks.


hm, .. there's already a lot of scaling going on, I use

image->set_size_request
image->set_alignment

after set_from_pixmap to make the ScrollableWindow show scrollbars appropriately


You'll probably want also check for reference leaks in your code to make sure you're not piling up pixbufs.


should not happen because pixbuf is not touched, and it would show that the memory is used by the app, not X, I think



If using a Canvas is not practical, you can probably drop a few steps by writing some of the more compute-intensive display stuff in C --- if you already have custom C code, then binding your own C widgets to gtk2-perl should be no problem. You could do stuff like render much smaller pieces from the source data and blit them exactly where they need to go in the master pixbuf.


One thing I'm missing is to be able to use gtk's drawing primitives, which are not available for me in C because I'm using only pixbuf there.

Thanks for the info so far.

Ari




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