Commit efb6ea9c authored by Michael Natterer's avatar Michael Natterer 😴

plug-ins: port file-fli to GimpProcedureConfig

While testing noticed that the plug-in either loads or saves total
garbage, but also in 2.10, so it's not a recent regression.
parent 886d0cae
Pipeline #120652 passed with stages
in 24 minutes and 29 seconds
...@@ -111,17 +111,19 @@ static GimpValueArray * fli_info (GimpProcedure *procedure, ...@@ -111,17 +111,19 @@ static GimpValueArray * fli_info (GimpProcedure *procedure,
gpointer run_data); gpointer run_data);
static GimpImage * load_image (GFile *file, static GimpImage * load_image (GFile *file,
gint32 from_frame, GObject *config,
gint32 to_frame,
GError **error); GError **error);
static gboolean load_dialog (GFile *file); static gboolean load_dialog (GFile *file,
GimpProcedure *procedure,
GObject *config);
static gboolean save_image (GFile *file, static gboolean save_image (GFile *file,
GimpImage *image, GimpImage *image,
gint32 from_frame, GObject *config,
gint32 to_frame,
GError **error); GError **error);
static gboolean save_dialog (GimpImage *image); static gboolean save_dialog (GimpImage *image,
GimpProcedure *procedure,
GObject *config);
static gboolean get_info (GFile *file, static gboolean get_info (GFile *file,
gint32 *width, gint32 *width,
...@@ -135,10 +137,6 @@ G_DEFINE_TYPE (Fli, fli, GIMP_TYPE_PLUG_IN) ...@@ -135,10 +137,6 @@ G_DEFINE_TYPE (Fli, fli, GIMP_TYPE_PLUG_IN)
GIMP_MAIN (FLI_TYPE) GIMP_MAIN (FLI_TYPE)
static gint32 from_frame;
static gint32 to_frame;
static void static void
fli_class_init (FliClass *klass) fli_class_init (FliClass *klass)
{ {
...@@ -259,11 +257,10 @@ fli_create_procedure (GimpPlugIn *plug_in, ...@@ -259,11 +257,10 @@ fli_create_procedure (GimpPlugIn *plug_in,
"Jens Ch. Restemeier", "Jens Ch. Restemeier",
"1997"); "1997");
GIMP_PROC_ARG_STRING (procedure, "uri", GIMP_PROC_ARG_FILE (procedure, "file",
"URI", "File",
"The local file:// URI of the file to get info", "The local file to get info about",
NULL, G_PARAM_READWRITE);
G_PARAM_READWRITE);
GIMP_PROC_VAL_INT (procedure, "width", GIMP_PROC_VAL_INT (procedure, "width",
"Width", "Width",
...@@ -294,35 +291,26 @@ fli_load (GimpProcedure *procedure, ...@@ -294,35 +291,26 @@ fli_load (GimpProcedure *procedure,
const GimpValueArray *args, const GimpValueArray *args,
gpointer run_data) gpointer run_data)
{ {
GimpValueArray *return_vals; GimpProcedureConfig *config;
GimpImage *image; GimpValueArray *return_vals;
GError *error = NULL; GimpImage *image;
GError *error = NULL;
INIT_I18N (); INIT_I18N ();
gegl_init (NULL, NULL); gegl_init (NULL, NULL);
switch (run_mode) config = gimp_procedure_create_config (procedure);
{ gimp_procedure_config_begin_run (config, NULL, run_mode, args);
case GIMP_RUN_NONINTERACTIVE:
from_frame = GIMP_VALUES_GET_INT (args, 0);
to_frame = GIMP_VALUES_GET_INT (args, 1);
break;
case GIMP_RUN_INTERACTIVE: if (run_mode == GIMP_RUN_INTERACTIVE)
if (! load_dialog (file)) {
if (! load_dialog (file, procedure, G_OBJECT (config)))
return gimp_procedure_new_return_values (procedure, return gimp_procedure_new_return_values (procedure,
GIMP_PDB_CANCEL, GIMP_PDB_CANCEL,
NULL); NULL);
break;
case GIMP_RUN_WITH_LAST_VALS:
return gimp_procedure_new_return_values (procedure,
GIMP_PDB_CALLING_ERROR,
error);
break;
} }
image = load_image (file, from_frame, to_frame, image = load_image (file, G_OBJECT (config),
&error); &error);
if (! image) if (! image)
...@@ -330,6 +318,9 @@ fli_load (GimpProcedure *procedure, ...@@ -330,6 +318,9 @@ fli_load (GimpProcedure *procedure,
GIMP_PDB_EXECUTION_ERROR, GIMP_PDB_EXECUTION_ERROR,
error); error);
gimp_procedure_config_end_run (config, GIMP_PDB_SUCCESS);
g_object_unref (config);
return_vals = gimp_procedure_new_return_values (procedure, return_vals = gimp_procedure_new_return_values (procedure,
GIMP_PDB_SUCCESS, GIMP_PDB_SUCCESS,
NULL); NULL);
...@@ -348,25 +339,19 @@ fli_save (GimpProcedure *procedure, ...@@ -348,25 +339,19 @@ fli_save (GimpProcedure *procedure,
const GimpValueArray *args, const GimpValueArray *args,
gpointer run_data) gpointer run_data)
{ {
GimpPDBStatusType status = GIMP_PDB_SUCCESS; GimpProcedureConfig *config;
GimpExportReturn export = GIMP_EXPORT_CANCEL; GimpPDBStatusType status = GIMP_PDB_SUCCESS;
GError *error = NULL; GimpExportReturn export = GIMP_EXPORT_CANCEL;
GError *error = NULL;
INIT_I18N (); INIT_I18N ();
gegl_init (NULL, NULL); gegl_init (NULL, NULL);
config = gimp_procedure_create_config (procedure);
gimp_procedure_config_begin_run (config, image, run_mode, args);
switch (run_mode) switch (run_mode)
{ {
case GIMP_RUN_NONINTERACTIVE:
from_frame = GIMP_VALUES_GET_INT (args, 0);
to_frame = GIMP_VALUES_GET_INT (args, 1);
if (from_frame > to_frame)
return gimp_procedure_new_return_values (procedure,
GIMP_PDB_CALLING_ERROR,
NULL);
break;
case GIMP_RUN_INTERACTIVE: case GIMP_RUN_INTERACTIVE:
case GIMP_RUN_WITH_LAST_VALS: case GIMP_RUN_WITH_LAST_VALS:
gimp_ui_init (PLUG_IN_BINARY); gimp_ui_init (PLUG_IN_BINARY);
...@@ -381,20 +366,30 @@ fli_save (GimpProcedure *procedure, ...@@ -381,20 +366,30 @@ fli_save (GimpProcedure *procedure,
return gimp_procedure_new_return_values (procedure, return gimp_procedure_new_return_values (procedure,
GIMP_PDB_CANCEL, GIMP_PDB_CANCEL,
NULL); NULL);
break;
if (! save_dialog (image)) default:
break;
}
if (run_mode == GIMP_RUN_INTERACTIVE)
{
if (! save_dialog (image, procedure, G_OBJECT (config)))
status = GIMP_PDB_CANCEL; status = GIMP_PDB_CANCEL;
} }
if (status == GIMP_PDB_SUCCESS) if (status == GIMP_PDB_SUCCESS)
{ {
if (! save_image (file, image, from_frame, to_frame, if (! save_image (file, image, G_OBJECT (config),
&error)) &error))
{ {
status = GIMP_PDB_EXECUTION_ERROR; status = GIMP_PDB_EXECUTION_ERROR;
} }
} }
gimp_procedure_config_end_run (config, status);
g_object_unref (config);
if (export == GIMP_EXPORT_EXPORT) if (export == GIMP_EXPORT_EXPORT)
gimp_image_delete (image); gimp_image_delete (image);
...@@ -413,7 +408,7 @@ fli_info (GimpProcedure *procedure, ...@@ -413,7 +408,7 @@ fli_info (GimpProcedure *procedure,
gint32 frames; gint32 frames;
GError *error = NULL; GError *error = NULL;
file = g_file_new_for_uri (GIMP_VALUES_GET_STRING (args, 0)); file = GIMP_VALUES_GET_FILE (args, 0);
if (! get_info (file, &width, &height, &frames, if (! get_info (file, &width, &height, &frames,
&error)) &error))
...@@ -476,10 +471,9 @@ get_info (GFile *file, ...@@ -476,10 +471,9 @@ get_info (GFile *file,
* load fli animation and store as framestack * load fli animation and store as framestack
*/ */
static GimpImage * static GimpImage *
load_image (GFile *file, load_image (GFile *file,
gint32 from_frame, GObject *config,
gint32 to_frame, GError **error)
GError **error)
{ {
gchar *filename; gchar *filename;
FILE *fp; FILE *fp;
...@@ -490,13 +484,20 @@ load_image (GFile *file, ...@@ -490,13 +484,20 @@ load_image (GFile *file,
guchar cm[768], ocm[768]; guchar cm[768], ocm[768];
s_fli_header fli_header; s_fli_header fli_header;
gint cnt; gint cnt;
gint from_frame;
gint to_frame;
g_object_get (config,
"from-frame", &from_frame,
"to-frame", &to_frame,
NULL);
gimp_progress_init_printf (_("Opening '%s'"), gimp_progress_init_printf (_("Opening '%s'"),
gimp_file_get_utf8_name (file)); gimp_file_get_utf8_name (file));
filename = g_file_get_path (file); filename = g_file_get_path (file);
fp = g_fopen (filename ,"rb"); fp = g_fopen (filename ,"rb");
g_free (file); g_free (filename);
if (! fp) if (! fp)
{ {
...@@ -520,31 +521,37 @@ load_image (GFile *file, ...@@ -520,31 +521,37 @@ load_image (GFile *file,
/* /*
* Fix parameters * Fix parameters
*/ */
if ((from_frame==-1) && (to_frame==-1)) if ((from_frame == -1) && (to_frame == -1))
{ {
/* to make scripting easier: */ /* to make scripting easier: */
from_frame=1; to_frame=fli_header.frames; from_frame = 1;
to_frame = fli_header.frames;
} }
if (to_frame < from_frame) if (to_frame < from_frame)
{ {
to_frame = fli_header.frames; to_frame = fli_header.frames;
} }
if (from_frame < 1) if (from_frame < 1)
{ {
from_frame = 1; from_frame = 1;
} }
if (to_frame < 1) if (to_frame < 1)
{ {
/* nothing to do ... */ /* nothing to do ... */
fclose (fp); fclose (fp);
return NULL; return NULL;
} }
if (from_frame >= fli_header.frames) if (from_frame >= fli_header.frames)
{ {
/* nothing to do ... */ /* nothing to do ... */
fclose (fp); fclose (fp);
return NULL; return NULL;
} }
if (to_frame > fli_header.frames) if (to_frame > fli_header.frames)
{ {
to_frame = fli_header.frames; to_frame = fli_header.frames;
...@@ -626,15 +633,14 @@ load_image (GFile *file, ...@@ -626,15 +633,14 @@ load_image (GFile *file,
static gboolean static gboolean
save_image (GFile *file, save_image (GFile *file,
GimpImage *image, GimpImage *image,
gint32 from_frame, GObject *config,
gint32 to_frame,
GError **error) GError **error)
{ {
gchar *filename; gchar *filename;
FILE *fp; FILE *fp;
GList *framelist; GList *framelist;
GList *iter; GList *iter;
gint nframes; gint n_frames;
gint colors, i; gint colors, i;
guchar *cmap; guchar *cmap;
guchar bg; guchar bg;
...@@ -648,19 +654,27 @@ save_image (GFile *file, ...@@ -648,19 +654,27 @@ save_image (GFile *file,
GimpRGB background; GimpRGB background;
s_fli_header fli_header; s_fli_header fli_header;
gint cnt; gint cnt;
gint from_frame;
gint to_frame;
g_object_get (config,
"from-frame", &from_frame,
"to-frame", &to_frame,
NULL);
framelist = gimp_image_list_layers (image); framelist = gimp_image_list_layers (image);
framelist = g_list_reverse (framelist); framelist = g_list_reverse (framelist);
nframes = g_list_length (framelist); n_frames = g_list_length (framelist);
if ((from_frame == -1) && (to_frame == -1)) if ((from_frame == -1) && (to_frame == -1))
{ {
/* to make scripting easier: */ /* to make scripting easier: */
from_frame = 0; to_frame = nframes; from_frame = 1;
to_frame = n_frames;
} }
if (to_frame < from_frame) if (to_frame < from_frame)
{ {
to_frame = nframes; to_frame = n_frames;
} }
if (from_frame < 1) if (from_frame < 1)
{ {
...@@ -671,14 +685,14 @@ save_image (GFile *file, ...@@ -671,14 +685,14 @@ save_image (GFile *file,
/* nothing to do ... */ /* nothing to do ... */
return FALSE; return FALSE;
} }
if (from_frame > nframes) if (from_frame > n_frames)
{ {
/* nothing to do ... */ /* nothing to do ... */
return FALSE; return FALSE;
} }
if (to_frame > nframes) if (to_frame > n_frames)
{ {
to_frame = nframes; to_frame = n_frames;
} }
gimp_context_get_background (&background); gimp_context_get_background (&background);
...@@ -856,7 +870,7 @@ save_image (GFile *file, ...@@ -856,7 +870,7 @@ save_image (GFile *file,
g_free (fb); g_free (fb);
g_free (ofb); g_free (ofb);
g_free (framelist); g_list_free (framelist);
gimp_progress_update (1.0); gimp_progress_update (1.0);
...@@ -867,35 +881,28 @@ save_image (GFile *file, ...@@ -867,35 +881,28 @@ save_image (GFile *file,
* Dialogs for interactive usage * Dialogs for interactive usage
*/ */
static gboolean static gboolean
load_dialog (GFile *file) load_dialog (GFile *file,
GimpProcedure *procedure,
GObject *config)
{ {
GtkWidget *dialog; GtkWidget *dialog;
GtkWidget *grid; GtkWidget *grid;
GtkWidget *spinbutton; GtkWidget *spinbutton;
GtkAdjustment *adj; gint width, height, n_frames;
gint32 width, height, nframes; gboolean run;
gboolean run;
get_info (file, &width, &height, &nframes, NULL); get_info (file, &width, &height, &n_frames, NULL);
from_frame = 1; g_object_set (config,
to_frame = nframes; "from-frame", 1,
"to-frame", n_frames,
NULL);
gimp_ui_init (PLUG_IN_BINARY); gimp_ui_init (PLUG_IN_BINARY);
dialog = gimp_dialog_new (_("GFLI 1.3 - Load framestack"), PLUG_IN_ROLE, dialog = gimp_procedure_dialog_new (procedure,
NULL, 0, GIMP_PROCEDURE_CONFIG (config),
gimp_standard_help_func, LOAD_PROC, _("Open FLIC Animation"));
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("_Open"), GTK_RESPONSE_OK,
NULL);
gimp_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
GTK_RESPONSE_OK,
GTK_RESPONSE_CANCEL,
-1);
grid = gtk_grid_new (); grid = gtk_grid_new ();
gtk_container_set_border_width (GTK_CONTAINER (grid), 12); gtk_container_set_border_width (GTK_CONTAINER (grid), 12);
...@@ -909,29 +916,22 @@ load_dialog (GFile *file) ...@@ -909,29 +916,22 @@ load_dialog (GFile *file)
* Maybe I add on-the-fly RGB conversion, to keep palettechanges... * Maybe I add on-the-fly RGB conversion, to keep palettechanges...
* But for now you can set a start- and a end-frame: * But for now you can set a start- and a end-frame:
*/ */
adj = gtk_adjustment_new (from_frame, 1, nframes, 1, 10, 0);
spinbutton = gimp_spin_button_new (adj, 1, 0); spinbutton = gimp_prop_spin_button_new (config, "from-frame",
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE); 1, 10, 0);
gimp_grid_attach_aligned (GTK_GRID (grid), 0, 0, gimp_grid_attach_aligned (GTK_GRID (grid), 0, 0,
C_("frame-range", "_From:"), 0.0, 0.5, C_("frame-range", "_From:"), 0.0, 0.5,
spinbutton, 1); spinbutton, 1);
g_signal_connect (adj, "value-changed",
G_CALLBACK (gimp_int_adjustment_update),
&from_frame);
adj = gtk_adjustment_new (to_frame, 1, nframes, 1, 10, 0); spinbutton = gimp_prop_spin_button_new (config, "to-frame",
spinbutton = gimp_spin_button_new (adj, 1, 0); 1, 10, 0);
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
gimp_grid_attach_aligned (GTK_GRID (grid), 0, 1, gimp_grid_attach_aligned (GTK_GRID (grid), 0, 1,
C_("frame-range", "_To:"), 0.0, 0.5, C_("frame-range", "_To:"), 0.0, 0.5,
spinbutton, 1); spinbutton, 1);
g_signal_connect (adj, "value-changed",
G_CALLBACK (gimp_int_adjustment_update),
&to_frame);
gtk_widget_show (dialog); gtk_widget_show (dialog);
run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK); run = gimp_procedure_dialog_run (GIMP_PROCEDURE_DIALOG (dialog));
gtk_widget_destroy (dialog); gtk_widget_destroy (dialog);
...@@ -939,27 +939,32 @@ load_dialog (GFile *file) ...@@ -939,27 +939,32 @@ load_dialog (GFile *file)
} }
static gboolean static gboolean
save_dialog (GimpImage *image) save_dialog (GimpImage *image,
GimpProcedure *procedure,
GObject *config)
{ {
GtkWidget *dialog; GtkWidget *dialog;
GtkWidget *grid; GtkWidget *grid;
GtkWidget *spinbutton; GtkWidget *spinbutton;
GtkAdjustment *adj; gint n_frames;
gint nframes; gboolean run;
gboolean run;
g_free (gimp_image_get_layers (image, &nframes)); g_free (gimp_image_get_layers (image, &n_frames));
from_frame = 1; g_object_set (config,
to_frame = nframes; "from-frame", 1,
"to-frame", n_frames,
NULL);
dialog = gimp_export_dialog_new (_("GFLI 1.3"), PLUG_IN_BINARY, SAVE_PROC); dialog = gimp_procedure_dialog_new (procedure,
GIMP_PROCEDURE_CONFIG (config),
_("Export Image as FLI Animation"));
grid = gtk_grid_new (); grid = gtk_grid_new ();
gtk_container_set_border_width (GTK_CONTAINER (grid), 12); gtk_container_set_border_width (GTK_CONTAINER (grid), 12);
gtk_grid_set_row_spacing (GTK_GRID (grid), 6); gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
gtk_grid_set_column_spacing (GTK_GRID (grid), 6); gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
gtk_box_pack_start (GTK_BOX (gimp_export_dialog_get_content_area (dialog)), gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
grid, FALSE, FALSE, 0); grid, FALSE, FALSE, 0);
gtk_widget_show (grid); gtk_widget_show (grid);
...@@ -967,29 +972,22 @@ save_dialog (GimpImage *image) ...@@ -967,29 +972,22 @@ save_dialog (GimpImage *image)
* Maybe I add on-the-fly RGB conversion, to keep palettechanges... * Maybe I add on-the-fly RGB conversion, to keep palettechanges...
* But for now you can set a start- and a end-frame: * But for now you can set a start- and a end-frame:
*/ */
adj = gtk_adjustment_new (from_frame, 1, nframes, 1, 10, 0);
spinbutton = gimp_spin_button_new (adj, 1, 0); spinbutton = gimp_prop_spin_button_new (config, "from-frame",
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE); 1, 10, 0);
gimp_grid_attach_aligned (GTK_GRID (grid), 0, 0, gimp_grid_attach_aligned (GTK_GRID (grid), 0, 0,
C_("frame-range", "_From:"), 0.0, 0.5, C_("frame-range", "_From:"), 0.0, 0.5,
spinbutton, 1); spinbutton, 1);
g_signal_connect (adj, "value-changed",
G_CALLBACK (gimp_int_adjustment_update),
&from_frame);
adj = gtk_adjustment_new (to_frame, 1, nframes, 1, 10, 0); spinbutton = gimp_prop_spin_button_new (config, "to-frame",
spinbutton = gimp_spin_button_new (adj, 1, 0); 1, 10, 0);
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
gimp_grid_attach_aligned (GTK_GRID (grid), 0, 1, gimp_grid_attach_aligned (GTK_GRID (grid), 0, 1,
C_("frame-range", "_To:"), 0.0, 0.5, C_("frame-range", "_To:"), 0.0, 0.5,
spinbutton, 1); spinbutton, 1);
g_signal_connect (adj, "value-changed",
G_CALLBACK (gimp_int_adjustment_update),
&to_frame);
gtk_widget_show (dialog); gtk_widget_show (dialog);
run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK); run = gimp_procedure_dialog_run (GIMP_PROCEDURE_DIALOG (dialog));
gtk_widget_destroy (dialog); gtk_widget_destroy (dialog);
......
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