Search code examples
scalegtkblurcairogtk3

scale surface without blurring it


I try to scale an image derivedfrom a file, to any (sensible) scale.

The problem is, cairo somhow autoblurrs it. How can I fix/remove it? The aim is to see the individual pixels.

Thanks for any reply.

Edit: Some code, triggering on "draw" event, parent is a GtkDrawingArea

static gboolean
cb_event_draw (GtkWidget *obj, cairo_t *cr, gpointer data)
{
    guint width, height;

    width = gtk_widget_get_allocated_width (obj);
    height = gtk_widget_get_allocated_height (obj);
    _priv = ...; //some struct


//  cairo_save (cr);
    cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
    cairo_scale (cr, _priv->zoom, _priv->zoom);


    cairo_set_source_surface (cr, _priv->image, 0., 0.);
    cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
    cairo_pattern_set_filter (cr, CAIRO_FILTER_FAST); // no matter if this is there or not
    // it does actually, matter, works with this:
    // cairo_pattern_set_filter (cairo_get_source (cr), CAIRO_FILTER_FAST);
    cairo_paint (cr);

// print some markers at defined locations


    return FALSE;
}

Solution

  • I suspect that you need:

    cairo_pattern_set_filter(cairo_get_source(cr), CAIRO_FILTER_FAST);