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

1822 lines
54 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
2013-10-04 04:06:24 +08:00
*
1997-11-25 06:05:25 +08:00
* PNM reading and writing code Copyright (C) 1996 Erik Nygren
*
* 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
*/
/*
* The pnm reading and writing code was written from scratch by Erik Nygren
* (nygren@mit.edu) based on the specifications in the man pages and
* does not contain any code from the netpbm or pbmplus distributions.
*
* 2006: pbm saving written by Martin K Collins (martin@mkcollins.org)
* 2015: pfm reading written by Tobias Ellinghaus (me@houz.org)
1997-11-25 06:05:25 +08:00
*/
New file. * plug-ins/makefile.msc: New file. * plug-ins/*/*.c (Well, not really all files, but many): Portability fixes. Include config.h, and guard inclusion of POSIX and Unix headers like <unistd.h>, <dirent.h> and <sys/time.h>. Include <string.h> if functions from it are used. Use g_ntohl() and g_htonl() insteead of ntohl() and htonl(), thus no need to include <netinet/in.h>. Include <io.h> on Win32 when using open/read/write (which actually are defined as _open/_read/_write by glib.h). Define S_* macros if necessary on Win32. Define rint() and M_PI if necessary (these definitions should be factored out somewhere, no sense repeating them in lots of files). Open files in binary mode when needed. * plug-ins/FractalExplorer/FractalExplorer.c: Use g_malloc()/g_free(). Use g_strdup_printf(). * plug-ins/dbbrowser/dbbrowser.c: No need to include <X11/Xlib.h>. * plug-ins/destripe/destripe.c: Guard use of SIGBUS. * plug-ins/{flame/flame,hrz/hrz,pnm/pnm}.c: No need to check for NULL returns from g_malloc() and g_new() as they abort on failure. Use g_strdup_printf(). * plug-ins/gz/gz.c: Win32 version of running the subprocess. * plug-ins/hrz/hrz.c: Win32 version. Use more generic tests for non-Unix (OS/2 and Win32), for instance HAVE_MMAP. * plug-ins/script-fu/interp_slib.c: Win32 version of myruntime(). * plug-ins/script-fu/interp_sliba.c: Handle \\ (escaped backslahsh). * plug-ins/script-fu/script-fu-console.c: Bypass on Win32. * plug-ins/script-fu/script-fu-scripts.c: Portability fixes. Use g_strdup_printf() instead of separate malloc() and sprintf(). Use g_strescape() for strings being passed to Scheme. Some Win32-only stuff.
1999-05-29 09:28:24 +08:00
#include "config.h"
1997-11-25 06:05:25 +08:00
#include <setjmp.h>
2013-10-04 03:44:24 +08:00
#include <stdlib.h>
#include <math.h>
#include <errno.h>
New file. * plug-ins/makefile.msc: New file. * plug-ins/*/*.c (Well, not really all files, but many): Portability fixes. Include config.h, and guard inclusion of POSIX and Unix headers like <unistd.h>, <dirent.h> and <sys/time.h>. Include <string.h> if functions from it are used. Use g_ntohl() and g_htonl() insteead of ntohl() and htonl(), thus no need to include <netinet/in.h>. Include <io.h> on Win32 when using open/read/write (which actually are defined as _open/_read/_write by glib.h). Define S_* macros if necessary on Win32. Define rint() and M_PI if necessary (these definitions should be factored out somewhere, no sense repeating them in lots of files). Open files in binary mode when needed. * plug-ins/FractalExplorer/FractalExplorer.c: Use g_malloc()/g_free(). Use g_strdup_printf(). * plug-ins/dbbrowser/dbbrowser.c: No need to include <X11/Xlib.h>. * plug-ins/destripe/destripe.c: Guard use of SIGBUS. * plug-ins/{flame/flame,hrz/hrz,pnm/pnm}.c: No need to check for NULL returns from g_malloc() and g_new() as they abort on failure. Use g_strdup_printf(). * plug-ins/gz/gz.c: Win32 version of running the subprocess. * plug-ins/hrz/hrz.c: Win32 version. Use more generic tests for non-Unix (OS/2 and Win32), for instance HAVE_MMAP. * plug-ins/script-fu/interp_slib.c: Win32 version of myruntime(). * plug-ins/script-fu/interp_sliba.c: Handle \\ (escaped backslahsh). * plug-ins/script-fu/script-fu-console.c: Bypass on Win32. * plug-ins/script-fu/script-fu-scripts.c: Portability fixes. Use g_strdup_printf() instead of separate malloc() and sprintf(). Use g_strescape() for strings being passed to Scheme. Some Win32-only stuff.
1999-05-29 09:28:24 +08:00
#include <libgimp/gimp.h>
1999-10-14 10:11:52 +08:00
#include <libgimp/gimpui.h>
#include "libgimp/stdplugins-intl.h"
New file. * plug-ins/makefile.msc: New file. * plug-ins/*/*.c (Well, not really all files, but many): Portability fixes. Include config.h, and guard inclusion of POSIX and Unix headers like <unistd.h>, <dirent.h> and <sys/time.h>. Include <string.h> if functions from it are used. Use g_ntohl() and g_htonl() insteead of ntohl() and htonl(), thus no need to include <netinet/in.h>. Include <io.h> on Win32 when using open/read/write (which actually are defined as _open/_read/_write by glib.h). Define S_* macros if necessary on Win32. Define rint() and M_PI if necessary (these definitions should be factored out somewhere, no sense repeating them in lots of files). Open files in binary mode when needed. * plug-ins/FractalExplorer/FractalExplorer.c: Use g_malloc()/g_free(). Use g_strdup_printf(). * plug-ins/dbbrowser/dbbrowser.c: No need to include <X11/Xlib.h>. * plug-ins/destripe/destripe.c: Guard use of SIGBUS. * plug-ins/{flame/flame,hrz/hrz,pnm/pnm}.c: No need to check for NULL returns from g_malloc() and g_new() as they abort on failure. Use g_strdup_printf(). * plug-ins/gz/gz.c: Win32 version of running the subprocess. * plug-ins/hrz/hrz.c: Win32 version. Use more generic tests for non-Unix (OS/2 and Win32), for instance HAVE_MMAP. * plug-ins/script-fu/interp_slib.c: Win32 version of myruntime(). * plug-ins/script-fu/interp_sliba.c: Handle \\ (escaped backslahsh). * plug-ins/script-fu/script-fu-console.c: Bypass on Win32. * plug-ins/script-fu/script-fu-scripts.c: Portability fixes. Use g_strdup_printf() instead of separate malloc() and sprintf(). Use g_strescape() for strings being passed to Scheme. Some Win32-only stuff.
1999-05-29 09:28:24 +08:00
#define LOAD_PROC "file-pnm-load"
#define PNM_SAVE_PROC "file-pnm-save"
#define PBM_SAVE_PROC "file-pbm-save"
#define PGM_SAVE_PROC "file-pgm-save"
#define PPM_SAVE_PROC "file-ppm-save"
#define PFM_SAVE_PROC "file-pfm-save"
#define PLUG_IN_BINARY "file-pnm"
#define PLUG_IN_ROLE "gimp-file-pnm"
1997-11-25 06:05:25 +08:00
/* Declare local data types
*/
2013-10-04 01:59:54 +08:00
typedef struct _PNMScanner PNMScanner;
2013-10-04 04:06:24 +08:00
typedef struct _PNMInfo PNMInfo;
typedef struct _PNMRowInfo PNMRowInfo;
typedef void (* PNMLoaderFunc) (PNMScanner *scanner,
PNMInfo *info,
GeglBuffer *buffer);
typedef gboolean (* PNMSaverowFunc) (PNMRowInfo *info,
guchar *data,
2013-10-04 04:06:24 +08:00
GError **error);
2013-10-04 01:59:54 +08:00
struct _PNMScanner
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
{
2013-10-04 01:59:54 +08:00
GInputStream *input; /* The input stream of the file being read */
gchar cur; /* The current character in the input stream */
gint eof; /* Have we reached end of file? */
gchar *inbuf; /* Input buffer - initially 0 */
gint inbufsize; /* Size of input buffer */
gint inbufvalidsize; /* Size of input buffer with valid data */
gint inbufpos; /* Position in input buffer */
};
struct _PNMInfo
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
{
2013-10-04 04:06:24 +08:00
gint xres, yres; /* The size of the image */
gboolean float_format; /* Whether it is a floating point format */
gint maxval; /* For integer format image files, the max value
* which we need to normalize to */
gfloat scale_factor; /* PFM files have a scale factor */
2013-10-04 04:06:24 +08:00
gint np; /* Number of image planes (0 for pbm) */
gboolean asciibody; /* 1 if ascii body, 0 if raw body */
jmp_buf jmpbuf; /* Where to jump to on an error loading */
PNMLoaderFunc loader; /* Routine to use to load the pnm body */
2013-10-04 01:59:54 +08:00
};
1997-11-25 06:05:25 +08:00
/* Contains the information needed to write out PNM rows */
2013-10-04 04:06:24 +08:00
struct _PNMRowInfo
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
{
2013-10-04 03:44:24 +08:00
GOutputStream *output; /* Output stream */
gchar *rowbuf; /* Buffer for writing out rows */
gint xres; /* X resolution */
gint np; /* Number of planes */
gint bpc; /* Bytes per color */
2013-10-04 03:44:24 +08:00
guchar *red; /* Colormap red */
guchar *grn; /* Colormap green */
guchar *blu; /* Colormap blue */
gboolean zero_is_black; /* index zero is black (PBM only) */
2013-10-04 04:06:24 +08:00
};
1997-11-25 06:05:25 +08:00
/* Export info */
1997-11-25 06:05:25 +08:00
typedef struct
{
gint raw; /* raw or ascii */
1997-11-25 06:05:25 +08:00
} PNMSaveVals;
#define BUFLEN 512 /* The input buffer size for data returned
* from the scanner. Note that lines
* aren't allowed to be over 256 characters
* by the spec anyways so this shouldn't
* be an issue. */
1997-11-25 06:05:25 +08:00
/* Declare some local functions.
*/
2013-10-04 03:44: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 (GFile *file,
GError **error);
static gint save_image (GFile *file,
gint32 image_ID,
gint32 drawable_ID,
gboolean pbm,
gboolean float_format,
2013-10-04 03:44:24 +08:00
GError **error);
2013-10-04 04:06:24 +08:00
static gboolean save_dialog (void);
2013-10-04 03:44:24 +08:00
static void pnm_load_ascii (PNMScanner *scan,
PNMInfo *info,
GeglBuffer *buffer);
static void pnm_load_raw (PNMScanner *scan,
PNMInfo *info,
GeglBuffer *buffer);
static void pnm_load_rawpbm (PNMScanner *scan,
PNMInfo *info,
GeglBuffer *buffer);
static void pnm_load_rawpfm (PNMScanner *scan,
PNMInfo *info,
GeglBuffer *buffer);
2013-10-04 03:44:24 +08:00
static gboolean pnmsaverow_ascii (PNMRowInfo *ri,
guchar *data,
2013-10-04 03:44:24 +08:00
GError **error);
static gboolean pnmsaverow_raw (PNMRowInfo *ri,
guchar *data,
2013-10-04 03:44:24 +08:00
GError **error);
static gboolean pnmsaverow_raw_pbm (PNMRowInfo *ri,
guchar *data,
2013-10-04 03:44:24 +08:00
GError **error);
static gboolean pnmsaverow_ascii_pbm (PNMRowInfo *ri,
guchar *data,
2013-10-04 03:44:24 +08:00
GError **error);
static gboolean pnmsaverow_ascii_indexed (PNMRowInfo *ri,
guchar *data,
2013-10-04 03:44:24 +08:00
GError **error);
static gboolean pnmsaverow_raw_indexed (PNMRowInfo *ri,
guchar *data,
2013-10-04 03:44:24 +08:00
GError **error);
static void pnmscanner_destroy (PNMScanner *s);
static void pnmscanner_createbuffer (PNMScanner *s,
gint bufsize);
static void pnmscanner_getchar (PNMScanner *s);
static void pnmscanner_eatwhitespace (PNMScanner *s);
static void pnmscanner_gettoken (PNMScanner *s,
gchar *buf,
gint bufsize);
static void pnmscanner_getsmalltoken (PNMScanner *s,
gchar *buf);
static PNMScanner * pnmscanner_create (GInputStream *input);
1997-11-25 06:05:25 +08:00
2013-10-04 01:59:54 +08:00
#define pnmscanner_eof(s) ((s)->eof)
#define pnmscanner_input(s) ((s)->input)
1997-11-25 06:05:25 +08:00
/* Checks for a fatal error */
2013-10-04 01:59:54 +08:00
#define CHECK_FOR_ERROR(predicate, jmpbuf, ...) \
1997-11-25 06:05:25 +08:00
if ((predicate)) \
2013-10-04 01:59:54 +08:00
{ g_message (__VA_ARGS__); longjmp ((jmpbuf), 1); }
1997-11-25 06:05:25 +08:00
2013-10-04 04:06:24 +08:00
static const struct
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
{
2013-10-04 04:06:24 +08:00
gchar name;
gint np;
gint asciibody;
gint maxval;
PNMLoaderFunc loader;
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
} pnm_types[] =
{
{ '1', 0, 1, 1, pnm_load_ascii }, /* ASCII PBM */
{ '2', 1, 1, 255, pnm_load_ascii }, /* ASCII PGM */
{ '3', 3, 1, 255, pnm_load_ascii }, /* ASCII PPM */
{ '4', 0, 0, 1, pnm_load_rawpbm }, /* RAW PBM */
{ '5', 1, 0, 255, pnm_load_raw }, /* RAW PGM */
{ '6', 3, 0, 255, pnm_load_raw }, /* RAW PPM */
{ 'F', 3, 0, 0, pnm_load_rawpfm }, /* RAW PFM (color) */
{ 'f', 1, 0, 0, pnm_load_rawpfm }, /* RAW PFM (grayscale) */
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
{ 0 , 0, 0, 0, NULL}
1997-11-25 06:05:25 +08:00
};
const GimpPlugInInfo PLUG_IN_INFO =
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
NULL, /* init_proc */
NULL, /* quit_proc */
query, /* query_proc */
run, /* run_proc */
1997-11-25 06:05:25 +08:00
};
static PNMSaveVals psvals =
{
TRUE /* raw? or ascii */
};
MAIN ()
static void
query (void)
1997-11-25 06:05:25 +08:00
{
static const GimpParamDef load_args[] =
1997-11-25 06:05:25 +08:00
{
{ GIMP_PDB_INT32, "run-mode", "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" },
{ GIMP_PDB_STRING, "filename", "The name of the file to load" },
{ GIMP_PDB_STRING, "raw-filename", "The name of the file to load" }
1997-11-25 06:05:25 +08:00
};
static const GimpParamDef load_return_vals[] =
1997-11-25 06:05:25 +08:00
{
{ GIMP_PDB_IMAGE, "image", "Output image" }
1997-11-25 06:05:25 +08:00
};
static const GimpParamDef save_args[] =
1997-11-25 06:05:25 +08:00
{
{ GIMP_PDB_INT32, "run-mode", "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" },
{ GIMP_PDB_IMAGE, "image", "Input image" },
{ GIMP_PDB_DRAWABLE, "drawable", "Drawable to export" },
{ GIMP_PDB_STRING, "filename", "The name of the file to export the image in" },
{ GIMP_PDB_STRING, "raw-filename", "The name of the file to export the image in" },
2013-10-04 04:06:24 +08:00
{ GIMP_PDB_INT32, "raw", "TRUE for raw output, FALSE for ascii output" }
1997-11-25 06:05:25 +08:00
};
static const GimpParamDef pfm_save_args[] =
{
{ GIMP_PDB_INT32, "run-mode", "The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }" },
{ GIMP_PDB_IMAGE, "image", "Input image" },
{ GIMP_PDB_DRAWABLE, "drawable", "Drawable to export" },
{ GIMP_PDB_STRING, "filename", "The name of the file to export the image in" },
{ GIMP_PDB_STRING, "raw-filename", "The name of the file to export the image in" }
};
gimp_install_procedure (LOAD_PROC,
"Loads files in the PNM file format",
"This plug-in loads files in the various Netpbm portable file formats.",
1997-11-25 06:05:25 +08:00
"Erik Nygren",
"Erik Nygren",
"1996",
N_("PNM Image"),
NULL,
GIMP_PLUGIN,
G_N_ELEMENTS (load_args),
G_N_ELEMENTS (load_return_vals),
1997-11-25 06:05:25 +08:00
load_args, load_return_vals);
gimp_register_file_handler_mime (LOAD_PROC, "image/x-portable-anymap");
gimp_register_file_handler_remote (LOAD_PROC);
gimp_register_magic_load_handler (LOAD_PROC,
"pnm,ppm,pgm,pbm,pfm",
"",
"0,string,P1,0,string,P2,0,string,P3,"
"0,string,P4,0,string,P5,0,string,P6,"
"0,string,PF,0,string,Pf");
gimp_install_procedure (PNM_SAVE_PROC,
"Exports files in the PNM file format",
"PNM exporting handles all image types without transparency.",
1997-11-25 06:05:25 +08:00
"Erik Nygren",
"Erik Nygren",
"1996",
N_("PNM image"),
"RGB, GRAY, INDEXED",
GIMP_PLUGIN,
G_N_ELEMENTS (save_args), 0,
1997-11-25 06:05:25 +08:00
save_args, NULL);
gimp_install_procedure (PBM_SAVE_PROC,
"Exports files in the PBM file format",
"PBM exporting produces mono images without transparency.",
"Martin K Collins",
"Erik Nygren",
"2006",
N_("PBM image"),
"RGB, GRAY, INDEXED",
GIMP_PLUGIN,
G_N_ELEMENTS (save_args), 0,
save_args, NULL);
gimp_install_procedure (PGM_SAVE_PROC,
"Exports files in the PGM file format",
"PGM exporting produces grayscale images without transparency.",
"Erik Nygren",
"Erik Nygren",
"1996",
N_("PGM image"),
"RGB, GRAY, INDEXED",
GIMP_PLUGIN,
G_N_ELEMENTS (save_args), 0,
save_args, NULL);
gimp_install_procedure (PPM_SAVE_PROC,
"Exports files in the PPM file format",
"PPM exporting handles RGB images without transparency.",
"Erik Nygren",
"Erik Nygren",
"1996",
N_("PPM image"),
"RGB, GRAY, INDEXED",
GIMP_PLUGIN,
G_N_ELEMENTS (save_args), 0,
save_args, NULL);
gimp_install_procedure (PFM_SAVE_PROC,
"Exports files in the PFM file format",
"PFM exporting handles all images without transparency.",
"Mukund Sivaraman",
"Mukund Sivaraman",
"2015",
N_("PFM image"),
"RGB, GRAY, INDEXED",
GIMP_PLUGIN,
G_N_ELEMENTS (pfm_save_args), 0,
pfm_save_args, NULL);
gimp_register_file_handler_mime (PNM_SAVE_PROC, "image/x-portable-anymap");
gimp_register_file_handler_mime (PBM_SAVE_PROC, "image/x-portable-bitmap");
gimp_register_file_handler_mime (PGM_SAVE_PROC, "image/x-portable-graymap");
gimp_register_file_handler_mime (PPM_SAVE_PROC, "image/x-portable-pixmap");
gimp_register_file_handler_mime (PPM_SAVE_PROC, "image/x-portable-floatmap");
2013-10-04 01:59:54 +08:00
gimp_register_file_handler_remote (PNM_SAVE_PROC);
gimp_register_file_handler_remote (PBM_SAVE_PROC);
gimp_register_file_handler_remote (PGM_SAVE_PROC);
gimp_register_file_handler_remote (PPM_SAVE_PROC);
gimp_register_file_handler_remote (PFM_SAVE_PROC);
2013-10-04 03:44:24 +08:00
gimp_register_save_handler (PNM_SAVE_PROC, "pnm", "");
gimp_register_save_handler (PBM_SAVE_PROC, "pbm", "");
gimp_register_save_handler (PGM_SAVE_PROC, "pgm", "");
gimp_register_save_handler (PPM_SAVE_PROC, "ppm", "");
gimp_register_save_handler (PFM_SAVE_PROC, "pfm", "");
1997-11-25 06:05:25 +08:00
}
static void
run (const gchar *name,
gint nparams,
const GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals)
1997-11-25 06:05:25 +08:00
{
static GimpParam values[2];
GimpRunMode run_mode;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
gint32 image_ID;
gint32 drawable_ID;
GimpExportReturn export = GIMP_EXPORT_CANCEL;
GError *error = NULL;
gboolean pbm = FALSE; /* flag for PBM output */
gboolean float_format = FALSE; /* flag for PFM output */
1997-11-25 06:05:25 +08:00
2012-11-26 08:31:39 +08:00
INIT_I18N ();
gegl_init (NULL, NULL);
1997-11-25 06:05:25 +08:00
run_mode = param[0].data.d_int32;
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
*nreturn_vals = 1;
*return_vals = values;
values[0].type = GIMP_PDB_STATUS;
values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
1997-11-25 06:05:25 +08:00
if (strcmp (name, LOAD_PROC) == 0)
1997-11-25 06:05:25 +08:00
{
2013-10-04 01:59:54 +08:00
image_ID = load_image (g_file_new_for_uri (param[1].data.d_string),
&error);
1997-11-25 06:05:25 +08:00
if (image_ID != -1)
{
*nreturn_vals = 2;
values[1].type = GIMP_PDB_IMAGE;
values[1].data.d_image = image_ID;
}
1997-11-25 06:05:25 +08:00
else
{
status = GIMP_PDB_EXECUTION_ERROR;
}
1997-11-25 06:05:25 +08:00
}
else if (strcmp (name, PNM_SAVE_PROC) == 0 ||
strcmp (name, PBM_SAVE_PROC) == 0 ||
strcmp (name, PGM_SAVE_PROC) == 0 ||
strcmp (name, PPM_SAVE_PROC) == 0 ||
strcmp (name, PFM_SAVE_PROC) == 0)
1997-11-25 06:05:25 +08:00
{
image_ID = param[1].data.d_int32;
drawable_ID = param[2].data.d_int32;
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
/* eventually export the image */
1999-10-14 10:11:52 +08:00
switch (run_mode)
{
case GIMP_RUN_INTERACTIVE:
case GIMP_RUN_WITH_LAST_VALS:
gimp_ui_init (PLUG_IN_BINARY, FALSE);
if (strcmp (name, PNM_SAVE_PROC) == 0)
{
export = gimp_export_image (&image_ID, &drawable_ID, "PNM",
GIMP_EXPORT_CAN_HANDLE_RGB |
GIMP_EXPORT_CAN_HANDLE_GRAY |
GIMP_EXPORT_CAN_HANDLE_INDEXED);
}
else if (strcmp (name, PBM_SAVE_PROC) == 0)
{
export = gimp_export_image (&image_ID, &drawable_ID, "PBM",
GIMP_EXPORT_CAN_HANDLE_BITMAP);
pbm = TRUE; /* gimp has no mono image type so hack it */
}
else if (strcmp (name, PGM_SAVE_PROC) == 0)
{
export = gimp_export_image (&image_ID, &drawable_ID, "PGM",
GIMP_EXPORT_CAN_HANDLE_GRAY);
}
else if (strcmp (name, PPM_SAVE_PROC) == 0)
{
export = gimp_export_image (&image_ID, &drawable_ID, "PPM",
GIMP_EXPORT_CAN_HANDLE_RGB |
GIMP_EXPORT_CAN_HANDLE_INDEXED);
}
else
{
export = gimp_export_image (&image_ID, &drawable_ID, "PFM",
GIMP_EXPORT_CAN_HANDLE_RGB |
GIMP_EXPORT_CAN_HANDLE_GRAY);
float_format = TRUE;
}
if (export == GIMP_EXPORT_CANCEL)
{
values[0].data.d_status = GIMP_PDB_CANCEL;
return;
}
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
if (strcmp (name, PFM_SAVE_PROC) != 0)
{
switch (run_mode)
{
case GIMP_RUN_INTERACTIVE:
/* Possibly retrieve data */
gimp_get_data (name, &psvals);
/* First acquire information with a dialog */
if (! save_dialog ())
status = GIMP_PDB_CANCEL;
break;
case GIMP_RUN_NONINTERACTIVE:
/* Make sure all the arguments are there! */
if (nparams != 6)
{
status = GIMP_PDB_CALLING_ERROR;
}
else
{
psvals.raw = (param[5].data.d_int32) ? TRUE : FALSE;
pbm = (strcmp (name, PBM_SAVE_PROC) == 0);
}
break;
case GIMP_RUN_WITH_LAST_VALS:
/* Possibly retrieve data */
gimp_get_data (name, &psvals);
break;
default:
break;
}
}
else
{
switch (run_mode)
{
case GIMP_RUN_NONINTERACTIVE:
/* Make sure all the arguments are there! */
if (nparams != 5)
{
status = GIMP_PDB_CALLING_ERROR;
}
break;
default:
break;
}
}
1997-11-25 06:05:25 +08:00
if (status == GIMP_PDB_SUCCESS)
{
2013-10-04 03:44:24 +08:00
if (save_image (g_file_new_for_uri (param[3].data.d_string),
image_ID, drawable_ID, pbm, float_format,
&error))
{
if (strcmp (name, PFM_SAVE_PROC) != 0)
{
/* Store psvals data */
gimp_set_data (name, &psvals, sizeof (PNMSaveVals));
}
}
else
{
status = GIMP_PDB_EXECUTION_ERROR;
}
}
1999-10-14 10:11:52 +08:00
if (export == GIMP_EXPORT_EXPORT)
gimp_image_delete (image_ID);
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
else
{
status = GIMP_PDB_CALLING_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
}
if (status != GIMP_PDB_SUCCESS && error)
{
*nreturn_vals = 2;
values[1].type = GIMP_PDB_STRING;
values[1].data.d_string = error->message;
}
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
values[0].data.d_status = status;
gegl_exit ();
1997-11-25 06:05:25 +08:00
}
static gint32
2013-10-04 01:59:54 +08:00
load_image (GFile *file,
GError **error)
1997-11-25 06:05:25 +08:00
{
2013-10-04 01:59:54 +08:00
GInputStream *input;
GeglBuffer *buffer;
gint32 volatile image_ID = -1;
gint32 layer_ID;
char buf[BUFLEN + 4]; /* buffer for random things like scanning */
PNMInfo *pnminfo;
PNMScanner *volatile scan;
int ctr;
GimpPrecision precision;
1997-11-25 06:05:25 +08:00
gimp_progress_init_printf (_("Opening '%s'"),
g_file_get_parse_name (file));
2013-10-04 01:59:54 +08:00
input = G_INPUT_STREAM (g_file_read (file, NULL, error));
if (! input)
return -1;
1997-11-25 06:05:25 +08:00
/* allocate the necessary structures */
pnminfo = g_new (PNMInfo, 1);
1997-11-25 06:05:25 +08:00
scan = NULL;
/* set error handling */
if (setjmp (pnminfo->jmpbuf))
{
/* If we get here, we had a problem reading the file */
if (scan)
pnmscanner_destroy (scan);
2013-10-04 01:59:54 +08:00
g_object_unref (input);
1997-11-25 06:05:25 +08:00
g_free (pnminfo);
2000-02-20 03:36:10 +08:00
if (image_ID != -1)
gimp_image_delete (image_ID);
1997-11-25 06:05:25 +08:00
return -1;
}
2013-10-04 01:59:54 +08:00
if (! (scan = pnmscanner_create (input)))
longjmp (pnminfo->jmpbuf, 1);
1997-11-25 06:05:25 +08:00
/* Get magic number */
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
pnmscanner_gettoken (scan, buf, BUFLEN);
CHECK_FOR_ERROR (pnmscanner_eof (scan), pnminfo->jmpbuf,
_("Premature end of file."));
CHECK_FOR_ERROR ((buf[0] != 'P' || buf[2]), pnminfo->jmpbuf,
_("Invalid file."));
1997-11-25 06:05:25 +08:00
/* Look up magic number to see what type of PNM this is */
for (ctr = 0; pnm_types[ctr].name; ctr++)
1997-11-25 06:05:25 +08:00
if (buf[1] == pnm_types[ctr].name)
{
pnminfo->np = pnm_types[ctr].np;
pnminfo->asciibody = pnm_types[ctr].asciibody;
pnminfo->float_format = g_ascii_tolower (pnm_types[ctr].name) == 'f';
pnminfo->maxval = pnm_types[ctr].maxval;
pnminfo->loader = pnm_types[ctr].loader;
1997-11-25 06:05:25 +08:00
}
1997-11-25 06:05:25 +08:00
if (!pnminfo->loader)
{
Cleaned up and improved the message system: 2003-06-13 Michael Natterer <mitch@gimp.org> Cleaned up and improved the message system: * app/core/gimp.[ch]: added "const gchar *domain" to GimpMessageFunc (a NULL domain means the message is from the GIMP core, everything else is a plug-in). * app/errors.c: pass "domain == NULL" to gimp_message(). * tools/pdbgen/pdb/message.pdb: derive the message domain from the current plug-in's menu_path (evil hack but works reasonably well). * app/pdb/message_cmds.c: regenerated. * app/widgets/gimpwidgets-utils.[ch] (gimp_message_box): added a header showing the message domain and changed the dialog layout to follow the HIG more closely. * app/gui/error-console-dialog.[ch]: removed. * app/widgets/gimperrorconsole.[ch] * app/gui/error-console-commands.[ch] * app/gui/error-console-menu.[ch]: new files containing a re-implementation of the error console dialog. * app/gui/Makefile.am * app/gui/dialogs-constructors.c * app/gui/gui.c * app/gui/menus.c * app/widgets/Makefile.am * app/widgets/widgets-types.h: changed accordingly. * app/display/gimpprogress.c: added more spacing and removed the separator (more HIG compliant). * plug-ins/[most plug-ins].c: Changed lots of messages and progress strings: - Removed plug-in names from messages since that's automatically covered by "domain" now. - Put all filenames in ''. - Changed "Loading" to "Opening". - Added "..." to all progress messages. - Cleaned up all file open/save error messages to look the same and include g_strerror(errno). - Removed special casing for progress bars and *always* show them, not only if run_mode != GIMP_RUN_NONINTERACTIVE (we can't expect all plug-ins to do this correctly but need to hack the core to sort out unwanted progress bars). Unrelated: - Cleaned up indentation, spacing, #includes, coding style and other stuff while I was at all these files.
2003-06-13 22:37:00 +08:00
g_message (_("File not in a supported format."));
longjmp (pnminfo->jmpbuf, 1);
1997-11-25 06:05:25 +08:00
}
pnmscanner_gettoken (scan, buf, BUFLEN);
CHECK_FOR_ERROR (pnmscanner_eof (scan), pnminfo->jmpbuf,
_("Premature end of file."));
pnminfo->xres = g_ascii_isdigit(*buf) ? atoi (buf) : 0;
CHECK_FOR_ERROR (pnminfo->xres <= 0, pnminfo->jmpbuf,
_("Invalid X resolution."));
CHECK_FOR_ERROR (pnminfo->xres > GIMP_MAX_IMAGE_SIZE, pnminfo->jmpbuf,
_("Image width is larger than GIMP can handle."));
pnmscanner_gettoken (scan, buf, BUFLEN);
CHECK_FOR_ERROR (pnmscanner_eof (scan), pnminfo->jmpbuf,
_("Premature end of file."));
pnminfo->yres = g_ascii_isdigit (*buf) ? atoi (buf) : 0;
CHECK_FOR_ERROR (pnminfo->yres <= 0, pnminfo->jmpbuf,
_("Invalid Y resolution."));
CHECK_FOR_ERROR (pnminfo->yres > GIMP_MAX_IMAGE_SIZE, pnminfo->jmpbuf,
_("Image height is larger than GIMP can handle."));
if (pnminfo->float_format)
{
gchar *endptr = NULL;
pnmscanner_gettoken (scan, buf, BUFLEN);
CHECK_FOR_ERROR (pnmscanner_eof (scan), pnminfo->jmpbuf,
_("Premature end of file."));
pnminfo->scale_factor = g_ascii_strtod (buf, &endptr);
CHECK_FOR_ERROR (endptr == NULL || *endptr != 0 || errno == ERANGE,
pnminfo->jmpbuf, _("Bogus scale factor."));
CHECK_FOR_ERROR (!isnormal (pnminfo->scale_factor),
pnminfo->jmpbuf, _("Unsupported scale factor."));
precision = GIMP_PRECISION_FLOAT_LINEAR;
}
else if (pnminfo->np != 0) /* pbm's don't have a maxval field */
1997-11-25 06:05:25 +08:00
{
pnmscanner_gettoken (scan, buf, BUFLEN);
CHECK_FOR_ERROR (pnmscanner_eof (scan), pnminfo->jmpbuf,
_("Premature end of file."));
pnminfo->maxval = g_ascii_isdigit (*buf) ? atoi (buf) : 0;
CHECK_FOR_ERROR (((pnminfo->maxval<=0) || (pnminfo->maxval>65535)),
pnminfo->jmpbuf, _("Unsupported maximum value."));
if (pnminfo->maxval < 256)
{
Initial space invasion commit in GIMP All babl formats now have a space equivalent to a color profile, determining the format's primaries and TRCs. This commit makes GIMP aware of this. libgimp: - enum GimpPrecision: rename GAMMA values to NON_LINEAR and keep GAMMA as deprecated aliases, add PERCEPTUAL values so we now have LINEAR, NON_LINEAR and PERCPTUAL for each encoding, matching the babl encoding variants RGB, R'G'B' and R~G~B~. - gimp_color_transform_can_gegl_copy() now returns TRUE if both profiles can return a babl space, increasing the amount of fast babl color conversions significantly. - TODO: no solution yet for getting libgimp drawable proxy buffers in the right format with space. plug-ins: - follow the GimpPrecision change. - TODO: everything else unchanged and partly broken or sub-optimal, like setting a new image's color profile too late. app: - add enum GimpTRCType { LINEAR, NON_LINEAR, PERCEPTUAL } as replacement for all "linear" booleans. - change gimp-babl functions to take babl spaces and GimpTRCType parameters and support all sorts of new perceptual ~ formats. - a lot of places changed in the early days of goat invasion didn't take advantage of gimp-babl utility functions and constructed formats manually. They all needed revisiting and many now use much simpler code calling gimp-babl API. - change gimp_babl_format_get_color_profile() to really extract a newly allocated color profile from the format, and add gimp_babl_get_builtin_color_profile() which does the same as gimp_babl_format_get_color_profile() did before. Visited all callers to decide whether they are looking for the format's actual profile, or for one of the builtin profiles, simplifying code that only needs builtin profiles. - drawables have a new get_space_api(), get_linear() is now get_trc(). - images now have a "layer space" and an API to get it, gimp_image_get_layer_format() returns formats in that space. - an image's layer space is created from the image's color profile, change gimpimage-color-profile to deal with that correctly - change many babl_format() calls to babl_format_with_space() and take the space from passed formats or drawables - add function gimp_layer_fix_format_space() which replaces the layer's buffer with one that has the image's layer format, but doesn't change pixel values - use gimp_layer_fix_format_space() to make sure layers loaded from XCF and created by plug-ins have the right space when added to the image, because it's impossible to always assign the right space upon layer creation - "assign color profile" and "discard color profile" now require use of gimp_layer_fix_format_space() too because the profile is now embedded in all formats via the space. Add gimp_image_assign_color_profile() which does all that and call it instead of a simple gimp_image_set_color_profile(), also from the PDB set-color-profile functions, which are essentially "assign" and "discard" calls. - generally, make sure a new image's color profile is set before adding layers to it, gimp_image_set_color_profile() is more than before considered know-what-you-are-doing API. - take special precaution in all places that call gimp_drawable_convert_type(), we now must pass a new_profile from all callers that convert layers within the same image (such as image_convert_type, image_convert_precision), because the layer's new space can't be determined from the image's layer format during the call. - change all "linear" properties to "trc", in all config objects like for levels and curves, in the histogram, in the widgets. This results in some GUI that now has three choices instead of two. TODO: we might want to reduce that back to two later. - keep "linear" boolean properties around as compat if needed for file pasring, but always convert the parsed parsed boolean to GimpTRCType. - TODO: the image's "enable color management" switch is currently broken, will fix that in another commit.
2018-07-21 20:23:01 +08:00
precision = GIMP_PRECISION_U8_NON_LINEAR;
}
else
{
Initial space invasion commit in GIMP All babl formats now have a space equivalent to a color profile, determining the format's primaries and TRCs. This commit makes GIMP aware of this. libgimp: - enum GimpPrecision: rename GAMMA values to NON_LINEAR and keep GAMMA as deprecated aliases, add PERCEPTUAL values so we now have LINEAR, NON_LINEAR and PERCPTUAL for each encoding, matching the babl encoding variants RGB, R'G'B' and R~G~B~. - gimp_color_transform_can_gegl_copy() now returns TRUE if both profiles can return a babl space, increasing the amount of fast babl color conversions significantly. - TODO: no solution yet for getting libgimp drawable proxy buffers in the right format with space. plug-ins: - follow the GimpPrecision change. - TODO: everything else unchanged and partly broken or sub-optimal, like setting a new image's color profile too late. app: - add enum GimpTRCType { LINEAR, NON_LINEAR, PERCEPTUAL } as replacement for all "linear" booleans. - change gimp-babl functions to take babl spaces and GimpTRCType parameters and support all sorts of new perceptual ~ formats. - a lot of places changed in the early days of goat invasion didn't take advantage of gimp-babl utility functions and constructed formats manually. They all needed revisiting and many now use much simpler code calling gimp-babl API. - change gimp_babl_format_get_color_profile() to really extract a newly allocated color profile from the format, and add gimp_babl_get_builtin_color_profile() which does the same as gimp_babl_format_get_color_profile() did before. Visited all callers to decide whether they are looking for the format's actual profile, or for one of the builtin profiles, simplifying code that only needs builtin profiles. - drawables have a new get_space_api(), get_linear() is now get_trc(). - images now have a "layer space" and an API to get it, gimp_image_get_layer_format() returns formats in that space. - an image's layer space is created from the image's color profile, change gimpimage-color-profile to deal with that correctly - change many babl_format() calls to babl_format_with_space() and take the space from passed formats or drawables - add function gimp_layer_fix_format_space() which replaces the layer's buffer with one that has the image's layer format, but doesn't change pixel values - use gimp_layer_fix_format_space() to make sure layers loaded from XCF and created by plug-ins have the right space when added to the image, because it's impossible to always assign the right space upon layer creation - "assign color profile" and "discard color profile" now require use of gimp_layer_fix_format_space() too because the profile is now embedded in all formats via the space. Add gimp_image_assign_color_profile() which does all that and call it instead of a simple gimp_image_set_color_profile(), also from the PDB set-color-profile functions, which are essentially "assign" and "discard" calls. - generally, make sure a new image's color profile is set before adding layers to it, gimp_image_set_color_profile() is more than before considered know-what-you-are-doing API. - take special precaution in all places that call gimp_drawable_convert_type(), we now must pass a new_profile from all callers that convert layers within the same image (such as image_convert_type, image_convert_precision), because the layer's new space can't be determined from the image's layer format during the call. - change all "linear" properties to "trc", in all config objects like for levels and curves, in the histogram, in the widgets. This results in some GUI that now has three choices instead of two. TODO: we might want to reduce that back to two later. - keep "linear" boolean properties around as compat if needed for file pasring, but always convert the parsed parsed boolean to GimpTRCType. - TODO: the image's "enable color management" switch is currently broken, will fix that in another commit.
2018-07-21 20:23:01 +08:00
precision = GIMP_PRECISION_U16_NON_LINEAR;
}
}
else
{
Initial space invasion commit in GIMP All babl formats now have a space equivalent to a color profile, determining the format's primaries and TRCs. This commit makes GIMP aware of this. libgimp: - enum GimpPrecision: rename GAMMA values to NON_LINEAR and keep GAMMA as deprecated aliases, add PERCEPTUAL values so we now have LINEAR, NON_LINEAR and PERCPTUAL for each encoding, matching the babl encoding variants RGB, R'G'B' and R~G~B~. - gimp_color_transform_can_gegl_copy() now returns TRUE if both profiles can return a babl space, increasing the amount of fast babl color conversions significantly. - TODO: no solution yet for getting libgimp drawable proxy buffers in the right format with space. plug-ins: - follow the GimpPrecision change. - TODO: everything else unchanged and partly broken or sub-optimal, like setting a new image's color profile too late. app: - add enum GimpTRCType { LINEAR, NON_LINEAR, PERCEPTUAL } as replacement for all "linear" booleans. - change gimp-babl functions to take babl spaces and GimpTRCType parameters and support all sorts of new perceptual ~ formats. - a lot of places changed in the early days of goat invasion didn't take advantage of gimp-babl utility functions and constructed formats manually. They all needed revisiting and many now use much simpler code calling gimp-babl API. - change gimp_babl_format_get_color_profile() to really extract a newly allocated color profile from the format, and add gimp_babl_get_builtin_color_profile() which does the same as gimp_babl_format_get_color_profile() did before. Visited all callers to decide whether they are looking for the format's actual profile, or for one of the builtin profiles, simplifying code that only needs builtin profiles. - drawables have a new get_space_api(), get_linear() is now get_trc(). - images now have a "layer space" and an API to get it, gimp_image_get_layer_format() returns formats in that space. - an image's layer space is created from the image's color profile, change gimpimage-color-profile to deal with that correctly - change many babl_format() calls to babl_format_with_space() and take the space from passed formats or drawables - add function gimp_layer_fix_format_space() which replaces the layer's buffer with one that has the image's layer format, but doesn't change pixel values - use gimp_layer_fix_format_space() to make sure layers loaded from XCF and created by plug-ins have the right space when added to the image, because it's impossible to always assign the right space upon layer creation - "assign color profile" and "discard color profile" now require use of gimp_layer_fix_format_space() too because the profile is now embedded in all formats via the space. Add gimp_image_assign_color_profile() which does all that and call it instead of a simple gimp_image_set_color_profile(), also from the PDB set-color-profile functions, which are essentially "assign" and "discard" calls. - generally, make sure a new image's color profile is set before adding layers to it, gimp_image_set_color_profile() is more than before considered know-what-you-are-doing API. - take special precaution in all places that call gimp_drawable_convert_type(), we now must pass a new_profile from all callers that convert layers within the same image (such as image_convert_type, image_convert_precision), because the layer's new space can't be determined from the image's layer format during the call. - change all "linear" properties to "trc", in all config objects like for levels and curves, in the histogram, in the widgets. This results in some GUI that now has three choices instead of two. TODO: we might want to reduce that back to two later. - keep "linear" boolean properties around as compat if needed for file pasring, but always convert the parsed parsed boolean to GimpTRCType. - TODO: the image's "enable color management" switch is currently broken, will fix that in another commit.
2018-07-21 20:23:01 +08:00
precision = GIMP_PRECISION_U8_NON_LINEAR;
1997-11-25 06:05:25 +08:00
}
2015-01-18 09:25:56 +08:00
/* Create a new image of the proper size and associate the filename
with it. */
image_ID = gimp_image_new_with_precision
(pnminfo->xres, pnminfo->yres,
(pnminfo->np >= 3) ? GIMP_RGB : GIMP_GRAY,
precision);
2015-01-18 09:25:56 +08:00
2013-10-04 01:59:54 +08:00
gimp_image_set_filename (image_ID, g_file_get_uri (file));
1997-11-25 06:05:25 +08:00
layer_ID = gimp_layer_new (image_ID, _("Background"),
pnminfo->xres, pnminfo->yres,
(pnminfo->np >= 3 ?
GIMP_RGB_IMAGE : GIMP_GRAY_IMAGE),
100,
gimp_image_get_default_new_layer_mode (image_ID));
gimp_image_insert_layer (image_ID, layer_ID, -1, 0);
1997-11-25 06:05:25 +08:00
2012-11-26 08:31:39 +08:00
buffer = gimp_drawable_get_buffer (layer_ID);
1997-11-25 06:05:25 +08:00
2012-11-26 08:31:39 +08:00
pnminfo->loader (scan, pnminfo, buffer);
1997-11-25 06:05:25 +08:00
/* Destroy the scanner */
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
pnmscanner_destroy (scan);
1997-11-25 06:05:25 +08:00
2012-11-26 08:31:39 +08:00
g_object_unref (buffer);
1997-11-25 06:05:25 +08:00
g_free (pnminfo);
2013-10-04 01:59:54 +08:00
g_object_unref (input);
1997-11-25 06:05:25 +08:00
return image_ID;
}
static void
2012-11-26 08:31:39 +08:00
pnm_load_ascii (PNMScanner *scan,
PNMInfo *info,
GeglBuffer *buffer)
1997-11-25 06:05:25 +08:00
{
gint bpc;
guchar *data, *d;
gushort *s;
gint x, y, i, b;
gint start, end, scanlines;
gint np;
gchar buf[BUFLEN];
gboolean aborted = FALSE;
1997-11-25 06:05:25 +08:00
np = (info->np) ? (info->np) : 1;
if (info->maxval > 255)
bpc = 2;
else
bpc = 1;
/* No overflow as long as gimp_tile_height() < 1365 = 2^(31 - 18) / 6 */
data = g_new (guchar, gimp_tile_height () * info->xres * np * bpc);
1997-11-25 06:05:25 +08:00
/* Buffer reads to increase performance */
pnmscanner_createbuffer (scan, 4096);
1997-11-25 06:05:25 +08:00
for (y = 0; y < info->yres; y += scanlines)
1997-11-25 06:05:25 +08:00
{
start = y;
end = y + gimp_tile_height ();
end = MIN (end, info->yres);
1997-11-25 06:05:25 +08:00
scanlines = end - start;
1997-11-25 06:05:25 +08:00
d = data;
s = (gushort *)d;
1997-11-25 06:05:25 +08:00
for (i = 0; i < scanlines; i++)
for (x = 0; x < info->xres; x++)
{
for (b = 0; b < np; b++)
{
if (aborted)
{
d[b] = 0;
continue;
}
/* Truncated files will just have all 0's
at the end of the images */
if (pnmscanner_eof (scan))
{
g_message (_("Premature end of file."));
aborted = TRUE;
d[b] = 0;
continue;
}
if (info->np)
pnmscanner_gettoken (scan, buf, BUFLEN);
else
pnmscanner_getsmalltoken (scan, buf);
if (info->maxval == 1)
{
if (info->np)
d[b] = (*buf == '0') ? 0x00 : 0xff;
else
d[b] = (*buf == '0') ? 0xff : 0x00; /* invert for PBM */
}
else if (bpc > 1)
{
s[b] = (65535.0 * (((gdouble) (g_ascii_isdigit (*buf) ?
atoi (buf) : 0))
/ (gdouble) (info->maxval)));
}
else
{
d[b] = (255.0 * (((gdouble) (g_ascii_isdigit (*buf) ?
atoi (buf) : 0))
/ (gdouble) (info->maxval)));
}
}
1997-11-25 06:05:25 +08:00
if (bpc > 1)
{
s += np;
}
else
{
d += np;
}
}
1997-11-25 06:05:25 +08:00
2012-11-26 08:31:39 +08:00
gegl_buffer_set (buffer, GEGL_RECTANGLE (0, y, info->xres, scanlines), 0,
NULL, data, GEGL_AUTO_ROWSTRIDE);
gimp_progress_update ((double) y / (double) info->yres);
1997-11-25 06:05:25 +08:00
}
g_free (data);
2012-11-26 08:31:39 +08:00
gimp_progress_update (1.0);
1997-11-25 06:05:25 +08:00
}
static void
2012-11-26 08:31:39 +08:00
pnm_load_raw (PNMScanner *scan,
PNMInfo *info,
GeglBuffer *buffer)
1997-11-25 06:05:25 +08:00
{
2013-10-04 01:59:54 +08:00
GInputStream *input;
gint bpc;
guchar *data, *d;
gushort *s;
2013-10-04 01:59:54 +08:00
gint x, y, i;
gint start, end, scanlines;
1997-11-25 06:05:25 +08:00
if (info->maxval > 255)
bpc = 2;
else
bpc = 1;
/* No overflow as long as gimp_tile_height() < 1365 = 2^(31 - 18) / 6 */
data = g_new (guchar, gimp_tile_height () * info->xres * info->np * bpc);
2013-10-04 01:59:54 +08:00
input = pnmscanner_input (scan);
1997-11-25 06:05:25 +08:00
2012-11-26 08:31:39 +08:00
for (y = 0; y < info->yres; y += scanlines)
1997-11-25 06:05:25 +08:00
{
start = y;
end = y + gimp_tile_height ();
end = MIN (end, info->yres);
scanlines = end - start;
d = data;
s = (gushort *)data;
1997-11-25 06:05:25 +08:00
for (i = 0; i < scanlines; i++)
{
2013-10-04 01:59:54 +08:00
gsize bytes_read;
GError *error = NULL;
if (g_input_stream_read_all (input, d, info->xres * info->np * bpc,
&bytes_read, NULL, &error))
{
CHECK_FOR_ERROR (info->xres * info->np * bpc != bytes_read,
info->jmpbuf,
_("Premature end of file."));
}
else
{
CHECK_FOR_ERROR (FALSE, info->jmpbuf, "%s", error->message);
}
if (bpc > 1)
{
for (x = 0; x < info->xres * info->np; x++)
{
int v;
v = *d++ << 8;
v += *d++;
s[x] = MIN (v, info->maxval); /* guard against overflow */
s[x] = 65535.0 * (gdouble) v / (gdouble) info->maxval;
}
s += info->xres * info->np;
}
else
{
if (info->maxval != 255) /* Normalize if needed */
{
for (x = 0; x < info->xres * info->np; x++)
{
d[x] = MIN (d[x], info->maxval); /* guard against overflow */
d[x] = 255.0 * (gdouble) d[x] / (gdouble) info->maxval;
}
}
1997-11-25 06:05:25 +08:00
d += info->xres * info->np;
}
}
1997-11-25 06:05:25 +08:00
gegl_buffer_set (buffer,
GEGL_RECTANGLE (0, y, info->xres, scanlines), 0,
NULL, data, GEGL_AUTO_ROWSTRIDE);
2012-11-26 08:31:39 +08:00
gimp_progress_update ((double) y / (double) info->yres);
1997-11-25 06:05:25 +08:00
}
g_free (data);
2012-11-26 08:31:39 +08:00
gimp_progress_update (1.0);
1997-11-25 06:05:25 +08:00
}
1999-10-14 10:11:52 +08:00
static void
2012-11-26 08:31:39 +08:00
pnm_load_rawpbm (PNMScanner *scan,
PNMInfo *info,
GeglBuffer *buffer)
1997-11-25 06:05:25 +08:00
{
2013-10-04 01:59:54 +08:00
GInputStream *input;
guchar *buf;
guchar curbyte;
guchar *data, *d;
gint x, y, i;
gint start, end, scanlines;
gint rowlen, bufpos;
input = pnmscanner_input (scan);
rowlen = (int)ceil ((double)(info->xres)/8.0);
data = g_new (guchar, gimp_tile_height () * info->xres);
buf = g_new (guchar, rowlen);
1997-11-25 06:05:25 +08:00
2012-11-26 08:31:39 +08:00
for (y = 0; y < info->yres; y += scanlines)
1997-11-25 06:05:25 +08:00
{
start = y;
end = y + gimp_tile_height ();
end = MIN (end, info->yres);
scanlines = end - start;
d = data;
for (i = 0; i < scanlines; i++)
{
2013-10-04 01:59:54 +08:00
gsize bytes_read;
GError *error = NULL;
if (g_input_stream_read_all (input, buf, rowlen,
&bytes_read, NULL, &error))
{
CHECK_FOR_ERROR (rowlen != bytes_read,
info->jmpbuf,
_("Premature end of file."));
}
else
{
CHECK_FOR_ERROR (FALSE, info->jmpbuf, "%s", error->message);
}
bufpos = 0;
curbyte = buf[0];
for (x = 0; x < info->xres; x++)
{
if ((x % 8) == 0)
curbyte = buf[bufpos++];
d[x] = (curbyte & 0x80) ? 0x00 : 0xff;
curbyte <<= 1;
}
d += info->xres;
}
1997-11-25 06:05:25 +08:00
2012-11-26 08:31:39 +08:00
gegl_buffer_set (buffer, GEGL_RECTANGLE (0, y, info->xres, scanlines), 0,
NULL, data, GEGL_AUTO_ROWSTRIDE);
gimp_progress_update ((double) y / (double) info->yres);
1997-11-25 06:05:25 +08:00
}
g_free (buf);
1997-11-25 06:05:25 +08:00
g_free (data);
2012-11-26 08:31:39 +08:00
gimp_progress_update (1.0);
1997-11-25 06:05:25 +08:00
}
static void
pnm_load_rawpfm (PNMScanner *scan,
PNMInfo *info,
GeglBuffer *buffer)
{
GInputStream *input;
gfloat *data;
gint x, y;
gboolean swap_byte_order;
swap_byte_order =
(info->scale_factor >= 0.0) ^ (G_BYTE_ORDER == G_BIG_ENDIAN);
data = g_new (gfloat, info->xres * info->np);
input = pnmscanner_input (scan);
for (y = info->yres - 1; y >= 0; y--)
{
gsize bytes_read;
GError *error = NULL;
if (g_input_stream_read_all (input, data,
info->xres * info->np * sizeof (float),
&bytes_read, NULL, &error))
{
CHECK_FOR_ERROR
(info->xres * info->np * sizeof (float) != bytes_read,
info->jmpbuf, _("Premature end of file."));
}
else
{
CHECK_FOR_ERROR (FALSE, info->jmpbuf, "%s", error->message);
}
for (x = 0; x < info->xres * info->np; x++)
{
if (swap_byte_order)
{
union { gfloat f; guint32 i; } v;
v.f = data[x];
v.i = GUINT32_SWAP_LE_BE (v.i);
data[x] = v.f;
}
2015-01-18 09:25:56 +08:00
/* let's see if this is what people want, the PFM specs are a
* little vague about what the scale factor should be used
* for */
data[x] *= fabsf (info->scale_factor);
/* Keep values smaller than zero. That is in line with what the
* TIFF loader does. If the user doesn't want the negative numbers
* he has to get rid of them afterwards */
/* data[x] = fmaxf (0.0f, fminf (FLT_MAX, data[x])); */
}
gegl_buffer_set (buffer,
GEGL_RECTANGLE (0, y, info->xres, 1), 0,
NULL, data, GEGL_AUTO_ROWSTRIDE);
if (y % 32 == 0)
gimp_progress_update ((double) (info->yres - y) / (double) info->yres);
}
g_free (data);
gimp_progress_update (1.0);
}
2013-10-04 03:44:24 +08:00
static gboolean
output_write (GOutputStream *output,
gconstpointer buffer,
gsize count,
GError **error)
{
return g_output_stream_write_all (output, buffer, count, NULL, NULL, error);
2013-10-04 03:44:24 +08:00
}
/* Writes out mono raw rows */
2013-10-04 03:44:24 +08:00
static gboolean
pnmsaverow_raw_pbm (PNMRowInfo *ri,
guchar *data,
2013-10-04 03:44:24 +08:00
GError **error)
{
gint b, p = 0;
gchar *rbcur = ri->rowbuf;
gint32 len = (gint) ceil ((gdouble) (ri->xres) / 8.0);
for (b = 0; b < len; b++) /* each output byte */
{
gint i;
rbcur[b] = 0;
for (i = 0; i < 8; i++) /* each bit in this byte */
{
if (p >= ri->xres)
break;
if (data[p] != ri->zero_is_black)
rbcur[b] |= (char) (1 << (7 - i));
p++;
}
}
2013-10-04 03:44:24 +08:00
return output_write (ri->output, ri->rowbuf, len, error);
}
/* Writes out mono ascii rows */
2013-10-04 03:44:24 +08:00
static gboolean
pnmsaverow_ascii_pbm (PNMRowInfo *ri,
guchar *data,
2013-10-04 03:44:24 +08:00
GError **error)
{
static gint line_len = 0; /* ascii pbm lines must be <= 70 chars long */
gint32 len = 0;
gint i;
gchar *rbcur = ri->rowbuf;
for (i = 0; i < ri->xres; i++)
{
if (line_len > 69)
{
rbcur[i] = '\n';
line_len = 0;
len++;
rbcur++;
}
if (data[i] == ri->zero_is_black)
rbcur[i] = '0';
else
rbcur[i] = '1';
line_len++;
len++;
}
*(rbcur+i) = '\n';
2013-10-04 03:44:24 +08:00
return output_write (ri->output, ri->rowbuf, len, error);
}
/* Writes out RGB and grayscale raw rows */
2013-10-04 03:44:24 +08:00
static gboolean
pnmsaverow_raw (PNMRowInfo *ri,
guchar *data,
2013-10-04 03:44:24 +08:00
GError **error)
1997-11-25 06:05:25 +08:00
{
gint i;
if (ri->bpc == 2)
{
gushort *d = (gushort *)data;
for (i = 0; i < ri->xres * ri->np; i++)
{
*d = g_htons(*d);
d++;
}
}
return output_write (ri->output, data, ri->xres * ri->np * ri->bpc, error);
1997-11-25 06:05:25 +08:00
}
/* Writes out RGB and grayscale float rows */
static gboolean
pnmsaverow_float (PNMRowInfo *ri,
const float *data,
GError **error)
{
return output_write (ri->output, data,
ri->xres * ri->np * sizeof (float),
error);
}
1997-11-25 06:05:25 +08:00
/* Writes out indexed raw rows */
2013-10-04 03:44:24 +08:00
static gboolean
pnmsaverow_raw_indexed (PNMRowInfo *ri,
guchar *data,
2013-10-04 03:44:24 +08:00
GError **error)
1997-11-25 06:05:25 +08:00
{
gint i;
gchar *rbcur = ri->rowbuf;
1997-11-25 06:05:25 +08:00
for (i = 0; i < ri->xres; i++)
{
*(rbcur++) = ri->red[*data];
*(rbcur++) = ri->grn[*data];
*(rbcur++) = ri->blu[*(data++)];
}
2013-10-04 03:44:24 +08:00
return output_write (ri->output, ri->rowbuf, ri->xres * 3, error);
1997-11-25 06:05:25 +08:00
}
/* Writes out RGB and grayscale ascii rows */
2013-10-04 03:44:24 +08:00
static gboolean
pnmsaverow_ascii (PNMRowInfo *ri,
guchar *data,
2013-10-04 03:44:24 +08:00
GError **error)
1997-11-25 06:05:25 +08:00
{
gint i;
gchar *rbcur = ri->rowbuf;
gushort *sdata = (gushort *)data;
1997-11-25 06:05:25 +08:00
2013-10-04 03:44:24 +08:00
for (i = 0; i < ri->xres * ri->np; i++)
1997-11-25 06:05:25 +08:00
{
if (ri->bpc == 2)
{
sprintf ((gchar *) rbcur,"%d\n", 0xffff & *(sdata++));
}
else
{
sprintf ((gchar *) rbcur,"%d\n", 0xff & *(data++));
}
rbcur += strlen (rbcur);
1997-11-25 06:05:25 +08:00
}
return output_write (ri->output, ri->rowbuf, rbcur - ri->rowbuf,
2013-10-04 03:44:24 +08:00
error);
1997-11-25 06:05:25 +08:00
}
/* Writes out RGB and grayscale ascii rows */
2013-10-04 03:44:24 +08:00
static gboolean
pnmsaverow_ascii_indexed (PNMRowInfo *ri,
guchar *data,
2013-10-04 03:44:24 +08:00
GError **error)
1997-11-25 06:05:25 +08:00
{
gint i;
gchar *rbcur = ri->rowbuf;
1997-11-25 06:05:25 +08:00
for (i = 0; i < ri->xres; i++)
{
sprintf (rbcur, "%d\n", 0xff & ri->red[*(data)]);
rbcur += strlen (rbcur);
sprintf (rbcur, "%d\n", 0xff & ri->grn[*(data)]);
rbcur += strlen (rbcur);
sprintf (rbcur, "%d\n", 0xff & ri->blu[*(data++)]);
rbcur += strlen (rbcur);
1997-11-25 06:05:25 +08:00
}
2013-10-04 03:44:24 +08:00
return output_write (ri->output, ri->rowbuf, strlen ((char *) ri->rowbuf),
error);
1997-11-25 06:05:25 +08:00
}
static gboolean
2013-10-04 03:44:24 +08:00
save_image (GFile *file,
gint32 image_ID,
gint32 drawable_ID,
gboolean pbm,
gboolean float_format,
2013-10-04 03:44:24 +08:00
GError **error)
1997-11-25 06:05:25 +08:00
{
gboolean status = FALSE;
GOutputStream *output = NULL;
GeglBuffer *buffer = NULL;
2012-11-26 08:31:39 +08:00
const Babl *format;
2013-10-04 03:44:24 +08:00
const gchar *header_string = NULL;
GimpImageType drawable_type;
PNMRowInfo rowinfo;
2013-10-04 04:06:24 +08:00
PNMSaverowFunc saverow = NULL;
guchar red[256];
guchar grn[256];
guchar blu[256];
gchar buf[BUFLEN];
gint np = 0;
gint xres, yres;
gint ypos, yend;
gint rowbufsize = 0;
gchar *comment = NULL;
1997-11-25 06:05:25 +08:00
/* Make sure we're not saving an image with an alpha channel */
if (gimp_drawable_has_alpha (drawable_ID))
{
g_message (_("Cannot export images with alpha channel."));
goto out;
1997-11-25 06:05:25 +08:00
}
gimp_progress_init_printf (_("Exporting '%s'"),
g_file_get_parse_name (file));
1997-11-25 06:05:25 +08:00
/* open the file */
output = G_OUTPUT_STREAM (g_file_replace (file,
NULL, FALSE, G_FILE_CREATE_NONE,
NULL, error));
2013-10-04 03:44:24 +08:00
if (! output)
goto out;
1997-11-25 06:05:25 +08:00
2012-11-26 08:31:39 +08:00
buffer = gimp_drawable_get_buffer (drawable_ID);
xres = gegl_buffer_get_width (buffer);
yres = gegl_buffer_get_height (buffer);
drawable_type = gimp_drawable_type (drawable_ID);
1997-11-25 06:05:25 +08:00
switch (gimp_image_get_precision (image_ID))
{
case GIMP_PRECISION_U8_LINEAR:
Initial space invasion commit in GIMP All babl formats now have a space equivalent to a color profile, determining the format's primaries and TRCs. This commit makes GIMP aware of this. libgimp: - enum GimpPrecision: rename GAMMA values to NON_LINEAR and keep GAMMA as deprecated aliases, add PERCEPTUAL values so we now have LINEAR, NON_LINEAR and PERCPTUAL for each encoding, matching the babl encoding variants RGB, R'G'B' and R~G~B~. - gimp_color_transform_can_gegl_copy() now returns TRUE if both profiles can return a babl space, increasing the amount of fast babl color conversions significantly. - TODO: no solution yet for getting libgimp drawable proxy buffers in the right format with space. plug-ins: - follow the GimpPrecision change. - TODO: everything else unchanged and partly broken or sub-optimal, like setting a new image's color profile too late. app: - add enum GimpTRCType { LINEAR, NON_LINEAR, PERCEPTUAL } as replacement for all "linear" booleans. - change gimp-babl functions to take babl spaces and GimpTRCType parameters and support all sorts of new perceptual ~ formats. - a lot of places changed in the early days of goat invasion didn't take advantage of gimp-babl utility functions and constructed formats manually. They all needed revisiting and many now use much simpler code calling gimp-babl API. - change gimp_babl_format_get_color_profile() to really extract a newly allocated color profile from the format, and add gimp_babl_get_builtin_color_profile() which does the same as gimp_babl_format_get_color_profile() did before. Visited all callers to decide whether they are looking for the format's actual profile, or for one of the builtin profiles, simplifying code that only needs builtin profiles. - drawables have a new get_space_api(), get_linear() is now get_trc(). - images now have a "layer space" and an API to get it, gimp_image_get_layer_format() returns formats in that space. - an image's layer space is created from the image's color profile, change gimpimage-color-profile to deal with that correctly - change many babl_format() calls to babl_format_with_space() and take the space from passed formats or drawables - add function gimp_layer_fix_format_space() which replaces the layer's buffer with one that has the image's layer format, but doesn't change pixel values - use gimp_layer_fix_format_space() to make sure layers loaded from XCF and created by plug-ins have the right space when added to the image, because it's impossible to always assign the right space upon layer creation - "assign color profile" and "discard color profile" now require use of gimp_layer_fix_format_space() too because the profile is now embedded in all formats via the space. Add gimp_image_assign_color_profile() which does all that and call it instead of a simple gimp_image_set_color_profile(), also from the PDB set-color-profile functions, which are essentially "assign" and "discard" calls. - generally, make sure a new image's color profile is set before adding layers to it, gimp_image_set_color_profile() is more than before considered know-what-you-are-doing API. - take special precaution in all places that call gimp_drawable_convert_type(), we now must pass a new_profile from all callers that convert layers within the same image (such as image_convert_type, image_convert_precision), because the layer's new space can't be determined from the image's layer format during the call. - change all "linear" properties to "trc", in all config objects like for levels and curves, in the histogram, in the widgets. This results in some GUI that now has three choices instead of two. TODO: we might want to reduce that back to two later. - keep "linear" boolean properties around as compat if needed for file pasring, but always convert the parsed parsed boolean to GimpTRCType. - TODO: the image's "enable color management" switch is currently broken, will fix that in another commit.
2018-07-21 20:23:01 +08:00
case GIMP_PRECISION_U8_NON_LINEAR:
case GIMP_PRECISION_U8_PERCEPTUAL:
rowinfo.bpc = 1;
break;
default:
rowinfo.bpc = 2;
break;
}
1997-11-25 06:05:25 +08:00
/* write out magic number */
if (!float_format && !psvals.raw)
{
if (pbm)
{
2013-10-04 03:44:24 +08:00
header_string = "P1\n";
format = gegl_buffer_get_format (buffer);
np = 0;
rowbufsize = xres + (int) (xres / 70) + 1;
saverow = pnmsaverow_ascii_pbm;
}
else
{
switch (drawable_type)
{
case GIMP_GRAY_IMAGE:
2013-10-04 03:44:24 +08:00
header_string = "P2\n";
if (rowinfo.bpc == 1)
{
format = babl_format ("Y' u8");
rowbufsize = xres * 4;
}
else
{
format = babl_format ("Y' u16");
rowbufsize = xres * 6;
}
np = 1;
saverow = pnmsaverow_ascii;
break;
case GIMP_RGB_IMAGE:
2013-10-04 03:44:24 +08:00
header_string = "P3\n";
if (rowinfo.bpc == 1)
{
format = babl_format ("R'G'B' u8");
rowbufsize = xres * 12;
}
else
{
format = babl_format ("R'G'B' u16");
rowbufsize = xres * 18;
}
np = 3;
saverow = pnmsaverow_ascii;
break;
case GIMP_INDEXED_IMAGE:
2013-10-04 03:44:24 +08:00
header_string = "P3\n";
2012-11-26 08:31:39 +08:00
format = gegl_buffer_get_format (buffer);
np = 1;
rowbufsize = xres * 12;
saverow = pnmsaverow_ascii_indexed;
break;
default:
g_warning ("PNM: Unknown drawable_type\n");
goto out;
}
}
}
else if (!float_format)
{
if (pbm)
{
2013-10-04 03:44:24 +08:00
header_string = "P4\n";
format = gegl_buffer_get_format (buffer);
np = 0;
2013-10-04 04:06:24 +08:00
rowbufsize = (gint) ceil ((gdouble) xres / 8.0);
saverow = pnmsaverow_raw_pbm;
}
else
{
switch (drawable_type)
{
case GIMP_GRAY_IMAGE:
2013-10-04 03:44:24 +08:00
header_string = "P5\n";
if (rowinfo.bpc == 1)
{
format = babl_format ("Y' u8");
rowbufsize = xres;
}
else
{
format = babl_format ("Y' u16");
rowbufsize = xres * 2;
}
np = 1;
saverow = pnmsaverow_raw;
break;
case GIMP_RGB_IMAGE:
2013-10-04 03:44:24 +08:00
header_string = "P6\n";
if (rowinfo.bpc == 1)
{
format = babl_format ("R'G'B' u8");
rowbufsize = xres * 3;
}
else
{
format = babl_format ("R'G'B' u16");
rowbufsize = xres * 6;
}
np = 3;
saverow = pnmsaverow_raw;
break;
case GIMP_INDEXED_IMAGE:
2013-10-04 03:44:24 +08:00
header_string = "P6\n";
2012-11-26 08:31:39 +08:00
format = gegl_buffer_get_format (buffer);
np = 1;
rowbufsize = xres * 3;
saverow = pnmsaverow_raw_indexed;
break;
default:
g_warning ("PNM: Unknown drawable_type\n");
goto out;
}
}
1997-11-25 06:05:25 +08:00
}
else
2013-10-04 03:44:24 +08:00
{
switch (drawable_type)
{
case GIMP_GRAY_IMAGE:
header_string = "Pf\n";
format = babl_format ("Y float");
np = 1;
break;
case GIMP_RGB_IMAGE:
header_string = "PF\n";
format = babl_format ("RGB float");
np = 3;
break;
default:
g_warning ("PFM: Unknown drawable_type\n");
goto out;
}
2013-10-04 03:44:24 +08:00
}
if (! output_write (output, header_string, strlen (header_string), error))
goto out;
rowinfo.zero_is_black = FALSE;
if (drawable_type == GIMP_INDEXED_IMAGE)
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
guchar *cmap;
gint num_colors;
1997-11-25 06:05:25 +08:00
cmap = gimp_image_get_colormap (image_ID, &num_colors);
1997-11-25 06:05:25 +08:00
if (pbm)
{
/* Test which of the two colors is white and which is black */
switch (num_colors)
{
case 1:
rowinfo.zero_is_black = (GIMP_RGB_LUMINANCE (cmap[0],
cmap[1],
cmap[2]) < 128);
break;
case 2:
rowinfo.zero_is_black = (GIMP_RGB_LUMINANCE (cmap[0],
cmap[1],
cmap[2]) <
GIMP_RGB_LUMINANCE (cmap[3],
cmap[4],
cmap[5]));
break;
default:
g_warning ("Images exported as PBM should be black/white");
break;
}
}
else
{
const guchar *c = cmap;
gint i;
for (i = 0; i < num_colors; i++)
{
red[i] = *c++;
grn[i] = *c++;
blu[i] = *c++;
}
rowinfo.red = red;
rowinfo.grn = grn;
rowinfo.blu = blu;
}
1997-11-25 06:05:25 +08:00
g_free (cmap);
1997-11-25 06:05:25 +08:00
}
if (!float_format)
{
/* write out comment string */
comment = g_strdup_printf("# Created by GIMP version %s PNM plug-in\n",
GIMP_VERSION);
if (! output_write (output, comment, strlen (comment), error))
goto out;
}
1997-11-25 06:05:25 +08:00
/* write out resolution and maxval */
if (pbm)
2013-10-04 03:44:24 +08:00
g_snprintf (buf, sizeof (buf), "%d %d\n", xres, yres);
else if (!float_format)
g_snprintf (buf, sizeof (buf), "%d %d\n%d\n", xres, yres,
rowinfo.bpc == 1 ? 255 : 65535);
else
g_snprintf (buf, sizeof (buf), "%d %d\n%s\n", xres, yres,
G_BYTE_ORDER == G_BIG_ENDIAN ? "1.0" : "-1.0");
2013-10-04 03:44:24 +08:00
if (! output_write (output, buf, strlen (buf), error))
goto out;
if (!float_format)
2013-10-04 03:44:24 +08:00
{
guchar *data;
guchar *d;
gchar *rowbuf = NULL;
1997-11-25 06:05:25 +08:00
/* allocate a buffer for retrieving information from the pixel region */
data = g_new (guchar,
gimp_tile_height () * xres *
babl_format_get_bytes_per_pixel (format));
2013-10-04 04:06:24 +08:00
rowbuf = g_new (gchar, rowbufsize + 1);
rowinfo.output = output;
rowinfo.rowbuf = rowbuf;
rowinfo.xres = xres;
rowinfo.np = np;
1997-11-25 06:05:25 +08:00
d = NULL; /* only to please the compiler */
/* Write the body out */
for (ypos = 0; ypos < yres; ypos++)
{
if ((ypos % gimp_tile_height ()) == 0)
{
yend = ypos + gimp_tile_height ();
yend = MIN (yend, yres);
gegl_buffer_get (buffer,
GEGL_RECTANGLE (0, ypos, xres, yend - ypos), 1.0,
format, data,
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
d = data;
}
if (! saverow (&rowinfo, d, error))
{
g_free (rowbuf);
g_free (data);
goto out;
}
d += xres * (np ? np : 1) * rowinfo.bpc;
if (ypos % 32 == 0)
gimp_progress_update ((double) ypos / (double) yres);
}
g_free (rowbuf);
g_free (data);
}
else
{
/* allocate a buffer for retrieving information from the pixel
region */
gfloat *data = g_new (gfloat, xres * np);
rowinfo.output = output;
rowinfo.rowbuf = NULL;
rowinfo.xres = xres;
rowinfo.np = np;
2012-11-26 08:31:39 +08:00
/* Write the body out in reverse row order */
for (ypos = yres - 1; ypos >= 0; ypos--)
{
2012-11-26 08:31:39 +08:00
gegl_buffer_get (buffer,
GEGL_RECTANGLE (0, ypos, xres, 1), 1.0,
format, data,
2012-11-26 08:31:39 +08:00
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
if (! pnmsaverow_float (&rowinfo, data, error))
{
g_free (data);
goto out;
}
1997-11-25 06:05:25 +08:00
if (ypos % 32 == 0)
gimp_progress_update ((double) (yres - ypos) / (double) yres);
2013-10-04 03:44:24 +08:00
}
g_free (data);
1997-11-25 06:05:25 +08:00
}
2012-11-26 08:31:39 +08:00
gimp_progress_update (1.0);
status = TRUE;
out:
if (! status)
{
GCancellable *cancellable = g_cancellable_new ();
g_cancellable_cancel (cancellable);
g_output_stream_close (output, cancellable, NULL);
g_object_unref (cancellable);
}
if (comment)
g_free (comment);
if (buffer)
g_object_unref (buffer);
if (output)
g_object_unref (output);
1997-11-25 06:05:25 +08:00
return status;
1997-11-25 06:05:25 +08:00
}
2013-10-04 04:06:24 +08:00
static gboolean
save_dialog (void)
1997-11-25 06:05:25 +08:00
{
GtkWidget *dialog;
1997-11-25 06:05:25 +08:00
GtkWidget *frame;
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
gboolean run;
1997-11-25 06:05:25 +08:00
dialog = gimp_export_dialog_new (_("PNM"), PLUG_IN_BINARY, PNM_SAVE_PROC);
1997-11-25 06:05:25 +08:00
/* file save type */
frame = gimp_int_radio_group_new (TRUE, _("Data formatting"),
G_CALLBACK (gimp_radio_button_update),
&psvals.raw, psvals.raw,
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
_("Raw"), TRUE, NULL,
2011-12-06 23:07:42 +08:00
_("ASCII"), FALSE, 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
NULL);
gtk_container_set_border_width (GTK_CONTAINER (frame), 6);
gtk_box_pack_start (GTK_BOX (gimp_export_dialog_get_content_area (dialog)),
frame, FALSE, TRUE, 0);
1997-11-25 06:05:25 +08:00
gtk_widget_show (frame);
gtk_widget_show (dialog);
1997-11-25 06:05:25 +08:00
run = (gimp_dialog_run (GIMP_DIALOG (dialog)) == GTK_RESPONSE_OK);
1997-11-25 06:05:25 +08:00
gtk_widget_destroy (dialog);
1997-11-25 06:05:25 +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;
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
}
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
1997-11-25 06:05:25 +08:00
/**************** FILE SCANNER UTILITIES **************/
/* pnmscanner_create ---
* Creates a new scanner based on a file descriptor. The
* look ahead buffer is one character initially.
*/
static PNMScanner *
2013-10-04 01:59:54 +08:00
pnmscanner_create (GInputStream *input)
1997-11-25 06:05:25 +08:00
{
PNMScanner *s;
2013-10-04 01:59:54 +08:00
gsize bytes_read;
1997-11-25 06:05:25 +08:00
s = g_new (PNMScanner, 1);
2013-10-04 01:59:54 +08:00
s->input = input;
Fix a bunch of warnings from Sparse: 2004-11-13 Manish Singh <yosh@gimp.org> Fix a bunch of warnings from Sparse: * app/actions/dockable-commands.c * app/actions/layers-actions.c * app/actions/view-commands.c * app/base/pixel-surround.c * app/config/gimpconfig-utils.c * app/config/gimpscanner.c * app/core/gimpbrushgenerated.c * app/core/gimpcontainer.c * app/core/gimpimage.c * app/dialogs/palette-import-dialog.c * app/file/gimprecentlist.c * app/plug-in/plug-in-params.c * app/text/gimptext-compat.c * app/text/gimptext-parasite.c * app/vectors/gimpbezierstroke.c * app/vectors/gimpstroke.c * app/widgets/gimpcellrendereraccel.c * app/widgets/gimpselectiondata.c * app/xcf/xcf.c * libgimp/gimp.c * libgimpthumb/gimpthumb-utils.c * libgimpthumb/gimpthumbnail.c * modules/cdisplay_proof.c * plug-ins/Lighting/lighting_ui.c * plug-ins/common/csource.c * plug-ins/common/glasstile.c * plug-ins/common/nova.c * plug-ins/common/pcx.c * plug-ins/common/pnm.c * plug-ins/common/randomize.c * plug-ins/common/screenshot.c * plug-ins/common/sel_gauss.c * plug-ins/common/spheredesigner.c * plug-ins/common/wind.c * plug-ins/gfig/gfig-dialog.c * plug-ins/gfig/gfig-dobject.c * plug-ins/gimpressionist/gimpressionist.c * plug-ins/ifscompose/ifscompose.c * plug-ins/print/gimp_main_window.c * plug-ins/print/print.c: Cleanup integer vs. pointer confusion. * app/base/temp-buf.c * app/dialogs/about-dialog.c * plug-ins/common/bumpmap.c * plug-ins/common/jigsaw.c * plug-ins/gfig/gfig-dobject.c: Cosmetic cleanups. * app/config/gimpconfig-deserialize.c * app/config/gimpconfig-path.c * app/config/gimpconfigwriter.c * app/core/gimpgradient.c * app/tools/gimpdrawtool.c * plug-ins/common/nlfilt.c * plug-ins/common/unsharp.c * plug-ins/common/zealouscrop.c: Define inline functions before they are used. * app/core/gimpdrawable-blend.c: PixelRegion definition was changed some time ago, but the initialization here didn't change. Fix it. * app/plug-in/plug-in-rc.c (plug_in_extra_deserialize): No need to assign token twice in a row. * libgimpbase/gimpdatafiles.c (gimp_datafiles_read_directories): No need to initialize file_data, since the code fills out all the fields. * plug-ins/common/CML_explorer.c * plug-ins/common/vpropagate.c: Declare function pointers fully. * plug-ins/common/grid.c (pix_composite): G_INLINE_FUNC isn't needed, we assume we can use the "inline" keyword always. * plug-ins/common/psd_save.c * plug-ins/common/vinvert.c * plug-ins/gfig/gfig-arc.c * plug-ins/gfig/gfig-bezier.c * plug-ins/gfig/gfig-circle.c * plug-ins/gfig/gfig-dialog.c * plug-ins/gfig/gfig-dobject.c * plug-ins/gfig/gfig-ellipse.c * plug-ins/gfig/gfig-line.c * plug-ins/gfig/gfig-poly.c * plug-ins/gfig/gfig-spiral.c * plug-ins/gfig/gfig-star.c * plug-ins/gfig/gfig.c * plug-ins/gimpressionist/orientmap.c * plug-ins/gimpressionist/placement.c * plug-ins/gimpressionist/sizemap.c * plug-ins/imagemap/imap_grid.c * plug-ins/imagemap/imap_main.c * plug-ins/imagemap/imap_preferences.c * plug-ins/imagemap/imap_settings.c * plug-ins/maze/maze.c * plug-ins/sel2path/curve.c * plug-ins/sel2path/fit.c * plug-ins/sel2path/pxl-outline.c * plug-ins/sel2path/spline.c * plug-ins/xjt/xjt.c: Functions with no args should be declared with (void). * plug-ins/common/retinex.c (MSRCR): Initialize max_preview to quiet the compiler.
2004-11-14 10:50:33 +08:00
s->inbuf = NULL;
2013-10-04 01:59:54 +08:00
s->eof = FALSE;
if (! g_input_stream_read_all (input, &s->cur, 1,
&bytes_read, NULL, NULL) ||
bytes_read != 1)
{
s->eof = TRUE;
}
return s;
1997-11-25 06:05:25 +08:00
}
/* pnmscanner_destroy ---
* Destroys a scanner and its resources. Doesn't close the fd.
*/
static void
1997-11-25 06:05:25 +08:00
pnmscanner_destroy (PNMScanner *s)
{
if (s->inbuf)
g_free (s->inbuf);
g_free (s);
1997-11-25 06:05:25 +08:00
}
/* pnmscanner_createbuffer ---
* Creates a buffer so we can do buffered reads.
*/
static void
1997-11-25 06:05:25 +08:00
pnmscanner_createbuffer (PNMScanner *s,
gint bufsize)
1997-11-25 06:05:25 +08:00
{
2013-10-04 01:59:54 +08:00
gsize bytes_read;
s->inbuf = g_new (gchar, bufsize);
s->inbufsize = bufsize;
s->inbufpos = 0;
2013-10-04 01:59:54 +08:00
s->inbufvalidsize = 0;
g_input_stream_read_all (s->input, s->inbuf, bufsize,
&bytes_read, NULL, NULL);
s->inbufvalidsize = bytes_read;
1997-11-25 06:05:25 +08:00
}
/* pnmscanner_gettoken ---
* Gets the next token, eating any leading whitespace.
*/
static void
1997-11-25 06:05:25 +08:00
pnmscanner_gettoken (PNMScanner *s,
gchar *buf,
gint bufsize)
1997-11-25 06:05:25 +08:00
{
gint ctr = 0;
1997-11-25 06:05:25 +08:00
pnmscanner_eatwhitespace (s);
while (! s->eof &&
! g_ascii_isspace (s->cur) &&
(s->cur != '#') &&
(ctr < bufsize))
1997-11-25 06:05:25 +08:00
{
buf[ctr++] = s->cur;
pnmscanner_getchar (s);
1997-11-25 06:05:25 +08:00
}
1997-11-25 06:05:25 +08:00
buf[ctr] = '\0';
}
2000-02-20 03:36:10 +08:00
/* pnmscanner_getsmalltoken ---
* Gets the next char, eating any leading whitespace.
*/
static void
pnmscanner_getsmalltoken (PNMScanner *s,
gchar *buf)
2000-02-20 03:36:10 +08:00
{
pnmscanner_eatwhitespace (s);
2013-10-04 04:06:24 +08:00
if (! s->eof && ! g_ascii_isspace (s->cur) && (s->cur != '#'))
2000-02-20 03:36:10 +08:00
{
*buf = s->cur;
pnmscanner_getchar (s);
2000-02-20 03:36:10 +08:00
}
}
1997-11-25 06:05:25 +08:00
/* pnmscanner_getchar ---
* Reads a character from the input stream
*/
static void
1997-11-25 06:05:25 +08:00
pnmscanner_getchar (PNMScanner *s)
{
if (s->inbuf)
{
s->cur = s->inbuf[s->inbufpos++];
1997-11-25 06:05:25 +08:00
if (s->inbufpos >= s->inbufvalidsize)
{
if (s->inbufpos > s->inbufvalidsize)
2013-10-04 01:59:54 +08:00
{
s->eof = 1;
}
else
2013-10-04 01:59:54 +08:00
{
gsize bytes_read;
g_input_stream_read_all (s->input, s->inbuf, s->inbufsize,
&bytes_read, NULL, NULL);
s->inbufvalidsize = bytes_read;
}
s->inbufpos = 0;
}
1997-11-25 06:05:25 +08:00
}
else
{
2013-10-04 01:59:54 +08:00
gsize bytes_read;
s->eof = FALSE;
if (! g_input_stream_read_all (s->input, &s->cur, 1,
&bytes_read, NULL, NULL) ||
bytes_read != 1)
{
s->eof = TRUE;
}
}
1997-11-25 06:05:25 +08:00
}
/* pnmscanner_eatwhitespace ---
* Eats up whitespace from the input and returns when done or eof.
* Also deals with comments.
*/
static void
1997-11-25 06:05:25 +08:00
pnmscanner_eatwhitespace (PNMScanner *s)
{
gint state = 0;
1997-11-25 06:05:25 +08:00
while (!(s->eof) && (state != -1))
{
switch (state)
{
case 0: /* in whitespace */
if (s->cur == '#')
{
state = 1; /* goto comment */
pnmscanner_getchar (s);
}
2013-10-04 04:06:24 +08:00
else if (! g_ascii_isspace (s->cur))
{
state = -1;
}
else
{
pnmscanner_getchar (s);
}
break;
case 1: /* in comment */
if (s->cur == '\n')
state = 0; /* goto whitespace */
pnmscanner_getchar (s);
break;
}
1997-11-25 06:05:25 +08:00
}
}