[gimp] Bug 658610 - Warn when importing PNG images with an offse
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] Bug 658610 - Warn when importing PNG images with an offse
- Date: Sun, 12 Feb 2012 19:50:15 +0000 (UTC)
commit f07b9606d833fe36009653be4fc2ae558efa23ad
Author: Ville Sokk <embassyhill gmail com>
Date: Thu Feb 9 20:09:14 2012 +0200
Bug 658610 - Warn when importing PNG images with an offse
Added a dialog about offsets to the PNG loader
plug-ins/common/file-png.c | 87 ++++++++++++++++++++++++++++++++++++++++----
1 files changed, 80 insertions(+), 7 deletions(-)
---
diff --git a/plug-ins/common/file-png.c b/plug-ins/common/file-png.c
index ad678c6..31517cd 100644
--- a/plug-ins/common/file-png.c
+++ b/plug-ins/common/file-png.c
@@ -26,6 +26,7 @@
* query() - Respond to a plug-in query...
* run() - Run the plug-in...
* load_image() - Load a PNG image into a new image window.
+ * offsets_dialog() - Asks the user about offsets when loading.
* respin_cmap() - Re-order a Gimp colormap for PNG tRNS
* save_image() - Save the specified image to a PNG file.
* save_compression_callback() - Update the image compression level.
@@ -151,6 +152,9 @@ static void save_dialog_response (GtkWidget *widget,
gint response_id,
gpointer data);
+static gboolean offsets_dialog (gint offset_x,
+ gint offset_y);
+
static gboolean ia_has_transparent_pixels (GimpDrawable *drawable);
static gint find_unused_ia_color (GimpDrawable *drawable,
@@ -918,14 +922,20 @@ load_image (const gchar *filename,
gint offset_x = png_get_x_offset_pixels (pp, info);
gint offset_y = png_get_y_offset_pixels (pp, info);
- gimp_layer_set_offsets (layer, offset_x, offset_y);
-
- if ((abs (offset_x) > png_get_image_width (pp, info)) ||
- (abs (offset_y) > png_get_image_height (pp, info)))
+ if (! interactive)
+ {
+ gimp_layer_set_offsets (layer, offset_x, offset_y);
+ }
+ else if (offsets_dialog (offset_x, offset_y))
{
- if (interactive)
- g_message (_("The PNG file specifies an offset that caused "
- "the layer to be positioned outside the image."));
+ gimp_layer_set_offsets (layer, offset_x, offset_y);
+
+ if ((abs (offset_x) > png_get_image_width (pp, info)) ||
+ (abs (offset_y) > png_get_image_height (pp, info)))
+ {
+ g_message (_("The PNG file specifies an offset that caused "
+ "the layer to be positioned outside the image."));
+ }
}
}
@@ -1209,6 +1219,69 @@ load_image (const gchar *filename,
return image;
}
+/*
+ * 'offsets_dialog ()' - Asks the user about offsets when loading.
+ */
+static gboolean
+offsets_dialog (gint offset_x,
+ gint offset_y)
+{
+ GtkWidget *dialog;
+ GtkWidget *hbox;
+ GtkWidget *image;
+ GtkWidget *label;
+ gchar *message;
+ gboolean run;
+
+ gimp_ui_init (PLUG_IN_BINARY, FALSE);
+
+ dialog = gimp_dialog_new (_("Apply PNG Offset"), PLUG_IN_ROLE,
+ NULL, 0,
+ gimp_standard_help_func, LOAD_PROC,
+
+ _("Ignore PNG offset"), GTK_RESPONSE_NO,
+ _("Apply PNG offset to layer"), GTK_RESPONSE_YES,
+
+ NULL);
+
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
+ gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
+ GTK_RESPONSE_YES,
+ GTK_RESPONSE_NO,
+ -1);
+
+ gimp_window_set_transient (GTK_WINDOW (dialog));
+ gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
+
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
+ gtk_container_set_border_width (GTK_CONTAINER (hbox), 12);
+ gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
+ hbox, FALSE, FALSE, 0);
+ gtk_widget_show (hbox);
+
+ image = gtk_image_new_from_stock (GIMP_STOCK_QUESTION, GTK_ICON_SIZE_DIALOG);
+ gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0);
+ gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
+ gtk_widget_show (image);
+
+ message = g_strdup_printf (_("The PNG image you are importing specifies an "
+ "offset of %d, %d. Do you want to apply "
+ "this offset to the layer?"),
+ offset_x, offset_y);
+ label = gtk_label_new (message);
+ gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.0);
+ gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+ gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
+ gtk_widget_show (label);
+
+ gtk_widget_show (dialog);
+
+ run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_YES);
+
+ gtk_widget_destroy (dialog);
+
+ return run;
+}
/*
* 'save_image ()' - Save the specified image to a PNG file.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]