Commit 9ce63151 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

merged Raphaels patch for bug #51114 from the stable branch.

2001-10-24  Sven Neumann  <sven@gimp.org>

	* libgimp/gimpexport.c: merged Raphaels patch for bug #51114 from the
	stable branch.

	* plug-ins/common/grid.c: merged the fix for indexed images from the
	stable branch.
parent f531d3af
2001-10-24 Sven Neumann <sven@gimp.org>
* libgimp/gimpexport.c: merged Raphaels patch for bug #51114 from the
stable branch.
* plug-ins/common/grid.c: merged the fix for indexed images from the
stable branch.
2001-10-24 Michael Natterer <mitch@gimp.org>
* app/file-open.c
......
......@@ -55,21 +55,31 @@ export_merge (gint32 image_ID,
gint32 nvisible = 0;
gint32 i;
gint32 *layers;
gint32 visible = *drawable_ID;
gint32 merged;
gint32 transp;
layers = gimp_image_get_layers (image_ID, &nlayers);
for (i = 0; i < nlayers; i++)
{
if (gimp_drawable_visible (layers[i]))
{
nvisible++;
visible = layers[i];
}
}
if (nvisible == 1 && *drawable_ID != visible)
*drawable_ID = visible;
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++;
}
if (nvisible > 1)
{
......@@ -162,6 +172,15 @@ static ExportAction export_action_merge =
0
};
static ExportAction export_action_merge_single =
{
export_merge,
NULL,
N_("can't handle layer offsets, size or opacity"),
{ N_("Merge Visible Layers"), NULL },
0
};
static ExportAction export_action_animate_or_merge =
{
export_merge,
......@@ -279,6 +298,14 @@ export_export_callback (GtkWidget *widget,
dialog_return = GIMP_EXPORT_EXPORT;
}
static void
export_confirm_callback (GtkWidget *widget,
gpointer data)
{
gtk_widget_destroy (dialog);
dialog_return = GIMP_EXPORT_EXPORT;
}
static void
export_skip_callback (GtkWidget *widget,
gpointer data)
......@@ -308,9 +335,62 @@ export_toggle_callback (GtkWidget *widget,
*choice = 1;
}
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;
}
static gint
export_dialog (GSList *actions,
const gchar *format)
const gchar *format_name)
{
GtkWidget *frame;
GtkWidget *vbox;
......@@ -322,14 +402,15 @@ export_dialog (GSList *actions,
ExportAction *action;
dialog_return = GIMP_EXPORT_CANCEL;
g_return_val_if_fail (actions != NULL && format != NULL, dialog_return);
g_return_val_if_fail (actions != NULL && format_name != NULL, dialog_return);
/*
* Plug-ins have called gtk_init () before calling gimp_export ().
* Plug-ins must have called gtk_init () before calling gimp_export ().
* Otherwise bad things will happen now!!
*/
/* the dialog */
dialog = gimp_dialog_new (_("Export File"), "export_file",
gimp_standard_help_func, "dialogs/export_file.html",
GTK_WIN_POS_MOUSE,
......@@ -365,7 +446,7 @@ export_dialog (GSList *actions,
{
action = (ExportAction *) (list->data);
text = g_strdup_printf ("%s %s", format, gettext (action->reason));
text = g_strdup_printf ("%s %s", format_name, gettext (action->reason));
frame = gtk_frame_new (text);
g_free (text);
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
......@@ -468,6 +549,8 @@ gimp_export_image (gint32 *image_ID,
gint32 i;
gint32 nlayers;
gint32* layers;
gint offset_x;
gint offset_y;
gboolean added_flatten = FALSE;
gboolean background_has_alpha = TRUE;
ExportAction *action;
......@@ -480,6 +563,23 @@ gimp_export_image (gint32 *image_ID,
if (capabilities & GIMP_EXPORT_CAN_HANDLE_LAYERS_AS_ANIMATION)
capabilities |= GIMP_EXPORT_CAN_HANDLE_LAYERS;
/* 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;
}
/* check alpha */
layers = gimp_image_get_layers (*image_ID, &nlayers);
for (i = 0; i < nlayers; i++)
......@@ -498,7 +598,7 @@ gimp_export_image (gint32 *image_ID,
{
/* If this is the last layer, it's visible and has no alpha
channel, then the image has a "flat" background */
if (i == nlayers - 1 && gimp_layer_get_visible(layers[i]))
if (i == nlayers - 1 && gimp_layer_get_visible (layers[i]))
background_has_alpha = FALSE;
if (capabilities & GIMP_EXPORT_NEEDS_ALPHA)
......@@ -510,8 +610,29 @@ gimp_export_image (gint32 *image_ID,
}
g_free (layers);
/* 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;
}
}
}
/* check multiple layers */
if (!added_flatten && nlayers > 1)
else if (!added_flatten && nlayers > 1)
{
if (capabilities & GIMP_EXPORT_CAN_HANDLE_LAYERS_AS_ANIMATION)
{
......
......@@ -71,8 +71,10 @@ static void doit (gint32 image_ID,
gboolean preview_mode);
static gint dialog (gint32 image_ID,
GimpDrawable *drawable);
static GtkWidget * preview_widget (GimpDrawable *drawable);
static GtkWidget * preview_widget (gint32 image_ID,
GimpDrawable *drawable);
static void fill_preview (GtkWidget *preview_widget,
gint32 image_ID,
GimpDrawable *drawable);
GimpPlugInInfo PLUG_IN_INFO =
......@@ -690,7 +692,7 @@ dialog (gint32 image_ID,
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
gtk_container_add (GTK_CONTAINER (abox), frame);
gtk_widget_show (frame);
preview = preview_widget (drawable); /* we are here */
preview = preview_widget (image_ID, drawable); /* we are here */
gtk_container_add (GTK_CONTAINER (frame), preview);
doit (image_ID, drawable, TRUE); /* render preview */
gtk_widget_show (preview);
......@@ -978,14 +980,16 @@ dialog (gint32 image_ID,
}
static GtkWidget *
preview_widget (GimpDrawable *drawable)
preview_widget (gint32 image_ID,
GimpDrawable *drawable)
{
gint size;
GtkWidget *preview;
preview = gtk_preview_new (GTK_PREVIEW_COLOR);
fill_preview (preview, drawable);
size = GTK_PREVIEW (preview)->rowstride * GTK_PREVIEW (preview)->buffer_height;
fill_preview (preview, image_ID, drawable);
size =
GTK_PREVIEW (preview)->rowstride * GTK_PREVIEW (preview)->buffer_height;
preview_bits = g_malloc (size);
memcpy (preview_bits, GTK_PREVIEW (preview)->buffer, size);
......@@ -994,6 +998,7 @@ preview_widget (GimpDrawable *drawable)
static void
fill_preview (GtkWidget *widget,
gint32 image_ID,
GimpDrawable *drawable)
{
GimpPixelRgn srcPR;
......@@ -1007,6 +1012,8 @@ fill_preview (GtkWidget *widget,
gdouble c0, c1;
guchar *p0, *p1;
guchar *even, *odd;
guchar *cmap;
gint ncolors;
gimp_drawable_mask_bounds (drawable->drawable_id, &x1, &y1, &x2, &y2);
......@@ -1031,6 +1038,11 @@ fill_preview (GtkWidget *widget,
odd = g_malloc (width * 3);
src = g_malloc (width * bpp);
if (gimp_drawable_is_indexed (drawable->drawable_id))
cmap = gimp_image_get_cmap (image_ID, &ncolors);
else
cmap = NULL;
for (y = 0; y < height; y++)
{
gimp_pixel_rgn_get_row (&srcPR, src, x1, y + y1, width);
......@@ -1053,10 +1065,22 @@ fill_preview (GtkWidget *widget,
b = ((gdouble)src[x*3+2]) / 255.0;
a = 1.0;
}
else
{
if (cmap)
{
gint index = MIN (src[x*bpp], ncolors - 1);
r = ((gdouble)cmap[index * 3 + 0]) / 255.0;
g = ((gdouble)cmap[index * 3 + 1]) / 255.0;
b = ((gdouble)cmap[index * 3 + 2]) / 255.0;
}
else
{
r = ((gdouble)src[x*bpp+0]) / 255.0;
g = b = r;
}
if (bpp == 2)
a = ((gdouble)src[x*bpp+1]) / 255.0;
else
......@@ -1093,4 +1117,7 @@ fill_preview (GtkWidget *widget,
g_free (even);
g_free (odd);
g_free (src);
if (cmap)
g_free (cmap);
}
2001-10-24 Sven Neumann <sven@gimp.org>
* POTFILES.in: added missing file (you probably already have
translations for the new messages in the po-plug-ins domain).
Fixes bug #62920.
2001-10-10 Christian Rose <menthos@menthos.com>
* sv.po: Updated Swedish translation.
......
......@@ -5,3 +5,4 @@ plug-ins/script-fu/script-fu-console.c
plug-ins/script-fu/script-fu-scripts.c
plug-ins/script-fu/script-fu-server.c
plug-ins/script-fu/script-fu.c
plug-ins/dbbrowser/dbbrowser_utils.c
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment