Commit 5cccad98 authored by Michael Natterer's avatar Michael Natterer 😴

plug-ins: move around and clean up some code in file-webp

as preparation for GimpProcedureConfig porting.
parent 80e2e0a5
...@@ -363,33 +363,33 @@ save_dialog (WebPSaveParams *params, ...@@ -363,33 +363,33 @@ save_dialog (WebPSaveParams *params,
/* Save EXIF data */ /* Save EXIF data */
toggle = gtk_check_button_new_with_mnemonic (_("_Save Exif data")); toggle = gtk_check_button_new_with_mnemonic (_("_Save Exif data"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), params->exif); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), params->save_exif);
gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
gtk_widget_show (toggle); gtk_widget_show (toggle);
g_signal_connect (toggle, "toggled", g_signal_connect (toggle, "toggled",
G_CALLBACK (gimp_toggle_button_update), G_CALLBACK (gimp_toggle_button_update),
&params->exif); &params->save_exif);
/* XMP metadata */ /* XMP metadata */
toggle = gtk_check_button_new_with_mnemonic (_("Save _XMP data")); toggle = gtk_check_button_new_with_mnemonic (_("Save _XMP data"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), params->xmp); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), params->save_xmp);
gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
gtk_widget_show (toggle); gtk_widget_show (toggle);
g_signal_connect (toggle, "toggled", g_signal_connect (toggle, "toggled",
G_CALLBACK (gimp_toggle_button_update), G_CALLBACK (gimp_toggle_button_update),
&params->xmp); &params->save_xmp);
/* Color profile */ /* Color profile */
toggle = gtk_check_button_new_with_mnemonic (_("Save color _profile")); toggle = gtk_check_button_new_with_mnemonic (_("Save color _profile"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), params->profile); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), params->save_profile);
gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
gtk_widget_show (toggle); gtk_widget_show (toggle);
g_signal_connect (toggle, "toggled", g_signal_connect (toggle, "toggled",
G_CALLBACK (gimp_toggle_button_update), G_CALLBACK (gimp_toggle_button_update),
&params->profile); &params->save_profile);
gtk_widget_show (dialog); gtk_widget_show (dialog);
......
...@@ -52,21 +52,6 @@ int webp_file_progress (int percent, ...@@ -52,21 +52,6 @@ int webp_file_progress (int percent,
const WebPPicture *picture); const WebPPicture *picture);
const gchar * webp_error_string (WebPEncodingError error_code); const gchar * webp_error_string (WebPEncodingError error_code);
gboolean save_layer (GFile *file,
gint32 nLayers,
GimpImage *image,
GimpDrawable *drawable,
WebPSaveParams *params,
GError **error);
gboolean save_animation (GFile *file,
gint32 nLayers,
GList *layers,
GimpImage *image,
GimpDrawable *drawable,
WebPSaveParams *params,
GError **error);
static void webp_decide_output (GimpImage *image, static void webp_decide_output (GimpImage *image,
WebPSaveParams *params, WebPSaveParams *params,
GimpColorProfile **profile, GimpColorProfile **profile,
...@@ -141,17 +126,16 @@ webp_error_string (WebPEncodingError error_code) ...@@ -141,17 +126,16 @@ webp_error_string (WebPEncodingError error_code)
gboolean gboolean
save_layer (GFile *file, save_layer (GFile *file,
gint32 nLayers,
GimpImage *image, GimpImage *image,
GimpDrawable *drawable, GimpDrawable *drawable,
WebPSaveParams *params, WebPSaveParams *params,
GError **error) GError **error)
{ {
gboolean status = FALSE; gboolean status = FALSE;
FILE *outfile = NULL; FILE *outfile = NULL;
WebPConfig config = {0}; WebPConfig webp_config = { 0, };
WebPPicture picture = {0}; WebPPicture picture = { 0, };
guchar *buffer = NULL; guchar *buffer = NULL;
gint w, h; gint w, h;
gboolean has_alpha; gboolean has_alpha;
const gchar *encoding; const gchar *encoding;
...@@ -245,11 +229,11 @@ save_layer (GFile *file, ...@@ -245,11 +229,11 @@ save_layer (GFile *file,
/* Initialize the WebP configuration with a preset and fill in the /* Initialize the WebP configuration with a preset and fill in the
* remaining values */ * remaining values */
WebPConfigPreset (&config, params->preset, params->quality); WebPConfigPreset (&webp_config, params->preset, params->quality);
config.lossless = params->lossless; webp_config.lossless = params->lossless;
config.method = 6; /* better quality */ webp_config.method = 6; /* better quality */
config.alpha_quality = params->alpha_quality; webp_config.alpha_quality = params->alpha_quality;
/* Prepare the WebP structure */ /* Prepare the WebP structure */
WebPPictureInit (&picture); WebPPictureInit (&picture);
...@@ -288,7 +272,7 @@ save_layer (GFile *file, ...@@ -288,7 +272,7 @@ save_layer (GFile *file,
} }
/* Perform the actual encode */ /* Perform the actual encode */
if (! WebPEncode (&config, &picture)) if (! WebPEncode (&webp_config, &picture))
{ {
g_printerr ("WebP error: '%s'", g_printerr ("WebP error: '%s'",
webp_error_string (picture.error_code)); webp_error_string (picture.error_code));
...@@ -451,7 +435,7 @@ parse_combine (const char* str) ...@@ -451,7 +435,7 @@ parse_combine (const char* str)
return FALSE; return FALSE;
} }
static gint static gboolean
get_layer_needs_combine (GimpLayer *layer) get_layer_needs_combine (GimpLayer *layer)
{ {
gchar *layer_name; gchar *layer_name;
...@@ -464,7 +448,7 @@ get_layer_needs_combine (GimpLayer *layer) ...@@ -464,7 +448,7 @@ get_layer_needs_combine (GimpLayer *layer)
return needs_combine; return needs_combine;
} }
static GeglBuffer* static GeglBuffer *
combine_buffers (GeglBuffer *layer_buffer, combine_buffers (GeglBuffer *layer_buffer,
GeglBuffer *prev_frame_buffer) GeglBuffer *prev_frame_buffer)
{ {
...@@ -506,13 +490,13 @@ combine_buffers (GeglBuffer *layer_buffer, ...@@ -506,13 +490,13 @@ combine_buffers (GeglBuffer *layer_buffer,
gboolean gboolean
save_animation (GFile *file, save_animation (GFile *file,
gint32 nLayers,
GList *layers,
GimpImage *image, GimpImage *image,
GimpDrawable *drawable, GimpDrawable *drawable,
WebPSaveParams *params, WebPSaveParams *params,
GError **error) GError **error)
{ {
GList *layers;
gint32 n_layers;
gboolean status = TRUE; gboolean status = TRUE;
FILE *outfile = NULL; FILE *outfile = NULL;
guchar *buffer = NULL; guchar *buffer = NULL;
...@@ -527,13 +511,18 @@ save_animation (GFile *file, ...@@ -527,13 +511,18 @@ save_animation (GFile *file,
WebPAnimEncoderOptions enc_options; WebPAnimEncoderOptions enc_options;
WebPData webp_data; WebPData webp_data;
int frame_timestamp = 0; int frame_timestamp = 0;
WebPAnimEncoder *enc = NULL; WebPAnimEncoder *enc = NULL;
GeglBuffer *prev_frame = NULL; GeglBuffer *prev_frame = NULL;
gboolean out_linear = FALSE; gboolean out_linear = FALSE;
if (nLayers < 1) layers = gimp_image_list_layers (image);
if (! layers)
return FALSE; return FALSE;
layers = g_list_reverse (layers);
n_layers = g_list_length (layers);
webp_decide_output (image, params, &profile, &out_linear); webp_decide_output (image, params, &profile, &out_linear);
if (profile) if (profile)
{ {
...@@ -550,6 +539,7 @@ save_animation (GFile *file, ...@@ -550,6 +539,7 @@ save_animation (GFile *file,
} }
} }
if (! space) if (! space)
space = gimp_drawable_get_format (drawable); space = gimp_drawable_get_format (drawable);
...@@ -612,7 +602,7 @@ save_animation (GFile *file, ...@@ -612,7 +602,7 @@ save_animation (GFile *file,
GeglBuffer *geglbuffer; GeglBuffer *geglbuffer;
GeglBuffer *current_frame; GeglBuffer *current_frame;
GeglRectangle extent; GeglRectangle extent;
WebPConfig config; WebPConfig webp_config;
WebPPicture picture; WebPPicture picture;
WebPMemoryWriter mw = { 0 }; WebPMemoryWriter mw = { 0 };
GimpDrawable *drawable = list->data; GimpDrawable *drawable = list->data;
...@@ -680,12 +670,12 @@ save_animation (GFile *file, ...@@ -680,12 +670,12 @@ save_animation (GFile *file,
} }
} }
WebPConfigPreset (&config, params->preset, params->quality); WebPConfigPreset (&webp_config, params->preset, params->quality);
config.lossless = params->lossless; webp_config.lossless = params->lossless;
config.method = 6; /* better quality */ webp_config.method = 6; /* better quality */
config.alpha_quality = params->alpha_quality; webp_config.alpha_quality = params->alpha_quality;
config.exact = 1; webp_config.exact = 1;
WebPMemoryWriterInit (&mw); WebPMemoryWriterInit (&mw);
...@@ -733,7 +723,8 @@ save_animation (GFile *file, ...@@ -733,7 +723,8 @@ save_animation (GFile *file,
G_STRFUNC); G_STRFUNC);
} }
/* Perform the actual encode */ /* Perform the actual encode */
else if (! WebPAnimEncoderAdd (enc, &picture, frame_timestamp, &config)) else if (! WebPAnimEncoderAdd (enc, &picture, frame_timestamp,
&webp_config))
{ {
g_printerr ("ERROR[%d]: %s\n", g_printerr ("ERROR[%d]: %s\n",
picture.error_code, picture.error_code,
...@@ -747,7 +738,7 @@ save_animation (GFile *file, ...@@ -747,7 +738,7 @@ save_animation (GFile *file,
if (status == FALSE) if (status == FALSE)
break; break;
gimp_progress_update ((loop + 1.0) / nLayers); gimp_progress_update ((loop + 1.0) / n_layers);
frame_timestamp += (delay <= 0 || force_delay) ? default_delay : delay; frame_timestamp += (delay <= 0 || force_delay) ? default_delay : delay;
} }
g_free (buffer); g_free (buffer);
...@@ -813,80 +804,8 @@ save_animation (GFile *file, ...@@ -813,80 +804,8 @@ save_animation (GFile *file,
if (outfile) if (outfile)
fclose (outfile); fclose (outfile);
return status;
}
gboolean
save_image (GFile *file,
GimpImage *image,
GimpDrawable *drawable,
GimpMetadata *metadata,
GimpMetadataSaveFlags metadata_flags,
WebPSaveParams *params,
GError **error)
{
gboolean status = FALSE;
GList *layers;
layers = gimp_image_list_layers (image);
layers = g_list_reverse (layers);
if (! layers)
return FALSE;
g_printerr ("Saving WebP file %s\n", gimp_file_get_utf8_name (file));
if (params->animation)
{
status = save_animation (file,
g_list_length (layers), layers,
image, drawable, params,
error);
}
else
{
status = save_layer (file,
g_list_length (layers),
image, drawable, params, error);
}
g_list_free (layers); g_list_free (layers);
if (metadata)
{
gimp_metadata_set_bits_per_sample (metadata, 8);
if (params->exif)
metadata_flags |= GIMP_METADATA_SAVE_EXIF;
else
metadata_flags &= ~GIMP_METADATA_SAVE_EXIF;
/* WebP doesn't support iptc natively and
sets it via xmp */
if (params->xmp)
{
metadata_flags |= GIMP_METADATA_SAVE_XMP;
metadata_flags |= GIMP_METADATA_SAVE_IPTC;
}
else
{
metadata_flags &= ~GIMP_METADATA_SAVE_XMP;
metadata_flags &= ~GIMP_METADATA_SAVE_IPTC;
}
if (params->profile)
metadata_flags |= GIMP_METADATA_SAVE_COLOR_PROFILE;
else
metadata_flags &= ~GIMP_METADATA_SAVE_COLOR_PROFILE;
gimp_image_metadata_save_finish (image,
"image/webp",
metadata, metadata_flags,
file, NULL);
}
/* Return the status */
return status; return status;
} }
...@@ -899,7 +818,8 @@ webp_decide_output (GimpImage *image, ...@@ -899,7 +818,8 @@ webp_decide_output (GimpImage *image,
g_return_if_fail (profile && *profile == NULL); g_return_if_fail (profile && *profile == NULL);
*out_linear = FALSE; *out_linear = FALSE;
if (params->profile)
if (params->save_profile)
{ {
*profile = gimp_image_get_color_profile (image); *profile = gimp_image_get_color_profile (image);
......
...@@ -33,22 +33,26 @@ typedef struct ...@@ -33,22 +33,26 @@ typedef struct
gint kf_distance; gint kf_distance;
gfloat quality; gfloat quality;
gfloat alpha_quality; gfloat alpha_quality;
gboolean exif; gboolean save_exif;
gboolean iptc; gboolean save_iptc;
gboolean xmp; gboolean save_xmp;
gboolean profile; gboolean save_profile;
gint delay; gint delay;
gboolean force_delay; gboolean force_delay;
} WebPSaveParams; } WebPSaveParams;
gboolean save_image (GFile *file, gboolean save_layer (GFile *file,
GimpImage *image, GimpImage *image,
GimpDrawable *drawable, GimpDrawable *drawable,
GimpMetadata *metadata, WebPSaveParams *params,
GimpMetadataSaveFlags metadata_flags, GError **error);
WebPSaveParams *params,
GError **error); gboolean save_animation (GFile *file,
GimpImage *image,
GimpDrawable *drawable,
WebPSaveParams *params,
GError **error);
#endif /* __WEBP_SAVE_H__ */ #endif /* __WEBP_SAVE_H__ */
...@@ -208,22 +208,22 @@ webp_create_procedure (GimpPlugIn *plug_in, ...@@ -208,22 +208,22 @@ webp_create_procedure (GimpPlugIn *plug_in,
0, G_MAXINT, 50, 0, G_MAXINT, 50,
G_PARAM_READWRITE); G_PARAM_READWRITE);
GIMP_PROC_ARG_BOOLEAN (procedure, "exif", GIMP_PROC_ARG_BOOLEAN (procedure, "save-exif",
"EXIF", "Save Exif",
"Toggle saving exif data", "Toggle saving Exif data",
FALSE, gimp_export_exif (),
G_PARAM_READWRITE); G_PARAM_READWRITE);
GIMP_PROC_ARG_BOOLEAN (procedure, "iptc", GIMP_PROC_ARG_BOOLEAN (procedure, "save-iptc",
"IPTC", "Save IPTC",
"Toggle saving iptc data", "Toggle saving IPTC data",
FALSE, gimp_export_iptc (),
G_PARAM_READWRITE); G_PARAM_READWRITE);
GIMP_PROC_ARG_BOOLEAN (procedure, "xmp", GIMP_PROC_ARG_BOOLEAN (procedure, "save-xmp",
"XMP", "Save XMP",
"Toggle saving xmp data", "Toggle saving XMP data",
FALSE, gimp_export_xmp (),
G_PARAM_READWRITE); G_PARAM_READWRITE);
GIMP_PROC_ARG_INT (procedure, "delay", GIMP_PROC_ARG_INT (procedure, "delay",
...@@ -304,9 +304,9 @@ webp_save (GimpProcedure *procedure, ...@@ -304,9 +304,9 @@ webp_save (GimpProcedure *procedure,
params.kf_distance = 50; params.kf_distance = 50;
params.quality = 90.0f; params.quality = 90.0f;
params.alpha_quality = 100.0f; params.alpha_quality = 100.0f;
params.exif = FALSE; params.save_exif = FALSE;
params.iptc = FALSE; params.save_iptc = FALSE;
params.xmp = FALSE; params.save_xmp = FALSE;
params.delay = 200; params.delay = 200;
params.force_delay = FALSE; params.force_delay = FALSE;
...@@ -314,10 +314,10 @@ webp_save (GimpProcedure *procedure, ...@@ -314,10 +314,10 @@ webp_save (GimpProcedure *procedure,
metadata = gimp_image_metadata_save_prepare (image, metadata = gimp_image_metadata_save_prepare (image,
"image/webp", "image/webp",
&metadata_flags); &metadata_flags);
params.exif = (metadata_flags & GIMP_METADATA_SAVE_EXIF) != 0; params.save_exif = (metadata_flags & GIMP_METADATA_SAVE_EXIF) != 0;
params.xmp = (metadata_flags & GIMP_METADATA_SAVE_XMP) != 0; params.save_xmp = (metadata_flags & GIMP_METADATA_SAVE_XMP) != 0;
params.iptc = (metadata_flags & GIMP_METADATA_SAVE_IPTC) != 0; params.save_iptc = (metadata_flags & GIMP_METADATA_SAVE_IPTC) != 0;
params.profile = (metadata_flags & GIMP_METADATA_SAVE_COLOR_PROFILE) != 0; params.save_profile = (metadata_flags & GIMP_METADATA_SAVE_COLOR_PROFILE) != 0;
switch (run_mode) switch (run_mode)
{ {
...@@ -345,9 +345,9 @@ webp_save (GimpProcedure *procedure, ...@@ -345,9 +345,9 @@ webp_save (GimpProcedure *procedure,
params.loop = GIMP_VALUES_GET_BOOLEAN (args, 5); params.loop = GIMP_VALUES_GET_BOOLEAN (args, 5);
params.minimize_size = GIMP_VALUES_GET_BOOLEAN (args, 6); params.minimize_size = GIMP_VALUES_GET_BOOLEAN (args, 6);
params.kf_distance = GIMP_VALUES_GET_INT (args, 7); params.kf_distance = GIMP_VALUES_GET_INT (args, 7);
params.exif = GIMP_VALUES_GET_BOOLEAN (args, 8); params.save_exif = GIMP_VALUES_GET_BOOLEAN (args, 8);
params.iptc = GIMP_VALUES_GET_BOOLEAN (args, 9); params.save_iptc = GIMP_VALUES_GET_BOOLEAN (args, 9);
params.xmp = GIMP_VALUES_GET_BOOLEAN (args, 10); params.save_xmp = GIMP_VALUES_GET_BOOLEAN (args, 10);
params.delay = GIMP_VALUES_GET_INT (args, 11); params.delay = GIMP_VALUES_GET_INT (args, 11);
params.force_delay = GIMP_VALUES_GET_BOOLEAN (args, 12); params.force_delay = GIMP_VALUES_GET_BOOLEAN (args, 12);
break; break;
...@@ -376,12 +376,54 @@ webp_save (GimpProcedure *procedure, ...@@ -376,12 +376,54 @@ webp_save (GimpProcedure *procedure,
NULL); NULL);
} }
if (! save_image (file, image, drawable, if (params.animation)
metadata, metadata_flags, {
&params, if (! save_animation (file, image, drawable, &params,
&error)) &error))
{
status = GIMP_PDB_EXECUTION_ERROR;
}
}
else
{
if (! save_layer (file, image, drawable, &params,
&error))
{
status = GIMP_PDB_EXECUTION_ERROR;
}
}
if (status == GIMP_PDB_SUCCESS && metadata)
{ {
status = GIMP_PDB_EXECUTION_ERROR; gimp_metadata_set_bits_per_sample (metadata, 8);
if (params.save_exif)
metadata_flags |= GIMP_METADATA_SAVE_EXIF;
else
metadata_flags &= ~GIMP_METADATA_SAVE_EXIF;
/* WebP doesn't support iptc natively and sets it via xmp
*/
if (params.save_xmp)
{
metadata_flags |= GIMP_METADATA_SAVE_XMP;
metadata_flags |= GIMP_METADATA_SAVE_IPTC;
}
else
{
metadata_flags &= ~GIMP_METADATA_SAVE_XMP;
metadata_flags &= ~GIMP_METADATA_SAVE_IPTC;
}
if (params.save_profile)
metadata_flags |= GIMP_METADATA_SAVE_COLOR_PROFILE;
else
metadata_flags &= ~GIMP_METADATA_SAVE_COLOR_PROFILE;
gimp_image_metadata_save_finish (image,
"image/webp",
metadata, metadata_flags,
file, NULL);
} }
if (export == GIMP_EXPORT_EXPORT) if (export == GIMP_EXPORT_EXPORT)
......
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