mirror of https://github.com/GNOME/gimp.git
plug-ins: WebP: save_dialog() before gimp_export()
As mentioned in issue #1777, exporting non-animated WebP images was only keeping the current layer. Mimick file-gif-save.c: display the encoding settings pop-up earlier so that gimp_export_image() can merge the layers unless "As Animation" is enabled. Call gimp_image_get_layers() directly in save_image() in case the layers were merged (for clarity because layers are used only for animations).
This commit is contained in:
parent
9969dd8b03
commit
8f828d1899
|
@ -81,8 +81,7 @@ show_maxkeyframe_hints (GtkAdjustment *adj,
|
|||
|
||||
gboolean
|
||||
save_dialog (WebPSaveParams *params,
|
||||
gint32 image_ID,
|
||||
gint32 n_layers)
|
||||
gint32 image_ID)
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
GtkWidget *vbox;
|
||||
|
@ -96,12 +95,14 @@ save_dialog (WebPSaveParams *params,
|
|||
GtkWidget *combo;
|
||||
GtkAdjustment *quality_scale;
|
||||
GtkAdjustment *alpha_quality_scale;
|
||||
gint32 nlayers;
|
||||
gboolean animation_supported = FALSE;
|
||||
gboolean run;
|
||||
gchar *text;
|
||||
gint row = 0;
|
||||
|
||||
animation_supported = n_layers > 1;
|
||||
g_free (gimp_image_get_layers (image_ID, &nlayers));
|
||||
animation_supported = nlayers > 1;
|
||||
|
||||
/* Create the dialog */
|
||||
dialog = gimp_export_dialog_new (_("WebP"), PLUG_IN_BINARY, SAVE_PROC);
|
||||
|
|
|
@ -27,8 +27,7 @@
|
|||
|
||||
|
||||
gboolean save_dialog (WebPSaveParams *params,
|
||||
gint32 image_ID,
|
||||
gint32 n_layers);
|
||||
gint32 image_ID);
|
||||
|
||||
|
||||
#endif /* __WEBP_DIALOG_H__ */
|
||||
|
|
|
@ -802,8 +802,6 @@ save_animation (const gchar *filename,
|
|||
|
||||
gboolean
|
||||
save_image (const gchar *filename,
|
||||
gint32 nLayers,
|
||||
gint32 *allLayers,
|
||||
gint32 image_ID,
|
||||
gint32 drawable_ID,
|
||||
GimpMetadata *metadata,
|
||||
|
@ -813,33 +811,33 @@ save_image (const gchar *filename,
|
|||
{
|
||||
GFile *file;
|
||||
gboolean status = FALSE;
|
||||
gint32 *layers;
|
||||
gint nlayers;
|
||||
|
||||
if (nLayers == 0)
|
||||
return FALSE;
|
||||
layers = gimp_image_get_layers (image_ID, &nlayers);
|
||||
|
||||
if (nlayers == 0)
|
||||
{
|
||||
g_free (layers);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
g_printerr ("Saving WebP file %s\n", filename);
|
||||
|
||||
if (nLayers == 1)
|
||||
if (params->animation)
|
||||
{
|
||||
status = save_layer (filename, nLayers, image_ID, drawable_ID, params,
|
||||
error);
|
||||
status = save_animation (filename,
|
||||
nlayers, layers, image_ID, drawable_ID, params,
|
||||
error);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (! params->animation)
|
||||
{
|
||||
status = save_layer (filename,
|
||||
nLayers, image_ID, drawable_ID, params,
|
||||
error);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = save_animation (filename,
|
||||
nLayers, allLayers, image_ID, drawable_ID,
|
||||
params, error);
|
||||
}
|
||||
status = save_layer (filename,
|
||||
nlayers, image_ID, drawable_ID, params, error);
|
||||
}
|
||||
|
||||
g_free (layers);
|
||||
|
||||
if (metadata)
|
||||
{
|
||||
gimp_metadata_set_bits_per_sample (metadata, 8);
|
||||
|
|
|
@ -43,8 +43,6 @@ typedef struct
|
|||
|
||||
|
||||
gboolean save_image (const gchar *filename,
|
||||
gint32 nLayers,
|
||||
gint32 *allLayers,
|
||||
gint32 image_ID,
|
||||
gint32 drawable_ID,
|
||||
GimpMetadata *metadata,
|
||||
|
|
|
@ -178,8 +178,6 @@ run (const gchar *name,
|
|||
GimpMetadataSaveFlags metadata_flags;
|
||||
WebPSaveParams params;
|
||||
GimpExportReturn export = GIMP_EXPORT_CANCEL;
|
||||
gint32 *layers = NULL;
|
||||
gint32 n_layers;
|
||||
|
||||
if (run_mode == GIMP_RUN_INTERACTIVE ||
|
||||
run_mode == GIMP_RUN_WITH_LAST_VALS)
|
||||
|
@ -188,50 +186,45 @@ run (const gchar *name,
|
|||
image_ID = param[1].data.d_int32;
|
||||
drawable_ID = param[2].data.d_int32;
|
||||
|
||||
/* Default settings */
|
||||
params.preset = WEBP_PRESET_DEFAULT;
|
||||
params.lossless = FALSE;
|
||||
params.animation = FALSE;
|
||||
params.loop = TRUE;
|
||||
params.minimize_size = TRUE;
|
||||
params.kf_distance = 50;
|
||||
params.quality = 90.0f;
|
||||
params.alpha_quality = 100.0f;
|
||||
params.exif = FALSE;
|
||||
params.iptc = FALSE;
|
||||
params.xmp = FALSE;
|
||||
params.delay = 200;
|
||||
params.force_delay = FALSE;
|
||||
|
||||
/* Override the defaults with preferences. */
|
||||
metadata = gimp_image_metadata_save_prepare (image_ID,
|
||||
"image/webp",
|
||||
&metadata_flags);
|
||||
params.exif = (metadata_flags & GIMP_METADATA_SAVE_EXIF) != 0;
|
||||
params.xmp = (metadata_flags & GIMP_METADATA_SAVE_XMP) != 0;
|
||||
params.iptc = (metadata_flags & GIMP_METADATA_SAVE_IPTC) != 0;
|
||||
params.profile = (metadata_flags & GIMP_METADATA_SAVE_COLOR_PROFILE) != 0;
|
||||
|
||||
switch (run_mode)
|
||||
{
|
||||
case GIMP_RUN_WITH_LAST_VALS:
|
||||
/* Possibly override with session data */
|
||||
gimp_get_data (SAVE_PROC, ¶ms);
|
||||
break;
|
||||
|
||||
case GIMP_RUN_INTERACTIVE:
|
||||
/* Default settings */
|
||||
params.preset = WEBP_PRESET_DEFAULT;
|
||||
params.lossless = FALSE;
|
||||
params.animation = FALSE;
|
||||
params.loop = TRUE;
|
||||
params.minimize_size = TRUE;
|
||||
params.kf_distance = 50;
|
||||
params.quality = 90.0f;
|
||||
params.alpha_quality = 100.0f;
|
||||
params.exif = FALSE;
|
||||
params.iptc = FALSE;
|
||||
params.xmp = FALSE;
|
||||
params.delay = 200;
|
||||
params.force_delay = FALSE;
|
||||
|
||||
/* Override the defaults with preferences. */
|
||||
metadata = gimp_image_metadata_save_prepare (image_ID,
|
||||
"image/webp",
|
||||
&metadata_flags);
|
||||
params.exif = (metadata_flags & GIMP_METADATA_SAVE_EXIF) != 0;
|
||||
params.xmp = (metadata_flags & GIMP_METADATA_SAVE_XMP) != 0;
|
||||
params.iptc = (metadata_flags & GIMP_METADATA_SAVE_IPTC) != 0;
|
||||
params.profile = (metadata_flags & GIMP_METADATA_SAVE_COLOR_PROFILE) != 0;
|
||||
|
||||
/* Possibly override with session data */
|
||||
gimp_get_data (SAVE_PROC, ¶ms);
|
||||
|
||||
export = gimp_export_image (&image_ID, &drawable_ID, "WebP",
|
||||
GIMP_EXPORT_CAN_HANDLE_RGB |
|
||||
GIMP_EXPORT_CAN_HANDLE_GRAY |
|
||||
GIMP_EXPORT_CAN_HANDLE_INDEXED |
|
||||
GIMP_EXPORT_CAN_HANDLE_ALPHA |
|
||||
GIMP_EXPORT_CAN_HANDLE_LAYERS_AS_ANIMATION);
|
||||
|
||||
if (export == GIMP_EXPORT_CANCEL)
|
||||
if (! save_dialog (¶ms, image_ID))
|
||||
{
|
||||
values[0].data.d_status = GIMP_PDB_CANCEL;
|
||||
status = GIMP_PDB_CANCEL;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case GIMP_RUN_NONINTERACTIVE:
|
||||
|
@ -266,24 +259,31 @@ run (const gchar *name,
|
|||
break;
|
||||
}
|
||||
|
||||
|
||||
if (status == GIMP_PDB_SUCCESS)
|
||||
if (status == GIMP_PDB_SUCCESS && (run_mode == GIMP_RUN_INTERACTIVE ||
|
||||
run_mode == GIMP_RUN_WITH_LAST_VALS))
|
||||
{
|
||||
layers = gimp_image_get_layers (image_ID, &n_layers);
|
||||
GimpExportCapabilities capabilities =
|
||||
GIMP_EXPORT_CAN_HANDLE_RGB |
|
||||
GIMP_EXPORT_CAN_HANDLE_GRAY |
|
||||
GIMP_EXPORT_CAN_HANDLE_INDEXED |
|
||||
GIMP_EXPORT_CAN_HANDLE_ALPHA;
|
||||
|
||||
if (run_mode == GIMP_RUN_INTERACTIVE)
|
||||
if (params.animation)
|
||||
capabilities |= GIMP_EXPORT_CAN_HANDLE_LAYERS_AS_ANIMATION;
|
||||
|
||||
export = gimp_export_image (&image_ID, &drawable_ID, "WebP",
|
||||
capabilities);
|
||||
|
||||
if (export == GIMP_EXPORT_CANCEL)
|
||||
{
|
||||
if (! save_dialog (¶ms, image_ID, n_layers))
|
||||
{
|
||||
status = GIMP_PDB_CANCEL;
|
||||
}
|
||||
values[0].data.d_status = GIMP_PDB_CANCEL;
|
||||
status = GIMP_PDB_CANCEL;
|
||||
}
|
||||
}
|
||||
|
||||
if (status == GIMP_PDB_SUCCESS)
|
||||
{
|
||||
if (! save_image (param[3].data.d_string,
|
||||
n_layers, layers,
|
||||
image_ID,
|
||||
drawable_ID,
|
||||
metadata, metadata_flags,
|
||||
|
@ -295,8 +295,6 @@ run (const gchar *name,
|
|||
}
|
||||
|
||||
|
||||
g_free (layers);
|
||||
|
||||
if (export == GIMP_EXPORT_EXPORT)
|
||||
gimp_image_delete (image_ID);
|
||||
|
||||
|
|
Loading…
Reference in New Issue