#include #include /* build with: * cc `pkg-config --cflags cairo` -ggdb3 -std=gnu99 `pkg-config --libs cairo` 1x1scale.c -o 1x1scale */ #define foreach(a, as) for(int _i=0, a=as[0]; _i<(sizeof(as)/sizeof(as[0])); ++_i, a = as[_i]) int main() { cairo_filter_t filters[] = {CAIRO_FILTER_NEAREST, CAIRO_FILTER_BEST}; cairo_filter_t f; foreach (f, filters) { // paint 1x1 black cairo_surface_t *one = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 4, 4); cairo_t *cr = cairo_create(one); cairo_set_source_rgb(cr, 0, 0, 0); cairo_paint(cr); cairo_destroy(cr); cairo_surface_t *s = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 800, 800); cr = cairo_create(s); cairo_set_source_rgb(cr, 1,1,1); cairo_paint(cr); cairo_translate(cr, 100, 75); cairo_pattern_t *p = cairo_pattern_create_for_surface(one); cairo_pattern_set_filter (p, f); cairo_select_font_face (cr, "Arial", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); cairo_set_font_size(cr, 10); /* values that make it disapear: * 4.9, 4.7, 4.5, 4.4, 4.2, 4.0, */ // write title cairo_save(cr); cairo_move_to(cr, -55., -20.); cairo_set_source_rgb(cr, 0, 0, 0); cairo_show_text(cr, "scale"); cairo_restore(cr); for (float sy = 5.0; sy >= 0.1; sy -= 0.3) { char scale_label[18]; cairo_set_source_rgb(cr, 0, 0, 0); cairo_move_to(cr, -50.0, 0); sprintf(scale_buf, "%1.1f", sy); cairo_show_text(cr, scale_label); cairo_save(cr); for (float sx = 5.0; sx >= 0.1; sx -= 0.3) { cairo_matrix_t matrix; cairo_matrix_init_scale(&matrix, sx, sy); cairo_pattern_set_matrix(p, &matrix); cairo_set_source(cr, p); cairo_paint(cr); cairo_translate(cr, 40, 0); } cairo_restore(cr); cairo_translate(cr, 0, 40); } cairo_pattern_destroy(p); cairo_destroy(cr); if (f == CAIRO_FILTER_NEAREST) cairo_surface_write_to_png(s, "scaleone-nearest.png"); else cairo_surface_write_to_png(s, "scaleone-best.png"); cairo_surface_destroy(one); cairo_surface_destroy(s); } }