Re: canvas, cairo and/or pixbufs? (was Re: Application Approach)



On Sun, 2006-11-05 at 09:35 -0700, Jim George wrote:
I suppose one problem with the Pixbuf approach is that a Pixbuf is not
a drawable (unlike a Pixmap), so you either need to come up with your
own drawing routines for lines and such, or draw onto a Pixmap and use
gdk_pixbuf_get_from_drawable. If there's a better way, do let me know
(it's one area where my application could use some speedup - I use the
second approach).

You can use Cairo to draw to the pixbuf.

You will need some information about the pixbuf:
gdk_pixbuf_get_pixels()
gdk_pixbuf_get_width()
gdk_pixbuf_get_height()
gdk_pixbuf_get_rowstride()

which you then give to Cairo to wrap a cairo_t around the raw pixel
buffer:

cairo_image_surface_create_for_data()

(you might need to modify the rowstride value before passing it to cairo
-- I haven't checked the details.)

Make sure that the pixbuf is in a Cairo-friendly format (ARGB32 or
RGB24).

In order to make Cairo and your own drawing code coexist nicely, you
will need to tell Cairo when it owns the pixbuf data and when it
doesn't:

cairo_surface_mark_dirty()
cairo_surface_mark_dirty_rectangle()
cairo_surface_flush()

-Peter




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