[cairo] floating point grey scale source/surface

Soeren Sandmann sandmann at daimi.au.dk
Mon Jan 11 09:22:04 PST 2010


> I'm interested in adapting Cairo so that I can draw to a
> floating-point grey-scale image surface. When the drawing is finished
> I would like to save the resulting image to e.g. TIFF.
> I browsed the code a little bit and my guess for doing this is to
> study how filling paths is done for an image surface of type
> IMAGE_FORMAT_A8. Then see how I can copy this behaviour for an image
> type of e.g. IMAGE_FORMAT_AFP, or something.
> After browsing the code I felt a little overwhelmed, what would be a
> good starting point for me?

First of all, thanks for looking at this. A floating point image
surface is something I'm personally interested in as well.

Most of the software rendering is done by the pixman library, which is
also where support for a floating point surface would need to be

> Is rendering to a floating point surface an easy thing to do implement
> in Cairo? I mean, would the current architecture enable such a thing
> without too much hassle, or will I be doing open heart surgery? This
> question may be too vague, I know, my major concern is the amount of
> time I would spend on adding this feature.

There is going to be some hassle involved, because pixman at the
moment doesn't deal with floating point intermediates at all. The two
formats we currently have are 16 bit integers and 32 bit integers. 

To add support for floating point intermediates, three things are
required in pixman:

1. The ability to convert any image format to an 128-bits-per-pixel
   floating point ARGB format.

2. The ability to blend 128 bit fp ARGB buffers together

3. The ability to convert from fp ARGB buffers to any format.

I would suggest simply replacing the 32 bit intermediate format with
the new floating point format since the floating point format would be
plenty precise and since the existing 10bit-per-component formats are
not very fast any way.

Depending on your requirements, you may also need to change the cairo
polygon rasterizer to output floating point alpha masks. I'm not very
familiar with that, so I'll let other people comment on how much
hassle would be involved in that.


More information about the cairo mailing list