2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1998-11-06 08:51:39 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2016-02-16 09:35:43 +08:00
|
|
|
* X10 and X11 bitmap (XBM) loading and exporting file filter for GIMP.
|
1998-11-06 08:51:39 +08:00
|
|
|
* XBM code Copyright (C) 1998 Gordon Matzigkeit
|
|
|
|
*
|
|
|
|
* The XBM reading and writing code was written from scratch by Gordon
|
|
|
|
* Matzigkeit <gord@gnu.org> based on the XReadBitmapFile(3X11) manual
|
|
|
|
* page distributed with X11R6 and by staring at valid XBM files. It
|
|
|
|
* does not contain any code written for other XBM file loaders.
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
1998-11-06 08:51:39 +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-11-06 08:51:39 +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-11-06 08:51:39 +08:00
|
|
|
|
|
|
|
/* Release 1.0, 1998-02-04, Gordon Matzigkeit <gord@gnu.org>:
|
|
|
|
* - Load and save X10 and X11 bitmaps.
|
|
|
|
* - Allow the user to specify the C identifier prefix.
|
|
|
|
*
|
|
|
|
* TODO:
|
|
|
|
* - Parsing is very tolerant, and the algorithms are quite hairy, so
|
|
|
|
* load_image should be carefully tested to make sure there are no XBM's
|
|
|
|
* that fail.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Set this for debugging. */
|
|
|
|
/* #define VERBOSE 2 */
|
|
|
|
|
1999-05-30 00:35:47 +08:00
|
|
|
#include "config.h"
|
2000-01-11 23:48:00 +08:00
|
|
|
|
2003-06-13 22:37:00 +08:00
|
|
|
#include <errno.h>
|
1998-11-06 08:51:39 +08:00
|
|
|
#include <string.h>
|
2000-01-11 23:48:00 +08:00
|
|
|
|
2005-03-04 23:12:29 +08:00
|
|
|
#include <glib/gstdio.h>
|
2000-01-11 23:48:00 +08:00
|
|
|
|
|
|
|
#include <libgimp/gimp.h>
|
|
|
|
#include <libgimp/gimpui.h>
|
|
|
|
|
1999-05-30 00:35:47 +08:00
|
|
|
#include "libgimp/stdplugins-intl.h"
|
1998-11-06 08:51:39 +08:00
|
|
|
|
2000-05-02 04:22:55 +08:00
|
|
|
|
2005-08-16 06:42:34 +08:00
|
|
|
#define LOAD_PROC "file-xbm-load"
|
|
|
|
#define SAVE_PROC "file-xbm-save"
|
2008-08-11 18:06:13 +08:00
|
|
|
#define PLUG_IN_BINARY "file-xbm"
|
2011-04-09 02:31:34 +08:00
|
|
|
#define PLUG_IN_ROLE "gimp-file-xbm"
|
2005-08-16 06:42:34 +08:00
|
|
|
|
|
|
|
|
1998-11-06 08:51:39 +08:00
|
|
|
/* Wear your GIMP with pride! */
|
|
|
|
#define DEFAULT_USE_COMMENT TRUE
|
2000-01-26 01:46:56 +08:00
|
|
|
#define MAX_COMMENT 72
|
2000-06-05 19:38:35 +08:00
|
|
|
#define MAX_MASK_EXT 32
|
1998-11-06 08:51:39 +08:00
|
|
|
|
|
|
|
/* C identifier prefix. */
|
|
|
|
#define DEFAULT_PREFIX "bitmap"
|
2006-06-17 01:38:01 +08:00
|
|
|
#define MAX_PREFIX 64
|
1998-11-06 08:51:39 +08:00
|
|
|
|
2016-02-16 09:35:43 +08:00
|
|
|
/* Whether or not to export as X10 bitmap. */
|
1998-11-06 08:51:39 +08:00
|
|
|
#define DEFAULT_X10_FORMAT FALSE
|
|
|
|
|
|
|
|
typedef struct _XBMSaveVals
|
|
|
|
{
|
2000-06-05 19:38:35 +08:00
|
|
|
gchar comment[MAX_COMMENT + 1];
|
|
|
|
gint x10_format;
|
|
|
|
gint use_hot;
|
|
|
|
gint x_hot;
|
|
|
|
gint y_hot;
|
|
|
|
gchar prefix[MAX_PREFIX + 1];
|
|
|
|
gboolean write_mask;
|
|
|
|
gchar mask_ext[MAX_MASK_EXT + 1];
|
1998-11-06 08:51:39 +08:00
|
|
|
} XBMSaveVals;
|
|
|
|
|
|
|
|
static XBMSaveVals xsvals =
|
|
|
|
{
|
2008-10-20 14:04:39 +08:00
|
|
|
"###", /* comment */
|
|
|
|
DEFAULT_X10_FORMAT, /* x10_format */
|
2000-03-04 08:24:39 +08:00
|
|
|
FALSE,
|
2008-10-20 14:04:39 +08:00
|
|
|
0, /* x_hot */
|
|
|
|
0, /* y_hot */
|
|
|
|
DEFAULT_PREFIX, /* prefix */
|
2000-06-05 19:38:35 +08:00
|
|
|
FALSE, /* write_mask */
|
2007-07-26 23:26:57 +08:00
|
|
|
"-mask"
|
1998-11-06 08:51:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Declare some local functions.
|
|
|
|
*/
|
2008-09-17 16:37:24 +08:00
|
|
|
static void query (void);
|
|
|
|
static void run (const gchar *name,
|
|
|
|
gint nparams,
|
|
|
|
const GimpParam *param,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals);
|
|
|
|
|
|
|
|
static gint32 load_image (const gchar *filename,
|
|
|
|
GError **error);
|
2014-10-06 00:06:03 +08:00
|
|
|
static gint save_image (GFile *file,
|
2008-09-17 16:37:24 +08:00
|
|
|
const gchar *prefix,
|
|
|
|
const gchar *comment,
|
|
|
|
gboolean save_mask,
|
|
|
|
gint32 image_ID,
|
|
|
|
gint32 drawable_ID,
|
|
|
|
GError **error);
|
|
|
|
static gboolean save_dialog (gint32 drawable_ID);
|
2014-10-06 00:06:03 +08:00
|
|
|
|
|
|
|
static gboolean print (GOutputStream *output,
|
|
|
|
GError **error,
|
|
|
|
const gchar *format,
|
|
|
|
...) G_GNUC_PRINTF (3, 4);
|
|
|
|
|
2002-11-08 03:09:01 +08:00
|
|
|
#if 0
|
|
|
|
/* DISABLED - see http://bugzilla.gnome.org/show_bug.cgi?id=82763 */
|
2008-09-17 16:37:24 +08:00
|
|
|
static void comment_entry_callback (GtkWidget *widget,
|
|
|
|
gpointer data);
|
2002-11-08 03:09:01 +08:00
|
|
|
#endif
|
2008-09-17 16:37:24 +08:00
|
|
|
static void prefix_entry_callback (GtkWidget *widget,
|
|
|
|
gpointer data);
|
|
|
|
static void mask_ext_entry_callback (GtkWidget *widget,
|
|
|
|
gpointer data);
|
2008-08-19 03:08:54 +08:00
|
|
|
|
2000-06-05 19:38:35 +08:00
|
|
|
|
2006-05-16 20:26:20 +08:00
|
|
|
const GimpPlugInInfo PLUG_IN_INFO =
|
1998-11-06 08:51:39 +08:00
|
|
|
{
|
2000-01-26 01:46:56 +08:00
|
|
|
NULL, /* init_proc */
|
|
|
|
NULL, /* quit_proc */
|
|
|
|
query, /* query_proc */
|
|
|
|
run, /* run_proc */
|
1998-11-06 08:51:39 +08:00
|
|
|
};
|
|
|
|
|
1999-04-27 12:57:59 +08:00
|
|
|
MAIN ()
|
1998-11-06 08:51:39 +08:00
|
|
|
|
|
|
|
#ifdef VERBOSE
|
|
|
|
static int verbose = VERBOSE;
|
|
|
|
#endif
|
|
|
|
|
2008-08-19 03:08:54 +08:00
|
|
|
|
1998-11-06 08:51:39 +08:00
|
|
|
static void
|
2000-01-26 01:46:56 +08:00
|
|
|
query (void)
|
1998-11-06 08:51:39 +08:00
|
|
|
{
|
2006-05-16 20:26:20 +08:00
|
|
|
static const GimpParamDef load_args[] =
|
1998-11-06 08:51:39 +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 09:26:57 +08:00
|
|
|
{ GIMP_PDB_STRING, "filename", "The name of the file to load" },
|
2005-08-16 06:42:34 +08:00
|
|
|
{ GIMP_PDB_STRING, "raw-filename", "The name entered" }
|
1998-11-06 08:51:39 +08:00
|
|
|
};
|
2000-05-02 04:22:55 +08:00
|
|
|
|
2006-05-16 20:26:20 +08:00
|
|
|
static const GimpParamDef load_return_vals[] =
|
1998-11-06 08:51:39 +08:00
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
{ GIMP_PDB_IMAGE, "image", "Output image" }
|
1998-11-06 08:51:39 +08:00
|
|
|
};
|
|
|
|
|
2006-05-16 20:26:20 +08:00
|
|
|
static const GimpParamDef save_args[] =
|
1998-11-06 08:51:39 +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 09:26:57 +08:00
|
|
|
{ GIMP_PDB_IMAGE, "image", "Input image" },
|
2016-02-16 09:35:43 +08:00
|
|
|
{ GIMP_PDB_DRAWABLE, "drawable", "Drawable to export" },
|
|
|
|
{ GIMP_PDB_STRING, "filename", "The name of the file to export" },
|
2005-08-16 06:42:34 +08:00
|
|
|
{ GIMP_PDB_STRING, "raw-filename", "The name entered" },
|
2000-08-22 09:26:57 +08:00
|
|
|
{ GIMP_PDB_STRING, "comment", "Image description (maximum 72 bytes)" },
|
2016-02-16 09:35:43 +08:00
|
|
|
{ GIMP_PDB_INT32, "x10", "Export in X10 format" },
|
2005-08-16 06:42:34 +08:00
|
|
|
{ GIMP_PDB_INT32, "x-hot", "X coordinate of hotspot" },
|
|
|
|
{ GIMP_PDB_INT32, "y-hot", "Y coordinate of hotspot" },
|
2000-08-22 09:26:57 +08:00
|
|
|
{ GIMP_PDB_STRING, "prefix", "Identifier prefix [determined from filename]"},
|
2005-08-16 06:42:34 +08:00
|
|
|
{ GIMP_PDB_INT32, "write-mask", "(0 = ignore, 1 = save as extra file)" },
|
|
|
|
{ GIMP_PDB_STRING, "mask-extension", "Extension of the mask file" }
|
1998-11-06 08:51:39 +08:00
|
|
|
} ;
|
|
|
|
|
2005-08-16 06:42:34 +08:00
|
|
|
gimp_install_procedure (LOAD_PROC,
|
2000-01-31 10:32:30 +08:00
|
|
|
"Load a file in X10 or X11 bitmap (XBM) file format",
|
|
|
|
"Load a file in X10 or X11 bitmap (XBM) file format. XBM is a lossless format for flat black-and-white (two color indexed) images.",
|
1998-11-06 08:51:39 +08:00
|
|
|
"Gordon Matzigkeit",
|
|
|
|
"Gordon Matzigkeit",
|
|
|
|
"1998",
|
2004-05-14 08:01:11 +08:00
|
|
|
N_("X BitMap image"),
|
2008-10-20 14:04:39 +08:00
|
|
|
NULL,
|
2000-08-22 09:26:57 +08:00
|
|
|
GIMP_PLUGIN,
|
2001-12-06 10:28:58 +08:00
|
|
|
G_N_ELEMENTS (load_args),
|
|
|
|
G_N_ELEMENTS (load_return_vals),
|
1998-11-06 08:51:39 +08:00
|
|
|
load_args, load_return_vals);
|
|
|
|
|
2005-08-16 06:42:34 +08:00
|
|
|
gimp_register_file_handler_mime (LOAD_PROC, "image/x-xbitmap");
|
|
|
|
gimp_register_load_handler (LOAD_PROC,
|
2008-10-20 14:04:39 +08:00
|
|
|
"xbm,icon,bitmap",
|
|
|
|
"");
|
2004-05-14 08:01:11 +08:00
|
|
|
|
2005-08-16 06:42:34 +08:00
|
|
|
gimp_install_procedure (SAVE_PROC,
|
2016-02-16 09:35:43 +08:00
|
|
|
"Export a file in X10 or X11 bitmap (XBM) file format",
|
|
|
|
"Export a file in X10 or X11 bitmap (XBM) file format. XBM is a lossless format for flat black-and-white (two color indexed) images.",
|
2008-10-20 14:04:39 +08:00
|
|
|
"Gordon Matzigkeit",
|
1998-11-06 08:51:39 +08:00
|
|
|
"Gordon Matzigkeit",
|
|
|
|
"1998",
|
2004-05-14 08:01:11 +08:00
|
|
|
N_("X BitMap image"),
|
2008-10-20 14:04:39 +08:00
|
|
|
"INDEXED",
|
2000-08-22 09:26:57 +08:00
|
|
|
GIMP_PLUGIN,
|
2001-12-06 10:28:58 +08:00
|
|
|
G_N_ELEMENTS (save_args), 0,
|
1998-11-06 08:51:39 +08:00
|
|
|
save_args, NULL);
|
|
|
|
|
2005-08-16 06:42:34 +08:00
|
|
|
gimp_register_file_handler_mime (SAVE_PROC, "image/x-xbitmap");
|
2014-10-06 00:06:03 +08:00
|
|
|
gimp_register_file_handler_uri (SAVE_PROC);
|
2005-08-16 06:42:34 +08:00
|
|
|
gimp_register_save_handler (SAVE_PROC, "xbm,icon,bitmap", "");
|
1998-11-06 08:51:39 +08:00
|
|
|
}
|
|
|
|
|
2000-06-05 19:38:35 +08:00
|
|
|
static gchar *
|
2001-07-29 17:43:09 +08:00
|
|
|
init_prefix (const gchar *filename)
|
1998-11-06 08:51:39 +08:00
|
|
|
{
|
2000-01-26 01:46:56 +08:00
|
|
|
gchar *p, *prefix;
|
|
|
|
gint len;
|
1998-11-06 08:51:39 +08:00
|
|
|
|
2001-07-29 17:43:09 +08:00
|
|
|
prefix = g_path_get_basename (filename);
|
1998-11-06 08:51:39 +08:00
|
|
|
|
|
|
|
memset (xsvals.prefix, 0, sizeof (xsvals.prefix));
|
2001-07-29 17:43:09 +08:00
|
|
|
|
|
|
|
if (prefix)
|
|
|
|
{
|
2005-08-10 04:49:55 +08:00
|
|
|
/* Strip any extension. */
|
2001-07-29 17:43:09 +08:00
|
|
|
p = strrchr (prefix, '.');
|
|
|
|
if (p && p != prefix)
|
|
|
|
len = MIN (MAX_PREFIX, p - prefix);
|
|
|
|
else
|
|
|
|
len = MAX_PREFIX;
|
|
|
|
|
|
|
|
strncpy (xsvals.prefix, prefix, len);
|
|
|
|
g_free (prefix);
|
|
|
|
}
|
2000-06-05 19:38:35 +08:00
|
|
|
|
|
|
|
return xsvals.prefix;
|
1998-11-06 08:51:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-07-02 21:00:16 +08:00
|
|
|
run (const gchar *name,
|
|
|
|
gint nparams,
|
|
|
|
const GimpParam *param,
|
|
|
|
gint *nreturn_vals,
|
|
|
|
GimpParam **return_vals)
|
1998-11-06 08:51:39 +08:00
|
|
|
{
|
2000-06-05 19:38:35 +08:00
|
|
|
static GimpParam values[2];
|
2002-01-16 02:35:29 +08:00
|
|
|
GimpRunMode run_mode;
|
2008-08-19 03:08:54 +08:00
|
|
|
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
|
2000-06-05 19:38:35 +08:00
|
|
|
gint32 image_ID;
|
|
|
|
gint32 drawable_ID;
|
2008-08-19 03:08:54 +08:00
|
|
|
GimpParasite *parasite = NULL;
|
2014-10-06 00:06:03 +08:00
|
|
|
gchar *mask_basename = NULL;
|
2008-08-19 03:08:54 +08:00
|
|
|
GError *error = NULL;
|
|
|
|
GimpExportReturn export = GIMP_EXPORT_CANCEL;
|
1998-11-06 08:51:39 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
INIT_I18N ();
|
2012-11-19 06:22:07 +08:00
|
|
|
gegl_init (NULL, NULL);
|
2003-03-26 00:38:19 +08:00
|
|
|
|
2005-10-06 08:44:41 +08:00
|
|
|
strncpy (xsvals.comment, "Created with GIMP", MAX_COMMENT);
|
1999-05-30 00:35:47 +08:00
|
|
|
|
1998-11-06 08:51:39 +08:00
|
|
|
run_mode = param[0].data.d_int32;
|
|
|
|
|
|
|
|
*nreturn_vals = 1;
|
2000-01-26 01:46:56 +08:00
|
|
|
*return_vals = values;
|
2002-01-16 02:35:29 +08:00
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
values[0].type = GIMP_PDB_STATUS;
|
|
|
|
values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
|
1998-11-06 08:51:39 +08:00
|
|
|
|
|
|
|
#ifdef VERBOSE
|
|
|
|
if (verbose)
|
|
|
|
printf ("XBM: RUN %s\n", name);
|
|
|
|
#endif
|
|
|
|
|
2005-08-16 06:42:34 +08:00
|
|
|
if (strcmp (name, LOAD_PROC) == 0)
|
1998-11-06 08:51:39 +08:00
|
|
|
{
|
2008-08-19 03:08:54 +08:00
|
|
|
image_ID = load_image (param[1].data.d_string, &error);
|
1998-11-06 08:51:39 +08:00
|
|
|
|
|
|
|
if (image_ID != -1)
|
|
|
|
{
|
|
|
|
*nreturn_vals = 2;
|
2000-08-22 09:26:57 +08:00
|
|
|
values[1].type = GIMP_PDB_IMAGE;
|
1998-11-06 08:51:39 +08:00
|
|
|
values[1].data.d_image = image_ID;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
1998-11-06 08:51:39 +08:00
|
|
|
}
|
|
|
|
}
|
2005-08-16 06:42:34 +08:00
|
|
|
else if (strcmp (name, SAVE_PROC) == 0)
|
1998-11-06 08:51:39 +08:00
|
|
|
{
|
2003-11-16 00:51:20 +08:00
|
|
|
image_ID = param[1].data.d_int32;
|
1999-10-14 10:11:52 +08:00
|
|
|
drawable_ID = param[2].data.d_int32;
|
2000-06-05 19:38:35 +08:00
|
|
|
|
1999-10-14 10:11:52 +08:00
|
|
|
switch (run_mode)
|
2008-10-20 14:04:39 +08:00
|
|
|
{
|
|
|
|
case GIMP_RUN_INTERACTIVE:
|
|
|
|
case GIMP_RUN_WITH_LAST_VALS:
|
|
|
|
gimp_ui_init (PLUG_IN_BINARY, FALSE);
|
2013-11-10 07:18:48 +08:00
|
|
|
|
|
|
|
export = gimp_export_image (&image_ID, &drawable_ID, "XBM",
|
2008-10-20 14:04:39 +08:00
|
|
|
GIMP_EXPORT_CAN_HANDLE_BITMAP |
|
|
|
|
GIMP_EXPORT_CAN_HANDLE_ALPHA);
|
|
|
|
|
|
|
|
if (export == GIMP_EXPORT_CANCEL)
|
|
|
|
{
|
|
|
|
values[0].data.d_status = GIMP_PDB_CANCEL;
|
|
|
|
return;
|
2003-11-16 00:51:20 +08:00
|
|
|
}
|
2008-10-20 14:04:39 +08:00
|
|
|
break;
|
2003-11-16 00:51:20 +08:00
|
|
|
|
2008-10-20 14:04:39 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
1998-11-06 08:51:39 +08:00
|
|
|
|
|
|
|
switch (run_mode)
|
2008-10-20 14:04:39 +08:00
|
|
|
{
|
|
|
|
case GIMP_RUN_INTERACTIVE:
|
|
|
|
case GIMP_RUN_WITH_LAST_VALS:
|
|
|
|
/* Possibly retrieve data */
|
|
|
|
gimp_get_data (SAVE_PROC, &xsvals);
|
|
|
|
|
|
|
|
/* Always override the prefix with the filename. */
|
2014-10-06 00:06:03 +08:00
|
|
|
mask_basename = g_strdup (init_prefix (param[3].data.d_string));
|
2008-10-20 14:04:39 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_RUN_NONINTERACTIVE:
|
|
|
|
/* Make sure all the required arguments are there! */
|
|
|
|
if (nparams < 5)
|
|
|
|
{
|
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gint i = 5;
|
|
|
|
|
|
|
|
if (nparams > i)
|
|
|
|
{
|
|
|
|
memset (xsvals.comment, 0, sizeof (xsvals.comment));
|
|
|
|
strncpy (xsvals.comment, param[i].data.d_string,
|
|
|
|
MAX_COMMENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
i ++;
|
|
|
|
if (nparams > i)
|
|
|
|
xsvals.x10_format = (param[i].data.d_int32) ? TRUE : FALSE;
|
|
|
|
|
|
|
|
i += 2;
|
|
|
|
if (nparams > i)
|
|
|
|
{
|
|
|
|
/* They've asked for a hotspot. */
|
|
|
|
xsvals.use_hot = TRUE;
|
|
|
|
xsvals.x_hot = param[i - 1].data.d_int32;
|
|
|
|
xsvals.y_hot = param[i].data.d_int32;
|
|
|
|
}
|
|
|
|
|
2014-10-06 00:06:03 +08:00
|
|
|
mask_basename = g_strdup (init_prefix (param[3].data.d_string));
|
2008-10-20 14:04:39 +08:00
|
|
|
|
|
|
|
i ++;
|
|
|
|
if (nparams > i)
|
|
|
|
{
|
|
|
|
memset (xsvals.prefix, 0, sizeof (xsvals.prefix));
|
|
|
|
strncpy (xsvals.prefix, param[i].data.d_string,
|
|
|
|
MAX_PREFIX);
|
|
|
|
}
|
|
|
|
|
|
|
|
i += 2;
|
|
|
|
if (nparams > i)
|
|
|
|
{
|
|
|
|
xsvals.write_mask = param[i - 1].data.d_int32;
|
|
|
|
memset (xsvals.mask_ext, 0, sizeof (xsvals.mask_ext));
|
|
|
|
strncpy (xsvals.mask_ext, param[i].data.d_string,
|
|
|
|
MAX_MASK_EXT);
|
|
|
|
}
|
|
|
|
|
|
|
|
i ++;
|
|
|
|
/* Too many arguments. */
|
|
|
|
if (nparams > i)
|
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2000-03-04 08:24:39 +08:00
|
|
|
|
2000-10-20 11:44:47 +08:00
|
|
|
if (run_mode == GIMP_RUN_INTERACTIVE)
|
2008-10-20 14:04:39 +08:00
|
|
|
{
|
|
|
|
/* Get the parasites */
|
2011-03-08 20:19:21 +08:00
|
|
|
parasite = gimp_image_get_parasite (image_ID, "gimp-comment");
|
2000-03-04 08:24:39 +08:00
|
|
|
|
2000-10-20 11:38:15 +08:00
|
|
|
if (parasite)
|
2008-10-20 14:04:39 +08:00
|
|
|
{
|
|
|
|
gint size = gimp_parasite_data_size (parasite);
|
2000-03-05 08:06:11 +08:00
|
|
|
|
2008-10-20 14:04:39 +08:00
|
|
|
strncpy (xsvals.comment,
|
|
|
|
gimp_parasite_data (parasite), MIN (size, MAX_COMMENT));
|
|
|
|
xsvals.comment[MIN (size, MAX_COMMENT) + 1] = 0;
|
2000-03-04 08:24:39 +08:00
|
|
|
|
2008-10-20 14:04:39 +08:00
|
|
|
gimp_parasite_free (parasite);
|
|
|
|
}
|
2000-03-05 08:06:11 +08:00
|
|
|
|
2011-03-08 20:19:21 +08:00
|
|
|
parasite = gimp_image_get_parasite (image_ID, "hot-spot");
|
2000-03-04 08:24:39 +08:00
|
|
|
|
2000-10-20 11:38:15 +08:00
|
|
|
if (parasite)
|
2008-10-20 14:04:39 +08:00
|
|
|
{
|
|
|
|
gint x, y;
|
|
|
|
|
|
|
|
if (sscanf (gimp_parasite_data (parasite), "%i %i", &x, &y) == 2)
|
|
|
|
{
|
|
|
|
xsvals.use_hot = TRUE;
|
|
|
|
xsvals.x_hot = x;
|
|
|
|
xsvals.y_hot = y;
|
|
|
|
}
|
|
|
|
gimp_parasite_free (parasite);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Acquire information with a dialog */
|
|
|
|
if (! save_dialog (drawable_ID))
|
|
|
|
status = GIMP_PDB_CANCEL;
|
|
|
|
}
|
1998-11-06 08:51:39 +08:00
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
if (status == GIMP_PDB_SUCCESS)
|
2008-10-20 14:04:39 +08:00
|
|
|
{
|
2014-10-06 00:06:03 +08:00
|
|
|
GFile *file = g_file_new_for_uri (param[3].data.d_string);
|
|
|
|
GFile *mask_file;
|
|
|
|
GFile *dir;
|
2008-10-20 14:04:39 +08:00
|
|
|
gchar *mask_prefix;
|
2014-10-06 00:06:03 +08:00
|
|
|
gchar *temp;
|
2008-10-20 14:04:39 +08:00
|
|
|
|
2014-10-06 00:06:03 +08:00
|
|
|
dir = g_file_get_parent (file);
|
|
|
|
temp = g_strdup_printf ("%s%s.xbm", mask_basename, xsvals.mask_ext);
|
2008-10-20 14:04:39 +08:00
|
|
|
|
2014-10-06 00:06:03 +08:00
|
|
|
mask_file = g_file_get_child (dir, temp);
|
2008-10-20 14:04:39 +08:00
|
|
|
|
|
|
|
g_free (temp);
|
2014-10-06 00:06:03 +08:00
|
|
|
g_object_unref (dir);
|
2008-10-20 14:04:39 +08:00
|
|
|
|
|
|
|
/* Change any non-alphanumeric prefix characters to underscores. */
|
|
|
|
for (temp = xsvals.prefix; *temp; temp++)
|
2005-08-10 04:49:55 +08:00
|
|
|
if (! g_ascii_isalnum (*temp))
|
|
|
|
*temp = '_';
|
1998-11-06 08:51:39 +08:00
|
|
|
|
2008-10-20 14:04:39 +08:00
|
|
|
mask_prefix = g_strdup_printf ("%s%s",
|
2003-07-02 21:00:16 +08:00
|
|
|
xsvals.prefix, xsvals.mask_ext);
|
1998-11-06 08:51:39 +08:00
|
|
|
|
2008-10-20 14:04:39 +08:00
|
|
|
for (temp = mask_prefix; *temp; temp++)
|
2005-08-10 04:49:55 +08:00
|
|
|
if (! g_ascii_isalnum (*temp))
|
|
|
|
*temp = '_';
|
|
|
|
|
2014-10-06 00:06:03 +08:00
|
|
|
if (save_image (file,
|
2008-10-20 14:04:39 +08:00
|
|
|
xsvals.prefix,
|
|
|
|
xsvals.comment,
|
|
|
|
FALSE,
|
|
|
|
image_ID, drawable_ID,
|
2008-08-19 03:08:54 +08:00
|
|
|
&error)
|
2014-10-06 00:06:03 +08:00
|
|
|
|
|
|
|
&& (! xsvals.write_mask ||
|
|
|
|
save_image (mask_file,
|
|
|
|
mask_prefix,
|
|
|
|
xsvals.comment,
|
|
|
|
TRUE,
|
|
|
|
image_ID, drawable_ID,
|
|
|
|
&error)))
|
2008-10-20 14:04:39 +08:00
|
|
|
{
|
|
|
|
/* Store xsvals data */
|
|
|
|
gimp_set_data (SAVE_PROC, &xsvals, sizeof (xsvals));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
status = GIMP_PDB_EXECUTION_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (mask_prefix);
|
2014-10-06 00:06:03 +08:00
|
|
|
g_free (mask_basename);
|
|
|
|
|
|
|
|
g_object_unref (file);
|
|
|
|
g_object_unref (mask_file);
|
2008-10-20 14:04:39 +08:00
|
|
|
}
|
1999-10-14 10:11:52 +08:00
|
|
|
|
2000-08-24 22:17:34 +08:00
|
|
|
if (export == GIMP_EXPORT_EXPORT)
|
2008-10-20 14:04:39 +08:00
|
|
|
gimp_image_delete (image_ID);
|
1998-11-06 08:51:39 +08:00
|
|
|
}
|
2000-01-26 01:46:56 +08:00
|
|
|
else
|
|
|
|
{
|
2000-08-22 09:26:57 +08:00
|
|
|
status = GIMP_PDB_CALLING_ERROR;
|
2000-01-26 01:46:56 +08:00
|
|
|
}
|
1998-11-06 08:51:39 +08:00
|
|
|
|
2008-08-19 03:08:54 +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;
|
|
|
|
}
|
1998-11-06 08:51:39 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* Return the value of a digit. */
|
|
|
|
static gint
|
2003-11-06 23:27:05 +08:00
|
|
|
getval (gint c,
|
2008-10-20 14:04:39 +08:00
|
|
|
gint base)
|
1998-11-06 08:51:39 +08:00
|
|
|
{
|
2003-07-03 21:26:06 +08:00
|
|
|
const gchar *digits = "0123456789abcdefABCDEF";
|
|
|
|
gint val;
|
1998-11-06 08:51:39 +08:00
|
|
|
|
|
|
|
/* Include uppercase hex digits. */
|
|
|
|
if (base == 16)
|
|
|
|
base = 22;
|
|
|
|
|
|
|
|
/* Find a match. */
|
|
|
|
for (val = 0; val < base; val ++)
|
|
|
|
if (c == digits[val])
|
|
|
|
return (val < 16) ? val : (val - 6);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-03-04 08:24:39 +08:00
|
|
|
/* Get a comment */
|
|
|
|
static gchar *
|
|
|
|
fgetcomment (FILE *fp)
|
|
|
|
{
|
|
|
|
GString *str = NULL;
|
|
|
|
gint comment, c;
|
|
|
|
|
|
|
|
comment = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
c = fgetc (fp);
|
|
|
|
if (comment)
|
2008-10-20 14:04:39 +08:00
|
|
|
{
|
|
|
|
if (c == '*')
|
|
|
|
{
|
|
|
|
/* In a comment, with potential to leave. */
|
|
|
|
comment = 1;
|
|
|
|
}
|
|
|
|
else if (comment == 1 && c == '/')
|
|
|
|
{
|
|
|
|
gchar *retval;
|
|
|
|
|
|
|
|
/* Leaving a comment. */
|
|
|
|
comment = 0;
|
|
|
|
|
|
|
|
retval = g_strstrip (g_strdup (str->str));
|
|
|
|
g_string_free (str, TRUE);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* In a comment, with no potential to leave. */
|
|
|
|
comment = 2;
|
|
|
|
g_string_append_c (str, c);
|
|
|
|
}
|
|
|
|
}
|
2000-03-04 08:24:39 +08:00
|
|
|
else
|
2008-10-20 14:04:39 +08:00
|
|
|
{
|
|
|
|
/* Not in a comment. */
|
|
|
|
if (c == '/')
|
|
|
|
{
|
|
|
|
/* Potential to enter a comment. */
|
|
|
|
c = fgetc (fp);
|
|
|
|
if (c == '*')
|
|
|
|
{
|
|
|
|
/* Entered a comment, with no potential to leave. */
|
|
|
|
comment = 2;
|
|
|
|
str = g_string_new (NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* put everything back and return */
|
|
|
|
ungetc (c, fp);
|
|
|
|
c = '/';
|
|
|
|
ungetc (c, fp);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (c != EOF && g_ascii_isspace (c))
|
|
|
|
{
|
|
|
|
/* Skip leading whitespace */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2000-03-04 08:24:39 +08:00
|
|
|
}
|
|
|
|
while (comment && c != EOF);
|
|
|
|
|
|
|
|
if (str)
|
|
|
|
g_string_free (str, TRUE);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-11-06 08:51:39 +08:00
|
|
|
/* Same as fgetc, but skip C-style comments and insert whitespace. */
|
|
|
|
static gint
|
|
|
|
cpp_fgetc (FILE *fp)
|
|
|
|
{
|
2000-01-26 01:46:56 +08:00
|
|
|
gint comment, c;
|
1998-11-06 08:51:39 +08:00
|
|
|
|
|
|
|
/* FIXME: insert whitespace as advertised. */
|
|
|
|
comment = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
c = fgetc (fp);
|
|
|
|
if (comment)
|
2008-10-20 14:04:39 +08:00
|
|
|
{
|
|
|
|
if (c == '*')
|
|
|
|
/* In a comment, with potential to leave. */
|
|
|
|
comment = 1;
|
|
|
|
else if (comment == 1 && c == '/')
|
|
|
|
/* Leaving a comment. */
|
|
|
|
comment = 0;
|
|
|
|
else
|
|
|
|
/* In a comment, with no potential to leave. */
|
|
|
|
comment = 2;
|
|
|
|
}
|
1998-11-06 08:51:39 +08:00
|
|
|
else
|
2008-10-20 14:04:39 +08:00
|
|
|
{
|
|
|
|
/* Not in a comment. */
|
|
|
|
if (c == '/')
|
|
|
|
{
|
|
|
|
/* Potential to enter a comment. */
|
|
|
|
c = fgetc (fp);
|
|
|
|
if (c == '*')
|
|
|
|
/* Entered a comment, with no potential to leave. */
|
|
|
|
comment = 2;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Just a slash in the open. */
|
|
|
|
ungetc (c, fp);
|
|
|
|
c = '/';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-11-06 08:51:39 +08:00
|
|
|
}
|
|
|
|
while (comment && c != EOF);
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Match a string with a file. */
|
|
|
|
static gint
|
2008-09-17 16:37:24 +08:00
|
|
|
match (FILE *fp,
|
|
|
|
const gchar *s)
|
1998-11-06 08:51:39 +08:00
|
|
|
{
|
2000-01-26 01:46:56 +08:00
|
|
|
gint c;
|
1998-11-06 08:51:39 +08:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
c = fgetc (fp);
|
|
|
|
if (c == *s)
|
2008-10-20 14:04:39 +08:00
|
|
|
s ++;
|
1998-11-06 08:51:39 +08:00
|
|
|
else
|
2008-10-20 14:04:39 +08:00
|
|
|
break;
|
1998-11-06 08:51:39 +08:00
|
|
|
}
|
|
|
|
while (c != EOF && *s);
|
|
|
|
|
|
|
|
if (!*s)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (c != EOF)
|
|
|
|
ungetc (c, fp);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Read the next integer from the file, skipping all non-integers. */
|
|
|
|
static gint
|
|
|
|
get_int (FILE *fp)
|
|
|
|
{
|
|
|
|
int digval, base, val, c;
|
|
|
|
|
|
|
|
do
|
|
|
|
c = cpp_fgetc (fp);
|
2003-11-27 03:20:24 +08:00
|
|
|
while (c != EOF && ! g_ascii_isdigit (c));
|
1998-11-06 08:51:39 +08:00
|
|
|
|
|
|
|
if (c == EOF)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Check for the base. */
|
|
|
|
if (c == '0')
|
|
|
|
{
|
|
|
|
c = fgetc (fp);
|
|
|
|
if (c == 'x' || c == 'X')
|
2008-10-20 14:04:39 +08:00
|
|
|
{
|
|
|
|
c = fgetc (fp);
|
|
|
|
base = 16;
|
|
|
|
}
|
2003-11-27 03:20:24 +08:00
|
|
|
else if (g_ascii_isdigit (c))
|
2008-10-20 14:04:39 +08:00
|
|
|
base = 8;
|
1998-11-06 08:51:39 +08:00
|
|
|
else
|
2008-10-20 14:04:39 +08:00
|
|
|
{
|
|
|
|
ungetc (c, fp);
|
|
|
|
return 0;
|
|
|
|
}
|
1998-11-06 08:51:39 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
base = 10;
|
|
|
|
|
|
|
|
val = 0;
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
digval = getval (c, base);
|
|
|
|
if (digval == -1)
|
2008-10-20 14:04:39 +08:00
|
|
|
{
|
|
|
|
ungetc (c, fp);
|
|
|
|
break;
|
|
|
|
}
|
1998-11-06 08:51:39 +08:00
|
|
|
val *= base;
|
|
|
|
val += digval;
|
|
|
|
c = fgetc (fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-17 16:37:24 +08:00
|
|
|
static gint32
|
2008-08-19 03:08:54 +08:00
|
|
|
load_image (const gchar *filename,
|
|
|
|
GError **error)
|
1998-11-06 08:51:39 +08:00
|
|
|
{
|
2008-09-17 16:37:24 +08:00
|
|
|
FILE *fp;
|
2012-11-19 06:22:07 +08:00
|
|
|
GeglBuffer *buffer;
|
2008-09-17 16:37:24 +08:00
|
|
|
gint32 image_ID;
|
|
|
|
gint32 layer_ID;
|
|
|
|
guchar *data;
|
|
|
|
gint intbits;
|
|
|
|
gint width = 0;
|
|
|
|
gint height = 0;
|
|
|
|
gint x_hot = 0;
|
|
|
|
gint y_hot = 0;
|
|
|
|
gint c, i, j, k;
|
|
|
|
gint tileheight, rowoffset;
|
|
|
|
gchar *comment;
|
1998-11-06 08:51:39 +08:00
|
|
|
|
2005-02-13 08:11:24 +08:00
|
|
|
const guchar cmap[] =
|
1998-11-06 08:51:39 +08:00
|
|
|
{
|
2008-10-20 14:04:39 +08:00
|
|
|
0x00, 0x00, 0x00, /* black */
|
|
|
|
0xff, 0xff, 0xff /* white */
|
1998-11-06 08:51:39 +08:00
|
|
|
};
|
|
|
|
|
2014-07-23 22:39:00 +08:00
|
|
|
gimp_progress_init_printf (_("Opening '%s'"),
|
|
|
|
gimp_filename_to_utf8 (filename));
|
|
|
|
|
2005-03-04 23:12:29 +08:00
|
|
|
fp = g_fopen (filename, "rb");
|
2008-08-19 03:08:54 +08:00
|
|
|
if (! fp)
|
1998-11-06 08:51:39 +08:00
|
|
|
{
|
2008-08-19 03:08:54 +08:00
|
|
|
g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
|
|
|
|
_("Could not open '%s' for reading: %s"),
|
|
|
|
gimp_filename_to_utf8 (filename), g_strerror (errno));
|
1998-11-06 08:51:39 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2000-03-04 08:24:39 +08:00
|
|
|
comment = fgetcomment (fp);
|
|
|
|
|
1998-11-06 08:51:39 +08:00
|
|
|
/* Loosely parse the header */
|
|
|
|
intbits = height = width = 0;
|
|
|
|
c = ' ';
|
|
|
|
do
|
|
|
|
{
|
2003-11-27 03:20:24 +08:00
|
|
|
if (g_ascii_isspace (c))
|
2008-10-20 14:04:39 +08:00
|
|
|
{
|
|
|
|
if (match (fp, "char"))
|
|
|
|
{
|
|
|
|
c = fgetc (fp);
|
|
|
|
if (g_ascii_isspace (c))
|
|
|
|
{
|
|
|
|
intbits = 8;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (match (fp, "short"))
|
|
|
|
{
|
|
|
|
c = fgetc (fp);
|
|
|
|
if (g_ascii_isspace (c))
|
|
|
|
{
|
|
|
|
intbits = 16;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-11-06 08:51:39 +08:00
|
|
|
|
|
|
|
if (c == '_')
|
2008-10-20 14:04:39 +08:00
|
|
|
{
|
|
|
|
if (match (fp, "width"))
|
|
|
|
{
|
|
|
|
c = fgetc (fp);
|
|
|
|
if (g_ascii_isspace (c))
|
|
|
|
{
|
|
|
|
width = get_int (fp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (match (fp, "height"))
|
|
|
|
{
|
|
|
|
c = fgetc (fp);
|
|
|
|
if (g_ascii_isspace (c))
|
|
|
|
{
|
|
|
|
height = get_int (fp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (match (fp, "x_hot"))
|
|
|
|
{
|
|
|
|
c = fgetc (fp);
|
|
|
|
if (g_ascii_isspace (c))
|
|
|
|
{
|
|
|
|
x_hot = get_int (fp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (match (fp, "y_hot"))
|
|
|
|
{
|
|
|
|
c = fgetc (fp);
|
|
|
|
if (g_ascii_isspace (c))
|
|
|
|
{
|
|
|
|
y_hot = get_int (fp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-11-06 08:51:39 +08:00
|
|
|
|
|
|
|
c = cpp_fgetc (fp);
|
|
|
|
}
|
|
|
|
while (c != '{' && c != EOF);
|
|
|
|
|
|
|
|
if (c == EOF)
|
|
|
|
{
|
2003-11-15 21:53:33 +08:00
|
|
|
g_message (_("'%s':\nCould not read header (ftell == %ld)"),
|
2004-01-19 11:06:04 +08:00
|
|
|
gimp_filename_to_utf8 (filename), ftell (fp));
|
1998-11-06 08:51:39 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-07-05 07:32:15 +08:00
|
|
|
if (width <= 0)
|
1998-11-06 08:51:39 +08:00
|
|
|
{
|
2004-01-19 11:06:04 +08:00
|
|
|
g_message (_("'%s':\nNo image width specified"),
|
|
|
|
gimp_filename_to_utf8 (filename));
|
1998-11-06 08:51:39 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-07-05 07:32:15 +08:00
|
|
|
if (width > GIMP_MAX_IMAGE_SIZE)
|
|
|
|
{
|
|
|
|
g_message (_("'%s':\nImage width is larger than GIMP can handle"),
|
|
|
|
gimp_filename_to_utf8 (filename));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (height <= 0)
|
1998-11-06 08:51:39 +08:00
|
|
|
{
|
2004-01-19 11:06:04 +08:00
|
|
|
g_message (_("'%s':\nNo image height specified"),
|
|
|
|
gimp_filename_to_utf8 (filename));
|
1998-11-06 08:51:39 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-07-05 07:32:15 +08:00
|
|
|
if (height > GIMP_MAX_IMAGE_SIZE)
|
|
|
|
{
|
|
|
|
g_message (_("'%s':\nImage height is larger than GIMP can handle"),
|
|
|
|
gimp_filename_to_utf8 (filename));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
1998-11-06 08:51:39 +08:00
|
|
|
if (intbits == 0)
|
|
|
|
{
|
2004-01-19 11:06:04 +08:00
|
|
|
g_message (_("'%s':\nNo image data type specified"),
|
|
|
|
gimp_filename_to_utf8 (filename));
|
1998-11-06 08:51:39 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2000-08-22 09:26:57 +08:00
|
|
|
image_ID = gimp_image_new (width, height, GIMP_INDEXED);
|
1998-11-06 08:51:39 +08:00
|
|
|
gimp_image_set_filename (image_ID, filename);
|
|
|
|
|
2000-03-04 08:24:39 +08:00
|
|
|
if (comment)
|
|
|
|
{
|
2000-05-27 06:28:40 +08:00
|
|
|
GimpParasite *parasite;
|
2000-03-04 08:24:39 +08:00
|
|
|
|
2000-05-27 06:28:40 +08:00
|
|
|
parasite = gimp_parasite_new ("gimp-comment",
|
2008-10-20 14:04:39 +08:00
|
|
|
GIMP_PARASITE_PERSISTENT,
|
|
|
|
strlen (comment) + 1, (gpointer) comment);
|
2011-03-08 20:19:21 +08:00
|
|
|
gimp_image_attach_parasite (image_ID, parasite);
|
2000-05-27 06:28:40 +08:00
|
|
|
gimp_parasite_free (parasite);
|
2000-03-04 08:24:39 +08:00
|
|
|
|
|
|
|
g_free (comment);
|
|
|
|
}
|
|
|
|
|
|
|
|
x_hot = CLAMP (x_hot, 0, width);
|
|
|
|
y_hot = CLAMP (y_hot, 0, height);
|
|
|
|
|
|
|
|
if (x_hot > 0 || y_hot > 0)
|
|
|
|
{
|
2000-05-27 06:28:40 +08:00
|
|
|
GimpParasite *parasite;
|
|
|
|
gchar *str;
|
2000-03-04 08:24:39 +08:00
|
|
|
|
|
|
|
str = g_strdup_printf ("%d %d", x_hot, y_hot);
|
2000-05-27 06:28:40 +08:00
|
|
|
parasite = gimp_parasite_new ("hot-spot",
|
2008-10-20 14:04:39 +08:00
|
|
|
GIMP_PARASITE_PERSISTENT,
|
|
|
|
strlen (str) + 1, (gpointer) str);
|
2000-03-04 08:24:39 +08:00
|
|
|
g_free (str);
|
2011-03-08 20:19:21 +08:00
|
|
|
gimp_image_attach_parasite (image_ID, parasite);
|
2000-05-27 06:28:40 +08:00
|
|
|
gimp_parasite_free (parasite);
|
2000-03-04 08:24:39 +08:00
|
|
|
}
|
|
|
|
|
1998-11-06 08:51:39 +08:00
|
|
|
/* Set a black-and-white colormap. */
|
2004-11-02 20:00:25 +08:00
|
|
|
gimp_image_set_colormap (image_ID, cmap, 2);
|
1998-11-06 08:51:39 +08:00
|
|
|
|
|
|
|
layer_ID = gimp_layer_new (image_ID,
|
2008-10-20 14:04:39 +08:00
|
|
|
_("Background"),
|
|
|
|
width, height,
|
|
|
|
GIMP_INDEXED_IMAGE,
|
|
|
|
100,
|
2017-08-20 23:12:46 +08:00
|
|
|
gimp_get_default_new_layer_mode ());
|
2010-09-06 17:40:46 +08:00
|
|
|
gimp_image_insert_layer (image_ID, layer_ID, -1, 0);
|
1998-11-06 08:51:39 +08:00
|
|
|
|
2012-11-19 06:22:07 +08:00
|
|
|
buffer = gimp_drawable_get_buffer (layer_ID);
|
1998-11-06 08:51:39 +08:00
|
|
|
|
|
|
|
/* Allocate the data. */
|
|
|
|
tileheight = gimp_tile_height ();
|
|
|
|
data = (guchar *) g_malloc (width * tileheight);
|
|
|
|
|
|
|
|
for (i = 0; i < height; i += tileheight)
|
|
|
|
{
|
|
|
|
tileheight = MIN (tileheight, height - i);
|
|
|
|
|
|
|
|
#ifdef VERBOSE
|
|
|
|
if (verbose > 1)
|
2008-10-20 14:04:39 +08:00
|
|
|
printf ("XBM: reading %dx(%d+%d) pixel region\n", width, i,
|
|
|
|
tileheight);
|
1998-11-06 08:51:39 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Parse the data from the file */
|
|
|
|
for (j = 0; j < tileheight; j ++)
|
2008-10-20 14:04:39 +08:00
|
|
|
{
|
|
|
|
/* Read each row. */
|
|
|
|
rowoffset = j * width;
|
|
|
|
for (k = 0; k < width; k ++)
|
|
|
|
{
|
|
|
|
/* Expand each integer into INTBITS pixels. */
|
|
|
|
if (k % intbits == 0)
|
|
|
|
{
|
|
|
|
c = get_int (fp);
|
|
|
|
|
|
|
|
/* Flip all the bits so that 1's become black and
|
1998-11-06 08:51:39 +08:00
|
|
|
0's become white. */
|
2008-10-20 14:04:39 +08:00
|
|
|
c ^= 0xffff;
|
|
|
|
}
|
1998-11-06 08:51:39 +08:00
|
|
|
|
2008-10-20 14:04:39 +08:00
|
|
|
data[rowoffset + k] = c & 1;
|
|
|
|
c >>= 1;
|
|
|
|
}
|
|
|
|
}
|
1998-11-06 08:51:39 +08:00
|
|
|
|
|
|
|
/* Put the data into the image. */
|
2012-11-19 06:22:07 +08:00
|
|
|
gegl_buffer_set (buffer, GEGL_RECTANGLE (0, i, width, tileheight), 0,
|
|
|
|
NULL, data, GEGL_AUTO_ROWSTRIDE);
|
|
|
|
|
1998-11-06 08:51:39 +08:00
|
|
|
gimp_progress_update ((double) (i + tileheight) / (double) height);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (data);
|
2012-11-19 06:22:07 +08:00
|
|
|
g_object_unref (buffer);
|
1998-11-06 08:51:39 +08:00
|
|
|
fclose (fp);
|
2000-01-26 01:46:56 +08:00
|
|
|
|
2012-11-19 06:22:07 +08:00
|
|
|
gimp_progress_update (1.0);
|
|
|
|
|
1998-11-06 08:51:39 +08:00
|
|
|
return image_ID;
|
|
|
|
}
|
|
|
|
|
2000-06-05 19:38:35 +08:00
|
|
|
static gboolean
|
2014-10-06 00:06:03 +08:00
|
|
|
save_image (GFile *file,
|
2008-10-20 14:04:39 +08:00
|
|
|
const gchar *prefix,
|
|
|
|
const gchar *comment,
|
|
|
|
gboolean save_mask,
|
|
|
|
gint32 image_ID,
|
|
|
|
gint32 drawable_ID,
|
2008-08-19 03:08:54 +08:00
|
|
|
GError **error)
|
1998-11-06 08:51:39 +08:00
|
|
|
{
|
2014-10-06 00:06:03 +08:00
|
|
|
GOutputStream *output;
|
|
|
|
GeglBuffer *buffer;
|
|
|
|
gint width, height, colors, dark;
|
|
|
|
gint intbits, lineints, need_comma, nints, rowoffset, tileheight;
|
|
|
|
gint c, i, j, k, thisbit;
|
|
|
|
gboolean has_alpha;
|
|
|
|
gint bpp;
|
|
|
|
guchar *data = NULL;
|
|
|
|
guchar *cmap;
|
|
|
|
const gchar *intfmt;
|
1998-11-06 08:51:39 +08:00
|
|
|
|
2005-08-10 04:49:55 +08:00
|
|
|
#if 0
|
|
|
|
if (save_mask)
|
|
|
|
g_printerr ("%s: save_mask '%s'\n", G_STRFUNC, prefix);
|
|
|
|
else
|
|
|
|
g_printerr ("%s: save_image '%s'\n", G_STRFUNC, prefix);
|
|
|
|
#endif
|
|
|
|
|
2012-11-19 06:22:07 +08:00
|
|
|
cmap = gimp_image_get_colormap (image_ID, &colors);
|
1998-11-06 08:51:39 +08:00
|
|
|
|
2003-11-16 00:51:20 +08:00
|
|
|
if (! gimp_drawable_is_indexed (drawable_ID) || colors > 2)
|
1998-11-06 08:51:39 +08:00
|
|
|
{
|
|
|
|
/* The image is not black-and-white. */
|
2016-02-16 09:35:43 +08:00
|
|
|
g_message (_("The image which you are trying to export as "
|
2008-10-20 14:04:39 +08:00
|
|
|
"an XBM contains more than two colors.\n\n"
|
|
|
|
"Please convert it to a black and white "
|
|
|
|
"(1-bit) indexed image and try again."));
|
2012-11-19 06:22:07 +08:00
|
|
|
g_free (cmap);
|
2000-06-05 19:38:35 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
has_alpha = gimp_drawable_has_alpha (drawable_ID);
|
|
|
|
|
2008-08-19 03:08:54 +08:00
|
|
|
if (! has_alpha && save_mask)
|
2000-06-05 19:38:35 +08:00
|
|
|
{
|
|
|
|
g_message (_("You cannot save a cursor mask for an image\n"
|
2008-10-20 14:04:39 +08:00
|
|
|
"which has no alpha channel."));
|
1998-11-06 08:51:39 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-11-19 06:22:07 +08:00
|
|
|
buffer = gimp_drawable_get_buffer (drawable_ID);
|
|
|
|
width = gegl_buffer_get_width (buffer);
|
|
|
|
height = gegl_buffer_get_height (buffer);
|
|
|
|
bpp = gimp_drawable_bpp (drawable_ID);
|
2000-06-05 19:38:35 +08:00
|
|
|
|
1998-11-06 08:51:39 +08:00
|
|
|
/* Figure out which color is black, and which is white. */
|
|
|
|
dark = 0;
|
|
|
|
if (colors > 1)
|
|
|
|
{
|
2000-06-05 19:38:35 +08:00
|
|
|
gint first, second;
|
1998-11-06 08:51:39 +08:00
|
|
|
|
|
|
|
/* Maybe the second color is darker than the first. */
|
2000-06-05 19:38:35 +08:00
|
|
|
first = (cmap[0] * cmap[0]) + (cmap[1] * cmap[1]) + (cmap[2] * cmap[2]);
|
1998-11-06 08:51:39 +08:00
|
|
|
second = (cmap[3] * cmap[3]) + (cmap[4] * cmap[4]) + (cmap[5] * cmap[5]);
|
|
|
|
|
|
|
|
if (second < first)
|
2008-10-20 14:04:39 +08:00
|
|
|
dark = 1;
|
1998-11-06 08:51:39 +08:00
|
|
|
}
|
|
|
|
|
2016-02-16 09:35:43 +08:00
|
|
|
gimp_progress_init_printf (_("Exporting '%s'"),
|
2014-10-06 00:06:03 +08:00
|
|
|
gimp_file_get_utf8_name (file));
|
2014-07-23 22:39:00 +08:00
|
|
|
|
2014-10-06 00:06:03 +08:00
|
|
|
output = G_OUTPUT_STREAM (g_file_replace (file,
|
|
|
|
NULL, FALSE, G_FILE_CREATE_NONE,
|
|
|
|
NULL, error));
|
|
|
|
if (output)
|
|
|
|
{
|
|
|
|
GOutputStream *buffered;
|
|
|
|
|
|
|
|
buffered = g_buffered_output_stream_new (output);
|
|
|
|
g_object_unref (output);
|
|
|
|
|
|
|
|
output = buffered;
|
|
|
|
}
|
|
|
|
else
|
1998-11-06 08:51:39 +08:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Maybe write the image comment. */
|
2002-11-08 03:09:01 +08:00
|
|
|
#if 0
|
|
|
|
/* DISABLED - see http://bugzilla.gnome.org/show_bug.cgi?id=82763 */
|
|
|
|
/* a future version should write the comment at the end of the file */
|
2000-06-05 19:38:35 +08:00
|
|
|
if (*comment)
|
2014-10-06 00:06:03 +08:00
|
|
|
{
|
|
|
|
if (! print (output, error, "/* %s */\n", comment))
|
|
|
|
goto fail;
|
|
|
|
}
|
2002-11-08 03:09:01 +08:00
|
|
|
#endif
|
1998-11-06 08:51:39 +08:00
|
|
|
|
|
|
|
/* Write out the image height and width. */
|
2014-10-06 00:06:03 +08:00
|
|
|
if (! print (output, error, "#define %s_width %d\n", prefix, width) ||
|
|
|
|
! print (output, error, "#define %s_height %d\n", prefix, height))
|
|
|
|
goto fail;
|
1998-11-06 08:51:39 +08:00
|
|
|
|
|
|
|
/* Write out the hotspot, if any. */
|
2000-03-04 08:24:39 +08:00
|
|
|
if (xsvals.use_hot)
|
1998-11-06 08:51:39 +08:00
|
|
|
{
|
2014-10-06 00:06:03 +08:00
|
|
|
if (! print (output, error,
|
|
|
|
"#define %s_x_hot %d\n", prefix, xsvals.x_hot) ||
|
|
|
|
! print (output, error,
|
|
|
|
"#define %s_y_hot %d\n", prefix, xsvals.y_hot))
|
|
|
|
goto fail;
|
1998-11-06 08:51:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Now write the actual data. */
|
|
|
|
if (xsvals.x10_format)
|
|
|
|
{
|
|
|
|
/* We can fit 9 hex shorts on a single line. */
|
|
|
|
lineints = 9;
|
|
|
|
intbits = 16;
|
|
|
|
intfmt = " 0x%04x";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* We can fit 12 hex chars on a single line. */
|
|
|
|
lineints = 12;
|
|
|
|
intbits = 8;
|
|
|
|
intfmt = " 0x%02x";
|
|
|
|
}
|
|
|
|
|
2014-10-06 00:06:03 +08:00
|
|
|
if (! print (output, error,
|
|
|
|
"static %s %s_bits[] = {\n ",
|
|
|
|
xsvals.x10_format ? "unsigned short" : "unsigned char", prefix))
|
|
|
|
goto fail;
|
1998-11-06 08:51:39 +08:00
|
|
|
|
|
|
|
/* Allocate a new set of pixels. */
|
|
|
|
tileheight = gimp_tile_height ();
|
2000-06-05 19:38:35 +08:00
|
|
|
data = (guchar *) g_malloc (width * tileheight * bpp);
|
1998-11-06 08:51:39 +08:00
|
|
|
|
|
|
|
/* Write out the integers. */
|
|
|
|
need_comma = 0;
|
|
|
|
nints = 0;
|
|
|
|
for (i = 0; i < height; i += tileheight)
|
|
|
|
{
|
|
|
|
/* Get a horizontal slice of the image. */
|
|
|
|
tileheight = MIN (tileheight, height - i);
|
2012-11-19 06:22:07 +08:00
|
|
|
|
|
|
|
gegl_buffer_get (buffer, GEGL_RECTANGLE (0, i, width, tileheight), 1.0,
|
|
|
|
NULL, data,
|
|
|
|
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
|
1998-11-06 08:51:39 +08:00
|
|
|
|
|
|
|
#ifdef VERBOSE
|
|
|
|
if (verbose > 1)
|
2008-10-20 14:04:39 +08:00
|
|
|
printf ("XBM: writing %dx(%d+%d) pixel region\n",
|
|
|
|
width, i, tileheight);
|
1998-11-06 08:51:39 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
for (j = 0; j < tileheight; j ++)
|
2008-10-20 14:04:39 +08:00
|
|
|
{
|
|
|
|
/* Write out a row at a time. */
|
|
|
|
rowoffset = j * width * bpp;
|
|
|
|
c = 0;
|
|
|
|
thisbit = 0;
|
|
|
|
|
|
|
|
for (k = 0; k < width * bpp; k += bpp)
|
|
|
|
{
|
|
|
|
if (k != 0 && thisbit == intbits)
|
|
|
|
{
|
|
|
|
/* Output a completed integer. */
|
|
|
|
if (need_comma)
|
2014-10-06 00:06:03 +08:00
|
|
|
{
|
|
|
|
if (! print (output, error, ","))
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2008-10-20 14:04:39 +08:00
|
|
|
need_comma = 1;
|
|
|
|
|
|
|
|
/* Maybe start a new line. */
|
|
|
|
if (nints ++ >= lineints)
|
|
|
|
{
|
|
|
|
nints = 1;
|
2014-10-06 00:06:03 +08:00
|
|
|
|
|
|
|
if (! print (output, error, "\n "))
|
|
|
|
goto fail;
|
2008-10-20 14:04:39 +08:00
|
|
|
}
|
2014-10-06 00:06:03 +08:00
|
|
|
|
|
|
|
if (! print (output, error, intfmt, c))
|
|
|
|
goto fail;
|
2008-10-20 14:04:39 +08:00
|
|
|
|
|
|
|
/* Start a new integer. */
|
|
|
|
c = 0;
|
|
|
|
thisbit = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Pack INTBITS pixels into an integer. */
|
|
|
|
if (save_mask)
|
|
|
|
{
|
|
|
|
c |= ((data[rowoffset + k + 1] < 128) ? 0 : 1) << (thisbit ++);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (has_alpha && (data[rowoffset + k + 1] < 128))
|
|
|
|
c |= 0 << (thisbit ++);
|
|
|
|
else
|
|
|
|
c |= ((data[rowoffset + k] == dark) ? 1 : 0) << (thisbit ++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (thisbit != 0)
|
|
|
|
{
|
|
|
|
/* Write out the last oddball int. */
|
|
|
|
if (need_comma)
|
2014-10-06 00:06:03 +08:00
|
|
|
{
|
|
|
|
if (! print (output, error, ","))
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2008-10-20 14:04:39 +08:00
|
|
|
need_comma = 1;
|
|
|
|
|
|
|
|
/* Maybe start a new line. */
|
|
|
|
if (nints ++ == lineints)
|
|
|
|
{
|
|
|
|
nints = 1;
|
2014-10-06 00:06:03 +08:00
|
|
|
|
|
|
|
if (! print (output, error, "\n "))
|
|
|
|
goto fail;
|
2008-10-20 14:04:39 +08:00
|
|
|
}
|
2014-10-06 00:06:03 +08:00
|
|
|
|
|
|
|
if (! print (output, error, intfmt, c))
|
|
|
|
goto fail;
|
2008-10-20 14:04:39 +08:00
|
|
|
}
|
|
|
|
}
|
1998-11-06 08:51:39 +08:00
|
|
|
|
|
|
|
gimp_progress_update ((double) (i + tileheight) / (double) height);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write the trailer. */
|
2014-10-06 00:06:03 +08:00
|
|
|
if (! print (output, error, " };\n"))
|
|
|
|
goto fail;
|
2012-11-19 06:22:07 +08:00
|
|
|
|
2014-10-06 00:06:03 +08:00
|
|
|
if (! g_output_stream_close (output, NULL, error))
|
|
|
|
goto fail;
|
2008-08-19 03:08:54 +08:00
|
|
|
|
2013-01-17 07:48:13 +08:00
|
|
|
g_free (data);
|
2014-10-06 00:06:03 +08:00
|
|
|
g_object_unref (buffer);
|
|
|
|
g_object_unref (output);
|
2013-01-17 07:48:13 +08:00
|
|
|
|
2012-11-19 06:22:07 +08:00
|
|
|
gimp_progress_update (1.0);
|
|
|
|
|
1998-11-06 08:51:39 +08:00
|
|
|
return TRUE;
|
2014-10-06 00:06:03 +08:00
|
|
|
|
|
|
|
fail:
|
|
|
|
|
|
|
|
g_free (data);
|
|
|
|
g_object_unref (buffer);
|
|
|
|
g_object_unref (output);
|
|
|
|
|
|
|
|
return FALSE;
|
1998-11-06 08:51:39 +08:00
|
|
|
}
|
|
|
|
|
2004-05-20 09:19:47 +08:00
|
|
|
static gboolean
|
2000-01-11 23:48:00 +08:00
|
|
|
save_dialog (gint32 drawable_ID)
|
1999-10-14 10:11:52 +08:00
|
|
|
{
|
2014-06-23 05:01:31 +08:00
|
|
|
GtkWidget *dialog;
|
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *toggle;
|
|
|
|
GtkWidget *table;
|
|
|
|
GtkWidget *entry;
|
|
|
|
GtkWidget *spinbutton;
|
|
|
|
GtkAdjustment *adj;
|
|
|
|
gboolean run;
|
1998-11-06 08:51:39 +08:00
|
|
|
|
2009-07-21 20:10:29 +08:00
|
|
|
dialog = gimp_export_dialog_new (_("XBM"), PLUG_IN_BINARY, SAVE_PROC);
|
2005-09-10 02:38:00 +08:00
|
|
|
|
1998-11-06 08:51:39 +08:00
|
|
|
/* parameter settings */
|
2004-05-20 09:19:47 +08:00
|
|
|
frame = gimp_frame_new (_("XBM Options"));
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (frame), 12);
|
2009-07-21 20:10:29 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (gimp_export_dialog_get_content_area (dialog)),
|
2005-09-10 02:38:00 +08:00
|
|
|
frame, TRUE, TRUE, 0);
|
1998-11-06 08:51:39 +08:00
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2011-09-30 18:17:53 +08:00
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
|
1998-11-06 08:51:39 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (frame), vbox);
|
|
|
|
|
|
|
|
/* X10 format */
|
2004-06-22 03:15:08 +08:00
|
|
|
toggle = gtk_check_button_new_with_mnemonic (_("_X10 format bitmap"));
|
2000-01-11 23:48:00 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
|
1999-01-16 01:35:04 +08:00
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), xsvals.x10_format);
|
1998-11-06 08:51:39 +08:00
|
|
|
gtk_widget_show (toggle);
|
|
|
|
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (toggle, "toggled",
|
2002-01-16 02:35:29 +08:00
|
|
|
G_CALLBACK (gimp_toggle_button_update),
|
|
|
|
&xsvals.x10_format);
|
|
|
|
|
2000-01-26 01:46:56 +08:00
|
|
|
table = gtk_table_new (2, 2, FALSE);
|
2004-05-20 09:19:47 +08:00
|
|
|
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
|
|
|
|
gtk_table_set_row_spacings (GTK_TABLE (table), 6);
|
2000-01-26 01:46:56 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (table);
|
1998-11-06 08:51:39 +08:00
|
|
|
|
2000-01-26 01:46:56 +08:00
|
|
|
/* prefix */
|
2002-01-16 02:35:29 +08:00
|
|
|
entry = gtk_entry_new ();
|
|
|
|
gtk_entry_set_max_length (GTK_ENTRY (entry), MAX_PREFIX);
|
1998-11-06 08:51:39 +08:00
|
|
|
gtk_entry_set_text (GTK_ENTRY (entry), xsvals.prefix);
|
2000-01-31 11:13:02 +08:00
|
|
|
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
|
2008-10-20 14:04:39 +08:00
|
|
|
_("_Identifier prefix:"), 0.0, 0.5,
|
|
|
|
entry, 1, TRUE);
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (entry, "changed",
|
2002-01-16 02:35:29 +08:00
|
|
|
G_CALLBACK (prefix_entry_callback),
|
|
|
|
NULL);
|
1998-11-06 08:51:39 +08:00
|
|
|
|
2000-01-26 01:46:56 +08:00
|
|
|
/* comment string. */
|
2002-11-08 03:09:01 +08:00
|
|
|
#if 0
|
2003-11-06 23:27:05 +08:00
|
|
|
/* DISABLED - see http://bugzilla.gnome.org/show_bug.cgi?id=82763 */
|
2002-01-16 02:35:29 +08:00
|
|
|
entry = gtk_entry_new ();
|
|
|
|
gtk_entry_set_max_length (GTK_ENTRY (entry), MAX_COMMENT);
|
2001-11-12 02:35:25 +08:00
|
|
|
gtk_widget_set_size_request (entry, 240, -1);
|
2000-01-26 01:46:56 +08:00
|
|
|
gtk_entry_set_text (GTK_ENTRY (entry), xsvals.comment);
|
2000-01-31 11:13:02 +08:00
|
|
|
gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
|
2008-10-20 14:04:39 +08:00
|
|
|
_("Comment:"), 0.0, 0.5,
|
|
|
|
entry, 1, TRUE);
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (entry, "changed",
|
2002-01-16 02:35:29 +08:00
|
|
|
G_CALLBACK (comment_entry_callback),
|
|
|
|
NULL);
|
2002-11-08 03:09:01 +08:00
|
|
|
#endif
|
1998-11-06 08:51:39 +08:00
|
|
|
|
2000-03-04 08:24:39 +08:00
|
|
|
/* hotspot toggle */
|
2004-06-22 03:15:08 +08:00
|
|
|
toggle = gtk_check_button_new_with_mnemonic (_("_Write hot spot values"));
|
2000-03-04 08:24:39 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), xsvals.use_hot);
|
|
|
|
gtk_widget_show (toggle);
|
|
|
|
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (toggle, "toggled",
|
2002-01-16 02:35:29 +08:00
|
|
|
G_CALLBACK (gimp_toggle_button_update),
|
|
|
|
&xsvals.use_hot);
|
|
|
|
|
2000-03-04 08:24:39 +08:00
|
|
|
table = gtk_table_new (2, 2, FALSE);
|
2004-05-20 09:19:47 +08:00
|
|
|
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
|
|
|
|
gtk_table_set_row_spacings (GTK_TABLE (table), 6);
|
2000-03-04 08:24:39 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (table);
|
|
|
|
|
2011-05-11 17:41:26 +08:00
|
|
|
g_object_bind_property (toggle, "active",
|
|
|
|
table, "sensitive",
|
|
|
|
G_BINDING_SYNC_CREATE);
|
2000-03-04 08:24:39 +08:00
|
|
|
|
2014-06-23 05:01:31 +08:00
|
|
|
adj = (GtkAdjustment *)
|
|
|
|
gtk_adjustment_new (xsvals.x_hot, 0,
|
|
|
|
gimp_drawable_width (drawable_ID) - 1,
|
|
|
|
1, 10, 0);
|
|
|
|
spinbutton = gtk_spin_button_new (adj, 1.0, 0);
|
|
|
|
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
|
2000-03-04 08:24:39 +08:00
|
|
|
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
|
2008-10-20 14:04:39 +08:00
|
|
|
_("Hot spot _X:"), 0.0, 0.5,
|
|
|
|
spinbutton, 1, TRUE);
|
2014-06-23 05:01:31 +08:00
|
|
|
|
2005-07-01 00:03:24 +08:00
|
|
|
g_signal_connect (adj, "value-changed",
|
2002-01-16 02:35:29 +08:00
|
|
|
G_CALLBACK (gimp_int_adjustment_update),
|
|
|
|
&xsvals.x_hot);
|
2000-03-04 08:24:39 +08:00
|
|
|
|
2014-06-23 05:01:31 +08:00
|
|
|
adj = (GtkAdjustment *)
|
|
|
|
gtk_adjustment_new (xsvals.y_hot, 0,
|
|
|
|
gimp_drawable_height (drawable_ID) - 1,
|
|
|
|
1, 10, 0);
|
|
|
|
spinbutton = gtk_spin_button_new (adj, 1.0, 0);
|
|
|
|
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbutton), TRUE);
|
2000-03-04 08:24:39 +08:00
|
|
|
gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
|
2008-10-20 14:04:39 +08:00
|
|
|
_("Hot spot _Y:"), 0.0, 0.5,
|
|
|
|
spinbutton, 1, TRUE);
|
2014-06-23 05:01:31 +08:00
|
|
|
|
2005-07-01 00:03:24 +08:00
|
|
|
g_signal_connect (adj, "value-changed",
|
2002-01-16 02:35:29 +08:00
|
|
|
G_CALLBACK (gimp_int_adjustment_update),
|
|
|
|
&xsvals.y_hot);
|
2000-03-04 08:24:39 +08:00
|
|
|
|
2000-06-05 19:38:35 +08:00
|
|
|
/* mask file */
|
2004-05-20 09:19:47 +08:00
|
|
|
frame = gimp_frame_new (_("Mask File"));
|
2000-06-05 19:38:35 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
|
|
|
table = gtk_table_new (2, 2, FALSE);
|
2004-05-20 09:19:47 +08:00
|
|
|
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
|
|
|
|
gtk_table_set_row_spacings (GTK_TABLE (table), 6);
|
2000-06-05 19:38:35 +08:00
|
|
|
gtk_container_add (GTK_CONTAINER (frame), table);
|
|
|
|
gtk_widget_show (table);
|
|
|
|
|
2004-06-22 03:15:08 +08:00
|
|
|
toggle = gtk_check_button_new_with_mnemonic (_("W_rite extra mask file"));
|
2000-06-05 19:38:35 +08:00
|
|
|
gtk_table_attach_defaults (GTK_TABLE (table), toggle, 0, 2, 0, 1);
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), xsvals.write_mask);
|
|
|
|
gtk_widget_show (toggle);
|
|
|
|
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (toggle, "toggled",
|
2002-01-16 02:35:29 +08:00
|
|
|
G_CALLBACK (gimp_toggle_button_update),
|
|
|
|
&xsvals.write_mask);
|
|
|
|
|
|
|
|
entry = gtk_entry_new ();
|
|
|
|
gtk_entry_set_max_length (GTK_ENTRY (entry), MAX_MASK_EXT);
|
2000-06-05 19:38:35 +08:00
|
|
|
gtk_entry_set_text (GTK_ENTRY (entry), xsvals.mask_ext);
|
|
|
|
gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
|
2008-10-20 14:04:39 +08:00
|
|
|
_("_Mask file extension:"), 0.0, 0.5,
|
|
|
|
entry, 1, TRUE);
|
2003-01-07 14:16:02 +08:00
|
|
|
g_signal_connect (entry, "changed",
|
2002-01-16 02:35:29 +08:00
|
|
|
G_CALLBACK (mask_ext_entry_callback),
|
|
|
|
NULL);
|
2000-06-05 19:38:35 +08:00
|
|
|
|
2011-05-11 17:41:26 +08:00
|
|
|
g_object_bind_property (toggle, "active",
|
|
|
|
entry, "sensitive",
|
|
|
|
G_BINDING_SYNC_CREATE);
|
2000-06-05 19:38:35 +08:00
|
|
|
|
|
|
|
gtk_widget_set_sensitive (frame, gimp_drawable_has_alpha (drawable_ID));
|
|
|
|
|
1998-11-06 08:51:39 +08:00
|
|
|
/* Done. */
|
|
|
|
gtk_widget_show (vbox);
|
2005-09-10 02:38:00 +08:00
|
|
|
gtk_widget_show (dialog);
|
1998-11-06 08:51:39 +08:00
|
|
|
|
2005-09-10 02:38:00 +08:00
|
|
|
run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
|
1998-11-06 08:51:39 +08:00
|
|
|
|
2005-09-10 02:38:00 +08:00
|
|
|
gtk_widget_destroy (dialog);
|
1998-11-06 08:51:39 +08:00
|
|
|
|
2003-11-06 23:27:05 +08:00
|
|
|
return run;
|
|
|
|
}
|
1998-11-06 08:51:39 +08:00
|
|
|
|
2014-10-06 00:06:03 +08:00
|
|
|
static gboolean
|
|
|
|
print (GOutputStream *output,
|
|
|
|
GError **error,
|
|
|
|
const gchar *format,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
gboolean success;
|
|
|
|
|
|
|
|
va_start (args, format);
|
|
|
|
success = g_output_stream_vprintf (output, NULL, NULL,
|
|
|
|
error, format, args);
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
1998-11-06 08:51:39 +08:00
|
|
|
/* Update the comment string. */
|
2002-11-08 03:09:01 +08:00
|
|
|
#if 0
|
|
|
|
/* DISABLED - see http://bugzilla.gnome.org/show_bug.cgi?id=82763 */
|
1998-11-06 08:51:39 +08:00
|
|
|
static void
|
1999-10-14 10:11:52 +08:00
|
|
|
comment_entry_callback (GtkWidget *widget,
|
2008-10-20 14:04:39 +08:00
|
|
|
gpointer data)
|
1998-11-06 08:51:39 +08:00
|
|
|
{
|
|
|
|
memset (xsvals.comment, 0, sizeof (xsvals.comment));
|
|
|
|
strncpy (xsvals.comment,
|
2008-10-20 14:04:39 +08:00
|
|
|
gtk_entry_get_text (GTK_ENTRY (widget)), MAX_COMMENT);
|
1998-11-06 08:51:39 +08:00
|
|
|
}
|
2002-11-08 03:09:01 +08:00
|
|
|
#endif
|
1998-11-06 08:51:39 +08:00
|
|
|
|
|
|
|
static void
|
1999-10-14 10:11:52 +08:00
|
|
|
prefix_entry_callback (GtkWidget *widget,
|
2008-10-20 14:04:39 +08:00
|
|
|
gpointer data)
|
1998-11-06 08:51:39 +08:00
|
|
|
{
|
|
|
|
memset (xsvals.prefix, 0, sizeof (xsvals.prefix));
|
2000-01-26 01:46:56 +08:00
|
|
|
strncpy (xsvals.prefix,
|
2008-10-20 14:04:39 +08:00
|
|
|
gtk_entry_get_text (GTK_ENTRY (widget)), MAX_PREFIX);
|
1998-11-06 08:51:39 +08:00
|
|
|
}
|
|
|
|
|
2000-06-05 19:38:35 +08:00
|
|
|
static void
|
|
|
|
mask_ext_entry_callback (GtkWidget *widget,
|
2008-10-20 14:04:39 +08:00
|
|
|
gpointer data)
|
2000-06-05 19:38:35 +08:00
|
|
|
{
|
2005-08-10 18:22:34 +08:00
|
|
|
memset (xsvals.mask_ext, 0, sizeof (xsvals.mask_ext));
|
2000-06-05 19:38:35 +08:00
|
|
|
strncpy (xsvals.mask_ext,
|
2008-10-20 14:04:39 +08:00
|
|
|
gtk_entry_get_text (GTK_ENTRY (widget)), MAX_MASK_EXT);
|
2000-06-05 19:38:35 +08:00
|
|
|
}
|