[cairo] Tiling the cairo surface

Uli Schlachter psychon at znc.in
Thu Jul 11 16:16:44 UTC 2019


Hi,

On 11.07.19 00:56, Ray Gardener wrote:
> I was wondering if Cairo has a mode where the rasterizer, when reaching
> a surface edge, wraps around (modulates the device coordinate) to simply
> draw pixels on the opposite side. This would make producing tileable
> images more accurate than modulating at the call level.

Not really, I think. However, you might be able to simulate this with a
tee surface. However, tee surfaces are not enabled by default.

To me, it sounds simpler if you were to just draw your image to a
slightly larger surface (on a transparent backround) and then copy from
this large surface to a new surface of the target size. This copy is
done five times: Once without a translation, and four times for things
like "copy the pixels on the left margin to the right side of the surface".

Does this make sense?

Perhaps this makes more sense:

- We want to draw something of size w x h
- Create a surface s of size (w + margin) x (h + margin) (where margin
could e.g. be 1)
- cairo_surface_set_device_offset(s, margin, margin)
- [Draw to surface s]
- Create a surface result of size w x h
- cr = cairo_create(result)
- cairo_set_source_surface(result, s, 0, 0);
- cairo_paint(cr);
- cairo_set_source_surface(result, s, w, h);
- cairo_paint(cr);
- cairo_set_source_surface(result, s, -w, h);
- cairo_paint(cr);
- cairo_set_source_surface(result, s, w, -h);
- cairo_paint(cr);
- cairo_set_source_surface(result, s, -w, -h);
- cairo_paint(cr);

Cheers,
Uli
-- 
Sent from my Game Boy.


More information about the cairo mailing list