[gimp/bug-728633: 1/3] Bug 728633 - Improvements to the file-raw plugin.
- From: Michael Schumacher <schumaml src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/bug-728633: 1/3] Bug 728633 - Improvements to the file-raw plugin.
- Date: Mon, 13 Jun 2016 23:39:17 +0000 (UTC)
commit 2395e99a1b4d6c71042c2550695bbb030bb451bc
Author: Björn Kautler <Bjoern Kautler net>
Date: Mon Jun 13 22:43:41 2016 +0200
Bug 728633 - Improvements to the file-raw plugin.
Use GtkBuilder for raw image data export dialog.
plug-ins/common/file-raw-data.c | 221 ++++++++++++++++++++++++--------------
plug-ins/ui/Makefile.am | 1 +
plug-ins/ui/plug-in-file-raw.ui | 76 +++++++++++++
po-plug-ins/POTFILES.in | 1 +
4 files changed, 217 insertions(+), 82 deletions(-)
---
diff --git a/plug-ins/common/file-raw-data.c b/plug-ins/common/file-raw-data.c
index db38787..3a65b6d 100644
--- a/plug-ins/common/file-raw-data.c
+++ b/plug-ins/common/file-raw-data.c
@@ -96,58 +96,59 @@ typedef struct
} RawGimpData;
-static void query (void);
-static void run (const gchar *name,
- gint nparams,
- const GimpParam *param,
- gint *nreturn_vals,
- GimpParam **return_vals);
+static void query (void);
+static void run (const gchar *name,
+ gint nparams,
+ const GimpParam *param,
+ gint *nreturn_vals,
+ GimpParam **return_vals);
/* prototypes for the new load functions */
-static gboolean raw_load_standard (RawGimpData *data,
- gint bpp);
-static gboolean raw_load_gray (RawGimpData *data,
- gint bpp,
- gint bitspp);
-static gboolean raw_load_rgb565 (RawGimpData *data,
- RawType type);
-static gboolean raw_load_planar (RawGimpData *data);
-static gboolean raw_load_palette (RawGimpData *data,
- const gchar *palette_filename);
+static gboolean raw_load_standard (RawGimpData *data,
+ gint bpp);
+static gboolean raw_load_gray (RawGimpData *data,
+ gint bpp,
+ gint bitspp);
+static gboolean raw_load_rgb565 (RawGimpData *data,
+ RawType type);
+static gboolean raw_load_planar (RawGimpData *data);
+static gboolean raw_load_palette (RawGimpData *data,
+ const gchar *palette_filename);
/* support functions */
-static goffset get_file_info (const gchar *filename);
-static void raw_read_row (FILE *fp,
- guchar *buf,
- gint32 offset,
- gint32 size);
-static int mmap_read (gint fd,
- gpointer buf,
- gint32 len,
- gint32 pos,
- gint rowstride);
-static void rgb_565_to_888 (guint16 *in,
- guchar *out,
- gint32 num_pixels,
- RawType type);
-
-static gint32 load_image (const gchar *filename,
- GError **error);
-static GimpPDBStatusType save_image (const gchar *filename,
- gint32 image_id,
- gint32 drawable_id,
- GError **error);
+static goffset get_file_info (const gchar *filename);
+static void raw_read_row (FILE *fp,
+ guchar *buf,
+ gint32 offset,
+ gint32 size);
+static int mmap_read (gint fd,
+ gpointer buf,
+ gint32 len,
+ gint32 pos,
+ gint rowstride);
+static void rgb_565_to_888 (guint16 *in,
+ guchar *out,
+ gint32 num_pixels,
+ RawType type);
+
+static gint32 load_image (const gchar *filename,
+ GError **error);
+static GimpPDBStatusType save_image (const gchar *filename,
+ gint32 image_id,
+ gint32 drawable_id,
+ GError **error);
/* gui functions */
-static void preview_update_size (GimpPreviewArea *preview);
-static void preview_update (GimpPreviewArea *preview);
-static void palette_update (GimpPreviewArea *preview);
-static gboolean load_dialog (const gchar *filename);
-static gboolean save_dialog (const gchar *filename,
- gint32 image_id,
- gint32 drawable_id);
-static void palette_callback (GtkFileChooser *button,
- GimpPreviewArea *preview);
+static void preview_update_size (GimpPreviewArea *preview);
+static void preview_update (GimpPreviewArea *preview);
+static void palette_update (GimpPreviewArea *preview);
+static gboolean load_dialog (const gchar *filename);
+static gboolean save_dialog (gint32 image_id);
+static void save_dialog_response (GtkWidget *widget,
+ gint response_id,
+ gpointer data);
+static void palette_callback (GtkFileChooser *button,
+ GimpPreviewArea *preview);
static RawConfig *runtime = NULL;
@@ -337,8 +338,7 @@ run (const gchar *name,
{
status = GIMP_PDB_CALLING_ERROR;
}
- else if (! save_dialog (param[3].data.d_string,
- image_id, drawable_id))
+ else if (! save_dialog (image_id))
{
status = GIMP_PDB_CANCEL;
}
@@ -1549,57 +1549,114 @@ load_dialog (const gchar *filename)
return run;
}
+static GtkWidget *
+radio_button_init (GtkBuilder *builder,
+ const gchar *name,
+ gint item_data,
+ gint initial_value,
+ gpointer value_pointer)
+{
+ GtkWidget *radio = NULL;
+
+ radio = GTK_WIDGET (gtk_builder_get_object (builder, name));
+ if (item_data)
+ g_object_set_data (G_OBJECT (radio), "gimp-item-data", GINT_TO_POINTER (item_data));
+ if (initial_value == item_data)
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio), TRUE);
+ g_signal_connect (radio, "toggled",
+ G_CALLBACK (gimp_radio_button_update),
+ value_pointer);
+
+ return radio;
+}
+
static gboolean
-save_dialog (const gchar *filename,
- gint32 image_id,
- gint32 drawable_id)
+save_dialog (gint32 image_id)
{
- GtkWidget *dialog;
- GtkWidget *main_vbox;
- GtkWidget *frame;
+ GtkWidget *dialog;
+ GtkBuilder *builder;
+ gchar *ui_file;
gboolean run;
+ GError *error = NULL;
gimp_ui_init (PLUG_IN_BINARY, TRUE);
+ /* Dialog init */
dialog = gimp_export_dialog_new (_("Raw Image"), PLUG_IN_BINARY, SAVE_PROC);
+ g_signal_connect (dialog, "response",
+ G_CALLBACK (save_dialog_response),
+ &run);
+ g_signal_connect (dialog, "destroy",
+ G_CALLBACK (gtk_main_quit),
+ NULL);
+
+ /* GtkBuilder init */
+ builder = gtk_builder_new ();
+ ui_file = g_build_filename (gimp_data_directory (),
+ "ui/plug-ins/plug-in-file-raw.ui",
+ NULL);
+ if (! gtk_builder_add_from_file (builder, ui_file, &error))
+ {
+ gchar *display_name = g_filename_display_name (ui_file);
+ g_printerr (_("Error loading UI file '%s': %s"),
+ display_name, error ? error->message : _("Unknown error"));
+ g_free (display_name);
+ }
- main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
- gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
+ g_free (ui_file);
+
+ /* VBox */
gtk_box_pack_start (GTK_BOX (gimp_export_dialog_get_content_area (dialog)),
- main_vbox, FALSE, FALSE, 0);
- gtk_widget_show (main_vbox);
+ GTK_WIDGET (gtk_builder_get_object (builder, "vbox")),
+ FALSE, FALSE, 0);
+
+ /* Radios */
+ radio_button_init (builder, "image-type-standard",
+ RAW_RGB,
+ runtime->image_type,
+ &runtime->image_type);
+ radio_button_init (builder, "image-type-planar",
+ RAW_PLANAR,
+ runtime->image_type,
+ &runtime->image_type);
+ radio_button_init (builder, "palette-type-normal",
+ RAW_PALETTE_RGB,
+ runtime->palette_type,
+ &runtime->palette_type);
+ radio_button_init (builder, "palette-type-bmp",
+ RAW_PALETTE_BGR,
+ runtime->palette_type,
+ &runtime->palette_type);
+
+ /* Show dialog and run */
+ gtk_widget_show (dialog);
- frame = gimp_int_radio_group_new (TRUE, _("RGB Save Type"),
- G_CALLBACK (gimp_radio_button_update),
- &runtime->image_type,
- runtime->image_type,
- _("Standard (RGB RGB RGB ...)"), RAW_RGB, NULL,
- _("Planar (RRR... GGG... BBB...)"), RAW_PLANAR, NULL,
- NULL);
- gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
- gtk_widget_show (frame);
+ run = FALSE;
- frame = gimp_int_radio_group_new (TRUE, _("Indexed Palette Type"),
- G_CALLBACK (gimp_radio_button_update),
- &runtime->palette_type,
- runtime->palette_type,
- _("R, G, B (normal)"),
- RAW_PALETTE_RGB, NULL,
- _("B, G, R, X (BMP style)"),
- RAW_PALETTE_BGR, NULL,
- NULL);
- gtk_box_pack_start (GTK_BOX (main_vbox), frame, FALSE, FALSE, 0);
- gtk_widget_show (frame);
+ gtk_main ();
- gtk_widget_show (dialog);
+ return run;
+}
- run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
+static void
+save_dialog_response (GtkWidget *widget,
+ gint response_id,
+ gpointer data)
+{
+ gboolean *run = data;
- gtk_widget_destroy (dialog);
+ switch (response_id)
+ {
+ case GTK_RESPONSE_OK:
+ *run = TRUE;
- return run;
+ default:
+ gtk_widget_destroy (widget);
+ break;
+ }
}
+
static void
palette_callback (GtkFileChooser *button,
GimpPreviewArea *preview)
diff --git a/plug-ins/ui/Makefile.am b/plug-ins/ui/Makefile.am
index aec82b9..1b569f8 100644
--- a/plug-ins/ui/Makefile.am
+++ b/plug-ins/ui/Makefile.am
@@ -3,6 +3,7 @@ uidatadir = $(gimpdatadir)/ui/plug-ins
uidata_DATA = \
plug-in-file-gif.ui \
plug-in-file-png.ui \
+ plug-in-file-raw.ui \
plug-in-file-tiff.ui \
plug-in-metadata.ui
diff --git a/plug-ins/ui/plug-in-file-raw.ui b/plug-ins/ui/plug-in-file-raw.ui
new file mode 100644
index 0000000..18368f1
--- /dev/null
+++ b/plug-ins/ui/plug-in-file-raw.ui
@@ -0,0 +1,76 @@
+<?xml version="1.0"?>
+<interface>
+ <!-- interface-requires gtk+ 2.12 -->
+ <!-- interface-naming-policy project-wide -->
+ <object class="GtkVBox" id="vbox">
+ <property name="visible">True</property>
+ <property name="border_width">12</property>
+ <property name="spacing">12</property>
+ <child>
+ <object class="GimpFrame" id="image-type-frame">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">RGB Save Type</property>
+ <child>
+ <object class="GtkVBox" id="image-type-vbox">
+ <property name="visible">True</property>
+ <property name="spacing">2</property>
+ <child>
+ <object class="GtkRadioButton" id="image-type-standard">
+ <property name="label" translatable="yes">Standard (R,G,B)</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_underline">True</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkRadioButton" id="image-type-planar">
+ <property name="label" translatable="yes">Planar (RRR,GGG,BBB)</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_underline">True</property>
+ <property name="draw_indicator">True</property>
+ <property name="group">image-type-standard</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
+ <object class="GimpFrame" id="palette-type-frame">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">RGB Save Type</property>
+ <child>
+ <object class="GtkVBox" id="palette-type-vbox">
+ <property name="visible">True</property>
+ <property name="spacing">2</property>
+ <child>
+ <object class="GtkRadioButton" id="palette-type-normal">
+ <property name="label" translatable="yes">R, G, B (normal)</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_underline">True</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkRadioButton" id="palette-type-bmp">
+ <property name="label" translatable="yes">B, G, R, X (BMP style)</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_underline">True</property>
+ <property name="draw_indicator">True</property>
+ <property name="group">palette-type-normal</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+ </child>
+ </object>
+</interface>
diff --git a/po-plug-ins/POTFILES.in b/po-plug-ins/POTFILES.in
index 5de4885..c638c58 100644
--- a/po-plug-ins/POTFILES.in
+++ b/po-plug-ins/POTFILES.in
@@ -153,6 +153,7 @@ plug-ins/gimpressionist/sizemap.c
plug-ins/gimpressionist/utils.c
[type: gettext/glade]plug-ins/ui/plug-in-file-gif.ui
[type: gettext/glade]plug-ins/ui/plug-in-file-png.ui
+[type: gettext/glade]plug-ins/ui/plug-in-file-raw.ui
[type: gettext/glade]plug-ins/ui/plug-in-file-tiff.ui
[type: gettext/glade]plug-ins/ui/plug-in-metadata.ui
plug-ins/gradient-flare/gradient-flare.c
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]