Efficient general purpose tile engine, and a cellular automata machine
cworth at redhat.com
Tue Apr 24 19:33:56 EDT 2007
On Tue, 24 Apr 2007 04:04:45 -0700, Don Hopkins wrote:
> Question: How to I tell Cairo to use FILTER_FAST instead of FILTER_BEST?
> The set_filter method is supported by the cairo pattern object, but not
> the surface or the context. How to I wrangle a surface into a pattern,
> or use a pattern instead of a surface, or whatever I have to do to
> switch to fast nearest neighbor interpolation mode when scaling a surface?
Whenever you're drawing anything with cairo there's a source pattern
object involved. That's most obvious when you set the pattern
explicitly with cairo_set_source. It's less obvious when you're using
the convenience function of cairo_set_source_surface. But it should be
clear again if you realize you could replace any call to
cairo_set_source_surface with the following sequence:
cairo_pattern_t *pattern = cairo_pattern_create_for_surface (surface);
cairo_matrix_init_translate (&matrix, -x, -y);
cairo_pattern_set_matrix (pattern, &matrix);
cairo_set_source (cr, pattern);
So there's the answer to your "wrangle a surface into a pattern"
But since cairo_set_source_surface is quite convenient at creating the
pattern for you, here's another idiom that would probably be helpful
cairo_set_source_surface (cr, surface, x, y);
cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_FAST);
That's what I'd recommend you do here.
Or I guess in python land that would be:
Very nice, thanks for sharing this.
By the way, with all the aggressive tile caching you are doing here,
and with the many repeated images, (at least in the current example),
have you considered regenerating the tiles at "native" scale when
zooming in? That could make for a very lovely effect. (Or are you just
loading images for those little circles and arrows instead of drawing
them with cairo?).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 189 bytes
Desc: not available
More information about the Devel