[cairo] Solid color pattern constructors
Bill Spitzak
spitzak at d2.com
Tue Jun 28 13:41:45 PDT 2005
> + cairo_color_t color;
> +
> + _cairo_restrict_value (&red, 0.0, 1.0);
> + _cairo_restrict_value (&green, 0.0, 1.0);
> + _cairo_restrict_value (&blue, 0.0, 1.0);
> + _cairo_restrict_value (&alpha, 0.0, 1.0);
> +
> + _cairo_color_init_rgba (&color, red, green, blue, alpha);
It seems to me that _cairo_color_init_rgba should do the restrict_value.
This would allow backends to handle HDR colors if they want, and also
it should be more efficient and make the results clearer. The following
code, for instance, is much faster for 0 and 1 and out-of-range and
handles NaN predictably (turning it into 0):
if (x >= 1.0) X = 255;
else if (x > 0) X = (int)(x*255+.5);
else X = 0;
In addition, I've generally seen "restrict_value" called "clamp" which
might be a better name. Because 0,1 is a very common range, adding a
clamp01() function is often a good idea, too.
More information about the cairo
mailing list