gimp/plug-ins/common/file-xpm.c

875 lines
26 KiB
C
Raw Normal View History

/* GIMP - The GNU Image Manipulation Program
1997-11-25 06:05:25 +08:00
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software: you can redistribute it and/or modify
1997-11-25 06:05:25 +08:00
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
1997-11-25 06:05:25 +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
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1997-11-25 06:05:25 +08:00
*/
/* XPM plugin version 1.2.7 */
1998-03-17 08:31:58 +08:00
/*
1.2.7 fixes saving unused transparency (bug #4560)
1.2.6 fixes crash when saving indexed images (bug #109567)
1.2.5 only creates a "None" color entry if the image has alpha (bug #108034)
1.2.4 displays an error message if saving fails (bug #87588)
1.2.3 fixes bug when running in noninteractive mode
changes alpha_threshold range from [0, 1] to [0,255] for consistency with
the threshold_alpha plugin
1.2.2 fixes bug that generated bad digits on images with more than 20000
colors. (thanks, yanele)
1998-03-17 08:31:58 +08:00
parses gtkrc (thanks, yosh)
doesn't load parameter screen on images that don't have alpha
1.2.1 fixes some minor bugs -- spaces in #XXXXXX strings, small typos in code.
1.2 compute color indexes so that we don't have to use XpmSaveXImage*
Previous...Inherited code from Ray Lehtiniemi, who inherited it from S & P.
*/
1997-11-25 06:05:25 +08:00
configure.in removed tips files, AC_SUBST GIMP_PLUGINS and GIMP_MODULES so * configure.in * Makefile.am: removed tips files, AC_SUBST GIMP_PLUGINS and GIMP_MODULES so you can easily skip those parts of the build * acinclude.m4 * config.sub * config.guess * ltconfig * ltmain.sh: libtool 1.3.2 * app/fileops.c: shuffle #includes to avoid warning about MIN and MAX [ The following is a big i18n patch from David Monniaux <david.monniaux@ens.fr> ] * tips/gimp_conseils.fr.txt * tips/gimp_tips.txt * tips/Makefile.am * configure.in: moved tips to separate dir * po-plugins: new dir for plug-in translation files * configure.in: add po-plugins dir and POTFILES processing * app/boundary.c * app/brightness_contrast.c * app/by_color_select.c * app/color_balance.c * app/convert.c * app/curves.c * app/free_select.c * app/gdisplay.c * app/gimpimage.c * app/gimpunit.c * app/gradient.c * app/gradient_select.c * app/install.c * app/session.c: various i18n tweaks * app/tips_dialog.c: localize tips filename * libgimp/gimpunit.c * libgimp/gimpunitmenu.c: #include "config.h" * plug-ins/CEL * plug-ins/CML_explorer * plug-ins/Lighting * plug-ins/apply_lens * plug-ins/autostretch_hsv * plug-ins/blur * plug-ins/bmp * plug-ins/borderaverage * plug-ins/bumpmap * plug-ins/bz2 * plug-ins/checkerboard * plug-ins/colorify * plug-ins/compose * plug-ins/convmatrix * plug-ins/cubism * plug-ins/depthmerge * plug-ins/destripe * plug-ins/gif * plug-ins/gifload * plug-ins/jpeg * plug-ins/mail * plug-ins/oilify * plug-ins/png * plug-ins/print * plug-ins/ps * plug-ins/xbm * plug-ins/xpm * plug-ins/xwd: plug-in i18n stuff -Yosh
1999-05-30 00:35:47 +08:00
#include "config.h"
2000-01-11 23:48:00 +08:00
1997-11-25 06:05:25 +08:00
#include <string.h>
2000-01-11 23:48:00 +08:00
#include <glib/gstdio.h>
2000-01-11 23:48:00 +08:00
#include <gdk/gdk.h> /* For GDK_WINDOWING_WIN32 */
#ifndef GDK_WINDOWING_X11
#ifndef XPM_NO_X
#define XPM_NO_X
#endif
#else
#include <X11/Xlib.h>
#endif
#include <X11/xpm.h>
2000-01-11 23:48:00 +08:00
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
configure.in removed tips files, AC_SUBST GIMP_PLUGINS and GIMP_MODULES so * configure.in * Makefile.am: removed tips files, AC_SUBST GIMP_PLUGINS and GIMP_MODULES so you can easily skip those parts of the build * acinclude.m4 * config.sub * config.guess * ltconfig * ltmain.sh: libtool 1.3.2 * app/fileops.c: shuffle #includes to avoid warning about MIN and MAX [ The following is a big i18n patch from David Monniaux <david.monniaux@ens.fr> ] * tips/gimp_conseils.fr.txt * tips/gimp_tips.txt * tips/Makefile.am * configure.in: moved tips to separate dir * po-plugins: new dir for plug-in translation files * configure.in: add po-plugins dir and POTFILES processing * app/boundary.c * app/brightness_contrast.c * app/by_color_select.c * app/color_balance.c * app/convert.c * app/curves.c * app/free_select.c * app/gdisplay.c * app/gimpimage.c * app/gimpunit.c * app/gradient.c * app/gradient_select.c * app/install.c * app/session.c: various i18n tweaks * app/tips_dialog.c: localize tips filename * libgimp/gimpunit.c * libgimp/gimpunitmenu.c: #include "config.h" * plug-ins/CEL * plug-ins/CML_explorer * plug-ins/Lighting * plug-ins/apply_lens * plug-ins/autostretch_hsv * plug-ins/blur * plug-ins/bmp * plug-ins/borderaverage * plug-ins/bumpmap * plug-ins/bz2 * plug-ins/checkerboard * plug-ins/colorify * plug-ins/compose * plug-ins/convmatrix * plug-ins/cubism * plug-ins/depthmerge * plug-ins/destripe * plug-ins/gif * plug-ins/gifload * plug-ins/jpeg * plug-ins/mail * plug-ins/oilify * plug-ins/png * plug-ins/print * plug-ins/ps * plug-ins/xbm * plug-ins/xpm * plug-ins/xwd: plug-in i18n stuff -Yosh
1999-05-30 00:35:47 +08:00
#include "libgimp/stdplugins-intl.h"
1997-11-25 06:05:25 +08:00
#define LOAD_PROC "file-xpm-load"
#define EXPORT_PROC "file-xpm-export"
#define PLUG_IN_BINARY "file-xpm"
#define PLUG_IN_ROLE "gimp-file-xpm"
#define SCALE_WIDTH 125
1997-11-25 06:05:25 +08:00
1998-02-25 14:21:26 +08:00
typedef struct
{
1999-10-04 07:48:33 +08:00
guchar r;
guchar g;
guchar b;
1998-02-25 14:21:26 +08:00
} rgbkey;
typedef struct _Xpm Xpm;
typedef struct _XpmClass XpmClass;
struct _Xpm
{
GimpPlugIn parent_instance;
};
struct _XpmClass
{
GimpPlugInClass parent_class;
};
#define XPM_TYPE (xpm_get_type ())
#define XPM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XPM_TYPE, Xpm))
GType xpm_get_type (void) G_GNUC_CONST;
static GList * xpm_query_procedures (GimpPlugIn *plug_in);
static GimpProcedure * xpm_create_procedure (GimpPlugIn *plug_in,
const gchar *name);
static GimpValueArray * xpm_load (GimpProcedure *procedure,
GimpRunMode run_mode,
GFile *file,
GimpMetadata *metadata,
GimpMetadataLoadFlags *flags,
GimpProcedureConfig *config,
gpointer run_data);
static GimpValueArray * xpm_export (GimpProcedure *procedure,
GimpRunMode run_mode,
GimpImage *image,
GFile *file,
GimpMetadata *metadata,
GimpProcedureConfig *config,
gpointer run_data);
static GimpImage * load_image (GFile *file,
GError **error);
static guchar * parse_colors (XpmImage *xpm_image);
static void parse_image (GimpImage *image,
XpmImage *xpm_image,
guchar *cmap);
static gboolean export_image (GFile *file,
GimpImage *image,
GimpDrawable *drawable,
GObject *config,
GError **error);
static gboolean save_dialog (GimpImage *image,
GimpProcedure *procedure,
GObject *config);
G_DEFINE_TYPE (Xpm, xpm, GIMP_TYPE_PLUG_IN)
GIMP_MAIN (XPM_TYPE)
DEFINE_STD_SET_I18N
static const gchar linenoise [] =
" .+@#$%&*=-;>,')!~{]^/(_:<[}|1234567890abcdefghijklmnopqrstuvwxyz\
ABCDEFGHIJKLMNOPQRSTUVWXYZ`";
configure.in po-plug-ins/POTFILES.in plug-ins/common/Makefile.am 2000-01-25 Michael Natterer <mitch@gimp.org> * configure.in * po-plug-ins/POTFILES.in * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl * plug-ins/megawidget/*: removed. (There were only 3 functions left which were used by ~5 plugins, so I moved the resp. functions to the plugins). More preview stuff to come... * app/airbrush_blob.c * modules/colorsel_triangle.c * modules/colorsel_water.c: use G_PI instead of M_PI. * app/procedural_db.h * libgimp/gimpenums.h * plug-ins/script-fu/script-fu-constants.c * tools/pdbgen/enums.pl: new PDB return value STATUS_CANCEL which indicates that "Cancel" was pressed in a plugin dialog. (Useful only for file load/save plugins). * app/fileops.[ch] * app/menus.c: changes to handle STATUS_CANCEL correctly. Did some code cleanup in fileops.[ch]. Pop up a warning if File->Save failed. * app/plug_in.c: return_val[0] is of type PDB_STATUS, not PDB_INT32. * libgimp/gimpmath.h: new constant G_MAXRAND which equals to RAND_MAX if it exists or to G_MAXINT otherwise. * libgimp/gimpwidgets.[ch]: new function gimp_random_seed_new() which creates a spinbutton and a "Time" toggle. Call the function which does the "set_sensitive" magic from the radio button callback. * plug-ins/[75 plugins]: - Return STATUS_CANCEL in all file load/save dialogs if "Cancel" was pressed. - Standardized the file plugins' "run" functions. - Use G_PI and G_MAXRAND everywhere. - Added tons of scales and spinbuttons instead of text entries. - Applied uniform packing/spacings all over the place. - Reorganized some UIs (stuff like moving the preview to the top left corner of the dialog). - Removed many ui helper functions and callbacks and use the stuff from libgimp instead. - I tried not to restrict the range of possible values when I replaced entries with spinbuttons/scales but may have failed, though in some cases. Please test ;-) - #include <libgimp/gimpmath.h> where appropriate and use it's constants. - Indentation, s/int/gint/ et.al., code cleanup. RFC: The plugins are definitely not useable with GIMP 1.0 any more, so shouldn't we remove all the remaining compatibility stuff ??? (like "#ifdef GIMP_HAVE_PARASITES")
2000-01-26 01:46:56 +08:00
/* whether the image is color or not. global so I only have to pass
* one user value to the GHFunc
*/
static gboolean color;
configure.in po-plug-ins/POTFILES.in plug-ins/common/Makefile.am 2000-01-25 Michael Natterer <mitch@gimp.org> * configure.in * po-plug-ins/POTFILES.in * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl * plug-ins/megawidget/*: removed. (There were only 3 functions left which were used by ~5 plugins, so I moved the resp. functions to the plugins). More preview stuff to come... * app/airbrush_blob.c * modules/colorsel_triangle.c * modules/colorsel_water.c: use G_PI instead of M_PI. * app/procedural_db.h * libgimp/gimpenums.h * plug-ins/script-fu/script-fu-constants.c * tools/pdbgen/enums.pl: new PDB return value STATUS_CANCEL which indicates that "Cancel" was pressed in a plugin dialog. (Useful only for file load/save plugins). * app/fileops.[ch] * app/menus.c: changes to handle STATUS_CANCEL correctly. Did some code cleanup in fileops.[ch]. Pop up a warning if File->Save failed. * app/plug_in.c: return_val[0] is of type PDB_STATUS, not PDB_INT32. * libgimp/gimpmath.h: new constant G_MAXRAND which equals to RAND_MAX if it exists or to G_MAXINT otherwise. * libgimp/gimpwidgets.[ch]: new function gimp_random_seed_new() which creates a spinbutton and a "Time" toggle. Call the function which does the "set_sensitive" magic from the radio button callback. * plug-ins/[75 plugins]: - Return STATUS_CANCEL in all file load/save dialogs if "Cancel" was pressed. - Standardized the file plugins' "run" functions. - Use G_PI and G_MAXRAND everywhere. - Added tons of scales and spinbuttons instead of text entries. - Applied uniform packing/spacings all over the place. - Reorganized some UIs (stuff like moving the preview to the top left corner of the dialog). - Removed many ui helper functions and callbacks and use the stuff from libgimp instead. - I tried not to restrict the range of possible values when I replaced entries with spinbuttons/scales but may have failed, though in some cases. Please test ;-) - #include <libgimp/gimpmath.h> where appropriate and use it's constants. - Indentation, s/int/gint/ et.al., code cleanup. RFC: The plugins are definitely not useable with GIMP 1.0 any more, so shouldn't we remove all the remaining compatibility stuff ??? (like "#ifdef GIMP_HAVE_PARASITES")
2000-01-26 01:46:56 +08:00
/* bytes per pixel. global so I only have to pass one user value
* to the GHFunc
*/
static gint cpp;
1998-02-25 14:21:26 +08:00
1997-11-25 06:05:25 +08:00
static void
xpm_class_init (XpmClass *klass)
1997-11-25 06:05:25 +08:00
{
GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
plug_in_class->query_procedures = xpm_query_procedures;
plug_in_class->create_procedure = xpm_create_procedure;
plug_in_class->set_i18n = STD_SET_I18N;
1997-11-25 06:05:25 +08:00
}
static void
xpm_init (Xpm *xpm)
1997-11-25 06:05:25 +08:00
{
}
1997-11-25 06:05:25 +08:00
static GList *
xpm_query_procedures (GimpPlugIn *plug_in)
{
GList *list = NULL;
2012-11-26 09:39:44 +08:00
list = g_list_append (list, g_strdup (LOAD_PROC));
list = g_list_append (list, g_strdup (EXPORT_PROC));
return list;
}
static GimpProcedure *
xpm_create_procedure (GimpPlugIn *plug_in,
const gchar *name)
{
GimpProcedure *procedure = NULL;
1997-11-25 06:05:25 +08:00
if (! strcmp (name, LOAD_PROC))
1997-11-25 06:05:25 +08:00
{
procedure = gimp_load_procedure_new (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
xpm_load, NULL, NULL);
gimp_procedure_set_menu_label (procedure, _("X PixMap image"));
gimp_procedure_set_documentation (procedure,
"Load files in XPM (X11 Pixmap) format.",
"Load files in XPM (X11 Pixmap) format. "
"XPM is a portable image format "
"designed to be included in C source "
"code. XLib provides utility functions "
"to read this format. Newer code should "
"however be using gdk-pixbuf-csource "
"instead. XPM supports colored images, "
"unlike the XBM format which XPM was "
"designed to replace.",
name);
gimp_procedure_set_attribution (procedure,
"Spencer Kimball & Peter Mattis & "
"Ray Lehtiniemi",
"Spencer Kimball & Peter Mattis",
"1997");
gimp_file_procedure_set_mime_types (GIMP_FILE_PROCEDURE (procedure),
"image/x-pixmap");
gimp_file_procedure_set_extensions (GIMP_FILE_PROCEDURE (procedure),
"xpm");
gimp_file_procedure_set_magics (GIMP_FILE_PROCEDURE (procedure),
"0, string,/*\\040XPM\\040*/");
1997-11-25 06:05:25 +08:00
}
else if (! strcmp (name, EXPORT_PROC))
1997-11-25 06:05:25 +08:00
{
procedure = gimp_export_procedure_new (plug_in, name,
GIMP_PDB_PROC_TYPE_PLUGIN,
FALSE, xpm_export, NULL, NULL);
gimp_procedure_set_image_types (procedure, "*");
gimp_procedure_set_menu_label (procedure, _("X PixMap image"));
gimp_procedure_set_documentation (procedure,
"Export files in XPM (X11 Pixmap) format.",
"Export files in XPM (X11 Pixmap) format. "
"XPM is a portable image format "
"designed to be included in C source "
"code. XLib provides utility functions "
"to read this format. Newer code should "
"however be using gdk-pixbuf-csource "
"instead. XPM supports colored images, "
"unlike the XBM format which XPM was "
"designed to replace.",
name);
gimp_procedure_set_attribution (procedure,
"Spencer Kimball & Peter Mattis & "
"Ray Lehtiniemi & Nathan Summers",
"Spencer Kimball & Peter Mattis",
"1997");
gimp_file_procedure_set_format_name (GIMP_FILE_PROCEDURE (procedure),
_("XPM"));
gimp_file_procedure_set_mime_types (GIMP_FILE_PROCEDURE (procedure),
"image/x-pixmap");
gimp_file_procedure_set_extensions (GIMP_FILE_PROCEDURE (procedure),
"xpm");
gimp_procedure_add_int_argument (procedure, "threshold",
_("_Threshold"),
_("Alpha threshold"),
0, 255, 127,
G_PARAM_READWRITE);
}
return procedure;
}
1999-10-04 07:48:33 +08:00
static GimpValueArray *
xpm_load (GimpProcedure *procedure,
GimpRunMode run_mode,
GFile *file,
GimpMetadata *metadata,
GimpMetadataLoadFlags *flags,
GimpProcedureConfig *config,
gpointer run_data)
{
GimpValueArray *return_vals;
GimpImage *image;
GError *error = NULL;
configure.in po-plug-ins/POTFILES.in plug-ins/common/Makefile.am 2000-01-25 Michael Natterer <mitch@gimp.org> * configure.in * po-plug-ins/POTFILES.in * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl * plug-ins/megawidget/*: removed. (There were only 3 functions left which were used by ~5 plugins, so I moved the resp. functions to the plugins). More preview stuff to come... * app/airbrush_blob.c * modules/colorsel_triangle.c * modules/colorsel_water.c: use G_PI instead of M_PI. * app/procedural_db.h * libgimp/gimpenums.h * plug-ins/script-fu/script-fu-constants.c * tools/pdbgen/enums.pl: new PDB return value STATUS_CANCEL which indicates that "Cancel" was pressed in a plugin dialog. (Useful only for file load/save plugins). * app/fileops.[ch] * app/menus.c: changes to handle STATUS_CANCEL correctly. Did some code cleanup in fileops.[ch]. Pop up a warning if File->Save failed. * app/plug_in.c: return_val[0] is of type PDB_STATUS, not PDB_INT32. * libgimp/gimpmath.h: new constant G_MAXRAND which equals to RAND_MAX if it exists or to G_MAXINT otherwise. * libgimp/gimpwidgets.[ch]: new function gimp_random_seed_new() which creates a spinbutton and a "Time" toggle. Call the function which does the "set_sensitive" magic from the radio button callback. * plug-ins/[75 plugins]: - Return STATUS_CANCEL in all file load/save dialogs if "Cancel" was pressed. - Standardized the file plugins' "run" functions. - Use G_PI and G_MAXRAND everywhere. - Added tons of scales and spinbuttons instead of text entries. - Applied uniform packing/spacings all over the place. - Reorganized some UIs (stuff like moving the preview to the top left corner of the dialog). - Removed many ui helper functions and callbacks and use the stuff from libgimp instead. - I tried not to restrict the range of possible values when I replaced entries with spinbuttons/scales but may have failed, though in some cases. Please test ;-) - #include <libgimp/gimpmath.h> where appropriate and use it's constants. - Indentation, s/int/gint/ et.al., code cleanup. RFC: The plugins are definitely not useable with GIMP 1.0 any more, so shouldn't we remove all the remaining compatibility stuff ??? (like "#ifdef GIMP_HAVE_PARASITES")
2000-01-26 01:46:56 +08:00
gegl_init (NULL, NULL);
1999-10-04 07:48:33 +08:00
image = load_image (file, &error);
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);
configure.in po-plug-ins/POTFILES.in plug-ins/common/Makefile.am 2000-01-25 Michael Natterer <mitch@gimp.org> * configure.in * po-plug-ins/POTFILES.in * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl * plug-ins/megawidget/*: removed. (There were only 3 functions left which were used by ~5 plugins, so I moved the resp. functions to the plugins). More preview stuff to come... * app/airbrush_blob.c * modules/colorsel_triangle.c * modules/colorsel_water.c: use G_PI instead of M_PI. * app/procedural_db.h * libgimp/gimpenums.h * plug-ins/script-fu/script-fu-constants.c * tools/pdbgen/enums.pl: new PDB return value STATUS_CANCEL which indicates that "Cancel" was pressed in a plugin dialog. (Useful only for file load/save plugins). * app/fileops.[ch] * app/menus.c: changes to handle STATUS_CANCEL correctly. Did some code cleanup in fileops.[ch]. Pop up a warning if File->Save failed. * app/plug_in.c: return_val[0] is of type PDB_STATUS, not PDB_INT32. * libgimp/gimpmath.h: new constant G_MAXRAND which equals to RAND_MAX if it exists or to G_MAXINT otherwise. * libgimp/gimpwidgets.[ch]: new function gimp_random_seed_new() which creates a spinbutton and a "Time" toggle. Call the function which does the "set_sensitive" magic from the radio button callback. * plug-ins/[75 plugins]: - Return STATUS_CANCEL in all file load/save dialogs if "Cancel" was pressed. - Standardized the file plugins' "run" functions. - Use G_PI and G_MAXRAND everywhere. - Added tons of scales and spinbuttons instead of text entries. - Applied uniform packing/spacings all over the place. - Reorganized some UIs (stuff like moving the preview to the top left corner of the dialog). - Removed many ui helper functions and callbacks and use the stuff from libgimp instead. - I tried not to restrict the range of possible values when I replaced entries with spinbuttons/scales but may have failed, though in some cases. Please test ;-) - #include <libgimp/gimpmath.h> where appropriate and use it's constants. - Indentation, s/int/gint/ et.al., code cleanup. RFC: The plugins are definitely not useable with GIMP 1.0 any more, so shouldn't we remove all the remaining compatibility stuff ??? (like "#ifdef GIMP_HAVE_PARASITES")
2000-01-26 01:46:56 +08:00
return return_vals;
}
1999-10-04 07:48:33 +08:00
static GimpValueArray *
xpm_export (GimpProcedure *procedure,
GimpRunMode run_mode,
GimpImage *image,
GFile *file,
GimpMetadata *metadata,
GimpProcedureConfig *config,
gpointer run_data)
{
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
GimpExportReturn export = GIMP_EXPORT_IGNORE;
GList *drawables;
GError *error = NULL;
gegl_init (NULL, NULL);
export = gimp_export_image (&image,
GIMP_EXPORT_CAN_HANDLE_RGB |
GIMP_EXPORT_CAN_HANDLE_GRAY |
GIMP_EXPORT_CAN_HANDLE_INDEXED |
GIMP_EXPORT_CAN_HANDLE_ALPHA);
drawables = gimp_image_list_layers (image);
if (run_mode == GIMP_RUN_INTERACTIVE)
configure.in po-plug-ins/POTFILES.in plug-ins/common/Makefile.am 2000-01-25 Michael Natterer <mitch@gimp.org> * configure.in * po-plug-ins/POTFILES.in * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl * plug-ins/megawidget/*: removed. (There were only 3 functions left which were used by ~5 plugins, so I moved the resp. functions to the plugins). More preview stuff to come... * app/airbrush_blob.c * modules/colorsel_triangle.c * modules/colorsel_water.c: use G_PI instead of M_PI. * app/procedural_db.h * libgimp/gimpenums.h * plug-ins/script-fu/script-fu-constants.c * tools/pdbgen/enums.pl: new PDB return value STATUS_CANCEL which indicates that "Cancel" was pressed in a plugin dialog. (Useful only for file load/save plugins). * app/fileops.[ch] * app/menus.c: changes to handle STATUS_CANCEL correctly. Did some code cleanup in fileops.[ch]. Pop up a warning if File->Save failed. * app/plug_in.c: return_val[0] is of type PDB_STATUS, not PDB_INT32. * libgimp/gimpmath.h: new constant G_MAXRAND which equals to RAND_MAX if it exists or to G_MAXINT otherwise. * libgimp/gimpwidgets.[ch]: new function gimp_random_seed_new() which creates a spinbutton and a "Time" toggle. Call the function which does the "set_sensitive" magic from the radio button callback. * plug-ins/[75 plugins]: - Return STATUS_CANCEL in all file load/save dialogs if "Cancel" was pressed. - Standardized the file plugins' "run" functions. - Use G_PI and G_MAXRAND everywhere. - Added tons of scales and spinbuttons instead of text entries. - Applied uniform packing/spacings all over the place. - Reorganized some UIs (stuff like moving the preview to the top left corner of the dialog). - Removed many ui helper functions and callbacks and use the stuff from libgimp instead. - I tried not to restrict the range of possible values when I replaced entries with spinbuttons/scales but may have failed, though in some cases. Please test ;-) - #include <libgimp/gimpmath.h> where appropriate and use it's constants. - Indentation, s/int/gint/ et.al., code cleanup. RFC: The plugins are definitely not useable with GIMP 1.0 any more, so shouldn't we remove all the remaining compatibility stuff ??? (like "#ifdef GIMP_HAVE_PARASITES")
2000-01-26 01:46:56 +08:00
{
gimp_ui_init (PLUG_IN_BINARY);
if (gimp_drawable_has_alpha (drawables->data))
if (! save_dialog (image, procedure, G_OBJECT (config)))
status = GIMP_PDB_CANCEL;
configure.in po-plug-ins/POTFILES.in plug-ins/common/Makefile.am 2000-01-25 Michael Natterer <mitch@gimp.org> * configure.in * po-plug-ins/POTFILES.in * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl * plug-ins/megawidget/*: removed. (There were only 3 functions left which were used by ~5 plugins, so I moved the resp. functions to the plugins). More preview stuff to come... * app/airbrush_blob.c * modules/colorsel_triangle.c * modules/colorsel_water.c: use G_PI instead of M_PI. * app/procedural_db.h * libgimp/gimpenums.h * plug-ins/script-fu/script-fu-constants.c * tools/pdbgen/enums.pl: new PDB return value STATUS_CANCEL which indicates that "Cancel" was pressed in a plugin dialog. (Useful only for file load/save plugins). * app/fileops.[ch] * app/menus.c: changes to handle STATUS_CANCEL correctly. Did some code cleanup in fileops.[ch]. Pop up a warning if File->Save failed. * app/plug_in.c: return_val[0] is of type PDB_STATUS, not PDB_INT32. * libgimp/gimpmath.h: new constant G_MAXRAND which equals to RAND_MAX if it exists or to G_MAXINT otherwise. * libgimp/gimpwidgets.[ch]: new function gimp_random_seed_new() which creates a spinbutton and a "Time" toggle. Call the function which does the "set_sensitive" magic from the radio button callback. * plug-ins/[75 plugins]: - Return STATUS_CANCEL in all file load/save dialogs if "Cancel" was pressed. - Standardized the file plugins' "run" functions. - Use G_PI and G_MAXRAND everywhere. - Added tons of scales and spinbuttons instead of text entries. - Applied uniform packing/spacings all over the place. - Reorganized some UIs (stuff like moving the preview to the top left corner of the dialog). - Removed many ui helper functions and callbacks and use the stuff from libgimp instead. - I tried not to restrict the range of possible values when I replaced entries with spinbuttons/scales but may have failed, though in some cases. Please test ;-) - #include <libgimp/gimpmath.h> where appropriate and use it's constants. - Indentation, s/int/gint/ et.al., code cleanup. RFC: The plugins are definitely not useable with GIMP 1.0 any more, so shouldn't we remove all the remaining compatibility stuff ??? (like "#ifdef GIMP_HAVE_PARASITES")
2000-01-26 01:46:56 +08:00
}
1997-11-25 06:05:25 +08:00
if (status == GIMP_PDB_SUCCESS)
{
if (! export_image (file, image, drawables->data, G_OBJECT (config),
&error))
{
status = GIMP_PDB_EXECUTION_ERROR;
}
}
if (export == GIMP_EXPORT_EXPORT)
gimp_image_delete (image);
g_list_free (drawables);
return gimp_procedure_new_return_values (procedure, status, error);
configure.in po-plug-ins/POTFILES.in plug-ins/common/Makefile.am 2000-01-25 Michael Natterer <mitch@gimp.org> * configure.in * po-plug-ins/POTFILES.in * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl * plug-ins/megawidget/*: removed. (There were only 3 functions left which were used by ~5 plugins, so I moved the resp. functions to the plugins). More preview stuff to come... * app/airbrush_blob.c * modules/colorsel_triangle.c * modules/colorsel_water.c: use G_PI instead of M_PI. * app/procedural_db.h * libgimp/gimpenums.h * plug-ins/script-fu/script-fu-constants.c * tools/pdbgen/enums.pl: new PDB return value STATUS_CANCEL which indicates that "Cancel" was pressed in a plugin dialog. (Useful only for file load/save plugins). * app/fileops.[ch] * app/menus.c: changes to handle STATUS_CANCEL correctly. Did some code cleanup in fileops.[ch]. Pop up a warning if File->Save failed. * app/plug_in.c: return_val[0] is of type PDB_STATUS, not PDB_INT32. * libgimp/gimpmath.h: new constant G_MAXRAND which equals to RAND_MAX if it exists or to G_MAXINT otherwise. * libgimp/gimpwidgets.[ch]: new function gimp_random_seed_new() which creates a spinbutton and a "Time" toggle. Call the function which does the "set_sensitive" magic from the radio button callback. * plug-ins/[75 plugins]: - Return STATUS_CANCEL in all file load/save dialogs if "Cancel" was pressed. - Standardized the file plugins' "run" functions. - Use G_PI and G_MAXRAND everywhere. - Added tons of scales and spinbuttons instead of text entries. - Applied uniform packing/spacings all over the place. - Reorganized some UIs (stuff like moving the preview to the top left corner of the dialog). - Removed many ui helper functions and callbacks and use the stuff from libgimp instead. - I tried not to restrict the range of possible values when I replaced entries with spinbuttons/scales but may have failed, though in some cases. Please test ;-) - #include <libgimp/gimpmath.h> where appropriate and use it's constants. - Indentation, s/int/gint/ et.al., code cleanup. RFC: The plugins are definitely not useable with GIMP 1.0 any more, so shouldn't we remove all the remaining compatibility stuff ??? (like "#ifdef GIMP_HAVE_PARASITES")
2000-01-26 01:46:56 +08:00
}
1997-11-25 06:05:25 +08:00
static GimpImage *
load_image (GFile *file,
GError **error)
1997-11-25 06:05:25 +08:00
{
XpmImage xpm_image;
guchar *cmap;
GimpImage *image;
1997-11-25 06:05:25 +08:00
gimp_progress_init_printf (_("Opening '%s'"),
gimp_file_get_utf8_name (file));
1997-11-25 06:05:25 +08:00
/* read the raw file */
switch (XpmReadFileToXpmImage ((char *) g_file_peek_path (file),
&xpm_image, NULL))
{
case XpmSuccess:
break;
case XpmOpenFailed:
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("Error opening file '%s'"),
gimp_file_get_utf8_name (file));
return NULL;
case XpmFileInvalid:
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
"%s", _("XPM file invalid"));
return NULL;
default:
return NULL;
}
1997-11-25 06:05:25 +08:00
cmap = parse_colors (&xpm_image);
configure.in po-plug-ins/POTFILES.in plug-ins/common/Makefile.am 2000-01-25 Michael Natterer <mitch@gimp.org> * configure.in * po-plug-ins/POTFILES.in * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl * plug-ins/megawidget/*: removed. (There were only 3 functions left which were used by ~5 plugins, so I moved the resp. functions to the plugins). More preview stuff to come... * app/airbrush_blob.c * modules/colorsel_triangle.c * modules/colorsel_water.c: use G_PI instead of M_PI. * app/procedural_db.h * libgimp/gimpenums.h * plug-ins/script-fu/script-fu-constants.c * tools/pdbgen/enums.pl: new PDB return value STATUS_CANCEL which indicates that "Cancel" was pressed in a plugin dialog. (Useful only for file load/save plugins). * app/fileops.[ch] * app/menus.c: changes to handle STATUS_CANCEL correctly. Did some code cleanup in fileops.[ch]. Pop up a warning if File->Save failed. * app/plug_in.c: return_val[0] is of type PDB_STATUS, not PDB_INT32. * libgimp/gimpmath.h: new constant G_MAXRAND which equals to RAND_MAX if it exists or to G_MAXINT otherwise. * libgimp/gimpwidgets.[ch]: new function gimp_random_seed_new() which creates a spinbutton and a "Time" toggle. Call the function which does the "set_sensitive" magic from the radio button callback. * plug-ins/[75 plugins]: - Return STATUS_CANCEL in all file load/save dialogs if "Cancel" was pressed. - Standardized the file plugins' "run" functions. - Use G_PI and G_MAXRAND everywhere. - Added tons of scales and spinbuttons instead of text entries. - Applied uniform packing/spacings all over the place. - Reorganized some UIs (stuff like moving the preview to the top left corner of the dialog). - Removed many ui helper functions and callbacks and use the stuff from libgimp instead. - I tried not to restrict the range of possible values when I replaced entries with spinbuttons/scales but may have failed, though in some cases. Please test ;-) - #include <libgimp/gimpmath.h> where appropriate and use it's constants. - Indentation, s/int/gint/ et.al., code cleanup. RFC: The plugins are definitely not useable with GIMP 1.0 any more, so shouldn't we remove all the remaining compatibility stuff ??? (like "#ifdef GIMP_HAVE_PARASITES")
2000-01-26 01:46:56 +08:00
image = gimp_image_new (xpm_image.width,
xpm_image.height,
GIMP_RGB);
1997-11-25 06:05:25 +08:00
/* fill it */
parse_image (image, &xpm_image, cmap);
g_free (cmap);
return image;
1997-11-25 06:05:25 +08:00
}
static guchar *
parse_colors (XpmImage *xpm_image)
1997-11-25 06:05:25 +08:00
{
#ifndef XPM_NO_X
1997-11-25 06:05:25 +08:00
Display *display;
Colormap colormap;
#endif
gint i, j;
guchar *cmap;
1997-11-25 06:05:25 +08:00
#ifndef XPM_NO_X
1997-11-25 06:05:25 +08:00
/* open the display and get the default color map */
display = XOpenDisplay (NULL);
if (display == NULL)
g_printerr ("Could not open display\n");
1997-11-25 06:05:25 +08:00
colormap = DefaultColormap (display, DefaultScreen (display));
#endif
1997-11-25 06:05:25 +08:00
/* alloc a buffer to hold the parsed colors */
cmap = g_new0 (guchar, 4 * xpm_image->ncolors);
1997-11-25 06:05:25 +08:00
/* parse each color in the file */
for (i = 0, j = 0; i < xpm_image->ncolors; i++)
1997-11-25 06:05:25 +08:00
{
gchar *colorspec = "None";
XpmColor *xpm_color;
#ifndef XPM_NO_X
XColor xcolor;
#else
GdkRGBA xcolor;
#endif
xpm_color = &(xpm_image->colorTable[i]);
/* pick the best spec available */
if (xpm_color->c_color)
colorspec = xpm_color->c_color;
else if (xpm_color->g_color)
colorspec = xpm_color->g_color;
else if (xpm_color->g4_color)
colorspec = xpm_color->g4_color;
else if (xpm_color->m_color)
colorspec = xpm_color->m_color;
/* parse if it's not transparent */
if (strcmp (colorspec, "None") != 0)
{
#ifndef XPM_NO_X
XParseColor (display, colormap, colorspec, &xcolor);
cmap[j++] = xcolor.red >> 8;
cmap[j++] = xcolor.green >> 8;
cmap[j++] = xcolor.blue >> 8;
#else
gdk_rgba_parse (&xcolor, colorspec);
cmap[j++] = CLAMP (xcolor.red * G_MAXUINT8, 0, G_MAXUINT8);
cmap[j++] = CLAMP (xcolor.green * G_MAXUINT8, 0, G_MAXUINT8);
cmap[j++] = CLAMP (xcolor.blue * G_MAXUINT8, 0, G_MAXUINT8);
#endif
cmap[j++] = ~0;
}
else
{
j += 4;
}
1997-11-25 06:05:25 +08:00
}
#ifndef XPM_NO_X
1997-11-25 06:05:25 +08:00
XCloseDisplay (display);
#endif
return cmap;
1997-11-25 06:05:25 +08:00
}
static void
parse_image (GimpImage *image,
XpmImage *xpm_image,
guchar *cmap)
1997-11-25 06:05:25 +08:00
{
2012-11-26 09:39:44 +08:00
GeglBuffer *buffer;
gint tile_height;
gint scanlines;
gint val;
guchar *buf;
guchar *dest;
guint *src;
GimpLayer *layer;
2012-11-26 09:39:44 +08:00
gint i;
layer = gimp_layer_new (image,
_("Color"),
xpm_image->width,
xpm_image->height,
GIMP_RGBA_IMAGE,
100,
gimp_image_get_default_new_layer_mode (image));
gimp_image_insert_layer (image, layer, NULL, 0);
1997-11-25 06:05:25 +08:00
buffer = gimp_drawable_get_buffer (GIMP_DRAWABLE (layer));
1997-11-25 06:05:25 +08:00
tile_height = gimp_tile_height ();
1997-11-25 06:05:25 +08:00
buf = g_new (guchar, tile_height * xpm_image->width * 4);
src = xpm_image->data;
2012-11-26 09:39:44 +08:00
for (i = 0; i < xpm_image->height; i += tile_height)
1997-11-25 06:05:25 +08:00
{
2012-11-26 09:39:44 +08:00
gint j;
dest = buf;
2012-11-26 09:39:44 +08:00
scanlines = MIN (tile_height, xpm_image->height - i);
j = scanlines * xpm_image->width;
2012-11-26 09:39:44 +08:00
while (j--)
{
2012-11-26 09:39:44 +08:00
{
val = *(src++) * 4;
*(dest) = cmap[val];
*(dest+1) = cmap[val+1];
*(dest+2) = cmap[val+2];
*(dest+3) = cmap[val+3];
dest += 4;
}
if ((j % 100) == 0)
gimp_progress_update ((double) i / (double) xpm_image->height);
}
2012-11-26 09:39:44 +08:00
gegl_buffer_set (buffer,
GEGL_RECTANGLE (0, i, xpm_image->width, scanlines), 0,
NULL, buf, GEGL_AUTO_ROWSTRIDE);
1997-11-25 06:05:25 +08:00
}
2012-11-26 09:39:44 +08:00
g_free (buf);
g_object_unref (buffer);
1998-02-25 14:21:26 +08:00
2012-11-26 09:39:44 +08:00
gimp_progress_update (1.0);
1997-11-25 06:05:25 +08:00
}
static guint
configure.in po-plug-ins/POTFILES.in plug-ins/common/Makefile.am 2000-01-25 Michael Natterer <mitch@gimp.org> * configure.in * po-plug-ins/POTFILES.in * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl * plug-ins/megawidget/*: removed. (There were only 3 functions left which were used by ~5 plugins, so I moved the resp. functions to the plugins). More preview stuff to come... * app/airbrush_blob.c * modules/colorsel_triangle.c * modules/colorsel_water.c: use G_PI instead of M_PI. * app/procedural_db.h * libgimp/gimpenums.h * plug-ins/script-fu/script-fu-constants.c * tools/pdbgen/enums.pl: new PDB return value STATUS_CANCEL which indicates that "Cancel" was pressed in a plugin dialog. (Useful only for file load/save plugins). * app/fileops.[ch] * app/menus.c: changes to handle STATUS_CANCEL correctly. Did some code cleanup in fileops.[ch]. Pop up a warning if File->Save failed. * app/plug_in.c: return_val[0] is of type PDB_STATUS, not PDB_INT32. * libgimp/gimpmath.h: new constant G_MAXRAND which equals to RAND_MAX if it exists or to G_MAXINT otherwise. * libgimp/gimpwidgets.[ch]: new function gimp_random_seed_new() which creates a spinbutton and a "Time" toggle. Call the function which does the "set_sensitive" magic from the radio button callback. * plug-ins/[75 plugins]: - Return STATUS_CANCEL in all file load/save dialogs if "Cancel" was pressed. - Standardized the file plugins' "run" functions. - Use G_PI and G_MAXRAND everywhere. - Added tons of scales and spinbuttons instead of text entries. - Applied uniform packing/spacings all over the place. - Reorganized some UIs (stuff like moving the preview to the top left corner of the dialog). - Removed many ui helper functions and callbacks and use the stuff from libgimp instead. - I tried not to restrict the range of possible values when I replaced entries with spinbuttons/scales but may have failed, though in some cases. Please test ;-) - #include <libgimp/gimpmath.h> where appropriate and use it's constants. - Indentation, s/int/gint/ et.al., code cleanup. RFC: The plugins are definitely not useable with GIMP 1.0 any more, so shouldn't we remove all the remaining compatibility stuff ??? (like "#ifdef GIMP_HAVE_PARASITES")
2000-01-26 01:46:56 +08:00
rgbhash (rgbkey *c)
1998-02-25 14:21:26 +08:00
{
return ((guint)c->r) ^ ((guint)c->g) ^ ((guint)c->b);
1998-02-25 14:21:26 +08:00
}
1997-11-25 06:05:25 +08:00
static guint
compare (rgbkey *c1,
rgbkey *c2)
1998-02-25 14:21:26 +08:00
{
return (c1->r == c2->r) && (c1->g == c2->g) && (c1->b == c2->b);
1998-02-25 14:21:26 +08:00
}
static void
set_XpmImage (XpmColor *array,
guint index,
gchar *colorstring)
1998-02-25 14:21:26 +08:00
{
configure.in po-plug-ins/POTFILES.in plug-ins/common/Makefile.am 2000-01-25 Michael Natterer <mitch@gimp.org> * configure.in * po-plug-ins/POTFILES.in * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl * plug-ins/megawidget/*: removed. (There were only 3 functions left which were used by ~5 plugins, so I moved the resp. functions to the plugins). More preview stuff to come... * app/airbrush_blob.c * modules/colorsel_triangle.c * modules/colorsel_water.c: use G_PI instead of M_PI. * app/procedural_db.h * libgimp/gimpenums.h * plug-ins/script-fu/script-fu-constants.c * tools/pdbgen/enums.pl: new PDB return value STATUS_CANCEL which indicates that "Cancel" was pressed in a plugin dialog. (Useful only for file load/save plugins). * app/fileops.[ch] * app/menus.c: changes to handle STATUS_CANCEL correctly. Did some code cleanup in fileops.[ch]. Pop up a warning if File->Save failed. * app/plug_in.c: return_val[0] is of type PDB_STATUS, not PDB_INT32. * libgimp/gimpmath.h: new constant G_MAXRAND which equals to RAND_MAX if it exists or to G_MAXINT otherwise. * libgimp/gimpwidgets.[ch]: new function gimp_random_seed_new() which creates a spinbutton and a "Time" toggle. Call the function which does the "set_sensitive" magic from the radio button callback. * plug-ins/[75 plugins]: - Return STATUS_CANCEL in all file load/save dialogs if "Cancel" was pressed. - Standardized the file plugins' "run" functions. - Use G_PI and G_MAXRAND everywhere. - Added tons of scales and spinbuttons instead of text entries. - Applied uniform packing/spacings all over the place. - Reorganized some UIs (stuff like moving the preview to the top left corner of the dialog). - Removed many ui helper functions and callbacks and use the stuff from libgimp instead. - I tried not to restrict the range of possible values when I replaced entries with spinbuttons/scales but may have failed, though in some cases. Please test ;-) - #include <libgimp/gimpmath.h> where appropriate and use it's constants. - Indentation, s/int/gint/ et.al., code cleanup. RFC: The plugins are definitely not useable with GIMP 1.0 any more, so shouldn't we remove all the remaining compatibility stuff ??? (like "#ifdef GIMP_HAVE_PARASITES")
2000-01-26 01:46:56 +08:00
gchar *p;
2012-11-26 09:39:44 +08:00
gint i, charnum, indtemp;
indtemp=index;
array[index].string = p = g_new (gchar, cpp+1);
/*convert the index number to base sizeof(linenoise)-1 */
for (i = 0; i < cpp; ++i)
{
charnum = indtemp % (sizeof (linenoise) - 1);
indtemp = indtemp / (sizeof (linenoise) - 1);
*p++ = linenoise[charnum];
}
/* *p++=linenoise[indtemp]; */
*p = '\0'; /* C and its stupid null-terminated strings... */
array[index].symbolic = NULL;
array[index].m_color = NULL;
array[index].g4_color = NULL;
if (color)
{
array[index].g_color = NULL;
array[index].c_color = colorstring;
}
else
{
array[index].c_color = NULL;
array[index].g_color = colorstring;
}
1998-02-25 14:21:26 +08:00
}
static void
create_colormap_from_hash (gpointer gkey,
gpointer value,
gpointer user_data)
1998-02-25 14:21:26 +08:00
{
rgbkey *key = gkey;
gchar *string = g_new (gchar, 8);
configure.in po-plug-ins/POTFILES.in plug-ins/common/Makefile.am 2000-01-25 Michael Natterer <mitch@gimp.org> * configure.in * po-plug-ins/POTFILES.in * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl * plug-ins/megawidget/*: removed. (There were only 3 functions left which were used by ~5 plugins, so I moved the resp. functions to the plugins). More preview stuff to come... * app/airbrush_blob.c * modules/colorsel_triangle.c * modules/colorsel_water.c: use G_PI instead of M_PI. * app/procedural_db.h * libgimp/gimpenums.h * plug-ins/script-fu/script-fu-constants.c * tools/pdbgen/enums.pl: new PDB return value STATUS_CANCEL which indicates that "Cancel" was pressed in a plugin dialog. (Useful only for file load/save plugins). * app/fileops.[ch] * app/menus.c: changes to handle STATUS_CANCEL correctly. Did some code cleanup in fileops.[ch]. Pop up a warning if File->Save failed. * app/plug_in.c: return_val[0] is of type PDB_STATUS, not PDB_INT32. * libgimp/gimpmath.h: new constant G_MAXRAND which equals to RAND_MAX if it exists or to G_MAXINT otherwise. * libgimp/gimpwidgets.[ch]: new function gimp_random_seed_new() which creates a spinbutton and a "Time" toggle. Call the function which does the "set_sensitive" magic from the radio button callback. * plug-ins/[75 plugins]: - Return STATUS_CANCEL in all file load/save dialogs if "Cancel" was pressed. - Standardized the file plugins' "run" functions. - Use G_PI and G_MAXRAND everywhere. - Added tons of scales and spinbuttons instead of text entries. - Applied uniform packing/spacings all over the place. - Reorganized some UIs (stuff like moving the preview to the top left corner of the dialog). - Removed many ui helper functions and callbacks and use the stuff from libgimp instead. - I tried not to restrict the range of possible values when I replaced entries with spinbuttons/scales but may have failed, though in some cases. Please test ;-) - #include <libgimp/gimpmath.h> where appropriate and use it's constants. - Indentation, s/int/gint/ et.al., code cleanup. RFC: The plugins are definitely not useable with GIMP 1.0 any more, so shouldn't we remove all the remaining compatibility stuff ??? (like "#ifdef GIMP_HAVE_PARASITES")
2000-01-26 01:46:56 +08:00
sprintf (string, "#%02X%02X%02X", (int)key->r, (int)key->g, (int)key->b);
set_XpmImage (user_data, *((int *) value), string);
1998-02-25 14:21:26 +08:00
}
1997-11-25 06:05:25 +08:00
static void
decrement_hash_values (gpointer gkey,
gpointer value,
gpointer user_data)
{
--(*((guint*) value));
}
static gboolean
export_image (GFile *file,
GimpImage *image,
GimpDrawable *drawable,
GObject *config,
GError **error)
1997-11-25 06:05:25 +08:00
{
2012-11-26 09:39:44 +08:00
GeglBuffer *buffer;
const Babl *format;
gint width;
gint height;
gint ncolors = 1;
gint *indexno;
gboolean indexed;
gboolean alpha;
gboolean alpha_used = FALSE;
2012-11-26 09:39:44 +08:00
XpmColor *colormap;
XpmImage *xpm_image;
2012-11-26 09:39:44 +08:00
guint *ibuff = NULL;
guchar *buf;
guchar *data;
1998-02-25 14:21:26 +08:00
GHashTable *hash = NULL;
2012-11-26 09:39:44 +08:00
gint i, j, k;
gint threshold;
2012-11-26 09:39:44 +08:00
gboolean success = FALSE;
configure.in po-plug-ins/POTFILES.in plug-ins/common/Makefile.am 2000-01-25 Michael Natterer <mitch@gimp.org> * configure.in * po-plug-ins/POTFILES.in * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl * plug-ins/megawidget/*: removed. (There were only 3 functions left which were used by ~5 plugins, so I moved the resp. functions to the plugins). More preview stuff to come... * app/airbrush_blob.c * modules/colorsel_triangle.c * modules/colorsel_water.c: use G_PI instead of M_PI. * app/procedural_db.h * libgimp/gimpenums.h * plug-ins/script-fu/script-fu-constants.c * tools/pdbgen/enums.pl: new PDB return value STATUS_CANCEL which indicates that "Cancel" was pressed in a plugin dialog. (Useful only for file load/save plugins). * app/fileops.[ch] * app/menus.c: changes to handle STATUS_CANCEL correctly. Did some code cleanup in fileops.[ch]. Pop up a warning if File->Save failed. * app/plug_in.c: return_val[0] is of type PDB_STATUS, not PDB_INT32. * libgimp/gimpmath.h: new constant G_MAXRAND which equals to RAND_MAX if it exists or to G_MAXINT otherwise. * libgimp/gimpwidgets.[ch]: new function gimp_random_seed_new() which creates a spinbutton and a "Time" toggle. Call the function which does the "set_sensitive" magic from the radio button callback. * plug-ins/[75 plugins]: - Return STATUS_CANCEL in all file load/save dialogs if "Cancel" was pressed. - Standardized the file plugins' "run" functions. - Use G_PI and G_MAXRAND everywhere. - Added tons of scales and spinbuttons instead of text entries. - Applied uniform packing/spacings all over the place. - Reorganized some UIs (stuff like moving the preview to the top left corner of the dialog). - Removed many ui helper functions and callbacks and use the stuff from libgimp instead. - I tried not to restrict the range of possible values when I replaced entries with spinbuttons/scales but may have failed, though in some cases. Please test ;-) - #include <libgimp/gimpmath.h> where appropriate and use it's constants. - Indentation, s/int/gint/ et.al., code cleanup. RFC: The plugins are definitely not useable with GIMP 1.0 any more, so shouldn't we remove all the remaining compatibility stuff ??? (like "#ifdef GIMP_HAVE_PARASITES")
2000-01-26 01:46:56 +08:00
g_object_get (config,
"threshold", &threshold,
NULL);
buffer = gimp_drawable_get_buffer (drawable);
1997-11-25 06:05:25 +08:00
2012-11-26 09:39:44 +08:00
width = gegl_buffer_get_width (buffer);
height = gegl_buffer_get_height (buffer);
1997-11-25 06:05:25 +08:00
alpha = gimp_drawable_has_alpha (drawable);
color = ! gimp_drawable_is_gray (drawable);
indexed = gimp_drawable_is_indexed (drawable);
1997-11-25 06:05:25 +08:00
switch (gimp_drawable_type (drawable))
2012-11-26 09:39:44 +08:00
{
case GIMP_RGB_IMAGE:
format = babl_format ("R'G'B' u8");
break;
case GIMP_RGBA_IMAGE:
format = babl_format ("R'G'B'A u8");
break;
case GIMP_GRAY_IMAGE:
format = babl_format ("Y' u8");
break;
case GIMP_GRAYA_IMAGE:
format = babl_format ("Y'A u8");
break;
case GIMP_INDEXED_IMAGE:
case GIMP_INDEXEDA_IMAGE:
format = gegl_buffer_get_format (buffer);
break;
default:
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("Unsupported drawable type"));
g_object_unref (buffer);
return FALSE;
2012-11-26 09:39:44 +08:00
}
/* allocate buffer making the assumption that ibuff is 32 bit aligned... */
ibuff = g_new (guint, width * height);
1997-11-25 06:05:25 +08:00
hash = g_hash_table_new ((GHashFunc) rgbhash, (GCompareFunc) compare);
gimp_progress_init_printf (_("Exporting '%s'"),
gimp_file_get_utf8_name (file));
1997-11-25 06:05:25 +08:00
ncolors = alpha ? 1 : 0;
1997-11-25 06:05:25 +08:00
/* allocate a pixel region to work with */
2012-11-26 09:39:44 +08:00
buf = g_new (guchar,
gimp_tile_height () * width *
babl_format_get_bytes_per_pixel (format));
1997-11-25 06:05:25 +08:00
/* process each row of tiles */
2012-11-26 09:39:44 +08:00
for (i = 0; i < height; i += gimp_tile_height ())
1997-11-25 06:05:25 +08:00
{
gint scanlines;
1997-11-25 06:05:25 +08:00
/* read the next row of tiles */
scanlines = MIN (gimp_tile_height(), height - i);
2012-11-26 09:39:44 +08:00
gegl_buffer_get (buffer, GEGL_RECTANGLE (0, i, width, scanlines), 1.0,
format, buf,
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
data = buf;
1997-11-25 06:05:25 +08:00
/* process each pixel row */
for (j = 0; j < scanlines; j++)
1997-11-25 06:05:25 +08:00
{
/* go to the start of this row in each image */
1998-02-25 14:21:26 +08:00
guint *idata = ibuff + (i+j) * width;
1997-11-25 06:05:25 +08:00
/* do each pixel in the row */
for (k = 0; k < width; k++)
1997-11-25 06:05:25 +08:00
{
rgbkey *key = g_new (rgbkey, 1);
guchar a;
1997-11-25 06:05:25 +08:00
/* get pixel data */
1998-02-25 14:21:26 +08:00
key->r = *(data++);
key->g = color && !indexed ? *(data++) : key->r;
key->b = color && !indexed ? *(data++) : key->r;
a = alpha ? *(data++) : 255;
if (a < threshold)
{
*(idata++) = 0;
alpha_used = TRUE;
}
else
{
if (indexed)
{
*(idata++) = (key->r) + (alpha ? 1 : 0);
}
else
{
indexno = g_hash_table_lookup (hash, key);
if (!indexno)
{
indexno = g_new (gint, 1);
*indexno = ncolors++;
g_hash_table_insert (hash, key, indexno);
key = g_new (rgbkey, 1);
}
*(idata++) = *indexno;
}
}
1997-11-25 06:05:25 +08:00
}
configure.in po-plug-ins/POTFILES.in plug-ins/common/Makefile.am 2000-01-25 Michael Natterer <mitch@gimp.org> * configure.in * po-plug-ins/POTFILES.in * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl * plug-ins/megawidget/*: removed. (There were only 3 functions left which were used by ~5 plugins, so I moved the resp. functions to the plugins). More preview stuff to come... * app/airbrush_blob.c * modules/colorsel_triangle.c * modules/colorsel_water.c: use G_PI instead of M_PI. * app/procedural_db.h * libgimp/gimpenums.h * plug-ins/script-fu/script-fu-constants.c * tools/pdbgen/enums.pl: new PDB return value STATUS_CANCEL which indicates that "Cancel" was pressed in a plugin dialog. (Useful only for file load/save plugins). * app/fileops.[ch] * app/menus.c: changes to handle STATUS_CANCEL correctly. Did some code cleanup in fileops.[ch]. Pop up a warning if File->Save failed. * app/plug_in.c: return_val[0] is of type PDB_STATUS, not PDB_INT32. * libgimp/gimpmath.h: new constant G_MAXRAND which equals to RAND_MAX if it exists or to G_MAXINT otherwise. * libgimp/gimpwidgets.[ch]: new function gimp_random_seed_new() which creates a spinbutton and a "Time" toggle. Call the function which does the "set_sensitive" magic from the radio button callback. * plug-ins/[75 plugins]: - Return STATUS_CANCEL in all file load/save dialogs if "Cancel" was pressed. - Standardized the file plugins' "run" functions. - Use G_PI and G_MAXRAND everywhere. - Added tons of scales and spinbuttons instead of text entries. - Applied uniform packing/spacings all over the place. - Reorganized some UIs (stuff like moving the preview to the top left corner of the dialog). - Removed many ui helper functions and callbacks and use the stuff from libgimp instead. - I tried not to restrict the range of possible values when I replaced entries with spinbuttons/scales but may have failed, though in some cases. Please test ;-) - #include <libgimp/gimpmath.h> where appropriate and use it's constants. - Indentation, s/int/gint/ et.al., code cleanup. RFC: The plugins are definitely not useable with GIMP 1.0 any more, so shouldn't we remove all the remaining compatibility stuff ??? (like "#ifdef GIMP_HAVE_PARASITES")
2000-01-26 01:46:56 +08:00
1997-11-25 06:05:25 +08:00
/* kick the progress bar */
gimp_progress_update ((gdouble) (i+j) / (gdouble) height);
}
}
2012-11-26 09:39:44 +08:00
g_free (buf);
1998-02-25 14:21:26 +08:00
/* remove alpha if not actually used */
if (alpha && !alpha_used)
{
gint i;
--ncolors;
for (i = 0; i < width * height; ++i)
--ibuff[i];
g_hash_table_foreach (hash, decrement_hash_values, NULL);
}
1998-02-25 14:21:26 +08:00
if (indexed)
1999-10-04 07:48:33 +08:00
{
guchar *cmap = gimp_image_get_colormap (image, NULL, &ncolors);
guchar *c;
c = cmap;
if (alpha_used)
ncolors++;
colormap = g_new (XpmColor, ncolors);
cpp =
1 + (gdouble) log (ncolors) / (gdouble) log (sizeof (linenoise) - 1.0);
if (alpha_used)
set_XpmImage (colormap, 0, "None");
for (i = alpha_used ? 1 : 0; i < ncolors; i++)
{
gchar *string;
guchar r, g, b;
r = *c++;
g = *c++;
b = *c++;
string = g_new (gchar, 8);
sprintf (string, "#%02X%02X%02X", (int)r, (int)g, (int)b);
set_XpmImage (colormap, i, string);
}
g_free (cmap);
1999-10-04 07:48:33 +08:00
}
else
{
colormap = g_new (XpmColor, ncolors);
cpp =
1 + (gdouble) log (ncolors) / (gdouble) log (sizeof (linenoise) - 1.0);
if (alpha_used)
set_XpmImage (colormap, 0, "None");
1999-10-04 07:48:33 +08:00
g_hash_table_foreach (hash, create_colormap_from_hash, colormap);
}
configure.in po-plug-ins/POTFILES.in plug-ins/common/Makefile.am 2000-01-25 Michael Natterer <mitch@gimp.org> * configure.in * po-plug-ins/POTFILES.in * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl * plug-ins/megawidget/*: removed. (There were only 3 functions left which were used by ~5 plugins, so I moved the resp. functions to the plugins). More preview stuff to come... * app/airbrush_blob.c * modules/colorsel_triangle.c * modules/colorsel_water.c: use G_PI instead of M_PI. * app/procedural_db.h * libgimp/gimpenums.h * plug-ins/script-fu/script-fu-constants.c * tools/pdbgen/enums.pl: new PDB return value STATUS_CANCEL which indicates that "Cancel" was pressed in a plugin dialog. (Useful only for file load/save plugins). * app/fileops.[ch] * app/menus.c: changes to handle STATUS_CANCEL correctly. Did some code cleanup in fileops.[ch]. Pop up a warning if File->Save failed. * app/plug_in.c: return_val[0] is of type PDB_STATUS, not PDB_INT32. * libgimp/gimpmath.h: new constant G_MAXRAND which equals to RAND_MAX if it exists or to G_MAXINT otherwise. * libgimp/gimpwidgets.[ch]: new function gimp_random_seed_new() which creates a spinbutton and a "Time" toggle. Call the function which does the "set_sensitive" magic from the radio button callback. * plug-ins/[75 plugins]: - Return STATUS_CANCEL in all file load/save dialogs if "Cancel" was pressed. - Standardized the file plugins' "run" functions. - Use G_PI and G_MAXRAND everywhere. - Added tons of scales and spinbuttons instead of text entries. - Applied uniform packing/spacings all over the place. - Reorganized some UIs (stuff like moving the preview to the top left corner of the dialog). - Removed many ui helper functions and callbacks and use the stuff from libgimp instead. - I tried not to restrict the range of possible values when I replaced entries with spinbuttons/scales but may have failed, though in some cases. Please test ;-) - #include <libgimp/gimpmath.h> where appropriate and use it's constants. - Indentation, s/int/gint/ et.al., code cleanup. RFC: The plugins are definitely not useable with GIMP 1.0 any more, so shouldn't we remove all the remaining compatibility stuff ??? (like "#ifdef GIMP_HAVE_PARASITES")
2000-01-26 01:46:56 +08:00
xpm_image = g_new (XpmImage, 1);
xpm_image->width = width;
xpm_image->height = height;
xpm_image->ncolors = ncolors;
xpm_image->cpp = cpp;
xpm_image->colorTable = colormap;
xpm_image->data = ibuff;
/* do the export */
switch (XpmWriteFileFromXpmImage ((char *) g_file_peek_path (file),
xpm_image, NULL))
{
case XpmSuccess:
success = TRUE;
break;
case XpmOpenFailed:
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
_("Error opening file '%s'"),
gimp_file_get_utf8_name (file));
break;
case XpmFileInvalid:
g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
"%s", _("XPM file invalid"));
break;
default:
break;
}
configure.in po-plug-ins/POTFILES.in plug-ins/common/Makefile.am 2000-01-25 Michael Natterer <mitch@gimp.org> * configure.in * po-plug-ins/POTFILES.in * plug-ins/common/Makefile.am * plug-ins/common/plugin-defs.pl * plug-ins/megawidget/*: removed. (There were only 3 functions left which were used by ~5 plugins, so I moved the resp. functions to the plugins). More preview stuff to come... * app/airbrush_blob.c * modules/colorsel_triangle.c * modules/colorsel_water.c: use G_PI instead of M_PI. * app/procedural_db.h * libgimp/gimpenums.h * plug-ins/script-fu/script-fu-constants.c * tools/pdbgen/enums.pl: new PDB return value STATUS_CANCEL which indicates that "Cancel" was pressed in a plugin dialog. (Useful only for file load/save plugins). * app/fileops.[ch] * app/menus.c: changes to handle STATUS_CANCEL correctly. Did some code cleanup in fileops.[ch]. Pop up a warning if File->Save failed. * app/plug_in.c: return_val[0] is of type PDB_STATUS, not PDB_INT32. * libgimp/gimpmath.h: new constant G_MAXRAND which equals to RAND_MAX if it exists or to G_MAXINT otherwise. * libgimp/gimpwidgets.[ch]: new function gimp_random_seed_new() which creates a spinbutton and a "Time" toggle. Call the function which does the "set_sensitive" magic from the radio button callback. * plug-ins/[75 plugins]: - Return STATUS_CANCEL in all file load/save dialogs if "Cancel" was pressed. - Standardized the file plugins' "run" functions. - Use G_PI and G_MAXRAND everywhere. - Added tons of scales and spinbuttons instead of text entries. - Applied uniform packing/spacings all over the place. - Reorganized some UIs (stuff like moving the preview to the top left corner of the dialog). - Removed many ui helper functions and callbacks and use the stuff from libgimp instead. - I tried not to restrict the range of possible values when I replaced entries with spinbuttons/scales but may have failed, though in some cases. Please test ;-) - #include <libgimp/gimpmath.h> where appropriate and use it's constants. - Indentation, s/int/gint/ et.al., code cleanup. RFC: The plugins are definitely not useable with GIMP 1.0 any more, so shouldn't we remove all the remaining compatibility stuff ??? (like "#ifdef GIMP_HAVE_PARASITES")
2000-01-26 01:46:56 +08:00
2012-11-26 09:39:44 +08:00
g_object_unref (buffer);
g_free (ibuff);
if (hash)
g_hash_table_destroy (hash);
2012-11-26 09:39:44 +08:00
gimp_progress_update (1.0);
return success;
1997-11-25 06:05:25 +08:00
}
static gboolean
save_dialog (GimpImage *image,
GimpProcedure *procedure,
GObject *config)
1997-11-25 06:05:25 +08:00
{
GtkWidget *dialog;
gboolean run;
1997-11-25 06:05:25 +08:00
dialog = gimp_export_procedure_dialog_new (GIMP_EXPORT_PROCEDURE (procedure),
GIMP_PROCEDURE_CONFIG (config),
image);
gimp_procedure_dialog_get_scale_entry (GIMP_PROCEDURE_DIALOG (dialog),
"threshold", 1.0);
gimp_procedure_dialog_fill (GIMP_PROCEDURE_DIALOG (dialog), NULL);
gtk_widget_show (dialog);
1997-11-25 06:05:25 +08:00
run = gimp_procedure_dialog_run (GIMP_PROCEDURE_DIALOG (dialog));
1997-11-25 06:05:25 +08:00
gtk_widget_destroy (dialog);
2000-01-11 23:48:00 +08:00
removed our own action_area API and use GtkDialog's one. Create all 2003-11-06 Michael Natterer <mitch@gimp.org> * libgimpwidgets/gimpdialog.[ch]: removed our own action_area API and use GtkDialog's one. Create all dialogs without separator. Changed almost everything else too. Fixes bug #125143. * libgimpwidgets/gimpquerybox.c * libgimpwidgets/gimpunitmenu.c: changed accordingly. * libgimp/gimpexport.[ch]: ditto. Renamed enum GimpExportReturnType to GimpExportReturn. * libgimp/gimpcompat.h: added a #define for the old name. * themes/Default/gtkrc: increased action_area border to 6 pixels. * app/display/gimpdisplayshell-filter-dialog.c * app/display/gimpdisplayshell-scale.c * app/display/gimpprogress.c * app/gui/brush-select.c * app/gui/channels-commands.c * app/gui/color-notebook.c * app/gui/convert-dialog.c * app/gui/file-new-dialog.c * app/gui/font-select.c * app/gui/gradient-editor-commands.c * app/gui/gradient-select.c * app/gui/grid-dialog.c * app/gui/image-commands.c * app/gui/info-window.c * app/gui/layers-commands.c * app/gui/module-browser.c * app/gui/offset-dialog.c * app/gui/palette-import-dialog.c * app/gui/palette-select.c * app/gui/pattern-select.c * app/gui/preferences-dialog.c * app/gui/qmask-commands.c * app/gui/resize-dialog.c * app/gui/resolution-calibrate-dialog.c * app/gui/stroke-dialog.c * app/gui/templates-commands.c * app/gui/user-install-dialog.c * app/gui/vectors-commands.c * app/tools/gimpcolorpickertool.c * app/tools/gimpcroptool.c * app/tools/gimpimagemaptool.c * app/tools/gimpmeasuretool.c * app/tools/gimptransformtool.c * app/widgets/gimptexteditor.c * app/widgets/gimptooldialog.[ch] * app/widgets/gimpviewabledialog.[ch] * app/widgets/gimpwidgets-utils.c: changed accordingly and increased the dialogs' outer borders to 6 pixels all over the place. * plug-ins/*/*.c: changed accordingly. The plug-ins may be arbitrarily broken, I tested none of them.
2003-11-06 23:27:05 +08:00
return run;
1997-11-25 06:05:25 +08:00
}