Commit b6b77fea authored by Michael Natterer's avatar Michael Natterer 😴

plug-ins: port file-bmp to GimpProcedureConfig and propwidgets

parent 68c35745
Pipeline #119042 passed with stages
in 12 minutes and 42 seconds
...@@ -53,30 +53,22 @@ typedef enum ...@@ -53,30 +53,22 @@ typedef enum
} RGBMode; } RGBMode;
static void write_image (FILE *f, static void write_image (FILE *f,
guchar *src, guchar *src,
gint width, gint width,
gint height, gint height,
gboolean use_run_length_encoding, gboolean use_run_length_encoding,
gint channels, gint channels,
gint bpp, gint bpp,
gint spzeile, gint spzeile,
gint MapSize, gint MapSize,
RGBMode rgb_format, RGBMode rgb_format,
gint mask_info_size, gint mask_info_size,
gint color_space_size); gint color_space_size);
static gboolean save_dialog (gint channels); static gboolean save_dialog (GimpProcedure *procedure,
GObject *config,
gint channels);
static struct
{
RGBMode rgb_format;
gboolean use_run_length_encoding;
/* Whether or not to write BITMAPV5HEADER color space data */
gboolean dont_write_color_space_data;
} BMPSaveData;
static void static void
...@@ -128,6 +120,8 @@ save_image (GFile *file, ...@@ -128,6 +120,8 @@ save_image (GFile *file,
GimpImage *image, GimpImage *image,
GimpDrawable *drawable, GimpDrawable *drawable,
GimpRunMode run_mode, GimpRunMode run_mode,
GimpProcedure *procedure,
GObject *config,
GError **error) GError **error)
{ {
gchar *filename; gchar *filename;
...@@ -144,13 +138,16 @@ save_image (GFile *file, ...@@ -144,13 +138,16 @@ save_image (GFile *file,
guchar *pixels; guchar *pixels;
GeglBuffer *buffer; GeglBuffer *buffer;
const Babl *format; const Babl *format;
GimpImageType drawable_type; GimpImageType drawable_type;
gint drawable_width; gint drawable_width;
gint drawable_height; gint drawable_height;
gint i; gint i;
gint mask_info_size; gint mask_info_size;
gint color_space_size; gint color_space_size;
guint32 Mask[4]; guint32 Mask[4];
gboolean use_rle;
gboolean write_color_space;
RGBMode rgb_format;
buffer = gimp_drawable_get_buffer (drawable); buffer = gimp_drawable_get_buffer (drawable);
...@@ -166,7 +163,10 @@ save_image (GFile *file, ...@@ -166,7 +163,10 @@ save_image (GFile *file,
BitsPerPixel = 32; BitsPerPixel = 32;
MapSize = 0; MapSize = 0;
channels = 4; channels = 4;
BMPSaveData.rgb_format = RGBA_8888;
g_object_set (config,
"rgb-format", RGBA_8888,
NULL);
break; break;
case GIMP_RGB_IMAGE: case GIMP_RGB_IMAGE:
...@@ -175,7 +175,10 @@ save_image (GFile *file, ...@@ -175,7 +175,10 @@ save_image (GFile *file,
BitsPerPixel = 24; BitsPerPixel = 24;
MapSize = 0; MapSize = 0;
channels = 3; channels = 3;
BMPSaveData.rgb_format = RGB_888;
g_object_set (config,
"rgb-format", RGBA_8888,
NULL);
break; break;
case GIMP_GRAYA_IMAGE: case GIMP_GRAYA_IMAGE:
...@@ -249,21 +252,13 @@ save_image (GFile *file, ...@@ -249,21 +252,13 @@ save_image (GFile *file,
g_assert_not_reached (); g_assert_not_reached ();
} }
BMPSaveData.use_run_length_encoding = FALSE;
BMPSaveData.dont_write_color_space_data = FALSE;
mask_info_size = 0; mask_info_size = 0;
if (run_mode != GIMP_RUN_NONINTERACTIVE)
{
gimp_get_data (SAVE_PROC, &BMPSaveData);
}
if (run_mode == GIMP_RUN_INTERACTIVE && if (run_mode == GIMP_RUN_INTERACTIVE &&
(BitsPerPixel == 8 || (BitsPerPixel == 8 ||
BitsPerPixel == 4)) BitsPerPixel == 4))
{ {
if (! save_dialog (1)) if (! save_dialog (procedure, config, 1))
return GIMP_PDB_CANCEL; return GIMP_PDB_CANCEL;
} }
else if (BitsPerPixel == 24 || else if (BitsPerPixel == 24 ||
...@@ -271,12 +266,16 @@ save_image (GFile *file, ...@@ -271,12 +266,16 @@ save_image (GFile *file,
{ {
if (run_mode == GIMP_RUN_INTERACTIVE) if (run_mode == GIMP_RUN_INTERACTIVE)
{ {
if (! save_dialog (channels)) if (! save_dialog (procedure, config, channels))
return GIMP_PDB_CANCEL; return GIMP_PDB_CANCEL;
} }
g_object_get (config,
"rgb-format", &rgb_format,
NULL);
/* mask_info_size is only set to non-zero for 16- and 32-bpp */ /* mask_info_size is only set to non-zero for 16- and 32-bpp */
switch (BMPSaveData.rgb_format) switch (rgb_format)
{ {
case RGB_888: case RGB_888:
BitsPerPixel = 24; BitsPerPixel = 24;
...@@ -306,13 +305,15 @@ save_image (GFile *file, ...@@ -306,13 +305,15 @@ save_image (GFile *file,
} }
} }
gimp_set_data (SAVE_PROC, &BMPSaveData, sizeof (BMPSaveData)); g_object_get (config,
"use-rle", &use_rle,
"write-color-space-info", &write_color_space,
"rgb-format", &rgb_format,
NULL);
/* Let's begin the progress */
gimp_progress_init_printf (_("Exporting '%s'"), gimp_progress_init_printf (_("Exporting '%s'"),
gimp_file_get_utf8_name (file)); gimp_file_get_utf8_name (file));
/* Let's take some file */
filename = g_file_get_path (file); filename = g_file_get_path (file);
outfile = g_fopen (filename, "wb"); outfile = g_fopen (filename, "wb");
g_free (filename); g_free (filename);
...@@ -328,8 +329,8 @@ save_image (GFile *file, ...@@ -328,8 +329,8 @@ save_image (GFile *file,
/* fetch the image */ /* fetch the image */
pixels = g_new (guchar, drawable_width * drawable_height * channels); pixels = g_new (guchar, drawable_width * drawable_height * channels);
gegl_buffer_get (buffer, GEGL_RECTANGLE (0, 0, gegl_buffer_get (buffer,
drawable_width, drawable_height), 1.0, GEGL_RECTANGLE (0, 0, drawable_width, drawable_height), 1.0,
format, pixels, format, pixels,
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE); GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
...@@ -350,7 +351,7 @@ save_image (GFile *file, ...@@ -350,7 +351,7 @@ save_image (GFile *file,
else else
SpZeile = ((gint) (((Spcols * BitsPerPixel) / 8) / 4) + 1) * 4; SpZeile = ((gint) (((Spcols * BitsPerPixel) / 8) / 4) + 1) * 4;
if (! BMPSaveData.dont_write_color_space_data) if (write_color_space)
color_space_size = 68; color_space_size = 68;
else else
color_space_size = 0; color_space_size = 0;
...@@ -368,7 +369,7 @@ save_image (GFile *file, ...@@ -368,7 +369,7 @@ save_image (GFile *file,
bitmap_head.biPlanes = 1; bitmap_head.biPlanes = 1;
bitmap_head.biBitCnt = BitsPerPixel; bitmap_head.biBitCnt = BitsPerPixel;
if (! BMPSaveData.use_run_length_encoding) if (! use_rle)
{ {
if (mask_info_size > 0) if (mask_info_size > 0)
bitmap_head.biCompr = 3; /* BI_BITFIELDS */ bitmap_head.biCompr = 3; /* BI_BITFIELDS */
...@@ -393,6 +394,7 @@ save_image (GFile *file, ...@@ -393,6 +394,7 @@ save_image (GFile *file,
{ {
gdouble xresolution; gdouble xresolution;
gdouble yresolution; gdouble yresolution;
gimp_image_get_resolution (image, &xresolution, &yresolution); gimp_image_get_resolution (image, &xresolution, &yresolution);
if (xresolution > GIMP_MIN_RESOLUTION && if (xresolution > GIMP_MIN_RESOLUTION &&
...@@ -458,7 +460,7 @@ save_image (GFile *file, ...@@ -458,7 +460,7 @@ save_image (GFile *file,
if (mask_info_size > 0) if (mask_info_size > 0)
{ {
switch (BMPSaveData.rgb_format) switch (rgb_format)
{ {
default: default:
case RGB_888: case RGB_888:
...@@ -506,7 +508,7 @@ save_image (GFile *file, ...@@ -506,7 +508,7 @@ save_image (GFile *file,
Write (outfile, &Mask, mask_info_size); Write (outfile, &Mask, mask_info_size);
} }
if (! BMPSaveData.dont_write_color_space_data) if (write_color_space)
{ {
guint32 buf[0x11]; guint32 buf[0x11];
...@@ -549,9 +551,9 @@ save_image (GFile *file, ...@@ -549,9 +551,9 @@ save_image (GFile *file,
write_image (outfile, write_image (outfile,
pixels, cols, rows, pixels, cols, rows,
BMPSaveData.use_run_length_encoding, use_rle,
channels, BitsPerPixel, SpZeile, channels, BitsPerPixel, SpZeile,
MapSize, BMPSaveData.rgb_format, MapSize, rgb_format,
mask_info_size, color_space_size); mask_info_size, color_space_size);
/* ... and exit normally */ /* ... and exit normally */
...@@ -912,18 +914,53 @@ format_sensitive_callback (gint value, ...@@ -912,18 +914,53 @@ format_sensitive_callback (gint value,
}; };
} }
static gboolean static void
save_dialog (gint channels) config_notify (GObject *config,
const GParamSpec *pspec,
gpointer data)
{ {
GtkWidget *dialog; gint channels = GPOINTER_TO_INT (data);
GtkWidget *toggle; RGBMode format;
GtkWidget *vbox;
GtkWidget *frame; g_object_get (config,
GtkWidget *combo; "rgb-format", &format,
gboolean run; NULL);
switch (format)
{
case RGBA_5551:
case RGBA_8888:
if (channels != 4)
{
g_signal_handlers_block_by_func (config, config_notify, data);
g_object_set (config, "rgb-format", format - 1, NULL);
g_signal_handlers_unblock_by_func (config, config_notify, data);
}
break;
default:
break;
};
}
/* Dialog init */ static gboolean
dialog = gimp_export_dialog_new ("BMP", PLUG_IN_BINARY, SAVE_PROC); save_dialog (GimpProcedure *procedure,
GObject *config,
gint channels)
{
GtkWidget *dialog;
GtkWidget *toggle;
GtkWidget *vbox;
GtkWidget *frame;
GtkListStore *store;
GtkWidget *combo;
gboolean run;
dialog = gimp_procedure_dialog_new (procedure,
GIMP_PROCEDURE_CONFIG (config),
_("Export Image as BMP"));
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
...@@ -934,41 +971,30 @@ save_dialog (gint channels) ...@@ -934,41 +971,30 @@ save_dialog (gint channels)
gtk_widget_show (vbox); gtk_widget_show (vbox);
/* Run-Length Encoded */ /* Run-Length Encoded */
toggle = gtk_check_button_new_with_mnemonic (_("_Run-Length Encoded")); toggle = gimp_prop_check_button_new (config, "use-rle",
_("_Run-Length Encoded"));
gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
BMPSaveData.use_run_length_encoding);
gtk_widget_show (toggle);
if (channels > 1) if (channels > 1)
gtk_widget_set_sensitive (toggle, FALSE); gtk_widget_set_sensitive (toggle, FALSE);
g_signal_connect (toggle, "toggled",
G_CALLBACK (gimp_toggle_button_update),
&BMPSaveData.use_run_length_encoding);
/* Compatibility Options */ /* Compatibility Options */
frame = gimp_frame_new (_("Compatibility")); frame = gimp_frame_new (_("Compatibility"));
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame); gtk_widget_show (frame);
toggle = gtk_check_button_new_with_mnemonic (_("_Do not write color space information")); toggle = gimp_prop_check_button_new (config, "write-color-space-info",
_("_Write color space information"));
gimp_help_set_help_data (toggle, gimp_help_set_help_data (toggle,
_("Some applications can not read BMP images that " _("Some applications can not read BMP images that "
"include color space information. GIMP writes " "include color space information. GIMP writes "
"color space information by default. Enabling " "color space information by default. Disabling "
"this option will cause GIMP to not write color " "this option will cause GIMP to not write color "
"space information to the file."), "space information to the file."),
NULL); NULL);
gtk_container_add (GTK_CONTAINER (frame), toggle); gtk_container_add (GTK_CONTAINER (frame), toggle);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
BMPSaveData.dont_write_color_space_data);
gtk_widget_show (toggle);
g_signal_connect (toggle, "toggled", /* RGB Encoding Pptions */
G_CALLBACK (gimp_toggle_button_update),
&BMPSaveData.dont_write_color_space_data);
/* Advanced Options */
frame = gimp_frame_new (_("RGB Encoding")); frame = gimp_frame_new (_("RGB Encoding"));
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame); gtk_widget_show (frame);
...@@ -976,20 +1002,16 @@ save_dialog (gint channels) ...@@ -976,20 +1002,16 @@ save_dialog (gint channels)
if (channels < 3) if (channels < 3)
gtk_widget_set_sensitive (frame, FALSE); gtk_widget_set_sensitive (frame, FALSE);
combo = gimp_int_combo_box_new (_("16 bit (R5 G6 B5"), RGB_565, store = gimp_int_store_new (_("16 bit (R5 G6 B5"), RGB_565,
_("16 bit (A1 R5 G5 B5"), RGBA_5551, _("16 bit (A1 R5 G5 B5"), RGBA_5551,
_("16 bit (X1 R5 G5 B5"), RGB_555, _("16 bit (X1 R5 G5 B5"), RGB_555,
_("24 bit (R8 G8 B8)"), RGB_888, _("24 bit (R8 G8 B8)"), RGB_888,
_("32 bit (A8 R8 G8 B8)"), RGBA_8888, _("32 bit (A8 R8 G8 B8)"), RGBA_8888,
_("32 bit (X8 R8 G8 B8)"), RGBX_8888, _("32 bit (X8 R8 G8 B8)"), RGBX_8888,
NULL); NULL);
combo = gimp_prop_int_combo_box_new (config, "rgb-format",
GIMP_INT_STORE (store));
gtk_container_add (GTK_CONTAINER (frame), combo); gtk_container_add (GTK_CONTAINER (frame), combo);
gtk_widget_show (combo);
gimp_int_combo_box_connect (GIMP_INT_COMBO_BOX (combo),
BMPSaveData.rgb_format,
G_CALLBACK (gimp_int_combo_box_get_active),
&BMPSaveData.rgb_format, NULL);
gimp_int_combo_box_set_sensitivity (GIMP_INT_COMBO_BOX (combo), gimp_int_combo_box_set_sensitivity (GIMP_INT_COMBO_BOX (combo),
format_sensitive_callback, format_sensitive_callback,
...@@ -997,7 +1019,15 @@ save_dialog (gint channels) ...@@ -997,7 +1019,15 @@ save_dialog (gint channels)
gtk_widget_show (dialog); gtk_widget_show (dialog);
run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK); g_signal_connect (config, "notify::rgb-format",
G_CALLBACK (config_notify),
GINT_TO_POINTER (channels));
run = gimp_procedure_dialog_run (GIMP_PROCEDURE_DIALOG (dialog));
g_signal_handlers_disconnect_by_func (config,
config_notify,
GINT_TO_POINTER (channels));
gtk_widget_destroy (dialog); gtk_widget_destroy (dialog);
......
...@@ -24,6 +24,8 @@ GimpPDBStatusType save_image (GFile *file, ...@@ -24,6 +24,8 @@ GimpPDBStatusType save_image (GFile *file,
GimpImage *image, GimpImage *image,
GimpDrawable *drawable, GimpDrawable *drawable,
GimpRunMode run_mode, GimpRunMode run_mode,
GimpProcedure *procedure,
GObject *config,
GError **error); GError **error);
......
...@@ -187,6 +187,25 @@ bmp_create_procedure (GimpPlugIn *plug_in, ...@@ -187,6 +187,25 @@ bmp_create_procedure (GimpPlugIn *plug_in,
"image/bmp"); "image/bmp");
gimp_file_procedure_set_extensions (GIMP_FILE_PROCEDURE (procedure), gimp_file_procedure_set_extensions (GIMP_FILE_PROCEDURE (procedure),
"bmp"); "bmp");
GIMP_PROC_AUX_ARG_BOOLEAN (procedure, "use-rle",
"Use RLE",
"Use run-lengh-encoding",
FALSE,
G_PARAM_READWRITE);
GIMP_PROC_AUX_ARG_BOOLEAN (procedure, "write-color-space-info",
"Write color space information",
"Whether or not to write BITMAPV5HEADER "
"color space data",
TRUE,
G_PARAM_READWRITE);
GIMP_PROC_AUX_ARG_INT (procedure, "rgb-format",
"RGB format",
"Export format for RGB images",
0, 5, 3,
G_PARAM_READWRITE);
} }
return procedure; return procedure;
...@@ -231,13 +250,17 @@ bmp_save (GimpProcedure *procedure, ...@@ -231,13 +250,17 @@ bmp_save (GimpProcedure *procedure,
const GimpValueArray *args, const GimpValueArray *args,
gpointer run_data) gpointer run_data)
{ {
GimpPDBStatusType status = GIMP_PDB_SUCCESS; GimpProcedureConfig *config;
GimpExportReturn export = GIMP_EXPORT_CANCEL; GimpPDBStatusType status = GIMP_PDB_SUCCESS;
GError *error = NULL; GimpExportReturn export = GIMP_EXPORT_CANCEL;
GError *error = NULL;
INIT_I18N (); INIT_I18N ();
gegl_init (NULL, NULL); gegl_init (NULL, NULL);
config = gimp_procedure_create_config (procedure);
gimp_procedure_config_begin_run (config, image, run_mode, args);
switch (run_mode) switch (run_mode)
{ {
case GIMP_RUN_INTERACTIVE: case GIMP_RUN_INTERACTIVE:
...@@ -261,8 +284,12 @@ bmp_save (GimpProcedure *procedure, ...@@ -261,8 +284,12 @@ bmp_save (GimpProcedure *procedure,
} }
status = save_image (file, image, drawable, run_mode, status = save_image (file, image, drawable, run_mode,
procedure, G_OBJECT (config),
&error); &error);
gimp_procedure_config_end_run (config, status);
g_object_unref (config);
if (export == GIMP_EXPORT_EXPORT) if (export == GIMP_EXPORT_EXPORT)
gimp_image_delete (image); gimp_image_delete (image);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment