[cairo] Supersampling - 1st attempt

Soeren Sandmann sandmann at daimi.au.dk
Tue Aug 10 18:18:47 PDT 2010

Hi Krzysztof,

> Patch contains initial attempt at supersampling in Pixman. Only

This looks like a really good start.

> bitmaps ("bits images") are supersampled, and the resampling filter
> is a simple box filter (average over the subpixels). To test,
> uncomment the fragment in pixman-bits-image.c - this will cause the
> sampling rate to adapt to the transformation matrix.

> Questions:
> 1. Is bits_image_fetch_transformed the right place for
> supersampling?

Yes, although in master that function has been split into two
functions, one that deals with the affine, no-alpha-map case, and one
that deals with projective transformations and alpha maps.

The way I'd add the super sampling is to:

    - introduce a new FAST_PATH flag that is set whenever the sample
      rate is 1.

    - make the affine version require this flag to be set

    - make the projective version do super sampling always (ie., don't
      special case the rate==1 case).

This will be rather slow, but I'd prefer to first get something
working, then add some tests, and then speed it up while making sure
the tests keep passing. See below for some ideas on how to speed
things up.

> 2. Shouldn't we use nearest-neighbor sampling to obtain subpixels?

That's determined by what filter is being used in the call
bits_fetch_pixel_filtered(). So if you call


with FILTER_NEAREST, then the subpixel will be obtained through
nearest-neighbor sampling. If you set it to LINEAR, then it will use
bilinear interpolation.

> 3. The performance isn't very good at the moment - any ideas on how it
> could be improved?

There are a number of things that could be done:

- The code as it stands has some divisions inside the loops that could
  be moved out.

- As you mention in a comment, it would be faster to compute fractions
  and then repeatedly add them. If this creates precision problems,
  maybe we need to look into using floating point.

- We could special-case the formats a8r8g8b8, x8r8g8b8, r5g6b5 etc. so
  that they don't have to go through the get_pixel() callback.

- We could use SIMD instructions, although that does require some
  infrastructure changes that are not quite yet in place.

And of course, the first thing to do is profile to see what's actually
going on and how much time is actually spent in the super sampling

Finally, a couple of overall comments:

- It doesn't apply against current pixman master (though that is
  probably because this code changed just a few days ago).

- Please CC pixman at lists.freedesktop.org on pixman patches

Thanks for doing this work. It looks very promising,

More information about the cairo mailing list