mirror of https://github.com/GNOME/gimp.git
plug-ins: port file-fli to GimpPlugIn and libgimp objects
This commit is contained in:
parent
bc1e611bf0
commit
5dd8add77a
|
@ -29,10 +29,9 @@ file_fli_SOURCES = \
|
|||
fli-gimp.c
|
||||
|
||||
AM_CPPFLAGS = \
|
||||
-DGIMP_DEPRECATED_REPLACE_NEW_API \
|
||||
-I$(top_srcdir) \
|
||||
$(GTK_CFLAGS) \
|
||||
$(GEGL_CFLAGS) \
|
||||
$(GEGL_CFLAGS) \
|
||||
-I$(includedir)
|
||||
|
||||
LDADD = \
|
||||
|
|
|
@ -71,377 +71,364 @@
|
|||
#define PLUG_IN_ROLE "gimp-file-fli"
|
||||
|
||||
|
||||
static void query (void);
|
||||
static void run (const gchar *name,
|
||||
gint nparams,
|
||||
const GimpParam *param,
|
||||
gint *nreturn_vals,
|
||||
GimpParam **return_vals);
|
||||
typedef struct _Fli Fli;
|
||||
typedef struct _FliClass FliClass;
|
||||
|
||||
/* return the image-ID of the new image, or -1 in case of an error */
|
||||
static gint32 load_image (const gchar *filename,
|
||||
gint32 from_frame,
|
||||
gint32 to_frame,
|
||||
GError **error);
|
||||
static gboolean load_dialog (const gchar *filename);
|
||||
|
||||
static gboolean save_image (const gchar *filename,
|
||||
gint32 image_id,
|
||||
gint32 from_frame,
|
||||
gint32 to_frame,
|
||||
GError **error);
|
||||
static gboolean save_dialog (gint32 image_id);
|
||||
|
||||
static gboolean get_info (const gchar *filename,
|
||||
gint32 *width,
|
||||
gint32 *height,
|
||||
gint32 *frames,
|
||||
GError **error);
|
||||
|
||||
/*
|
||||
* GIMP interface
|
||||
*/
|
||||
const GimpPlugInInfo PLUG_IN_INFO =
|
||||
struct _Fli
|
||||
{
|
||||
NULL, /* init_proc */
|
||||
NULL, /* quit_proc */
|
||||
query, /* query_proc */
|
||||
run, /* run_proc */
|
||||
GimpPlugIn parent_instance;
|
||||
};
|
||||
|
||||
static const GimpParamDef load_args[] =
|
||||
struct _FliClass
|
||||
{
|
||||
{ GIMP_PDB_INT32, "run-mode", "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" },
|
||||
{ GIMP_PDB_STRING, "filename", "The name of the file to load" },
|
||||
{ GIMP_PDB_STRING, "raw-filename", "The name entered" },
|
||||
{ GIMP_PDB_INT32, "from-frame", "Load beginning from this frame" },
|
||||
{ GIMP_PDB_INT32, "to-frame", "End loading with this frame" }
|
||||
GimpPlugInClass parent_class;
|
||||
};
|
||||
|
||||
static const GimpParamDef load_return_vals[] =
|
||||
{
|
||||
{ GIMP_PDB_IMAGE, "image", "Output image" },
|
||||
};
|
||||
|
||||
static const GimpParamDef save_args[] =
|
||||
{
|
||||
{ GIMP_PDB_INT32, "run-mode", "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" },
|
||||
{ GIMP_PDB_IMAGE, "image", "Input image" },
|
||||
{ GIMP_PDB_DRAWABLE, "drawable", "Input drawable (unused)" },
|
||||
{ GIMP_PDB_STRING, "filename", "The name of the file to export" },
|
||||
{ GIMP_PDB_STRING, "raw-filename", "The name entered" },
|
||||
{ GIMP_PDB_INT32, "from-frame", "Export beginning from this frame" },
|
||||
{ GIMP_PDB_INT32, "to-frame", "End exporting with this frame" },
|
||||
};
|
||||
#define FLI_TYPE (fli_get_type ())
|
||||
#define FLI (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), FLI_TYPE, Fli))
|
||||
|
||||
static const GimpParamDef info_args[] =
|
||||
{
|
||||
{ GIMP_PDB_STRING, "filename", "The name of the file to get info" },
|
||||
};
|
||||
static const GimpParamDef info_return_vals[] =
|
||||
{
|
||||
{ GIMP_PDB_INT32, "width", "Width of one frame" },
|
||||
{ GIMP_PDB_INT32, "height", "Height of one frame" },
|
||||
{ GIMP_PDB_INT32, "frames", "Number of Frames" },
|
||||
};
|
||||
GType fli_get_type (void) G_GNUC_CONST;
|
||||
|
||||
static GList * fli_query_procedures (GimpPlugIn *plug_in);
|
||||
static GimpProcedure * fli_create_procedure (GimpPlugIn *plug_in,
|
||||
const gchar *name);
|
||||
|
||||
static GimpValueArray * fli_load (GimpProcedure *procedure,
|
||||
GimpRunMode run_mode,
|
||||
GFile *file,
|
||||
const GimpValueArray *args,
|
||||
gpointer run_data);
|
||||
static GimpValueArray * fli_save (GimpProcedure *procedure,
|
||||
GimpRunMode run_mode,
|
||||
GimpImage *image,
|
||||
GimpDrawable *drawable,
|
||||
GFile *file,
|
||||
const GimpValueArray *args,
|
||||
gpointer run_data);
|
||||
static GimpValueArray * fli_info (GimpProcedure *procedure,
|
||||
const GimpValueArray *args,
|
||||
gpointer run_data);
|
||||
|
||||
static GimpImage * load_image (const gchar *filename,
|
||||
gint32 from_frame,
|
||||
gint32 to_frame,
|
||||
GError **error);
|
||||
static gboolean load_dialog (const gchar *filename);
|
||||
|
||||
static gboolean save_image (const gchar *filename,
|
||||
GimpImage *image,
|
||||
gint32 from_frame,
|
||||
gint32 to_frame,
|
||||
GError **error);
|
||||
static gboolean save_dialog (GimpImage *image);
|
||||
|
||||
static gboolean get_info (const gchar *filename,
|
||||
gint32 *width,
|
||||
gint32 *height,
|
||||
gint32 *frames,
|
||||
GError **error);
|
||||
|
||||
|
||||
G_DEFINE_TYPE (Fli, fli, GIMP_TYPE_PLUG_IN)
|
||||
|
||||
GIMP_MAIN (FLI_TYPE)
|
||||
|
||||
|
||||
static gint32 from_frame;
|
||||
static gint32 to_frame;
|
||||
|
||||
MAIN ()
|
||||
|
||||
static void
|
||||
query (void)
|
||||
fli_class_init (FliClass *klass)
|
||||
{
|
||||
/*
|
||||
* Load/export procedures
|
||||
*/
|
||||
gimp_install_procedure (LOAD_PROC,
|
||||
"load FLI-movies",
|
||||
"This is an experimantal plug-in to handle FLI movies",
|
||||
"Jens Ch. Restemeier",
|
||||
"Jens Ch. Restemeier",
|
||||
"1997",
|
||||
N_("AutoDesk FLIC animation"),
|
||||
NULL,
|
||||
GIMP_PLUGIN,
|
||||
G_N_ELEMENTS (load_args) - 2,
|
||||
G_N_ELEMENTS (load_return_vals),
|
||||
load_args,
|
||||
load_return_vals);
|
||||
GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
|
||||
|
||||
gimp_register_file_handler_mime (LOAD_PROC, "image/x-flic");
|
||||
gimp_register_magic_load_handler (LOAD_PROC,
|
||||
"fli,flc",
|
||||
"",
|
||||
"");
|
||||
|
||||
gimp_install_procedure (SAVE_PROC,
|
||||
"export FLI-movies",
|
||||
"This is an experimantal plug-in to handle FLI movies",
|
||||
"Jens Ch. Restemeier",
|
||||
"Jens Ch. Restemeier",
|
||||
"1997",
|
||||
N_("AutoDesk FLIC animation"),
|
||||
"INDEXED,GRAY",
|
||||
GIMP_PLUGIN,
|
||||
G_N_ELEMENTS (save_args), 0,
|
||||
save_args, NULL);
|
||||
|
||||
gimp_register_file_handler_mime (SAVE_PROC, "image/x-flic");
|
||||
gimp_register_save_handler (SAVE_PROC,
|
||||
"fli,flc",
|
||||
"");
|
||||
|
||||
/*
|
||||
* Utility functions:
|
||||
*/
|
||||
gimp_install_procedure (INFO_PROC,
|
||||
"Get information about a Fli movie",
|
||||
"This is a experimantal plug-in to handle FLI movies",
|
||||
"Jens Ch. Restemeier",
|
||||
"Jens Ch. Restemeier",
|
||||
"1997",
|
||||
NULL,
|
||||
NULL,
|
||||
GIMP_PLUGIN,
|
||||
G_N_ELEMENTS (info_args),
|
||||
G_N_ELEMENTS (info_return_vals),
|
||||
info_args,
|
||||
info_return_vals);
|
||||
plug_in_class->query_procedures = fli_query_procedures;
|
||||
plug_in_class->create_procedure = fli_create_procedure;
|
||||
}
|
||||
|
||||
static void
|
||||
run (const gchar *name,
|
||||
gint nparams,
|
||||
const GimpParam *param,
|
||||
gint *nreturn_vals,
|
||||
GimpParam **return_vals)
|
||||
fli_init (Fli *fli)
|
||||
{
|
||||
static GimpParam values[5];
|
||||
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
||||
GimpRunMode run_mode;
|
||||
gint32 pc;
|
||||
gint32 image_ID;
|
||||
gint32 drawable_ID;
|
||||
gint32 orig_image_ID;
|
||||
GFile *file;
|
||||
GimpExportReturn export = GIMP_EXPORT_CANCEL;
|
||||
GError *error = NULL;
|
||||
}
|
||||
|
||||
static GList *
|
||||
fli_query_procedures (GimpPlugIn *plug_in)
|
||||
{
|
||||
GList *list = NULL;
|
||||
|
||||
list = g_list_append (list, g_strdup (LOAD_PROC));
|
||||
list = g_list_append (list, g_strdup (SAVE_PROC));
|
||||
list = g_list_append (list, g_strdup (INFO_PROC));
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
static GimpProcedure *
|
||||
fli_create_procedure (GimpPlugIn *plug_in,
|
||||
const gchar *name)
|
||||
{
|
||||
GimpProcedure *procedure = NULL;
|
||||
|
||||
if (! strcmp (name, LOAD_PROC))
|
||||
{
|
||||
procedure = gimp_load_procedure_new (plug_in, name, GIMP_PLUGIN,
|
||||
fli_load, NULL, NULL);
|
||||
|
||||
gimp_procedure_set_menu_label (procedure, N_("AutoDesk FLIC animation"));
|
||||
|
||||
gimp_procedure_set_documentation (procedure,
|
||||
"Load FLI-movies",
|
||||
"This is an experimantal plug-in to "
|
||||
"handle FLI movies",
|
||||
name);
|
||||
gimp_procedure_set_attribution (procedure,
|
||||
"Jens Ch. Restemeier",
|
||||
"Jens Ch. Restemeier",
|
||||
"1997");
|
||||
|
||||
gimp_file_procedure_set_mime_types (GIMP_FILE_PROCEDURE (procedure),
|
||||
"image/x-flic");
|
||||
gimp_file_procedure_set_extensions (GIMP_FILE_PROCEDURE (procedure),
|
||||
"fli,flc");
|
||||
|
||||
GIMP_PROC_ARG_INT (procedure, "from-frame",
|
||||
"From frame",
|
||||
"Load beginning from this frame",
|
||||
-1, G_MAXINT, -1,
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
GIMP_PROC_ARG_INT (procedure, "to-frame",
|
||||
"To frame",
|
||||
"End loading with this frame",
|
||||
-1, G_MAXINT, -1,
|
||||
G_PARAM_READWRITE);
|
||||
}
|
||||
else if (! strcmp (name, SAVE_PROC))
|
||||
{
|
||||
procedure = gimp_save_procedure_new (plug_in, name, GIMP_PLUGIN,
|
||||
fli_save, NULL, NULL);
|
||||
|
||||
gimp_procedure_set_image_types (procedure, "INDEXED, GRAY");
|
||||
|
||||
gimp_procedure_set_menu_label (procedure, N_("AutoDesk FLIC animation"));
|
||||
|
||||
gimp_procedure_set_documentation (procedure,
|
||||
"Export FLI-movies",
|
||||
"This is an experimantal plug-in to "
|
||||
"handle FLI movies",
|
||||
name);
|
||||
gimp_procedure_set_attribution (procedure,
|
||||
"Jens Ch. Restemeier",
|
||||
"Jens Ch. Restemeier",
|
||||
"1997");
|
||||
|
||||
gimp_file_procedure_set_mime_types (GIMP_FILE_PROCEDURE (procedure),
|
||||
"image/x-flic");
|
||||
gimp_file_procedure_set_extensions (GIMP_FILE_PROCEDURE (procedure),
|
||||
"fli,flc");
|
||||
|
||||
GIMP_PROC_ARG_INT (procedure, "from-frame",
|
||||
"From frame",
|
||||
"Export beginning from this frame",
|
||||
-1, G_MAXINT, -1,
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
GIMP_PROC_ARG_INT (procedure, "to-frame",
|
||||
"To frame",
|
||||
"End exporting with this frame",
|
||||
-1, G_MAXINT, -1,
|
||||
G_PARAM_READWRITE);
|
||||
}
|
||||
else if (! strcmp (name, INFO_PROC))
|
||||
{
|
||||
procedure = gimp_procedure_new (plug_in, name, GIMP_PLUGIN,
|
||||
fli_info, NULL, NULL);
|
||||
|
||||
gimp_procedure_set_documentation (procedure,
|
||||
"Get information about a Fli movie",
|
||||
"This is an experimantal plug-in to "
|
||||
"handle FLI movies",
|
||||
name);
|
||||
gimp_procedure_set_attribution (procedure,
|
||||
"Jens Ch. Restemeier",
|
||||
"Jens Ch. Restemeier",
|
||||
"1997");
|
||||
|
||||
GIMP_PROC_ARG_STRING (procedure, "uri",
|
||||
"URI",
|
||||
"The local file:// URI of the file to get info",
|
||||
NULL,
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
GIMP_PROC_VAL_INT (procedure, "width",
|
||||
"Width",
|
||||
"Width of one frame",
|
||||
0, GIMP_MAX_IMAGE_SIZE, 0,
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
GIMP_PROC_VAL_INT (procedure, "height",
|
||||
"Height",
|
||||
"Height of one frame",
|
||||
0, GIMP_MAX_IMAGE_SIZE, 0,
|
||||
G_PARAM_READWRITE);
|
||||
|
||||
GIMP_PROC_VAL_INT (procedure, "frames",
|
||||
"Frames",
|
||||
"Number of frames",
|
||||
0, G_MAXINT, 0,
|
||||
G_PARAM_READWRITE);
|
||||
}
|
||||
|
||||
return procedure;
|
||||
}
|
||||
|
||||
static GimpValueArray *
|
||||
fli_load (GimpProcedure *procedure,
|
||||
GimpRunMode run_mode,
|
||||
GFile *file,
|
||||
const GimpValueArray *args,
|
||||
gpointer run_data)
|
||||
{
|
||||
GimpValueArray *return_vals;
|
||||
GimpImage *image;
|
||||
GError *error = NULL;
|
||||
|
||||
INIT_I18N ();
|
||||
gegl_init (NULL, NULL);
|
||||
|
||||
run_mode = param[0].data.d_int32;
|
||||
|
||||
*nreturn_vals = 1;
|
||||
*return_vals = values;
|
||||
|
||||
values[0].type = GIMP_PDB_STATUS;
|
||||
values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
|
||||
|
||||
if (strcmp (name, LOAD_PROC) == 0)
|
||||
switch (run_mode)
|
||||
{
|
||||
file = g_file_new_for_uri (param[1].data.d_string);
|
||||
case GIMP_RUN_NONINTERACTIVE:
|
||||
from_frame = GIMP_VALUES_GET_INT (args, 0);
|
||||
to_frame = GIMP_VALUES_GET_INT (args, 1);
|
||||
break;
|
||||
|
||||
switch (run_mode)
|
||||
case GIMP_RUN_INTERACTIVE:
|
||||
if (! load_dialog (g_file_get_path (file)))
|
||||
return gimp_procedure_new_return_values (procedure,
|
||||
GIMP_PDB_CANCEL,
|
||||
NULL);
|
||||
break;
|
||||
|
||||
case GIMP_RUN_WITH_LAST_VALS:
|
||||
return gimp_procedure_new_return_values (procedure,
|
||||
GIMP_PDB_CALLING_ERROR,
|
||||
error);
|
||||
break;
|
||||
}
|
||||
|
||||
image = load_image (g_file_get_path (file),
|
||||
from_frame, to_frame, &error);
|
||||
|
||||
if (! image)
|
||||
return gimp_procedure_new_return_values (procedure,
|
||||
GIMP_PDB_EXECUTION_ERROR,
|
||||
error);
|
||||
|
||||
return_vals = gimp_procedure_new_return_values (procedure,
|
||||
GIMP_PDB_SUCCESS,
|
||||
NULL);
|
||||
|
||||
GIMP_VALUES_SET_IMAGE (return_vals, 1, image);
|
||||
|
||||
return return_vals;
|
||||
}
|
||||
|
||||
static GimpValueArray *
|
||||
fli_save (GimpProcedure *procedure,
|
||||
GimpRunMode run_mode,
|
||||
GimpImage *image,
|
||||
GimpDrawable *drawable,
|
||||
GFile *file,
|
||||
const GimpValueArray *args,
|
||||
gpointer run_data)
|
||||
{
|
||||
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
||||
GimpExportReturn export = GIMP_EXPORT_CANCEL;
|
||||
GError *error = NULL;
|
||||
|
||||
INIT_I18N ();
|
||||
gegl_init (NULL, NULL);
|
||||
|
||||
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_WITH_LAST_VALS:
|
||||
gimp_ui_init (PLUG_IN_BINARY, FALSE);
|
||||
|
||||
export = gimp_export_image (&image, &drawable, "FLI",
|
||||
GIMP_EXPORT_CAN_HANDLE_INDEXED |
|
||||
GIMP_EXPORT_CAN_HANDLE_GRAY |
|
||||
GIMP_EXPORT_CAN_HANDLE_ALPHA |
|
||||
GIMP_EXPORT_CAN_HANDLE_LAYERS);
|
||||
|
||||
if (export == GIMP_EXPORT_CANCEL)
|
||||
return gimp_procedure_new_return_values (procedure,
|
||||
GIMP_PDB_CANCEL,
|
||||
NULL);
|
||||
|
||||
if (! save_dialog (image))
|
||||
status = GIMP_PDB_CANCEL;
|
||||
}
|
||||
|
||||
if (status == GIMP_PDB_SUCCESS)
|
||||
{
|
||||
if (! save_image (g_file_get_path (file), image,
|
||||
from_frame, to_frame, &error))
|
||||
{
|
||||
case GIMP_RUN_NONINTERACTIVE:
|
||||
/*
|
||||
* check for valid parameters:
|
||||
* (Or can I trust GIMP ?)
|
||||
*/
|
||||
if ((nparams < G_N_ELEMENTS (load_args) - 2) ||
|
||||
(G_N_ELEMENTS (load_args) < nparams))
|
||||
{
|
||||
status = GIMP_PDB_CALLING_ERROR;
|
||||
break;
|
||||
}
|
||||
for (pc = 0; pc < G_N_ELEMENTS (load_args) - 2; pc++)
|
||||
{
|
||||
if (load_args[pc].type != param[pc].type)
|
||||
{
|
||||
status = GIMP_PDB_CALLING_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (pc = G_N_ELEMENTS (load_args) - 2; pc < nparams; pc++)
|
||||
{
|
||||
if (load_args[pc].type != param[pc].type)
|
||||
{
|
||||
status = GIMP_PDB_CALLING_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
to_frame = ((nparams < G_N_ELEMENTS (load_args) - 1) ?
|
||||
1 : param[3].data.d_int32);
|
||||
from_frame = ((nparams < G_N_ELEMENTS (load_args)) ?
|
||||
-1 : param[4].data.d_int32);
|
||||
|
||||
image_ID = load_image (g_file_get_path (file),
|
||||
from_frame, to_frame, &error);
|
||||
|
||||
if (image_ID != -1)
|
||||
{
|
||||
*nreturn_vals = 2;
|
||||
values[1].type = GIMP_PDB_IMAGE;
|
||||
values[1].data.d_image = image_ID;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = GIMP_PDB_EXECUTION_ERROR;
|
||||
}
|
||||
break;
|
||||
|
||||
case GIMP_RUN_INTERACTIVE:
|
||||
if (load_dialog (g_file_get_path (file)))
|
||||
{
|
||||
image_ID = load_image (g_file_get_path (file),
|
||||
from_frame, to_frame, &error);
|
||||
|
||||
if (image_ID != -1)
|
||||
{
|
||||
*nreturn_vals = 2;
|
||||
values[1].type = GIMP_PDB_IMAGE;
|
||||
values[1].data.d_image = image_ID;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = GIMP_PDB_EXECUTION_ERROR;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
status = GIMP_PDB_CANCEL;
|
||||
}
|
||||
break;
|
||||
|
||||
case GIMP_RUN_WITH_LAST_VALS:
|
||||
status = GIMP_PDB_CALLING_ERROR;
|
||||
break;
|
||||
status = GIMP_PDB_EXECUTION_ERROR;
|
||||
}
|
||||
}
|
||||
else if (strcmp (name, SAVE_PROC) == 0)
|
||||
|
||||
if (export == GIMP_EXPORT_EXPORT)
|
||||
gimp_image_delete (image);
|
||||
|
||||
return gimp_procedure_new_return_values (procedure, status, error);
|
||||
}
|
||||
|
||||
static GimpValueArray *
|
||||
fli_info (GimpProcedure *procedure,
|
||||
const GimpValueArray *args,
|
||||
gpointer run_data)
|
||||
{
|
||||
GimpValueArray *return_vals;
|
||||
GFile *file;
|
||||
gint32 width;
|
||||
gint32 height;
|
||||
gint32 frames;
|
||||
GError *error = NULL;
|
||||
|
||||
file = g_file_new_for_uri (GIMP_VALUES_GET_STRING (args, 0));
|
||||
|
||||
if (! get_info (g_file_get_path (file),
|
||||
&width, &height, &frames, &error))
|
||||
{
|
||||
GFile *file = g_file_new_for_uri (param[3].data.d_string);
|
||||
|
||||
image_ID = orig_image_ID = param[1].data.d_int32;
|
||||
drawable_ID = param[2].data.d_int32;
|
||||
|
||||
switch (run_mode)
|
||||
{
|
||||
case GIMP_RUN_NONINTERACTIVE:
|
||||
if (nparams != G_N_ELEMENTS (save_args))
|
||||
{
|
||||
status = GIMP_PDB_CALLING_ERROR;
|
||||
break;
|
||||
}
|
||||
for (pc = 0; pc < G_N_ELEMENTS (save_args); pc++)
|
||||
{
|
||||
if (save_args[pc].type!=param[pc].type)
|
||||
{
|
||||
status = GIMP_PDB_CALLING_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (! save_image (g_file_get_path (file), image_ID,
|
||||
param[5].data.d_int32,
|
||||
param[6].data.d_int32, &error))
|
||||
{
|
||||
status = GIMP_PDB_EXECUTION_ERROR;
|
||||
}
|
||||
break;
|
||||
|
||||
case GIMP_RUN_INTERACTIVE:
|
||||
case GIMP_RUN_WITH_LAST_VALS:
|
||||
gimp_ui_init (PLUG_IN_BINARY, FALSE);
|
||||
|
||||
export = gimp_export_image (&image_ID, &drawable_ID, "FLI",
|
||||
GIMP_EXPORT_CAN_HANDLE_INDEXED |
|
||||
GIMP_EXPORT_CAN_HANDLE_GRAY |
|
||||
GIMP_EXPORT_CAN_HANDLE_ALPHA |
|
||||
GIMP_EXPORT_CAN_HANDLE_LAYERS);
|
||||
|
||||
if (export == GIMP_EXPORT_CANCEL)
|
||||
{
|
||||
values[0].data.d_status = GIMP_PDB_CANCEL;
|
||||
return;
|
||||
}
|
||||
|
||||
if (save_dialog (param[1].data.d_image))
|
||||
{
|
||||
if (! save_image (g_file_get_path (file),
|
||||
image_ID, from_frame, to_frame, &error))
|
||||
{
|
||||
status = GIMP_PDB_EXECUTION_ERROR;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
status = GIMP_PDB_CANCEL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (export == GIMP_EXPORT_EXPORT)
|
||||
gimp_image_delete (image_ID);
|
||||
}
|
||||
else if (strcmp (name, INFO_PROC) == 0)
|
||||
{
|
||||
gint32 width, height, frames;
|
||||
|
||||
/*
|
||||
* check for valid parameters;
|
||||
*/
|
||||
if (nparams != G_N_ELEMENTS (info_args))
|
||||
status = GIMP_PDB_CALLING_ERROR;
|
||||
|
||||
if (status == GIMP_PDB_SUCCESS)
|
||||
{
|
||||
for (pc = 0; pc < G_N_ELEMENTS (save_args); pc++)
|
||||
{
|
||||
if (info_args[pc].type != param[pc].type)
|
||||
{
|
||||
status = GIMP_PDB_CALLING_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (status == GIMP_PDB_SUCCESS)
|
||||
{
|
||||
if (get_info (param[0].data.d_string,
|
||||
&width, &height, &frames, &error))
|
||||
{
|
||||
*nreturn_vals = 4;
|
||||
values[1].type = GIMP_PDB_INT32;
|
||||
values[1].data.d_int32 = width;
|
||||
values[2].type = GIMP_PDB_INT32;
|
||||
values[2].data.d_int32 = height;
|
||||
values[3].type = GIMP_PDB_INT32;
|
||||
values[3].data.d_int32 = frames;
|
||||
}
|
||||
else
|
||||
{
|
||||
status = GIMP_PDB_EXECUTION_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
status = GIMP_PDB_CALLING_ERROR;
|
||||
return gimp_procedure_new_return_values (procedure,
|
||||
GIMP_PDB_EXECUTION_ERROR,
|
||||
error);
|
||||
}
|
||||
|
||||
if (status != GIMP_PDB_SUCCESS && error)
|
||||
{
|
||||
*nreturn_vals = 2;
|
||||
values[1].type = GIMP_PDB_STRING;
|
||||
values[1].data.d_string = error->message;
|
||||
}
|
||||
return_vals = gimp_procedure_new_return_values (procedure,
|
||||
GIMP_PDB_SUCCESS,
|
||||
NULL);
|
||||
|
||||
values[0].data.d_status = status;
|
||||
GIMP_VALUES_SET_INT (return_vals, 1, width);
|
||||
GIMP_VALUES_SET_INT (return_vals, 2, height);
|
||||
GIMP_VALUES_SET_INT (return_vals, 3, frames);
|
||||
|
||||
return return_vals;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -454,8 +441,8 @@ get_info (const gchar *filename,
|
|||
gint32 *frames,
|
||||
GError **error)
|
||||
{
|
||||
FILE *file;
|
||||
s_fli_header fli_header;
|
||||
FILE *file;
|
||||
s_fli_header fli_header;
|
||||
|
||||
*width = 0; *height = 0; *frames = 0;
|
||||
|
||||
|
@ -482,7 +469,7 @@ get_info (const gchar *filename,
|
|||
/*
|
||||
* load fli animation and store as framestack
|
||||
*/
|
||||
static gint32
|
||||
static GimpImage *
|
||||
load_image (const gchar *filename,
|
||||
gint32 from_frame,
|
||||
gint32 to_frame,
|
||||
|
@ -490,7 +477,8 @@ load_image (const gchar *filename,
|
|||
{
|
||||
FILE *file;
|
||||
GeglBuffer *buffer;
|
||||
gint32 image_id, layer_ID;
|
||||
GimpImage *image;
|
||||
GimpLayer *layer;
|
||||
guchar *fb, *ofb, *fb_x;
|
||||
guchar cm[768], ocm[768];
|
||||
s_fli_header fli_header;
|
||||
|
@ -500,19 +488,19 @@ load_image (const gchar *filename,
|
|||
gimp_filename_to_utf8 (filename));
|
||||
|
||||
file = g_fopen (filename ,"rb");
|
||||
if (!file)
|
||||
if (! file)
|
||||
{
|
||||
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
|
||||
_("Could not open '%s' for reading: %s"),
|
||||
gimp_filename_to_utf8 (filename), g_strerror (errno));
|
||||
return -1;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fli_read_header (file, &fli_header);
|
||||
if (fli_header.magic == NO_HEADER)
|
||||
{
|
||||
fclose (file);
|
||||
return -1;
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -527,7 +515,7 @@ load_image (const gchar *filename,
|
|||
/* to make scripting easier: */
|
||||
from_frame=1; to_frame=fli_header.frames;
|
||||
}
|
||||
if (to_frame<from_frame)
|
||||
if (to_frame < from_frame)
|
||||
{
|
||||
to_frame = fli_header.frames;
|
||||
}
|
||||
|
@ -539,23 +527,23 @@ load_image (const gchar *filename,
|
|||
{
|
||||
/* nothing to do ... */
|
||||
fclose (file);
|
||||
return -1;
|
||||
return NULL;
|
||||
}
|
||||
if (from_frame >= fli_header.frames)
|
||||
{
|
||||
/* nothing to do ... */
|
||||
fclose (file);
|
||||
return -1;
|
||||
return NULL;
|
||||
}
|
||||
if (to_frame>fli_header.frames)
|
||||
if (to_frame > fli_header.frames)
|
||||
{
|
||||
to_frame = fli_header.frames;
|
||||
}
|
||||
|
||||
image_id = gimp_image_new (fli_header.width, fli_header.height, GIMP_INDEXED);
|
||||
gimp_image_set_filename (image_id, filename);
|
||||
image = gimp_image_new (fli_header.width, fli_header.height, GIMP_INDEXED);
|
||||
gimp_image_set_filename (image, filename);
|
||||
|
||||
fb = g_malloc (fli_header.width * fli_header.height);
|
||||
fb = g_malloc (fli_header.width * fli_header.height);
|
||||
ofb = g_malloc (fli_header.width * fli_header.height);
|
||||
|
||||
/*
|
||||
|
@ -574,14 +562,14 @@ load_image (const gchar *filename,
|
|||
{
|
||||
gchar *name_buf = g_strdup_printf (_("Frame (%i)"), cnt);
|
||||
|
||||
layer_ID = gimp_layer_new (image_id, name_buf,
|
||||
fli_header.width, fli_header.height,
|
||||
GIMP_INDEXED_IMAGE,
|
||||
100,
|
||||
gimp_image_get_default_new_layer_mode (image_id));
|
||||
layer = gimp_layer_new (image, name_buf,
|
||||
fli_header.width, fli_header.height,
|
||||
GIMP_INDEXED_IMAGE,
|
||||
100,
|
||||
gimp_image_get_default_new_layer_mode (image));
|
||||
g_free (name_buf);
|
||||
|
||||
buffer = gimp_drawable_get_buffer (layer_ID);
|
||||
buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer));
|
||||
|
||||
fli_read_frame (file, &fli_header, ofb, ocm, fb, cm);
|
||||
|
||||
|
@ -593,9 +581,9 @@ load_image (const gchar *filename,
|
|||
g_object_unref (buffer);
|
||||
|
||||
if (cnt > 0)
|
||||
gimp_layer_add_alpha (layer_ID);
|
||||
gimp_layer_add_alpha (layer);
|
||||
|
||||
gimp_image_insert_layer (image_id, layer_ID, -1, 0);
|
||||
gimp_image_insert_layer (image, layer, NULL, 0);
|
||||
|
||||
if (cnt < to_frame)
|
||||
{
|
||||
|
@ -606,7 +594,7 @@ load_image (const gchar *filename,
|
|||
gimp_progress_update ((double) cnt + 1 / (double)(to_frame - from_frame));
|
||||
}
|
||||
|
||||
gimp_image_set_colormap (image_id, cm, 256);
|
||||
gimp_image_set_colormap (image, cm, 256);
|
||||
|
||||
fclose (file);
|
||||
|
||||
|
@ -615,7 +603,7 @@ load_image (const gchar *filename,
|
|||
|
||||
gimp_progress_update (1.0);
|
||||
|
||||
return image_id;
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
|
@ -627,13 +615,14 @@ load_image (const gchar *filename,
|
|||
*/
|
||||
static gboolean
|
||||
save_image (const gchar *filename,
|
||||
gint32 image_id,
|
||||
GimpImage *image,
|
||||
gint32 from_frame,
|
||||
gint32 to_frame,
|
||||
GError **error)
|
||||
{
|
||||
FILE *file;
|
||||
gint32 *framelist;
|
||||
GList *framelist;
|
||||
GList *list;
|
||||
gint nframes;
|
||||
gint colors, i;
|
||||
guchar *cmap;
|
||||
|
@ -649,7 +638,8 @@ save_image (const gchar *filename,
|
|||
s_fli_header fli_header;
|
||||
gint cnt;
|
||||
|
||||
framelist = gimp_image_get_layers (image_id, &nframes);
|
||||
framelist = gimp_image_get_layers (image);
|
||||
nframes = g_list_length (framelist);
|
||||
|
||||
if ((from_frame == -1) && (to_frame == -1))
|
||||
{
|
||||
|
@ -682,7 +672,7 @@ save_image (const gchar *filename,
|
|||
gimp_context_get_background (&background);
|
||||
gimp_rgb_get_uchar (&background, &red, &green, &blue);
|
||||
|
||||
switch (gimp_image_base_type (image_id))
|
||||
switch (gimp_image_base_type (image))
|
||||
{
|
||||
case GIMP_GRAY:
|
||||
/* build grayscale palette */
|
||||
|
@ -696,7 +686,7 @@ save_image (const gchar *filename,
|
|||
case GIMP_INDEXED:
|
||||
max = MAXDIFF;
|
||||
bg = 0;
|
||||
cmap = gimp_image_get_colormap (image_id, &colors);
|
||||
cmap = gimp_image_get_colormap (image, &colors);
|
||||
for (i = 0; i < MIN (colors, 256); i++)
|
||||
{
|
||||
cm[i*3+0] = cmap[i*3+0];
|
||||
|
@ -735,8 +725,8 @@ save_image (const gchar *filename,
|
|||
*/
|
||||
fli_header.filesize = 0; /* will be fixed when writing the header */
|
||||
fli_header.frames = 0; /* will be fixed during the write */
|
||||
fli_header.width = gimp_image_width (image_id);
|
||||
fli_header.height = gimp_image_height (image_id);
|
||||
fli_header.width = gimp_image_width (image);
|
||||
fli_header.height = gimp_image_height (image);
|
||||
|
||||
if ((fli_header.width == 320) && (fli_header.height == 200))
|
||||
{
|
||||
|
@ -774,16 +764,19 @@ save_image (const gchar *filename,
|
|||
/*
|
||||
* Now write all frames
|
||||
*/
|
||||
for (cnt = from_frame; cnt <= to_frame; cnt++)
|
||||
for (cnt = from_frame, list = g_list_nth (framelist, nframes - cnt);
|
||||
cnt <= to_frame && list;
|
||||
cnt++, list = g_list_previous (list))
|
||||
{
|
||||
GeglBuffer *buffer;
|
||||
const Babl *format = NULL;
|
||||
GimpDrawable *drawable = list->data;
|
||||
GeglBuffer *buffer;
|
||||
const Babl *format = NULL;
|
||||
|
||||
buffer = gimp_drawable_get_buffer (framelist[nframes-cnt]);
|
||||
buffer = gimp_drawable_get_buffer (drawable);
|
||||
|
||||
if (gimp_drawable_is_gray (framelist[nframes-cnt]))
|
||||
if (gimp_drawable_is_gray (drawable))
|
||||
{
|
||||
if (gimp_drawable_has_alpha (framelist[nframes-cnt]))
|
||||
if (gimp_drawable_has_alpha (drawable))
|
||||
format = babl_format ("Y' u8");
|
||||
else
|
||||
format = babl_format ("Y'A u8");
|
||||
|
@ -796,7 +789,7 @@ save_image (const gchar *filename,
|
|||
cols = gegl_buffer_get_width (buffer);
|
||||
rows = gegl_buffer_get_height (buffer);
|
||||
|
||||
gimp_drawable_offsets (framelist[nframes-cnt], &offset_x, &offset_y);
|
||||
gimp_drawable_offsets (drawable, &offset_x, &offset_y);
|
||||
|
||||
bytes = babl_format_get_bytes_per_pixel (format);
|
||||
|
||||
|
@ -848,7 +841,7 @@ save_image (const gchar *filename,
|
|||
|
||||
g_free (fb);
|
||||
g_free (ofb);
|
||||
g_free (framelist);
|
||||
g_list_free (framelist);
|
||||
|
||||
gimp_progress_update (1.0);
|
||||
|
||||
|
@ -931,16 +924,19 @@ load_dialog (const gchar *filename)
|
|||
}
|
||||
|
||||
static gboolean
|
||||
save_dialog (gint32 image_id)
|
||||
save_dialog (GimpImage *image)
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
GtkWidget *grid;
|
||||
GtkWidget *spinbutton;
|
||||
GtkAdjustment *adj;
|
||||
GList *frames;
|
||||
gint nframes;
|
||||
gboolean run;
|
||||
|
||||
g_free (gimp_image_get_layers (image_id, &nframes));
|
||||
frames = gimp_image_get_layers (image);
|
||||
nframes = g_list_length (frames);
|
||||
g_list_free (frames);
|
||||
|
||||
from_frame = 1;
|
||||
to_frame = nframes;
|
||||
|
|
Loading…
Reference in New Issue