[cairo] cairocffi and GDK-PixBuf for decoding JPEG and other image formats

Bill Spitzak spitzak at gmail.com
Sat Mar 2 11:00:35 PST 2013

It is written for game development which may be a reason it is being 
ignored here, but ImageMagic (sp?) does the job. It reads lots of image 
formats, produces ARGB32, and *only* does images (ie you are not getting 
glib or gtk). It reads hundreds of image formats using a .so system.

I think there are about a dozen others as well.

Should probably look into them.

On 02/27/2013 07:15 PM, Krzysztof Kosiński wrote:
> 2013/2/26 Simon Sapin <simon.sapin at exyr.org>:
>> Hi,
>> A long-standing feature request on cairo has been the ability to decode JPEG
>> and other image formats, just like cairo_image_surface_create_from_png()
>> does for PNG.
>> The response has been that this does not belong in cairo itself.
>> GDK-PixBuf can load many image formats, but uses a different internal format
>> for pixel data. I just added some integration code in cairocffi, to wrap
>> GDK-PixBuf and do the pixel conversion:
>> http://pythonhosted.org/cairocffi/pixbuf.html
>> (cairocffi is a drop-in alternative to pycairo.)
> In Inkscape I wanted to avoid using gdk_cairo_set_source_pixbuf(),
> since it creates a copy and therefore unnecessarily wastes memory.
> This can be a problem when the SVG file contains several full-size
> photos. I used a hack that involves shuffling around the components
> and premultiplying alpha in the pixbuf data, then calling
> cairo_image_surface_create_for_data(). This is followed by calling
> cairo_set_user_data() with g_object_unref() as a destroy function to
> store a reference to the GdkPixbuf in the image surface. Naturally, if
> the pixbuf is not reverted to its original state before e.g. saving
> it, the output will be garbled.
> This hack could be avoided if there was a way to specify image formats
> other than Cairo's default of native-endian ARGB with premultiplied
> alpha, so that the data in a GdkPixbuf could be used to create a Cairo
> image surface without modifications.
> Regards, Krzysztof

More information about the cairo mailing list