[cairo] shading, take 2

Thomas Hunger info at teh-web.de
Wed Mar 3 07:21:27 PST 2004


Hi
Based on the ideas discussed here I refactored cairo a bit to implement 
shading.
Each backend has now a create_pattern callback which takes a cairo_pattern_t 
and the dimensions of the expected image. It may then either fill it or 
return NULL which starts a software shader (again, only linear so far, radial 
is in work, others would be nice, suggestions welcome) which returns the 
wanted image.
since solid color and bitmaps are patterns, too, I plugged them into the 
cairo_pattern_t. 
This function now replaces the ensure_source function which was used by cairo 
before.
Patterns may have an etxra transformation matrix set which maps to different 
purposes:

set_pattern: sets the surface matrix before surface is composited  (1)
set_pattern_linear|radial: transforms the control points

colors are controlled via 

void
cairo_pattern_add_color_stop (cairo_t *cr, double offset, double r, double g, 
double b, double a);

which should work for linear shaders. Like in svg offset has to be a value 
between 0 and 1.

In svg different  models are supported when the offset goes behind 1: pad, 
mirror and repeat. currently the linear shader only pads, but the other 
functions are in work.

The surface matrix is now part of the pattern state (see (1)), the functions 
cairo_surface_set_matrix, repeat, filter have moved to the private api. this 
breaks at least one cairo-demo so far (knockout)

Since shader and maybe the user want to know which rectangular area is 
covered by a fill or stroke operation the following functions have moved into 
the public api:

void
cairo_stroke_extents (cairo_t *cr, pixman_box16_t *extents);
void
cairo_fill_extents (cairo_t *cr, pixman_box16_t *extents);

This implements one part of functionality proposed by Carl Worth in this mail:
http://www.cairographics.org/pipermail/cairo/2003-October/000689.html

This is only a quick overview, not all work is done yet, but I would be happy 
about comments. The names of the functions can easily be changed if you are 
unhappy with them (I did not waste much time to make them up).

some screenshots and a tarball can be found here:
http://www.iqo.uni-hannover.de/gnome/cairo/

Tom

P.S. is there acutally transparency in svg? I searched but could not find 
it...





More information about the cairo mailing list