2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2004-10-27 09:20:07 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2004-10-27 09:20:07 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2004-10-27 09:20:07 +08:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2004-10-27 09:20:07 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2008-05-23 22:09:55 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2004-10-27 09:20:07 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "libgimpbase/gimpbase.h"
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "dialogs-types.h"
|
|
|
|
|
|
|
|
#include "config/gimpguiconfig.h"
|
|
|
|
|
|
|
|
#include "core/gimp.h"
|
|
|
|
#include "core/gimpcontext.h"
|
|
|
|
#include "core/gimpimage.h"
|
|
|
|
#include "core/gimpimage-scale.h"
|
|
|
|
|
|
|
|
#include "widgets/gimphelp-ids.h"
|
|
|
|
#include "widgets/gimpmessagebox.h"
|
|
|
|
#include "widgets/gimpmessagedialog.h"
|
|
|
|
|
|
|
|
#include "scale-dialog.h"
|
|
|
|
|
|
|
|
#include "image-scale-dialog.h"
|
|
|
|
|
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
|
2007-05-24 04:08:27 +08:00
|
|
|
typedef struct
|
2006-10-15 00:51:30 +08:00
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
|
|
|
|
|
|
|
GimpImage *image;
|
|
|
|
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
GimpUnit unit;
|
|
|
|
GimpInterpolationType interpolation;
|
|
|
|
gdouble xresolution;
|
|
|
|
gdouble yresolution;
|
|
|
|
GimpUnit resolution_unit;
|
|
|
|
|
|
|
|
GimpScaleCallback callback;
|
|
|
|
gpointer user_data;
|
2007-05-24 04:08:27 +08:00
|
|
|
} ImageScaleDialog;
|
|
|
|
|
2006-10-15 00:51:30 +08:00
|
|
|
|
2016-10-28 03:26:07 +08:00
|
|
|
/* local function prototypes */
|
|
|
|
|
|
|
|
static void image_scale_dialog_free (ImageScaleDialog *private);
|
|
|
|
static void image_scale_callback (GtkWidget *widget,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
GimpUnit unit,
|
|
|
|
GimpInterpolationType interpolation,
|
|
|
|
gdouble xresolution,
|
|
|
|
gdouble yresolution,
|
|
|
|
GimpUnit resolution_unit,
|
|
|
|
gpointer data);
|
|
|
|
|
|
|
|
static GtkWidget * image_scale_confirm_dialog (ImageScaleDialog *private);
|
|
|
|
static void image_scale_confirm_large (ImageScaleDialog *private,
|
|
|
|
gint64 new_memsize,
|
|
|
|
gint64 max_memsize);
|
|
|
|
static void image_scale_confirm_small (ImageScaleDialog *private);
|
|
|
|
static void image_scale_confirm_response (GtkWidget *widget,
|
|
|
|
gint response_id,
|
|
|
|
ImageScaleDialog *private);
|
2004-10-27 09:20:07 +08:00
|
|
|
|
2006-10-15 00:51:30 +08:00
|
|
|
|
2004-10-27 09:20:07 +08:00
|
|
|
/* public functions */
|
|
|
|
|
2006-10-15 00:51:30 +08:00
|
|
|
GtkWidget *
|
|
|
|
image_scale_dialog_new (GimpImage *image,
|
|
|
|
GimpContext *context,
|
|
|
|
GtkWidget *parent,
|
|
|
|
GimpUnit unit,
|
|
|
|
GimpInterpolationType interpolation,
|
|
|
|
GimpScaleCallback callback,
|
|
|
|
gpointer user_data)
|
2004-10-27 09:20:07 +08:00
|
|
|
{
|
2016-10-28 03:26:07 +08:00
|
|
|
ImageScaleDialog *private;
|
2004-10-27 09:20:07 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
|
|
|
g_return_val_if_fail (callback != NULL, NULL);
|
|
|
|
|
2016-10-28 03:26:07 +08:00
|
|
|
private = g_slice_new0 (ImageScaleDialog);
|
2004-10-27 09:20:07 +08:00
|
|
|
|
2016-10-28 03:26:07 +08:00
|
|
|
private->image = image;
|
|
|
|
private->callback = callback;
|
|
|
|
private->user_data = user_data;
|
2006-10-15 00:51:30 +08:00
|
|
|
|
2016-10-28 03:26:07 +08:00
|
|
|
private->dialog = scale_dialog_new (GIMP_VIEWABLE (image), context,
|
|
|
|
C_("dialog-title", "Scale Image"),
|
|
|
|
"gimp-image-scale",
|
|
|
|
parent,
|
|
|
|
gimp_standard_help_func,
|
|
|
|
GIMP_HELP_IMAGE_SCALE,
|
|
|
|
unit,
|
|
|
|
interpolation,
|
|
|
|
image_scale_callback,
|
|
|
|
private);
|
2006-10-15 00:51:30 +08:00
|
|
|
|
2016-10-28 03:26:07 +08:00
|
|
|
g_object_weak_ref (G_OBJECT (private->dialog),
|
|
|
|
(GWeakNotify) image_scale_dialog_free, private);
|
2006-10-15 00:51:30 +08:00
|
|
|
|
2016-10-28 03:26:07 +08:00
|
|
|
return private->dialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
|
|
|
static void
|
|
|
|
image_scale_dialog_free (ImageScaleDialog *private)
|
|
|
|
{
|
|
|
|
g_slice_free (ImageScaleDialog, private);
|
2004-10-27 09:20:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
image_scale_callback (GtkWidget *widget,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gint width,
|
|
|
|
gint height,
|
|
|
|
GimpUnit unit,
|
|
|
|
GimpInterpolationType interpolation,
|
|
|
|
gdouble xresolution,
|
|
|
|
gdouble yresolution,
|
|
|
|
GimpUnit resolution_unit,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2016-10-28 03:26:07 +08:00
|
|
|
ImageScaleDialog *private = data;
|
|
|
|
GimpImage *image = GIMP_IMAGE (viewable);
|
2004-10-27 09:20:07 +08:00
|
|
|
GimpImageScaleCheckType scale_check;
|
|
|
|
gint64 max_memsize;
|
|
|
|
gint64 new_memsize;
|
|
|
|
|
2016-10-28 03:26:07 +08:00
|
|
|
private->width = width;
|
|
|
|
private->height = height;
|
|
|
|
private->unit = unit;
|
|
|
|
private->interpolation = interpolation;
|
|
|
|
private->xresolution = xresolution;
|
|
|
|
private->yresolution = yresolution;
|
|
|
|
private->resolution_unit = resolution_unit;
|
2004-10-27 09:20:07 +08:00
|
|
|
|
|
|
|
gtk_widget_set_sensitive (widget, FALSE);
|
|
|
|
|
|
|
|
max_memsize = GIMP_GUI_CONFIG (image->gimp->config)->max_new_image_size;
|
|
|
|
|
|
|
|
scale_check = gimp_image_scale_check (image,
|
|
|
|
width, height, max_memsize,
|
|
|
|
&new_memsize);
|
|
|
|
switch (scale_check)
|
|
|
|
{
|
|
|
|
case GIMP_IMAGE_SCALE_TOO_BIG:
|
2016-10-28 03:26:07 +08:00
|
|
|
image_scale_confirm_large (private, new_memsize, max_memsize);
|
2004-10-27 09:20:07 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_IMAGE_SCALE_TOO_SMALL:
|
2016-10-28 03:26:07 +08:00
|
|
|
image_scale_confirm_small (private);
|
2004-10-27 09:20:07 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_IMAGE_SCALE_OK:
|
2016-10-28 03:26:07 +08:00
|
|
|
private->callback (private->dialog,
|
|
|
|
GIMP_VIEWABLE (private->image),
|
|
|
|
private->width,
|
|
|
|
private->height,
|
|
|
|
private->unit,
|
|
|
|
private->interpolation,
|
|
|
|
private->xresolution,
|
|
|
|
private->yresolution,
|
|
|
|
private->resolution_unit,
|
|
|
|
private->user_data);
|
2004-10-27 09:20:07 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *
|
2016-10-28 03:26:07 +08:00
|
|
|
image_scale_confirm_dialog (ImageScaleDialog *private)
|
2004-10-27 09:20:07 +08:00
|
|
|
{
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
|
|
|
widget = gimp_message_dialog_new (_("Confirm Scaling"),
|
2017-03-05 23:01:59 +08:00
|
|
|
GIMP_ICON_DIALOG_WARNING,
|
2016-10-28 03:26:07 +08:00
|
|
|
private->dialog,
|
2004-10-27 09:20:07 +08:00
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
gimp_standard_help_func,
|
|
|
|
GIMP_HELP_IMAGE_SCALE_WARNING,
|
|
|
|
|
2017-02-12 23:06:34 +08:00
|
|
|
_("_Cancel"), GTK_RESPONSE_CANCEL,
|
|
|
|
_("_Scale"), GTK_RESPONSE_OK,
|
2004-10-27 09:20:07 +08:00
|
|
|
|
|
|
|
NULL);
|
|
|
|
|
2018-05-10 23:04:37 +08:00
|
|
|
gimp_dialog_set_alternative_button_order (GTK_DIALOG (widget),
|
2005-09-28 02:51:44 +08:00
|
|
|
GTK_RESPONSE_OK,
|
|
|
|
GTK_RESPONSE_CANCEL,
|
|
|
|
-1);
|
2005-02-09 04:40:33 +08:00
|
|
|
|
2006-10-15 00:51:30 +08:00
|
|
|
g_signal_connect (widget, "response",
|
|
|
|
G_CALLBACK (image_scale_confirm_response),
|
2016-10-28 03:26:07 +08:00
|
|
|
private);
|
2006-10-15 00:51:30 +08:00
|
|
|
|
2004-10-27 09:20:07 +08:00
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-10-28 03:26:07 +08:00
|
|
|
image_scale_confirm_large (ImageScaleDialog *private,
|
2004-10-27 09:20:07 +08:00
|
|
|
gint64 new_memsize,
|
|
|
|
gint64 max_memsize)
|
|
|
|
{
|
2016-10-28 03:26:07 +08:00
|
|
|
GtkWidget *widget = image_scale_confirm_dialog (private);
|
2004-10-27 09:20:07 +08:00
|
|
|
gchar *size;
|
|
|
|
|
2011-09-13 17:39:24 +08:00
|
|
|
size = g_format_size (new_memsize);
|
2004-10-27 09:20:07 +08:00
|
|
|
gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (widget)->box,
|
|
|
|
_("You are trying to create an image "
|
|
|
|
"with a size of %s."), size);
|
|
|
|
g_free (size);
|
|
|
|
|
2011-09-13 17:39:24 +08:00
|
|
|
size = g_format_size (max_memsize);
|
2004-10-27 09:20:07 +08:00
|
|
|
gimp_message_box_set_text (GIMP_MESSAGE_DIALOG (widget)->box,
|
2005-04-15 00:19:30 +08:00
|
|
|
_("Scaling the image to the chosen size will "
|
2004-10-27 09:20:07 +08:00
|
|
|
"make it use more memory than what is "
|
|
|
|
"configured as \"Maximum Image Size\" in the "
|
|
|
|
"Preferences dialog (currently %s)."), size);
|
|
|
|
g_free (size);
|
|
|
|
|
|
|
|
gtk_widget_show (widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-10-28 03:26:07 +08:00
|
|
|
image_scale_confirm_small (ImageScaleDialog *private)
|
2004-10-27 09:20:07 +08:00
|
|
|
{
|
2016-10-28 03:26:07 +08:00
|
|
|
GtkWidget *widget = image_scale_confirm_dialog (private);
|
2004-10-27 09:20:07 +08:00
|
|
|
|
|
|
|
gimp_message_box_set_primary_text (GIMP_MESSAGE_DIALOG (widget)->box,
|
2005-04-15 00:19:30 +08:00
|
|
|
_("Scaling the image to the chosen size "
|
2004-10-27 09:20:07 +08:00
|
|
|
"will shrink some layers completely "
|
|
|
|
"away."));
|
|
|
|
gimp_message_box_set_text (GIMP_MESSAGE_DIALOG (widget)->box,
|
|
|
|
_("Is this what you want to do?"));
|
|
|
|
|
|
|
|
gtk_widget_show (widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
image_scale_confirm_response (GtkWidget *widget,
|
|
|
|
gint response_id,
|
2016-10-28 03:26:07 +08:00
|
|
|
ImageScaleDialog *private)
|
2004-10-27 09:20:07 +08:00
|
|
|
{
|
|
|
|
gtk_widget_destroy (widget);
|
|
|
|
|
|
|
|
if (response_id == GTK_RESPONSE_OK)
|
|
|
|
{
|
2016-10-28 03:26:07 +08:00
|
|
|
private->callback (private->dialog,
|
|
|
|
GIMP_VIEWABLE (private->image),
|
|
|
|
private->width,
|
|
|
|
private->height,
|
|
|
|
private->unit,
|
|
|
|
private->interpolation,
|
|
|
|
private->xresolution,
|
|
|
|
private->yresolution,
|
|
|
|
private->resolution_unit,
|
|
|
|
private->user_data);
|
2004-10-27 09:20:07 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-10-28 03:26:07 +08:00
|
|
|
gtk_widget_set_sensitive (private->dialog, TRUE);
|
2004-10-27 09:20:07 +08:00
|
|
|
}
|
|
|
|
}
|