Re: Confused about GDKPixBuf/Cairo interaction



Hi,

Le 18/02/2013 11:10, Rena a écrit :
Hi, just joined the mailing list, been using GTK and related projects
for a while now. Recently I've been developing a Game Boy emulator
that uses GtkDrawingArea and GdkPixbuf to display the game screen.

In addition to the game output I want to also be able to draw text and
shapes on the display window, and Cairo seems to be the ideal way to
draw shapes. I'm already using Cairo to copy the Pixbuf to the
GtkDrawingArea, so that seems like a good sign that Cairo and
GdkPixbuf should interact nicely.

However, it doesn't look like they should be able to interact at all,
as they don't seem to be able to agree on a pixel format:
http://developer.gnome.org/gdk-pixbuf/stable/gdk-pixbuf-Image-Data-in-Memory.html#gdk-pixbuf-new-from-data
"Currently only RGB images with 8 bits per sample are supported."
http://developer.gnome.org/gdk-pixbuf/stable/gdk-pixbuf-The-GdkPixbuf-Structure.html#image-data
"p[0] = red; p[1] = green; p[2] = blue; p[3] = alpha;"
That seems to suggest that GdkPixbuf supports only RGB (24-bit) and
RGBA (32-bit). But...

http://www.cairographics.org/manual/cairo-Image-Surfaces.html#cairo-format-t
CAIRO_FORMAT_ARGB32 is ARGB ("each pixel is a 32-bit quantity, with
alpha in the upper 8 bits..."). CAIRO_FORMAT_RGB24 is xRGB ("each
pixel is a 32-bit quantity, with the upper 8 bits unused..."). Neither
of those are RGB or RGBA. So, how can Cairo operate on a surface
provided by GdkPixbuf?

I don't really get it.  You say you already use Cairo to draw your
pixbuf, but also that you can't see how to use a GdkPixbuf with Cairo?
This seems contradictory to me.

Anyway, what you want is gdk_cairo_set_source_pixbuf()[1] that does the
appropriate conversions to create a Cairo pattern from a GdkPixbuf.
Then you can use this pattern like any other Cairo pattern (e.g.
cairo_paint()), and you're done.

Hope it helps.
Colomban

[1]
http://developer.gnome.org/gdk/stable/gdk-Cairo-Interaction.html#gdk-cairo-set-source-pixbuf


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