From: johanengelen Date: Fri, 16 Nov 2007 18:43:48 +0000 (+0000) Subject: Fix: [ 1829427 ] PNG export via cmd line is restricted to 65535x65535 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=b51ec9ee0a6f46a4616c6a8b64edafc41263c660;p=inkscape.git Fix: [ 1829427 ] PNG export via cmd line is restricted to 65535x65535 --- diff --git a/src/dialogs/export.cpp b/src/dialogs/export.cpp index 1b74afb7e..d26a5cde1 100644 --- a/src/dialogs/export.cpp +++ b/src/dialogs/export.cpp @@ -60,6 +60,7 @@ #include "io/sys.h" #include "helper/png-write.h" +#include #define SP_EXPORT_MIN_SIZE 1.0 @@ -314,7 +315,7 @@ sp_export_dialog_area_box (GtkWidget * dlg) G_CALLBACK (sp_export_area_x_value_changed), dlg ); - sp_export_spinbutton_new ( "width", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, + sp_export_spinbutton_new ( "width", 0.0, 0.0, PNG_UINT_31_MAX, 0.1, 1.0, us->gobj(), GTK_WIDGET(t->gobj()), 4, 0, _("Width:"), NULL, EXPORT_COORD_PRECISION, 1, G_CALLBACK (sp_export_area_width_value_changed), @@ -330,7 +331,7 @@ sp_export_dialog_area_box (GtkWidget * dlg) G_CALLBACK (sp_export_area_y_value_changed), dlg ); - sp_export_spinbutton_new ( "height", 0.0, -1000000.0, 1000000.0, 0.1, 1.0, + sp_export_spinbutton_new ( "height", 0.0, 0.0, PNG_UINT_31_MAX, 0.1, 1.0, us->gobj(), GTK_WIDGET(t->gobj()), 4, 1, _("Height:"), NULL, EXPORT_COORD_PRECISION, 1, G_CALLBACK (sp_export_area_height_value_changed), dlg ); @@ -1144,8 +1145,8 @@ sp_export_export_clicked (GtkButton */*button*/, GtkObject *base) float const y1 = sp_export_value_get_px(base, "y1"); float const xdpi = sp_export_value_get(base, "xdpi"); float const ydpi = sp_export_value_get(base, "ydpi"); - int const width = int(sp_export_value_get(base, "bmwidth") + 0.5); - int const height = int(sp_export_value_get(base, "bmheight") + 0.5); + unsigned long int const width = int(sp_export_value_get(base, "bmwidth") + 0.5); + unsigned long int const height = int(sp_export_value_get(base, "bmheight") + 0.5); if (filename == NULL || *filename == '\0') { sp_ui_error_dialog(_("You have to enter a filename")); @@ -1178,7 +1179,7 @@ sp_export_export_clicked (GtkButton */*button*/, GtkObject *base) gchar *fn = g_path_get_basename (filename_ext); - gchar *progress_text = g_strdup_printf (_("Exporting %s (%d x %d)"), fn, width, height); + gchar *progress_text = g_strdup_printf (_("Exporting %s (%lu x %lu)"), fn, width, height); g_free (fn); GtkWidget *prog_dlg = create_progress_dialog (base, progress_text); g_free (progress_text); diff --git a/src/helper/png-write.cpp b/src/helper/png-write.cpp index 14c1ec325..6feefec7d 100644 --- a/src/helper/png-write.cpp +++ b/src/helper/png-write.cpp @@ -46,7 +46,7 @@ static unsigned int const MAX_STRIPE_SIZE = 1024*1024; struct SPEBP { - int width, height, sheight; + unsigned long int width, height, sheight; guchar r, g, b, a; NRArenaItem *root; // the root arena item to show; it is assumed that all unneeded items are hidden guchar *px; @@ -62,7 +62,7 @@ typedef struct SPPNGBD { } SPPNGBD; static bool -sp_png_write_rgba_striped(gchar const *filename, int width, int height, double xdpi, double ydpi, +sp_png_write_rgba_striped(gchar const *filename, unsigned long int width, unsigned long int height, double xdpi, double ydpi, int (* get_rows)(guchar const **rows, int row, int num_rows, void *data), void *data) { @@ -294,7 +294,7 @@ hide_other_items_recursively(SPObject *o, GSList *list, unsigned dkey) bool sp_export_png_file(SPDocument *doc, gchar const *filename, double x0, double y0, double x1, double y1, - unsigned width, unsigned height, double xdpi, double ydpi, + unsigned long width, unsigned long height, double xdpi, double ydpi, unsigned long bgcolor, unsigned (*status)(float, void *), void *data, bool force_overwrite, diff --git a/src/helper/png-write.h b/src/helper/png-write.h index 3f1e1761f..1217ba276 100644 --- a/src/helper/png-write.h +++ b/src/helper/png-write.h @@ -16,9 +16,9 @@ struct SPDocument; bool sp_export_png_file (SPDocument *doc, gchar const *filename, - double x0, double y0, double x1, double y1, - unsigned int width, unsigned int height, double xdpi, double ydpi, - unsigned long bgcolor, - unsigned int (*status) (float, void *), void *data, bool force_overwrite = false, GSList *items_only = NULL); + double x0, double y0, double x1, double y1, + unsigned long int width, unsigned long int height, double xdpi, double ydpi, + unsigned long bgcolor, + unsigned int (*status) (float, void *), void *data, bool force_overwrite = false, GSList *items_only = NULL); #endif diff --git a/src/main.cpp b/src/main.cpp index d70a7a030..99e90b7b5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -110,6 +110,8 @@ using Inkscape::Extension::Internal::PrintWin32; #include "main-cmdlineact.h" +#include + enum { SP_ARG_NONE, SP_ARG_NOGUI, @@ -971,33 +973,33 @@ sp_do_export_png(SPDocument *doc) if (dpi == 0.0) dpi = PX_PER_IN; - gint width = 0; - gint height = 0; + unsigned long int width = 0; + unsigned long int height = 0; if (sp_export_width) { - width = atoi(sp_export_width); - if ((width < 1) || (width > 65536)) { - g_warning("Export width %d out of range (1 - 65536). Nothing exported.", width); + width = strtoul(sp_export_width, NULL, 0); + if ((width < 1) || (width > PNG_UINT_31_MAX) || (errno == ERANGE) ) { + g_warning("Export width %lu out of range (1 - %lu). Nothing exported.", width, (unsigned long int)PNG_UINT_31_MAX); return; } dpi = (gdouble) width * PX_PER_IN / (area.x1 - area.x0); } if (sp_export_height) { - height = atoi(sp_export_height); - if ((height < 1) || (height > 65536)) { - g_warning("Export height %d out of range (1 - 65536). Nothing exported.", width); + height = strtoul(sp_export_height, NULL, 0); + if ((height < 1) || (height > PNG_UINT_31_MAX)) { + g_warning("Export height %lu out of range (1 - %lu). Nothing exported.", height, (unsigned long int)PNG_UINT_31_MAX); return; } dpi = (gdouble) height * PX_PER_IN / (area.y1 - area.y0); } if (!sp_export_width) { - width = (gint) ((area.x1 - area.x0) * dpi / PX_PER_IN + 0.5); + width = (unsigned long int) ((area.x1 - area.x0) * dpi / PX_PER_IN + 0.5); } if (!sp_export_height) { - height = (gint) ((area.y1 - area.y0) * dpi / PX_PER_IN + 0.5); + height = (unsigned long int) ((area.y1 - area.y0) * dpi / PX_PER_IN + 0.5); } guint32 bgcolor = 0x00000000; @@ -1032,14 +1034,14 @@ sp_do_export_png(SPDocument *doc) g_print("Background RRGGBBAA: %08x\n", bgcolor); - g_print("Area %g:%g:%g:%g exported to %d x %d pixels (%g dpi)\n", area.x0, area.y0, area.x1, area.y1, width, height, dpi); + g_print("Area %g:%g:%g:%g exported to %lu x %lu pixels (%g dpi)\n", area.x0, area.y0, area.x1, area.y1, width, height, dpi); g_print("Bitmap saved as: %s\n", filename); - if ((width >= 1) && (height >= 1) && (width < 65536) && (height < 65536)) { + if ((width >= 1) && (height >= 1) && (width <= PNG_UINT_31_MAX) && (height <= PNG_UINT_31_MAX)) { sp_export_png_file(doc, filename, area.x0, area.y0, area.x1, area.y1, width, height, dpi, dpi, bgcolor, NULL, NULL, true, sp_export_id_only ? items : NULL); } else { - g_warning("Calculated bitmap dimensions %d %d are out of range (1 - 65535). Nothing exported.", width, height); + g_warning("Calculated bitmap dimensions %lu %lu are out of range (1 - %lu). Nothing exported.", width, height, (unsigned long int)PNG_UINT_31_MAX); } g_slist_free (items);