2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2001-07-04 02:38:56 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2001-07-04 02:38:56 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2001-07-04 02:38:56 +08:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2001-07-04 02:38:56 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <string.h>
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2011-04-28 21:50:39 +08:00
|
|
|
#include <cairo.h>
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2012-05-03 09:36:22 +08:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
#include "libgimpbase/gimpbase.h"
|
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
|
|
|
|
|
|
|
#include "core/core-types.h"
|
|
|
|
|
2002-11-19 04:50:31 +08:00
|
|
|
#include "config/gimpcoreconfig.h"
|
|
|
|
|
2012-04-03 05:32:38 +08:00
|
|
|
#include "gegl/gimp-gegl-tile-compat.h"
|
|
|
|
|
2001-07-06 00:21:36 +08:00
|
|
|
#include "core/gimp.h"
|
2001-07-04 02:38:56 +08:00
|
|
|
#include "core/gimpcontainer.h"
|
2009-02-04 07:57:11 +08:00
|
|
|
#include "core/gimpdrawable-private.h" /* eek */
|
2003-10-10 22:11:47 +08:00
|
|
|
#include "core/gimpgrid.h"
|
2009-08-31 03:28:59 +08:00
|
|
|
#include "core/gimpgrouplayer.h"
|
2001-07-04 02:38:56 +08:00
|
|
|
#include "core/gimpimage.h"
|
2007-10-26 17:48:07 +08:00
|
|
|
#include "core/gimpimage-colormap.h"
|
2003-07-05 03:55:58 +08:00
|
|
|
#include "core/gimpimage-grid.h"
|
include the new "paint-funcs/paint-funcs-types.h".
2001-11-28 Michael Natterer <mitch@gimp.org>
* app/base/base-types.h: include the new
"paint-funcs/paint-funcs-types.h".
* app/paint-funcs/Makefile.am
* app/paint-funcs/paint-funcs-types.h: new file. Includes
"base/base-types.h".
* app/paint-funcs/paint-funcs.[ch]: removed the enums here,
include "paint-funcs-types.h".
* app/widgets/widgets-types.h: include "display/display-types.h"
* app/display/display-types.h: include "widgets/widgets-types.h".
* app/tools/tools-types.h: include "display/display-types.h"
* app/gui/gui-types.h: include "tools/tools-types.h".
The order of namespaces/dependencies should be (but is not):
(base, paint-funcs) -> (core, file, xcf, pdb) ->
(widgets, display) -> tools -> gui
* app/path.c: include "tools/tools-types.h".
* app/core/Makefile.am
* app/core/gimpimage-guides.[ch]
* app/core/gimpimage-merge.[ch]
* app/core/gimpimage-resize.[ch]
* app/core/gimpimage-scale.[ch]: new files.
* app/core/gimpimage.[ch]: removed the stuff which is in the new
files. Reordered all functions in both the .h and .c files,
commented the groups of functions.
* app/core/gimpcontainer.c: create the handler_id using a counter,
not the address of a pointer, because the address *may* be the
same twice, added debugging output.
* app/core/gimpviewable.[ch]: added primitive support for getting
a preview GdkPixbuf.
* app/nav_window.c
* app/undo.c
* app/undo_history.c
* app/core/gimpimage-duplicate.c
* app/core/gimpimage-mask.[ch]
* app/display/gimpdisplay.c
* app/display/gimpdisplayshell-callbacks.c
* app/display/gimpdisplayshell-dnd.c
* app/display/gimpdisplayshell-render.c
* app/display/gimpdisplayshell-scale.c
* app/display/gimpdisplayshell-scroll.c
* app/gui/image-commands.c
* app/gui/info-window.c
* app/gui/layers-commands.c
* app/gui/palette-import-dialog.c
* app/tools/gimpbycolorselecttool.c
* app/tools/gimpeditselectiontool.c
* app/tools/gimpmeasuretool.c
* app/tools/gimpmovetool.c
* app/widgets/gimpcontainerview-utils.c
* app/xcf/xcf-load.c: changed accordingly, some cleanup.
* tools/pdbgen/pdb/guides.pdb
* tools/pdbgen/pdb/image.pdb: changed accordingly, reordered functions.
* app/plug_in.c: set the labels of the "Repeat" and "Re-Show" menu
items to the name of the last plug-in (Fixes #50986).
* app/display/gimpdisplayshell.[ch]: set the labels of "Undo" and
"Redo" to the resp. undo names. Much simplified the WM icon stuff
by removing most code and using gimp_viewable_get_new_preview_pixbuf().
* app/widgets/gimpbrushfactoryview.c: forgot to assign the GQuark
returned by gimp_container_add_handler().
* app/pdb/guides_cmds.c
* app/pdb/image_cmds.c
* libgimp/gimpimage_pdb.[ch]: regenerated.
2001-11-29 01:51:06 +08:00
|
|
|
#include "core/gimpimage-guides.h"
|
2010-02-04 05:16:02 +08:00
|
|
|
#include "core/gimpimage-private.h"
|
2006-08-11 01:10:12 +08:00
|
|
|
#include "core/gimpimage-sample-points.h"
|
2010-02-08 18:11:33 +08:00
|
|
|
#include "core/gimpimage-undo.h"
|
2009-08-31 03:28:59 +08:00
|
|
|
#include "core/gimpitemstack.h"
|
2002-02-22 06:19:45 +08:00
|
|
|
#include "core/gimplayer-floating-sel.h"
|
2001-07-04 02:38:56 +08:00
|
|
|
#include "core/gimplayermask.h"
|
2001-07-10 03:48:30 +08:00
|
|
|
#include "core/gimpparasitelist.h"
|
2006-07-12 04:21:18 +08:00
|
|
|
#include "core/gimpprogress.h"
|
2003-09-03 07:07:40 +08:00
|
|
|
#include "core/gimpselection.h"
|
2003-10-14 23:20:59 +08:00
|
|
|
#include "core/gimptemplate.h"
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2004-03-18 23:27:23 +08:00
|
|
|
#include "text/gimptextlayer.h"
|
2003-10-28 05:50:41 +08:00
|
|
|
#include "text/gimptextlayer-xcf.h"
|
2003-06-24 21:59:36 +08:00
|
|
|
|
2003-09-09 23:46:59 +08:00
|
|
|
#include "vectors/gimpanchor.h"
|
|
|
|
#include "vectors/gimpstroke.h"
|
|
|
|
#include "vectors/gimpbezierstroke.h"
|
2003-05-15 03:21:42 +08:00
|
|
|
#include "vectors/gimpvectors.h"
|
2003-05-23 03:02:38 +08:00
|
|
|
#include "vectors/gimpvectors-compat.h"
|
2003-05-15 03:21:42 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
#include "xcf-private.h"
|
|
|
|
#include "xcf-load.h"
|
|
|
|
#include "xcf-read.h"
|
|
|
|
#include "xcf-seek.h"
|
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2006-07-12 04:21:18 +08:00
|
|
|
|
2004-03-03 23:54:19 +08:00
|
|
|
/* #define GIMP_XCF_PATH_DEBUG */
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2012-04-03 05:32:38 +08:00
|
|
|
static void xcf_load_add_masks (GimpImage *image);
|
|
|
|
static gboolean xcf_load_image_props (XcfInfo *info,
|
|
|
|
GimpImage *image);
|
|
|
|
static gboolean xcf_load_layer_props (XcfInfo *info,
|
|
|
|
GimpImage *image,
|
|
|
|
GimpLayer **layer,
|
|
|
|
GList **item_path,
|
|
|
|
gboolean *apply_mask,
|
|
|
|
gboolean *edit_mask,
|
|
|
|
gboolean *show_mask,
|
|
|
|
guint32 *text_layer_flags,
|
|
|
|
guint32 *group_layer_flags);
|
|
|
|
static gboolean xcf_load_channel_props (XcfInfo *info,
|
|
|
|
GimpImage *image,
|
|
|
|
GimpChannel **channel);
|
|
|
|
static gboolean xcf_load_prop (XcfInfo *info,
|
|
|
|
PropType *prop_type,
|
|
|
|
guint32 *prop_size);
|
|
|
|
static GimpLayer * xcf_load_layer (XcfInfo *info,
|
|
|
|
GimpImage *image,
|
|
|
|
GList **item_path);
|
|
|
|
static GimpChannel * xcf_load_channel (XcfInfo *info,
|
|
|
|
GimpImage *image);
|
|
|
|
static GimpLayerMask * xcf_load_layer_mask (XcfInfo *info,
|
|
|
|
GimpImage *image);
|
|
|
|
static gboolean xcf_load_buffer (XcfInfo *info,
|
|
|
|
GeglBuffer *buffer);
|
|
|
|
static gboolean xcf_load_level (XcfInfo *info,
|
|
|
|
GeglBuffer *buffer);
|
|
|
|
static gboolean xcf_load_tile (XcfInfo *info,
|
|
|
|
GeglBuffer *buffer,
|
2012-04-21 05:45:22 +08:00
|
|
|
GeglRectangle *tile_rect,
|
|
|
|
const Babl *format);
|
2012-04-03 05:32:38 +08:00
|
|
|
static gboolean xcf_load_tile_rle (XcfInfo *info,
|
|
|
|
GeglBuffer *buffer,
|
|
|
|
GeglRectangle *tile_rect,
|
2012-04-21 05:45:22 +08:00
|
|
|
const Babl *format,
|
2012-04-03 05:32:38 +08:00
|
|
|
gint data_length);
|
|
|
|
static GimpParasite * xcf_load_parasite (XcfInfo *info);
|
|
|
|
static gboolean xcf_load_old_paths (XcfInfo *info,
|
|
|
|
GimpImage *image);
|
|
|
|
static gboolean xcf_load_old_path (XcfInfo *info,
|
|
|
|
GimpImage *image);
|
|
|
|
static gboolean xcf_load_vectors (XcfInfo *info,
|
|
|
|
GimpImage *image);
|
|
|
|
static gboolean xcf_load_vector (XcfInfo *info,
|
|
|
|
GimpImage *image);
|
|
|
|
|
|
|
|
static gboolean xcf_skip_unknown_prop (XcfInfo *info,
|
|
|
|
gsize size);
|
2010-08-07 06:26:58 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2006-07-12 04:21:18 +08:00
|
|
|
#define xcf_progress_update(info) G_STMT_START \
|
|
|
|
{ \
|
|
|
|
if (info->progress) \
|
|
|
|
gimp_progress_pulse (info->progress); \
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
GimpImage *
|
2007-12-03 15:44:49 +08:00
|
|
|
xcf_load_image (Gimp *gimp,
|
|
|
|
XcfInfo *info,
|
|
|
|
GError **error)
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
2006-04-02 23:37:25 +08:00
|
|
|
GimpImage *image;
|
|
|
|
const GimpParasite *parasite;
|
|
|
|
guint32 saved_pos;
|
|
|
|
guint32 offset;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gint image_type;
|
2012-04-27 22:42:19 +08:00
|
|
|
gint precision = GIMP_PRECISION_U8;
|
2006-04-02 23:37:25 +08:00
|
|
|
gint num_successful_elements = 0;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
/* read in the image width, height and type */
|
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) &width, 1);
|
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) &height, 1);
|
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) &image_type, 1);
|
|
|
|
|
2012-04-27 22:42:19 +08:00
|
|
|
if (info->file_version >= 4)
|
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) &precision, 1);
|
|
|
|
|
|
|
|
image = gimp_create_image (gimp, width, height, image_type, precision,
|
2012-04-22 23:31:32 +08:00
|
|
|
FALSE);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_undo_disable (image);
|
2005-08-05 22:13:10 +08:00
|
|
|
|
2006-07-12 04:21:18 +08:00
|
|
|
xcf_progress_update (info);
|
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
/* read the image properties */
|
2006-03-29 01:08:36 +08:00
|
|
|
if (! xcf_load_image_props (info, image))
|
2001-07-04 02:38:56 +08:00
|
|
|
goto hard_error;
|
|
|
|
|
2003-07-05 03:55:58 +08:00
|
|
|
/* check for a GimpGrid parasite */
|
2006-03-29 01:08:36 +08:00
|
|
|
parasite = gimp_image_parasite_find (GIMP_IMAGE (image),
|
2003-07-05 03:55:58 +08:00
|
|
|
gimp_grid_parasite_name ());
|
|
|
|
if (parasite)
|
|
|
|
{
|
|
|
|
GimpGrid *grid = gimp_grid_from_parasite (parasite);
|
|
|
|
|
|
|
|
if (grid)
|
|
|
|
{
|
2010-02-04 06:42:32 +08:00
|
|
|
GimpImagePrivate *private = GIMP_IMAGE_GET_PRIVATE (image);
|
|
|
|
|
|
|
|
gimp_parasite_list_remove (private->parasites,
|
2003-07-05 03:55:58 +08:00
|
|
|
gimp_parasite_name (parasite));
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_set_grid (GIMP_IMAGE (image), grid, FALSE);
|
2008-03-31 01:03:18 +08:00
|
|
|
g_object_unref (grid);
|
2003-07-05 03:55:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-12 04:21:18 +08:00
|
|
|
xcf_progress_update (info);
|
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
while (TRUE)
|
|
|
|
{
|
2009-08-31 03:07:22 +08:00
|
|
|
GimpLayer *layer;
|
2009-08-31 03:28:59 +08:00
|
|
|
GList *item_path = NULL;
|
2009-08-31 03:07:22 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
/* read in the offset of the next layer */
|
|
|
|
info->cp += xcf_read_int32 (info->fp, &offset, 1);
|
|
|
|
|
|
|
|
/* if the offset is 0 then we are at the end
|
|
|
|
* of the layer list.
|
|
|
|
*/
|
|
|
|
if (offset == 0)
|
2004-11-02 02:33:09 +08:00
|
|
|
break;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
/* save the current position as it is where the
|
|
|
|
* next layer offset is stored.
|
|
|
|
*/
|
|
|
|
saved_pos = info->cp;
|
|
|
|
|
|
|
|
/* seek to the layer offset */
|
2002-12-20 14:26:34 +08:00
|
|
|
if (! xcf_seek_pos (info, offset, NULL))
|
|
|
|
goto error;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
/* read in the layer */
|
2009-08-31 03:28:59 +08:00
|
|
|
layer = xcf_load_layer (info, image, &item_path);
|
2001-07-04 02:38:56 +08:00
|
|
|
if (!layer)
|
2004-11-02 02:33:09 +08:00
|
|
|
goto error;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
num_successful_elements++;
|
|
|
|
|
2006-07-12 04:21:18 +08:00
|
|
|
xcf_progress_update (info);
|
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
/* add the layer to the image if its not the floating selection */
|
|
|
|
if (layer != info->floating_sel)
|
2009-08-31 03:28:59 +08:00
|
|
|
{
|
|
|
|
GimpContainer *layers = gimp_image_get_layers (image);
|
|
|
|
GimpContainer *container;
|
|
|
|
GimpLayer *parent;
|
|
|
|
|
|
|
|
if (item_path)
|
|
|
|
{
|
2009-08-31 21:15:30 +08:00
|
|
|
if (info->floating_sel)
|
|
|
|
{
|
|
|
|
/* there is a floating selection, but it will get
|
|
|
|
* added after all layers are loaded, so toplevel
|
|
|
|
* layer indices are off-by-one. Adjust item paths
|
|
|
|
* accordingly:
|
|
|
|
*/
|
|
|
|
gint toplevel_index;
|
|
|
|
|
|
|
|
toplevel_index = GPOINTER_TO_UINT (item_path->data);
|
|
|
|
|
|
|
|
toplevel_index--;
|
|
|
|
|
|
|
|
item_path->data = GUINT_TO_POINTER (toplevel_index);
|
|
|
|
}
|
|
|
|
|
2009-08-31 03:28:59 +08:00
|
|
|
parent = GIMP_LAYER
|
|
|
|
(gimp_item_stack_get_parent_by_path (GIMP_ITEM_STACK (layers),
|
|
|
|
item_path,
|
|
|
|
NULL));
|
|
|
|
|
|
|
|
container = gimp_viewable_get_children (GIMP_VIEWABLE (parent));
|
2012-02-07 21:06:12 +08:00
|
|
|
|
|
|
|
g_list_free (item_path);
|
2009-08-31 03:28:59 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
parent = NULL;
|
|
|
|
container = layers;
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_image_add_layer (image, layer,
|
|
|
|
parent,
|
|
|
|
gimp_container_get_n_children (container),
|
|
|
|
FALSE);
|
|
|
|
}
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
/* restore the saved position so we'll be ready to
|
|
|
|
* read the next offset.
|
|
|
|
*/
|
2002-12-20 14:26:34 +08:00
|
|
|
if (! xcf_seek_pos (info, saved_pos, NULL))
|
|
|
|
goto error;
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
2009-08-31 03:07:22 +08:00
|
|
|
GimpChannel *channel;
|
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
/* read in the offset of the next channel */
|
|
|
|
info->cp += xcf_read_int32 (info->fp, &offset, 1);
|
|
|
|
|
|
|
|
/* if the offset is 0 then we are at the end
|
|
|
|
* of the channel list.
|
|
|
|
*/
|
|
|
|
if (offset == 0)
|
2004-11-02 02:33:09 +08:00
|
|
|
break;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
/* save the current position as it is where the
|
|
|
|
* next channel offset is stored.
|
|
|
|
*/
|
|
|
|
saved_pos = info->cp;
|
|
|
|
|
|
|
|
/* seek to the channel offset */
|
2002-12-20 14:26:34 +08:00
|
|
|
if (! xcf_seek_pos (info, offset, NULL))
|
|
|
|
goto error;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2009-08-30 17:52:06 +08:00
|
|
|
/* read in the channel */
|
2006-03-29 01:08:36 +08:00
|
|
|
channel = xcf_load_channel (info, image);
|
2001-07-04 02:38:56 +08:00
|
|
|
if (!channel)
|
2004-11-02 02:33:09 +08:00
|
|
|
goto error;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
num_successful_elements++;
|
|
|
|
|
2006-07-12 04:21:18 +08:00
|
|
|
xcf_progress_update (info);
|
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
/* add the channel to the image if its not the selection */
|
2007-12-26 00:21:40 +08:00
|
|
|
if (channel != gimp_image_get_mask (image))
|
2006-11-22 18:19:53 +08:00
|
|
|
gimp_image_add_channel (image, channel,
|
2009-08-04 01:21:51 +08:00
|
|
|
NULL, /* FIXME tree */
|
2010-02-04 06:00:31 +08:00
|
|
|
gimp_container_get_n_children (gimp_image_get_channels (image)),
|
2008-10-10 03:40:41 +08:00
|
|
|
FALSE);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
/* restore the saved position so we'll be ready to
|
|
|
|
* read the next offset.
|
|
|
|
*/
|
2002-12-20 14:26:34 +08:00
|
|
|
if (! xcf_seek_pos (info, saved_pos, NULL))
|
|
|
|
goto error;
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
|
2009-09-04 01:11:02 +08:00
|
|
|
xcf_load_add_masks (image);
|
|
|
|
|
2004-01-26 23:34:47 +08:00
|
|
|
if (info->floating_sel && info->floating_sel_drawable)
|
|
|
|
floating_sel_attach (info->floating_sel, info->floating_sel_drawable);
|
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
if (info->active_layer)
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_set_active_layer (image, info->active_layer);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
if (info->active_channel)
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_set_active_channel (image, info->active_channel);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_set_filename (image, info->filename);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2003-12-06 23:53:26 +08:00
|
|
|
if (info->tattoo_state > 0)
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_set_tattoo_state (image, info->tattoo_state);
|
2003-12-06 23:53:26 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_undo_enable (image);
|
2005-08-05 22:13:10 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
return image;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
error:
|
|
|
|
if (num_successful_elements == 0)
|
|
|
|
goto hard_error;
|
|
|
|
|
2008-11-04 20:33:09 +08:00
|
|
|
gimp_message_literal (gimp, G_OBJECT (info->progress), GIMP_MESSAGE_WARNING,
|
|
|
|
_("This XCF file is corrupt! I have loaded as much "
|
|
|
|
"of it as I can, but it is incomplete."));
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2009-09-04 01:11:02 +08:00
|
|
|
xcf_load_add_masks (image);
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_undo_enable (image);
|
2005-08-05 22:13:10 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
return image;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2003-09-01 07:46:05 +08:00
|
|
|
hard_error:
|
2008-11-04 20:33:09 +08:00
|
|
|
g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
|
|
|
|
_("This XCF file is corrupt! I could not even "
|
|
|
|
"salvage any partial image data from it."));
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
g_object_unref (image);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-09-04 01:11:02 +08:00
|
|
|
static void
|
|
|
|
xcf_load_add_masks (GimpImage *image)
|
|
|
|
{
|
|
|
|
GList *layers;
|
|
|
|
GList *list;
|
|
|
|
|
|
|
|
layers = gimp_image_get_layer_list (image);
|
|
|
|
|
|
|
|
for (list = layers; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
GimpLayer *layer = list->data;
|
|
|
|
GimpLayerMask *mask;
|
|
|
|
|
|
|
|
mask = g_object_get_data (G_OBJECT (layer), "gimp-layer-mask");
|
|
|
|
|
|
|
|
if (mask)
|
|
|
|
{
|
2012-03-18 01:30:13 +08:00
|
|
|
gboolean apply_mask;
|
|
|
|
gboolean edit_mask;
|
|
|
|
gboolean show_mask;
|
|
|
|
|
|
|
|
apply_mask = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (layer),
|
|
|
|
"gimp-layer-mask-apply"));
|
|
|
|
edit_mask = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (layer),
|
|
|
|
"gimp-layer-mask-edit"));
|
|
|
|
show_mask = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (layer),
|
|
|
|
"gimp-layer-mask-show"));
|
|
|
|
|
2009-09-04 01:11:02 +08:00
|
|
|
gimp_layer_add_mask (layer, mask, FALSE, NULL);
|
|
|
|
|
2012-03-18 01:30:13 +08:00
|
|
|
gimp_layer_set_apply_mask (layer, apply_mask, FALSE);
|
|
|
|
gimp_layer_set_edit_mask (layer, edit_mask);
|
|
|
|
gimp_layer_set_show_mask (layer, show_mask, FALSE);
|
|
|
|
|
|
|
|
g_object_set_data (G_OBJECT (layer), "gimp-layer-mask", NULL);
|
|
|
|
g_object_set_data (G_OBJECT (layer), "gimp-layer-mask-apply", NULL);
|
|
|
|
g_object_set_data (G_OBJECT (layer), "gimp-layer-mask-edit", NULL);
|
|
|
|
g_object_set_data (G_OBJECT (layer), "gimp-layer-mask-show", NULL);
|
2009-09-04 01:11:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (layers);
|
|
|
|
}
|
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
static gboolean
|
|
|
|
xcf_load_image_props (XcfInfo *info,
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image)
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
|
|
|
PropType prop_type;
|
|
|
|
guint32 prop_size;
|
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
2007-07-05 23:12:43 +08:00
|
|
|
if (! xcf_load_prop (info, &prop_type, &prop_size))
|
2004-11-02 02:33:09 +08:00
|
|
|
return FALSE;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
switch (prop_type)
|
2004-11-02 02:33:09 +08:00
|
|
|
{
|
|
|
|
case PROP_END:
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
case PROP_COLORMAP:
|
2007-12-22 00:37:01 +08:00
|
|
|
{
|
|
|
|
guint32 n_colors;
|
|
|
|
guchar cmap[GIMP_IMAGE_COLORMAP_SIZE];
|
2004-11-02 02:33:09 +08:00
|
|
|
|
2007-12-22 00:37:01 +08:00
|
|
|
info->cp += xcf_read_int32 (info->fp, &n_colors, 1);
|
2004-11-02 02:33:09 +08:00
|
|
|
|
2010-10-16 06:52:11 +08:00
|
|
|
if (n_colors > (GIMP_IMAGE_COLORMAP_SIZE / 3))
|
|
|
|
{
|
|
|
|
gimp_message (info->gimp, G_OBJECT (info->progress),
|
|
|
|
GIMP_MESSAGE_ERROR,
|
|
|
|
"Maximum colormap size (%d) exceeded",
|
|
|
|
GIMP_IMAGE_COLORMAP_SIZE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-12-22 00:37:01 +08:00
|
|
|
if (info->file_version == 0)
|
|
|
|
{
|
|
|
|
gint i;
|
2004-11-02 02:33:09 +08:00
|
|
|
|
2008-11-04 20:33:09 +08:00
|
|
|
gimp_message_literal (info->gimp, G_OBJECT (info->progress),
|
|
|
|
GIMP_MESSAGE_WARNING,
|
|
|
|
_("XCF warning: version 0 of XCF file format\n"
|
|
|
|
"did not save indexed colormaps correctly.\n"
|
|
|
|
"Substituting grayscale map."));
|
2007-12-22 00:37:01 +08:00
|
|
|
|
|
|
|
if (! xcf_seek_pos (info, info->cp + n_colors, NULL))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (i = 0; i < n_colors; i++)
|
|
|
|
{
|
|
|
|
cmap[i * 3 + 0] = i;
|
|
|
|
cmap[i * 3 + 1] = i;
|
|
|
|
cmap[i * 3 + 2] = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
info->cp += xcf_read_int8 (info->fp, cmap, n_colors * 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* only set color map if image is not indexed, this is
|
|
|
|
* just sanity checking to make sure gimp doesn't end up
|
|
|
|
* with an image state that is impossible.
|
|
|
|
*/
|
2012-05-08 03:57:33 +08:00
|
|
|
if (gimp_image_get_base_type (image) == GIMP_INDEXED)
|
2007-12-22 00:37:01 +08:00
|
|
|
gimp_image_set_colormap (image, cmap, n_colors, FALSE);
|
|
|
|
}
|
2004-11-02 02:33:09 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_COMPRESSION:
|
|
|
|
{
|
|
|
|
guint8 compression;
|
|
|
|
|
|
|
|
info->cp += xcf_read_int8 (info->fp, (guint8 *) &compression, 1);
|
|
|
|
|
|
|
|
if ((compression != COMPRESS_NONE) &&
|
|
|
|
(compression != COMPRESS_RLE) &&
|
|
|
|
(compression != COMPRESS_ZLIB) &&
|
|
|
|
(compression != COMPRESS_FRACTAL))
|
|
|
|
{
|
2006-10-09 16:17:22 +08:00
|
|
|
gimp_message (info->gimp, G_OBJECT (info->progress),
|
|
|
|
GIMP_MESSAGE_ERROR,
|
2007-07-06 18:02:31 +08:00
|
|
|
"Unknown compression type: %d",
|
2008-11-04 20:33:09 +08:00
|
|
|
(gint) compression);
|
2004-11-02 02:33:09 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
info->compression = compression;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_GUIDES:
|
|
|
|
{
|
2010-02-04 05:16:02 +08:00
|
|
|
GimpImagePrivate *private = GIMP_IMAGE_GET_PRIVATE (image);
|
|
|
|
gint32 position;
|
|
|
|
gint8 orientation;
|
|
|
|
gint i, nguides;
|
2004-11-02 02:33:09 +08:00
|
|
|
|
|
|
|
nguides = prop_size / (4 + 1);
|
|
|
|
for (i = 0; i < nguides; i++)
|
|
|
|
{
|
2007-07-05 23:12:43 +08:00
|
|
|
info->cp += xcf_read_int32 (info->fp,
|
|
|
|
(guint32 *) &position, 1);
|
|
|
|
info->cp += xcf_read_int8 (info->fp,
|
|
|
|
(guint8 *) &orientation, 1);
|
2003-04-30 20:51:11 +08:00
|
|
|
|
|
|
|
/* skip -1 guides from old XCFs */
|
|
|
|
if (position < 0)
|
|
|
|
continue;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2004-11-02 02:33:09 +08:00
|
|
|
switch (orientation)
|
|
|
|
{
|
|
|
|
case XCF_ORIENTATION_HORIZONTAL:
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_add_hguide (image, position, FALSE);
|
2004-11-02 02:33:09 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case XCF_ORIENTATION_VERTICAL:
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_add_vguide (image, position, FALSE);
|
2004-11-02 02:33:09 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2008-11-04 20:33:09 +08:00
|
|
|
gimp_message_literal (info->gimp, G_OBJECT (info->progress),
|
|
|
|
GIMP_MESSAGE_WARNING,
|
|
|
|
"Guide orientation out of range in XCF file");
|
2004-11-02 02:33:09 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this is silly as the order of guides doesn't really matter,
|
2010-02-04 05:16:02 +08:00
|
|
|
* but it restores the list to its original order, which
|
2004-11-02 02:33:09 +08:00
|
|
|
* cannot be wrong --Mitch
|
|
|
|
*/
|
2010-02-04 05:16:02 +08:00
|
|
|
private->guides = g_list_reverse (private->guides);
|
2004-11-02 02:33:09 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-08-11 01:10:12 +08:00
|
|
|
case PROP_SAMPLE_POINTS:
|
|
|
|
{
|
|
|
|
gint32 x, y;
|
|
|
|
gint i, n_sample_points;
|
|
|
|
|
|
|
|
n_sample_points = prop_size / (4 + 4);
|
|
|
|
for (i = 0; i < n_sample_points; i++)
|
|
|
|
{
|
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) &x, 1);
|
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) &y, 1);
|
|
|
|
|
|
|
|
gimp_image_add_sample_point_at_pos (image, x, y, FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2004-11-02 02:33:09 +08:00
|
|
|
case PROP_RESOLUTION:
|
|
|
|
{
|
|
|
|
gfloat xres, yres;
|
|
|
|
|
|
|
|
info->cp += xcf_read_float (info->fp, &xres, 1);
|
|
|
|
info->cp += xcf_read_float (info->fp, &yres, 1);
|
2007-12-22 00:37:01 +08:00
|
|
|
|
2004-11-02 02:33:09 +08:00
|
|
|
if (xres < GIMP_MIN_RESOLUTION || xres > GIMP_MAX_RESOLUTION ||
|
|
|
|
yres < GIMP_MIN_RESOLUTION || yres > GIMP_MAX_RESOLUTION)
|
|
|
|
{
|
2011-03-02 17:16:43 +08:00
|
|
|
GimpTemplate *template = image->gimp->config->default_image;
|
|
|
|
|
2008-11-04 20:33:09 +08:00
|
|
|
gimp_message_literal (info->gimp, G_OBJECT (info->progress),
|
|
|
|
GIMP_MESSAGE_WARNING,
|
|
|
|
"Warning, resolution out of range in XCF file");
|
2011-03-02 17:16:43 +08:00
|
|
|
xres = gimp_template_get_resolution_x (template);
|
|
|
|
yres = gimp_template_get_resolution_y (template);
|
2004-11-02 02:33:09 +08:00
|
|
|
}
|
2007-12-22 00:37:01 +08:00
|
|
|
|
2007-12-27 01:33:41 +08:00
|
|
|
gimp_image_set_resolution (image, xres, yres);
|
2004-11-02 02:33:09 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_TATTOO:
|
|
|
|
{
|
|
|
|
info->cp += xcf_read_int32 (info->fp, &info->tattoo_state, 1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_PARASITES:
|
|
|
|
{
|
|
|
|
glong base = info->cp;
|
|
|
|
GimpParasite *p;
|
|
|
|
|
|
|
|
while (info->cp - base < prop_size)
|
|
|
|
{
|
|
|
|
p = xcf_load_parasite (info);
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_parasite_attach (image, p);
|
2004-11-02 02:33:09 +08:00
|
|
|
gimp_parasite_free (p);
|
|
|
|
}
|
2007-12-22 00:37:01 +08:00
|
|
|
|
2004-11-02 02:33:09 +08:00
|
|
|
if (info->cp - base != prop_size)
|
2008-11-04 20:33:09 +08:00
|
|
|
gimp_message_literal (info->gimp, G_OBJECT (info->progress),
|
|
|
|
GIMP_MESSAGE_WARNING,
|
|
|
|
"Error while loading an image's parasites");
|
2004-11-02 02:33:09 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_UNIT:
|
|
|
|
{
|
|
|
|
guint32 unit;
|
|
|
|
|
|
|
|
info->cp += xcf_read_int32 (info->fp, &unit, 1);
|
|
|
|
|
|
|
|
if ((unit <= GIMP_UNIT_PIXEL) ||
|
2010-02-21 23:46:39 +08:00
|
|
|
(unit >= gimp_unit_get_number_of_built_in_units ()))
|
2004-11-02 02:33:09 +08:00
|
|
|
{
|
2008-11-04 20:33:09 +08:00
|
|
|
gimp_message_literal (info->gimp, G_OBJECT (info->progress),
|
|
|
|
GIMP_MESSAGE_WARNING,
|
|
|
|
"Warning, unit out of range in XCF file, "
|
|
|
|
"falling back to inches");
|
2004-11-02 02:33:09 +08:00
|
|
|
unit = GIMP_UNIT_INCH;
|
|
|
|
}
|
2003-09-01 07:46:05 +08:00
|
|
|
|
2010-02-04 02:53:45 +08:00
|
|
|
gimp_image_set_unit (image, unit);
|
2004-11-02 02:33:09 +08:00
|
|
|
}
|
|
|
|
break;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2004-11-02 02:33:09 +08:00
|
|
|
case PROP_PATHS:
|
2006-03-29 01:08:36 +08:00
|
|
|
xcf_load_old_paths (info, image);
|
2004-11-02 02:33:09 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_USER_UNIT:
|
|
|
|
{
|
|
|
|
gchar *unit_strings[5];
|
|
|
|
float factor;
|
|
|
|
guint32 digits;
|
|
|
|
GimpUnit unit;
|
|
|
|
gint num_units;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
info->cp += xcf_read_float (info->fp, &factor, 1);
|
|
|
|
info->cp += xcf_read_int32 (info->fp, &digits, 1);
|
|
|
|
info->cp += xcf_read_string (info->fp, unit_strings, 5);
|
|
|
|
|
|
|
|
for (i = 0; i < 5; i++)
|
|
|
|
if (unit_strings[i] == NULL)
|
|
|
|
unit_strings[i] = g_strdup ("");
|
|
|
|
|
2010-02-21 23:46:39 +08:00
|
|
|
num_units = gimp_unit_get_number_of_units ();
|
2004-11-02 02:33:09 +08:00
|
|
|
|
2010-02-21 23:46:39 +08:00
|
|
|
for (unit = gimp_unit_get_number_of_built_in_units ();
|
2004-11-02 02:33:09 +08:00
|
|
|
unit < num_units; unit++)
|
|
|
|
{
|
|
|
|
/* if the factor and the identifier match some unit
|
|
|
|
* in unitrc, use the unitrc unit
|
|
|
|
*/
|
2010-02-21 23:46:39 +08:00
|
|
|
if ((ABS (gimp_unit_get_factor (unit) - factor) < 1e-5) &&
|
2004-11-02 02:33:09 +08:00
|
|
|
(strcmp (unit_strings[0],
|
2010-02-21 23:46:39 +08:00
|
|
|
gimp_unit_get_identifier (unit)) == 0))
|
2004-11-02 02:33:09 +08:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no match */
|
|
|
|
if (unit == num_units)
|
2010-02-21 23:46:39 +08:00
|
|
|
unit = gimp_unit_new (unit_strings[0],
|
|
|
|
factor,
|
|
|
|
digits,
|
|
|
|
unit_strings[1],
|
|
|
|
unit_strings[2],
|
|
|
|
unit_strings[3],
|
|
|
|
unit_strings[4]);
|
2004-11-02 02:33:09 +08:00
|
|
|
|
2010-02-04 02:53:45 +08:00
|
|
|
gimp_image_set_unit (image, unit);
|
2004-11-02 02:33:09 +08:00
|
|
|
|
|
|
|
for (i = 0; i < 5; i++)
|
|
|
|
g_free (unit_strings[i]);
|
|
|
|
}
|
|
|
|
break;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2003-09-09 23:46:59 +08:00
|
|
|
case PROP_VECTORS:
|
|
|
|
{
|
|
|
|
guint32 base = info->cp;
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
if (xcf_load_vectors (info, image))
|
2003-09-09 23:46:59 +08:00
|
|
|
{
|
|
|
|
if (base + prop_size != info->cp)
|
|
|
|
{
|
2006-07-11 00:40:26 +08:00
|
|
|
g_printerr ("Mismatch in PROP_VECTORS size: "
|
|
|
|
"skipping %d bytes.\n",
|
|
|
|
base + prop_size - info->cp);
|
2003-09-09 23:46:59 +08:00
|
|
|
xcf_seek_pos (info, base + prop_size, NULL);
|
|
|
|
}
|
2003-09-11 00:22:33 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-09-09 23:46:59 +08:00
|
|
|
/* skip silently since we don't understand the format and
|
2003-09-11 00:22:33 +08:00
|
|
|
* xcf_load_vectors already explained what was wrong
|
|
|
|
*/
|
2003-09-09 23:46:59 +08:00
|
|
|
xcf_seek_pos (info, base + prop_size, NULL);
|
|
|
|
}
|
|
|
|
}
|
2004-11-02 02:33:09 +08:00
|
|
|
break;
|
2003-09-09 23:46:59 +08:00
|
|
|
|
2004-11-02 02:33:09 +08:00
|
|
|
default:
|
2004-03-18 23:27:23 +08:00
|
|
|
#ifdef GIMP_UNSTABLE
|
2006-07-11 00:40:26 +08:00
|
|
|
g_printerr ("unexpected/unknown image property: %d (skipping)\n",
|
2004-03-18 23:27:23 +08:00
|
|
|
prop_type);
|
|
|
|
#endif
|
2010-08-07 06:26:58 +08:00
|
|
|
if (! xcf_skip_unknown_prop (info, prop_size))
|
|
|
|
return FALSE;
|
2004-11-02 02:33:09 +08:00
|
|
|
break;
|
|
|
|
}
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2009-08-30 19:14:28 +08:00
|
|
|
xcf_load_layer_props (XcfInfo *info,
|
|
|
|
GimpImage *image,
|
|
|
|
GimpLayer **layer,
|
2009-08-31 03:28:59 +08:00
|
|
|
GList **item_path,
|
2009-08-30 19:14:28 +08:00
|
|
|
gboolean *apply_mask,
|
|
|
|
gboolean *edit_mask,
|
|
|
|
gboolean *show_mask,
|
2011-09-26 03:57:20 +08:00
|
|
|
guint32 *text_layer_flags,
|
|
|
|
guint32 *group_layer_flags)
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
|
|
|
PropType prop_type;
|
|
|
|
guint32 prop_size;
|
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
2007-07-05 23:12:43 +08:00
|
|
|
if (! xcf_load_prop (info, &prop_type, &prop_size))
|
2004-11-02 02:33:09 +08:00
|
|
|
return FALSE;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
switch (prop_type)
|
2004-11-02 02:33:09 +08:00
|
|
|
{
|
|
|
|
case PROP_END:
|
|
|
|
return TRUE;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2004-11-02 02:33:09 +08:00
|
|
|
case PROP_ACTIVE_LAYER:
|
2009-08-30 19:14:28 +08:00
|
|
|
info->active_layer = *layer;
|
2004-11-02 02:33:09 +08:00
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2004-11-02 02:33:09 +08:00
|
|
|
case PROP_FLOATING_SELECTION:
|
2009-08-30 19:14:28 +08:00
|
|
|
info->floating_sel = *layer;
|
2004-11-02 02:33:09 +08:00
|
|
|
info->cp +=
|
2003-09-01 07:46:05 +08:00
|
|
|
xcf_read_int32 (info->fp,
|
2003-04-10 22:37:06 +08:00
|
|
|
(guint32 *) &info->floating_sel_offset, 1);
|
2004-11-02 02:33:09 +08:00
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2004-11-02 02:33:09 +08:00
|
|
|
case PROP_OPACITY:
|
2002-03-04 22:52:54 +08:00
|
|
|
{
|
|
|
|
guint32 opacity;
|
|
|
|
|
|
|
|
info->cp += xcf_read_int32 (info->fp, &opacity, 1);
|
2009-08-30 19:14:28 +08:00
|
|
|
gimp_layer_set_opacity (*layer, (gdouble) opacity / 255.0, FALSE);
|
2002-03-04 22:52:54 +08:00
|
|
|
}
|
2004-11-02 02:33:09 +08:00
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2004-11-02 02:33:09 +08:00
|
|
|
case PROP_VISIBLE:
|
|
|
|
{
|
|
|
|
gboolean visible;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2004-11-02 02:33:09 +08:00
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) &visible, 1);
|
2009-08-30 19:14:28 +08:00
|
|
|
gimp_item_set_visible (GIMP_ITEM (*layer), visible, FALSE);
|
2004-11-02 02:33:09 +08:00
|
|
|
}
|
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2004-11-02 02:33:09 +08:00
|
|
|
case PROP_LINKED:
|
2003-05-09 04:26:01 +08:00
|
|
|
{
|
|
|
|
gboolean linked;
|
|
|
|
|
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) &linked, 1);
|
2009-08-30 19:14:28 +08:00
|
|
|
gimp_item_set_linked (GIMP_ITEM (*layer), linked, FALSE);
|
2003-05-09 04:26:01 +08:00
|
|
|
}
|
2004-11-02 02:33:09 +08:00
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2009-08-30 18:44:35 +08:00
|
|
|
case PROP_LOCK_CONTENT:
|
|
|
|
{
|
|
|
|
gboolean lock_content;
|
|
|
|
|
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) &lock_content, 1);
|
2009-08-31 03:02:43 +08:00
|
|
|
|
|
|
|
if (gimp_item_can_lock_content (GIMP_ITEM (*layer)))
|
|
|
|
gimp_item_set_lock_content (GIMP_ITEM (*layer),
|
|
|
|
lock_content, FALSE);
|
2009-08-30 18:44:35 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-07-11 05:17:22 +08:00
|
|
|
case PROP_LOCK_ALPHA:
|
2007-12-19 03:12:43 +08:00
|
|
|
{
|
|
|
|
gboolean lock_alpha;
|
|
|
|
|
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) &lock_alpha, 1);
|
2009-08-31 03:02:43 +08:00
|
|
|
|
|
|
|
if (gimp_layer_can_lock_alpha (*layer))
|
|
|
|
gimp_layer_set_lock_alpha (*layer, lock_alpha, FALSE);
|
2007-12-19 03:12:43 +08:00
|
|
|
}
|
2004-11-02 02:33:09 +08:00
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2004-11-02 02:33:09 +08:00
|
|
|
case PROP_APPLY_MASK:
|
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) apply_mask, 1);
|
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2004-11-02 02:33:09 +08:00
|
|
|
case PROP_EDIT_MASK:
|
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) edit_mask, 1);
|
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2004-11-02 02:33:09 +08:00
|
|
|
case PROP_SHOW_MASK:
|
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) show_mask, 1);
|
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2004-11-02 02:33:09 +08:00
|
|
|
case PROP_OFFSETS:
|
2008-11-04 05:17:50 +08:00
|
|
|
{
|
|
|
|
guint32 offset_x;
|
|
|
|
guint32 offset_y;
|
|
|
|
|
|
|
|
info->cp += xcf_read_int32 (info->fp, &offset_x, 1);
|
|
|
|
info->cp += xcf_read_int32 (info->fp, &offset_y, 1);
|
|
|
|
|
2009-08-30 19:14:28 +08:00
|
|
|
gimp_item_set_offset (GIMP_ITEM (*layer), offset_x, offset_y);
|
2008-11-04 05:17:50 +08:00
|
|
|
}
|
2004-11-02 02:33:09 +08:00
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2004-11-02 02:33:09 +08:00
|
|
|
case PROP_MODE:
|
2007-12-19 03:12:43 +08:00
|
|
|
{
|
|
|
|
guint32 mode;
|
|
|
|
|
|
|
|
info->cp += xcf_read_int32 (info->fp, &mode, 1);
|
2009-08-30 19:14:28 +08:00
|
|
|
gimp_layer_set_mode (*layer, (GimpLayerModeEffects) mode, FALSE);
|
2007-12-19 03:12:43 +08:00
|
|
|
}
|
2004-11-02 02:33:09 +08:00
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2004-11-02 02:33:09 +08:00
|
|
|
case PROP_TATTOO:
|
2007-12-19 03:12:43 +08:00
|
|
|
{
|
|
|
|
GimpTattoo tattoo;
|
|
|
|
|
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) &tattoo, 1);
|
2009-08-30 19:14:28 +08:00
|
|
|
gimp_item_set_tattoo (GIMP_ITEM (*layer), tattoo);
|
2007-12-19 03:12:43 +08:00
|
|
|
}
|
2004-11-02 02:33:09 +08:00
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
|
|
|
case PROP_PARASITES:
|
|
|
|
{
|
|
|
|
glong base = info->cp;
|
|
|
|
GimpParasite *p;
|
|
|
|
|
|
|
|
while (info->cp - base < prop_size)
|
|
|
|
{
|
|
|
|
p = xcf_load_parasite (info);
|
2011-01-31 03:40:43 +08:00
|
|
|
gimp_item_parasite_attach (GIMP_ITEM (*layer), p, FALSE);
|
2004-03-18 23:27:23 +08:00
|
|
|
gimp_parasite_free (p);
|
|
|
|
}
|
2007-07-05 23:12:43 +08:00
|
|
|
|
2004-03-18 23:27:23 +08:00
|
|
|
if (info->cp - base != prop_size)
|
2008-11-04 20:33:09 +08:00
|
|
|
gimp_message_literal (info->gimp, G_OBJECT (info->progress),
|
|
|
|
GIMP_MESSAGE_WARNING,
|
|
|
|
"Error while loading a layer's parasites");
|
2004-03-18 23:27:23 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_TEXT_LAYER_FLAGS:
|
|
|
|
info->cp += xcf_read_int32 (info->fp, text_layer_flags, 1);
|
|
|
|
break;
|
|
|
|
|
2009-08-31 03:28:59 +08:00
|
|
|
case PROP_GROUP_ITEM:
|
|
|
|
{
|
|
|
|
GimpLayer *group;
|
|
|
|
|
|
|
|
group = gimp_group_layer_new (image);
|
|
|
|
|
|
|
|
gimp_object_set_name (GIMP_OBJECT (group),
|
|
|
|
gimp_object_get_name (*layer));
|
|
|
|
|
|
|
|
g_object_ref_sink (*layer);
|
|
|
|
g_object_unref (*layer);
|
|
|
|
*layer = group;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_ITEM_PATH:
|
|
|
|
{
|
|
|
|
glong base = info->cp;
|
|
|
|
GList *path = NULL;
|
|
|
|
|
|
|
|
while (info->cp - base < prop_size)
|
|
|
|
{
|
|
|
|
guint32 index;
|
|
|
|
|
|
|
|
info->cp += xcf_read_int32 (info->fp, &index, 1);
|
|
|
|
|
|
|
|
path = g_list_append (path, GUINT_TO_POINTER (index));
|
|
|
|
}
|
|
|
|
|
|
|
|
*item_path = path;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-09-26 03:57:20 +08:00
|
|
|
case PROP_GROUP_ITEM_FLAGS:
|
|
|
|
info->cp += xcf_read_int32 (info->fp, group_layer_flags, 1);
|
|
|
|
break;
|
|
|
|
|
2004-11-02 02:33:09 +08:00
|
|
|
default:
|
2006-07-11 00:40:26 +08:00
|
|
|
#ifdef GIMP_UNSTABLE
|
|
|
|
g_printerr ("unexpected/unknown layer property: %d (skipping)\n",
|
|
|
|
prop_type);
|
|
|
|
#endif
|
2010-08-07 06:26:58 +08:00
|
|
|
if (! xcf_skip_unknown_prop (info, prop_size))
|
|
|
|
return FALSE;
|
2004-11-02 02:33:09 +08:00
|
|
|
break;
|
|
|
|
}
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2003-09-03 07:07:40 +08:00
|
|
|
xcf_load_channel_props (XcfInfo *info,
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image,
|
2004-11-02 02:33:09 +08:00
|
|
|
GimpChannel **channel)
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
|
|
|
PropType prop_type;
|
|
|
|
guint32 prop_size;
|
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
2007-07-05 23:12:43 +08:00
|
|
|
if (! xcf_load_prop (info, &prop_type, &prop_size))
|
2004-11-02 02:33:09 +08:00
|
|
|
return FALSE;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
switch (prop_type)
|
2004-11-02 02:33:09 +08:00
|
|
|
{
|
|
|
|
case PROP_END:
|
|
|
|
return TRUE;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2004-11-02 02:33:09 +08:00
|
|
|
case PROP_ACTIVE_CHANNEL:
|
|
|
|
info->active_channel = *channel;
|
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2004-11-02 02:33:09 +08:00
|
|
|
case PROP_SELECTION:
|
2007-12-26 00:21:40 +08:00
|
|
|
{
|
2012-05-14 07:44:41 +08:00
|
|
|
GimpChannel *mask;
|
2007-12-26 00:21:40 +08:00
|
|
|
|
2012-05-14 07:44:41 +08:00
|
|
|
mask =
|
2007-12-26 00:21:40 +08:00
|
|
|
gimp_selection_new (image,
|
2008-11-03 08:09:01 +08:00
|
|
|
gimp_item_get_width (GIMP_ITEM (*channel)),
|
|
|
|
gimp_item_get_height (GIMP_ITEM (*channel)));
|
2012-05-14 07:44:41 +08:00
|
|
|
gimp_image_take_mask (image, mask);
|
2007-12-26 00:21:40 +08:00
|
|
|
|
2012-03-22 04:26:05 +08:00
|
|
|
g_object_unref (GIMP_DRAWABLE (mask)->private->buffer);
|
|
|
|
GIMP_DRAWABLE (mask)->private->buffer =
|
|
|
|
GIMP_DRAWABLE (*channel)->private->buffer;
|
|
|
|
GIMP_DRAWABLE (*channel)->private->buffer = NULL;
|
2007-12-26 00:21:40 +08:00
|
|
|
g_object_unref (*channel);
|
|
|
|
*channel = mask;
|
|
|
|
(*channel)->boundary_known = FALSE;
|
|
|
|
(*channel)->bounds_known = FALSE;
|
|
|
|
}
|
2004-11-02 02:33:09 +08:00
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2004-11-02 02:33:09 +08:00
|
|
|
case PROP_OPACITY:
|
|
|
|
{
|
|
|
|
guint32 opacity;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2004-11-02 02:33:09 +08:00
|
|
|
info->cp += xcf_read_int32 (info->fp, &opacity, 1);
|
2007-12-19 03:12:43 +08:00
|
|
|
gimp_channel_set_opacity (*channel, opacity / 255.0, FALSE);
|
2004-11-02 02:33:09 +08:00
|
|
|
}
|
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2004-11-02 02:33:09 +08:00
|
|
|
case PROP_VISIBLE:
|
|
|
|
{
|
|
|
|
gboolean visible;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2004-11-02 02:33:09 +08:00
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) &visible, 1);
|
|
|
|
gimp_item_set_visible (GIMP_ITEM (*channel),
|
2003-09-12 03:52:29 +08:00
|
|
|
visible ? TRUE : FALSE, FALSE);
|
2004-11-02 02:33:09 +08:00
|
|
|
}
|
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2004-11-02 02:33:09 +08:00
|
|
|
case PROP_LINKED:
|
2003-05-14 02:30:15 +08:00
|
|
|
{
|
|
|
|
gboolean linked;
|
|
|
|
|
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) &linked, 1);
|
2003-09-03 07:07:40 +08:00
|
|
|
gimp_item_set_linked (GIMP_ITEM (*channel),
|
2003-05-14 02:30:15 +08:00
|
|
|
linked ? TRUE : FALSE, FALSE);
|
|
|
|
}
|
2004-11-02 02:33:09 +08:00
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2009-08-30 18:44:35 +08:00
|
|
|
case PROP_LOCK_CONTENT:
|
|
|
|
{
|
|
|
|
gboolean lock_content;
|
|
|
|
|
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) &lock_content, 1);
|
|
|
|
gimp_item_set_lock_content (GIMP_ITEM (*channel),
|
|
|
|
lock_content ? TRUE : FALSE, FALSE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2004-11-02 02:33:09 +08:00
|
|
|
case PROP_SHOW_MASKED:
|
2003-09-03 07:07:40 +08:00
|
|
|
{
|
|
|
|
gboolean show_masked;
|
|
|
|
|
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) &show_masked, 1);
|
|
|
|
gimp_channel_set_show_masked (*channel, show_masked);
|
|
|
|
}
|
2004-11-02 02:33:09 +08:00
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2004-11-02 02:33:09 +08:00
|
|
|
case PROP_COLOR:
|
|
|
|
{
|
|
|
|
guchar col[3];
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2004-11-02 02:33:09 +08:00
|
|
|
info->cp += xcf_read_int8 (info->fp, (guint8 *) col, 3);
|
|
|
|
gimp_rgb_set_uchar (&(*channel)->color, col[0], col[1], col[2]);
|
|
|
|
}
|
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2004-11-02 02:33:09 +08:00
|
|
|
case PROP_TATTOO:
|
2007-12-19 03:12:43 +08:00
|
|
|
{
|
|
|
|
GimpTattoo tattoo;
|
|
|
|
|
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) &tattoo, 1);
|
|
|
|
gimp_item_set_tattoo (GIMP_ITEM (*channel), tattoo);
|
|
|
|
}
|
2004-11-02 02:33:09 +08:00
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
|
|
|
case PROP_PARASITES:
|
|
|
|
{
|
|
|
|
glong base = info->cp;
|
|
|
|
GimpParasite *p;
|
|
|
|
|
|
|
|
while ((info->cp - base) < prop_size)
|
|
|
|
{
|
|
|
|
p = xcf_load_parasite (info);
|
2011-01-31 03:40:43 +08:00
|
|
|
gimp_item_parasite_attach (GIMP_ITEM (*channel), p, FALSE);
|
2004-03-18 23:27:23 +08:00
|
|
|
gimp_parasite_free (p);
|
|
|
|
}
|
2007-07-05 23:12:43 +08:00
|
|
|
|
2004-03-18 23:27:23 +08:00
|
|
|
if (info->cp - base != prop_size)
|
2008-11-04 20:33:09 +08:00
|
|
|
gimp_message_literal (info->gimp, G_OBJECT (info->progress),
|
|
|
|
GIMP_MESSAGE_WARNING,
|
|
|
|
"Error while loading a channel's parasites");
|
2004-03-18 23:27:23 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2004-11-02 02:33:09 +08:00
|
|
|
default:
|
2004-03-18 23:27:23 +08:00
|
|
|
#ifdef GIMP_UNSTABLE
|
2006-07-11 00:40:26 +08:00
|
|
|
g_printerr ("unexpected/unknown channel property: %d (skipping)\n",
|
2004-03-18 23:27:23 +08:00
|
|
|
prop_type);
|
|
|
|
#endif
|
2010-08-07 06:26:58 +08:00
|
|
|
if (! xcf_skip_unknown_prop (info, prop_size))
|
|
|
|
return FALSE;
|
2004-11-02 02:33:09 +08:00
|
|
|
break;
|
|
|
|
}
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
xcf_load_prop (XcfInfo *info,
|
2004-11-02 02:33:09 +08:00
|
|
|
PropType *prop_type,
|
|
|
|
guint32 *prop_size)
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
2007-07-05 23:12:43 +08:00
|
|
|
if (G_UNLIKELY (xcf_read_int32 (info->fp, (guint32 *) prop_type, 1) != 4))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
info->cp += 4;
|
|
|
|
|
|
|
|
if (G_UNLIKELY (xcf_read_int32 (info->fp, (guint32 *) prop_size, 1) != 4))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
info->cp += 4;
|
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GimpLayer *
|
2009-08-31 03:28:59 +08:00
|
|
|
xcf_load_layer (XcfInfo *info,
|
|
|
|
GimpImage *image,
|
|
|
|
GList **item_path)
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
2012-05-11 20:22:50 +08:00
|
|
|
GimpLayer *layer;
|
|
|
|
GimpLayerMask *layer_mask;
|
|
|
|
guint32 hierarchy_offset;
|
|
|
|
guint32 layer_mask_offset;
|
|
|
|
gboolean apply_mask = TRUE;
|
|
|
|
gboolean edit_mask = FALSE;
|
|
|
|
gboolean show_mask = FALSE;
|
|
|
|
gboolean active;
|
|
|
|
gboolean floating;
|
|
|
|
guint32 group_layer_flags = 0;
|
|
|
|
guint32 text_layer_flags = 0;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gint type;
|
|
|
|
GimpImageBaseType base_type;
|
|
|
|
gboolean has_alpha;
|
|
|
|
const Babl *format;
|
|
|
|
gboolean is_fs_drawable;
|
|
|
|
gchar *name;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
/* check and see if this is the drawable the floating selection
|
2004-01-26 23:34:47 +08:00
|
|
|
* is attached to. if it is then we'll do the attachment in our caller.
|
2001-07-04 02:38:56 +08:00
|
|
|
*/
|
2004-01-26 23:34:47 +08:00
|
|
|
is_fs_drawable = (info->cp == info->floating_sel_offset);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
/* read in the layer width, height, type and name */
|
2003-04-10 22:37:06 +08:00
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) &width, 1);
|
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) &height, 1);
|
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) &type, 1);
|
2001-07-04 02:38:56 +08:00
|
|
|
info->cp += xcf_read_string (info->fp, &name, 1);
|
|
|
|
|
2012-05-11 20:22:50 +08:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case GIMP_RGB_IMAGE:
|
|
|
|
base_type = GIMP_RGB;
|
|
|
|
has_alpha = FALSE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_RGBA_IMAGE:
|
|
|
|
base_type = GIMP_RGB;
|
|
|
|
has_alpha = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_GRAY_IMAGE:
|
|
|
|
base_type = GIMP_GRAY;
|
|
|
|
has_alpha = FALSE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_GRAYA_IMAGE:
|
|
|
|
base_type = GIMP_GRAY;
|
|
|
|
has_alpha = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_INDEXED_IMAGE:
|
|
|
|
base_type = GIMP_INDEXED;
|
|
|
|
has_alpha = FALSE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_INDEXEDA_IMAGE:
|
|
|
|
base_type = GIMP_INDEXED;
|
|
|
|
has_alpha = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* do not use gimp_image_get_layer_format() because it might
|
|
|
|
* be the floating selection of a channel or mask
|
|
|
|
*/
|
|
|
|
format = gimp_image_get_format (image, base_type,
|
|
|
|
gimp_image_get_precision (image),
|
|
|
|
has_alpha);
|
2012-04-12 00:40:30 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
/* create a new layer */
|
2006-03-29 01:08:36 +08:00
|
|
|
layer = gimp_layer_new (image, width, height,
|
2012-05-11 20:22:50 +08:00
|
|
|
format, name, 255, GIMP_NORMAL_MODE);
|
2001-07-04 02:38:56 +08:00
|
|
|
g_free (name);
|
2003-06-24 21:59:36 +08:00
|
|
|
if (! layer)
|
2001-07-04 02:38:56 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* read in the layer properties */
|
2009-08-31 03:28:59 +08:00
|
|
|
if (! xcf_load_layer_props (info, image, &layer, item_path,
|
2004-03-18 23:27:23 +08:00
|
|
|
&apply_mask, &edit_mask, &show_mask,
|
2011-09-26 03:57:20 +08:00
|
|
|
&text_layer_flags, &group_layer_flags))
|
2001-07-04 02:38:56 +08:00
|
|
|
goto error;
|
|
|
|
|
2006-07-12 04:21:18 +08:00
|
|
|
xcf_progress_update (info);
|
|
|
|
|
2003-10-28 05:50:41 +08:00
|
|
|
/* call the evil text layer hack that might change our layer pointer */
|
|
|
|
active = (info->active_layer == layer);
|
|
|
|
floating = (info->floating_sel == layer);
|
2003-06-24 21:59:36 +08:00
|
|
|
|
2003-10-28 05:50:41 +08:00
|
|
|
if (gimp_text_layer_xcf_load_hack (&layer))
|
2003-06-25 03:45:55 +08:00
|
|
|
{
|
2004-03-18 23:27:23 +08:00
|
|
|
gimp_text_layer_set_xcf_flags (GIMP_TEXT_LAYER (layer),
|
|
|
|
text_layer_flags);
|
|
|
|
|
2003-07-08 18:38:13 +08:00
|
|
|
if (active)
|
2003-09-01 07:46:05 +08:00
|
|
|
info->active_layer = layer;
|
2003-07-08 18:38:13 +08:00
|
|
|
if (floating)
|
|
|
|
info->floating_sel = layer;
|
2003-06-25 03:45:55 +08:00
|
|
|
}
|
2003-06-24 21:59:36 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
/* read the hierarchy and layer mask offsets */
|
|
|
|
info->cp += xcf_read_int32 (info->fp, &hierarchy_offset, 1);
|
|
|
|
info->cp += xcf_read_int32 (info->fp, &layer_mask_offset, 1);
|
|
|
|
|
2009-08-31 03:28:59 +08:00
|
|
|
/* read in the hierarchy (ignore it for group layers, both as an
|
|
|
|
* optimization and because the hierarchy's extents don't match
|
|
|
|
* the group layer's tiles)
|
|
|
|
*/
|
|
|
|
if (! gimp_viewable_get_children (GIMP_VIEWABLE (layer)))
|
|
|
|
{
|
|
|
|
if (! xcf_seek_pos (info, hierarchy_offset, NULL))
|
|
|
|
goto error;
|
2002-12-20 14:26:34 +08:00
|
|
|
|
2012-04-03 05:32:38 +08:00
|
|
|
if (! xcf_load_buffer (info,
|
|
|
|
gimp_drawable_get_buffer (GIMP_DRAWABLE (layer))))
|
2009-08-31 03:28:59 +08:00
|
|
|
goto error;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2009-08-31 03:28:59 +08:00
|
|
|
xcf_progress_update (info);
|
|
|
|
}
|
2011-09-26 03:57:20 +08:00
|
|
|
else
|
|
|
|
{
|
2011-10-08 02:05:52 +08:00
|
|
|
gboolean expanded = group_layer_flags & XCF_GROUP_ITEM_EXPANDED;
|
|
|
|
|
|
|
|
gimp_viewable_set_expanded (GIMP_VIEWABLE (layer), expanded);
|
2011-09-26 03:57:20 +08:00
|
|
|
}
|
2006-07-12 04:21:18 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
/* read in the layer mask */
|
|
|
|
if (layer_mask_offset != 0)
|
|
|
|
{
|
2002-12-20 14:26:34 +08:00
|
|
|
if (! xcf_seek_pos (info, layer_mask_offset, NULL))
|
|
|
|
goto error;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
layer_mask = xcf_load_layer_mask (info, image);
|
2003-06-24 21:59:36 +08:00
|
|
|
if (! layer_mask)
|
2004-11-02 02:33:09 +08:00
|
|
|
goto error;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2006-07-12 04:21:18 +08:00
|
|
|
xcf_progress_update (info);
|
|
|
|
|
2009-09-04 01:11:02 +08:00
|
|
|
/* don't add the layer mask yet, that won't work for group
|
|
|
|
* layers which update their size automatically; instead
|
|
|
|
* attach it so it can be added when all layers are loaded
|
|
|
|
*/
|
|
|
|
g_object_set_data_full (G_OBJECT (layer), "gimp-layer-mask",
|
2011-03-03 17:57:38 +08:00
|
|
|
g_object_ref_sink (layer_mask),
|
2009-09-04 01:11:02 +08:00
|
|
|
(GDestroyNotify) g_object_unref);
|
2012-03-18 01:30:13 +08:00
|
|
|
g_object_set_data (G_OBJECT (layer), "gimp-layer-mask-apply",
|
|
|
|
GINT_TO_POINTER (apply_mask));
|
|
|
|
g_object_set_data (G_OBJECT (layer), "gimp-layer-mask-edit",
|
|
|
|
GINT_TO_POINTER (edit_mask));
|
|
|
|
g_object_set_data (G_OBJECT (layer), "gimp-layer-mask-show",
|
|
|
|
GINT_TO_POINTER (show_mask));
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* attach the floating selection... */
|
2004-01-26 23:34:47 +08:00
|
|
|
if (is_fs_drawable)
|
|
|
|
info->floating_sel_drawable = GIMP_DRAWABLE (layer);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
return layer;
|
|
|
|
|
|
|
|
error:
|
2003-01-06 06:07:10 +08:00
|
|
|
g_object_unref (layer);
|
2001-07-04 02:38:56 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GimpChannel *
|
|
|
|
xcf_load_channel (XcfInfo *info,
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image)
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
|
|
|
GimpChannel *channel;
|
|
|
|
guint32 hierarchy_offset;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
2004-01-26 23:34:47 +08:00
|
|
|
gboolean is_fs_drawable;
|
2001-07-04 02:38:56 +08:00
|
|
|
gchar *name;
|
2002-03-04 01:38:12 +08:00
|
|
|
GimpRGB color = { 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE };
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
/* check and see if this is the drawable the floating selection
|
2004-01-26 23:34:47 +08:00
|
|
|
* is attached to. if it is then we'll do the attachment in our caller.
|
2001-07-04 02:38:56 +08:00
|
|
|
*/
|
2004-01-26 23:34:47 +08:00
|
|
|
is_fs_drawable = (info->cp == info->floating_sel_offset);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
/* read in the layer width, height and name */
|
2003-04-10 22:37:06 +08:00
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) &width, 1);
|
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) &height, 1);
|
2001-07-04 02:38:56 +08:00
|
|
|
info->cp += xcf_read_string (info->fp, &name, 1);
|
|
|
|
|
|
|
|
/* create a new channel */
|
2006-03-29 01:08:36 +08:00
|
|
|
channel = gimp_channel_new (image, width, height, name, &color);
|
2001-07-04 02:38:56 +08:00
|
|
|
g_free (name);
|
|
|
|
if (!channel)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* read in the channel properties */
|
2006-03-29 01:08:36 +08:00
|
|
|
if (!xcf_load_channel_props (info, image, &channel))
|
2001-07-04 02:38:56 +08:00
|
|
|
goto error;
|
|
|
|
|
2006-07-12 04:21:18 +08:00
|
|
|
xcf_progress_update (info);
|
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
/* read the hierarchy and layer mask offsets */
|
|
|
|
info->cp += xcf_read_int32 (info->fp, &hierarchy_offset, 1);
|
|
|
|
|
|
|
|
/* read in the hierarchy */
|
2002-12-20 14:26:34 +08:00
|
|
|
if (!xcf_seek_pos (info, hierarchy_offset, NULL))
|
|
|
|
goto error;
|
2003-09-01 07:46:05 +08:00
|
|
|
|
2012-04-03 05:32:38 +08:00
|
|
|
if (!xcf_load_buffer (info,
|
|
|
|
gimp_drawable_get_buffer (GIMP_DRAWABLE (channel))))
|
2001-07-04 02:38:56 +08:00
|
|
|
goto error;
|
|
|
|
|
2006-07-12 04:21:18 +08:00
|
|
|
xcf_progress_update (info);
|
|
|
|
|
2004-01-26 23:34:47 +08:00
|
|
|
if (is_fs_drawable)
|
|
|
|
info->floating_sel_drawable = GIMP_DRAWABLE (channel);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
return channel;
|
|
|
|
|
2003-04-10 22:15:24 +08:00
|
|
|
error:
|
2003-01-06 06:07:10 +08:00
|
|
|
g_object_unref (channel);
|
2001-07-04 02:38:56 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GimpLayerMask *
|
|
|
|
xcf_load_layer_mask (XcfInfo *info,
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image)
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
|
|
|
GimpLayerMask *layer_mask;
|
2004-01-26 17:22:06 +08:00
|
|
|
GimpChannel *channel;
|
2001-07-04 02:38:56 +08:00
|
|
|
guint32 hierarchy_offset;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
2004-01-26 23:34:47 +08:00
|
|
|
gboolean is_fs_drawable;
|
2001-07-04 02:38:56 +08:00
|
|
|
gchar *name;
|
2002-03-04 01:38:12 +08:00
|
|
|
GimpRGB color = { 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE };
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
/* check and see if this is the drawable the floating selection
|
2004-01-26 23:34:47 +08:00
|
|
|
* is attached to. if it is then we'll do the attachment in our caller.
|
2001-07-04 02:38:56 +08:00
|
|
|
*/
|
2004-01-26 23:34:47 +08:00
|
|
|
is_fs_drawable = (info->cp == info->floating_sel_offset);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
/* read in the layer width, height and name */
|
2003-04-10 22:37:06 +08:00
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) &width, 1);
|
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) &height, 1);
|
2001-07-04 02:38:56 +08:00
|
|
|
info->cp += xcf_read_string (info->fp, &name, 1);
|
|
|
|
|
|
|
|
/* create a new layer mask */
|
2006-03-29 01:08:36 +08:00
|
|
|
layer_mask = gimp_layer_mask_new (image, width, height, name, &color);
|
2001-07-04 02:38:56 +08:00
|
|
|
g_free (name);
|
|
|
|
if (!layer_mask)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* read in the layer_mask properties */
|
2004-01-26 17:22:06 +08:00
|
|
|
channel = GIMP_CHANNEL (layer_mask);
|
2006-03-29 01:08:36 +08:00
|
|
|
if (!xcf_load_channel_props (info, image, &channel))
|
2001-07-04 02:38:56 +08:00
|
|
|
goto error;
|
|
|
|
|
2006-07-12 04:21:18 +08:00
|
|
|
xcf_progress_update (info);
|
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
/* read the hierarchy and layer mask offsets */
|
|
|
|
info->cp += xcf_read_int32 (info->fp, &hierarchy_offset, 1);
|
|
|
|
|
|
|
|
/* read in the hierarchy */
|
2002-12-20 14:26:34 +08:00
|
|
|
if (! xcf_seek_pos (info, hierarchy_offset, NULL))
|
|
|
|
goto error;
|
|
|
|
|
2012-04-03 05:32:38 +08:00
|
|
|
if (!xcf_load_buffer (info,
|
|
|
|
gimp_drawable_get_buffer (GIMP_DRAWABLE (layer_mask))))
|
2001-07-04 02:38:56 +08:00
|
|
|
goto error;
|
|
|
|
|
2006-07-12 04:21:18 +08:00
|
|
|
xcf_progress_update (info);
|
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
/* attach the floating selection... */
|
2004-01-26 23:34:47 +08:00
|
|
|
if (is_fs_drawable)
|
|
|
|
info->floating_sel_drawable = GIMP_DRAWABLE (layer_mask);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
return layer_mask;
|
|
|
|
|
2003-04-10 22:15:24 +08:00
|
|
|
error:
|
2003-01-06 06:07:10 +08:00
|
|
|
g_object_unref (layer_mask);
|
2001-07-04 02:38:56 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-04-03 05:32:38 +08:00
|
|
|
xcf_load_buffer (XcfInfo *info,
|
|
|
|
GeglBuffer *buffer)
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
2012-04-03 05:32:38 +08:00
|
|
|
const Babl *format;
|
|
|
|
guint32 saved_pos;
|
|
|
|
guint32 offset;
|
|
|
|
guint32 junk;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gint bpp;
|
|
|
|
|
|
|
|
format = gegl_buffer_get_format (buffer);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) &width, 1);
|
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) &height, 1);
|
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) &bpp, 1);
|
|
|
|
|
|
|
|
/* make sure the values in the file correspond to the values
|
|
|
|
* calculated when the TileManager was created.
|
|
|
|
*/
|
2012-04-03 05:32:38 +08:00
|
|
|
if (width != gegl_buffer_get_width (buffer) ||
|
|
|
|
height != gegl_buffer_get_height (buffer) ||
|
|
|
|
bpp != babl_format_get_bytes_per_pixel (format))
|
2001-07-04 02:38:56 +08:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* load in the levels...we make sure that the number of levels
|
|
|
|
* calculated when the TileManager was created is the same
|
|
|
|
* as the number of levels found in the file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
info->cp += xcf_read_int32 (info->fp, &offset, 1); /* top level */
|
|
|
|
|
|
|
|
/* discard offsets for layers below first, if any.
|
|
|
|
*/
|
2003-09-01 07:46:05 +08:00
|
|
|
do
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
|
|
|
info->cp += xcf_read_int32 (info->fp, &junk, 1);
|
|
|
|
}
|
|
|
|
while (junk != 0);
|
|
|
|
|
|
|
|
/* save the current position as it is where the
|
|
|
|
* next level offset is stored.
|
|
|
|
*/
|
|
|
|
saved_pos = info->cp;
|
2003-09-01 07:46:05 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
/* seek to the level offset */
|
2002-12-20 14:26:34 +08:00
|
|
|
if (!xcf_seek_pos (info, offset, NULL))
|
|
|
|
return FALSE;
|
2003-09-01 07:46:05 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
/* read in the level */
|
2012-04-03 05:32:38 +08:00
|
|
|
if (!xcf_load_level (info, buffer))
|
2001-07-04 02:38:56 +08:00
|
|
|
return FALSE;
|
2003-09-01 07:46:05 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
/* restore the saved position so we'll be ready to
|
|
|
|
* read the next offset.
|
|
|
|
*/
|
2002-12-20 14:26:34 +08:00
|
|
|
if (!xcf_seek_pos (info, saved_pos, NULL))
|
|
|
|
return FALSE;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2012-04-03 05:32:38 +08:00
|
|
|
xcf_load_level (XcfInfo *info,
|
|
|
|
GeglBuffer *buffer)
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
2012-04-21 05:45:22 +08:00
|
|
|
const Babl *format;
|
|
|
|
guint32 saved_pos;
|
|
|
|
guint32 offset, offset2;
|
|
|
|
gint n_tile_rows;
|
|
|
|
gint n_tile_cols;
|
|
|
|
guint ntiles;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
gint i;
|
|
|
|
gint fail;
|
|
|
|
|
|
|
|
format = gegl_buffer_get_format (buffer);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2003-04-10 22:37:06 +08:00
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) &width, 1);
|
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) &height, 1);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2012-04-03 05:32:38 +08:00
|
|
|
if (width != gegl_buffer_get_width (buffer) ||
|
|
|
|
height != gegl_buffer_get_height (buffer))
|
2001-07-04 02:38:56 +08:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* read in the first tile offset.
|
|
|
|
* if it is '0', then this tile level is empty
|
|
|
|
* and we can simply return.
|
|
|
|
*/
|
|
|
|
info->cp += xcf_read_int32 (info->fp, &offset, 1);
|
|
|
|
if (offset == 0)
|
|
|
|
return TRUE;
|
|
|
|
|
2012-04-03 05:32:38 +08:00
|
|
|
n_tile_rows = gimp_gegl_buffer_get_n_tile_rows (buffer, XCF_TILE_HEIGHT);
|
|
|
|
n_tile_cols = gimp_gegl_buffer_get_n_tile_cols (buffer, XCF_TILE_WIDTH);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2012-04-03 05:32:38 +08:00
|
|
|
ntiles = n_tile_rows * n_tile_cols;
|
2001-07-04 02:38:56 +08:00
|
|
|
for (i = 0; i < ntiles; i++)
|
|
|
|
{
|
2012-04-03 05:32:38 +08:00
|
|
|
GeglRectangle rect;
|
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
fail = FALSE;
|
|
|
|
|
|
|
|
if (offset == 0)
|
2004-11-02 02:33:09 +08:00
|
|
|
{
|
2008-11-04 20:33:09 +08:00
|
|
|
gimp_message_literal (info->gimp, G_OBJECT (info->progress),
|
|
|
|
GIMP_MESSAGE_ERROR,
|
|
|
|
"not enough tiles found in level");
|
2004-11-02 02:33:09 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
/* save the current position as it is where the
|
|
|
|
* next tile offset is stored.
|
|
|
|
*/
|
|
|
|
saved_pos = info->cp;
|
|
|
|
|
|
|
|
/* read in the offset of the next tile so we can calculate the amount
|
2004-11-02 02:33:09 +08:00
|
|
|
of data needed for this tile*/
|
2001-07-04 02:38:56 +08:00
|
|
|
info->cp += xcf_read_int32 (info->fp, &offset2, 1);
|
2003-09-01 07:46:05 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
/* if the offset is 0 then we need to read in the maximum possible
|
2004-11-02 02:33:09 +08:00
|
|
|
allowing for negative compression */
|
2001-07-04 02:38:56 +08:00
|
|
|
if (offset2 == 0)
|
2012-04-03 05:32:38 +08:00
|
|
|
offset2 = offset + XCF_TILE_WIDTH * XCF_TILE_WIDTH * 4 * 1.5;
|
2001-07-04 02:38:56 +08:00
|
|
|
/* 1.5 is probably more
|
2004-11-02 02:33:09 +08:00
|
|
|
than we need to allow */
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
/* seek to the tile offset */
|
2002-12-20 14:26:34 +08:00
|
|
|
if (! xcf_seek_pos (info, offset, NULL))
|
|
|
|
return FALSE;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
/* get the tile from the tile manager */
|
2012-04-03 05:32:38 +08:00
|
|
|
gimp_gegl_buffer_get_tile_rect (buffer,
|
|
|
|
XCF_TILE_WIDTH, XCF_TILE_HEIGHT,
|
|
|
|
i, &rect);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
/* read in the tile */
|
|
|
|
switch (info->compression)
|
2004-11-02 02:33:09 +08:00
|
|
|
{
|
|
|
|
case COMPRESS_NONE:
|
2012-04-21 05:45:22 +08:00
|
|
|
if (!xcf_load_tile (info, buffer, &rect, format))
|
2004-11-02 02:33:09 +08:00
|
|
|
fail = TRUE;
|
|
|
|
break;
|
|
|
|
case COMPRESS_RLE:
|
2012-04-21 05:45:22 +08:00
|
|
|
if (!xcf_load_tile_rle (info, buffer, &rect, format,
|
|
|
|
offset2 - offset))
|
2004-11-02 02:33:09 +08:00
|
|
|
fail = TRUE;
|
|
|
|
break;
|
|
|
|
case COMPRESS_ZLIB:
|
|
|
|
g_error ("xcf: zlib compression unimplemented");
|
|
|
|
fail = TRUE;
|
|
|
|
break;
|
|
|
|
case COMPRESS_FRACTAL:
|
|
|
|
g_error ("xcf: fractal compression unimplemented");
|
|
|
|
fail = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2003-09-01 07:46:05 +08:00
|
|
|
if (fail)
|
2012-04-03 05:32:38 +08:00
|
|
|
return FALSE;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
/* restore the saved position so we'll be ready to
|
|
|
|
* read the next offset.
|
|
|
|
*/
|
2002-12-20 14:26:34 +08:00
|
|
|
if (!xcf_seek_pos (info, saved_pos, NULL))
|
|
|
|
return FALSE;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
/* read in the offset of the next tile */
|
|
|
|
info->cp += xcf_read_int32 (info->fp, &offset, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (offset != 0)
|
|
|
|
{
|
2006-10-09 16:17:22 +08:00
|
|
|
gimp_message (info->gimp, G_OBJECT (info->progress), GIMP_MESSAGE_ERROR,
|
2006-08-09 05:06:36 +08:00
|
|
|
"encountered garbage after reading level: %d", offset);
|
2001-07-04 02:38:56 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-04-03 05:32:38 +08:00
|
|
|
xcf_load_tile (XcfInfo *info,
|
|
|
|
GeglBuffer *buffer,
|
2012-04-21 05:45:22 +08:00
|
|
|
GeglRectangle *tile_rect,
|
|
|
|
const Babl *format)
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
2012-04-21 05:45:22 +08:00
|
|
|
gint bpp = babl_format_get_bytes_per_pixel (format);
|
|
|
|
gint tile_size = bpp * tile_rect->width * tile_rect->height;
|
|
|
|
guchar *tile_data = g_alloca (tile_size);
|
2012-04-03 05:32:38 +08:00
|
|
|
|
|
|
|
info->cp += xcf_read_int8 (info->fp, tile_data, tile_size);
|
|
|
|
|
2012-04-21 05:45:22 +08:00
|
|
|
gegl_buffer_set (buffer, tile_rect, 0, format, tile_data,
|
2012-04-03 05:32:38 +08:00
|
|
|
GEGL_AUTO_ROWSTRIDE);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2012-04-03 05:32:38 +08:00
|
|
|
xcf_load_tile_rle (XcfInfo *info,
|
|
|
|
GeglBuffer *buffer,
|
|
|
|
GeglRectangle *tile_rect,
|
2012-04-21 05:45:22 +08:00
|
|
|
const Babl *format,
|
2012-04-03 05:32:38 +08:00
|
|
|
gint data_length)
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
2012-04-21 05:45:22 +08:00
|
|
|
gint bpp = babl_format_get_bytes_per_pixel (format);
|
|
|
|
gint tile_size = bpp * tile_rect->width * tile_rect->height;
|
|
|
|
guchar *tile_data = g_alloca (tile_size);
|
|
|
|
gint i;
|
|
|
|
gint nmemb_read_successfully;
|
|
|
|
guchar *xcfdata;
|
|
|
|
guchar *xcfodata;
|
|
|
|
guchar *xcfdatalimit;
|
2003-09-01 07:46:05 +08:00
|
|
|
|
2006-10-11 17:19:12 +08:00
|
|
|
/* Workaround for bug #357809: avoid crashing on g_malloc() and skip
|
|
|
|
* this tile (return TRUE without storing data) as if it did not
|
|
|
|
* contain any data. It is better than returning FALSE, which would
|
|
|
|
* skip the whole hierarchy while there may still be some valid
|
|
|
|
* tiles in the file.
|
|
|
|
*/
|
|
|
|
if (data_length <= 0)
|
|
|
|
return TRUE;
|
|
|
|
|
2012-04-03 05:32:38 +08:00
|
|
|
xcfdata = xcfodata = g_alloca (data_length);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
/* we have to use fread instead of xcf_read_* because we may be
|
2012-04-03 05:32:38 +08:00
|
|
|
* reading past the end of the file here
|
|
|
|
*/
|
2003-04-10 22:37:06 +08:00
|
|
|
nmemb_read_successfully = fread ((gchar *) xcfdata, sizeof (gchar),
|
2004-11-02 02:33:09 +08:00
|
|
|
data_length, info->fp);
|
2001-07-04 02:38:56 +08:00
|
|
|
info->cp += nmemb_read_successfully;
|
|
|
|
|
|
|
|
xcfdatalimit = &xcfodata[nmemb_read_successfully - 1];
|
2003-09-01 07:46:05 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
for (i = 0; i < bpp; i++)
|
|
|
|
{
|
2012-04-03 05:32:38 +08:00
|
|
|
guchar *data = tile_data + i;
|
|
|
|
gint size = tile_rect->width * tile_rect->height;
|
|
|
|
gint count = 0;
|
|
|
|
guchar val;
|
|
|
|
gint length;
|
|
|
|
gint j;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
while (size > 0)
|
2004-11-02 02:33:09 +08:00
|
|
|
{
|
|
|
|
if (xcfdata > xcfdatalimit)
|
|
|
|
{
|
|
|
|
goto bogus_rle;
|
|
|
|
}
|
|
|
|
|
|
|
|
val = *xcfdata++;
|
|
|
|
|
|
|
|
length = val;
|
|
|
|
if (length >= 128)
|
|
|
|
{
|
|
|
|
length = 255 - (length - 1);
|
|
|
|
if (length == 128)
|
|
|
|
{
|
|
|
|
if (xcfdata >= xcfdatalimit)
|
|
|
|
{
|
|
|
|
goto bogus_rle;
|
|
|
|
}
|
|
|
|
|
|
|
|
length = (*xcfdata << 8) + xcfdata[1];
|
|
|
|
xcfdata += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
count += length;
|
|
|
|
size -= length;
|
|
|
|
|
|
|
|
if (size < 0)
|
|
|
|
{
|
|
|
|
goto bogus_rle;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (&xcfdata[length-1] > xcfdatalimit)
|
|
|
|
{
|
|
|
|
goto bogus_rle;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (length-- > 0)
|
|
|
|
{
|
|
|
|
*data = *xcfdata++;
|
|
|
|
data += bpp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
length += 1;
|
|
|
|
if (length == 128)
|
|
|
|
{
|
|
|
|
if (xcfdata >= xcfdatalimit)
|
|
|
|
{
|
|
|
|
goto bogus_rle;
|
|
|
|
}
|
|
|
|
|
|
|
|
length = (*xcfdata << 8) + xcfdata[1];
|
|
|
|
xcfdata += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
count += length;
|
|
|
|
size -= length;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
if (size < 0)
|
2004-11-02 02:33:09 +08:00
|
|
|
{
|
|
|
|
goto bogus_rle;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xcfdata > xcfdatalimit)
|
|
|
|
{
|
|
|
|
goto bogus_rle;
|
|
|
|
}
|
|
|
|
|
|
|
|
val = *xcfdata++;
|
|
|
|
|
|
|
|
for (j = 0; j < length; j++)
|
|
|
|
{
|
|
|
|
*data = val;
|
|
|
|
data += bpp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
2012-04-03 05:32:38 +08:00
|
|
|
|
2012-04-21 05:45:22 +08:00
|
|
|
gegl_buffer_set (buffer, tile_rect, 0, format, tile_data,
|
2012-04-03 05:32:38 +08:00
|
|
|
GEGL_AUTO_ROWSTRIDE);
|
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
bogus_rle:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-05-15 03:21:42 +08:00
|
|
|
static GimpParasite *
|
|
|
|
xcf_load_parasite (XcfInfo *info)
|
|
|
|
{
|
2007-12-22 00:37:01 +08:00
|
|
|
GimpParasite *parasite;
|
2007-05-22 23:12:30 +08:00
|
|
|
gchar *name;
|
2007-12-22 00:37:01 +08:00
|
|
|
guint32 flags;
|
|
|
|
guint32 size;
|
|
|
|
gpointer data;
|
2007-05-22 23:12:30 +08:00
|
|
|
|
|
|
|
info->cp += xcf_read_string (info->fp, &name, 1);
|
2007-12-22 00:37:01 +08:00
|
|
|
info->cp += xcf_read_int32 (info->fp, &flags, 1);
|
|
|
|
info->cp += xcf_read_int32 (info->fp, &size, 1);
|
|
|
|
|
|
|
|
data = g_new (gchar, size);
|
|
|
|
info->cp += xcf_read_int8 (info->fp, data, size);
|
2003-05-15 03:21:42 +08:00
|
|
|
|
2007-12-22 00:37:01 +08:00
|
|
|
parasite = gimp_parasite_new (name, flags, size, data);
|
|
|
|
|
|
|
|
g_free (name);
|
|
|
|
g_free (data);
|
2003-05-15 03:21:42 +08:00
|
|
|
|
2007-12-22 00:37:01 +08:00
|
|
|
return parasite;
|
2003-05-15 03:21:42 +08:00
|
|
|
}
|
|
|
|
|
2003-05-22 01:38:14 +08:00
|
|
|
static gboolean
|
2003-05-15 03:21:42 +08:00
|
|
|
xcf_load_old_paths (XcfInfo *info,
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image)
|
2003-05-15 03:21:42 +08:00
|
|
|
{
|
2003-05-22 01:38:14 +08:00
|
|
|
guint32 num_paths;
|
|
|
|
guint32 last_selected_row;
|
2003-05-15 03:21:42 +08:00
|
|
|
GimpVectors *active_vectors;
|
|
|
|
|
|
|
|
info->cp += xcf_read_int32 (info->fp, &last_selected_row, 1);
|
|
|
|
info->cp += xcf_read_int32 (info->fp, &num_paths, 1);
|
|
|
|
|
|
|
|
while (num_paths-- > 0)
|
2006-03-29 01:08:36 +08:00
|
|
|
xcf_load_old_path (info, image);
|
2003-05-15 03:21:42 +08:00
|
|
|
|
2009-08-02 21:48:27 +08:00
|
|
|
active_vectors =
|
2010-02-04 06:00:31 +08:00
|
|
|
GIMP_VECTORS (gimp_container_get_child_by_index (gimp_image_get_vectors (image),
|
2009-08-02 21:48:27 +08:00
|
|
|
last_selected_row));
|
2003-05-15 03:21:42 +08:00
|
|
|
|
|
|
|
if (active_vectors)
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_set_active_vectors (image, active_vectors);
|
2003-05-15 03:21:42 +08:00
|
|
|
|
2003-05-22 01:38:14 +08:00
|
|
|
return TRUE;
|
2003-05-15 03:21:42 +08:00
|
|
|
}
|
|
|
|
|
2003-05-22 01:38:14 +08:00
|
|
|
static gboolean
|
2003-05-15 03:21:42 +08:00
|
|
|
xcf_load_old_path (XcfInfo *info,
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image)
|
2003-05-15 03:21:42 +08:00
|
|
|
{
|
2003-05-23 03:02:38 +08:00
|
|
|
gchar *name;
|
|
|
|
guint32 locked;
|
|
|
|
guint8 state;
|
|
|
|
guint32 closed;
|
|
|
|
guint32 num_points;
|
|
|
|
guint32 version; /* changed from num_paths */
|
|
|
|
GimpTattoo tattoo = 0;
|
|
|
|
GimpVectors *vectors;
|
|
|
|
GimpVectorsCompatPoint *points;
|
|
|
|
gint i;
|
2003-05-15 03:21:42 +08:00
|
|
|
|
|
|
|
info->cp += xcf_read_string (info->fp, &name, 1);
|
|
|
|
info->cp += xcf_read_int32 (info->fp, &locked, 1);
|
|
|
|
info->cp += xcf_read_int8 (info->fp, &state, 1);
|
|
|
|
info->cp += xcf_read_int32 (info->fp, &closed, 1);
|
|
|
|
info->cp += xcf_read_int32 (info->fp, &num_points, 1);
|
|
|
|
info->cp += xcf_read_int32 (info->fp, &version, 1);
|
|
|
|
|
2003-05-23 03:02:38 +08:00
|
|
|
if (version == 2)
|
2003-05-15 03:21:42 +08:00
|
|
|
{
|
2003-05-22 01:38:14 +08:00
|
|
|
guint32 dummy;
|
|
|
|
|
2003-05-15 03:21:42 +08:00
|
|
|
/* Had extra type field and points are stored as doubles */
|
2003-05-22 01:38:14 +08:00
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) &dummy, 1);
|
2003-05-15 03:21:42 +08:00
|
|
|
}
|
|
|
|
else if (version == 3)
|
|
|
|
{
|
2003-05-22 01:38:14 +08:00
|
|
|
guint32 dummy;
|
|
|
|
|
2003-05-15 03:21:42 +08:00
|
|
|
/* Has extra tatto field */
|
2003-05-23 03:02:38 +08:00
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) &dummy, 1);
|
2003-05-15 03:21:42 +08:00
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) &tattoo, 1);
|
|
|
|
}
|
2003-05-23 03:02:38 +08:00
|
|
|
else if (version != 1)
|
2003-05-15 03:21:42 +08:00
|
|
|
{
|
|
|
|
g_warning ("Unknown path type. Possibly corrupt XCF file");
|
|
|
|
|
2003-05-23 03:02:38 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
2003-05-15 03:21:42 +08:00
|
|
|
|
2003-09-09 23:46:59 +08:00
|
|
|
/* skip empty compatibility paths */
|
|
|
|
if (num_points == 0)
|
2012-02-07 21:06:12 +08:00
|
|
|
{
|
|
|
|
g_free (name);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-09-09 23:46:59 +08:00
|
|
|
|
2003-05-23 03:02:38 +08:00
|
|
|
points = g_new0 (GimpVectorsCompatPoint, num_points);
|
2003-05-22 01:38:14 +08:00
|
|
|
|
2003-05-23 03:02:38 +08:00
|
|
|
for (i = 0; i < num_points; i++)
|
2003-05-15 20:32:53 +08:00
|
|
|
{
|
2003-05-23 03:02:38 +08:00
|
|
|
if (version == 1)
|
2003-05-15 20:32:53 +08:00
|
|
|
{
|
2003-05-23 03:02:38 +08:00
|
|
|
gint32 x;
|
|
|
|
gint32 y;
|
2003-05-15 20:32:53 +08:00
|
|
|
|
2003-05-23 03:02:38 +08:00
|
|
|
info->cp += xcf_read_int32 (info->fp, &points[i].type, 1);
|
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) &x, 1);
|
|
|
|
info->cp += xcf_read_int32 (info->fp, (guint32 *) &y, 1);
|
2003-05-15 20:32:53 +08:00
|
|
|
|
2003-05-23 03:02:38 +08:00
|
|
|
points[i].x = x;
|
|
|
|
points[i].y = y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gfloat x;
|
|
|
|
gfloat y;
|
2003-09-01 07:46:05 +08:00
|
|
|
|
2003-05-23 03:02:38 +08:00
|
|
|
info->cp += xcf_read_int32 (info->fp, &points[i].type, 1);
|
|
|
|
info->cp += xcf_read_float (info->fp, &x, 1);
|
|
|
|
info->cp += xcf_read_float (info->fp, &y, 1);
|
2003-05-19 00:36:10 +08:00
|
|
|
|
2003-05-23 03:02:38 +08:00
|
|
|
points[i].x = x;
|
|
|
|
points[i].y = y;
|
|
|
|
}
|
|
|
|
}
|
2003-05-19 00:36:10 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
vectors = gimp_vectors_compat_new (image, name, points, num_points, closed);
|
2003-05-15 20:32:53 +08:00
|
|
|
|
2004-11-03 19:50:37 +08:00
|
|
|
g_free (name);
|
2003-05-23 03:02:38 +08:00
|
|
|
g_free (points);
|
2003-05-15 03:21:42 +08:00
|
|
|
|
2007-12-19 03:12:43 +08:00
|
|
|
gimp_item_set_linked (GIMP_ITEM (vectors), locked, FALSE);
|
2003-05-15 20:32:53 +08:00
|
|
|
|
2003-05-23 03:02:38 +08:00
|
|
|
if (tattoo)
|
2007-12-19 03:12:43 +08:00
|
|
|
gimp_item_set_tattoo (GIMP_ITEM (vectors), tattoo);
|
2003-05-15 03:21:42 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_add_vectors (image, vectors,
|
2009-08-04 01:21:51 +08:00
|
|
|
NULL, /* can't be a tree */
|
2010-02-04 06:00:31 +08:00
|
|
|
gimp_container_get_n_children (gimp_image_get_vectors (image)),
|
2008-10-10 03:40:41 +08:00
|
|
|
FALSE);
|
2003-05-15 03:21:42 +08:00
|
|
|
|
2003-05-22 01:38:14 +08:00
|
|
|
return TRUE;
|
2003-05-15 03:21:42 +08:00
|
|
|
}
|
|
|
|
|
2003-09-09 23:46:59 +08:00
|
|
|
static gboolean
|
|
|
|
xcf_load_vectors (XcfInfo *info,
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image)
|
2003-09-09 23:46:59 +08:00
|
|
|
{
|
|
|
|
guint32 version;
|
2003-09-11 00:22:33 +08:00
|
|
|
guint32 active_index;
|
|
|
|
guint32 num_paths;
|
2003-09-09 23:46:59 +08:00
|
|
|
GimpVectors *active_vectors;
|
|
|
|
|
2004-03-03 23:54:19 +08:00
|
|
|
#ifdef GIMP_XCF_PATH_DEBUG
|
2003-09-09 23:46:59 +08:00
|
|
|
g_printerr ("xcf_load_vectors\n");
|
2004-03-03 23:54:19 +08:00
|
|
|
#endif
|
2003-09-09 23:46:59 +08:00
|
|
|
|
|
|
|
info->cp += xcf_read_int32 (info->fp, &version, 1);
|
|
|
|
|
|
|
|
if (version != 1)
|
|
|
|
{
|
2006-10-09 16:17:22 +08:00
|
|
|
gimp_message (info->gimp, G_OBJECT (info->progress),
|
|
|
|
GIMP_MESSAGE_WARNING,
|
2006-08-09 05:06:36 +08:00
|
|
|
"Unknown vectors version: %d (skipping)", version);
|
2003-09-09 23:46:59 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-09-11 00:22:33 +08:00
|
|
|
info->cp += xcf_read_int32 (info->fp, &active_index, 1);
|
|
|
|
info->cp += xcf_read_int32 (info->fp, &num_paths, 1);
|
2003-09-09 23:46:59 +08:00
|
|
|
|
2004-03-03 23:54:19 +08:00
|
|
|
#ifdef GIMP_XCF_PATH_DEBUG
|
2003-09-11 00:22:33 +08:00
|
|
|
g_printerr ("%d paths (active: %d)\n", num_paths, active_index);
|
2004-03-03 23:54:19 +08:00
|
|
|
#endif
|
2003-09-09 23:46:59 +08:00
|
|
|
|
|
|
|
while (num_paths-- > 0)
|
2006-03-29 01:08:36 +08:00
|
|
|
if (! xcf_load_vector (info, image))
|
2003-09-11 00:22:33 +08:00
|
|
|
return FALSE;
|
2003-09-09 23:46:59 +08:00
|
|
|
|
2009-08-02 21:48:27 +08:00
|
|
|
/* FIXME tree */
|
|
|
|
active_vectors =
|
2010-02-04 06:00:31 +08:00
|
|
|
GIMP_VECTORS (gimp_container_get_child_by_index (gimp_image_get_vectors (image),
|
2009-08-02 21:48:27 +08:00
|
|
|
active_index));
|
2003-09-09 23:46:59 +08:00
|
|
|
|
|
|
|
if (active_vectors)
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_set_active_vectors (image, active_vectors);
|
2003-09-09 23:46:59 +08:00
|
|
|
|
2004-03-03 23:54:19 +08:00
|
|
|
#ifdef GIMP_XCF_PATH_DEBUG
|
2003-09-09 23:46:59 +08:00
|
|
|
g_printerr ("xcf_load_vectors: loaded %d bytes\n", info->cp - base);
|
2004-03-03 23:54:19 +08:00
|
|
|
#endif
|
2003-09-09 23:46:59 +08:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
xcf_load_vector (XcfInfo *info,
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image)
|
2003-09-09 23:46:59 +08:00
|
|
|
{
|
2003-09-11 00:22:33 +08:00
|
|
|
gchar *name;
|
|
|
|
GimpTattoo tattoo = 0;
|
2003-09-12 03:52:29 +08:00
|
|
|
guint32 visible;
|
2003-09-11 00:22:33 +08:00
|
|
|
guint32 linked;
|
|
|
|
guint32 num_parasites;
|
|
|
|
guint32 num_strokes;
|
|
|
|
GimpVectors *vectors;
|
|
|
|
gint i;
|
2003-09-09 23:46:59 +08:00
|
|
|
|
2004-03-03 23:54:19 +08:00
|
|
|
#ifdef GIMP_XCF_PATH_DEBUG
|
2003-09-09 23:46:59 +08:00
|
|
|
g_printerr ("xcf_load_vector\n");
|
2004-03-03 23:54:19 +08:00
|
|
|
#endif
|
2003-09-09 23:46:59 +08:00
|
|
|
|
2003-09-11 00:22:33 +08:00
|
|
|
info->cp += xcf_read_string (info->fp, &name, 1);
|
|
|
|
info->cp += xcf_read_int32 (info->fp, &tattoo, 1);
|
2003-09-12 03:52:29 +08:00
|
|
|
info->cp += xcf_read_int32 (info->fp, &visible, 1);
|
2003-09-11 00:22:33 +08:00
|
|
|
info->cp += xcf_read_int32 (info->fp, &linked, 1);
|
|
|
|
info->cp += xcf_read_int32 (info->fp, &num_parasites, 1);
|
|
|
|
info->cp += xcf_read_int32 (info->fp, &num_strokes, 1);
|
|
|
|
|
2004-03-03 23:54:19 +08:00
|
|
|
#ifdef GIMP_XCF_PATH_DEBUG
|
2006-07-06 20:42:34 +08:00
|
|
|
g_printerr ("name: %s, tattoo: %d, visible: %d, linked: %d, "
|
|
|
|
"num_parasites %d, num_strokes %d\n",
|
2003-09-12 03:52:29 +08:00
|
|
|
name, tattoo, visible, linked, num_parasites, num_strokes);
|
2004-03-03 23:54:19 +08:00
|
|
|
#endif
|
2003-09-09 23:46:59 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
vectors = gimp_vectors_new (image, name);
|
2012-02-07 21:06:12 +08:00
|
|
|
g_free (name);
|
2003-09-09 23:46:59 +08:00
|
|
|
|
2007-12-19 03:12:43 +08:00
|
|
|
gimp_item_set_visible (GIMP_ITEM (vectors), visible, FALSE);
|
|
|
|
gimp_item_set_linked (GIMP_ITEM (vectors), linked, FALSE);
|
2003-09-11 00:22:33 +08:00
|
|
|
|
|
|
|
if (tattoo)
|
2007-12-19 03:12:43 +08:00
|
|
|
gimp_item_set_tattoo (GIMP_ITEM (vectors), tattoo);
|
2003-09-11 00:22:33 +08:00
|
|
|
|
|
|
|
for (i = 0; i < num_parasites; i++)
|
|
|
|
{
|
2006-07-06 20:42:34 +08:00
|
|
|
GimpParasite *parasite = xcf_load_parasite (info);
|
2003-09-11 00:22:33 +08:00
|
|
|
|
|
|
|
if (! parasite)
|
|
|
|
return FALSE;
|
|
|
|
|
2011-01-31 03:40:43 +08:00
|
|
|
gimp_item_parasite_attach (GIMP_ITEM (vectors), parasite, FALSE);
|
2003-09-11 00:22:33 +08:00
|
|
|
gimp_parasite_free (parasite);
|
|
|
|
}
|
|
|
|
|
2003-09-09 23:46:59 +08:00
|
|
|
for (i = 0; i < num_strokes; i++)
|
|
|
|
{
|
2005-08-03 21:48:40 +08:00
|
|
|
guint32 stroke_type_id;
|
|
|
|
guint32 closed;
|
|
|
|
guint32 num_axes;
|
|
|
|
guint32 num_control_points;
|
|
|
|
guint32 type;
|
2010-02-01 04:35:21 +08:00
|
|
|
gfloat coords[8] = GIMP_COORDS_DEFAULT_VALUES;
|
2003-09-11 00:22:33 +08:00
|
|
|
GimpStroke *stroke;
|
|
|
|
gint j;
|
2003-09-09 23:46:59 +08:00
|
|
|
|
2012-05-04 06:50:23 +08:00
|
|
|
GimpValueArray *control_points;
|
|
|
|
GValue value = { 0, };
|
|
|
|
GimpAnchor anchor = { { 0, } };
|
|
|
|
GType stroke_type;
|
2003-09-09 23:46:59 +08:00
|
|
|
|
2003-09-11 00:22:33 +08:00
|
|
|
g_value_init (&value, GIMP_TYPE_ANCHOR);
|
2003-09-09 23:46:59 +08:00
|
|
|
|
2003-09-11 00:22:33 +08:00
|
|
|
info->cp += xcf_read_int32 (info->fp, &stroke_type_id, 1);
|
|
|
|
info->cp += xcf_read_int32 (info->fp, &closed, 1);
|
|
|
|
info->cp += xcf_read_int32 (info->fp, &num_axes, 1);
|
|
|
|
info->cp += xcf_read_int32 (info->fp, &num_control_points, 1);
|
2003-09-09 23:46:59 +08:00
|
|
|
|
2004-03-03 23:54:19 +08:00
|
|
|
#ifdef GIMP_XCF_PATH_DEBUG
|
2003-09-09 23:46:59 +08:00
|
|
|
g_printerr ("stroke_type: %d, closed: %d, num_axes %d, len %d\n",
|
|
|
|
stroke_type_id, closed, num_axes, num_control_points);
|
2004-03-03 23:54:19 +08:00
|
|
|
#endif
|
2003-09-09 23:46:59 +08:00
|
|
|
|
|
|
|
switch (stroke_type_id)
|
|
|
|
{
|
|
|
|
case XCF_STROKETYPE_BEZIER_STROKE:
|
2004-01-19 01:41:29 +08:00
|
|
|
stroke_type = GIMP_TYPE_BEZIER_STROKE;
|
2003-09-09 23:46:59 +08:00
|
|
|
break;
|
2003-09-11 00:22:33 +08:00
|
|
|
|
2003-09-09 23:46:59 +08:00
|
|
|
default:
|
|
|
|
g_printerr ("skipping unknown stroke type\n");
|
2003-09-10 18:40:57 +08:00
|
|
|
xcf_seek_pos (info,
|
2003-09-09 23:46:59 +08:00
|
|
|
info->cp + 4 * num_axes * num_control_points,
|
|
|
|
NULL);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2006-07-06 20:42:34 +08:00
|
|
|
if (num_axes < 2 || num_axes > 6)
|
|
|
|
{
|
|
|
|
g_printerr ("bad number of axes in stroke description\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-05-04 06:50:23 +08:00
|
|
|
control_points = gimp_value_array_new (num_control_points);
|
2003-09-09 23:46:59 +08:00
|
|
|
|
2003-09-11 00:22:33 +08:00
|
|
|
anchor.selected = FALSE;
|
2003-09-09 23:46:59 +08:00
|
|
|
|
2003-09-11 00:22:33 +08:00
|
|
|
for (j = 0; j < num_control_points; j++)
|
2003-09-09 23:46:59 +08:00
|
|
|
{
|
|
|
|
info->cp += xcf_read_int32 (info->fp, &type, 1);
|
|
|
|
info->cp += xcf_read_float (info->fp, coords, num_axes);
|
|
|
|
|
|
|
|
anchor.type = type;
|
|
|
|
anchor.position.x = coords[0];
|
|
|
|
anchor.position.y = coords[1];
|
|
|
|
anchor.position.pressure = coords[2];
|
|
|
|
anchor.position.xtilt = coords[3];
|
|
|
|
anchor.position.ytilt = coords[4];
|
|
|
|
anchor.position.wheel = coords[5];
|
|
|
|
|
|
|
|
g_value_set_boxed (&value, &anchor);
|
2012-05-04 06:50:23 +08:00
|
|
|
gimp_value_array_append (control_points, &value);
|
2003-09-09 23:46:59 +08:00
|
|
|
|
2004-03-03 23:54:19 +08:00
|
|
|
#ifdef GIMP_XCF_PATH_DEBUG
|
2003-09-09 23:46:59 +08:00
|
|
|
g_printerr ("Anchor: %d, (%f, %f, %f, %f, %f, %f)\n", type,
|
|
|
|
coords[0], coords[1], coords[2], coords[3],
|
|
|
|
coords[4], coords[5]);
|
2004-03-03 23:54:19 +08:00
|
|
|
#endif
|
2003-09-09 23:46:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
g_value_unset (&value);
|
|
|
|
|
2003-09-11 00:22:33 +08:00
|
|
|
stroke = g_object_new (stroke_type,
|
|
|
|
"closed", closed,
|
|
|
|
"control-points", control_points,
|
|
|
|
NULL);
|
2003-09-09 23:46:59 +08:00
|
|
|
|
|
|
|
gimp_vectors_stroke_add (vectors, stroke);
|
2012-02-07 21:06:12 +08:00
|
|
|
|
|
|
|
g_object_unref (stroke);
|
2012-05-04 06:50:23 +08:00
|
|
|
gimp_value_array_unref (control_points);
|
2003-09-09 23:46:59 +08:00
|
|
|
}
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
gimp_image_add_vectors (image, vectors,
|
2009-08-04 01:21:51 +08:00
|
|
|
NULL, /* FIXME tree */
|
2010-02-04 06:00:31 +08:00
|
|
|
gimp_container_get_n_children (gimp_image_get_vectors (image)),
|
2008-10-10 03:40:41 +08:00
|
|
|
FALSE);
|
2003-09-09 23:46:59 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2010-08-07 06:26:58 +08:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
xcf_skip_unknown_prop (XcfInfo *info,
|
|
|
|
gsize size)
|
|
|
|
{
|
|
|
|
guint8 buf[16];
|
|
|
|
guint amount;
|
|
|
|
|
|
|
|
while (size > 0)
|
|
|
|
{
|
|
|
|
if (feof (info->fp))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
amount = MIN (16, size);
|
|
|
|
info->cp += xcf_read_int8 (info->fp, buf, amount);
|
|
|
|
size -= MIN (16, amount);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|