[cairo] Thoughts on plans for 1.6

Bill Spitzak spitzak at thefoundry.co.uk
Thu Sep 6 02:37:24 PDT 2007

Carl Worth wrote:

>   * Fix CAIRO_EXTEND_PAD for image surfaces
> 	This should be a trivial fix to pixman. It will allow
> 	applications to easily avoid the "faded image edges" when
> 	drawing scaled-up images. The current ugly effects are
> 	achieved with:
> 		cairo_scale (cr, x_scale, y_scale);
> 		cairo_set_source_surface, (cr, surface, x, y);
> 		cairo_paint (cr);
> 	And the fix is:
> 		cairo_scale (cr, x_scale, y_scale);
> 		cairo_set_source_surface, (cr, surface, x, y);
> 		cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_PAD);
> 		cairo_rectangle (cr, x, y, width, height);
> 		cairo_fill (cr);
> 	But obviously that requires that CAIRO_EXTEND_PAD work.
> 	This problem has been hit by Mozilla, Webkit, poppler, and
> 	likely many other applications. It will be most welcome when
> 	it is fixed.

I feel that the fixed result is actually the desired result in *all* 
cases. The default behavior sould be like EXTEND_PAD with the clipping 
quadralateral as shown in the above code. The EXTEND_PAD control itself 
would disable the clipping rectangle.

I very much doubt this would break any existing Cairo output in any 
serious way.

The advantages are that it is a lot easier to get the desired output, 
and that this clipping could be done by the low level code faster. Also 
the results match other graphics libraries and how OpenGL hardware works.

A disadvantage is that it can lead to double-premultiplied edges (when 
the user makes a clip that aligns with the image edge), which are a 
harder to detect rendering error than the current blurry edges. However 
if forcing people to produce correct graphics was a goal, then it should 
have used EXTEND_PAD with no clipping as the default, because it then 
would be obvious that you need to do something to add an edge to the image.

More information about the cairo mailing list