[cairo] Compiling Cairo with MinGW under Win32

Carl Worth cworth at cworth.org
Mon Nov 1 10:19:31 PST 2004


On Mon, 1 Nov 2004 12:13:19 -0500 (EST), Jack Chen wrote:
> Hi, Carl, thank you. That's whay I wanted.

You're quite welcome.

> 1.) Suppose I create a bmp, a square, and apply a gradient to fill
> it.If I save the file and load it, will the above programs you
> mentioned be able to interpret the bmp as a vector format with the same
> simplicity as when I construct them with Cairo?

I don't know details about those programs, and we'd be getting off-topic
to discuss them more here. Gradient extraction sounds like a difficult
problem to me, but you'll have to go ask in the forums for those
programs for more details.

> 2.) With question #1 there comes another question. How exactly does
> Cairo structure a gradient? Do I just specify a color at each point of
> a shape and let Cairo's internal rendering engine do all the work for
> me (like OpenGL), or is there something more to it?

With cairo right now we've got 2 kinds of gradients, linear and
radial. They are created with these function calls:

	cairo_pattern_t *
	cairo_pattern_create_linear (double x0, double y0,
	                             double x1, double y1);

	cairo_pattern_t *
	cairo_pattern_create_radial (double cx0, double cy0, double radius0,
	                             double cx1, double cy1, double radius1);

And then the following functions is called one or more times to create
color stops with the gradient:

	cairo_status_t
	cairo_pattern_add_color_stop (cairo_pattern_t *pattern,
	                              double offset,
	                              double red, double green, double blue,
	                              double alpha);

There are also various other cairo_pattern functions for transforming
the pattern, controlling how the pattern extends beyond its natural
boundaries, etc.

There's a cute little example showing all the code needed for a linear
and a radial gradient here:

	http://cairographics.org/samples/gradient.html

> 3.) Is Cairo able to do radial gradients? If so, can you please tell me
> how? I read the tutorial by Keith Packard but couldn't find information
> on that topic. libsvg has radial gradient capabilities, though.

Yes, radial gradients are there. They didn't exist at the time Keith
whipped up that tutorial, and we don't have any more updated
documentation yet. I am planning on doing more soon. Any help would also
be greatly appreciated.

> 4.) Is Cairo's gradient calculated linearly?

We haven't yet drawn up a specification of the gradients, so the only
thing we have now is what is in the current implementation. But I
believe that what is there does linear interpolation between color
stops.

If something besides linear interpolation is desired, it can be
approximated by a series of piece-wise linear color stops. If this is
not sufficient for what someone would like to do, then please let me
know.

Also, the current implementation is linear in sRGB space. If someone
wants something linear in some other color space it would also have to
be approximated as piecewise-linear steps in sRGB. Can anyone point to a
usage scenario where this would break down?

I know that I would like to come up with a way to specify gradients more
general than the current linear and radial gradients. Any good
recommendations in this area would be welcome.

> 5.) A side question. OpenGL uses a surface normal to create a gradient
> for a surface if the scene uses a light, but when OpenGL calculates the
> colors falling from one point to another, is the change an arithmatic
> sequence or is it a sin() function?

I don't know, and the question is a bit off-topic.

> Oh and, why don't you post this webpage on your website
> 
> http://cairographics.org/cairo/win32

Apparently the page is posted, since you were able to find it. ;-)

I didn't know the page existed, and I didn't create it. I notice that
starting from http://cairographics.org and using the "Index" link the
page is only two links away from the top page.

If there are more logical places to link in this page, then anyone can
edit any relevant pages--it's all a wiki. Just click "Edit" and create
an account if necessary.

I think the only things that are hard to change are the top page and the
menu/navigation bar across the top. Please let me know if you'd like to
change those and I will be glad to provide access.

-Carl



More information about the cairo mailing list