gimp/plug-ins/common/gif-load.c

1120 lines
30 KiB
C
Raw Normal View History

/* GIF loading file filter for GIMP 2.x
* +-------------------------------------------------------------------+
* | Copyright Adam D. Moss, Peter Mattis, Spencer Kimball |
* +-------------------------------------------------------------------+
* Version 1.50.4 - 2003/06/03
1999-03-21 03:50:30 +08:00
* Adam D. Moss - <adam@gimp.org> <adam@foxbox.org>
*/
/* Copyright notice for old GIF code from which this plugin was long ago */
/* derived (David Koblas has kindly granted permission to relicense): */
/* +-------------------------------------------------------------------+ */
/* | Copyright 1990, 1991, 1993, David Koblas. (koblas@extra.com) | */
/* +-------------------------------------------------------------------+ */
/* Also...
* 'This filter uses code taken from the "giftopnm" and "ppmtogif" programs
* which are part of the "netpbm" package.'
1999-03-21 03:50:30 +08:00
*/
/* Additionally...
1999-03-21 03:50:30 +08:00
* "The Graphics Interchange Format(c) is the Copyright property of
* CompuServe Incorporated. GIF(sm) is a Service Mark property of
plug-ins/FractalExplorer/Dialogs.c 2003-11-15 Michael Natterer <mitch@gimp.org> * plug-ins/FractalExplorer/Dialogs.c * plug-ins/FractalExplorer/FractalExplorer.c * plug-ins/bmp/bmpread.c * plug-ins/bmp/bmpwrite.c * plug-ins/common/CEL.c * plug-ins/common/CML_explorer.c * plug-ins/common/animoptimize.c * plug-ins/common/bz2.c * plug-ins/common/convmatrix.c * plug-ins/common/curve_bend.c * plug-ins/common/dicom.c * plug-ins/common/gauss_iir.c * plug-ins/common/gauss_rle.c * plug-ins/common/gbr.c * plug-ins/common/gif.c * plug-ins/common/gifload.c * plug-ins/common/gih.c * plug-ins/common/grid.c * plug-ins/common/gtm.c * plug-ins/common/gz.c * plug-ins/common/hrz.c * plug-ins/common/jpeg.c * plug-ins/common/mail.c * plug-ins/common/mapcolor.c * plug-ins/common/pat.c * plug-ins/common/pcx.c * plug-ins/common/pix.c * plug-ins/common/png.c * plug-ins/common/pnm.c * plug-ins/common/ps.c * plug-ins/common/psd.c * plug-ins/common/psd_save.c * plug-ins/common/psp.c * plug-ins/common/sel_gauss.c * plug-ins/common/spheredesigner.c * plug-ins/common/sunras.c * plug-ins/common/svg.c * plug-ins/common/tga.c * plug-ins/common/tiff.c * plug-ins/common/wmf.c * plug-ins/common/xbm.c * plug-ins/common/xwd.c * plug-ins/faxg3/faxg3.c * plug-ins/fits/fits.c * plug-ins/flame/flame.c * plug-ins/gfig/gfig.c * plug-ins/gflare/gflare.c * plug-ins/gfli/gfli.c * plug-ins/gimpressionist/brush.c * plug-ins/gimpressionist/ppmtool.c * plug-ins/helpbrowser/domain.c * plug-ins/ifscompose/ifscompose.c * plug-ins/sgi/sgi.c * plug-ins/twain/twain.c * plug-ins/winsnap/winsnap.c * plug-ins/xjt/xjt.c: removed explicit newlines from messages. Made file open/save messages the same all over the place. Reduced number of translatable strings by adding some more "standard" messages. Removed plug-in names from messages. Added some random mnemonics. Unmarked some strings for translation and added some that were forgotten. General message cleanup. Removed trailing whitespace.
2003-11-15 21:53:33 +08:00
* CompuServe Incorporated."
1999-03-21 03:50:30 +08:00
*/
/*
* REVISION HISTORY
*
* 2003/06/03
* 1.50.04 - When initializing the LZW state, watch out for a completely
* bogus input_code_size [based on fix by Raphael Quinet]
* Also, fix a stupid old bug when clearing the code table between
* subimages. (Enables us to deal better with errors when the stream is
* corrupted pretty early in a subimage.) [adam]
* Minor-version-bump to distinguish between gimp1.2/1.4 branches.
*
* 2000/03/31
* 1.00.03 - Just mildly more useful comments/messages concerning frame
* disposals.
*
* 1999/11/20
* 1.00.02 - Fixed a couple of possible infinite loops where an
* error condition was not being checked. Also changed some g_message()s
* back to g_warning()s as they should be (don't get carried away with
* the user feedback fellahs, no-one wants to be told of every single
* corrupt byte and block in its own little window. :-( ).
*
* 1999/11/11
* 1.00.01 - Fixed an uninitialized variable which has been around
* forever... thanks to jrb@redhat.com for noticing that there
* was a problem somewhere!
*
* 1999/03/20
1999-03-21 03:50:30 +08:00
* 1.00.00 - GIF load-only code split from main GIF plugin.
*
* For previous revision information, please consult the comments
* in the 'gif' plugin.
*/
/*
* TODO (more *'s means more important!)
*
* - PDB stuff for comments
*
* - Remove unused colourmap entries for GRAYSCALE images.
*/
configure.in removed tips files, AC_SUBST GIMP_PLUGINS and GIMP_MODULES so * configure.in * Makefile.am: removed tips files, AC_SUBST GIMP_PLUGINS and GIMP_MODULES so you can easily skip those parts of the build * acinclude.m4 * config.sub * config.guess * ltconfig * ltmain.sh: libtool 1.3.2 * app/fileops.c: shuffle #includes to avoid warning about MIN and MAX [ The following is a big i18n patch from David Monniaux <david.monniaux@ens.fr> ] * tips/gimp_conseils.fr.txt * tips/gimp_tips.txt * tips/Makefile.am * configure.in: moved tips to separate dir * po-plugins: new dir for plug-in translation files * configure.in: add po-plugins dir and POTFILES processing * app/boundary.c * app/brightness_contrast.c * app/by_color_select.c * app/color_balance.c * app/convert.c * app/curves.c * app/free_select.c * app/gdisplay.c * app/gimpimage.c * app/gimpunit.c * app/gradient.c * app/gradient_select.c * app/install.c * app/session.c: various i18n tweaks * app/tips_dialog.c: localize tips filename * libgimp/gimpunit.c * libgimp/gimpunitmenu.c: #include "config.h" * plug-ins/CEL * plug-ins/CML_explorer * plug-ins/Lighting * plug-ins/apply_lens * plug-ins/autostretch_hsv * plug-ins/blur * plug-ins/bmp * plug-ins/borderaverage * plug-ins/bumpmap * plug-ins/bz2 * plug-ins/checkerboard * plug-ins/colorify * plug-ins/compose * plug-ins/convmatrix * plug-ins/cubism * plug-ins/depthmerge * plug-ins/destripe * plug-ins/gif * plug-ins/gifload * plug-ins/jpeg * plug-ins/mail * plug-ins/oilify * plug-ins/png * plug-ins/print * plug-ins/ps * plug-ins/xbm * plug-ins/xpm * plug-ins/xwd: plug-in i18n stuff -Yosh
1999-05-30 00:35:47 +08:00
#include "config.h"
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
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
#include <errno.h>
1999-03-21 03:50:30 +08:00
#include <string.h>
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
#include <glib/gstdio.h>
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
#include <libgimp/gimp.h>
configure.in removed tips files, AC_SUBST GIMP_PLUGINS and GIMP_MODULES so * configure.in * Makefile.am: removed tips files, AC_SUBST GIMP_PLUGINS and GIMP_MODULES so you can easily skip those parts of the build * acinclude.m4 * config.sub * config.guess * ltconfig * ltmain.sh: libtool 1.3.2 * app/fileops.c: shuffle #includes to avoid warning about MIN and MAX [ The following is a big i18n patch from David Monniaux <david.monniaux@ens.fr> ] * tips/gimp_conseils.fr.txt * tips/gimp_tips.txt * tips/Makefile.am * configure.in: moved tips to separate dir * po-plugins: new dir for plug-in translation files * configure.in: add po-plugins dir and POTFILES processing * app/boundary.c * app/brightness_contrast.c * app/by_color_select.c * app/color_balance.c * app/convert.c * app/curves.c * app/free_select.c * app/gdisplay.c * app/gimpimage.c * app/gimpunit.c * app/gradient.c * app/gradient_select.c * app/install.c * app/session.c: various i18n tweaks * app/tips_dialog.c: localize tips filename * libgimp/gimpunit.c * libgimp/gimpunitmenu.c: #include "config.h" * plug-ins/CEL * plug-ins/CML_explorer * plug-ins/Lighting * plug-ins/apply_lens * plug-ins/autostretch_hsv * plug-ins/blur * plug-ins/bmp * plug-ins/borderaverage * plug-ins/bumpmap * plug-ins/bz2 * plug-ins/checkerboard * plug-ins/colorify * plug-ins/compose * plug-ins/convmatrix * plug-ins/cubism * plug-ins/depthmerge * plug-ins/destripe * plug-ins/gif * plug-ins/gifload * plug-ins/jpeg * plug-ins/mail * plug-ins/oilify * plug-ins/png * plug-ins/print * plug-ins/ps * plug-ins/xbm * plug-ins/xpm * plug-ins/xwd: plug-in i18n stuff -Yosh
1999-05-30 00:35:47 +08:00
#include "libgimp/stdplugins-intl.h"
1999-03-21 03:50:30 +08:00
#define LOAD_PROC "file-gif-load"
#define LOAD_THUMB_PROC "file-gif-load-thumb"
1999-03-21 03:50:30 +08:00
/* uncomment the line below for a little debugging info */
/* #define GIFDEBUG yesplease */
/* Declare some local functions.
*/
static void query (void);
static void run (const gchar *name,
gint nparams,
const GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals);
static gint32 load_image (const gchar *filename,
gboolean thumbnail);
1999-03-21 03:50:30 +08:00
static guchar used_cmap[3][256];
static guchar highest_used_index;
static gboolean promote_to_rgb = FALSE;
static guchar gimp_cmap[768];
static GimpParasite *comment_parasite = NULL;
1999-03-21 03:50:30 +08:00
const GimpPlugInInfo PLUG_IN_INFO =
1999-03-21 03:50:30 +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 */
1999-03-21 03:50:30 +08:00
};
MAIN ()
static void
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
query (void)
1999-03-21 03:50:30 +08:00
{
static const GimpParamDef load_args[] =
1999-03-21 03:50:30 +08:00
{
{ GIMP_PDB_INT32, "run-mode", "Interactive, non-interactive" },
{ GIMP_PDB_STRING, "filename", "The name of the file to load" },
{ GIMP_PDB_STRING, "raw-filename", "The name entered" }
1999-03-21 03:50:30 +08:00
};
static const GimpParamDef load_return_vals[] =
1999-03-21 03:50:30 +08:00
{
{ GIMP_PDB_IMAGE, "image", "Output image" }
};
static const GimpParamDef thumb_args[] =
{
{ GIMP_PDB_STRING, "filename", "The name of the file to load" },
{ GIMP_PDB_INT32, "thumb-size", "Preferred thumbnail size" }
1999-03-21 03:50:30 +08:00
};
gimp_install_procedure (LOAD_PROC,
"Loads files of Compuserve GIF file format",
1999-03-21 03:50:30 +08:00
"FIXME: write help for gif_load",
"Spencer Kimball, Peter Mattis, Adam Moss, David Koblas",
"Spencer Kimball, Peter Mattis, Adam Moss, David Koblas",
"1995-2006",
N_("GIF image"),
NULL,
GIMP_PLUGIN,
G_N_ELEMENTS (load_args),
G_N_ELEMENTS (load_return_vals),
1999-03-21 03:50:30 +08:00
load_args, load_return_vals);
gimp_register_file_handler_mime (LOAD_PROC, "image/gif");
gimp_register_magic_load_handler (LOAD_PROC,
"gif",
"",
"0,string,GIF8");
1999-03-21 03:50:30 +08:00
gimp_install_procedure (LOAD_THUMB_PROC,
"Loads only the first frame of a GIF image, to be "
"used as a thumbnail",
"",
"Sven Neumann",
"Sven Neumann",
"2006",
NULL,
NULL,
GIMP_PLUGIN,
G_N_ELEMENTS (thumb_args),
G_N_ELEMENTS (load_return_vals),
thumb_args, load_return_vals);
gimp_register_thumbnail_loader (LOAD_PROC, LOAD_THUMB_PROC);
}
1999-03-21 03:50:30 +08:00
static void
run (const gchar *name,
gint nparams,
const GimpParam *param,
gint *nreturn_vals,
GimpParam **return_vals)
1999-03-21 03:50:30 +08:00
{
static GimpParam values[2];
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
gint32 image_ID;
1999-03-21 03:50:30 +08:00
INIT_I18N ();
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;
1999-03-21 03:50:30 +08:00
if (strcmp (name, LOAD_PROC) == 0)
1999-03-21 03:50:30 +08:00
{
image_ID = load_image (param[1].data.d_string, FALSE);
}
else if (strcmp (name, LOAD_THUMB_PROC) == 0)
{
image_ID = load_image (param[0].data.d_string, TRUE);
}
else
{
status = GIMP_PDB_CALLING_ERROR;
}
1999-03-21 03:50:30 +08:00
if (status == GIMP_PDB_SUCCESS)
{
1999-03-21 03:50:30 +08:00
if (image_ID != -1)
{
/* The GIF format only tells you how many bits per pixel
* are in the image, not the actual number of used indices (D'OH!)
*
* So if we're not careful, repeated load/save of a transparent GIF
* without intermediate indexed->RGB->indexed pumps up the number of
* bits used, as we add an index each time for the transparent
* colour. Ouch. We either do some heavier analysis at save-time,
* or trim down the number of GIMP colours at load-time. We do the
* latter for now.
*/
#ifdef GIFDEBUG
g_print ("GIF: Highest used index is %d\n", highest_used_index);
#endif
if (! promote_to_rgb)
gimp_image_set_colormap (image_ID,
gimp_cmap, highest_used_index + 1);
*nreturn_vals = 2;
values[1].type = GIMP_PDB_IMAGE;
1999-03-21 03:50:30 +08:00
values[1].data.d_image = image_ID;
}
else
{
status = GIMP_PDB_EXECUTION_ERROR;
1999-03-21 03:50:30 +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
values[0].data.d_status = status;
1999-03-21 03:50:30 +08:00
}
#define MAXCOLORMAPSIZE 256
#define CM_RED 0
#define CM_GREEN 1
#define CM_BLUE 2
#define MAX_LZW_BITS 12
1999-03-21 03:50:30 +08:00
#define INTERLACE 0x40
#define LOCALCOLORMAP 0x80
#define BitSet(byte, bit) (((byte) & (bit)) == (bit))
#define ReadOK(file,buffer,len) (fread(buffer, len, 1, file) != 0)
#define LM_to_uint(a,b) (((b)<<8)|(a))
#define GRAYSCALE 1
#define COLOR 2
typedef unsigned char CMap[3][MAXCOLORMAPSIZE];
static struct
{
unsigned int Width;
unsigned int Height;
CMap ColorMap;
1999-03-21 03:50:30 +08:00
unsigned int BitPixel;
unsigned int ColorResolution;
unsigned int Background;
unsigned int AspectRatio;
/*
**
*/
int GrayScale;
1999-03-21 03:50:30 +08:00
} GifScreen;
static struct
{
int transparent;
int delayTime;
int inputFlag;
int disposal;
} Gif89 = { -1, -1, -1, 0 };
static int ReadColorMap (FILE *, int, CMap, int *);
static int DoExtension (FILE *, int);
1999-03-21 03:50:30 +08:00
static int GetDataBlock (FILE *, unsigned char *);
static int GetCode (FILE *, int, int);
static int LZWReadByte (FILE *, int, int);
static gint32 ReadImage (FILE *, const gchar *,
int, int, CMap, int, int, int, int,
guint, guint, guint, guint);
1999-03-21 03:50:30 +08:00
static gint32
load_image (const gchar *filename,
gboolean thumbnail)
1999-03-21 03:50:30 +08:00
{
FILE *fd;
guchar buf[16];
guchar c;
CMap localColorMap;
gint grayScale;
gboolean useGlobalColormap;
gint bitPixel;
gint imageCount = 0;
gchar version[4];
gint32 image_ID = -1;
1999-03-21 03:50:30 +08:00
fd = g_fopen (filename, "rb");
1999-03-21 03:50:30 +08:00
if (!fd)
{
g_message (_("Could not open '%s' for reading: %s"),
2004-01-19 11:06:04 +08:00
gimp_filename_to_utf8 (filename), g_strerror (errno));
1999-03-21 03:50:30 +08:00
return -1;
}
gimp_progress_init_printf (_("Opening '%s'"),
gimp_filename_to_utf8 (filename));
1999-03-21 03:50:30 +08:00
if (!ReadOK (fd, buf, 6))
{
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 ("Error reading magic number");
1999-03-21 03:50:30 +08:00
return -1;
}
if (strncmp ((gchar *) buf, "GIF", 3) != 0)
1999-03-21 03:50:30 +08:00
{
g_message (_("This is not a GIF file"));
1999-03-21 03:50:30 +08:00
return -1;
}
strncpy (version, (gchar *) buf + 3, 3);
1999-03-21 03:50:30 +08:00
version[3] = '\0';
if ((strcmp (version, "87a") != 0) && (strcmp (version, "89a") != 0))
{
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 ("Bad version number, not '87a' or '89a'");
1999-03-21 03:50:30 +08:00
return -1;
}
if (!ReadOK (fd, buf, 7))
{
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 ("Failed to read screen descriptor");
1999-03-21 03:50:30 +08:00
return -1;
}
GifScreen.Width = LM_to_uint (buf[0], buf[1]);
GifScreen.Height = LM_to_uint (buf[2], buf[3]);
GifScreen.BitPixel = 2 << (buf[4] & 0x07);
GifScreen.ColorResolution = (((buf[4] & 0x70) >> 3) + 1);
GifScreen.Background = buf[5];
GifScreen.AspectRatio = buf[6];
if (BitSet (buf[4], LOCALCOLORMAP))
{
/* Global Colormap */
if (ReadColorMap (fd, GifScreen.BitPixel, GifScreen.ColorMap,
&GifScreen.GrayScale))
{
g_message ("Error reading global colormap");
return -1;
}
1999-03-21 03:50:30 +08:00
}
if (GifScreen.AspectRatio != 0 && GifScreen.AspectRatio != 49)
{
g_message (_("Non-square pixels. Image might look squashed."));
1999-03-21 03:50:30 +08:00
}
highest_used_index = 0;
plug-ins/FractalExplorer/Dialogs.c 2003-11-15 Michael Natterer <mitch@gimp.org> * plug-ins/FractalExplorer/Dialogs.c * plug-ins/FractalExplorer/FractalExplorer.c * plug-ins/bmp/bmpread.c * plug-ins/bmp/bmpwrite.c * plug-ins/common/CEL.c * plug-ins/common/CML_explorer.c * plug-ins/common/animoptimize.c * plug-ins/common/bz2.c * plug-ins/common/convmatrix.c * plug-ins/common/curve_bend.c * plug-ins/common/dicom.c * plug-ins/common/gauss_iir.c * plug-ins/common/gauss_rle.c * plug-ins/common/gbr.c * plug-ins/common/gif.c * plug-ins/common/gifload.c * plug-ins/common/gih.c * plug-ins/common/grid.c * plug-ins/common/gtm.c * plug-ins/common/gz.c * plug-ins/common/hrz.c * plug-ins/common/jpeg.c * plug-ins/common/mail.c * plug-ins/common/mapcolor.c * plug-ins/common/pat.c * plug-ins/common/pcx.c * plug-ins/common/pix.c * plug-ins/common/png.c * plug-ins/common/pnm.c * plug-ins/common/ps.c * plug-ins/common/psd.c * plug-ins/common/psd_save.c * plug-ins/common/psp.c * plug-ins/common/sel_gauss.c * plug-ins/common/spheredesigner.c * plug-ins/common/sunras.c * plug-ins/common/svg.c * plug-ins/common/tga.c * plug-ins/common/tiff.c * plug-ins/common/wmf.c * plug-ins/common/xbm.c * plug-ins/common/xwd.c * plug-ins/faxg3/faxg3.c * plug-ins/fits/fits.c * plug-ins/flame/flame.c * plug-ins/gfig/gfig.c * plug-ins/gflare/gflare.c * plug-ins/gfli/gfli.c * plug-ins/gimpressionist/brush.c * plug-ins/gimpressionist/ppmtool.c * plug-ins/helpbrowser/domain.c * plug-ins/ifscompose/ifscompose.c * plug-ins/sgi/sgi.c * plug-ins/twain/twain.c * plug-ins/winsnap/winsnap.c * plug-ins/xjt/xjt.c: removed explicit newlines from messages. Made file open/save messages the same all over the place. Reduced number of translatable strings by adding some more "standard" messages. Removed plug-in names from messages. Added some random mnemonics. Unmarked some strings for translation and added some that were forgotten. General message cleanup. Removed trailing whitespace.
2003-11-15 21:53:33 +08:00
1999-03-21 03:50:30 +08:00
for (;;)
{
if (!ReadOK (fd, &c, 1))
{
g_message ("EOF / read error on image data");
return image_ID; /* will be -1 if failed on first image! */
}
1999-03-21 03:50:30 +08:00
if (c == ';')
{
/* GIF terminator */
return image_ID;
}
1999-03-21 03:50:30 +08:00
if (c == '!')
{
/* Extension */
if (!ReadOK (fd, &c, 1))
{
g_message ("EOF / read error on extension function code");
return image_ID; /* will be -1 if failed on first image! */
}
DoExtension (fd, c);
continue;
}
1999-03-21 03:50:30 +08:00
if (c != ',')
{
/* Not a valid start character */
g_printerr ("GIF: bogus character 0x%02x, ignoring.\n", (int) c);
continue;
}
1999-03-21 03:50:30 +08:00
++imageCount;
if (!ReadOK (fd, buf, 9))
{
g_message ("Couldn't read left/top/width/height");
return image_ID; /* will be -1 if failed on first image! */
}
1999-03-21 03:50:30 +08:00
useGlobalColormap = !BitSet (buf[8], LOCALCOLORMAP);
bitPixel = 1 << ((buf[8] & 0x07) + 1);
if (! useGlobalColormap)
{
if (ReadColorMap (fd, bitPixel, localColorMap, &grayScale))
{
g_message ("Error reading local colormap");
return image_ID; /* will be -1 if failed on first image! */
}
image_ID = ReadImage (fd, filename, LM_to_uint (buf[4], buf[5]),
LM_to_uint (buf[6], buf[7]),
localColorMap, bitPixel,
grayScale,
BitSet (buf[8], INTERLACE), imageCount,
(guint) LM_to_uint (buf[0], buf[1]),
(guint) LM_to_uint (buf[2], buf[3]),
GifScreen.Width,
GifScreen.Height);
}
1999-03-21 03:50:30 +08:00
else
{
image_ID = ReadImage (fd, filename, LM_to_uint (buf[4], buf[5]),
LM_to_uint (buf[6], buf[7]),
GifScreen.ColorMap, GifScreen.BitPixel,
GifScreen.GrayScale,
BitSet (buf[8], INTERLACE), imageCount,
(guint) LM_to_uint (buf[0], buf[1]),
(guint) LM_to_uint (buf[2], buf[3]),
GifScreen.Width,
GifScreen.Height);
}
1999-03-21 03:50:30 +08:00
if (comment_parasite != NULL)
{
if (! thumbnail)
gimp_image_parasite_attach (image_ID, comment_parasite);
gimp_parasite_free (comment_parasite);
comment_parasite = NULL;
}
1999-03-21 03:50:30 +08:00
/* If we are loading a thumbnail, we stop after the first frame. */
if (thumbnail)
break;
1999-03-21 03:50:30 +08:00
}
return image_ID;
}
static int
ReadColorMap (FILE *fd,
int number,
CMap buffer,
int *format)
1999-03-21 03:50:30 +08:00
{
guchar rgb[3];
gint flag;
gint i;
1999-03-21 03:50:30 +08:00
flag = TRUE;
for (i = 0; i < number; ++i)
{
if (!ReadOK (fd, rgb, sizeof (rgb)))
{
g_message ("Bad colormap");
return TRUE;
}
1999-03-21 03:50:30 +08:00
buffer[CM_RED][i] = rgb[0];
buffer[CM_GREEN][i] = rgb[1];
buffer[CM_BLUE][i] = rgb[2];
flag &= (rgb[0] == rgb[1] && rgb[1] == rgb[2]);
}
*format = (flag) ? GRAYSCALE : COLOR;
return FALSE;
}
static int
DoExtension (FILE *fd,
int label)
1999-03-21 03:50:30 +08:00
{
static guchar buf[256];
gchar *str;
1999-03-21 03:50:30 +08:00
switch (label)
{
case 0x01: /* Plain Text Extension */
1999-03-21 03:50:30 +08:00
str = "Plain Text Extension";
#ifdef notdef
if (GetDataBlock (fd, (unsigned char *) buf) == 0)
;
1999-03-21 03:50:30 +08:00
lpos = LM_to_uint (buf[0], buf[1]);
tpos = LM_to_uint (buf[2], buf[3]);
width = LM_to_uint (buf[4], buf[5]);
height = LM_to_uint (buf[6], buf[7]);
cellw = buf[8];
cellh = buf[9];
foreground = buf[10];
background = buf[11];
while (GetDataBlock (fd, (unsigned char *) buf) > 0)
{
PPM_ASSIGN (image[ypos][xpos],
cmap[CM_RED][v],
cmap[CM_GREEN][v],
cmap[CM_BLUE][v]);
++index;
}
1999-03-21 03:50:30 +08:00
return FALSE;
#else
break;
#endif
case 0xff: /* Application Extension */
1999-03-21 03:50:30 +08:00
str = "Application Extension";
break;
case 0xfe: /* Comment Extension */
1999-03-21 03:50:30 +08:00
str = "Comment Extension";
while (GetDataBlock (fd, (unsigned char *) buf) > 0)
{
gchar *comment = (gchar *) buf;
if (!g_utf8_validate (comment, -1, NULL))
continue;
if (comment_parasite)
gimp_parasite_free (comment_parasite);
plug-ins/FractalExplorer/Dialogs.c 2003-11-15 Michael Natterer <mitch@gimp.org> * plug-ins/FractalExplorer/Dialogs.c * plug-ins/FractalExplorer/FractalExplorer.c * plug-ins/bmp/bmpread.c * plug-ins/bmp/bmpwrite.c * plug-ins/common/CEL.c * plug-ins/common/CML_explorer.c * plug-ins/common/animoptimize.c * plug-ins/common/bz2.c * plug-ins/common/convmatrix.c * plug-ins/common/curve_bend.c * plug-ins/common/dicom.c * plug-ins/common/gauss_iir.c * plug-ins/common/gauss_rle.c * plug-ins/common/gbr.c * plug-ins/common/gif.c * plug-ins/common/gifload.c * plug-ins/common/gih.c * plug-ins/common/grid.c * plug-ins/common/gtm.c * plug-ins/common/gz.c * plug-ins/common/hrz.c * plug-ins/common/jpeg.c * plug-ins/common/mail.c * plug-ins/common/mapcolor.c * plug-ins/common/pat.c * plug-ins/common/pcx.c * plug-ins/common/pix.c * plug-ins/common/png.c * plug-ins/common/pnm.c * plug-ins/common/ps.c * plug-ins/common/psd.c * plug-ins/common/psd_save.c * plug-ins/common/psp.c * plug-ins/common/sel_gauss.c * plug-ins/common/spheredesigner.c * plug-ins/common/sunras.c * plug-ins/common/svg.c * plug-ins/common/tga.c * plug-ins/common/tiff.c * plug-ins/common/wmf.c * plug-ins/common/xbm.c * plug-ins/common/xwd.c * plug-ins/faxg3/faxg3.c * plug-ins/fits/fits.c * plug-ins/flame/flame.c * plug-ins/gfig/gfig.c * plug-ins/gflare/gflare.c * plug-ins/gfli/gfli.c * plug-ins/gimpressionist/brush.c * plug-ins/gimpressionist/ppmtool.c * plug-ins/helpbrowser/domain.c * plug-ins/ifscompose/ifscompose.c * plug-ins/sgi/sgi.c * plug-ins/twain/twain.c * plug-ins/winsnap/winsnap.c * plug-ins/xjt/xjt.c: removed explicit newlines from messages. Made file open/save messages the same all over the place. Reduced number of translatable strings by adding some more "standard" messages. Removed plug-in names from messages. Added some random mnemonics. Unmarked some strings for translation and added some that were forgotten. General message cleanup. Removed trailing whitespace.
2003-11-15 21:53:33 +08:00
comment_parasite = gimp_parasite_new ("gimp-comment",
GIMP_PARASITE_PERSISTENT,
strlen (comment) + 1, comment);
}
1999-03-21 03:50:30 +08:00
return TRUE;
break;
case 0xf9: /* Graphic Control Extension */
1999-03-21 03:50:30 +08:00
str = "Graphic Control Extension";
(void) GetDataBlock (fd, (unsigned char *) buf);
Gif89.disposal = (buf[0] >> 2) & 0x7;
Gif89.inputFlag = (buf[0] >> 1) & 0x1;
Gif89.delayTime = LM_to_uint (buf[1], buf[2]);
if ((buf[0] & 0x1) != 0)
Gif89.transparent = buf[3];
1999-03-21 03:50:30 +08:00
else
Gif89.transparent = -1;
1999-03-21 03:50:30 +08:00
while (GetDataBlock (fd, (unsigned char *) buf) > 0)
;
1999-03-21 03:50:30 +08:00
return FALSE;
break;
default:
str = (char *)buf;
sprintf ((char *)buf, "UNKNOWN (0x%02x)", label);
break;
}
#ifdef GIFDEBUG
g_print ("GIF: got a '%s'\n", str);
#endif
while (GetDataBlock (fd, (unsigned char *) buf) > 0)
1999-03-21 03:50:30 +08:00
;
return FALSE;
}
int ZeroDataBlock = FALSE;
static int
GetDataBlock (FILE *fd,
unsigned char *buf)
1999-03-21 03:50:30 +08:00
{
unsigned char count;
if (!ReadOK (fd, &count, 1))
{
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 ("Error in getting DataBlock size");
1999-03-21 03:50:30 +08:00
return -1;
}
ZeroDataBlock = count == 0;
if ((count != 0) && (!ReadOK (fd, buf, count)))
{
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 ("Error in reading DataBlock");
1999-03-21 03:50:30 +08:00
return -1;
}
return count;
}
static int
GetCode (FILE *fd,
int code_size,
int flag)
1999-03-21 03:50:30 +08:00
{
static unsigned char buf[280];
static int curbit, lastbit, done, last_byte;
int i, j, ret, count;
1999-03-21 03:50:30 +08:00
if (flag)
{
curbit = 0;
lastbit = 0;
done = FALSE;
1999-11-12 05:53:40 +08:00
last_byte = 2;
1999-03-21 03:50:30 +08:00
return 0;
}
if ((curbit + code_size) >= lastbit)
{
if (done)
{
if (curbit >= lastbit)
{
g_message ("Ran off the end of my bits");
gimp_quit ();
}
return -1;
}
1999-03-21 03:50:30 +08:00
buf[0] = buf[last_byte - 2];
buf[1] = buf[last_byte - 1];
if ((count = GetDataBlock (fd, &buf[2])) <= 0)
done = TRUE;
1999-03-21 03:50:30 +08:00
last_byte = 2 + count;
curbit = (curbit - lastbit) + 16;
lastbit = (2 + count) * 8;
}
ret = 0;
for (i = curbit, j = 0; j < code_size; ++i, ++j)
ret |= ((buf[i / 8] & (1 << (i % 8))) != 0) << j;
curbit += code_size;
return ret;
}
static int
LZWReadByte (FILE *fd,
int just_reset_LZW,
int input_code_size)
1999-03-21 03:50:30 +08:00
{
static int fresh = FALSE;
int code, incode;
static int code_size, set_code_size;
static int max_code, max_code_size;
static int firstcode, oldcode;
static int clear_code, end_code;
static int table[2][(1 << MAX_LZW_BITS)];
static int stack[(1 << (MAX_LZW_BITS)) * 2], *sp;
1999-03-21 03:50:30 +08:00
register int i;
if (just_reset_LZW)
1999-03-21 03:50:30 +08:00
{
if (input_code_size > MAX_LZW_BITS)
{
g_message("Value out of range for code size (corrupted file?)");
return -1;
}
1999-03-21 03:50:30 +08:00
set_code_size = input_code_size;
code_size = set_code_size + 1;
clear_code = 1 << set_code_size;
end_code = clear_code + 1;
max_code_size = 2 * clear_code;
max_code = clear_code + 2;
GetCode (fd, 0, TRUE);
fresh = TRUE;
sp = stack;
1999-03-21 03:50:30 +08:00
for (i = 0; i < clear_code; ++i)
{
table[0][i] = 0;
table[1][i] = i;
}
for (; i < (1 << MAX_LZW_BITS); ++i)
{
table[0][i] = 0;
table[1][i] = 0;
}
1999-03-21 03:50:30 +08:00
return 0;
}
else if (fresh)
{
fresh = FALSE;
do
{
firstcode = oldcode =
GetCode (fd, code_size, FALSE);
}
1999-03-21 03:50:30 +08:00
while (firstcode == clear_code);
return firstcode;
}
if (sp > stack)
return *--sp;
while ((code = GetCode (fd, code_size, FALSE)) >= 0)
{
if (code == clear_code)
{
for (i = 0; i < clear_code; ++i)
{
table[0][i] = 0;
table[1][i] = i;
}
for (; i < (1 << MAX_LZW_BITS); ++i)
{
table[0][i] = 0;
table[1][i] = 0;
}
code_size = set_code_size + 1;
max_code_size = 2 * clear_code;
max_code = clear_code + 2;
sp = stack;
firstcode = oldcode =
GetCode (fd, code_size, FALSE);
return firstcode;
}
1999-03-21 03:50:30 +08:00
else if (code == end_code)
{
int count;
unsigned char buf[260];
1999-03-21 03:50:30 +08:00
if (ZeroDataBlock)
return -2;
1999-03-21 03:50:30 +08:00
while ((count = GetDataBlock (fd, buf)) > 0)
;
1999-03-21 03:50:30 +08:00
if (count != 0)
g_print ("GIF: missing EOD in data stream (common occurence)");
return -2;
}
1999-03-21 03:50:30 +08:00
incode = code;
if (code >= max_code)
{
*sp++ = firstcode;
code = oldcode;
}
1999-03-21 03:50:30 +08:00
while (code >= clear_code)
{
*sp++ = table[1][code];
if (code == table[0][code])
{
g_message ("Circular table entry. Corrupt file.");
gimp_quit ();
}
code = table[0][code];
}
1999-03-21 03:50:30 +08:00
*sp++ = firstcode = table[1][code];
if ((code = max_code) < (1 << MAX_LZW_BITS))
{
table[0][code] = oldcode;
table[1][code] = firstcode;
++max_code;
if ((max_code >= max_code_size) &&
(max_code_size < (1 << MAX_LZW_BITS)))
{
max_code_size *= 2;
++code_size;
}
}
1999-03-21 03:50:30 +08:00
oldcode = incode;
if (sp > stack)
return *--sp;
1999-03-21 03:50:30 +08:00
}
return code;
}
static gint32
ReadImage (FILE *fd,
const gchar *filename,
gint len,
gint height,
CMap cmap,
gint ncols,
gint format,
gint interlace,
gint number,
guint leftpos,
guint toppos,
guint screenwidth,
guint screenheight)
1999-03-21 03:50:30 +08:00
{
static gint32 image_ID = -1;
1999-03-21 03:50:30 +08:00
static gint frame_number = 1;
gint32 layer_ID;
GimpPixelRgn pixel_rgn;
GimpDrawable *drawable;
1999-03-21 03:50:30 +08:00
guchar *dest, *temp;
guchar c;
gint xpos = 0, ypos = 0, pass = 0;
gint cur_progress, max_progress;
gint v;
gint i, j;
gchar *framename;
gchar *framename_ptr;
1999-03-21 03:50:30 +08:00
gboolean alpha_frame = FALSE;
static int previous_disposal;
/* Guard against bogus frame size */
if (len < 1 || height < 1)
{
g_message ("Bogus frame dimensions");
return -1;
}
1999-03-21 03:50:30 +08:00
/*
** Initialize the Compression routines
*/
if (!ReadOK (fd, &c, 1))
{
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 ("EOF / read error on image data");
1999-03-21 03:50:30 +08:00
return -1;
}
if (LZWReadByte (fd, TRUE, c) < 0)
1999-03-21 03:50:30 +08:00
{
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 ("Error while reading");
1999-03-21 03:50:30 +08:00
return -1;
}
if (frame_number == 1)
1999-03-21 03:50:30 +08:00
{
/* Guard against bogus logical screen size values */
if (screenwidth == 0)
screenwidth = len;
if (screenheight == 0)
screenheight = height;
image_ID = gimp_image_new (screenwidth, screenheight, GIMP_INDEXED);
1999-03-21 03:50:30 +08:00
gimp_image_set_filename (image_ID, filename);
for (i = 0, j = 0; i < ncols; i++)
{
used_cmap[0][i] = gimp_cmap[j++] = cmap[0][i];
used_cmap[1][i] = gimp_cmap[j++] = cmap[1][i];
used_cmap[2][i] = gimp_cmap[j++] = cmap[2][i];
}
1999-03-21 03:50:30 +08:00
gimp_image_set_colormap (image_ID, gimp_cmap, ncols);
1999-03-21 03:50:30 +08:00
if (Gif89.delayTime < 0)
framename = g_strdup (_("Background"));
1999-03-21 03:50:30 +08:00
else
framename = g_strdup_printf (_("Background (%d%s)"),
10 * Gif89.delayTime, "ms");
1999-03-21 03:50:30 +08:00
previous_disposal = Gif89.disposal;
if (Gif89.transparent == -1)
{
layer_ID = gimp_layer_new (image_ID, framename,
len, height,
GIMP_INDEXED_IMAGE, 100, GIMP_NORMAL_MODE);
}
1999-03-21 03:50:30 +08:00
else
{
layer_ID = gimp_layer_new (image_ID, framename,
len, height,
GIMP_INDEXEDA_IMAGE, 100, GIMP_NORMAL_MODE);
alpha_frame=TRUE;
}
g_free (framename);
1999-03-21 03:50:30 +08:00
}
else /* NOT FIRST FRAME */
{
gimp_progress_set_text_printf (_("Opening '%s' (frame %d)"),
gimp_filename_to_utf8 (filename),
frame_number);
gimp_progress_pulse ();
/* If the colourmap is now different, we have to promote to RGB! */
1999-03-21 03:50:30 +08:00
if (!promote_to_rgb)
{
for (i = 0; i < ncols; i++)
{
if ((used_cmap[0][i] != cmap[0][i]) ||
(used_cmap[1][i] != cmap[1][i]) ||
(used_cmap[2][i] != cmap[2][i]))
{
/* Everything is RGB(A) from now on... sigh. */
promote_to_rgb = TRUE;
plug-ins/FractalExplorer/Dialogs.c 2003-11-15 Michael Natterer <mitch@gimp.org> * plug-ins/FractalExplorer/Dialogs.c * plug-ins/FractalExplorer/FractalExplorer.c * plug-ins/bmp/bmpread.c * plug-ins/bmp/bmpwrite.c * plug-ins/common/CEL.c * plug-ins/common/CML_explorer.c * plug-ins/common/animoptimize.c * plug-ins/common/bz2.c * plug-ins/common/convmatrix.c * plug-ins/common/curve_bend.c * plug-ins/common/dicom.c * plug-ins/common/gauss_iir.c * plug-ins/common/gauss_rle.c * plug-ins/common/gbr.c * plug-ins/common/gif.c * plug-ins/common/gifload.c * plug-ins/common/gih.c * plug-ins/common/grid.c * plug-ins/common/gtm.c * plug-ins/common/gz.c * plug-ins/common/hrz.c * plug-ins/common/jpeg.c * plug-ins/common/mail.c * plug-ins/common/mapcolor.c * plug-ins/common/pat.c * plug-ins/common/pcx.c * plug-ins/common/pix.c * plug-ins/common/png.c * plug-ins/common/pnm.c * plug-ins/common/ps.c * plug-ins/common/psd.c * plug-ins/common/psd_save.c * plug-ins/common/psp.c * plug-ins/common/sel_gauss.c * plug-ins/common/spheredesigner.c * plug-ins/common/sunras.c * plug-ins/common/svg.c * plug-ins/common/tga.c * plug-ins/common/tiff.c * plug-ins/common/wmf.c * plug-ins/common/xbm.c * plug-ins/common/xwd.c * plug-ins/faxg3/faxg3.c * plug-ins/fits/fits.c * plug-ins/flame/flame.c * plug-ins/gfig/gfig.c * plug-ins/gflare/gflare.c * plug-ins/gfli/gfli.c * plug-ins/gimpressionist/brush.c * plug-ins/gimpressionist/ppmtool.c * plug-ins/helpbrowser/domain.c * plug-ins/ifscompose/ifscompose.c * plug-ins/sgi/sgi.c * plug-ins/twain/twain.c * plug-ins/winsnap/winsnap.c * plug-ins/xjt/xjt.c: removed explicit newlines from messages. Made file open/save messages the same all over the place. Reduced number of translatable strings by adding some more "standard" messages. Removed plug-in names from messages. Added some random mnemonics. Unmarked some strings for translation and added some that were forgotten. General message cleanup. Removed trailing whitespace.
2003-11-15 21:53:33 +08:00
/* Promote everything we have so far into RGB(A) */
1999-03-21 03:50:30 +08:00
#ifdef GIFDEBUG
g_print ("GIF: Promoting image to RGB...\n");
1999-03-21 03:50:30 +08:00
#endif
gimp_image_convert_rgb (image_ID);
break;
}
}
}
1999-03-21 03:50:30 +08:00
if (Gif89.delayTime < 0)
framename = g_strdup_printf (_("Frame %d"), frame_number);
1999-03-21 03:50:30 +08:00
else
framename = g_strdup_printf (_("Frame %d (%d%s)"),
frame_number, 10 * Gif89.delayTime, "ms");
1999-03-21 03:50:30 +08:00
switch (previous_disposal)
{
case 0x00:
break; /* 'don't care' */
case 0x01:
framename_ptr = framename;
framename = g_strconcat (framename, " (combine)", NULL);
g_free (framename_ptr);
break;
case 0x02:
framename_ptr = framename;
framename = g_strconcat (framename, " (replace)", NULL);
g_free (framename_ptr);
break;
case 0x03: /* Rarely-used, and unhandled by many
loaders/players (including GIMP: we treat as
'combine' mode). */
framename_ptr = framename;
framename = g_strconcat (framename, " (combine) (!)", NULL);
g_free (framename_ptr);
break;
case 0x04: /* I've seen a composite of this type. stvo_online_banner2.gif */
case 0x05:
case 0x06: /* I've seen a composite of this type. bn31.Gif */
case 0x07:
framename_ptr = framename;
framename = g_strconcat (framename, " (unknown disposal)", NULL);
g_free (framename_ptr);
g_message (_("GIF: Undocumented GIF composite type %d is "
"not handled. Animation might not play or "
"re-save perfectly."),
previous_disposal);
break;
default:
g_message ("Disposal word got corrupted. Bug.");
break;
}
1999-03-21 03:50:30 +08:00
previous_disposal = Gif89.disposal;
layer_ID = gimp_layer_new (image_ID, framename,
len, height,
promote_to_rgb ?
GIMP_RGBA_IMAGE : GIMP_INDEXEDA_IMAGE,
100, GIMP_NORMAL_MODE);
1999-03-21 03:50:30 +08:00
alpha_frame = TRUE;
g_free (framename);
1999-03-21 03:50:30 +08:00
}
frame_number++;
gimp_image_add_layer (image_ID, layer_ID, 0);
gimp_layer_translate (layer_ID, (gint) leftpos, (gint) toppos);
1999-03-21 03:50:30 +08:00
drawable = gimp_drawable_get (layer_ID);
cur_progress = 0;
max_progress = height;
if (alpha_frame)
dest = (guchar *) g_malloc (len * height *
(promote_to_rgb ? 4 : 2));
1999-03-21 03:50:30 +08:00
else
dest = (guchar *) g_malloc (len * height);
#ifdef GIFDEBUG
g_print ("GIF: reading %d by %d%s GIF image, ncols=%d\n",
len, height, interlace ? " interlaced" : "", ncols);
#endif
1999-03-21 03:50:30 +08:00
if (!alpha_frame && promote_to_rgb)
{
/* I don't see how one would easily construct a GIF in which
this could happen, but it's a mad mad world. */
g_message ("Ouch! Can't handle non-alpha RGB frames.\n"
2004-01-19 11:06:04 +08:00
"Please file a bug report in GIMP's bugzilla.");
gimp_quit ();
1999-03-21 03:50:30 +08:00
}
while ((v = LZWReadByte (fd, FALSE, c)) >= 0)
1999-03-21 03:50:30 +08:00
{
if (alpha_frame)
{
if (((guchar) v > highest_used_index) && !(v == Gif89.transparent))
highest_used_index = (guchar) v;
if (promote_to_rgb)
{
temp = dest + ( (ypos * len) + xpos ) * 4;
*(temp ) = (guchar) cmap[0][v];
*(temp+1) = (guchar) cmap[1][v];
*(temp+2) = (guchar) cmap[2][v];
*(temp+3) = (guchar) ((v == Gif89.transparent) ? 0 : 255);
}
else
{
temp = dest + ( (ypos * len) + xpos ) * 2;
*temp = (guchar) v;
*(temp+1) = (guchar) ((v == Gif89.transparent) ? 0 : 255);
}
}
1999-03-21 03:50:30 +08:00
else
{
if ((guchar) v > highest_used_index)
highest_used_index = (guchar) v;
1999-03-21 03:50:30 +08:00
temp = dest + (ypos * len) + xpos;
*temp = (guchar) v;
}
1999-03-21 03:50:30 +08:00
xpos++;
if (xpos == len)
{
xpos = 0;
if (interlace)
{
switch (pass)
{
case 0:
case 1:
ypos += 8;
break;
case 2:
ypos += 4;
break;
case 3:
ypos += 2;
break;
}
if (ypos >= height)
{
pass++;
switch (pass)
{
case 1:
ypos = 4;
break;
case 2:
ypos = 2;
break;
case 3:
ypos = 1;
break;
default:
goto fini;
}
}
}
else
{
ypos++;
}
1999-03-21 03:50:30 +08:00
if (frame_number == 1)
{
cur_progress++;
if ((cur_progress % 16) == 0)
gimp_progress_update ((gdouble) cur_progress /
(gdouble) max_progress);
}
}
1999-03-21 03:50:30 +08:00
if (ypos >= height)
break;
1999-03-21 03:50:30 +08:00
}
fini:
if (LZWReadByte (fd, FALSE, c) >= 0)
g_print ("GIF: too much input data, ignoring extra...\n");
1999-03-21 03:50:30 +08:00
gimp_pixel_rgn_init (&pixel_rgn, drawable,
0, 0, drawable->width, drawable->height, TRUE, FALSE);
gimp_pixel_rgn_set_rect (&pixel_rgn, dest,
0, 0, drawable->width, drawable->height);
1999-03-21 03:50:30 +08:00
g_free (dest);
gimp_drawable_flush (drawable);
gimp_drawable_detach (drawable);
return image_ID;
}