[cairo] cairo+DevIL ?

John Ellson john.ellson at comcast.net
Thu Aug 23 08:42:34 PDT 2007

Vladimir Vukicevic wrote:
> John Ellson wrote:
>> In a January 2007 posting
>> <http://lists.cairographics.org/archives/cairo/2007-January/009198.html>
>> Vlad suggested that DevIL
>>     <http://openil.sourceforge.net/>
>> would make a good backend for rendering other bitmap formats (gif, 
>> jpeg, tga, ...) from cairo.
>> Is this still the best-practice recommendation?   Is there any sample 
>> code out there?
>> I've made an initial attempt to bind the two together.  The problem 
>> I'm having at the moment
>> is that the in-memory data formats seem to be incompatible:
>> Do I really have to byte-twiddle the image data just to transfer 
>> between these two fine libraries?
> I'm not sure if there is a single best-practice recommendation; I've 
> certainly had good experience using DevIL in the past, though I have 
> never used it with cairo.  It's interesting that DevIL only provides 
> IL_RGBA and IL_BGRA; the documentation annoyingly states that these 
> formats are "self explanatory", which they are not.  Maybe IL_BGRA 
> happens to be compatible, if they're talking about byte order?
>     - Vlad

Just a followup on this topic.   In graphviz I've now built three new 
backends for cairo.
My immediate needs are for GIF and JPG.

    DevIL        + supports JPG
                 - no support for GIF output
                 + can use cairo's image data allocation without memory 
free problems
                 + IL_BGRA matches CAIRO_FORMAT_ARGB32
                 - Y ordering is inverted requiring an in-place 
byte-flipping pass over the data
                    (can't invert Y in cairo because pango doesn't 
support this for text)
                 - output to FILE* using ilSaveF() truncates output files
                    (this bug has been reported via Fedora bugzilla, a 
fix has been
                    reported and should be available soon)

    gdk-pixbuf:  + supports JPG
                 - no support for GIF output
                 + can use cairo's image data allocation without memory 
free problems
                 - byte ordering is ABGR, requiring an in-place 
byte-flipping pass over the data
                 + Y ordering matches
                 ++ accepts user-supplier file io functions

     gd:         + supports JPG
                 + supports GIF
                 - will internally free the image data when generating 
paletted images,
                    so cairo's data has to be copied
                 - ARGB byte ordering matches, but alpha channel is 
transparency 0..127,
                    rather than opaqueness 0..255 used in cairo.
                 + Y ordering matches
                 + output to FILE* works

So currently graphviz's preferred plugins are: gdk-pixbuf for JPG, and 
gd for GIF.

It would be nice to have a set of bitmap file formatter backends that 
efficiently accept a cairo ARGB surface. I think gdk-pixbuf is where 
this belongs.  One of the projects should bite-the-bullet and support 
the other's byte ordering.

If anyone wants to see my hacks, they are in the sources of the latest 
graphviz development snapshots from http://www.graphviz.org/ in:


More information about the cairo mailing list