1998-03-17 17:39:40 +08:00
|
|
|
/* bmp.c */
|
2006-07-12 22:25:17 +08:00
|
|
|
/* Version 0.52 */
|
1999-11-04 02:47:35 +08:00
|
|
|
/* This is a File input and output filter for the */
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Gimp. It loads and saves images in windows(TM) */
|
|
|
|
/* bitmap format. */
|
|
|
|
/* Some Parts that deal with the interaction with */
|
2007-06-06 16:44:52 +08:00
|
|
|
/* GIMP are taken from the GIF plugin by */
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Peter Mattis & Spencer Kimball and from the */
|
|
|
|
/* PCX plugin by Francisco Bustamante. */
|
|
|
|
/* */
|
|
|
|
/* Alexander.Schulz@stud.uni-karlsruhe.de */
|
|
|
|
|
1998-03-17 17:39:40 +08:00
|
|
|
/* Changes: 28.11.1997 Noninteractive operation */
|
|
|
|
/* 16.03.1998 Endian-independent!! */
|
2006-07-12 22:25:17 +08:00
|
|
|
/* 21.03.1998 Little Bug-fix */
|
1998-04-07 11:41:22 +08:00
|
|
|
/* 06.04.1998 Bugfix in Padding */
|
1998-04-12 06:07:00 +08:00
|
|
|
/* 11.04.1998 Arch. cleanup (-Wall) */
|
|
|
|
/* Parses gtkrc */
|
1998-04-28 00:16:23 +08:00
|
|
|
/* 14.04.1998 Another Bug in Padding */
|
1999-11-04 02:47:35 +08: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 20:20:38 +08:00
|
|
|
/* 19.12.1999 Resolution support added */
|
2000-05-06 09:38:32 +08:00
|
|
|
/* 06.05.2000 Overhaul for 16&24-bit */
|
|
|
|
/* plus better OS/2 code */
|
|
|
|
/* by njl195@zepler.org.uk */
|
2006-07-12 22:25:17 +08:00
|
|
|
/* 29.06.2006 Full support for 16/32 */
|
|
|
|
/* bits bitmaps and support */
|
|
|
|
/* for alpha channel */
|
|
|
|
/* by p.filiciak@zax.pl */
|
1999-11-04 02:47:35 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
/*
|
2006-12-10 05:33:38 +08:00
|
|
|
* GIMP - The GNU Image Manipulation Program
|
1998-03-17 17:39:40 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1998-03-17 17:39:40 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
1998-03-17 17:39:40 +08: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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
1998-03-17 17:39:40 +08:00
|
|
|
* ----------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
1999-05-30 00:35:47 +08:00
|
|
|
#include "config.h"
|
2000-01-26 01:46:56 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <stdlib.h>
|
2000-01-26 01:46:56 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include "bmp.h"
|
2016-04-20 20:55:53 +08:00
|
|
|
#include "bmp-load.h"
|
|
|
|
#include "bmp-save.h"
|
2000-01-26 01:46:56 +08:00
|
|
|
|
1999-05-30 00:35:47 +08:00
|
|
|
#include "libgimp/stdplugins-intl.h"
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-03-04 21:23:32 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Declare some local functions.
|
|
|
|
*/
|
2003-07-02 23:23:47 +08:00
|
|
|
static void query (void);
|
|
|
|
static void run (const gchar *name,
|
|
|
|
gint nparams,
|
|
|
|
const GimpParam *param,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2016-04-20 20:55:53 +08:00
|
|
|
|
2006-05-16 20:26:20 +08:00
|
|
|
const GimpPlugInInfo PLUG_IN_INFO =
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-01-26 01:46:56 +08:00
|
|
|
NULL, /* init_proc */
|
|
|
|
NULL, /* quit_proc */
|
|
|
|
query, /* query_proc */
|
|
|
|
run, /* run_proc */
|
1997-11-25 06:05:25 +08:00
|
|
|
};
|
|
|
|
|
2016-04-20 20:55:53 +08:00
|
|
|
|
gimp-joke-980321
* app/iscissors.c, app/tips_dialog.c, app/gradient.c,
libgimp/gimp.c, plug-ins/AlienMap/AlienMap.c,
plug-ins/bmp/bmp.c, plug-ins/fits/fitsrw.h,
plug-ins/fits/fitsrw.c, plug-ins/flarefx/flarefx.c,
plug-ins/gfig/gfig.c, plug-ins/gfli/gfli.c,
plug-ins/gicon/gicon.c, plug-ins/gqbist/gqbist.c,
plug-ins/gtm/gtm.c, plug-ins/hot/hot.c,
plug-ins/ifscompose/ifscompose.c,
plug-ins/ifscompose/ifscompose_utils.c
plug-ins/max_rgb/max_rgb.c, plug-ins/nlfilt/nlfilt.c,
plug-ins/pat/pat.c, plug-ins/pcx/pcx.c, plug-ins/rotate/rotate.c,
plug-ins/script-fu/script-fu-server.c, plug-ins/snoise/snoise.c,
plug-ins/threshold_alpha/threshold_alpha.c,
plug-ins/zealouscrop/zealouscrop.c :gimp-joke-980321
plug-ins/CML_explorer, plug-ins/autocrop,
plug-ins/align_layers, plug-ins/blinds,
plug-ins/bmp, plug-ins/megawidget: gimp-joke-980322
Applied gimp-joke-980322-0.patch and gimp-joke-980321-0.patch
from Yasuhiro SHIRASAKI <joke@awa.tohoku.ac.jp>. Mostly
portability for DEC osf1's cc. Lots of MAIN();'s, trailing
commas in enums, and guchar/gchar madness.
Gimp now sends mail, cleans vinyl records,
removes stubborn stains, julien fries, and more!
-adrian
1998-03-23 04:44:39 +08:00
|
|
|
MAIN ()
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2016-04-20 20:55:53 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static void
|
2000-01-26 01:46:56 +08:00
|
|
|
query (void)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2006-05-16 20:26:20 +08:00
|
|
|
static const GimpParamDef load_args[] =
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2009-01-20 04:11:36 +08:00
|
|
|
{ GIMP_PDB_INT32, "run-mode", "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" },
|
2000-08-22 11:27:14 +08:00
|
|
|
{ GIMP_PDB_STRING, "filename", "The name of the file to load" },
|
2005-08-12 23:46:46 +08:00
|
|
|
{ GIMP_PDB_STRING, "raw-filename", "The name entered" },
|
1997-11-25 06:05:25 +08:00
|
|
|
};
|
2006-05-16 20:26:20 +08:00
|
|
|
static const GimpParamDef load_return_vals[] =
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2000-08-22 11:27:14 +08:00
|
|
|
{ GIMP_PDB_IMAGE, "image", "Output image" },
|
1997-11-25 06:05:25 +08:00
|
|
|
};
|
|
|
|
|
2006-05-16 20:26:20 +08:00
|
|
|
static const GimpParamDef save_args[] =
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2009-01-20 04:11:36 +08:00
|
|
|
{ GIMP_PDB_INT32, "run-mode", "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" },
|
2000-08-22 11:27:14 +08:00
|
|
|
{ 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" },
|
2005-08-12 23:46:46 +08:00
|
|
|
{ GIMP_PDB_STRING, "raw-filename", "The name entered" },
|
1997-11-25 06:05:25 +08:00
|
|
|
};
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2005-08-12 23:46:46 +08:00
|
|
|
gimp_install_procedure (LOAD_PROC,
|
2000-01-31 10:32:30 +08:00
|
|
|
"Loads files of Windows BMP file format",
|
|
|
|
"Loads files of Windows BMP file format",
|
1997-11-25 06:05:25 +08:00
|
|
|
"Alexander Schulz",
|
|
|
|
"Alexander Schulz",
|
|
|
|
"1997",
|
2004-05-14 08:01:11 +08:00
|
|
|
N_("Windows BMP image"),
|
1997-11-25 06:05:25 +08:00
|
|
|
NULL,
|
2000-08-22 11:27:14 +08:00
|
|
|
GIMP_PLUGIN,
|
2001-12-06 10:28:58 +08:00
|
|
|
G_N_ELEMENTS (load_args),
|
|
|
|
G_N_ELEMENTS (load_return_vals),
|
1997-11-25 06:05:25 +08:00
|
|
|
load_args, load_return_vals);
|
|
|
|
|
2005-08-12 23:46:46 +08:00
|
|
|
gimp_register_file_handler_mime (LOAD_PROC, "image/bmp");
|
|
|
|
gimp_register_magic_load_handler (LOAD_PROC,
|
2006-07-12 22:25:17 +08:00
|
|
|
"bmp",
|
|
|
|
"",
|
|
|
|
"0,string,BM");
|
2004-05-14 08:01:11 +08:00
|
|
|
|
2005-08-12 23:46:46 +08:00
|
|
|
gimp_install_procedure (SAVE_PROC,
|
2000-01-31 10:32:30 +08:00
|
|
|
"Saves files in Windows BMP file format",
|
|
|
|
"Saves files in Windows BMP file format",
|
1997-11-25 06:05:25 +08:00
|
|
|
"Alexander Schulz",
|
|
|
|
"Alexander Schulz",
|
|
|
|
"1997",
|
2004-05-14 08:01:11 +08:00
|
|
|
N_("Windows BMP image"),
|
2005-06-08 00:55:21 +08:00
|
|
|
"INDEXED, GRAY, RGB*",
|
2000-08-22 11:27:14 +08:00
|
|
|
GIMP_PLUGIN,
|
2001-12-06 10:28:58 +08:00
|
|
|
G_N_ELEMENTS (save_args), 0,
|
1997-11-25 06:05:25 +08:00
|
|
|
save_args, NULL);
|
|
|
|
|
2005-08-12 23:46:46 +08:00
|
|
|
gimp_register_file_handler_mime (SAVE_PROC, "image/bmp");
|
|
|
|
gimp_register_save_handler (SAVE_PROC, "bmp", "");
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-07-02 08:15:09 +08:00
|
|
|
run (const gchar *name,
|
2016-04-20 20:55:53 +08:00
|
|
|
gint nparams,
|
2003-07-02 08:15:09 +08:00
|
|
|
const GimpParam *param,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2008-08-19 14:27:32 +08:00
|
|
|
static GimpParam values[2];
|
|
|
|
GimpRunMode run_mode;
|
|
|
|
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
|
|
|
GError *error = NULL;
|
2003-11-06 23:27:05 +08:00
|
|
|
|
2012-11-28 03:58:05 +08:00
|
|
|
INIT_I18N ();
|
2012-09-22 01:18:34 +08:00
|
|
|
gegl_init (NULL, NULL);
|
|
|
|
|
2012-11-28 03:58:05 +08:00
|
|
|
run_mode = param[0].data.d_int32;
|
2003-03-26 00:38:19 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
*nreturn_vals = 1;
|
2000-01-26 01:46:56 +08:00
|
|
|
*return_vals = values;
|
2012-11-28 03:58:05 +08:00
|
|
|
|
2000-08-22 11:27:14 +08:00
|
|
|
values[0].type = GIMP_PDB_STATUS;
|
|
|
|
values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2005-08-12 23:46:46 +08:00
|
|
|
if (strcmp (name, LOAD_PROC) == 0)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2016-04-20 20:55:53 +08:00
|
|
|
switch (run_mode)
|
1998-03-17 17:39:40 +08:00
|
|
|
{
|
2000-08-22 11:27:14 +08:00
|
|
|
case GIMP_RUN_INTERACTIVE:
|
1998-03-17 17:39:40 +08:00
|
|
|
break;
|
|
|
|
|
2000-08-22 11:27:14 +08:00
|
|
|
case GIMP_RUN_NONINTERACTIVE:
|
1998-03-17 17:39:40 +08:00
|
|
|
/* Make sure all the arguments are there! */
|
2006-07-12 22:25:17 +08:00
|
|
|
if (nparams != 3)
|
2000-08-22 11:27:14 +08:00
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
1998-03-17 17:39:40 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-04-20 20:55:53 +08:00
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
|
|
|
{
|
|
|
|
gint32 image_ID = load_image (param[1].data.d_string,
|
|
|
|
&error);
|
|
|
|
|
|
|
|
if (image_ID != -1)
|
|
|
|
{
|
|
|
|
*nreturn_vals = 2;
|
|
|
|
values[1].type = GIMP_PDB_IMAGE;
|
|
|
|
values[1].data.d_image = image_ID;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
|
|
|
}
|
|
|
|
}
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2005-08-12 23:46:46 +08:00
|
|
|
else if (strcmp (name, SAVE_PROC) == 0)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2016-04-20 20:55:53 +08:00
|
|
|
gint32 image_ID = param[1].data.d_int32;
|
|
|
|
gint32 drawable_ID = param[2].data.d_int32;
|
|
|
|
GimpExportReturn export = GIMP_EXPORT_CANCEL;
|
1999-10-04 02:54:54 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
/* eventually export the image */
|
1999-10-04 02:54:54 +08:00
|
|
|
switch (run_mode)
|
2006-07-12 22:25:17 +08:00
|
|
|
{
|
|
|
|
case GIMP_RUN_INTERACTIVE:
|
|
|
|
case GIMP_RUN_WITH_LAST_VALS:
|
2008-08-12 03:42:08 +08:00
|
|
|
gimp_ui_init (PLUG_IN_BINARY, FALSE);
|
2013-11-10 07:18:48 +08:00
|
|
|
|
|
|
|
export = gimp_export_image (&image_ID, &drawable_ID, "BMP",
|
|
|
|
GIMP_EXPORT_CAN_HANDLE_RGB |
|
|
|
|
GIMP_EXPORT_CAN_HANDLE_GRAY |
|
|
|
|
GIMP_EXPORT_CAN_HANDLE_ALPHA |
|
|
|
|
GIMP_EXPORT_CAN_HANDLE_INDEXED);
|
|
|
|
|
2006-07-12 22:25:17 +08:00
|
|
|
if (export == GIMP_EXPORT_CANCEL)
|
|
|
|
{
|
|
|
|
values[0].data.d_status = GIMP_PDB_CANCEL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-08-22 11:27:14 +08:00
|
|
|
case GIMP_RUN_NONINTERACTIVE:
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Make sure all the arguments are there! */
|
2006-07-12 22:25:17 +08:00
|
|
|
if (nparams != 5)
|
2000-08-22 11:27:14 +08:00
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
1997-11-25 06:05:25 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-08-22 11:27:14 +08:00
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
2016-04-20 20:55:53 +08:00
|
|
|
status = save_image (param[3].data.d_string,
|
|
|
|
image_ID, drawable_ID,
|
|
|
|
run_mode,
|
|
|
|
&error);
|
1999-10-04 02:54:54 +08:00
|
|
|
|
2000-08-24 22:17:34 +08:00
|
|
|
if (export == GIMP_EXPORT_EXPORT)
|
2006-07-12 22:25:17 +08:00
|
|
|
gimp_image_delete (image_ID);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
2000-01-26 01:46:56 +08:00
|
|
|
else
|
|
|
|
{
|
2000-08-22 11:27:14 +08:00
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
2000-01-26 01:46:56 +08:00
|
|
|
}
|
|
|
|
|
2008-08-19 14:27:32 +08:00
|
|
|
if (status != GIMP_PDB_SUCCESS && error)
|
|
|
|
{
|
|
|
|
*nreturn_vals = 2;
|
|
|
|
values[1].type = GIMP_PDB_STRING;
|
|
|
|
values[1].data.d_string = error->message;
|
|
|
|
}
|
|
|
|
|
2000-01-26 01:46:56 +08:00
|
|
|
values[0].data.d_status = status;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|