mirror of https://github.com/GNOME/gimp.git
app: add a callback to the convert precision dialog
and move the image manipulation code out of convert-precision-dialog.c into image-commands.c where it belongs.
This commit is contained in:
parent
98232c25a5
commit
2a04cc91a2
|
@ -20,6 +20,7 @@
|
|||
#include <gegl.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "libgimpbase/gimpbase.h"
|
||||
#include "libgimpcolor/gimpcolor.h"
|
||||
#include "libgimpwidgets/gimpwidgets.h"
|
||||
|
||||
|
@ -77,42 +78,50 @@
|
|||
|
||||
/* local function prototypes */
|
||||
|
||||
static void image_resize_callback (GtkWidget *dialog,
|
||||
GimpViewable *viewable,
|
||||
GimpContext *context,
|
||||
gint width,
|
||||
gint height,
|
||||
GimpUnit unit,
|
||||
gint offset_x,
|
||||
gint offset_y,
|
||||
GimpItemSet layer_set,
|
||||
gboolean resize_text_layers,
|
||||
gpointer user_data);
|
||||
static void image_convert_precision_callback (GtkWidget *dialog,
|
||||
GimpImage *image,
|
||||
GimpPrecision precision,
|
||||
GeglDitherMethod layer_dither_method,
|
||||
GeglDitherMethod text_layer_dither_method,
|
||||
GeglDitherMethod mask_dither_method,
|
||||
gpointer user_data);
|
||||
|
||||
static void image_print_size_callback (GtkWidget *dialog,
|
||||
GimpImage *image,
|
||||
gdouble xresolution,
|
||||
gdouble yresolution,
|
||||
GimpUnit resolution_unit,
|
||||
gpointer user_data);
|
||||
static void image_resize_callback (GtkWidget *dialog,
|
||||
GimpViewable *viewable,
|
||||
GimpContext *context,
|
||||
gint width,
|
||||
gint height,
|
||||
GimpUnit unit,
|
||||
gint offset_x,
|
||||
gint offset_y,
|
||||
GimpItemSet layer_set,
|
||||
gboolean resize_text_layers,
|
||||
gpointer user_data);
|
||||
|
||||
static void image_scale_callback (GtkWidget *dialog,
|
||||
GimpViewable *viewable,
|
||||
gint width,
|
||||
gint height,
|
||||
GimpUnit unit,
|
||||
GimpInterpolationType interpolation,
|
||||
gdouble xresolution,
|
||||
gdouble yresolution,
|
||||
GimpUnit resolution_unit,
|
||||
gpointer user_data);
|
||||
static void image_print_size_callback (GtkWidget *dialog,
|
||||
GimpImage *image,
|
||||
gdouble xresolution,
|
||||
gdouble yresolution,
|
||||
GimpUnit resolution_unit,
|
||||
gpointer user_data);
|
||||
|
||||
static void image_merge_layers_callback (GtkWidget *dialog,
|
||||
GimpImage *image,
|
||||
GimpContext *context,
|
||||
GimpMergeType merge_type,
|
||||
gboolean merge_active_group,
|
||||
gboolean discard_invisible);
|
||||
static void image_scale_callback (GtkWidget *dialog,
|
||||
GimpViewable *viewable,
|
||||
gint width,
|
||||
gint height,
|
||||
GimpUnit unit,
|
||||
GimpInterpolationType interpolation,
|
||||
gdouble xresolution,
|
||||
gdouble yresolution,
|
||||
GimpUnit resolution_unit,
|
||||
gpointer user_data);
|
||||
|
||||
static void image_merge_layers_callback (GtkWidget *dialog,
|
||||
GimpImage *image,
|
||||
GimpContext *context,
|
||||
GimpMergeType merge_type,
|
||||
gboolean merge_active_group,
|
||||
gboolean discard_invisible);
|
||||
|
||||
|
||||
/* private variables */
|
||||
|
@ -258,6 +267,7 @@ image_convert_precision_cmd_callback (GtkAction *action,
|
|||
GimpImage *image;
|
||||
GimpDisplay *display;
|
||||
GtkWidget *widget;
|
||||
GimpDialogConfig *config;
|
||||
GtkWidget *dialog;
|
||||
GimpComponentType value;
|
||||
return_if_no_image (image, data);
|
||||
|
@ -273,18 +283,27 @@ image_convert_precision_cmd_callback (GtkAction *action,
|
|||
|
||||
dialog = dialogs_get_dialog (G_OBJECT (image), CONVERT_PRECISION_DIALOG_KEY);
|
||||
|
||||
if (! dialog)
|
||||
if (dialog)
|
||||
{
|
||||
dialog = convert_precision_dialog_new (image,
|
||||
action_data_get_context (data),
|
||||
widget,
|
||||
value,
|
||||
GIMP_PROGRESS (display));
|
||||
|
||||
dialogs_attach_dialog (G_OBJECT (image),
|
||||
CONVERT_PRECISION_DIALOG_KEY, dialog);
|
||||
gtk_widget_destroy (dialog);
|
||||
dialog = NULL;
|
||||
}
|
||||
|
||||
config = GIMP_DIALOG_CONFIG (image->gimp->config);
|
||||
|
||||
dialog = convert_precision_dialog_new (image,
|
||||
action_data_get_context (data),
|
||||
widget,
|
||||
value,
|
||||
config->image_convert_precision_layer_dither_method,
|
||||
config->image_convert_precision_text_layer_dither_method,
|
||||
config->image_convert_precision_channel_dither_method,
|
||||
image_convert_precision_callback,
|
||||
display);
|
||||
|
||||
dialogs_attach_dialog (G_OBJECT (image),
|
||||
CONVERT_PRECISION_DIALOG_KEY, dialog);
|
||||
|
||||
gtk_window_present (GTK_WINDOW (dialog));
|
||||
|
||||
/* see comment above */
|
||||
|
@ -872,6 +891,50 @@ image_properties_cmd_callback (GtkAction *action,
|
|||
|
||||
/* private functions */
|
||||
|
||||
static void
|
||||
image_convert_precision_callback (GtkWidget *dialog,
|
||||
GimpImage *image,
|
||||
GimpPrecision precision,
|
||||
GeglDitherMethod layer_dither_method,
|
||||
GeglDitherMethod text_layer_dither_method,
|
||||
GeglDitherMethod channel_dither_method,
|
||||
gpointer user_data)
|
||||
{
|
||||
GimpDialogConfig *config = GIMP_DIALOG_CONFIG (image->gimp->config);
|
||||
GimpProgress *progress = user_data;
|
||||
const gchar *enum_desc;
|
||||
|
||||
g_object_set (config,
|
||||
"image-convert-precision-layer-dither-method",
|
||||
layer_dither_method,
|
||||
"image-convert-precision-text-layer-dither-method",
|
||||
text_layer_dither_method,
|
||||
"image-convert-precision-channel-dither-method",
|
||||
channel_dither_method,
|
||||
NULL);
|
||||
|
||||
gimp_enum_get_value (GIMP_TYPE_PRECISION, precision,
|
||||
NULL, NULL, &enum_desc, NULL);
|
||||
|
||||
progress = gimp_progress_start (progress, FALSE,
|
||||
_("Converting image to %s"),
|
||||
enum_desc);
|
||||
|
||||
gimp_image_convert_precision (image,
|
||||
precision,
|
||||
layer_dither_method,
|
||||
text_layer_dither_method,
|
||||
channel_dither_method,
|
||||
progress);
|
||||
|
||||
if (progress)
|
||||
gimp_progress_end (progress);
|
||||
|
||||
gimp_image_flush (image);
|
||||
|
||||
gtk_widget_destroy (dialog);
|
||||
}
|
||||
|
||||
static void
|
||||
image_resize_callback (GtkWidget *dialog,
|
||||
GimpViewable *viewable,
|
||||
|
|
|
@ -26,19 +26,11 @@
|
|||
#include "dialogs-types.h"
|
||||
|
||||
#include "gegl/gimp-babl.h"
|
||||
#include "gegl/gimp-gegl-utils.h"
|
||||
|
||||
#include "config/gimpdialogconfig.h"
|
||||
|
||||
#include "core/gimp.h"
|
||||
#include "core/gimpcontext.h"
|
||||
#include "core/gimpimage.h"
|
||||
#include "core/gimpimage-convert-precision.h"
|
||||
#include "core/gimplist.h"
|
||||
#include "core/gimpprogress.h"
|
||||
|
||||
#include "widgets/gimphelp-ids.h"
|
||||
#include "widgets/gimpviewablebox.h"
|
||||
#include "widgets/gimpviewabledialog.h"
|
||||
#include "widgets/gimpwidgets-utils.h"
|
||||
|
||||
|
@ -49,36 +41,40 @@
|
|||
|
||||
typedef struct
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
|
||||
GimpImage *image;
|
||||
GimpProgress *progress;
|
||||
|
||||
GimpComponentType component_type;
|
||||
gboolean linear;
|
||||
gint bits;
|
||||
GeglDitherMethod layer_dither_method;
|
||||
GeglDitherMethod text_layer_dither_method;
|
||||
GeglDitherMethod mask_dither_method;
|
||||
GimpImage *image;
|
||||
GimpComponentType component_type;
|
||||
gboolean linear;
|
||||
gint bits;
|
||||
GeglDitherMethod layer_dither_method;
|
||||
GeglDitherMethod text_layer_dither_method;
|
||||
GeglDitherMethod channel_dither_method;
|
||||
GimpConvertPrecisionCallback callback;
|
||||
gpointer user_data;
|
||||
} ConvertDialog;
|
||||
|
||||
|
||||
static void convert_precision_dialog_response (GtkWidget *widget,
|
||||
gint response_id,
|
||||
ConvertDialog *dialog);
|
||||
static void convert_precision_dialog_free (ConvertDialog *dialog);
|
||||
ConvertDialog *private);
|
||||
static void convert_precision_dialog_free (ConvertDialog *private);
|
||||
|
||||
|
||||
/* public functions */
|
||||
|
||||
GtkWidget *
|
||||
convert_precision_dialog_new (GimpImage *image,
|
||||
GimpContext *context,
|
||||
GtkWidget *parent,
|
||||
GimpComponentType component_type,
|
||||
GimpProgress *progress)
|
||||
convert_precision_dialog_new (GimpImage *image,
|
||||
GimpContext *context,
|
||||
GtkWidget *parent,
|
||||
GimpComponentType component_type,
|
||||
GeglDitherMethod layer_dither_method,
|
||||
GeglDitherMethod text_layer_dither_method,
|
||||
GeglDitherMethod channel_dither_method,
|
||||
GimpConvertPrecisionCallback callback,
|
||||
gpointer user_data)
|
||||
|
||||
{
|
||||
ConvertDialog *dialog;
|
||||
ConvertDialog *private;
|
||||
GtkWidget *dialog;
|
||||
GtkWidget *button;
|
||||
GtkWidget *main_vbox;
|
||||
GtkWidget *vbox;
|
||||
|
@ -96,9 +92,7 @@ convert_precision_dialog_new (GimpImage *image,
|
|||
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 (GTK_IS_WIDGET (parent), NULL);
|
||||
g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), NULL);
|
||||
|
||||
dialog = g_slice_new0 (ConvertDialog);
|
||||
g_return_val_if_fail (callback != NULL, NULL);
|
||||
|
||||
/* a random format with precision */
|
||||
format = gimp_babl_format (GIMP_RGB,
|
||||
|
@ -110,71 +104,61 @@ convert_precision_dialog_new (GimpImage *image,
|
|||
linear = gimp_babl_format_get_linear (gimp_image_get_layer_format (image,
|
||||
FALSE));
|
||||
|
||||
dialog->image = image;
|
||||
dialog->progress = progress;
|
||||
dialog->component_type = component_type;
|
||||
dialog->linear = linear;
|
||||
dialog->bits = bits;
|
||||
private = g_slice_new0 (ConvertDialog);
|
||||
|
||||
/* gegl:color-reduction only does 16 bits */
|
||||
if (bits <= 16)
|
||||
{
|
||||
GimpDialogConfig *config = GIMP_DIALOG_CONFIG (image->gimp->config);
|
||||
|
||||
dialog->layer_dither_method =
|
||||
config->image_convert_precision_layer_dither_method;
|
||||
|
||||
dialog->text_layer_dither_method =
|
||||
config->image_convert_precision_text_layer_dither_method;
|
||||
|
||||
dialog->mask_dither_method =
|
||||
config->image_convert_precision_channel_dither_method;
|
||||
}
|
||||
private->image = image;
|
||||
private->component_type = component_type;
|
||||
private->linear = linear;
|
||||
private->bits = bits;
|
||||
private->layer_dither_method = layer_dither_method;
|
||||
private->text_layer_dither_method = text_layer_dither_method;
|
||||
private->channel_dither_method = channel_dither_method;
|
||||
private->callback = callback;
|
||||
private->user_data = user_data;
|
||||
|
||||
gimp_enum_get_value (GIMP_TYPE_COMPONENT_TYPE, component_type,
|
||||
NULL, NULL, &enum_desc, NULL);
|
||||
|
||||
blurb = g_strdup_printf (_("Convert Image to %s"), enum_desc);
|
||||
|
||||
dialog->dialog =
|
||||
gimp_viewable_dialog_new (GIMP_VIEWABLE (image), context,
|
||||
_("Precision Conversion"),
|
||||
"gimp-image-convert-precision",
|
||||
GIMP_STOCK_CONVERT_PRECISION,
|
||||
blurb,
|
||||
parent,
|
||||
gimp_standard_help_func,
|
||||
GIMP_HELP_IMAGE_CONVERT_PRECISION,
|
||||
dialog = gimp_viewable_dialog_new (GIMP_VIEWABLE (image), context,
|
||||
_("Precision Conversion"),
|
||||
"gimp-image-convert-precision",
|
||||
GIMP_STOCK_CONVERT_PRECISION,
|
||||
blurb,
|
||||
parent,
|
||||
gimp_standard_help_func,
|
||||
GIMP_HELP_IMAGE_CONVERT_PRECISION,
|
||||
|
||||
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
||||
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
||||
|
||||
NULL);
|
||||
NULL);
|
||||
|
||||
g_free (blurb);
|
||||
|
||||
button = gtk_dialog_add_button (GTK_DIALOG (dialog->dialog),
|
||||
button = gtk_dialog_add_button (GTK_DIALOG (dialog),
|
||||
_("C_onvert"), GTK_RESPONSE_OK);
|
||||
gtk_button_set_image (GTK_BUTTON (button),
|
||||
gtk_image_new_from_icon_name (GIMP_STOCK_CONVERT_PRECISION,
|
||||
GTK_ICON_SIZE_BUTTON));
|
||||
|
||||
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog->dialog),
|
||||
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
|
||||
GTK_RESPONSE_OK,
|
||||
GTK_RESPONSE_CANCEL,
|
||||
-1);
|
||||
|
||||
gtk_window_set_resizable (GTK_WINDOW (dialog->dialog), FALSE);
|
||||
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
|
||||
|
||||
g_object_weak_ref (G_OBJECT (dialog->dialog),
|
||||
(GWeakNotify) convert_precision_dialog_free, dialog);
|
||||
g_object_weak_ref (G_OBJECT (dialog),
|
||||
(GWeakNotify) convert_precision_dialog_free, private);
|
||||
|
||||
g_signal_connect (dialog->dialog, "response",
|
||||
g_signal_connect (dialog, "response",
|
||||
G_CALLBACK (convert_precision_dialog_response),
|
||||
dialog);
|
||||
private);
|
||||
|
||||
main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
|
||||
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog->dialog))),
|
||||
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
|
||||
main_vbox, TRUE, TRUE, 0);
|
||||
gtk_widget_show (main_vbox);
|
||||
|
||||
|
@ -212,9 +196,9 @@ convert_precision_dialog_new (GimpImage *image,
|
|||
gtk_widget_show (combo);
|
||||
|
||||
gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo),
|
||||
dialog->layer_dither_method,
|
||||
private->layer_dither_method,
|
||||
G_CALLBACK (gimp_int_combo_box_get_active),
|
||||
&dialog->layer_dither_method);
|
||||
&private->layer_dither_method);
|
||||
|
||||
/* text layers */
|
||||
|
||||
|
@ -234,9 +218,9 @@ convert_precision_dialog_new (GimpImage *image,
|
|||
gtk_widget_show (combo);
|
||||
|
||||
gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo),
|
||||
dialog->text_layer_dither_method,
|
||||
private->text_layer_dither_method,
|
||||
G_CALLBACK (gimp_int_combo_box_get_active),
|
||||
&dialog->text_layer_dither_method);
|
||||
&private->text_layer_dither_method);
|
||||
|
||||
gimp_help_set_help_data (combo,
|
||||
_("Dithering text layers will make them uneditable"),
|
||||
|
@ -260,9 +244,9 @@ convert_precision_dialog_new (GimpImage *image,
|
|||
gtk_widget_show (combo);
|
||||
|
||||
gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo),
|
||||
dialog->mask_dither_method,
|
||||
private->channel_dither_method,
|
||||
G_CALLBACK (gimp_int_combo_box_get_active),
|
||||
&dialog->mask_dither_method);
|
||||
&private->channel_dither_method);
|
||||
|
||||
g_object_unref (size_group);
|
||||
|
||||
|
@ -278,7 +262,7 @@ convert_precision_dialog_new (GimpImage *image,
|
|||
|
||||
hbox = gimp_int_radio_group_new (FALSE, NULL,
|
||||
G_CALLBACK (gimp_radio_button_update),
|
||||
&dialog->linear,
|
||||
&private->linear,
|
||||
linear,
|
||||
|
||||
_("Perceptual gamma (sRGB)"), FALSE, NULL,
|
||||
|
@ -288,68 +272,38 @@ convert_precision_dialog_new (GimpImage *image,
|
|||
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
||||
gtk_widget_show (hbox);
|
||||
|
||||
return dialog->dialog;
|
||||
return dialog;
|
||||
}
|
||||
|
||||
|
||||
/* private functions */
|
||||
|
||||
static void
|
||||
convert_precision_dialog_response (GtkWidget *widget,
|
||||
convert_precision_dialog_response (GtkWidget *dialog,
|
||||
gint response_id,
|
||||
ConvertDialog *dialog)
|
||||
ConvertDialog *private)
|
||||
{
|
||||
if (response_id == GTK_RESPONSE_OK)
|
||||
{
|
||||
GimpProgress *progress;
|
||||
GimpPrecision precision;
|
||||
const gchar *enum_desc;
|
||||
GimpPrecision precision = gimp_babl_precision (private->component_type,
|
||||
private->linear);
|
||||
|
||||
precision = gimp_babl_precision (dialog->component_type,
|
||||
dialog->linear);
|
||||
|
||||
gimp_enum_get_value (GIMP_TYPE_PRECISION, precision,
|
||||
NULL, NULL, &enum_desc, NULL);
|
||||
|
||||
progress = gimp_progress_start (dialog->progress, FALSE,
|
||||
_("Converting image to %s"),
|
||||
enum_desc);
|
||||
|
||||
gimp_image_convert_precision (dialog->image,
|
||||
precision,
|
||||
dialog->layer_dither_method,
|
||||
dialog->text_layer_dither_method,
|
||||
dialog->mask_dither_method,
|
||||
progress);
|
||||
|
||||
if (progress)
|
||||
gimp_progress_end (progress);
|
||||
|
||||
gimp_image_flush (dialog->image);
|
||||
|
||||
/* gegl:color-reduction only does 16 bits */
|
||||
if (dialog->bits <= 16)
|
||||
{
|
||||
GimpDialogConfig *config =
|
||||
GIMP_DIALOG_CONFIG (dialog->image->gimp->config);
|
||||
|
||||
/* Save defaults for next time */
|
||||
g_object_set (config,
|
||||
"image-convert-precision-layer-dither-method",
|
||||
dialog->layer_dither_method,
|
||||
"image-convert-precision-text-layer-dither-method",
|
||||
dialog->text_layer_dither_method,
|
||||
"image-convert-precision-channel-dither-method",
|
||||
dialog->mask_dither_method,
|
||||
NULL);
|
||||
}
|
||||
private->callback (dialog,
|
||||
private->image,
|
||||
precision,
|
||||
private->layer_dither_method,
|
||||
private->text_layer_dither_method,
|
||||
private->channel_dither_method,
|
||||
private->user_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_widget_destroy (dialog);
|
||||
}
|
||||
|
||||
gtk_widget_destroy (dialog->dialog);
|
||||
}
|
||||
|
||||
static void
|
||||
convert_precision_dialog_free (ConvertDialog *dialog)
|
||||
convert_precision_dialog_free (ConvertDialog *private)
|
||||
{
|
||||
g_slice_free (ConvertDialog, dialog);
|
||||
g_slice_free (ConvertDialog, private);
|
||||
}
|
||||
|
|
|
@ -19,11 +19,24 @@
|
|||
#define __CONVERT_PRECISION_DIALOG_H__
|
||||
|
||||
|
||||
GtkWidget * convert_precision_dialog_new (GimpImage *image,
|
||||
GimpContext *context,
|
||||
GtkWidget *parent,
|
||||
GimpComponentType component_type,
|
||||
GimpProgress *progress);
|
||||
typedef void (* GimpConvertPrecisionCallback) (GtkWidget *dialog,
|
||||
GimpImage *image,
|
||||
GimpPrecision precision,
|
||||
GeglDitherMethod layer_dither_method,
|
||||
GeglDitherMethod text_layer_dither_method,
|
||||
GeglDitherMethod channel_dither_method,
|
||||
gpointer user_data);
|
||||
|
||||
|
||||
GtkWidget * convert_precision_dialog_new (GimpImage *image,
|
||||
GimpContext *context,
|
||||
GtkWidget *parent,
|
||||
GimpComponentType component_type,
|
||||
GeglDitherMethod layer_dither_method,
|
||||
GeglDitherMethod text_layer_dither_method,
|
||||
GeglDitherMethod channel_dither_method,
|
||||
GimpConvertPrecisionCallback callback,
|
||||
gpointer user_data);
|
||||
|
||||
|
||||
#endif /* __CONVERT_PRECISION_DIALOG_H__ */
|
||||
|
|
Loading…
Reference in New Issue