[cairo] JPEG Support For Libcairo

Behdad Esfahbod behdad.esfahbod at gmail.com
Thu Dec 31 05:02:53 PST 2015

On 15-12-29 12:16 PM, Adrian Johnson wrote:
> On 29/12/15 12:35, Enrico Weigelt, metux IT consult wrote:
>> On 28.12.2015 15:12, Bernhard Fischer wrote:
>>> I implemented two small functions which read/write JPEG into/from a Cairo 
>>> image surface.
>> Added it to cairo tree - see patches.
> The API is missing the stream functions. JPEG API has previously been
> proposed [1]. Behdad's reply [2] summarizes the reason the patches were
> declined:

Hi everyone,

Indeed, at the time, the impression I got from Carl and others was that the
PNG support is just a convenience and everything else should be done on top.
gtkpixbuf is one such library that supports a bunch of formats.  I imagine the
glib dependency might not be desirable, so someone might want to start a new

At Google, we have code for a faster PNG export as well as JPG and a couple
other formats.  I have had wanted to open source it for a while, but it hasn't
been priority.

I still think these should go in a separate library, for the following reasons:

  - It should be possible to implement reader/writer for new / custom formats
solely on top of the public API.  In other words, if there's a need for such a
reader/writer that is not possible with the public API, then the public API
needs to be extended,

  - There are many many formats, and adding support for all of them is both
impractical and not the focus of whatever limited maintenance resources we
have left for cairo,

  - Implementing reader/writers correctly (the stream and non-stream versions,
threadsafe, etc) is a lot of work, with diminishing returns as soon as you
address the top 2 / 3 formats, but if we establish that new formats are
accepted in cairo itself, there will forever be people who want to contribute
implementation for one more format.  It's a slippery slope we don't want to go

Maybe one can write a single-file library to hook up cairo to the image
routines here:


Cheers, and happy Gregorian new year in advance,


>   "PNG support is cairo's way to import and export images, and it
>   does the job just like that, losslessly and in a rather efficient
>   format. Anything else should be implemented on top of other cairo
>   API.  It's like the toy text api."
> [1] http://lists.cairographics.org/archives/cairo/2007-January/009194.html
> [2] http://lists.cairographics.org/archives/cairo/2007-January/009200.html

More information about the cairo mailing list