[cairo] Disabling filtering when scaling a bitmap

Greg Lowe greg at vis.net.nz
Wed Apr 7 01:03:33 PDT 2010

Hi all,

I would like to paint an image surface scaled 4x, and use no filter
when scaling, so that the image appears blocky.

As an real-world example, consider a bitmap painting program when
viewing an image at high-zoom. A single image pixel takes up a
whole-number sized square of pixels on the screen.

I can't figure out how to do this with Cairo. Could someone please
point me in the right direction.

(Well - I can think of the brute force approach, that is, reading the
surface RGBA data myself and drawing a large number of rectangles. But
I assume the API has built-in way to do this.)

A second question - I've had a quick experiment with the gaussian blur
code in the cookbook ( http://cairographics.org/cookbook/blur.c ). For
some reason it doesn't seem to blur much until I set the radius really
large - say 1000. I was expecting the radius to be in pixel units. How
do I get this to work in pixel units, or have I done something totally
wrong? I've included my sample code below.

Advice much appreciated,

main (int argc, char **argv)
	cairo_t *cr;
	cairo_surface_t *surface;

	surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 400, 400);
        cr = cairo_create (surface);

        cairo_save (cr);

	cairo_set_source_rgb (cr, 1, 0, 0);
	cairo_rectangle (cr, 100, 100, 200, 200);
	cairo_fill (cr);

	blur_image_surface (surface, 1000);

        cairo_restore (cr);

	cairo_surface_write_to_png (surface, "blur.png");
        cairo_destroy (cr);
	cairo_surface_destroy (surface);	

More information about the cairo mailing list