1998-03-17 09:39:40 +00:00
|
|
|
/* bmp.c */
|
2006-07-12 14:25:17 +00:00
|
|
|
/* Version 0.52 */
|
1999-11-03 18:47:35 +00:00
|
|
|
/* This is a File input and output filter for the */
|
2024-04-13 15:10:25 +00:00
|
|
|
/* Gimp. It loads and exports images in the */
|
|
|
|
/* windows(TM) bitmap format. */
|
1997-11-24 22:05:25 +00:00
|
|
|
/* Some Parts that deal with the interaction with */
|
2007-06-06 08:44:52 +00:00
|
|
|
/* GIMP are taken from the GIF plugin by */
|
1997-11-24 22:05:25 +00:00
|
|
|
/* Peter Mattis & Spencer Kimball and from the */
|
|
|
|
/* PCX plugin by Francisco Bustamante. */
|
|
|
|
/* */
|
|
|
|
/* Alexander.Schulz@stud.uni-karlsruhe.de */
|
|
|
|
|
1998-03-17 09:39:40 +00:00
|
|
|
/* Changes: 28.11.1997 Noninteractive operation */
|
|
|
|
/* 16.03.1998 Endian-independent!! */
|
2006-07-12 14:25:17 +00:00
|
|
|
/* 21.03.1998 Little Bug-fix */
|
1998-04-07 03:41:22 +00:00
|
|
|
/* 06.04.1998 Bugfix in Padding */
|
1998-04-11 22:07:00 +00:00
|
|
|
/* 11.04.1998 Arch. cleanup (-Wall) */
|
|
|
|
/* Parses gtkrc */
|
1998-04-27 16:16:23 +00:00
|
|
|
/* 14.04.1998 Another Bug in Padding */
|
1999-11-03 18:47:35 +00:00
|
|
|
/* 28.04.1998 RLE-Encoding rewritten */
|
|
|
|
/* 29.10.1998 Changes by Tor Lillqvist */
|
|
|
|
/* <tml@iki.fi> to support */
|
|
|
|
/* 16 and 32 bit images */
|
|
|
|
/* 28.11.1998 Bug in RLE-read-padding */
|
|
|
|
/* fixed. */
|
1999-12-19 12:20:38 +00:00
|
|
|
/* 19.12.1999 Resolution support added */
|
2000-05-06 01:38:32 +00:00
|
|
|
/* 06.05.2000 Overhaul for 16&24-bit */
|
|
|
|
/* plus better OS/2 code */
|
|
|
|
/* by njl195@zepler.org.uk */
|
2006-07-12 14:25:17 +00:00
|
|
|
/* 29.06.2006 Full support for 16/32 */
|
|
|
|
/* bits bitmaps and support */
|
|
|
|
/* for alpha channel */
|
|
|
|
/* by p.filiciak@zax.pl */
|
1999-11-03 18:47:35 +00:00
|
|
|
|
2003-11-06 15:27:05 +00:00
|
|
|
/*
|
2006-12-09 21:33:38 +00:00
|
|
|
* GIMP - The GNU Image Manipulation Program
|
1998-03-17 09:39:40 +00:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-17 22:28:01 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1998-03-17 09:39:40 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 22:28:01 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1998-03-17 09:39:40 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2018-07-11 23:27:07 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
1998-03-17 09:39:40 +00:00
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
1999-05-29 16:35:47 +00:00
|
|
|
#include "config.h"
|
2000-01-25 17:46:56 +00:00
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
#include <stdlib.h>
|
2000-01-25 17:46:56 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
#include "bmp.h"
|
2016-04-20 13:55:53 +01:00
|
|
|
#include "bmp-load.h"
|
2024-04-21 16:36:01 +02:00
|
|
|
#include "bmp-export.h"
|
2000-01-25 17:46:56 +00:00
|
|
|
|
1999-05-29 16:35:47 +00:00
|
|
|
#include "libgimp/stdplugins-intl.h"
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2005-03-04 13:23:32 +00:00
|
|
|
|
2019-08-24 17:26:00 +02:00
|
|
|
typedef struct _Bmp Bmp;
|
|
|
|
typedef struct _BmpClass BmpClass;
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2019-08-24 17:26:00 +02:00
|
|
|
struct _Bmp
|
|
|
|
{
|
|
|
|
GimpPlugIn parent_instance;
|
|
|
|
};
|
2016-04-20 13:55:53 +01:00
|
|
|
|
2019-08-24 17:26:00 +02:00
|
|
|
struct _BmpClass
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2019-08-24 17:26:00 +02:00
|
|
|
GimpPlugInClass parent_class;
|
1997-11-24 22:05:25 +00:00
|
|
|
};
|
|
|
|
|
2016-04-20 13:55:53 +01:00
|
|
|
|
2019-08-24 17:26:00 +02:00
|
|
|
#define BMP_TYPE (bmp_get_type ())
|
2023-10-18 18:29:37 +02:00
|
|
|
#define BMP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BMP_TYPE, Bmp))
|
2019-08-24 17:26:00 +02:00
|
|
|
|
|
|
|
GType bmp_get_type (void) G_GNUC_CONST;
|
|
|
|
|
2023-08-06 02:56:44 +02:00
|
|
|
static GList * bmp_query_procedures (GimpPlugIn *plug_in);
|
|
|
|
static GimpProcedure * bmp_create_procedure (GimpPlugIn *plug_in,
|
|
|
|
const gchar *name);
|
|
|
|
|
|
|
|
static GimpValueArray * bmp_load (GimpProcedure *procedure,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
GFile *file,
|
|
|
|
GimpMetadata *metadata,
|
|
|
|
GimpMetadataLoadFlags *flags,
|
|
|
|
GimpProcedureConfig *config,
|
|
|
|
gpointer run_data);
|
2024-04-13 15:10:25 +00:00
|
|
|
static GimpValueArray * bmp_export (GimpProcedure *procedure,
|
2023-08-06 02:56:44 +02:00
|
|
|
GimpRunMode run_mode,
|
|
|
|
GimpImage *image,
|
|
|
|
GFile *file,
|
2024-05-06 18:38:12 +00:00
|
|
|
GimpExportOptions *options,
|
2023-08-06 02:56:44 +02:00
|
|
|
GimpMetadata *metadata,
|
|
|
|
GimpProcedureConfig *config,
|
|
|
|
gpointer run_data);
|
2019-08-24 17:26:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (Bmp, bmp, GIMP_TYPE_PLUG_IN)
|
|
|
|
|
|
|
|
GIMP_MAIN (BMP_TYPE)
|
2022-05-26 00:59:36 +02:00
|
|
|
DEFINE_STD_SET_I18N
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2016-04-20 13:55:53 +01:00
|
|
|
|
1997-11-24 22:05:25 +00:00
|
|
|
static void
|
2019-08-24 17:26:00 +02:00
|
|
|
bmp_class_init (BmpClass *klass)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2019-08-24 17:26:00 +02:00
|
|
|
GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
|
|
|
|
|
|
|
|
plug_in_class->query_procedures = bmp_query_procedures;
|
|
|
|
plug_in_class->create_procedure = bmp_create_procedure;
|
2022-05-26 00:59:36 +02:00
|
|
|
plug_in_class->set_i18n = STD_SET_I18N;
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-08-24 17:26:00 +02:00
|
|
|
bmp_init (Bmp *bmp)
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2019-08-24 17:26:00 +02:00
|
|
|
}
|
2003-11-06 15:27:05 +00:00
|
|
|
|
2019-08-24 17:26:00 +02:00
|
|
|
static GList *
|
|
|
|
bmp_query_procedures (GimpPlugIn *plug_in)
|
|
|
|
{
|
|
|
|
GList *list = NULL;
|
2012-09-21 19:18:34 +02:00
|
|
|
|
2019-08-24 17:26:00 +02:00
|
|
|
list = g_list_append (list, g_strdup (LOAD_PROC));
|
2024-04-13 15:10:25 +00:00
|
|
|
list = g_list_append (list, g_strdup (EXPORT_PROC));
|
2003-03-25 16:38:19 +00:00
|
|
|
|
2019-08-24 17:26:00 +02:00
|
|
|
return list;
|
|
|
|
}
|
2012-11-27 20:58:05 +01:00
|
|
|
|
2019-08-24 17:26:00 +02:00
|
|
|
static GimpProcedure *
|
|
|
|
bmp_create_procedure (GimpPlugIn *plug_in,
|
|
|
|
const gchar *name)
|
|
|
|
{
|
|
|
|
GimpProcedure *procedure = NULL;
|
1997-11-24 22:05:25 +00:00
|
|
|
|
2019-08-24 17:26:00 +02:00
|
|
|
if (! strcmp (name, LOAD_PROC))
|
1997-11-24 22:05:25 +00:00
|
|
|
{
|
2023-08-06 03:21:27 +02:00
|
|
|
procedure = gimp_load_procedure_new (plug_in, name,
|
|
|
|
GIMP_PDB_PROC_TYPE_PLUGIN,
|
|
|
|
bmp_load, NULL, NULL);
|
2019-08-24 17:26:00 +02:00
|
|
|
|
2022-07-04 22:50:53 +02:00
|
|
|
gimp_procedure_set_menu_label (procedure, _("Windows BMP image"));
|
2019-08-24 17:26:00 +02:00
|
|
|
|
|
|
|
gimp_procedure_set_documentation (procedure,
|
2023-03-21 02:52:15 +00:00
|
|
|
_("Loads files of Windows BMP file format"),
|
|
|
|
_("Loads files of Windows BMP file format"),
|
2019-08-24 17:26:00 +02:00
|
|
|
name);
|
|
|
|
gimp_procedure_set_attribution (procedure,
|
|
|
|
"Alexander Schulz",
|
|
|
|
"Alexander Schulz",
|
|
|
|
"1997");
|
|
|
|
|
|
|
|
gimp_file_procedure_set_mime_types (GIMP_FILE_PROCEDURE (procedure),
|
|
|
|
"image/bmp");
|
|
|
|
gimp_file_procedure_set_extensions (GIMP_FILE_PROCEDURE (procedure),
|
|
|
|
"bmp");
|
|
|
|
gimp_file_procedure_set_magics (GIMP_FILE_PROCEDURE (procedure),
|
|
|
|
"0,string,BM");
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|
2024-04-13 15:10:25 +00:00
|
|
|
else if (! strcmp (name, EXPORT_PROC))
|
2000-01-25 17:46:56 +00:00
|
|
|
{
|
2024-04-20 03:08:57 +00:00
|
|
|
procedure = gimp_export_procedure_new (plug_in, name,
|
|
|
|
GIMP_PDB_PROC_TYPE_PLUGIN,
|
|
|
|
FALSE, bmp_export, NULL, NULL);
|
2019-08-24 17:26:00 +02:00
|
|
|
|
|
|
|
gimp_procedure_set_image_types (procedure, "INDEXED, GRAY, RGB*");
|
|
|
|
|
2022-07-04 22:50:53 +02:00
|
|
|
gimp_procedure_set_menu_label (procedure, _("Windows BMP image"));
|
2023-03-21 02:52:15 +00:00
|
|
|
gimp_file_procedure_set_format_name (GIMP_FILE_PROCEDURE (procedure),
|
|
|
|
_("BMP"));
|
2019-08-24 17:26:00 +02:00
|
|
|
|
|
|
|
gimp_procedure_set_documentation (procedure,
|
2023-03-21 02:52:15 +00:00
|
|
|
_("Saves files in Windows BMP file format"),
|
|
|
|
_("Saves files in Windows BMP file format"),
|
2019-08-24 17:26:00 +02:00
|
|
|
name);
|
|
|
|
gimp_procedure_set_attribution (procedure,
|
|
|
|
"Alexander Schulz",
|
|
|
|
"Alexander Schulz",
|
|
|
|
"1997");
|
|
|
|
|
|
|
|
gimp_file_procedure_set_mime_types (GIMP_FILE_PROCEDURE (procedure),
|
|
|
|
"image/bmp");
|
|
|
|
gimp_file_procedure_set_extensions (GIMP_FILE_PROCEDURE (procedure),
|
|
|
|
"bmp");
|
2019-09-28 19:59:03 +02:00
|
|
|
|
2024-05-06 18:38:12 +00:00
|
|
|
gimp_export_procedure_set_capabilities (GIMP_EXPORT_PROCEDURE (procedure),
|
|
|
|
GIMP_EXPORT_CAN_HANDLE_RGB |
|
|
|
|
GIMP_EXPORT_CAN_HANDLE_GRAY |
|
|
|
|
GIMP_EXPORT_CAN_HANDLE_ALPHA |
|
|
|
|
GIMP_EXPORT_CAN_HANDLE_INDEXED,
|
app, libgimp*, pdb, plug-ins: review and enhance MR !1549.
- Fix annotations for gimp_export_options_get_image() to make it
actually introspectable with the GimpImage being both input and
output. Even though the logic doesn't change much (the input image may
be overriden or not), it doesn't matter for introspection because
images are handled centrally by libgimp and therefore must not be
freed. Actually deleting the image from the central list of images
though remains a manual action depending on code logic, not some
automatic action to be handled by binding engines.
- Add G_GNUC_WARN_UNUSED_RESULT to gimp_export_options_get_image()
because ignoring the returned value is rarely a good idea (as you
usually want to delete the image).
- Remove gimp_export_options_new(): we don't need this constructor
because at this point, the best is to tell plug-in developers to just
pass NULL everywhere. This leaves us free to create a more useful
default constructor if needed, in the future. Main description for
GimpExportOptions has also been updated to say this.
- Add a data_destroy callback for the user data passed in
gimp_export_procedure_set_capabilities().
- Fixing annotations of 'export_options' object from pdb/pdb.pl: input
args would actually be (nullable) and would not transfer ownership
(calling code must still free the object). Return value's ownership on
the other hand is fully transfered.
- Add C and Python unit testing for GimpExportOptions and
gimp_export_options_get_image() in particular.
- Fix or improve various details.
Note that I have also considered for a long time changing the signature
of gimp_export_options_get_image() to return a boolean indicating
whether `image` had been replaced (hence needed deletion) or not. This
also meant getting rid of the GimpExportReturn enum. Right now it would
work because there are no third case, but I was considering the future
possibility that for instance we got some impossible conversion for some
future capability. I'm not sure it would ever happen; and for sure, this
is not desirable because it implies an export failure a bit late in the
workflow. But just in case, let's keep the enum return value. It does
not even make the using code that much more complicated (well just a
value comparison instead of a simple boolean test).
2024-08-17 15:06:27 +02:00
|
|
|
NULL, NULL, NULL);
|
2024-05-06 18:38:12 +00:00
|
|
|
|
2024-06-12 16:53:12 +00:00
|
|
|
gimp_procedure_add_boolean_argument (procedure, "use-rle",
|
|
|
|
_("Ru_n-Length Encoded"),
|
|
|
|
_("Use run-length-encoding compression "
|
|
|
|
"(only valid for 4 and 8-bit indexed images)"),
|
|
|
|
FALSE,
|
|
|
|
G_PARAM_READWRITE);
|
|
|
|
|
|
|
|
gimp_procedure_add_boolean_argument (procedure, "write-color-space",
|
|
|
|
_("_Write color space information"),
|
|
|
|
_("Whether or not to write BITMAPV5HEADER "
|
|
|
|
"color space data"),
|
|
|
|
TRUE,
|
|
|
|
G_PARAM_READWRITE);
|
|
|
|
|
2024-08-19 14:40:46 +00:00
|
|
|
gimp_procedure_add_choice_argument (procedure, "rgb-format",
|
|
|
|
_("R_GB format"),
|
|
|
|
_("Export format for RGB images"),
|
|
|
|
gimp_choice_new_with_values ("rgb-565", RGB_565, _("16 bit (R5 G6 B5)"), NULL,
|
|
|
|
"rgba-5551", RGBA_5551, _("16 bit (A1 R5 G5 B5)"), NULL,
|
|
|
|
"rgb-555", RGB_555, _("16 bit (X1 R5 G5 B5)"), NULL,
|
|
|
|
"rgb-888", RGB_888, _("24 bit (R8 G8 B8)"), NULL,
|
|
|
|
"rgba-8888", RGBA_8888, _("32 bit (A8 R8 G8 B8)"), NULL,
|
2024-08-20 12:50:49 +00:00
|
|
|
"rgbx-8888", RGBX_8888, _("32 bit (X8 R8 G8 B8)"), NULL,
|
2024-08-19 14:40:46 +00:00
|
|
|
NULL),
|
|
|
|
"rgb-888",
|
|
|
|
G_PARAM_READWRITE);
|
2000-01-25 17:46:56 +00:00
|
|
|
}
|
|
|
|
|
2019-08-24 17:26:00 +02:00
|
|
|
return procedure;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GimpValueArray *
|
2023-08-06 02:56:44 +02:00
|
|
|
bmp_load (GimpProcedure *procedure,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
GFile *file,
|
|
|
|
GimpMetadata *metadata,
|
|
|
|
GimpMetadataLoadFlags *flags,
|
|
|
|
GimpProcedureConfig *config,
|
|
|
|
gpointer run_data)
|
2019-08-24 17:26:00 +02:00
|
|
|
{
|
|
|
|
GimpValueArray *return_vals;
|
|
|
|
GimpImage *image;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
gegl_init (NULL, NULL);
|
|
|
|
|
2019-09-11 21:48:34 +02:00
|
|
|
image = load_image (file, &error);
|
2019-08-24 17:26:00 +02:00
|
|
|
|
|
|
|
if (! image)
|
|
|
|
return gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_EXECUTION_ERROR,
|
|
|
|
error);
|
|
|
|
|
|
|
|
return_vals = gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_SUCCESS,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
GIMP_VALUES_SET_IMAGE (return_vals, 1, image);
|
|
|
|
|
|
|
|
return return_vals;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GimpValueArray *
|
2024-04-13 15:10:25 +00:00
|
|
|
bmp_export (GimpProcedure *procedure,
|
|
|
|
GimpRunMode run_mode,
|
|
|
|
GimpImage *image,
|
|
|
|
GFile *file,
|
2024-05-06 18:38:12 +00:00
|
|
|
GimpExportOptions *options,
|
2024-04-13 15:10:25 +00:00
|
|
|
GimpMetadata *metadata,
|
|
|
|
GimpProcedureConfig *config,
|
|
|
|
gpointer run_data)
|
2019-08-24 17:26:00 +02:00
|
|
|
{
|
2023-07-21 18:08:00 +02:00
|
|
|
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
2024-04-30 04:25:51 +00:00
|
|
|
GimpExportReturn export = GIMP_EXPORT_IGNORE;
|
2024-04-30 13:50:24 +00:00
|
|
|
GList *drawables;
|
|
|
|
GError *error = NULL;
|
2019-08-24 17:26:00 +02:00
|
|
|
|
|
|
|
gegl_init (NULL, NULL);
|
|
|
|
|
2024-07-14 20:12:57 +00:00
|
|
|
if (run_mode == GIMP_RUN_INTERACTIVE)
|
|
|
|
gimp_ui_init (PLUG_IN_BINARY);
|
|
|
|
|
2024-05-06 18:38:12 +00:00
|
|
|
export = gimp_export_options_get_image (options, &image);
|
2024-04-30 13:50:24 +00:00
|
|
|
drawables = gimp_image_list_layers (image);
|
2008-08-19 06:27:32 +00:00
|
|
|
|
2024-04-30 13:50:24 +00:00
|
|
|
status = export_image (file, image, drawables->data, run_mode,
|
2024-04-13 15:10:25 +00:00
|
|
|
procedure, G_OBJECT (config),
|
|
|
|
&error);
|
2019-08-24 17:26:00 +02:00
|
|
|
|
|
|
|
if (export == GIMP_EXPORT_EXPORT)
|
2024-04-30 13:50:24 +00:00
|
|
|
gimp_image_delete (image);
|
2019-08-24 17:26:00 +02:00
|
|
|
|
2024-04-30 13:50:24 +00:00
|
|
|
g_list_free (drawables);
|
2019-08-24 17:26:00 +02:00
|
|
|
return gimp_procedure_new_return_values (procedure, status, error);
|
1997-11-24 22:05:25 +00:00
|
|
|
}
|