[cairo] Large image support?

Simon Budig simon at budig.de
Wed Apr 1 05:41:28 PDT 2009

Ian Britten (britten at caris.com) wrote:
> 2) Creating large images
>     We have workflows where users need to generate very large
>     high-res images (eg: 50000x50000 pixels).  Again in this case,
>     simply trying to allocate a Cairo image surface that size will
>     likely exceed the available memory.

In Gimp images internally are stored in relatively small "tiles". When
using cairo to render to these tiles (actually usually masks, which are
organized in tiles as well but are 8-bit alpha) we basically use this:

for (all tiles) {
   surface = cairo_image_surface_create_for_data (tmp_buf,
                                                  width, height,

   cairo_surface_set_device_offset (surface, -x0, -y0);
   cr = cairo_create (surface);
    [drawing code]
   cairo_destroy (cr);
   cairo_surface_destroy (surface);

i.e. we render the same drawing operations multiple times to different
tiles, adjusting the device offset accordingly.

We're still iterating over all pixels, but are doing so in a more local
manner, so that individual tiles can actually easily be swapped out etc.

Hope this helps,
              simon at budig.de              http://simon.budig.de/

More information about the cairo mailing list