Issue #12816: fix custom procedure config parasite.

It was broken in 2 ways:

- The parasite name was wrong, first because it used the old -save name
  instead of the new -export name, but also because the prefix was
  wrong. Since it is hard to automatize correctly having the correct
  name (if this changes again), I left a quite exhaustive comment for
  future people to easily retrieve where it is used.
- The format for the compression argument was wrong (it is now a
  GimpChoice arg, which is serialized as a string).
This commit is contained in:
Jehan 2025-10-23 19:34:03 +02:00
parent 0ff960c45b
commit 492f61e4c1
4 changed files with 54 additions and 14 deletions

View file

@ -1212,12 +1212,29 @@ load_image (GimpProcedure *procedure,
writer = gimp_config_writer_new_from_string (string);
gimp_config_writer_open (writer, "compression");
gimp_config_writer_printf (writer, "%d", gimp_compression);
gimp_config_writer_string (writer, gimp_compression_to_nick (gimp_compression));
gimp_config_writer_close (writer);
gimp_config_writer_finish (writer, NULL, NULL);
parasite = gimp_parasite_new ("GimpProcedureConfig-file-tiff-save-last",
/* This parasite name is kinda feeble and it is hard to
* automatize in a robust way since it depends on code private
* to libgimp:
*
* 1. The first part is the config type name as returned by
* hidden _gimp_procedure_create_run_config(), which is
* usually "GimpProcedureConfigRun-" followed by the
* procedure name. Note that this is different from the type
* name of the config returned by
* gimp_procedure_create_config().
* 2. Then "-last" is appended per private function
* gimp_procedure_config_parasite_name().
*
* So we just recreate it manually hoping it won't break.
* Hopefully it should not since it would break usual settings
* remembrance (in parasite, as well as config files) anyway.
*/
parasite = gimp_parasite_new ("GimpProcedureConfigRun-" EXPORT_PROC "-last",
GIMP_PARASITE_PERSISTENT,
string->len + 1, string->str);
gimp_image_attach_parasite (*image, parasite);

View file

@ -22,7 +22,6 @@
#ifndef __FILE_TIFF_LOAD_H__
#define __FILE_TIFF_LOAD_H__
#define LOAD_PROC "file-tiff-load"
typedef enum
{

View file

@ -57,7 +57,6 @@
#include "libgimp/stdplugins-intl.h"
#define EXPORT_PROC "file-tiff-export"
#define PLUG_IN_BINARY "file-tiff"
@ -67,6 +66,8 @@ typedef struct _TiffClass TiffClass;
struct _Tiff
{
GimpPlugIn parent_instance;
GimpChoice *compression_choice;
};
struct _TiffClass
@ -136,6 +137,14 @@ tiff_class_init (TiffClass *klass)
static void
tiff_init (Tiff *tiff)
{
tiff->compression_choice = gimp_choice_new_with_values ("none", GIMP_COMPRESSION_NONE, _("None"), NULL,
"lzw", GIMP_COMPRESSION_LZW, _("LZW"), NULL,
"packbits", GIMP_COMPRESSION_PACKBITS, _("Pack Bits"), NULL,
"adobe_deflate", GIMP_COMPRESSION_ADOBE_DEFLATE, _("Deflate"), NULL,
"jpeg", GIMP_COMPRESSION_JPEG, _("JPEG"), NULL,
"ccittfax3", GIMP_COMPRESSION_CCITTFAX3, _("CCITT Group 3 fax"), NULL,
"ccittfax4", GIMP_COMPRESSION_CCITTFAX4, _("CCITT Group 4 fax"), NULL,
NULL);
}
static GList *
@ -154,6 +163,7 @@ tiff_create_procedure (GimpPlugIn *plug_in,
const gchar *name)
{
GimpProcedure *procedure = NULL;
Tiff *tiff = TIFF (plug_in);
if (! strcmp (name, LOAD_PROC))
{
@ -244,14 +254,7 @@ tiff_create_procedure (GimpPlugIn *plug_in,
gimp_procedure_add_choice_argument (procedure, "compression",
_("Co_mpression"),
_("Compression type"),
gimp_choice_new_with_values ("none", GIMP_COMPRESSION_NONE, _("None"), NULL,
"lzw", GIMP_COMPRESSION_LZW, _("LZW"), NULL,
"packbits", GIMP_COMPRESSION_PACKBITS, _("Pack Bits"), NULL,
"adobe_deflate", GIMP_COMPRESSION_ADOBE_DEFLATE, _("Deflate"), NULL,
"jpeg", GIMP_COMPRESSION_JPEG, _("JPEG"), NULL,
"ccittfax3", GIMP_COMPRESSION_CCITTFAX3, _("CCITT Group 3 fax"), NULL,
"ccittfax4", GIMP_COMPRESSION_CCITTFAX4, _("CCITT Group 4 fax"), NULL,
NULL),
tiff->compression_choice,
"none", G_PARAM_READWRITE);
gimp_procedure_add_boolean_argument (procedure, "save-transparent-pixels",
@ -580,3 +583,21 @@ tiff_compression_to_gimp_compression (gint compression)
return GIMP_COMPRESSION_NONE;
}
const gchar *
gimp_compression_to_nick (GimpCompression compression)
{
GList *nicks;
GimpPlugIn *plug_in = gimp_get_plug_in ();
Tiff *tiff = TIFF (plug_in);
nicks = gimp_choice_list_nicks (tiff->compression_choice);
for (GList *iter = nicks; iter; iter = iter->next)
{
if (gimp_choice_get_id (tiff->compression_choice, iter->data) == compression)
return iter->data;
}
return "none";
}

View file

@ -5,6 +5,8 @@
#ifndef __FILE_TIFF_H__
#define __FILE_TIFF_H__
#define LOAD_PROC "file-tiff-load"
#define EXPORT_PROC "file-tiff-export"
typedef enum
{
@ -18,8 +20,9 @@ typedef enum
} GimpCompression;
gint gimp_compression_to_tiff_compression (GimpCompression compression);
GimpCompression tiff_compression_to_gimp_compression (gint compression);
gint gimp_compression_to_tiff_compression (GimpCompression compression);
GimpCompression tiff_compression_to_gimp_compression (gint compression);
const gchar * gimp_compression_to_nick (GimpCompression compression);
#endif /* __FILE_TIFF_H__ */