[cairo] Large image support?

Ian Britten britten at caris.com
Wed Apr 1 07:57:35 PDT 2009


Simon Budig 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".
> 
> for (all tiles) {
>    surface = cairo_image_surface_create_for_data (tmp_buf,
>                                                   CAIRO_FORMAT_A8,
>                                                   width, height,
>                                                   stride);
> 
>    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.

Ya, we had kicked around a similar idea here already...  A couple of
issues:
- Our 'canvas' just receives the data once, and isn't really in a
   position to trigger multiple redraws.  However, I might be able to
   come up with something (It's solely our problem)
- A large portion of our data is vector, not raster.  I can see
   cases where a tile may end up lacking data, due to the main part
   of the vector data being prematurely discarded for not falling
   within the tile (eg: Point data that draws extra labels, etc).

So, what about a slightly different approach?
I know from my PDF usage that Cairo maintains the vector data
internally somehow (non-raster).  Could I maybe:
- Render all my data to a PDF (or similar) surface first, as I
   currently do.  Then, once done:
- Make a temporary image tile
- Iterate over the PDF surface an appropriate number of times.
- On each iteration, copy from the PDF surface to my tile.
- Write/concatenate the tile to the output image file.
My (limited) understanding is that Cairo should/will flatten and
rasterize the PDF data when copied to an image surface, thus
giving me the raster pixels I need.  As well, since my main
target surface is PDF, it won't allocate that 50000x50000 pixel
buffer, bypassing that problem.

Thoughts?  Problems?
As always, many thanks for any feedback!
Ian


More information about the cairo mailing list