Re: This takes 30 secs to render
- From: cecashon aol com
- To: mrt303xx aol com, gtk-app-devel-list gnome org
- Subject: Re: This takes 30 secs to render
- Date: Fri, 1 Jun 2018 17:52:01 -0400
The other way to go about it is to just use cairo. I don't think that it will give a speed improvement but it
might be worth a try. I figure you are trying to scale the png first and then draw it in a widget. Once the
image is sized it shouldn't be a problem to draw quickly.
Eric
//gcc -Wall big_png1.c -o big_png1 `pkg-config gtk+-3.0 --cflags --libs`
#include<gtk/gtk.h>
static gboolean da_drawing(GtkWidget *da, cairo_t *cr, cairo_surface_t *surface);
static void save_png();
static cairo_surface_t *get_and_scale_png();
int main(int argc, char *argv[])
{
gtk_init(&argc, &argv);
GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Big PNG");
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 500, 500);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
GTimer *timer=g_timer_new();
save_png();
g_print("Save Time %f\n", g_timer_elapsed(timer, NULL));
g_timer_start(timer);
cairo_surface_t *surface=get_and_scale_png();
g_print("Get Time %f\n", g_timer_elapsed(timer, NULL));
g_timer_destroy(timer);
GtkWidget *da=gtk_drawing_area_new();
gtk_widget_set_size_request(da, 10000, 10000);
gtk_widget_set_hexpand(da, TRUE);
gtk_widget_set_vexpand(da, TRUE);
g_signal_connect(da, "draw", G_CALLBACK(da_drawing), surface);
GtkWidget *scroll=gtk_scrolled_window_new(NULL, NULL);
gtk_container_add(GTK_CONTAINER(scroll), da);
GtkWidget *grid=gtk_grid_new();
gtk_grid_attach(GTK_GRID(grid), scroll, 0, 0, 1, 1);
gtk_container_add(GTK_CONTAINER(window), grid);
gtk_widget_show_all(window);
gtk_main();
cairo_surface_destroy(surface);
return 0;
}
static gboolean da_drawing(GtkWidget *da, cairo_t *cr, cairo_surface_t *surface)
{
GTimer *timer=g_timer_new();
cairo_set_source_surface(cr, surface, 0.0, 0.0);
cairo_paint(cr);
g_print("Draw Time %f\n", g_timer_elapsed(timer, NULL));
g_timer_destroy(timer);
return FALSE;
}
static void save_png()
{
gdouble width=5000.0;
gdouble height=5000.0;
cairo_surface_t *surface=cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
cairo_t *cr=cairo_create(surface);
//Paint the green background.
cairo_set_source_rgba(cr, 0.0, 1.0, 0.0, 1.0);
cairo_paint(cr);
cairo_set_source_rgba(cr, 1.0, 0.0, 1.0, 1.0);
cairo_set_line_width(cr, 80.0);
cairo_rectangle(cr, 0.0, 0.0, width, height);
cairo_stroke(cr);
cairo_surface_write_to_png(surface, "big.png");
cairo_destroy(cr);
cairo_surface_destroy(surface);
}
static cairo_surface_t *get_and_scale_png()
{
//The 5,000x5,000 surface.
cairo_surface_t *surface=cairo_image_surface_create_from_png("big.png");
//Scale to 1/10 of width and height.
cairo_surface_t *surface2=cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 500.0, 500.0);
cairo_t *cr2=cairo_create(surface2);
cairo_scale(cr2, 1.0/10.0, 1.0/10.0);
cairo_set_source_surface(cr2, surface, 0.0, 0.0);
cairo_pattern_set_filter(cairo_get_source(cr2), CAIRO_FILTER_FAST);
cairo_paint(cr2);
cairo_destroy(cr2);
cairo_surface_destroy(surface);
return surface2;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]