diff --git a/plug-ins/common/Makefile.am b/plug-ins/common/Makefile.am index aca8e3e9a5..f47ec09d09 100644 --- a/plug-ins/common/Makefile.am +++ b/plug-ins/common/Makefile.am @@ -567,8 +567,6 @@ file_aa_LDADD = \ $(INTLLIBS) \ $(file_aa_RC) -file_cel_CPPFLAGS = $(AM_CPPFLAGS) -DGIMP_DEPRECATED_REPLACE_NEW_API - file_cel_SOURCES = \ file-cel.c diff --git a/plug-ins/common/file-cel.c b/plug-ins/common/file-cel.c index 3a49f128b2..7a819064d5 100644 --- a/plug-ins/common/file-cel.c +++ b/plug-ins/common/file-cel.c @@ -37,253 +37,287 @@ #define PLUG_IN_ROLE "gimp-file-cel" -static void query (void); -static void run (const gchar *name, - gint nparams, - const GimpParam *param, - gint *nreturn_vals, - GimpParam **return_vals); +typedef struct _Cel Cel; +typedef struct _CelClass CelClass; -static gint load_palette (const gchar *file, - FILE *fp, - guchar palette[], - GError **error); -static gint32 load_image (const gchar *file, - GError **error); -static gboolean save_image (GFile *file, - gint32 image, - gint32 layer, - GError **error); -static void palette_dialog (const gchar *title); -static gboolean need_palette (const gchar *file, - GError **error); - - -/* Globals... */ - -const GimpPlugInInfo PLUG_IN_INFO = +struct _Cel { - NULL, /* init_proc */ - NULL, /* quit_proc */ - query, /* query_proc */ - run, /* run_proc */ + GimpPlugIn parent_instance; }; +struct _CelClass +{ + GimpPlugInClass parent_class; +}; + + +#define CEL_TYPE (cel_get_type ()) +#define CEL (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CEL_TYPE, Cel)) + +GType cel_get_type (void) G_GNUC_CONST; + +static GList * cel_query_procedures (GimpPlugIn *plug_in); +static GimpProcedure * cel_create_procedure (GimpPlugIn *plug_in, + const gchar *name); + +static GimpValueArray * cel_load (GimpProcedure *procedure, + GimpRunMode run_mode, + GFile *file, + const GimpValueArray *args, + gpointer run_data); +static GimpValueArray * cel_save (GimpProcedure *procedure, + GimpRunMode run_mode, + GimpImage *image, + GimpDrawable *drawable, + GFile *file, + const GimpValueArray *args, + gpointer run_data); + +static gint load_palette (const gchar *file, + FILE *fp, + guchar palette[], + GError **error); +static GimpImage * load_image (const gchar *file, + GError **error); +static gboolean save_image (GFile *file, + GimpImage *image, + GimpDrawable *drawable, + GError **error); +static void palette_dialog (const gchar *title); +static gboolean need_palette (const gchar *file, + GError **error); + + +G_DEFINE_TYPE (Cel, cel, GIMP_TYPE_PLUG_IN) + +GIMP_MAIN (CEL_TYPE) + + static gchar *palette_file = NULL; static gsize data_length = 0; -/* Let GIMP library handle initialisation (and inquisitive users) */ - -MAIN () - -/* GIMP queries plug-in for parameters etc. */ static void -query (void) +cel_class_init (CelClass *klass) { - static const GimpParamDef load_args[] = - { - { GIMP_PDB_INT32, "run-mode", "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" }, - { GIMP_PDB_STRING, "filename", "Filename to load image from" }, - { GIMP_PDB_STRING, "raw-filename", "Name entered" }, - { GIMP_PDB_STRING, "palette-filename", "Filename to load palette from" } - }; - static const GimpParamDef load_return_vals[] = - { - { GIMP_PDB_IMAGE, "image", "Output image" } - }; + GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass); - 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", "Drawable to export" }, - { GIMP_PDB_STRING, "filename", "Filename to export image to" }, - { GIMP_PDB_STRING, "raw-filename", "Name entered" }, - { GIMP_PDB_STRING, "palette-filename", "Filename to save palette to" }, - }; - - gimp_install_procedure (LOAD_PROC, - "Loads files in KISS CEL file format", - "This plug-in loads individual KISS cell files.", - "Nick Lamb", - "Nick Lamb ", - "May 1998", - N_("KISS CEL"), - NULL, - GIMP_PLUGIN, - G_N_ELEMENTS (load_args), - G_N_ELEMENTS (load_return_vals), - load_args, load_return_vals); - - gimp_register_magic_load_handler (LOAD_PROC, - "cel", - "", - "0,string,KiSS\\040"); - - gimp_install_procedure (SAVE_PROC, - "Exports files in KISS CEL file format", - "This plug-in exports individual KISS cell files.", - "Nick Lamb", - "Nick Lamb ", - "May 1998", - N_("KISS CEL"), - "RGB*, INDEXED*", - GIMP_PLUGIN, - G_N_ELEMENTS (save_args), 0, - save_args, NULL); - - gimp_register_file_handler_remote (SAVE_PROC); - gimp_register_save_handler (SAVE_PROC, "cel", ""); + plug_in_class->query_procedures = cel_query_procedures; + plug_in_class->create_procedure = cel_create_procedure; } static void -run (const gchar *name, - gint nparams, - const GimpParam *param, - gint *nreturn_vals, - GimpParam **return_vals) +cel_init (Cel *cel) { - static GimpParam values[2]; /* Return values */ - GimpRunMode run_mode; - gint32 image_ID; - gint32 drawable_ID; - GimpPDBStatusType status = GIMP_PDB_SUCCESS; - gint32 image; - GimpExportReturn export = GIMP_EXPORT_CANCEL; - GError *error = NULL; - gint needs_palette = 0; +} + +static GList * +cel_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)); + + return list; +} + +static GimpProcedure * +cel_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, + cel_load, NULL, NULL); + + gimp_procedure_set_menu_label (procedure, N_("KISS CEL")); + + gimp_procedure_set_documentation (procedure, + "Loads files in KISS CEL file format", + "This plug-in loads individual KISS " + "cell files.", + name); + gimp_procedure_set_attribution (procedure, + "Nick Lamb", + "Nick Lamb ", + "May 1998"); + + gimp_file_procedure_set_extensions (GIMP_FILE_PROCEDURE (procedure), + "cel"); + gimp_file_procedure_set_magics (GIMP_FILE_PROCEDURE (procedure), + "0,string,KiSS\\040"); + + GIMP_PROC_ARG_STRING (procedure, "palette-filename", + "Palette filename", + "Filename to load palette from", + NULL, + G_PARAM_READWRITE | + GIMP_PARAM_NO_VALIDATE); + } + else if (! strcmp (name, SAVE_PROC)) + { + procedure = gimp_save_procedure_new (plug_in, name, GIMP_PLUGIN, + cel_save, NULL, NULL); + + gimp_procedure_set_image_types (procedure, "RGB*, INDEXED*"); + + gimp_procedure_set_menu_label (procedure, N_("KISS CEL")); + + gimp_procedure_set_documentation (procedure, + "Exports files in KISS CEL file format", + "This plug-in exports individual KISS " + "cell files.", + name); + gimp_procedure_set_attribution (procedure, + "Nick Lamb", + "Nick Lamb ", + "May 1998"); + + gimp_file_procedure_set_handles_remote (GIMP_FILE_PROCEDURE (procedure), + TRUE); + gimp_file_procedure_set_extensions (GIMP_FILE_PROCEDURE (procedure), + "cel"); + + GIMP_PROC_ARG_STRING (procedure, "palette-filename", + "Palette filename", + "Filename to save palette to", + NULL, + G_PARAM_READWRITE | + GIMP_PARAM_NO_VALIDATE); + } + + return procedure; +} + +static GimpValueArray * +cel_load (GimpProcedure *procedure, + GimpRunMode run_mode, + GFile *file, + const GimpValueArray *args, + gpointer run_data) +{ + GimpValueArray *return_vals; + GimpImage *image = NULL; + gboolean needs_palette = FALSE; + GError *error = NULL; INIT_I18N (); gegl_init (NULL, NULL); - run_mode = param[0].data.d_int32; - - /* Set up default return values */ - - *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) + if (run_mode != GIMP_RUN_NONINTERACTIVE) { - if (run_mode != GIMP_RUN_NONINTERACTIVE) + data_length = gimp_get_data_size (SAVE_PROC); + if (data_length > 0) { - data_length = gimp_get_data_size (SAVE_PROC); - if (data_length > 0) - { - palette_file = g_malloc (data_length); - gimp_get_data (SAVE_PROC, palette_file); - } - else - { - palette_file = g_strdup ("*.kcf"); - data_length = strlen (palette_file) + 1; - } + palette_file = g_malloc (data_length); + gimp_get_data (SAVE_PROC, palette_file); } - - if (run_mode == GIMP_RUN_NONINTERACTIVE) + else { - palette_file = param[3].data.d_string; - if (palette_file) - data_length = strlen (palette_file) + 1; - else - data_length = 0; + palette_file = g_strdup ("*.kcf"); + data_length = strlen (palette_file) + 1; } - else if (run_mode == GIMP_RUN_INTERACTIVE) - { - /* Let user choose KCF palette (cancel ignores) */ - needs_palette = need_palette (param[1].data.d_string, &error); + } - if (! error) - { - if (needs_palette) - palette_dialog (_("Load KISS Palette")); - - gimp_set_data (SAVE_PROC, palette_file, data_length); - } - } + if (run_mode == GIMP_RUN_NONINTERACTIVE) + { + palette_file = (gchar *) GIMP_VALUES_GET_STRING (args, 0); + if (palette_file) + data_length = strlen (palette_file) + 1; + else + data_length = 0; + } + else if (run_mode == GIMP_RUN_INTERACTIVE) + { + /* Let user choose KCF palette (cancel ignores) */ + needs_palette = need_palette (g_file_get_path (file), &error); if (! error) { - GFile *file = g_file_new_for_uri (param[1].data.d_string); + if (needs_palette) + palette_dialog (_("Load KISS Palette")); - image = load_image (g_file_get_path (file), - &error); - - if (image != -1) - { - *nreturn_vals = 2; - values[1].type = GIMP_PDB_IMAGE; - values[1].data.d_image = image; - } - else - { - status = GIMP_PDB_EXECUTION_ERROR; - } - } - else - { - status = GIMP_PDB_EXECUTION_ERROR; + gimp_set_data (SAVE_PROC, palette_file, data_length); } } - else if (strcmp (name, SAVE_PROC) == 0) + + if (! error) { - image_ID = param[1].data.d_int32; - drawable_ID = param[2].data.d_int32; + image = load_image (g_file_get_path (file), + &error); + } - /* eventually export the image */ - switch (run_mode) + 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 * +cel_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_INTERACTIVE: + case GIMP_RUN_WITH_LAST_VALS: + gimp_ui_init (PLUG_IN_BINARY, FALSE); + + export = gimp_export_image (&image, &drawable, "CEL", + GIMP_EXPORT_CAN_HANDLE_RGB | + GIMP_EXPORT_CAN_HANDLE_ALPHA | + GIMP_EXPORT_CAN_HANDLE_INDEXED); + + if (export == GIMP_EXPORT_CANCEL) + return gimp_procedure_new_return_values (procedure, + GIMP_PDB_CANCEL, + NULL); + break; + + default: + break; + } + + if (save_image (file, image, drawable, + &error)) + { + if (data_length) { - 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, "CEL", - GIMP_EXPORT_CAN_HANDLE_RGB | - GIMP_EXPORT_CAN_HANDLE_ALPHA | - GIMP_EXPORT_CAN_HANDLE_INDEXED); - - if (export == GIMP_EXPORT_CANCEL) - { - values[0].data.d_status = GIMP_PDB_CANCEL; - return; - } - break; - default: - break; + gimp_set_data (SAVE_PROC, palette_file, data_length); } - - if (save_image (g_file_new_for_uri (param[3].data.d_string), - image_ID, drawable_ID, &error)) - { - if (data_length) - { - gimp_set_data (SAVE_PROC, palette_file, data_length); - } - } - else - { - status = GIMP_PDB_EXECUTION_ERROR; - } - - if (export == GIMP_EXPORT_EXPORT) - gimp_image_delete (image_ID); } else { - status = GIMP_PDB_CALLING_ERROR; + status = GIMP_PDB_EXECUTION_ERROR; } - if (status != GIMP_PDB_SUCCESS && error) - { - *nreturn_vals = 2; - values[1].type = GIMP_PDB_STRING; - values[1].data.d_string = error->message; - } + if (export == GIMP_EXPORT_EXPORT) + gimp_image_delete (image); - values[0].data.d_status = status; + return gimp_procedure_new_return_values (procedure, status, error); } /* Peek into the file to determine whether we need a palette */ @@ -320,7 +354,7 @@ need_palette (const gchar *file, /* Load CEL image into GIMP */ -static gint32 +static GimpImage * load_image (const gchar *file, GError **error) { @@ -332,8 +366,8 @@ load_image (const gchar *file, offx, offy, /* Layer offsets */ colors; /* Number of colors */ - gint32 image, /* Image */ - layer; /* Layer */ + GimpImage *image; /* Image */ + GimpLayer *layer; /* Layer */ guchar *buf; /* Temporary buffer */ guchar *line; /* Pixel data */ GeglBuffer *buffer; /* Buffer for layer */ @@ -352,7 +386,7 @@ load_image (const gchar *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 (file), g_strerror (errno)); - return -1; + return NULL; } /* Get the image dimensions and create the image... */ @@ -364,7 +398,7 @@ load_image (const gchar *file, g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("EOF or error while reading image header")); fclose (fp); - return -1; + return NULL; } if (strncmp ((const gchar *) header, "KiSS", 4)) @@ -385,7 +419,7 @@ load_image (const gchar *file, g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("EOF or error while reading image header")); fclose (fp); - return -1; + return NULL; } file_mark = header[0]; @@ -394,7 +428,7 @@ load_image (const gchar *file, g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("is not a CEL image file")); fclose (fp); - return -1; + return NULL; } bpp = header[1]; @@ -409,7 +443,7 @@ load_image (const gchar *file, g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("illegal bpp value in image: %hhu"), bpp); fclose (fp); - return -1; + return NULL; } width = header[4] + (256 * header[5]); @@ -426,7 +460,7 @@ load_image (const gchar *file, "%d, height: %d, vertical offset: %d"), width, offx, height, offy); fclose (fp); - return -1; + return NULL; } if (bpp == 32) @@ -434,11 +468,11 @@ load_image (const gchar *file, else image = gimp_image_new (width + offx, height + offy, GIMP_INDEXED); - if (image == -1) + if (! image) { g_set_error (error, 0, 0, _("Can't create a new image")); fclose (fp); - return -1; + return NULL; } gimp_image_set_filename (image, file); @@ -454,12 +488,12 @@ load_image (const gchar *file, GIMP_INDEXEDA_IMAGE, 100, gimp_image_get_default_new_layer_mode (image)); - gimp_image_insert_layer (image, layer, -1, 0); + gimp_image_insert_layer (image, layer, NULL, 0); gimp_layer_set_offsets (layer, offx, offy); /* Get the drawable and set the pixel region for our load... */ - buffer = gimp_drawable_get_buffer (layer); + buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer)); /* Read the image in and give it to GIMP a line at a time */ buf = g_new (guchar, width * 4); @@ -477,7 +511,7 @@ load_image (const gchar *file, g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("EOF or error while reading image data")); fclose (fp); - return -1; + return NULL; } for (j = 0, k = 0; j < width * 2; j+= 4, ++k) @@ -514,7 +548,7 @@ load_image (const gchar *file, g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("EOF or error while reading image data")); fclose (fp); - return -1; + return NULL; } for (j = 0, k = 0; j < width * 2; j+= 2, ++k) @@ -540,7 +574,7 @@ load_image (const gchar *file, g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("EOF or error while reading image data")); fclose (fp); - return -1; + return NULL; } /* The CEL file order is BGR so we need to swap B and R @@ -558,7 +592,7 @@ load_image (const gchar *file, g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("Unsupported bit depth (%d)!"), bpp); fclose (fp); - return -1; + return NULL; } gegl_buffer_set (buffer, GEGL_RECTANGLE (0, i, width, 1), 0, @@ -593,7 +627,7 @@ load_image (const gchar *file, _("Could not open '%s' for reading: %s"), gimp_filename_to_utf8 (palette_file), g_strerror (errno)); - return -1; + return NULL; } } @@ -602,7 +636,7 @@ load_image (const gchar *file, colors = load_palette (palette_file, fp, palette, error); fclose (fp); if (colors < 0 || *error) - return -1; + return NULL; } else { @@ -747,10 +781,10 @@ load_palette (const gchar *file, } static gboolean -save_image (GFile *file, - gint32 image, - gint32 layer, - GError **error) +save_image (GFile *file, + GimpImage *image, + GimpDrawable *drawable, + GError **error) { GOutputStream *output; GeglBuffer *buffer; @@ -768,7 +802,7 @@ save_image (GFile *file, gint i, j, k; /* Counters */ /* Check that this is an indexed image, fail otherwise */ - type = gimp_drawable_type (layer); + type = gimp_drawable_type (drawable); if (type == GIMP_INDEXEDA_IMAGE) { @@ -782,9 +816,9 @@ save_image (GFile *file, } /* Find out how offset this layer was */ - gimp_drawable_offsets (layer, &offx, &offy); + gimp_drawable_offsets (drawable, &offx, &offy); - buffer = gimp_drawable_get_buffer (layer); + buffer = gimp_drawable_get_buffer (drawable); width = gegl_buffer_get_width (buffer); height = gegl_buffer_get_height (buffer); diff --git a/plug-ins/common/plugin-defs.pl b/plug-ins/common/plugin-defs.pl index 8ebc596881..5a032f3e1c 100644 --- a/plug-ins/common/plugin-defs.pl +++ b/plug-ins/common/plugin-defs.pl @@ -17,7 +17,7 @@ 'despeckle' => { ui => 1, gegl => 1 }, 'destripe' => { ui => 1, gegl => 1 }, 'file-aa' => { ui => 1, gegl => 1, optional => 1, libs => 'AA_LIBS', old_api => 1 }, - 'file-cel' => { ui => 1, gegl => 1, old_api => 1 }, + 'file-cel' => { ui => 1, gegl => 1 }, 'file-csource' => { ui => 1, gegl => 1 }, 'file-compressor' => { gio => 1, libdep => 'Z:BZIP2:LZMA', cflags => 'LZMA_CFLAGS' }, 'file-desktop-link' => { gio => 1 },