diff options
author | Thomas White <taw@physics.org> | 2011-03-01 10:55:21 +0100 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2012-02-22 15:27:16 +0100 |
commit | 6341b8ee8d9be0b6fed14cf418161706e4caa5c5 (patch) | |
tree | ee4a45341508c41da13e59d0c40b8cfc78e69a99 /src | |
parent | fbd247a5c5f098688e98e77af95505422db62ef1 (diff) |
Fix hdfsee's PNG saving
Diffstat (limited to 'src')
-rw-r--r-- | src/displaywindow.c | 52 | ||||
-rw-r--r-- | src/render.c | 7 | ||||
-rw-r--r-- | src/render.h | 1 |
3 files changed, 43 insertions, 17 deletions
diff --git a/src/displaywindow.c b/src/displaywindow.c index 3329649e..0045c191 100644 --- a/src/displaywindow.c +++ b/src/displaywindow.c @@ -161,19 +161,17 @@ static void show_ring(cairo_t *cr, DisplayWindow *dw, } -static gboolean displaywindow_expose(GtkWidget *da, GdkEventExpose *event, - DisplayWindow *dw) +static int draw_stuff(cairo_surface_t *surf, DisplayWindow *dw) { cairo_t *cr; int i; cairo_matrix_t basic_m; cairo_matrix_t m; - cr = gdk_cairo_create(da->window); + cr = cairo_create(surf); /* Blank white background */ - cairo_rectangle(cr, 0.0, 0.0, da->allocation.width, - da->allocation.height); + cairo_rectangle(cr, 0.0, 0.0, dw->width, dw->height); cairo_set_source_rgb(cr, 0.5, 0.5, 0.5); cairo_fill(cr); @@ -246,13 +244,13 @@ static gboolean displaywindow_expose(GtkWidget *da, GdkEventExpose *event, if ( dw->image->features == NULL ) { cairo_destroy(cr); - return FALSE; + return 0; } /* Ensure a clean Cairo context, since the rings often cause * matrix trouble */ cairo_destroy(cr); - cr = gdk_cairo_create(da->window); + cr = cairo_create(surf); cairo_set_matrix(cr, &basic_m); for ( i=0; i<image_feature_count(dw->image->features); i++ ) { @@ -301,10 +299,47 @@ static gboolean displaywindow_expose(GtkWidget *da, GdkEventExpose *event, cairo_destroy(cr); + return 0; +} + + +static gboolean displaywindow_expose(GtkWidget *da, GdkEventExpose *event, + DisplayWindow *dw) +{ + cairo_t *cr; + cairo_surface_t *surf; + + cr = gdk_cairo_create(da->window); + surf = cairo_get_target(cr); + draw_stuff(surf, dw); + cairo_destroy(cr); + return FALSE; } +static int write_png(const char *filename, DisplayWindow *dw) +{ + cairo_status_t r; + cairo_t *cr; + cairo_surface_t *surf; + + surf = gdk_window_create_similar_surface(dw->drawingarea->window, + CAIRO_CONTENT_COLOR, + dw->width, dw->height); + + draw_stuff(surf, dw); + + r = cairo_surface_write_to_png(surf, filename); + if ( r != CAIRO_STATUS_SUCCESS ) return 1; + + cairo_destroy(cr); + cairo_surface_destroy(surf); + + return 0; +} + + static gint displaywindow_close(GtkWidget *widget, DisplayWindow *dw) { gtk_widget_destroy(dw->window); @@ -817,8 +852,7 @@ static gint displaywindow_save_response(GtkWidget *d, gint response, type = gtk_combo_box_get_active(GTK_COMBO_BOX(cd->cb)); if ( type == 0 ) { - /* FIXME: Use Cairo or something */ - r = render_png(dw->pixbufs[0], file); + r = write_png(file, dw); } else if ( type == 1 ) { r = render_tiff_fp(dw->image, file); } else if ( type == 2 ) { diff --git a/src/render.c b/src/render.c index ba64b779..63357083 100644 --- a/src/render.c +++ b/src/render.c @@ -325,13 +325,6 @@ GdkPixbuf *render_get_colour_scale(size_t w, size_t h, int scale) } -int render_png(GdkPixbuf *pixbuf, const char *filename) -{ - gdk_pixbuf_save(pixbuf, filename, "png", NULL, NULL); - return 0; -} - - int render_tiff_fp(struct image *image, const char *filename) { #ifdef HAVE_TIFF diff --git a/src/render.h b/src/render.h index bdfb9bc4..e8017de8 100644 --- a/src/render.h +++ b/src/render.h @@ -43,7 +43,6 @@ extern GdkPixbuf **render_panels(struct image *image, extern GdkPixbuf *render_get_colour_scale(size_t w, size_t h, int scale); -extern int render_png(GdkPixbuf *pixbuf, const char *filename); extern int render_tiff_fp(struct image *image, const char *filename); extern int render_tiff_int16(struct image *image, const char *filename, double boost); |