(Backport) Issue #491: Script-fu support for all BMP save features

This commit is contained in:
Nikc
2022-02-12 11:45:16 +00:00
committed by Jehan
parent 78f6812518
commit 1ce7888630
4 changed files with 93 additions and 13 deletions

View File

@ -77,6 +77,7 @@ static struct
/* Whether or not to write BITMAPV5HEADER color space data */ /* Whether or not to write BITMAPV5HEADER color space data */
gint dont_write_color_space_data; gint dont_write_color_space_data;
gboolean overwrite_RGB_format;
} BMPSaveData; } BMPSaveData;
@ -166,6 +167,7 @@ save_image (const gchar *filename,
BitsPerPixel = 32; BitsPerPixel = 32;
MapSize = 0; MapSize = 0;
channels = 4; channels = 4;
if (!BMPSaveData.overwrite_RGB_format)
BMPSaveData.rgb_format = RGBA_8888; BMPSaveData.rgb_format = RGBA_8888;
break; break;
@ -175,6 +177,7 @@ save_image (const gchar *filename,
BitsPerPixel = 24; BitsPerPixel = 24;
MapSize = 0; MapSize = 0;
channels = 3; channels = 3;
if (!BMPSaveData.overwrite_RGB_format)
BMPSaveData.rgb_format = RGB_888; BMPSaveData.rgb_format = RGB_888;
break; break;
@ -249,7 +252,11 @@ save_image (const gchar *filename,
g_assert_not_reached (); g_assert_not_reached ();
} }
/* Don't alter option data if already defined in non-interactive mode Script-fu */
if (BMPSaveData.use_run_length_encoding != 1)
BMPSaveData.use_run_length_encoding = 0; BMPSaveData.use_run_length_encoding = 0;
if (BMPSaveData.dont_write_color_space_data != 1)
BMPSaveData.dont_write_color_space_data = 0; BMPSaveData.dont_write_color_space_data = 0;
mask_info_size = 0; mask_info_size = 0;
@ -569,6 +576,27 @@ save_image (const gchar *filename,
return GIMP_PDB_SUCCESS; return GIMP_PDB_SUCCESS;
} }
/* Entry point for file-bmp-save2 */
GimpPDBStatusType
save_image2 (const gchar *filename,
gint32 image,
gint32 drawable_ID,
gint32 use_rle,
gint32 write_color_space,
gint32 rgb_format,
GimpRunMode run_mode,
GError **error)
{
BMPSaveData.use_run_length_encoding = use_rle;
BMPSaveData.dont_write_color_space_data = write_color_space;
BMPSaveData.rgb_format = (RGBMode) rgb_format;
/* Prevents save_image () from overwriting user's RGB format */
BMPSaveData.overwrite_RGB_format = TRUE;
return save_image (filename, image, drawable_ID,
run_mode, error);
}
static inline void static inline void
Make565 (guchar r, Make565 (guchar r,
guchar g, guchar g,

View File

@ -26,5 +26,14 @@ GimpPDBStatusType save_image (const gchar *filename,
GimpRunMode run_mode, GimpRunMode run_mode,
GError **error); GError **error);
GimpPDBStatusType save_image2 (const gchar *filename,
gint32 image,
gint32 drawable_ID,
gint32 use_rle,
gint32 write_color_space,
gint32 rgb_format,
GimpRunMode run_mode,
GError **error);
#endif /* __BMP_SAVE_H__ */ #endif /* __BMP_SAVE_H__ */

View File

@ -111,6 +111,18 @@ query (void)
{ GIMP_PDB_STRING, "raw-filename", "The name entered" }, { GIMP_PDB_STRING, "raw-filename", "The name entered" },
}; };
static const GimpParamDef save_args2[] =
{
{ 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 save" },
{ GIMP_PDB_STRING, "filename", "The name of the file to save the image in" },
{ GIMP_PDB_STRING, "raw-filename", "The name entered" },
{ GIMP_PDB_INT32, "use-rle", "Use run-length-encoding compression (only valid for 4 and 8-bit indexed images)" },
{ GIMP_PDB_INT32, "write-color-space", "Whether or not to write BITMAPV5HEADER color space data" },
{ GIMP_PDB_INT32, "rgb-format", "Export format for RGB images (0=RGB_565, 1=RGBA_5551, 2=RGB_555, 3=RGB_888, 4=RGBA_8888, 5=RGBX_8888)" },
};
gimp_install_procedure (LOAD_PROC, gimp_install_procedure (LOAD_PROC,
"Loads files of Windows BMP file format", "Loads files of Windows BMP file format",
"Loads files of Windows BMP file format", "Loads files of Windows BMP file format",
@ -144,6 +156,23 @@ query (void)
gimp_register_file_handler_mime (SAVE_PROC, "image/bmp"); gimp_register_file_handler_mime (SAVE_PROC, "image/bmp");
gimp_register_save_handler (SAVE_PROC, "bmp", ""); gimp_register_save_handler (SAVE_PROC, "bmp", "");
gimp_install_procedure (SAVE_PROC2,
"Saves files in Windows BMP file format",
"Saves files in Windows BMP file format, "
"with RLE, color space information, and RGB format "
"options available non-interactively",
"Alexander Schulz",
"Alexander Schulz",
"1997",
N_("Windows BMP image"),
"INDEXED, GRAY, RGB*",
GIMP_PLUGIN,
G_N_ELEMENTS (save_args2), 0,
save_args2, NULL);
gimp_register_file_handler_mime (SAVE_PROC2, "image/bmp");
gimp_register_save_handler (SAVE_PROC2, "bmp", "");
} }
static void static void
@ -203,7 +232,8 @@ run (const gchar *name,
} }
} }
} }
else if (strcmp (name, SAVE_PROC) == 0) else if (strcmp (name, SAVE_PROC) == 0 ||
strcmp (name, SAVE_PROC2) == 0)
{ {
gint32 image_ID = param[1].data.d_int32; gint32 image_ID = param[1].data.d_int32;
gint32 drawable_ID = param[2].data.d_int32; gint32 drawable_ID = param[2].data.d_int32;
@ -231,7 +261,8 @@ run (const gchar *name,
case GIMP_RUN_NONINTERACTIVE: case GIMP_RUN_NONINTERACTIVE:
/* Make sure all the arguments are there! */ /* Make sure all the arguments are there! */
if (nparams != 5) if ((strcmp (name, SAVE_PROC) == 0 && nparams != 5) ||
(strcmp (name, SAVE_PROC2) == 0 && nparams != 8))
status = GIMP_PDB_CALLING_ERROR; status = GIMP_PDB_CALLING_ERROR;
break; break;
@ -240,10 +271,21 @@ run (const gchar *name,
} }
if (status == GIMP_PDB_SUCCESS) if (status == GIMP_PDB_SUCCESS)
{
if (strcmp (name, SAVE_PROC) == 0)
status = save_image (param[3].data.d_string, status = save_image (param[3].data.d_string,
image_ID, drawable_ID, image_ID, drawable_ID,
run_mode, run_mode,
&error); &error);
else
status = save_image2 (param[3].data.d_string,
image_ID, drawable_ID,
param[5].data.d_int32,
param[6].data.d_int32,
param[7].data.d_int32,
run_mode,
&error);
}
if (export == GIMP_EXPORT_EXPORT) if (export == GIMP_EXPORT_EXPORT)
gimp_image_delete (image_ID); gimp_image_delete (image_ID);

View File

@ -22,6 +22,7 @@
#define LOAD_PROC "file-bmp-load" #define LOAD_PROC "file-bmp-load"
#define SAVE_PROC "file-bmp-save" #define SAVE_PROC "file-bmp-save"
#define SAVE_PROC2 "file-bmp-save2"
#define PLUG_IN_BINARY "file-bmp" #define PLUG_IN_BINARY "file-bmp"
#define PLUG_IN_ROLE "gimp-file-bmp" #define PLUG_IN_ROLE "gimp-file-bmp"