1999-10-04 02:54:54 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
|
|
|
*
|
2000-02-26 11:41:06 +08:00
|
|
|
* gimpexport.c
|
|
|
|
* Copyright (C) 1999-2000 Sven Neumann <sven@gimp.org>
|
|
|
|
*
|
1999-10-04 02:54:54 +08:00
|
|
|
* This library is free software; you can redistribute it and/or
|
1999-11-18 05:13:50 +08:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
1999-10-04 02:54:54 +08:00
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
1999-11-18 05:13:50 +08:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
1999-10-04 02:54:54 +08:00
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
2000-06-01 05:16:11 +08:00
|
|
|
|
1999-11-14 10:08:07 +08:00
|
|
|
#include "config.h"
|
1999-10-04 02:54:54 +08:00
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "gimp.h"
|
2000-06-01 05:16:11 +08:00
|
|
|
#include "gimpui.h"
|
2000-01-27 09:54:52 +08:00
|
|
|
|
|
|
|
#include "libgimp-intl.h"
|
1999-10-04 02:54:54 +08:00
|
|
|
|
2000-06-01 05:16:11 +08:00
|
|
|
|
2000-11-18 08:25:42 +08:00
|
|
|
typedef void (* ExportFunc) (gint32 imageID,
|
|
|
|
gint32 *drawable_ID);
|
|
|
|
|
1999-10-04 02:54:54 +08:00
|
|
|
|
|
|
|
/* the export action structure */
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
ExportFunc default_action;
|
|
|
|
ExportFunc alt_action;
|
|
|
|
gchar *reason;
|
|
|
|
gchar *possibilities[2];
|
|
|
|
gint choice;
|
|
|
|
} ExportAction;
|
|
|
|
|
|
|
|
|
|
|
|
/* the functions that do the actual export */
|
1999-10-24 21:26:30 +08:00
|
|
|
|
1999-10-04 02:54:54 +08:00
|
|
|
static void
|
|
|
|
export_merge (gint32 image_ID,
|
|
|
|
gint32 *drawable_ID)
|
|
|
|
{
|
2000-02-09 01:04:19 +08:00
|
|
|
gint32 nlayers;
|
|
|
|
gint32 nvisible = 0;
|
|
|
|
gint32 i;
|
1999-10-24 21:26:30 +08:00
|
|
|
gint32 *layers;
|
2000-02-09 01:04:19 +08:00
|
|
|
gint32 merged;
|
2001-10-25 01:34:44 +08:00
|
|
|
gint32 transp;
|
1999-10-24 21:26:30 +08:00
|
|
|
|
2000-02-09 01:04:19 +08:00
|
|
|
layers = gimp_image_get_layers (image_ID, &nlayers);
|
|
|
|
for (i = 0; i < nlayers; i++)
|
|
|
|
{
|
|
|
|
if (gimp_drawable_visible (layers[i]))
|
2001-10-25 01:34:44 +08:00
|
|
|
nvisible++;
|
2000-02-09 01:04:19 +08:00
|
|
|
}
|
|
|
|
|
2001-10-25 01:34:44 +08:00
|
|
|
if (nvisible <= 1)
|
|
|
|
{
|
|
|
|
/* if there is only one (or zero) visible layer, add a new transparent
|
|
|
|
layer that has the same size as the canvas. The merge that follows
|
|
|
|
will ensure that the offset, opacity and size are correct */
|
|
|
|
transp = gimp_layer_new (image_ID, "-",
|
|
|
|
gimp_image_width (image_ID),
|
|
|
|
gimp_image_height (image_ID),
|
|
|
|
gimp_drawable_type (*drawable_ID) | 1,
|
|
|
|
100.0, GIMP_NORMAL_MODE);
|
|
|
|
gimp_image_add_layer (image_ID, transp, 1);
|
|
|
|
gimp_selection_none (image_ID);
|
|
|
|
gimp_edit_clear (transp);
|
|
|
|
nvisible++;
|
|
|
|
}
|
2000-02-09 01:04:19 +08:00
|
|
|
|
|
|
|
if (nvisible > 1)
|
|
|
|
{
|
|
|
|
g_free (layers);
|
|
|
|
merged = gimp_image_merge_visible_layers (image_ID, GIMP_CLIP_TO_IMAGE);
|
|
|
|
|
|
|
|
if (merged != -1)
|
|
|
|
*drawable_ID = merged;
|
|
|
|
else
|
|
|
|
return; /* shouldn't happen */
|
|
|
|
|
|
|
|
layers = gimp_image_get_layers (image_ID, &nlayers);
|
|
|
|
}
|
1999-10-24 21:26:30 +08:00
|
|
|
|
|
|
|
/* remove any remaining (invisible) layers */
|
|
|
|
for (i = 0; i < nlayers; i++)
|
|
|
|
{
|
|
|
|
if (layers[i] != *drawable_ID)
|
|
|
|
gimp_image_remove_layer (image_ID, layers[i]);
|
|
|
|
}
|
|
|
|
g_free (layers);
|
1999-10-04 02:54:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
export_flatten (gint32 image_ID,
|
|
|
|
gint32 *drawable_ID)
|
|
|
|
{
|
2000-02-09 01:04:19 +08:00
|
|
|
gint32 flattened;
|
|
|
|
|
|
|
|
flattened = gimp_image_flatten (image_ID);
|
|
|
|
|
|
|
|
if (flattened != -1)
|
|
|
|
*drawable_ID = flattened;
|
1999-10-04 02:54:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
export_convert_rgb (gint32 image_ID,
|
|
|
|
gint32 *drawable_ID)
|
|
|
|
{
|
|
|
|
gimp_image_convert_rgb (image_ID);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
export_convert_grayscale (gint32 image_ID,
|
|
|
|
gint32 *drawable_ID)
|
|
|
|
{
|
|
|
|
gimp_image_convert_grayscale (image_ID);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
export_convert_indexed (gint32 image_ID,
|
|
|
|
gint32 *drawable_ID)
|
|
|
|
{
|
2000-02-09 01:04:19 +08:00
|
|
|
gint32 nlayers;
|
1999-10-04 02:54:54 +08:00
|
|
|
|
|
|
|
/* check alpha */
|
|
|
|
g_free (gimp_image_get_layers (image_ID, &nlayers));
|
|
|
|
if (nlayers > 1 || gimp_drawable_has_alpha (*drawable_ID))
|
|
|
|
gimp_image_convert_indexed (image_ID, GIMP_FS_DITHER, GIMP_MAKE_PALETTE, 255, FALSE, FALSE, "");
|
|
|
|
else
|
|
|
|
gimp_image_convert_indexed (image_ID, GIMP_FS_DITHER, GIMP_MAKE_PALETTE, 256, FALSE, FALSE, "");
|
|
|
|
}
|
|
|
|
|
1999-10-09 08:11:50 +08:00
|
|
|
static void
|
|
|
|
export_add_alpha (gint32 image_ID,
|
|
|
|
gint32 *drawable_ID)
|
|
|
|
{
|
2000-02-09 01:04:19 +08:00
|
|
|
gint32 nlayers;
|
|
|
|
gint32 i;
|
1999-10-09 08:11:50 +08:00
|
|
|
gint32 *layers;
|
|
|
|
|
|
|
|
layers = gimp_image_get_layers (image_ID, &nlayers);
|
|
|
|
for (i = 0; i < nlayers; i++)
|
|
|
|
{
|
|
|
|
if (!gimp_drawable_has_alpha (layers[i]))
|
|
|
|
gimp_layer_add_alpha (layers[i]);
|
|
|
|
}
|
|
|
|
g_free (layers);
|
|
|
|
}
|
|
|
|
|
1999-10-24 21:26:30 +08:00
|
|
|
|
1999-10-04 02:54:54 +08:00
|
|
|
/* a set of predefined actions */
|
|
|
|
|
|
|
|
static ExportAction export_action_merge =
|
|
|
|
{
|
|
|
|
export_merge,
|
|
|
|
NULL,
|
2000-06-28 06:02:27 +08:00
|
|
|
N_("can't handle layers"),
|
2000-01-11 23:48:00 +08:00
|
|
|
{ N_("Merge Visible Layers"), NULL },
|
1999-10-04 02:54:54 +08:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2001-10-25 01:34:44 +08:00
|
|
|
static ExportAction export_action_merge_single =
|
|
|
|
{
|
|
|
|
export_merge,
|
|
|
|
NULL,
|
|
|
|
N_("can't handle layer offsets, size or opacity"),
|
|
|
|
{ N_("Merge Visible Layers"), NULL },
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
1999-10-04 02:54:54 +08:00
|
|
|
static ExportAction export_action_animate_or_merge =
|
|
|
|
{
|
|
|
|
export_merge,
|
2000-07-09 23:47:11 +08:00
|
|
|
NULL,
|
2000-06-28 06:02:27 +08:00
|
|
|
N_("can only handle layers as animation frames"),
|
2000-07-09 23:47:11 +08:00
|
|
|
{ N_("Merge Visible Layers"), N_("Save as Animation")},
|
1999-10-04 02:54:54 +08:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2000-04-08 04:04:00 +08:00
|
|
|
static ExportAction export_action_animate_or_flatten =
|
|
|
|
{
|
|
|
|
export_flatten,
|
2000-07-09 23:47:11 +08:00
|
|
|
NULL,
|
2000-06-28 06:02:27 +08:00
|
|
|
N_("can only handle layers as animation frames"),
|
2000-07-09 23:47:11 +08:00
|
|
|
{ N_("Flatten Image"), N_("Save as Animation") },
|
2000-04-08 04:04:00 +08:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2000-06-26 07:18:56 +08:00
|
|
|
static ExportAction export_action_merge_flat =
|
|
|
|
{
|
|
|
|
export_flatten,
|
|
|
|
NULL,
|
2000-06-28 06:02:27 +08:00
|
|
|
N_("can't handle layers"),
|
2000-06-26 07:18:56 +08:00
|
|
|
{ N_("Flatten Image"), NULL },
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
1999-10-04 02:54:54 +08:00
|
|
|
static ExportAction export_action_flatten =
|
|
|
|
{
|
2000-04-08 04:04:00 +08:00
|
|
|
export_flatten,
|
1999-10-04 02:54:54 +08:00
|
|
|
NULL,
|
2000-06-28 06:02:27 +08:00
|
|
|
N_("can't handle transparency"),
|
1999-10-04 02:54:54 +08:00
|
|
|
{ N_("Flatten Image"), NULL },
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
static ExportAction export_action_convert_rgb =
|
|
|
|
{
|
2000-04-08 04:04:00 +08:00
|
|
|
export_convert_rgb,
|
1999-10-04 02:54:54 +08:00
|
|
|
NULL,
|
2000-06-28 06:02:27 +08:00
|
|
|
N_("can only handle RGB images"),
|
1999-10-04 02:54:54 +08:00
|
|
|
{ N_("Convert to RGB"), NULL },
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
static ExportAction export_action_convert_grayscale =
|
|
|
|
{
|
2000-04-08 04:04:00 +08:00
|
|
|
export_convert_grayscale,
|
1999-10-04 02:54:54 +08:00
|
|
|
NULL,
|
2000-06-28 06:02:27 +08:00
|
|
|
N_("can only handle grayscale images"),
|
2000-01-11 23:48:00 +08:00
|
|
|
{ N_("Convert to Grayscale"), NULL },
|
1999-10-04 02:54:54 +08:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
static ExportAction export_action_convert_indexed =
|
|
|
|
{
|
2000-04-08 04:04:00 +08:00
|
|
|
export_convert_indexed,
|
1999-10-04 02:54:54 +08:00
|
|
|
NULL,
|
2000-06-28 06:02:27 +08:00
|
|
|
N_("can only handle indexed images"),
|
|
|
|
{ N_("Convert to Indexed using default settings\n"
|
2000-01-11 23:48:00 +08:00
|
|
|
"(Do it manually to tune the result)"), NULL },
|
1999-10-04 02:54:54 +08:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
static ExportAction export_action_convert_rgb_or_grayscale =
|
|
|
|
{
|
2000-04-08 04:04:00 +08:00
|
|
|
export_convert_rgb,
|
|
|
|
export_convert_grayscale,
|
2000-06-28 06:02:27 +08:00
|
|
|
N_("can only handle RGB or grayscale images"),
|
2000-01-11 23:48:00 +08:00
|
|
|
{ N_("Convert to RGB"), N_("Convert to Grayscale")},
|
1999-10-04 02:54:54 +08:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
static ExportAction export_action_convert_rgb_or_indexed =
|
|
|
|
{
|
2000-04-08 04:04:00 +08:00
|
|
|
export_convert_rgb,
|
|
|
|
export_convert_indexed,
|
2000-06-28 06:02:27 +08:00
|
|
|
N_("can only handle RGB or indexed images"),
|
|
|
|
{ N_("Convert to RGB"), N_("Convert to Indexed using default settings\n"
|
2000-01-11 23:48:00 +08:00
|
|
|
"(Do it manually to tune the result)")},
|
1999-10-04 02:54:54 +08:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
static ExportAction export_action_convert_indexed_or_grayscale =
|
|
|
|
{
|
2000-04-08 04:04:00 +08:00
|
|
|
export_convert_indexed,
|
|
|
|
export_convert_grayscale,
|
2000-06-28 06:02:27 +08:00
|
|
|
N_("can only handle grayscale or indexed images"),
|
|
|
|
{ N_("Convert to Indexed using default settings\n"
|
2000-01-11 23:48:00 +08:00
|
|
|
"(Do it manually to tune the result)"),
|
|
|
|
N_("Convert to Grayscale") },
|
1999-10-04 02:54:54 +08:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
1999-10-09 08:11:50 +08:00
|
|
|
static ExportAction export_action_add_alpha =
|
|
|
|
{
|
2000-04-08 04:04:00 +08:00
|
|
|
export_add_alpha,
|
1999-10-09 08:11:50 +08:00
|
|
|
NULL,
|
2000-06-28 06:02:27 +08:00
|
|
|
N_("needs an alpha channel"),
|
2000-01-11 23:48:00 +08:00
|
|
|
{ N_("Add Alpha Channel"), NULL},
|
1999-10-09 08:11:50 +08:00
|
|
|
0
|
|
|
|
};
|
1999-10-04 02:54:54 +08:00
|
|
|
|
1999-10-24 21:26:30 +08:00
|
|
|
|
1999-10-04 02:54:54 +08:00
|
|
|
/* dialog functions */
|
|
|
|
|
1999-10-04 07:48:33 +08:00
|
|
|
static GtkWidget *dialog = NULL;
|
2000-08-24 22:17:34 +08:00
|
|
|
static GimpExportReturnType dialog_return = GIMP_EXPORT_CANCEL;
|
1999-10-04 02:54:54 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
export_export_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gtk_widget_destroy (dialog);
|
2000-08-24 22:17:34 +08:00
|
|
|
dialog_return = GIMP_EXPORT_EXPORT;
|
1999-10-04 07:48:33 +08:00
|
|
|
}
|
|
|
|
|
2001-10-25 01:34:44 +08:00
|
|
|
static void
|
|
|
|
export_confirm_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gtk_widget_destroy (dialog);
|
|
|
|
dialog_return = GIMP_EXPORT_EXPORT;
|
|
|
|
}
|
|
|
|
|
1999-10-04 07:48:33 +08:00
|
|
|
static void
|
|
|
|
export_skip_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gtk_widget_destroy (dialog);
|
2000-08-24 22:17:34 +08:00
|
|
|
dialog_return = GIMP_EXPORT_IGNORE;
|
1999-10-04 02:54:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
export_cancel_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2000-08-24 22:17:34 +08:00
|
|
|
dialog_return = GIMP_EXPORT_CANCEL;
|
1999-10-04 02:54:54 +08:00
|
|
|
dialog = NULL;
|
|
|
|
gtk_main_quit ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
export_toggle_callback (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gint *choice = (gint*)data;
|
|
|
|
|
|
|
|
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
|
|
|
|
*choice = 0;
|
|
|
|
else
|
|
|
|
*choice = 1;
|
|
|
|
}
|
|
|
|
|
2001-10-25 01:34:44 +08:00
|
|
|
static gint
|
|
|
|
confirm_save_dialog (const gchar *saving_what,
|
|
|
|
const gchar *format_name)
|
|
|
|
{
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *label;
|
|
|
|
gchar *text;
|
|
|
|
|
|
|
|
dialog_return = GIMP_EXPORT_CANCEL;
|
|
|
|
g_return_val_if_fail (saving_what != NULL && format_name != NULL, dialog_return);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Plug-ins must have called gtk_init () before calling gimp_export ().
|
|
|
|
* Otherwise bad things will happen now!!
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* the dialog */
|
|
|
|
|
|
|
|
dialog = gimp_dialog_new (_("Confirm Save"), "confirm_save",
|
|
|
|
gimp_standard_help_func, "dialogs/confirm_save.html",
|
|
|
|
GTK_WIN_POS_MOUSE,
|
|
|
|
FALSE, FALSE, FALSE,
|
|
|
|
_("Confirm"), export_confirm_callback,
|
|
|
|
NULL, NULL, NULL, TRUE, FALSE,
|
|
|
|
_("Cancel"), gtk_widget_destroy,
|
|
|
|
NULL, 1, NULL, FALSE, TRUE,
|
|
|
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gtk_signal_connect (GTK_OBJECT (dialog), "destroy",
|
|
|
|
GTK_SIGNAL_FUNC (export_cancel_callback),
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
vbox = gtk_vbox_new (FALSE, 6);
|
|
|
|
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), vbox);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (vbox), 6);
|
|
|
|
gtk_widget_show (vbox);
|
|
|
|
|
|
|
|
text = g_strdup_printf (_("You are about to save %s as %s.\n"
|
|
|
|
"This will not save the visible layers."),
|
|
|
|
saving_what, format_name);
|
|
|
|
label = gtk_label_new (text);
|
|
|
|
g_free (text);
|
|
|
|
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
gtk_widget_show (dialog);
|
|
|
|
gtk_main ();
|
|
|
|
|
|
|
|
return dialog_return;
|
|
|
|
}
|
|
|
|
|
1999-10-04 02:54:54 +08:00
|
|
|
static gint
|
2000-11-18 08:25:42 +08:00
|
|
|
export_dialog (GSList *actions,
|
2001-10-25 01:34:44 +08:00
|
|
|
const gchar *format_name)
|
1999-10-04 02:54:54 +08:00
|
|
|
{
|
2000-01-11 23:48:00 +08:00
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *button;
|
|
|
|
GtkWidget *label;
|
|
|
|
GSList *list;
|
|
|
|
gchar *text;
|
1999-10-04 02:54:54 +08:00
|
|
|
ExportAction *action;
|
|
|
|
|
2000-08-24 22:17:34 +08:00
|
|
|
dialog_return = GIMP_EXPORT_CANCEL;
|
2001-10-25 01:34:44 +08:00
|
|
|
g_return_val_if_fail (actions != NULL && format_name != NULL, dialog_return);
|
1999-10-04 02:54:54 +08:00
|
|
|
|
|
|
|
/*
|
2001-10-25 01:34:44 +08:00
|
|
|
* Plug-ins must have called gtk_init () before calling gimp_export ().
|
1999-10-04 02:54:54 +08:00
|
|
|
* Otherwise bad things will happen now!!
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* the dialog */
|
2001-10-25 01:34:44 +08:00
|
|
|
|
2000-01-11 23:48:00 +08:00
|
|
|
dialog = gimp_dialog_new (_("Export File"), "export_file",
|
|
|
|
gimp_standard_help_func, "dialogs/export_file.html",
|
|
|
|
GTK_WIN_POS_MOUSE,
|
|
|
|
FALSE, FALSE, FALSE,
|
|
|
|
|
|
|
|
_("Export"), export_export_callback,
|
|
|
|
NULL, NULL, NULL, TRUE, FALSE,
|
|
|
|
_("Ignore"), export_skip_callback,
|
|
|
|
NULL, NULL, NULL, FALSE, FALSE,
|
2001-08-04 03:52:08 +08:00
|
|
|
GTK_STOCK_CANCEL, gtk_widget_destroy,
|
2000-01-11 23:48:00 +08:00
|
|
|
NULL, 1, NULL, FALSE, TRUE,
|
|
|
|
|
|
|
|
NULL);
|
|
|
|
|
2001-07-31 20:10:14 +08:00
|
|
|
g_signal_connect (G_OBJECT (dialog), "destroy",
|
|
|
|
G_CALLBACK (export_cancel_callback),
|
|
|
|
NULL);
|
1999-10-04 02:54:54 +08:00
|
|
|
|
|
|
|
/* the headline */
|
1999-11-20 23:52:25 +08:00
|
|
|
vbox = gtk_vbox_new (FALSE, 6);
|
|
|
|
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), vbox);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (vbox), 6);
|
|
|
|
gtk_widget_show (vbox);
|
|
|
|
|
2000-01-11 23:48:00 +08:00
|
|
|
label = gtk_label_new (_("Your image should be exported before it "
|
|
|
|
"can be saved for the following reasons:"));
|
1999-10-04 02:54:54 +08:00
|
|
|
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
|
|
|
|
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER);
|
1999-11-20 23:52:25 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
|
1999-10-04 02:54:54 +08:00
|
|
|
gtk_widget_show (label);
|
|
|
|
|
|
|
|
for (list = actions; list; list = list->next)
|
|
|
|
{
|
2000-01-11 23:48:00 +08:00
|
|
|
action = (ExportAction *) (list->data);
|
|
|
|
|
2001-10-25 01:34:44 +08:00
|
|
|
text = g_strdup_printf ("%s %s", format_name, gettext (action->reason));
|
1999-10-04 02:54:54 +08:00
|
|
|
frame = gtk_frame_new (text);
|
|
|
|
g_free (text);
|
1999-11-20 23:52:25 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
|
2000-01-11 23:48:00 +08:00
|
|
|
|
1999-11-20 23:52:25 +08:00
|
|
|
hbox = gtk_hbox_new (FALSE, 4);
|
1999-10-04 02:54:54 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (frame), hbox);
|
2000-01-11 23:48:00 +08:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (hbox), 4);
|
1999-11-20 23:52:25 +08:00
|
|
|
|
1999-10-04 02:54:54 +08:00
|
|
|
if (action->possibilities[0] && action->possibilities[1])
|
|
|
|
{
|
|
|
|
GSList *radio_group = NULL;
|
|
|
|
|
|
|
|
button = gtk_radio_button_new_with_label (radio_group,
|
|
|
|
gettext (action->possibilities[0]));
|
2001-07-31 20:10:14 +08:00
|
|
|
gtk_label_set_justify (GTK_LABEL (GTK_BIN (button)->child),
|
|
|
|
GTK_JUSTIFY_LEFT);
|
|
|
|
radio_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));
|
1999-11-20 23:52:25 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
|
2001-07-31 20:10:14 +08:00
|
|
|
g_signal_connect (G_OBJECT (button), "toggled",
|
|
|
|
G_CALLBACK (export_toggle_callback),
|
|
|
|
&action->choice);
|
1999-10-04 02:54:54 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
|
|
|
|
gtk_widget_show (button);
|
|
|
|
|
|
|
|
button = gtk_radio_button_new_with_label (radio_group,
|
|
|
|
gettext (action->possibilities[1]));
|
2001-07-31 20:10:14 +08:00
|
|
|
gtk_label_set_justify (GTK_LABEL (GTK_BIN (button)->child),
|
|
|
|
GTK_JUSTIFY_LEFT);
|
|
|
|
radio_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));
|
1999-11-20 23:52:25 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
|
1999-10-04 02:54:54 +08:00
|
|
|
gtk_widget_show (button);
|
|
|
|
}
|
|
|
|
else if (action->possibilities[0])
|
|
|
|
{
|
|
|
|
label = gtk_label_new (gettext (action->possibilities[0]));
|
|
|
|
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
|
1999-11-20 23:52:25 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 2);
|
1999-10-04 02:54:54 +08:00
|
|
|
gtk_widget_show (label);
|
|
|
|
action->choice = 0;
|
|
|
|
}
|
|
|
|
else if (action->possibilities[1])
|
|
|
|
{
|
|
|
|
label = gtk_label_new (gettext (action->possibilities[1]));
|
|
|
|
gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
|
1999-11-20 23:52:25 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 2);
|
1999-10-04 02:54:54 +08:00
|
|
|
gtk_widget_show (label);
|
|
|
|
action->choice = 1;
|
|
|
|
}
|
|
|
|
gtk_widget_show (hbox);
|
|
|
|
gtk_widget_show (frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the footline */
|
2000-02-09 01:04:19 +08:00
|
|
|
label = gtk_label_new (_("The export conversion won't modify your original image."));
|
1999-11-20 23:52:25 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
|
1999-10-04 02:54:54 +08:00
|
|
|
gtk_widget_show (label);
|
1999-11-20 23:52:25 +08:00
|
|
|
|
1999-10-04 02:54:54 +08:00
|
|
|
gtk_widget_show (dialog);
|
|
|
|
gtk_main ();
|
|
|
|
|
2000-01-11 23:48:00 +08:00
|
|
|
return dialog_return;
|
1999-10-04 02:54:54 +08:00
|
|
|
}
|
|
|
|
|
2000-02-05 02:55:32 +08:00
|
|
|
/**
|
|
|
|
* gimp_export_image:
|
|
|
|
* @image_ID: Pointer to the image_ID.
|
|
|
|
* @drawable_ID: Pointer to the drawable_ID.
|
2000-02-07 05:19:10 +08:00
|
|
|
* @format_name: The (short) name of the image_format (e.g. JPEG or GIF).
|
2000-02-05 02:55:32 +08:00
|
|
|
* @capabilities: What can the image_format do?
|
|
|
|
*
|
2000-02-07 05:19:10 +08:00
|
|
|
* Takes an image and a drawable to be saved together with a
|
|
|
|
* description of the capabilities of the image_format. If the
|
|
|
|
* type of image doesn't match the capabilities of the format
|
2000-02-05 02:55:32 +08:00
|
|
|
* a dialog is opened that informs the user that the image has
|
|
|
|
* to be exported and offers to do the necessary conversions.
|
|
|
|
*
|
|
|
|
* If the user chooses to export the image, a copy is created.
|
|
|
|
* This copy is then converted, the image_ID and drawable_ID
|
|
|
|
* are changed to point to the new image and the procedure returns
|
2000-08-24 22:17:34 +08:00
|
|
|
* GIMP_EXPORT_EXPORT. The save_plugin has to take care of deleting the
|
2000-02-07 05:19:10 +08:00
|
|
|
* created image using gimp_image_delete() when it has saved it.
|
2000-02-05 02:55:32 +08:00
|
|
|
*
|
|
|
|
* If the user chooses to Ignore the export problem, the image_ID
|
2000-08-24 22:17:34 +08:00
|
|
|
* and drawable_ID is not altered, GIMP_EXPORT_IGNORE is returned and
|
2000-02-05 02:55:32 +08:00
|
|
|
* the save_plugin should try to save the original image. If the
|
2000-08-24 22:17:34 +08:00
|
|
|
* user chooses Cancel, GIMP_EXPORT_CANCEL is returned and the
|
2000-02-05 02:55:32 +08:00
|
|
|
* save_plugin should quit itself with status #STATUS_CANCEL.
|
|
|
|
*
|
2000-02-05 03:15:53 +08:00
|
|
|
* Returns: An enum of #GimpExportReturnType describing the user_action.
|
2000-11-18 08:25:42 +08:00
|
|
|
**/
|
1999-10-04 07:48:33 +08:00
|
|
|
GimpExportReturnType
|
2000-02-07 05:19:10 +08:00
|
|
|
gimp_export_image (gint32 *image_ID,
|
|
|
|
gint32 *drawable_ID,
|
2000-11-18 08:25:42 +08:00
|
|
|
const gchar *format_name,
|
2000-02-07 05:19:10 +08:00
|
|
|
GimpExportCapabilities capabilities)
|
1999-10-04 02:54:54 +08:00
|
|
|
{
|
1999-10-22 03:35:35 +08:00
|
|
|
GSList *actions = NULL;
|
|
|
|
GSList *list;
|
1999-10-04 02:54:54 +08:00
|
|
|
GimpImageBaseType type;
|
2000-02-09 01:04:19 +08:00
|
|
|
gint32 i;
|
|
|
|
gint32 nlayers;
|
1999-10-09 08:11:50 +08:00
|
|
|
gint32* layers;
|
2001-10-25 01:34:44 +08:00
|
|
|
gint offset_x;
|
|
|
|
gint offset_y;
|
1999-10-04 02:54:54 +08:00
|
|
|
gboolean added_flatten = FALSE;
|
2000-04-10 09:46:51 +08:00
|
|
|
gboolean background_has_alpha = TRUE;
|
1999-10-04 02:54:54 +08:00
|
|
|
ExportAction *action;
|
|
|
|
|
2000-02-05 02:55:32 +08:00
|
|
|
g_return_val_if_fail (*image_ID > -1 && *drawable_ID > -1, FALSE);
|
1999-10-04 02:54:54 +08:00
|
|
|
|
1999-10-09 08:11:50 +08:00
|
|
|
/* do some sanity checks */
|
2000-08-24 22:17:34 +08:00
|
|
|
if (capabilities & GIMP_EXPORT_NEEDS_ALPHA)
|
|
|
|
capabilities |= GIMP_EXPORT_CAN_HANDLE_ALPHA ;
|
|
|
|
if (capabilities & GIMP_EXPORT_CAN_HANDLE_LAYERS_AS_ANIMATION)
|
|
|
|
capabilities |= GIMP_EXPORT_CAN_HANDLE_LAYERS;
|
1999-10-09 08:11:50 +08:00
|
|
|
|
2001-10-25 01:34:44 +08:00
|
|
|
/* ask for confirmation if the user is not saving a layer (see bug #51114) */
|
|
|
|
if (!gimp_drawable_is_layer (*drawable_ID)
|
|
|
|
&& !(capabilities & GIMP_EXPORT_CAN_HANDLE_LAYERS))
|
|
|
|
{
|
|
|
|
if (gimp_drawable_is_layer_mask (*drawable_ID))
|
|
|
|
dialog_return = confirm_save_dialog (_("a layer mask"), format_name);
|
|
|
|
else if (gimp_drawable_is_channel (*drawable_ID))
|
|
|
|
dialog_return = confirm_save_dialog (_("a channel (saved selection)"),
|
|
|
|
format_name);
|
|
|
|
else
|
|
|
|
; /* this should not happen */
|
|
|
|
|
|
|
|
/* cancel - the user can then select an appropriate layer to save */
|
|
|
|
if (dialog_return == GIMP_EXPORT_CANCEL)
|
|
|
|
return GIMP_EXPORT_CANCEL;
|
|
|
|
}
|
|
|
|
|
1999-10-04 02:54:54 +08:00
|
|
|
/* check alpha */
|
2000-02-05 02:55:32 +08:00
|
|
|
layers = gimp_image_get_layers (*image_ID, &nlayers);
|
1999-10-09 08:11:50 +08:00
|
|
|
for (i = 0; i < nlayers; i++)
|
1999-10-04 02:54:54 +08:00
|
|
|
{
|
1999-10-09 08:11:50 +08:00
|
|
|
if (gimp_drawable_has_alpha (layers[i]))
|
1999-10-04 02:54:54 +08:00
|
|
|
{
|
2000-04-08 04:04:00 +08:00
|
|
|
|
2000-08-24 22:17:34 +08:00
|
|
|
if ( !(capabilities & GIMP_EXPORT_CAN_HANDLE_ALPHA ) )
|
1999-10-09 08:11:50 +08:00
|
|
|
{
|
1999-10-22 03:35:35 +08:00
|
|
|
actions = g_slist_prepend (actions, &export_action_flatten);
|
1999-10-09 08:11:50 +08:00
|
|
|
added_flatten = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-04-10 09:46:51 +08:00
|
|
|
/* If this is the last layer, it's visible and has no alpha
|
|
|
|
channel, then the image has a "flat" background */
|
2001-10-25 01:34:44 +08:00
|
|
|
if (i == nlayers - 1 && gimp_layer_get_visible (layers[i]))
|
2000-04-10 09:46:51 +08:00
|
|
|
background_has_alpha = FALSE;
|
|
|
|
|
2000-08-24 22:17:34 +08:00
|
|
|
if (capabilities & GIMP_EXPORT_NEEDS_ALPHA)
|
1999-10-09 08:11:50 +08:00
|
|
|
{
|
1999-10-22 03:35:35 +08:00
|
|
|
actions = g_slist_prepend (actions, &export_action_add_alpha);
|
1999-10-09 08:11:50 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1999-10-04 02:54:54 +08:00
|
|
|
}
|
1999-10-09 08:11:50 +08:00
|
|
|
g_free (layers);
|
1999-10-04 02:54:54 +08:00
|
|
|
|
2001-10-25 01:34:44 +08:00
|
|
|
/* check if layer size != canvas size, opacity != 100%, or offsets != 0 */
|
|
|
|
if (!added_flatten && nlayers == 1 && gimp_drawable_is_layer (*drawable_ID)
|
|
|
|
&& !(capabilities & GIMP_EXPORT_CAN_HANDLE_LAYERS))
|
|
|
|
{
|
|
|
|
gimp_drawable_offsets (*drawable_ID, &offset_x, &offset_y);
|
|
|
|
if ((gimp_layer_get_opacity (*drawable_ID) < 100.0)
|
|
|
|
|| (gimp_image_width (*image_ID)
|
|
|
|
!= gimp_drawable_width (*drawable_ID))
|
|
|
|
|| (gimp_image_height (*image_ID)
|
|
|
|
!= gimp_drawable_height (*drawable_ID))
|
|
|
|
|| offset_x || offset_y)
|
|
|
|
{
|
|
|
|
if (capabilities & GIMP_EXPORT_CAN_HANDLE_ALPHA)
|
|
|
|
actions = g_slist_prepend (actions, &export_action_merge_single);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
actions = g_slist_prepend (actions, &export_action_flatten);
|
|
|
|
added_flatten = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-10-04 02:54:54 +08:00
|
|
|
/* check multiple layers */
|
2001-10-25 01:34:44 +08:00
|
|
|
else if (!added_flatten && nlayers > 1)
|
1999-10-04 02:54:54 +08:00
|
|
|
{
|
2000-08-24 22:17:34 +08:00
|
|
|
if (capabilities & GIMP_EXPORT_CAN_HANDLE_LAYERS_AS_ANIMATION)
|
2000-04-08 04:04:00 +08:00
|
|
|
{
|
2000-08-24 22:17:34 +08:00
|
|
|
if (background_has_alpha || capabilities & GIMP_EXPORT_NEEDS_ALPHA)
|
2000-04-08 04:04:00 +08:00
|
|
|
actions = g_slist_prepend (actions, &export_action_animate_or_merge);
|
|
|
|
else
|
|
|
|
actions = g_slist_prepend (actions, &export_action_animate_or_flatten);
|
|
|
|
}
|
2000-08-24 22:17:34 +08:00
|
|
|
else if ( !(capabilities & GIMP_EXPORT_CAN_HANDLE_LAYERS))
|
2000-04-08 04:04:00 +08:00
|
|
|
{
|
2000-08-24 22:17:34 +08:00
|
|
|
if (background_has_alpha || capabilities & GIMP_EXPORT_NEEDS_ALPHA)
|
2000-04-08 04:04:00 +08:00
|
|
|
actions = g_slist_prepend (actions, &export_action_merge);
|
|
|
|
else
|
2000-06-26 07:18:56 +08:00
|
|
|
actions = g_slist_prepend (actions, &export_action_merge_flat);
|
2000-04-08 04:04:00 +08:00
|
|
|
}
|
1999-10-04 02:54:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check the image type */
|
2000-02-05 02:55:32 +08:00
|
|
|
type = gimp_image_base_type (*image_ID);
|
1999-10-04 02:54:54 +08:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case GIMP_RGB:
|
2000-08-24 22:17:34 +08:00
|
|
|
if ( !(capabilities & GIMP_EXPORT_CAN_HANDLE_RGB) )
|
1999-10-04 02:54:54 +08:00
|
|
|
{
|
2000-08-24 22:17:34 +08:00
|
|
|
if ((capabilities & GIMP_EXPORT_CAN_HANDLE_INDEXED) && (capabilities & GIMP_EXPORT_CAN_HANDLE_GRAY))
|
1999-10-22 03:35:35 +08:00
|
|
|
actions = g_slist_prepend (actions, &export_action_convert_indexed_or_grayscale);
|
2000-08-24 22:17:34 +08:00
|
|
|
else if (capabilities & GIMP_EXPORT_CAN_HANDLE_INDEXED)
|
1999-10-22 03:35:35 +08:00
|
|
|
actions = g_slist_prepend (actions, &export_action_convert_indexed);
|
2000-08-24 22:17:34 +08:00
|
|
|
else if (capabilities & GIMP_EXPORT_CAN_HANDLE_GRAY)
|
1999-10-22 03:35:35 +08:00
|
|
|
actions = g_slist_prepend (actions, &export_action_convert_grayscale);
|
1999-10-04 02:54:54 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GIMP_GRAY:
|
2000-08-24 22:17:34 +08:00
|
|
|
if ( !(capabilities & GIMP_EXPORT_CAN_HANDLE_GRAY) )
|
1999-10-04 02:54:54 +08:00
|
|
|
{
|
2000-08-24 22:17:34 +08:00
|
|
|
if ((capabilities & GIMP_EXPORT_CAN_HANDLE_RGB) && (capabilities & GIMP_EXPORT_CAN_HANDLE_INDEXED))
|
1999-10-22 03:35:35 +08:00
|
|
|
actions = g_slist_prepend (actions, &export_action_convert_rgb_or_indexed);
|
2000-08-24 22:17:34 +08:00
|
|
|
else if (capabilities & GIMP_EXPORT_CAN_HANDLE_RGB)
|
1999-10-22 03:35:35 +08:00
|
|
|
actions = g_slist_prepend (actions, &export_action_convert_rgb);
|
2000-08-24 22:17:34 +08:00
|
|
|
else if (capabilities & GIMP_EXPORT_CAN_HANDLE_INDEXED)
|
1999-10-22 03:35:35 +08:00
|
|
|
actions = g_slist_prepend (actions, &export_action_convert_indexed);
|
1999-10-04 02:54:54 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GIMP_INDEXED:
|
2000-08-24 22:17:34 +08:00
|
|
|
if ( !(capabilities & GIMP_EXPORT_CAN_HANDLE_INDEXED) )
|
1999-10-04 02:54:54 +08:00
|
|
|
{
|
2000-08-24 22:17:34 +08:00
|
|
|
if ((capabilities & GIMP_EXPORT_CAN_HANDLE_RGB) && (capabilities & GIMP_EXPORT_CAN_HANDLE_GRAY))
|
1999-10-22 03:35:35 +08:00
|
|
|
actions = g_slist_prepend (actions, &export_action_convert_rgb_or_grayscale);
|
2000-08-24 22:17:34 +08:00
|
|
|
else if (capabilities & GIMP_EXPORT_CAN_HANDLE_RGB)
|
1999-10-22 03:35:35 +08:00
|
|
|
actions = g_slist_prepend (actions, &export_action_convert_rgb);
|
2000-08-24 22:17:34 +08:00
|
|
|
else if (capabilities & GIMP_EXPORT_CAN_HANDLE_GRAY)
|
1999-10-22 03:35:35 +08:00
|
|
|
actions = g_slist_prepend (actions, &export_action_convert_grayscale);
|
1999-10-04 02:54:54 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (actions)
|
1999-10-22 03:35:35 +08:00
|
|
|
{
|
|
|
|
actions = g_slist_reverse (actions);
|
2000-02-05 02:55:32 +08:00
|
|
|
dialog_return = export_dialog (actions, format_name);
|
1999-10-22 03:35:35 +08:00
|
|
|
}
|
1999-10-04 14:36:38 +08:00
|
|
|
else
|
2000-08-24 22:17:34 +08:00
|
|
|
dialog_return = GIMP_EXPORT_IGNORE;
|
1999-10-04 02:54:54 +08:00
|
|
|
|
2000-08-24 22:17:34 +08:00
|
|
|
if (dialog_return == GIMP_EXPORT_EXPORT)
|
1999-10-04 02:54:54 +08:00
|
|
|
{
|
2000-02-05 02:55:32 +08:00
|
|
|
*image_ID = gimp_image_duplicate (*image_ID);
|
|
|
|
*drawable_ID = gimp_image_get_active_layer (*image_ID);
|
|
|
|
gimp_image_undo_disable (*image_ID);
|
1999-10-04 02:54:54 +08:00
|
|
|
for (list = actions; list; list = list->next)
|
1999-10-22 03:35:35 +08:00
|
|
|
{
|
1999-10-04 02:54:54 +08:00
|
|
|
action = (ExportAction*)(list->data);
|
|
|
|
if (action->choice == 0 && action->default_action)
|
2000-02-05 02:55:32 +08:00
|
|
|
action->default_action (*image_ID, drawable_ID);
|
1999-10-04 02:54:54 +08:00
|
|
|
else if (action->choice == 1 && action->alt_action)
|
2000-02-05 02:55:32 +08:00
|
|
|
action->alt_action (*image_ID, drawable_ID);
|
1999-10-04 02:54:54 +08:00
|
|
|
}
|
|
|
|
}
|
1999-10-24 21:26:30 +08:00
|
|
|
g_slist_free (actions);
|
1999-10-04 02:54:54 +08:00
|
|
|
|
2000-01-11 23:48:00 +08:00
|
|
|
return dialog_return;
|
1999-10-04 02:54:54 +08:00
|
|
|
}
|