plug-ins: Port file-tiff-load to GimpProcedureDialog

Note that GimpPageSelector is still added
manually as there is no GimpProcedureDialog 
equivalent yet.
This commit is contained in:
Alx Sa 2024-05-31 04:34:51 +00:00
parent 583dfbd8a3
commit e9f2e9012f
3 changed files with 108 additions and 114 deletions

View file

@ -91,66 +91,67 @@ typedef enum
/* Declare some local functions */ /* Declare some local functions */
static GimpColorProfile * load_profile (TIFF *tif); static GimpColorProfile * load_profile (TIFF *tif);
static void load_rgba (TIFF *tif, static void load_rgba (TIFF *tif,
ChannelData *channel); ChannelData *channel);
static void load_contiguous (TIFF *tif, static void load_contiguous (TIFF *tif,
ChannelData *channel, ChannelData *channel,
const Babl *type, const Babl *type,
gushort bps, gushort bps,
gushort spp, gushort spp,
TiffColorMode tiff_mode, TiffColorMode tiff_mode,
gboolean is_signed, gboolean is_signed,
gint extra); gint extra);
static void load_separate (TIFF *tif, static void load_separate (TIFF *tif,
ChannelData *channel, ChannelData *channel,
const Babl *type, const Babl *type,
gushort bps, gushort bps,
gushort spp, gushort spp,
TiffColorMode tiff_mode, TiffColorMode tiff_mode,
gboolean is_signed, gboolean is_signed,
gint extra); gint extra);
static gboolean is_non_conformant_tiff (gushort photomet, static gboolean is_non_conformant_tiff (gushort photomet,
gushort spp); gushort spp);
static gushort get_extra_channels_count (gushort photomet, static gushort get_extra_channels_count (gushort photomet,
gushort spp, gushort spp,
gboolean alpha); gboolean alpha);
static void fill_bit2byte (TiffColorMode tiff_mode); static void fill_bit2byte (TiffColorMode tiff_mode);
static void fill_2bit2byte (TiffColorMode tiff_mode); static void fill_2bit2byte (TiffColorMode tiff_mode);
static void fill_4bit2byte (TiffColorMode tiff_mode); static void fill_4bit2byte (TiffColorMode tiff_mode);
static void convert_bit2byte (const guchar *src, static void convert_bit2byte (const guchar *src,
guchar *dest, guchar *dest,
gint width, gint width,
gint height); gint height);
static void convert_2bit2byte (const guchar *src, static void convert_2bit2byte (const guchar *src,
guchar *dest, guchar *dest,
gint width, gint width,
gint height); gint height);
static void convert_4bit2byte (const guchar *src, static void convert_4bit2byte (const guchar *src,
guchar *dest, guchar *dest,
gint width, gint width,
gint height); gint height);
static void convert_miniswhite (guchar *buffer, static void convert_miniswhite (guchar *buffer,
gint width, gint width,
gint height); gint height);
static void convert_int2uint (guchar *buffer, static void convert_int2uint (guchar *buffer,
gint bps, gint bps,
gint spp, gint spp,
gint width, gint width,
gint height, gint height,
gint stride); gint stride);
static gboolean load_dialog (const gchar *help_id, static gboolean load_dialog (GimpProcedure *procedure,
TiffSelectedPages *pages, GimpProcedureConfig *config,
const gchar *extra_message, TiffSelectedPages *pages,
DefaultExtra *default_extra); const gchar *extra_message,
DefaultExtra *default_extra);
static void tiff_dialog_show_reduced (GtkWidget *toggle, static void tiff_dialog_show_reduced (GtkWidget *toggle,
gpointer data); gpointer data);
@ -259,7 +260,8 @@ get_extra_channels_count (gushort photomet, gushort spp, gboolean alpha)
} }
GimpPDBStatusType GimpPDBStatusType
load_image (GFile *file, load_image (GimpProcedure *procedure,
GFile *file,
GimpRunMode run_mode, GimpRunMode run_mode,
GimpImage **image, GimpImage **image,
gboolean *resolution_loaded, gboolean *resolution_loaded,
@ -484,10 +486,10 @@ load_image (GFile *file,
pages.tif = tif; pages.tif = tif;
if (run_mode == GIMP_RUN_INTERACTIVE && if (run_mode == GIMP_RUN_INTERACTIVE &&
(pages.n_pages > 1 || extra_message) && (pages.n_pages > 1 || extra_message) &&
! load_dialog (LOAD_PROC, &pages, ! load_dialog (procedure, config, &pages, extra_message,
extra_message, &default_extra)) &default_extra))
{ {
TIFFClose (tif); TIFFClose (tif);
g_clear_pointer (&pages.pages, g_free); g_clear_pointer (&pages.pages, g_free);
@ -2530,47 +2532,38 @@ convert_int2uint (guchar *buffer,
} }
static gboolean static gboolean
load_dialog (const gchar *help_id, load_dialog (GimpProcedure *procedure,
TiffSelectedPages *pages, GimpProcedureConfig *config,
const gchar *extra_message, TiffSelectedPages *pages,
DefaultExtra *default_extra) const gchar *extra_message,
DefaultExtra *default_extra)
{ {
GtkWidget *dialog; GtkWidget *dialog;
GtkWidget *vbox; GtkWidget *vbox;
GtkWidget *show_reduced = NULL; GtkWidget *toggle = NULL;
GtkWidget *crop_option = NULL; GtkWidget *extra_radio = NULL;
GtkWidget *extra_radio = NULL;
gboolean run; gboolean run;
pages->selector = NULL; pages->selector = NULL;
dialog = gimp_dialog_new (_("Import from TIFF"), PLUG_IN_ROLE, dialog = gimp_procedure_dialog_new (procedure,
NULL, 0, GIMP_PROCEDURE_CONFIG (config),
gimp_standard_help_func, help_id, _("Import from TIFF"));
_("_Cancel"), GTK_RESPONSE_CANCEL, vbox = gimp_procedure_dialog_fill_box (GIMP_PROCEDURE_DIALOG (dialog), "tiff-vbox",
_("_Import"), GTK_RESPONSE_OK, "keep-empty-space", NULL);
NULL); gimp_procedure_dialog_fill (GIMP_PROCEDURE_DIALOG (dialog),
"tiff-vbox", NULL);
gimp_dialog_set_alternative_button_order (GTK_DIALOG (dialog), toggle = gtk_check_button_new_with_mnemonic (_("_Show reduced images"));
GTK_RESPONSE_OK, gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
GTK_RESPONSE_CANCEL,
-1);
gimp_window_set_transient (GTK_WINDOW (dialog));
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))),
vbox, TRUE, TRUE, 0);
show_reduced = gtk_check_button_new_with_mnemonic (_("_Show reduced images"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (show_reduced),
pages->show_reduced); pages->show_reduced);
gtk_box_pack_start (GTK_BOX (vbox), show_reduced, TRUE, TRUE, 0); gtk_widget_set_margin_bottom (toggle, 6);
gtk_box_pack_start (GTK_BOX (vbox), toggle, TRUE, TRUE, 0);
gtk_widget_set_visible (toggle, TRUE);
g_signal_connect (show_reduced, "toggled", g_signal_connect (toggle, "toggled",
G_CALLBACK (tiff_dialog_show_reduced), G_CALLBACK (tiff_dialog_show_reduced),
pages); pages);
@ -2580,6 +2573,7 @@ load_dialog (const gchar *help_id,
pages->selector = gimp_page_selector_new (); pages->selector = gimp_page_selector_new ();
gtk_widget_set_size_request (pages->selector, 300, 200); gtk_widget_set_size_request (pages->selector, 300, 200);
gtk_box_pack_start (GTK_BOX (vbox), pages->selector, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (vbox), pages->selector, TRUE, TRUE, 0);
gtk_widget_set_visible (pages->selector, TRUE);
gimp_page_selector_set_n_pages (GIMP_PAGE_SELECTOR (pages->selector), gimp_page_selector_set_n_pages (GIMP_PAGE_SELECTOR (pages->selector),
pages->n_filtered_pages); pages->n_filtered_pages);
@ -2589,20 +2583,11 @@ load_dialog (const gchar *help_id,
/* Load a set number of pages, based on whether "Show Reduced Images" /* Load a set number of pages, based on whether "Show Reduced Images"
* is checked * is checked
*/ */
tiff_dialog_show_reduced (show_reduced, pages); tiff_dialog_show_reduced (toggle, pages);
g_signal_connect_swapped (pages->selector, "activate", g_signal_connect_swapped (pages->selector, "activate",
G_CALLBACK (gtk_window_activate_default), G_CALLBACK (gtk_window_activate_default),
dialog); dialog);
/* Option to shrink the loaded image to its bounding box
or keep as much empty space as possible.
Note that there seems to be no way to keep the empty
space on the right and bottom. */
crop_option = gtk_check_button_new_with_mnemonic (_("_Keep empty space around imported layers"));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (crop_option),
pages->keep_empty_space);
gtk_box_pack_start (GTK_BOX (vbox), crop_option, TRUE, TRUE, 0);
} }
if (extra_message) if (extra_message)
@ -2614,7 +2599,7 @@ load_dialog (const gchar *help_id,
"hint", extra_message, "hint", extra_message,
NULL); NULL);
gtk_box_pack_start (GTK_BOX (vbox), warning, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (vbox), warning, TRUE, TRUE, 0);
gtk_widget_show (warning); gtk_widget_set_visible (warning, TRUE);
extra_radio = gimp_int_radio_group_new (TRUE, _("Process extra channel as:"), extra_radio = gimp_int_radio_group_new (TRUE, _("Process extra channel as:"),
(GCallback) gimp_radio_button_update, (GCallback) gimp_radio_button_update,
@ -2624,19 +2609,29 @@ load_dialog (const gchar *help_id,
_("Channe_l"), GIMP_TIFF_LOAD_CHANNEL, NULL, _("Channe_l"), GIMP_TIFF_LOAD_CHANNEL, NULL,
NULL); NULL);
gtk_box_pack_start (GTK_BOX (vbox), extra_radio, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (vbox), extra_radio, TRUE, TRUE, 0);
gtk_widget_show (extra_radio); gtk_widget_set_visible (extra_radio, TRUE);
} }
toggle = gimp_procedure_dialog_get_widget (GIMP_PROCEDURE_DIALOG (dialog),
"keep-empty-space", G_TYPE_NONE);
gtk_widget_set_margin_top (toggle, 6);
gtk_widget_set_margin_bottom (toggle, 6);
gtk_box_reorder_child (GTK_BOX (vbox), toggle, -1);
/* Setup done; display the dialog */ /* Setup done; display the dialog */
gtk_widget_show_all (dialog); gtk_widget_set_visible (dialog, TRUE);
/* run the dialog */ /* run the dialog */
run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK); run = gimp_procedure_dialog_run (GIMP_PROCEDURE_DIALOG (dialog));
if (run) if (run)
{ {
if (pages->n_pages > 1) if (pages->n_pages > 1)
{ {
g_object_get (config,
"keep-empty-space", &pages->keep_empty_space,
NULL);
pages->target = pages->target =
gimp_page_selector_get_target (GIMP_PAGE_SELECTOR (pages->selector)); gimp_page_selector_get_target (GIMP_PAGE_SELECTOR (pages->selector));
@ -2644,9 +2639,6 @@ load_dialog (const gchar *help_id,
gimp_page_selector_get_selected_pages (GIMP_PAGE_SELECTOR (pages->selector), gimp_page_selector_get_selected_pages (GIMP_PAGE_SELECTOR (pages->selector),
&pages->n_pages); &pages->n_pages);
pages->keep_empty_space =
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (crop_option));
/* select all if none selected */ /* select all if none selected */
if (pages->n_pages == 0) if (pages->n_pages == 0)
{ {

View file

@ -46,7 +46,8 @@ typedef struct
} TiffSelectedPages; } TiffSelectedPages;
GimpPDBStatusType load_image (GFile *file, GimpPDBStatusType load_image (GimpProcedure *procedure,
GFile *file,
GimpRunMode run_mode, GimpRunMode run_mode,
GimpImage **image, GimpImage **image,
gboolean *resolution_loaded, gboolean *resolution_loaded,

View file

@ -158,9 +158,9 @@ tiff_create_procedure (GimpPlugIn *plug_in,
gimp_procedure_set_menu_label (procedure, _("TIFF or BigTIFF image")); gimp_procedure_set_menu_label (procedure, _("TIFF or BigTIFF image"));
gimp_procedure_set_documentation (procedure, gimp_procedure_set_documentation (procedure,
"Loads files of the TIFF and BigTIFF file formats", _("Loads files of the TIFF and BigTIFF file formats"),
"Loads files of the Tag Image File Format (TIFF) and " _("Loads files of the Tag Image File Format (TIFF) and "
"its 64-bit offsets variant (BigTIFF)", "its 64-bit offsets variant (BigTIFF)"),
name); name);
gimp_procedure_set_attribution (procedure, gimp_procedure_set_attribution (procedure,
"Spencer Kimball, Peter Mattis & Nick Lamb", "Spencer Kimball, Peter Mattis & Nick Lamb",
@ -204,10 +204,10 @@ tiff_create_procedure (GimpPlugIn *plug_in,
gimp_procedure_set_menu_label (procedure, _("TIFF or BigTIFF image")); gimp_procedure_set_menu_label (procedure, _("TIFF or BigTIFF image"));
gimp_procedure_set_documentation (procedure, gimp_procedure_set_documentation (procedure,
"Exports files in the TIFF or BigTIFF file formats", _("Exports files in the TIFF or BigTIFF file formats"),
"Exports files in the Tag Image File Format (TIFF) or " _("Exports files in the Tag Image File Format (TIFF) or "
"its 64-bit offsets variant (BigTIFF) able to support " "its 64-bit offsets variant (BigTIFF) able to support "
"much bigger file sizes", "much bigger file sizes"),
name); name);
gimp_procedure_set_attribution (procedure, gimp_procedure_set_attribution (procedure,
"Spencer Kimball & Peter Mattis", "Spencer Kimball & Peter Mattis",
@ -309,7 +309,8 @@ tiff_load (GimpProcedure *procedure,
if (run_mode == GIMP_RUN_INTERACTIVE) if (run_mode == GIMP_RUN_INTERACTIVE)
gimp_ui_init (PLUG_IN_BINARY); gimp_ui_init (PLUG_IN_BINARY);
status = load_image (file, run_mode, &image, status = load_image (procedure,
file, run_mode, &image,
&resolution_loaded, &resolution_loaded,
&profile_loaded, &profile_loaded,
&ps_metadata_loaded, &ps_metadata_loaded,
@ -473,7 +474,7 @@ tiff_export_rec (GimpProcedure *procedure,
tiff_reset_file_size_error (); tiff_reset_file_size_error ();
g_clear_error (error); g_clear_error (error);
return tiff_export_rec (procedure, run_mode, orig_image, return tiff_export_rec (procedure, run_mode, orig_image,
file, config, metadata, TRUE, error); file, config, metadata, TRUE, error);
} }