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
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2001-07-04 02:38:56 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <string.h>
|
2014-09-15 21:33:22 +08:00
|
|
|
#include <zlib.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"
|
|
|
|
|
2012-04-25 19:02:20 +08:00
|
|
|
#include "gegl/gimp-babl-compat.h"
|
2012-04-03 06:00:15 +08:00
|
|
|
#include "gegl/gimp-gegl-tile-compat.h"
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2006-08-09 05:06:36 +08:00
|
|
|
#include "core/gimp.h"
|
2008-11-03 04:46:57 +08:00
|
|
|
#include "core/gimpcontainer.h"
|
2001-07-04 02:38:56 +08:00
|
|
|
#include "core/gimpchannel.h"
|
|
|
|
#include "core/gimpdrawable.h"
|
2003-07-05 03:55:58 +08:00
|
|
|
#include "core/gimpgrid.h"
|
2006-06-07 06:48:57 +08:00
|
|
|
#include "core/gimpguide.h"
|
2001-07-04 02:38:56 +08:00
|
|
|
#include "core/gimpimage.h"
|
2007-12-22 00:37:01 +08:00
|
|
|
#include "core/gimpimage-colormap.h"
|
2003-07-05 03:55:58 +08:00
|
|
|
#include "core/gimpimage-grid.h"
|
2003-10-06 20:17:11 +08:00
|
|
|
#include "core/gimpimage-guides.h"
|
2013-10-20 00:38:01 +08:00
|
|
|
#include "core/gimpimage-metadata.h"
|
2010-02-04 06:42:32 +08:00
|
|
|
#include "core/gimpimage-private.h"
|
2006-08-11 01:10:12 +08:00
|
|
|
#include "core/gimpimage-sample-points.h"
|
2016-01-28 02:18:53 +08:00
|
|
|
#include "core/gimpimage-symmetry.h"
|
2001-07-04 02:38:56 +08:00
|
|
|
#include "core/gimplayer.h"
|
|
|
|
#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"
|
2007-01-30 18:34:59 +08:00
|
|
|
#include "core/gimpsamplepoint.h"
|
2016-01-28 02:18:53 +08:00
|
|
|
#include "core/gimpsymmetry.h"
|
2001-07-04 02:38:56 +08:00
|
|
|
|
app: future-proof XCF layer blend/composite props
The layer blend space, composite space, and composite mode
properties have a special AUTO value, which may map to different
concrete values based on the layer mode. Make sure we can change
this mapping in the future, without affecting existing XCFs (saved
after this commit), by encoding these properties as follows:
When saving an XCF, if the property has a concrete (non-AUTO)
value, which is always positive, encode it as is. If the property
is AUTO, which is always 0, encode it as the negative of the value
it actually maps to at the time of saving (note that in some cases
AUTO may map to AUTO, in which case it's encoded as 0).
When loading an XCF, if the encoded property (stored in the file)
is nonnegative, use it as is. Otherwise, compare the negative of
the encoded property to the value AUTO maps to at the time of
loading. If the values are equal, set the property to AUTO;
otherwise, use the concrete value (i.e., the negative of the value
stored in the XCF).
Note that XCFs saved prior to this commit still load fine, it's
simply that if we change the AUTO mapping in the future, all their
AUTO properties will keep being loaded as AUTO, even if the
resulting concrete values will have changed.
2017-05-21 20:01:39 +08:00
|
|
|
#include "operations/layer-modes/gimp-layer-modes.h"
|
|
|
|
|
2003-06-24 21:59:36 +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-22 01:38:14 +08:00
|
|
|
#include "vectors/gimpvectors.h"
|
2003-05-23 03:02:38 +08:00
|
|
|
#include "vectors/gimpvectors-compat.h"
|
2003-05-22 01:38:14 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
#include "xcf-private.h"
|
|
|
|
#include "xcf-read.h"
|
2006-10-30 18:13:06 +08:00
|
|
|
#include "xcf-save.h"
|
2001-07-04 02:38:56 +08:00
|
|
|
#include "xcf-seek.h"
|
|
|
|
#include "xcf-write.h"
|
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2002-12-20 14:26:34 +08:00
|
|
|
|
2003-05-22 01:38:14 +08:00
|
|
|
|
2003-09-11 00:22:33 +08:00
|
|
|
static gboolean xcf_save_image_props (XcfInfo *info,
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image,
|
2003-09-11 00:22:33 +08:00
|
|
|
GError **error);
|
|
|
|
static gboolean xcf_save_layer_props (XcfInfo *info,
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image,
|
2003-09-11 00:22:33 +08:00
|
|
|
GimpLayer *layer,
|
|
|
|
GError **error);
|
|
|
|
static gboolean xcf_save_channel_props (XcfInfo *info,
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image,
|
2003-09-11 00:22:33 +08:00
|
|
|
GimpChannel *channel,
|
|
|
|
GError **error);
|
|
|
|
static gboolean xcf_save_prop (XcfInfo *info,
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image,
|
2003-09-11 00:22:33 +08:00
|
|
|
PropType prop_type,
|
|
|
|
GError **error,
|
2003-05-15 20:47:42 +08:00
|
|
|
...);
|
2003-09-11 00:22:33 +08:00
|
|
|
static gboolean xcf_save_layer (XcfInfo *info,
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image,
|
2003-09-11 00:22:33 +08:00
|
|
|
GimpLayer *layer,
|
|
|
|
GError **error);
|
|
|
|
static gboolean xcf_save_channel (XcfInfo *info,
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image,
|
2003-09-11 00:22:33 +08:00
|
|
|
GimpChannel *channel,
|
|
|
|
GError **error);
|
2012-04-03 06:00:15 +08:00
|
|
|
static gboolean xcf_save_buffer (XcfInfo *info,
|
|
|
|
GeglBuffer *buffer,
|
2003-09-11 00:22:33 +08:00
|
|
|
GError **error);
|
|
|
|
static gboolean xcf_save_level (XcfInfo *info,
|
2012-04-03 06:00:15 +08:00
|
|
|
GeglBuffer *buffer,
|
2003-09-11 00:22:33 +08:00
|
|
|
GError **error);
|
|
|
|
static gboolean xcf_save_tile (XcfInfo *info,
|
2012-04-03 06:00:15 +08:00
|
|
|
GeglBuffer *buffer,
|
|
|
|
GeglRectangle *tile_rect,
|
2012-04-21 05:45:22 +08:00
|
|
|
const Babl *format,
|
2003-09-11 00:22:33 +08:00
|
|
|
GError **error);
|
|
|
|
static gboolean xcf_save_tile_rle (XcfInfo *info,
|
2012-04-03 06:00:15 +08:00
|
|
|
GeglBuffer *buffer,
|
|
|
|
GeglRectangle *tile_rect,
|
2012-04-21 05:45:22 +08:00
|
|
|
const Babl *format,
|
2003-09-11 00:22:33 +08:00
|
|
|
guchar *rlebuf,
|
|
|
|
GError **error);
|
2014-09-15 21:33:22 +08:00
|
|
|
static gboolean xcf_save_tile_zlib (XcfInfo *info,
|
|
|
|
GeglBuffer *buffer,
|
|
|
|
GeglRectangle *tile_rect,
|
|
|
|
const Babl *format,
|
|
|
|
GError **error);
|
2003-09-11 00:22:33 +08:00
|
|
|
static gboolean xcf_save_parasite (XcfInfo *info,
|
|
|
|
GimpParasite *parasite,
|
|
|
|
GError **error);
|
|
|
|
static gboolean xcf_save_parasite_list (XcfInfo *info,
|
|
|
|
GimpParasiteList *parasite,
|
|
|
|
GError **error);
|
|
|
|
static gboolean xcf_save_old_paths (XcfInfo *info,
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image,
|
2003-09-11 00:22:33 +08:00
|
|
|
GError **error);
|
|
|
|
static gboolean xcf_save_vectors (XcfInfo *info,
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image,
|
2003-09-11 00:22:33 +08:00
|
|
|
GError **error);
|
2003-05-15 20:47:42 +08:00
|
|
|
|
2002-12-20 14:26:34 +08:00
|
|
|
|
2004-01-26 17:22:06 +08:00
|
|
|
/* private convenience macros */
|
2017-03-23 19:42:38 +08:00
|
|
|
#define xcf_write_int32_check_error(info, data, count) G_STMT_START { \
|
|
|
|
xcf_write_int32 (info, data, count, &tmp_error); \
|
|
|
|
if (tmp_error) \
|
|
|
|
{ \
|
|
|
|
g_propagate_error (error, tmp_error); \
|
|
|
|
return FALSE; \
|
|
|
|
} \
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
|
|
#define xcf_write_offset_check_error(info, data, count) G_STMT_START { \
|
|
|
|
xcf_write_offset (info, data, count, &tmp_error); \
|
2013-10-09 03:22:14 +08:00
|
|
|
if (tmp_error) \
|
|
|
|
{ \
|
|
|
|
g_propagate_error (error, tmp_error); \
|
|
|
|
return FALSE; \
|
|
|
|
} \
|
2003-04-10 22:15:24 +08:00
|
|
|
} G_STMT_END
|
|
|
|
|
2017-03-23 19:42:38 +08:00
|
|
|
#define xcf_write_zero_offset_check_error(info, count) G_STMT_START { \
|
|
|
|
xcf_write_zero_offset (info, count, &tmp_error); \
|
|
|
|
if (tmp_error) \
|
|
|
|
{ \
|
|
|
|
g_propagate_error (error, tmp_error); \
|
|
|
|
return FALSE; \
|
|
|
|
} \
|
2017-03-23 18:44:41 +08:00
|
|
|
} G_STMT_END
|
|
|
|
|
2017-03-23 19:42:38 +08:00
|
|
|
#define xcf_write_int8_check_error(info, data, count) G_STMT_START { \
|
|
|
|
xcf_write_int8 (info, data, count, &tmp_error); \
|
|
|
|
if (tmp_error) \
|
|
|
|
{ \
|
|
|
|
g_propagate_error (error, tmp_error); \
|
|
|
|
return FALSE; \
|
|
|
|
} \
|
2014-10-18 01:12:05 +08:00
|
|
|
} G_STMT_END
|
|
|
|
|
2017-03-23 19:42:38 +08:00
|
|
|
#define xcf_write_float_check_error(info, data, count) G_STMT_START { \
|
|
|
|
xcf_write_float (info, data, count, &tmp_error); \
|
2013-10-09 03:22:14 +08:00
|
|
|
if (tmp_error) \
|
|
|
|
{ \
|
|
|
|
g_propagate_error (error, tmp_error); \
|
|
|
|
return FALSE; \
|
|
|
|
} \
|
2003-04-10 22:15:24 +08:00
|
|
|
} G_STMT_END
|
|
|
|
|
2017-03-23 19:42:38 +08:00
|
|
|
#define xcf_write_string_check_error(info, data, count) G_STMT_START { \
|
|
|
|
xcf_write_string (info, data, count, &tmp_error); \
|
2013-10-09 03:22:14 +08:00
|
|
|
if (tmp_error) \
|
|
|
|
{ \
|
|
|
|
g_propagate_error (error, tmp_error); \
|
|
|
|
return FALSE; \
|
|
|
|
} \
|
2003-04-10 22:15:24 +08:00
|
|
|
} G_STMT_END
|
|
|
|
|
2017-09-17 01:03:20 +08:00
|
|
|
#define xcf_write_component_check_error(info, bpc, data, count) G_STMT_START { \
|
|
|
|
xcf_write_component (info, bpc, data, count, &tmp_error); \
|
|
|
|
if (tmp_error) \
|
|
|
|
{ \
|
|
|
|
g_propagate_error (error, tmp_error); \
|
|
|
|
return FALSE; \
|
|
|
|
} \
|
|
|
|
} G_STMT_END
|
|
|
|
|
2004-01-26 17:22:06 +08:00
|
|
|
#define xcf_write_prop_type_check_error(info, prop_type) G_STMT_START { \
|
2017-03-23 19:42:38 +08:00
|
|
|
guint32 _prop_int32 = prop_type; \
|
|
|
|
xcf_write_int32_check_error (info, &_prop_int32, 1); \
|
2004-01-26 17:22:06 +08:00
|
|
|
} G_STMT_END
|
|
|
|
|
2003-04-10 22:15:24 +08:00
|
|
|
#define xcf_check_error(x) G_STMT_START { \
|
2017-03-23 19:42:38 +08:00
|
|
|
if (! (x)) \
|
|
|
|
return FALSE; \
|
2003-04-10 22:15:24 +08:00
|
|
|
} G_STMT_END
|
2003-09-10 18:40:57 +08:00
|
|
|
|
2006-07-12 04:21:18 +08:00
|
|
|
#define xcf_progress_update(info) G_STMT_START \
|
|
|
|
{ \
|
|
|
|
progress++; \
|
|
|
|
if (info->progress) \
|
|
|
|
gimp_progress_set_value (info->progress, \
|
|
|
|
(gdouble) progress / (gdouble) max_progress); \
|
|
|
|
} G_STMT_END
|
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2014-09-28 02:38:43 +08:00
|
|
|
gboolean
|
2007-12-03 15:44:49 +08:00
|
|
|
xcf_save_image (XcfInfo *info,
|
|
|
|
GimpImage *image,
|
|
|
|
GError **error)
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
2009-08-31 03:19:42 +08:00
|
|
|
GList *all_layers;
|
|
|
|
GList *all_channels;
|
|
|
|
GList *list;
|
2017-03-23 18:44:41 +08:00
|
|
|
goffset saved_pos;
|
|
|
|
goffset offset;
|
2009-08-31 03:19:42 +08:00
|
|
|
guint32 value;
|
|
|
|
guint n_layers;
|
|
|
|
guint n_channels;
|
|
|
|
guint progress = 0;
|
|
|
|
guint max_progress;
|
|
|
|
gchar version_tag[16];
|
|
|
|
GError *tmp_error = NULL;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
/* write out the tag information for the image */
|
2003-09-10 18:40:57 +08:00
|
|
|
if (info->file_version > 0)
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
2018-08-21 18:19:55 +08:00
|
|
|
g_snprintf (version_tag, sizeof (version_tag),
|
|
|
|
"gimp xcf v%03d", info->file_version);
|
2003-09-10 18:40:57 +08:00
|
|
|
}
|
|
|
|
else
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
|
|
|
strcpy (version_tag, "gimp xcf file");
|
|
|
|
}
|
2006-07-12 04:21:18 +08:00
|
|
|
|
2007-12-03 15:44:49 +08:00
|
|
|
xcf_write_int8_check_error (info, (guint8 *) version_tag, 14);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
/* write out the width, height and image type information for the image */
|
2007-12-26 00:21:40 +08:00
|
|
|
value = gimp_image_get_width (image);
|
|
|
|
xcf_write_int32_check_error (info, (guint32 *) &value, 1);
|
|
|
|
|
|
|
|
value = gimp_image_get_height (image);
|
|
|
|
xcf_write_int32_check_error (info, (guint32 *) &value, 1);
|
2007-04-12 22:48:04 +08:00
|
|
|
|
2012-05-08 03:57:33 +08:00
|
|
|
value = gimp_image_get_base_type (image);
|
2007-12-03 15:44:49 +08:00
|
|
|
xcf_write_int32_check_error (info, &value, 1);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2012-04-27 22:42:19 +08:00
|
|
|
if (info->file_version >= 4)
|
|
|
|
{
|
|
|
|
value = gimp_image_get_precision (image);
|
|
|
|
xcf_write_int32_check_error (info, &value, 1);
|
|
|
|
}
|
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
/* determine the number of layers and channels in the image */
|
2009-08-31 03:19:42 +08:00
|
|
|
all_layers = gimp_image_get_layer_list (image);
|
|
|
|
all_channels = gimp_image_get_channel_list (image);
|
2006-07-12 04:21:18 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
/* check and see if we have to save out the selection */
|
2015-07-01 03:59:26 +08:00
|
|
|
if (! gimp_channel_is_empty (gimp_image_get_mask (image)))
|
2009-08-31 03:19:42 +08:00
|
|
|
{
|
|
|
|
all_channels = g_list_append (all_channels, gimp_image_get_mask (image));
|
|
|
|
}
|
|
|
|
|
|
|
|
n_layers = (guint) g_list_length (all_layers);
|
|
|
|
n_channels = (guint) g_list_length (all_channels);
|
|
|
|
|
|
|
|
max_progress = 1 + n_layers + n_channels;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2017-03-23 18:44:41 +08:00
|
|
|
/* write the property information for the image */
|
2007-12-03 15:44:49 +08:00
|
|
|
xcf_check_error (xcf_save_image_props (info, image, error));
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2006-07-12 04:21:18 +08:00
|
|
|
xcf_progress_update (info);
|
|
|
|
|
2014-10-18 01:12:05 +08:00
|
|
|
/* 'saved_pos' is the next slot in the offset table */
|
|
|
|
saved_pos = info->cp;
|
|
|
|
|
|
|
|
/* write an empty offset table */
|
2017-03-23 18:44:41 +08:00
|
|
|
xcf_write_zero_offset_check_error (info, n_layers + n_channels + 2);
|
2014-10-18 01:12:05 +08:00
|
|
|
|
|
|
|
/* 'offset' is where we will write the next layer or channel */
|
|
|
|
offset = info->cp;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2009-08-31 03:19:42 +08:00
|
|
|
for (list = all_layers; list; list = g_list_next (list))
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
2009-08-31 03:07:22 +08:00
|
|
|
GimpLayer *layer = list->data;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2014-10-18 01:12:05 +08:00
|
|
|
/* seek back to the next slot in the offset table and write the
|
|
|
|
* offset of the layer
|
|
|
|
*/
|
|
|
|
xcf_check_error (xcf_seek_pos (info, saved_pos, error));
|
2017-03-23 18:44:41 +08:00
|
|
|
xcf_write_offset_check_error (info, &offset, 1);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2014-10-18 01:12:05 +08:00
|
|
|
/* remember the next slot in the offset table */
|
2014-10-16 05:15:18 +08:00
|
|
|
saved_pos = info->cp;
|
|
|
|
|
|
|
|
/* seek to the layer offset and save the layer */
|
|
|
|
xcf_check_error (xcf_seek_pos (info, offset, error));
|
2007-12-03 15:44:49 +08:00
|
|
|
xcf_check_error (xcf_save_layer (info, image, layer, error));
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2014-10-16 05:15:18 +08:00
|
|
|
/* the next layer's offset is after the layer we just wrote */
|
|
|
|
offset = info->cp;
|
2006-07-12 04:21:18 +08:00
|
|
|
|
2014-10-16 05:15:18 +08:00
|
|
|
xcf_progress_update (info);
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
|
2014-10-18 01:12:05 +08:00
|
|
|
/* skip a '0' in the offset table to indicate the end of the layer
|
|
|
|
* offsets
|
|
|
|
*/
|
2017-03-23 18:44:41 +08:00
|
|
|
saved_pos += info->bytes_per_offset;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2009-08-31 03:19:42 +08:00
|
|
|
for (list = all_channels; list; list = g_list_next (list))
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
2009-08-31 03:19:42 +08:00
|
|
|
GimpChannel *channel = list->data;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2014-10-18 01:12:05 +08:00
|
|
|
/* seek back to the next slot in the offset table and write the
|
|
|
|
* offset of the channel
|
|
|
|
*/
|
|
|
|
xcf_check_error (xcf_seek_pos (info, saved_pos, error));
|
2017-03-23 18:44:41 +08:00
|
|
|
xcf_write_offset_check_error (info, &offset, 1);
|
2014-10-16 05:15:18 +08:00
|
|
|
|
2014-10-18 01:12:05 +08:00
|
|
|
/* remember the next slot in the offset table */
|
2014-10-16 05:15:18 +08:00
|
|
|
saved_pos = info->cp;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2014-10-16 05:15:18 +08:00
|
|
|
/* seek to the channel offset and save the channel */
|
|
|
|
xcf_check_error (xcf_seek_pos (info, offset, error));
|
2007-12-03 15:44:49 +08:00
|
|
|
xcf_check_error (xcf_save_channel (info, image, channel, error));
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2014-10-18 01:12:05 +08:00
|
|
|
/* the next channels's offset is after the channel we just wrote */
|
2014-10-16 05:15:18 +08:00
|
|
|
offset = info->cp;
|
2006-07-12 04:21:18 +08:00
|
|
|
|
2014-10-16 05:15:18 +08:00
|
|
|
xcf_progress_update (info);
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
|
2014-10-18 01:12:05 +08:00
|
|
|
/* there is already a '0' at the end of the offset table to indicate
|
|
|
|
* the end of the channel offsets
|
|
|
|
*/
|
2014-10-16 05:15:18 +08:00
|
|
|
|
2009-08-31 03:19:42 +08:00
|
|
|
g_list_free (all_layers);
|
|
|
|
g_list_free (all_channels);
|
|
|
|
|
2013-10-09 03:22:14 +08:00
|
|
|
return ! g_output_stream_is_closed (info->output);
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
|
2002-12-20 14:26:34 +08:00
|
|
|
static gboolean
|
2006-11-06 16:14:46 +08:00
|
|
|
xcf_save_image_props (XcfInfo *info,
|
|
|
|
GimpImage *image,
|
|
|
|
GError **error)
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
2017-03-24 01:03:27 +08:00
|
|
|
GimpImagePrivate *private = GIMP_IMAGE_GET_PRIVATE (image);
|
|
|
|
GimpParasite *grid_parasite = NULL;
|
|
|
|
GimpParasite *meta_parasite = NULL;
|
2016-01-28 02:18:53 +08:00
|
|
|
GList *symmetry_parasites = NULL;
|
|
|
|
GList *iter;
|
2017-03-24 01:03:27 +08:00
|
|
|
GimpUnit unit = gimp_image_get_unit (image);
|
2010-02-04 06:42:32 +08:00
|
|
|
gdouble xres;
|
|
|
|
gdouble yres;
|
2007-12-27 01:33:41 +08:00
|
|
|
|
|
|
|
gimp_image_get_resolution (image, &xres, &yres);
|
2003-07-05 03:55:58 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
/* check and see if we should save the colormap property */
|
2007-12-22 00:37:01 +08:00
|
|
|
if (gimp_image_get_colormap (image))
|
2006-03-29 01:08:36 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_COLORMAP, error,
|
2007-12-22 00:37:01 +08:00
|
|
|
gimp_image_get_colormap_size (image),
|
|
|
|
gimp_image_get_colormap (image)));
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
if (info->compression != COMPRESS_NONE)
|
2007-12-26 01:09:04 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_COMPRESSION, error,
|
|
|
|
info->compression));
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2007-12-26 01:09:04 +08:00
|
|
|
if (gimp_image_get_guides (image))
|
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_GUIDES, error,
|
|
|
|
gimp_image_get_guides (image)));
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2007-12-26 01:09:04 +08:00
|
|
|
if (gimp_image_get_sample_points (image))
|
2018-07-16 07:42:19 +08:00
|
|
|
{
|
|
|
|
/* save the new property before the old one, so loading can skip
|
|
|
|
* the latter
|
|
|
|
*/
|
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_SAMPLE_POINTS, error,
|
|
|
|
gimp_image_get_sample_points (image)));
|
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_OLD_SAMPLE_POINTS, error,
|
|
|
|
gimp_image_get_sample_points (image)));
|
|
|
|
}
|
2006-08-11 01:10:12 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_RESOLUTION, error,
|
2007-12-27 01:33:41 +08:00
|
|
|
xres, yres));
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_TATTOO, error,
|
2007-12-22 00:37:01 +08:00
|
|
|
gimp_image_get_tattoo_state (image)));
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2010-02-21 23:46:39 +08:00
|
|
|
if (unit < gimp_unit_get_number_of_built_in_units ())
|
2006-03-29 01:08:36 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_UNIT, error, unit));
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2010-02-04 06:00:31 +08:00
|
|
|
if (gimp_container_get_n_children (gimp_image_get_vectors (image)) > 0)
|
2003-09-09 23:46:59 +08:00
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
if (gimp_vectors_compat_is_compatible (image))
|
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_PATHS, error));
|
2003-09-09 23:46:59 +08:00
|
|
|
else
|
2006-03-29 01:08:36 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_VECTORS, error));
|
2003-09-09 23:46:59 +08:00
|
|
|
}
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2010-02-21 23:46:39 +08:00
|
|
|
if (unit >= gimp_unit_get_number_of_built_in_units ())
|
2006-03-29 01:08:36 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_USER_UNIT, error, unit));
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2010-02-04 05:16:02 +08:00
|
|
|
if (gimp_image_get_grid (image))
|
2003-07-05 03:55:58 +08:00
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpGrid *grid = gimp_image_get_grid (image);
|
2003-07-05 03:55:58 +08:00
|
|
|
|
2013-10-20 00:38:01 +08:00
|
|
|
grid_parasite = gimp_grid_to_parasite (grid);
|
|
|
|
gimp_parasite_list_add (private->parasites, grid_parasite);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gimp_image_get_metadata (image))
|
|
|
|
{
|
|
|
|
GimpMetadata *metadata = gimp_image_get_metadata (image);
|
|
|
|
gchar *meta_string;
|
|
|
|
|
|
|
|
meta_string = gimp_metadata_serialize (metadata);
|
|
|
|
|
|
|
|
if (meta_string)
|
|
|
|
{
|
|
|
|
meta_parasite = gimp_parasite_new ("gimp-image-metadata",
|
|
|
|
GIMP_PARASITE_PERSISTENT,
|
|
|
|
strlen (meta_string) + 1,
|
|
|
|
meta_string);
|
|
|
|
gimp_parasite_list_add (private->parasites, meta_parasite);
|
|
|
|
g_free (meta_string);
|
|
|
|
}
|
2003-07-05 03:55:58 +08:00
|
|
|
}
|
|
|
|
|
2016-01-28 02:18:53 +08:00
|
|
|
if (g_list_length (gimp_image_symmetry_get (image)))
|
|
|
|
{
|
|
|
|
GimpParasite *parasite = NULL;
|
|
|
|
GimpSymmetry *symmetry;
|
|
|
|
|
|
|
|
for (iter = gimp_image_symmetry_get (image); iter; iter = g_list_next (iter))
|
|
|
|
{
|
|
|
|
symmetry = GIMP_SYMMETRY (iter->data);
|
|
|
|
if (G_TYPE_FROM_INSTANCE (symmetry) == GIMP_TYPE_SYMMETRY)
|
|
|
|
/* Do not save the identity symmetry. */
|
|
|
|
continue;
|
|
|
|
parasite = gimp_symmetry_to_parasite (GIMP_SYMMETRY (iter->data));
|
|
|
|
gimp_parasite_list_add (private->parasites, parasite);
|
|
|
|
symmetry_parasites = g_list_prepend (symmetry_parasites, parasite);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-04 06:42:32 +08:00
|
|
|
if (gimp_parasite_list_length (private->parasites) > 0)
|
2003-07-05 03:55:58 +08:00
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_PARASITES, error,
|
2010-02-04 06:42:32 +08:00
|
|
|
private->parasites));
|
2003-07-05 03:55:58 +08:00
|
|
|
}
|
|
|
|
|
2013-10-20 00:38:01 +08:00
|
|
|
if (grid_parasite)
|
|
|
|
{
|
|
|
|
gimp_parasite_list_remove (private->parasites,
|
2021-04-06 00:36:44 +08:00
|
|
|
gimp_parasite_get_name (grid_parasite));
|
2013-10-20 00:38:01 +08:00
|
|
|
gimp_parasite_free (grid_parasite);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (meta_parasite)
|
2003-07-05 03:55:58 +08:00
|
|
|
{
|
2010-02-04 06:42:32 +08:00
|
|
|
gimp_parasite_list_remove (private->parasites,
|
2021-04-06 00:36:44 +08:00
|
|
|
gimp_parasite_get_name (meta_parasite));
|
2013-10-20 00:38:01 +08:00
|
|
|
gimp_parasite_free (meta_parasite);
|
2003-07-05 03:55:58 +08:00
|
|
|
}
|
|
|
|
|
2016-01-28 02:18:53 +08:00
|
|
|
for (iter = symmetry_parasites; iter; iter = g_list_next (iter))
|
|
|
|
{
|
|
|
|
GimpParasite *parasite = iter->data;
|
|
|
|
|
|
|
|
gimp_parasite_list_remove (private->parasites,
|
2021-04-06 00:36:44 +08:00
|
|
|
gimp_parasite_get_name (parasite));
|
2016-01-28 02:18:53 +08:00
|
|
|
}
|
|
|
|
g_list_free_full (symmetry_parasites,
|
|
|
|
(GDestroyNotify) gimp_parasite_free);
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_END, error));
|
2002-12-20 14:26:34 +08:00
|
|
|
|
|
|
|
return TRUE;
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
|
2003-09-10 18:40:57 +08:00
|
|
|
static gboolean
|
2006-11-06 16:14:46 +08:00
|
|
|
xcf_save_layer_props (XcfInfo *info,
|
|
|
|
GimpImage *image,
|
|
|
|
GimpLayer *layer,
|
|
|
|
GError **error)
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
2011-02-01 06:51:18 +08:00
|
|
|
GimpParasiteList *parasites;
|
|
|
|
gint offset_x;
|
|
|
|
gint offset_y;
|
2003-06-24 21:59:36 +08:00
|
|
|
|
2009-08-31 03:28:59 +08:00
|
|
|
if (gimp_viewable_get_children (GIMP_VIEWABLE (layer)))
|
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_GROUP_ITEM, error));
|
|
|
|
|
|
|
|
if (gimp_viewable_get_parent (GIMP_VIEWABLE (layer)))
|
|
|
|
{
|
|
|
|
GList *path;
|
|
|
|
|
|
|
|
path = gimp_item_get_path (GIMP_ITEM (layer));
|
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_ITEM_PATH, error,
|
|
|
|
path));
|
|
|
|
g_list_free (path);
|
|
|
|
}
|
|
|
|
|
2020-04-15 03:36:58 +08:00
|
|
|
if (g_list_find (gimp_image_get_selected_layers (image), layer))
|
2006-03-29 01:08:36 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_ACTIVE_LAYER, error));
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2008-11-14 23:01:44 +08:00
|
|
|
if (layer == gimp_image_get_floating_selection (image))
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
2009-01-27 06:47:16 +08:00
|
|
|
info->floating_sel_drawable = gimp_layer_get_floating_sel_drawable (layer);
|
2006-03-29 01:08:36 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_FLOATING_SELECTION,
|
2002-12-20 14:26:34 +08:00
|
|
|
error));
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_OPACITY, error,
|
2007-12-19 03:12:43 +08:00
|
|
|
gimp_layer_get_opacity (layer)));
|
2015-10-17 03:59:11 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_FLOAT_OPACITY, error,
|
|
|
|
gimp_layer_get_opacity (layer)));
|
2006-03-29 01:08:36 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_VISIBLE, error,
|
2006-04-12 20:49:29 +08:00
|
|
|
gimp_item_get_visible (GIMP_ITEM (layer))));
|
2006-03-29 01:08:36 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_LINKED, error,
|
2003-05-14 02:30:15 +08:00
|
|
|
gimp_item_get_linked (GIMP_ITEM (layer))));
|
2016-11-15 06:02:43 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_COLOR_TAG, error,
|
|
|
|
gimp_item_get_color_tag (GIMP_ITEM (layer))));
|
2009-08-30 18:44:35 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_LOCK_CONTENT, error,
|
|
|
|
gimp_item_get_lock_content (GIMP_ITEM (layer))));
|
2007-12-22 00:37:01 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_LOCK_ALPHA, error,
|
|
|
|
gimp_layer_get_lock_alpha (layer)));
|
2012-11-09 18:17:25 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_LOCK_POSITION, error,
|
|
|
|
gimp_item_get_lock_position (GIMP_ITEM (layer))));
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2007-12-22 00:37:01 +08:00
|
|
|
if (gimp_layer_get_mask (layer))
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
2007-12-22 00:37:01 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_APPLY_MASK, error,
|
2012-03-18 01:30:13 +08:00
|
|
|
gimp_layer_get_apply_mask (layer)));
|
2007-12-22 00:37:01 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_EDIT_MASK, error,
|
2012-03-18 01:30:13 +08:00
|
|
|
gimp_layer_get_edit_mask (layer)));
|
2007-12-22 00:37:01 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_SHOW_MASK, error,
|
2012-03-18 01:30:13 +08:00
|
|
|
gimp_layer_get_show_mask (layer)));
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-12-22 00:37:01 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_APPLY_MASK, error,
|
|
|
|
FALSE));
|
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_EDIT_MASK, error,
|
|
|
|
FALSE));
|
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_SHOW_MASK, error,
|
|
|
|
FALSE));
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
|
2008-11-04 05:17:50 +08:00
|
|
|
gimp_item_get_offset (GIMP_ITEM (layer), &offset_x, &offset_y);
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_OFFSETS, error,
|
2008-11-04 05:17:50 +08:00
|
|
|
offset_x, offset_y));
|
2006-03-29 01:08:36 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_MODE, error,
|
2007-12-19 03:12:43 +08:00
|
|
|
gimp_layer_get_mode (layer)));
|
2017-02-13 06:49:26 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_BLEND_SPACE, error,
|
app: future-proof XCF layer blend/composite props
The layer blend space, composite space, and composite mode
properties have a special AUTO value, which may map to different
concrete values based on the layer mode. Make sure we can change
this mapping in the future, without affecting existing XCFs (saved
after this commit), by encoding these properties as follows:
When saving an XCF, if the property has a concrete (non-AUTO)
value, which is always positive, encode it as is. If the property
is AUTO, which is always 0, encode it as the negative of the value
it actually maps to at the time of saving (note that in some cases
AUTO may map to AUTO, in which case it's encoded as 0).
When loading an XCF, if the encoded property (stored in the file)
is nonnegative, use it as is. Otherwise, compare the negative of
the encoded property to the value AUTO maps to at the time of
loading. If the values are equal, set the property to AUTO;
otherwise, use the concrete value (i.e., the negative of the value
stored in the XCF).
Note that XCFs saved prior to this commit still load fine, it's
simply that if we change the AUTO mapping in the future, all their
AUTO properties will keep being loaded as AUTO, even if the
resulting concrete values will have changed.
2017-05-21 20:01:39 +08:00
|
|
|
gimp_layer_get_mode (layer),
|
2017-02-13 06:49:26 +08:00
|
|
|
gimp_layer_get_blend_space (layer)));
|
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_COMPOSITE_SPACE, error,
|
app: future-proof XCF layer blend/composite props
The layer blend space, composite space, and composite mode
properties have a special AUTO value, which may map to different
concrete values based on the layer mode. Make sure we can change
this mapping in the future, without affecting existing XCFs (saved
after this commit), by encoding these properties as follows:
When saving an XCF, if the property has a concrete (non-AUTO)
value, which is always positive, encode it as is. If the property
is AUTO, which is always 0, encode it as the negative of the value
it actually maps to at the time of saving (note that in some cases
AUTO may map to AUTO, in which case it's encoded as 0).
When loading an XCF, if the encoded property (stored in the file)
is nonnegative, use it as is. Otherwise, compare the negative of
the encoded property to the value AUTO maps to at the time of
loading. If the values are equal, set the property to AUTO;
otherwise, use the concrete value (i.e., the negative of the value
stored in the XCF).
Note that XCFs saved prior to this commit still load fine, it's
simply that if we change the AUTO mapping in the future, all their
AUTO properties will keep being loaded as AUTO, even if the
resulting concrete values will have changed.
2017-05-21 20:01:39 +08:00
|
|
|
gimp_layer_get_mode (layer),
|
2017-02-13 06:49:26 +08:00
|
|
|
gimp_layer_get_composite_space (layer)));
|
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_COMPOSITE_MODE, error,
|
app: future-proof XCF layer blend/composite props
The layer blend space, composite space, and composite mode
properties have a special AUTO value, which may map to different
concrete values based on the layer mode. Make sure we can change
this mapping in the future, without affecting existing XCFs (saved
after this commit), by encoding these properties as follows:
When saving an XCF, if the property has a concrete (non-AUTO)
value, which is always positive, encode it as is. If the property
is AUTO, which is always 0, encode it as the negative of the value
it actually maps to at the time of saving (note that in some cases
AUTO may map to AUTO, in which case it's encoded as 0).
When loading an XCF, if the encoded property (stored in the file)
is nonnegative, use it as is. Otherwise, compare the negative of
the encoded property to the value AUTO maps to at the time of
loading. If the values are equal, set the property to AUTO;
otherwise, use the concrete value (i.e., the negative of the value
stored in the XCF).
Note that XCFs saved prior to this commit still load fine, it's
simply that if we change the AUTO mapping in the future, all their
AUTO properties will keep being loaded as AUTO, even if the
resulting concrete values will have changed.
2017-05-21 20:01:39 +08:00
|
|
|
gimp_layer_get_mode (layer),
|
2017-02-13 06:49:26 +08:00
|
|
|
gimp_layer_get_composite_mode (layer)));
|
2006-03-29 01:08:36 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_TATTOO, error,
|
2007-12-19 03:12:43 +08:00
|
|
|
gimp_item_get_tattoo (GIMP_ITEM (layer))));
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2004-03-18 23:27:23 +08:00
|
|
|
if (GIMP_IS_TEXT_LAYER (layer) && GIMP_TEXT_LAYER (layer)->text)
|
|
|
|
{
|
|
|
|
GimpTextLayer *text_layer = GIMP_TEXT_LAYER (layer);
|
|
|
|
guint32 flags = gimp_text_layer_get_xcf_flags (text_layer);
|
|
|
|
|
|
|
|
gimp_text_layer_xcf_save_prepare (text_layer);
|
|
|
|
|
|
|
|
if (flags)
|
|
|
|
xcf_check_error (xcf_save_prop (info,
|
2006-03-29 01:08:36 +08:00
|
|
|
image, PROP_TEXT_LAYER_FLAGS, error,
|
2004-03-18 23:27:23 +08:00
|
|
|
flags));
|
|
|
|
}
|
2003-06-24 21:59:36 +08:00
|
|
|
|
2011-09-26 03:57:20 +08:00
|
|
|
if (gimp_viewable_get_children (GIMP_VIEWABLE (layer)))
|
|
|
|
{
|
2011-10-08 02:05:52 +08:00
|
|
|
gint32 flags = 0;
|
|
|
|
|
|
|
|
if (gimp_viewable_get_expanded (GIMP_VIEWABLE (layer)))
|
|
|
|
flags |= XCF_GROUP_ITEM_EXPANDED;
|
2011-09-26 03:57:20 +08:00
|
|
|
|
|
|
|
xcf_check_error (xcf_save_prop (info,
|
|
|
|
image, PROP_GROUP_ITEM_FLAGS, error,
|
|
|
|
flags));
|
|
|
|
}
|
|
|
|
|
2011-02-01 06:51:18 +08:00
|
|
|
parasites = gimp_item_get_parasites (GIMP_ITEM (layer));
|
|
|
|
|
|
|
|
if (gimp_parasite_list_length (parasites) > 0)
|
2003-06-24 21:59:36 +08:00
|
|
|
{
|
2006-03-29 01:08:36 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_PARASITES, error,
|
2011-02-01 06:51:18 +08:00
|
|
|
parasites));
|
2003-06-24 21:59:36 +08:00
|
|
|
}
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_END, error));
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2002-12-20 14:26:34 +08:00
|
|
|
return TRUE;
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
|
2002-12-20 14:26:34 +08:00
|
|
|
static gboolean
|
2006-11-06 16:14:46 +08:00
|
|
|
xcf_save_channel_props (XcfInfo *info,
|
|
|
|
GimpImage *image,
|
|
|
|
GimpChannel *channel,
|
|
|
|
GError **error)
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
2011-02-01 06:51:18 +08:00
|
|
|
GimpParasiteList *parasites;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2021-06-20 06:00:53 +08:00
|
|
|
if (g_list_find (gimp_image_get_selected_channels (image), channel))
|
2006-03-29 01:08:36 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_ACTIVE_CHANNEL, error));
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2007-12-26 00:21:40 +08:00
|
|
|
if (channel == gimp_image_get_mask (image))
|
2006-03-29 01:08:36 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_SELECTION, error));
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_OPACITY, error,
|
2007-12-22 00:37:01 +08:00
|
|
|
gimp_channel_get_opacity (channel)));
|
2015-10-17 03:59:11 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_FLOAT_OPACITY, error,
|
|
|
|
gimp_channel_get_opacity (channel)));
|
2006-03-29 01:08:36 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_VISIBLE, error,
|
2006-04-12 20:49:29 +08:00
|
|
|
gimp_item_get_visible (GIMP_ITEM (channel))));
|
2006-03-29 01:08:36 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_LINKED, error,
|
2003-05-14 02:30:15 +08:00
|
|
|
gimp_item_get_linked (GIMP_ITEM (channel))));
|
2016-11-15 06:02:43 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_COLOR_TAG, error,
|
|
|
|
gimp_item_get_color_tag (GIMP_ITEM (channel))));
|
2009-08-30 18:44:35 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_LOCK_CONTENT, error,
|
|
|
|
gimp_item_get_lock_content (GIMP_ITEM (channel))));
|
2012-11-09 18:17:25 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_LOCK_POSITION, error,
|
|
|
|
gimp_item_get_lock_position (GIMP_ITEM (channel))));
|
2006-03-29 01:08:36 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_SHOW_MASKED, error,
|
2007-12-22 00:37:01 +08:00
|
|
|
gimp_channel_get_show_masked (channel)));
|
2017-03-25 05:35:57 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_COLOR, error,
|
|
|
|
&channel->color));
|
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_FLOAT_COLOR, error,
|
|
|
|
&channel->color));
|
2006-03-29 01:08:36 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_TATTOO, error,
|
2007-12-19 03:12:43 +08:00
|
|
|
gimp_item_get_tattoo (GIMP_ITEM (channel))));
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2011-02-01 06:51:18 +08:00
|
|
|
parasites = gimp_item_get_parasites (GIMP_ITEM (channel));
|
|
|
|
|
|
|
|
if (gimp_parasite_list_length (parasites) > 0)
|
|
|
|
{
|
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_PARASITES, error,
|
|
|
|
parasites));
|
|
|
|
}
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
xcf_check_error (xcf_save_prop (info, image, PROP_END, error));
|
2002-12-20 14:26:34 +08:00
|
|
|
|
|
|
|
return TRUE;
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
|
2002-12-20 14:26:34 +08:00
|
|
|
static gboolean
|
2006-11-06 16:14:46 +08:00
|
|
|
xcf_save_prop (XcfInfo *info,
|
|
|
|
GimpImage *image,
|
|
|
|
PropType prop_type,
|
|
|
|
GError **error,
|
2006-04-12 20:49:29 +08:00
|
|
|
...)
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
2017-03-23 20:02:36 +08:00
|
|
|
guint32 size;
|
|
|
|
va_list args;
|
|
|
|
GError *tmp_error = NULL;
|
2002-12-20 14:26:34 +08:00
|
|
|
|
|
|
|
va_start (args, error);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
switch (prop_type)
|
|
|
|
{
|
|
|
|
case PROP_END:
|
|
|
|
size = 0;
|
|
|
|
|
2004-01-26 17:22:06 +08:00
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
2003-09-11 00:33:59 +08:00
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2001-07-04 02:38:56 +08:00
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
case PROP_COLORMAP:
|
|
|
|
{
|
2017-03-23 20:02:36 +08:00
|
|
|
guint32 n_colors = va_arg (args, guint32);
|
|
|
|
guchar *colors = va_arg (args, guchar *);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2007-12-22 00:37:01 +08:00
|
|
|
size = 4 + n_colors * 3;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2004-01-26 17:22:06 +08:00
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
2006-04-12 20:49:29 +08:00
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2017-03-23 20:02:36 +08:00
|
|
|
|
2007-12-22 00:37:01 +08:00
|
|
|
xcf_write_int32_check_error (info, &n_colors, 1);
|
2017-03-23 20:02:36 +08:00
|
|
|
xcf_write_int8_check_error (info, colors, n_colors * 3);
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
case PROP_ACTIVE_LAYER:
|
|
|
|
case PROP_ACTIVE_CHANNEL:
|
|
|
|
case PROP_SELECTION:
|
2009-08-31 03:28:59 +08:00
|
|
|
case PROP_GROUP_ITEM:
|
2001-07-04 02:38:56 +08:00
|
|
|
size = 0;
|
|
|
|
|
2004-01-26 17:22:06 +08:00
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
2003-09-11 00:33:59 +08:00
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2001-07-04 02:38:56 +08:00
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
case PROP_FLOATING_SELECTION:
|
2017-03-23 20:02:36 +08:00
|
|
|
size = info->bytes_per_offset;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2017-03-23 20:02:36 +08:00
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2017-03-23 20:02:36 +08:00
|
|
|
info->floating_sel_offset = info->cp;
|
|
|
|
xcf_write_zero_offset_check_error (info, 1);
|
2001-07-04 02:38:56 +08:00
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
case PROP_OPACITY:
|
|
|
|
{
|
2017-03-23 20:02:36 +08:00
|
|
|
gdouble opacity = va_arg (args, gdouble);
|
|
|
|
guint32 uint_opacity = opacity * 255.999;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
size = 4;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2004-01-26 17:22:06 +08:00
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
2006-04-12 20:49:29 +08:00
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2017-03-23 20:02:36 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
xcf_write_int32_check_error (info, &uint_opacity, 1);
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2015-10-17 03:59:11 +08:00
|
|
|
case PROP_FLOAT_OPACITY:
|
|
|
|
{
|
2017-03-23 20:02:36 +08:00
|
|
|
gfloat opacity = va_arg (args, gdouble);
|
2015-10-17 03:59:11 +08:00
|
|
|
|
|
|
|
size = 4;
|
|
|
|
|
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2017-03-23 20:02:36 +08:00
|
|
|
|
2015-10-17 03:59:11 +08:00
|
|
|
xcf_write_float_check_error (info, &opacity, 1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
case PROP_MODE:
|
|
|
|
{
|
2017-03-23 20:02:36 +08:00
|
|
|
gint32 mode = va_arg (args, gint32);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
size = 4;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2017-01-09 08:27:20 +08:00
|
|
|
if (mode == GIMP_LAYER_MODE_OVERLAY_LEGACY)
|
|
|
|
mode = GIMP_LAYER_MODE_SOFTLIGHT_LEGACY;
|
2015-04-28 05:48:00 +08:00
|
|
|
|
2004-01-26 17:22:06 +08:00
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
2006-04-12 20:49:29 +08:00
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2017-03-23 20:02:36 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
xcf_write_int32_check_error (info, (guint32 *) &mode, 1);
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2017-02-13 06:49:26 +08:00
|
|
|
case PROP_BLEND_SPACE:
|
2017-02-02 07:38:25 +08:00
|
|
|
{
|
app: future-proof XCF layer blend/composite props
The layer blend space, composite space, and composite mode
properties have a special AUTO value, which may map to different
concrete values based on the layer mode. Make sure we can change
this mapping in the future, without affecting existing XCFs (saved
after this commit), by encoding these properties as follows:
When saving an XCF, if the property has a concrete (non-AUTO)
value, which is always positive, encode it as is. If the property
is AUTO, which is always 0, encode it as the negative of the value
it actually maps to at the time of saving (note that in some cases
AUTO may map to AUTO, in which case it's encoded as 0).
When loading an XCF, if the encoded property (stored in the file)
is nonnegative, use it as is. Otherwise, compare the negative of
the encoded property to the value AUTO maps to at the time of
loading. If the values are equal, set the property to AUTO;
otherwise, use the concrete value (i.e., the negative of the value
stored in the XCF).
Note that XCFs saved prior to this commit still load fine, it's
simply that if we change the AUTO mapping in the future, all their
AUTO properties will keep being loaded as AUTO, even if the
resulting concrete values will have changed.
2017-05-21 20:01:39 +08:00
|
|
|
GimpLayerMode mode = va_arg (args, GimpLayerMode);
|
|
|
|
gint32 blend_space = va_arg (args, gint32);
|
|
|
|
|
|
|
|
G_STATIC_ASSERT (GIMP_LAYER_COLOR_SPACE_AUTO == 0);
|
|
|
|
|
|
|
|
/* if blend_space is AUTO, save the negative of the actual value AUTO
|
|
|
|
* maps to for the given mode, so that we can correctly load it even if
|
|
|
|
* the mapping changes in the future.
|
|
|
|
*/
|
|
|
|
if (blend_space == GIMP_LAYER_COLOR_SPACE_AUTO)
|
|
|
|
blend_space = -gimp_layer_mode_get_blend_space (mode);
|
2017-02-02 07:38:25 +08:00
|
|
|
|
|
|
|
size = 4;
|
|
|
|
|
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2017-03-23 20:02:36 +08:00
|
|
|
|
2017-02-13 06:49:26 +08:00
|
|
|
xcf_write_int32_check_error (info, (guint32 *) &blend_space, 1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_COMPOSITE_SPACE:
|
|
|
|
{
|
app: future-proof XCF layer blend/composite props
The layer blend space, composite space, and composite mode
properties have a special AUTO value, which may map to different
concrete values based on the layer mode. Make sure we can change
this mapping in the future, without affecting existing XCFs (saved
after this commit), by encoding these properties as follows:
When saving an XCF, if the property has a concrete (non-AUTO)
value, which is always positive, encode it as is. If the property
is AUTO, which is always 0, encode it as the negative of the value
it actually maps to at the time of saving (note that in some cases
AUTO may map to AUTO, in which case it's encoded as 0).
When loading an XCF, if the encoded property (stored in the file)
is nonnegative, use it as is. Otherwise, compare the negative of
the encoded property to the value AUTO maps to at the time of
loading. If the values are equal, set the property to AUTO;
otherwise, use the concrete value (i.e., the negative of the value
stored in the XCF).
Note that XCFs saved prior to this commit still load fine, it's
simply that if we change the AUTO mapping in the future, all their
AUTO properties will keep being loaded as AUTO, even if the
resulting concrete values will have changed.
2017-05-21 20:01:39 +08:00
|
|
|
GimpLayerMode mode = va_arg (args, GimpLayerMode);
|
|
|
|
gint32 composite_space = va_arg (args, gint32);
|
|
|
|
|
|
|
|
G_STATIC_ASSERT (GIMP_LAYER_COLOR_SPACE_AUTO == 0);
|
|
|
|
|
|
|
|
/* if composite_space is AUTO, save the negative of the actual value
|
|
|
|
* AUTO maps to for the given mode, so that we can correctly load it
|
|
|
|
* even if the mapping changes in the future.
|
|
|
|
*/
|
|
|
|
if (composite_space == GIMP_LAYER_COLOR_SPACE_AUTO)
|
|
|
|
composite_space = -gimp_layer_mode_get_composite_space (mode);
|
2017-02-13 06:49:26 +08:00
|
|
|
|
|
|
|
size = 4;
|
|
|
|
|
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2017-03-23 20:02:36 +08:00
|
|
|
|
2017-02-13 06:49:26 +08:00
|
|
|
xcf_write_int32_check_error (info, (guint32 *) &composite_space, 1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_COMPOSITE_MODE:
|
|
|
|
{
|
app: future-proof XCF layer blend/composite props
The layer blend space, composite space, and composite mode
properties have a special AUTO value, which may map to different
concrete values based on the layer mode. Make sure we can change
this mapping in the future, without affecting existing XCFs (saved
after this commit), by encoding these properties as follows:
When saving an XCF, if the property has a concrete (non-AUTO)
value, which is always positive, encode it as is. If the property
is AUTO, which is always 0, encode it as the negative of the value
it actually maps to at the time of saving (note that in some cases
AUTO may map to AUTO, in which case it's encoded as 0).
When loading an XCF, if the encoded property (stored in the file)
is nonnegative, use it as is. Otherwise, compare the negative of
the encoded property to the value AUTO maps to at the time of
loading. If the values are equal, set the property to AUTO;
otherwise, use the concrete value (i.e., the negative of the value
stored in the XCF).
Note that XCFs saved prior to this commit still load fine, it's
simply that if we change the AUTO mapping in the future, all their
AUTO properties will keep being loaded as AUTO, even if the
resulting concrete values will have changed.
2017-05-21 20:01:39 +08:00
|
|
|
GimpLayerMode mode = va_arg (args, GimpLayerMode);
|
|
|
|
gint32 composite_mode = va_arg (args, gint32);
|
|
|
|
|
|
|
|
G_STATIC_ASSERT (GIMP_LAYER_COMPOSITE_AUTO == 0);
|
|
|
|
|
|
|
|
/* if composite_mode is AUTO, save the negative of the actual value
|
|
|
|
* AUTO maps to for the given mode, so that we can correctly load it
|
|
|
|
* even if the mapping changes in the future.
|
|
|
|
*/
|
|
|
|
if (composite_mode == GIMP_LAYER_COMPOSITE_AUTO)
|
|
|
|
composite_mode = -gimp_layer_mode_get_composite_mode (mode);
|
2017-02-13 06:49:26 +08:00
|
|
|
|
|
|
|
size = 4;
|
|
|
|
|
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2017-03-23 20:02:36 +08:00
|
|
|
|
2017-02-13 06:49:26 +08:00
|
|
|
xcf_write_int32_check_error (info, (guint32 *) &composite_mode, 1);
|
2017-02-02 07:38:25 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
case PROP_VISIBLE:
|
|
|
|
{
|
2017-03-23 20:02:36 +08:00
|
|
|
guint32 visible = va_arg (args, guint32);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
size = 4;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2004-01-26 17:22:06 +08:00
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
2006-04-12 20:49:29 +08:00
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2017-03-23 20:02:36 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
xcf_write_int32_check_error (info, &visible, 1);
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
case PROP_LINKED:
|
|
|
|
{
|
2017-03-23 20:02:36 +08:00
|
|
|
guint32 linked = va_arg (args, guint32);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
size = 4;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2004-01-26 17:22:06 +08:00
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
2006-04-12 20:49:29 +08:00
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2017-03-23 20:02:36 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
xcf_write_int32_check_error (info, &linked, 1);
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2016-11-15 06:02:43 +08:00
|
|
|
case PROP_COLOR_TAG:
|
|
|
|
{
|
2017-03-23 20:02:36 +08:00
|
|
|
guint32 color_tag = va_arg (args, gint32);
|
2016-11-15 06:02:43 +08:00
|
|
|
|
|
|
|
size = 4;
|
|
|
|
|
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2017-03-23 20:02:36 +08:00
|
|
|
|
2016-11-15 06:02:43 +08:00
|
|
|
xcf_write_int32_check_error (info, &color_tag, 1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-08-30 18:44:35 +08:00
|
|
|
case PROP_LOCK_CONTENT:
|
|
|
|
{
|
2017-03-23 20:02:36 +08:00
|
|
|
guint32 lock_content = va_arg (args, guint32);
|
2009-08-30 18:44:35 +08:00
|
|
|
|
|
|
|
size = 4;
|
|
|
|
|
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2017-03-23 20:02:36 +08:00
|
|
|
|
2009-08-30 18:44:35 +08:00
|
|
|
xcf_write_int32_check_error (info, &lock_content, 1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-07-11 05:17:22 +08:00
|
|
|
case PROP_LOCK_ALPHA:
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
2017-03-23 20:02:36 +08:00
|
|
|
guint32 lock_alpha = va_arg (args, guint32);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
size = 4;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2004-01-26 17:22:06 +08:00
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
2006-04-12 20:49:29 +08:00
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2017-03-23 20:02:36 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
xcf_write_int32_check_error (info, &lock_alpha, 1);
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2012-11-09 18:17:25 +08:00
|
|
|
case PROP_LOCK_POSITION:
|
|
|
|
{
|
2017-03-23 20:02:36 +08:00
|
|
|
guint32 lock_position = va_arg (args, guint32);
|
2012-11-09 18:17:25 +08:00
|
|
|
|
|
|
|
size = 4;
|
|
|
|
|
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2017-03-23 20:02:36 +08:00
|
|
|
|
2012-11-09 18:17:25 +08:00
|
|
|
xcf_write_int32_check_error (info, &lock_position, 1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
case PROP_APPLY_MASK:
|
|
|
|
{
|
2017-03-23 20:02:36 +08:00
|
|
|
guint32 apply_mask = va_arg (args, guint32);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
size = 4;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2004-01-26 17:22:06 +08:00
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
2006-04-12 20:49:29 +08:00
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2017-03-23 20:02:36 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
xcf_write_int32_check_error (info, &apply_mask, 1);
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
case PROP_EDIT_MASK:
|
|
|
|
{
|
2017-03-23 20:02:36 +08:00
|
|
|
guint32 edit_mask = va_arg (args, guint32);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
size = 4;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2004-01-26 17:22:06 +08:00
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
2006-04-12 20:49:29 +08:00
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2017-03-23 20:02:36 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
xcf_write_int32_check_error (info, &edit_mask, 1);
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
case PROP_SHOW_MASK:
|
|
|
|
{
|
2017-03-23 20:02:36 +08:00
|
|
|
guint32 show_mask = va_arg (args, guint32);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
size = 4;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2004-01-26 17:22:06 +08:00
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
2006-04-12 20:49:29 +08:00
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2017-03-23 20:02:36 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
xcf_write_int32_check_error (info, &show_mask, 1);
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
case PROP_SHOW_MASKED:
|
|
|
|
{
|
2017-03-23 20:02:36 +08:00
|
|
|
guint32 show_masked = va_arg (args, guint32);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
size = 4;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2004-01-26 17:22:06 +08:00
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
2006-04-12 20:49:29 +08:00
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2017-03-23 20:02:36 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
xcf_write_int32_check_error (info, &show_masked, 1);
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
case PROP_OFFSETS:
|
|
|
|
{
|
2006-04-12 20:49:29 +08:00
|
|
|
gint32 offsets[2];
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
offsets[0] = va_arg (args, gint32);
|
|
|
|
offsets[1] = va_arg (args, gint32);
|
2017-03-23 20:02:36 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
size = 8;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2004-01-26 17:22:06 +08:00
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
2006-04-12 20:49:29 +08:00
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2017-03-23 20:02:36 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
xcf_write_int32_check_error (info, (guint32 *) offsets, 2);
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
case PROP_COLOR:
|
|
|
|
{
|
2017-03-25 05:35:57 +08:00
|
|
|
GimpRGB *color = va_arg (args, GimpRGB *);
|
|
|
|
guchar col[3];
|
|
|
|
|
|
|
|
gimp_rgb_get_uchar (color, &col[0], &col[1], &col[2]);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
size = 3;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2004-01-26 17:22:06 +08:00
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
2006-04-12 20:49:29 +08:00
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2017-03-23 20:02:36 +08:00
|
|
|
|
2017-03-25 05:35:57 +08:00
|
|
|
xcf_write_int8_check_error (info, col, 3);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_FLOAT_COLOR:
|
|
|
|
{
|
|
|
|
GimpRGB *color = va_arg (args, GimpRGB *);
|
|
|
|
gfloat col[3];
|
|
|
|
|
|
|
|
col[0] = color->r;
|
|
|
|
col[1] = color->g;
|
|
|
|
col[2] = color->b;
|
|
|
|
|
|
|
|
size = 3 * 4;
|
|
|
|
|
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
|
|
|
|
|
|
|
xcf_write_float_check_error (info, col, 3);
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
case PROP_COMPRESSION:
|
|
|
|
{
|
2017-03-23 20:02:36 +08:00
|
|
|
guint8 compression = (guint8) va_arg (args, guint32);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
size = 1;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2004-01-26 17:22:06 +08:00
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
2006-04-12 20:49:29 +08:00
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2017-03-23 20:02:36 +08:00
|
|
|
|
|
|
|
xcf_write_int8_check_error (info, &compression, 1);
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
case PROP_GUIDES:
|
|
|
|
{
|
2017-03-23 20:02:36 +08:00
|
|
|
GList *guides = va_arg (args, GList *);
|
|
|
|
gint n_guides = g_list_length (guides);
|
2015-12-15 09:54:04 +08:00
|
|
|
GList *iter;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2015-12-15 09:54:04 +08:00
|
|
|
for (iter = guides; iter; iter = g_list_next (iter))
|
|
|
|
{
|
|
|
|
/* Do not save custom guides. */
|
|
|
|
if (gimp_guide_is_custom (GIMP_GUIDE (iter->data)))
|
|
|
|
n_guides--;
|
|
|
|
}
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2017-03-23 20:02:36 +08:00
|
|
|
if (n_guides > 0)
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
2017-03-23 20:02:36 +08:00
|
|
|
size = n_guides * (4 + 1);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2017-03-23 20:02:36 +08:00
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2015-12-15 09:54:04 +08:00
|
|
|
|
2017-03-23 20:02:36 +08:00
|
|
|
for (; guides; guides = g_list_next (guides))
|
2003-02-08 01:12:21 +08:00
|
|
|
{
|
2017-03-23 20:02:36 +08:00
|
|
|
GimpGuide *guide = guides->data;
|
|
|
|
gint32 position = gimp_guide_get_position (guide);
|
|
|
|
gint8 orientation;
|
|
|
|
|
|
|
|
if (gimp_guide_is_custom (guide))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch (gimp_guide_get_orientation (guide))
|
|
|
|
{
|
|
|
|
case GIMP_ORIENTATION_HORIZONTAL:
|
|
|
|
orientation = XCF_ORIENTATION_HORIZONTAL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_ORIENTATION_VERTICAL:
|
|
|
|
orientation = XCF_ORIENTATION_VERTICAL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_warning ("%s: skipping guide with bad orientation",
|
|
|
|
G_STRFUNC);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
xcf_write_int32_check_error (info, (guint32 *) &position, 1);
|
|
|
|
xcf_write_int8_check_error (info, (guint8 *) &orientation, 1);
|
2003-02-08 01:12:21 +08:00
|
|
|
}
|
2006-04-12 20:49:29 +08:00
|
|
|
}
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
2006-08-11 01:10:12 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_SAMPLE_POINTS:
|
|
|
|
{
|
2018-07-16 07:42:19 +08:00
|
|
|
GList *sample_points = va_arg (args, GList *);
|
|
|
|
gint n_sample_points = g_list_length (sample_points);
|
|
|
|
|
|
|
|
size = n_sample_points * (5 * 4);
|
|
|
|
|
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
|
|
|
|
|
|
|
for (; sample_points; sample_points = g_list_next (sample_points))
|
|
|
|
{
|
|
|
|
GimpSamplePoint *sample_point = sample_points->data;
|
|
|
|
gint32 x, y;
|
|
|
|
GimpColorPickMode pick_mode;
|
|
|
|
guint32 padding[2] = { 0, };
|
|
|
|
|
|
|
|
gimp_sample_point_get_position (sample_point, &x, &y);
|
|
|
|
pick_mode = gimp_sample_point_get_pick_mode (sample_point);
|
|
|
|
|
|
|
|
xcf_write_int32_check_error (info, (guint32 *) &x, 1);
|
|
|
|
xcf_write_int32_check_error (info, (guint32 *) &y, 1);
|
|
|
|
xcf_write_int32_check_error (info, (guint32 *) &pick_mode, 1);
|
|
|
|
xcf_write_int32_check_error (info, (guint32 *) padding, 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROP_OLD_SAMPLE_POINTS:
|
|
|
|
{
|
2017-03-23 20:02:36 +08:00
|
|
|
GList *sample_points = va_arg (args, GList *);
|
|
|
|
gint n_sample_points = g_list_length (sample_points);
|
2006-08-11 01:10:12 +08:00
|
|
|
|
|
|
|
size = n_sample_points * (4 + 4);
|
|
|
|
|
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
|
|
|
|
|
|
|
for (; sample_points; sample_points = g_list_next (sample_points))
|
|
|
|
{
|
|
|
|
GimpSamplePoint *sample_point = sample_points->data;
|
|
|
|
gint32 x, y;
|
|
|
|
|
2016-01-05 05:06:27 +08:00
|
|
|
gimp_sample_point_get_position (sample_point, &x, &y);
|
2006-08-11 01:10:12 +08:00
|
|
|
|
2007-12-22 00:37:01 +08:00
|
|
|
xcf_write_int32_check_error (info, (guint32 *) &x, 1);
|
|
|
|
xcf_write_int32_check_error (info, (guint32 *) &y, 1);
|
2006-08-11 01:10:12 +08:00
|
|
|
}
|
|
|
|
}
|
2001-07-04 02:38:56 +08:00
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
case PROP_RESOLUTION:
|
|
|
|
{
|
2017-03-23 20:02:36 +08:00
|
|
|
gfloat resolution[2];
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2017-03-23 20:02:36 +08:00
|
|
|
resolution[0] = va_arg (args, double);
|
|
|
|
resolution[1] = va_arg (args, double);
|
2003-09-10 18:40:57 +08:00
|
|
|
|
2017-03-23 20:02:36 +08:00
|
|
|
size = 2 * 4;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2004-01-26 17:22:06 +08:00
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
2006-04-12 20:49:29 +08:00
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2017-03-23 20:02:36 +08:00
|
|
|
xcf_write_float_check_error (info, resolution, 2);
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
case PROP_TATTOO:
|
|
|
|
{
|
2017-03-23 20:02:36 +08:00
|
|
|
guint32 tattoo = va_arg (args, guint32);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
size = 4;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2004-01-26 17:22:06 +08:00
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
2006-04-12 20:49:29 +08:00
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2017-03-23 20:02:36 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
xcf_write_int32_check_error (info, &tattoo, 1);
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
case PROP_PARASITES:
|
|
|
|
{
|
2017-03-23 20:02:36 +08:00
|
|
|
GimpParasiteList *list = va_arg (args, GimpParasiteList *);
|
2001-07-05 06:59:25 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
if (gimp_parasite_list_persistent_length (list) > 0)
|
|
|
|
{
|
2017-03-23 18:44:41 +08:00
|
|
|
goffset base;
|
|
|
|
goffset pos;
|
2017-03-23 20:02:36 +08:00
|
|
|
|
|
|
|
size = 0;
|
2012-08-04 09:20:36 +08:00
|
|
|
|
2004-01-26 17:22:06 +08:00
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
|
|
|
|
2017-03-23 18:44:41 +08:00
|
|
|
/* because we don't know how much room the parasite list
|
|
|
|
* will take we save the file position and write the
|
|
|
|
* length later
|
2006-04-12 20:49:29 +08:00
|
|
|
*/
|
2001-07-19 23:34:19 +08:00
|
|
|
pos = info->cp;
|
2017-03-23 20:02:36 +08:00
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2017-03-23 18:44:41 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
base = info->cp;
|
2003-09-11 00:22:33 +08:00
|
|
|
|
|
|
|
xcf_check_error (xcf_save_parasite_list (info, list, error));
|
|
|
|
|
2017-03-23 20:02:36 +08:00
|
|
|
size = info->cp - base;
|
2014-10-16 05:36:06 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
/* go back to the saved position and write the length */
|
2002-12-20 14:26:34 +08:00
|
|
|
xcf_check_error (xcf_seek_pos (info, pos, error));
|
2017-03-23 20:02:36 +08:00
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2003-09-10 18:40:57 +08:00
|
|
|
|
2017-03-23 20:02:36 +08:00
|
|
|
xcf_check_error (xcf_seek_pos (info, base + size, error));
|
2006-04-12 20:49:29 +08:00
|
|
|
}
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
case PROP_UNIT:
|
|
|
|
{
|
2017-03-23 20:02:36 +08:00
|
|
|
guint32 unit = va_arg (args, guint32);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
size = 4;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2004-01-26 17:22:06 +08:00
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
2006-04-12 20:49:29 +08:00
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2017-03-23 20:02:36 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
xcf_write_int32_check_error (info, &unit, 1);
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
case PROP_PATHS:
|
|
|
|
{
|
2017-03-23 18:44:41 +08:00
|
|
|
goffset base;
|
|
|
|
goffset pos;
|
2017-03-23 20:02:36 +08:00
|
|
|
|
|
|
|
size = 0;
|
2003-05-22 01:38:14 +08:00
|
|
|
|
2004-01-26 17:22:06 +08:00
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
2003-05-22 01:38:14 +08:00
|
|
|
|
2017-03-23 18:44:41 +08:00
|
|
|
/* because we don't know how much room the paths list will
|
|
|
|
* take we save the file position and write the length later
|
2004-01-26 17:22:06 +08:00
|
|
|
*/
|
2003-05-22 01:38:14 +08:00
|
|
|
pos = info->cp;
|
2017-03-23 20:02:36 +08:00
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2001-07-19 23:34:19 +08:00
|
|
|
|
2003-05-22 01:38:14 +08:00
|
|
|
base = info->cp;
|
2001-07-19 23:34:19 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
xcf_check_error (xcf_save_old_paths (info, image, error));
|
2003-05-22 01:38:14 +08:00
|
|
|
|
2017-03-23 20:02:36 +08:00
|
|
|
size = info->cp - base;
|
2003-05-22 01:38:14 +08:00
|
|
|
|
|
|
|
/* go back to the saved position and write the length */
|
|
|
|
xcf_check_error (xcf_seek_pos (info, pos, error));
|
2017-03-23 20:02:36 +08:00
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2003-05-22 01:38:14 +08:00
|
|
|
|
2017-03-23 20:02:36 +08:00
|
|
|
xcf_check_error (xcf_seek_pos (info, base + size, error));
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
case PROP_USER_UNIT:
|
|
|
|
{
|
2017-03-23 20:02:36 +08:00
|
|
|
GimpUnit unit = va_arg (args, guint32);
|
2006-04-12 20:49:29 +08:00
|
|
|
const gchar *unit_strings[5];
|
|
|
|
gfloat factor;
|
|
|
|
guint32 digits;
|
|
|
|
|
|
|
|
/* write the entire unit definition */
|
2010-02-21 23:46:39 +08:00
|
|
|
unit_strings[0] = gimp_unit_get_identifier (unit);
|
|
|
|
factor = gimp_unit_get_factor (unit);
|
|
|
|
digits = gimp_unit_get_digits (unit);
|
|
|
|
unit_strings[1] = gimp_unit_get_symbol (unit);
|
|
|
|
unit_strings[2] = gimp_unit_get_abbreviation (unit);
|
|
|
|
unit_strings[3] = gimp_unit_get_singular (unit);
|
|
|
|
unit_strings[4] = gimp_unit_get_plural (unit);
|
2006-04-12 20:49:29 +08:00
|
|
|
|
|
|
|
size =
|
|
|
|
2 * 4 +
|
|
|
|
strlen (unit_strings[0]) ? strlen (unit_strings[0]) + 5 : 4 +
|
|
|
|
strlen (unit_strings[1]) ? strlen (unit_strings[1]) + 5 : 4 +
|
|
|
|
strlen (unit_strings[2]) ? strlen (unit_strings[2]) + 5 : 4 +
|
|
|
|
strlen (unit_strings[3]) ? strlen (unit_strings[3]) + 5 : 4 +
|
|
|
|
strlen (unit_strings[4]) ? strlen (unit_strings[4]) + 5 : 4;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2004-01-26 17:22:06 +08:00
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
2006-04-12 20:49:29 +08:00
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2017-03-23 20:02:36 +08:00
|
|
|
|
|
|
|
xcf_write_float_check_error (info, &factor, 1);
|
|
|
|
xcf_write_int32_check_error (info, &digits, 1);
|
2006-04-12 20:49:29 +08:00
|
|
|
xcf_write_string_check_error (info, (gchar **) unit_strings, 5);
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2003-09-09 23:46:59 +08:00
|
|
|
case PROP_VECTORS:
|
|
|
|
{
|
2017-03-23 18:44:41 +08:00
|
|
|
goffset base;
|
|
|
|
goffset pos;
|
2017-03-23 20:02:36 +08:00
|
|
|
|
|
|
|
size = 0;
|
2003-09-09 23:46:59 +08:00
|
|
|
|
2004-01-26 17:22:06 +08:00
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
2003-09-09 23:46:59 +08:00
|
|
|
|
2017-03-23 18:44:41 +08:00
|
|
|
/* because we don't know how much room the paths list will
|
|
|
|
* take we save the file position and write the length later
|
2004-01-26 17:22:06 +08:00
|
|
|
*/
|
2003-09-09 23:46:59 +08:00
|
|
|
pos = info->cp;
|
2017-03-23 20:02:36 +08:00
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2003-09-09 23:46:59 +08:00
|
|
|
|
|
|
|
base = info->cp;
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
xcf_check_error (xcf_save_vectors (info, image, error));
|
2003-09-09 23:46:59 +08:00
|
|
|
|
2017-03-23 20:02:36 +08:00
|
|
|
size = info->cp - base;
|
2003-09-09 23:46:59 +08:00
|
|
|
|
|
|
|
/* go back to the saved position and write the length */
|
|
|
|
xcf_check_error (xcf_seek_pos (info, pos, error));
|
2017-03-23 20:02:36 +08:00
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2003-09-09 23:46:59 +08:00
|
|
|
|
2017-03-23 20:02:36 +08:00
|
|
|
xcf_check_error (xcf_seek_pos (info, base + size, error));
|
2003-09-09 23:46:59 +08:00
|
|
|
}
|
|
|
|
break;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
|
|
|
case PROP_TEXT_LAYER_FLAGS:
|
|
|
|
{
|
2017-03-23 20:02:36 +08:00
|
|
|
guint32 flags = va_arg (args, guint32);
|
2004-03-18 23:27:23 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
size = 4;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
2006-04-12 20:49:29 +08:00
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
2017-03-23 20:02:36 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
xcf_write_int32_check_error (info, &flags, 1);
|
2004-03-18 23:27:23 +08:00
|
|
|
}
|
|
|
|
break;
|
2009-08-31 03:28:59 +08:00
|
|
|
|
|
|
|
case PROP_ITEM_PATH:
|
|
|
|
{
|
2017-03-23 20:02:36 +08:00
|
|
|
GList *path = va_arg (args, GList *);
|
2009-08-31 03:28:59 +08:00
|
|
|
|
|
|
|
size = 4 * g_list_length (path);
|
|
|
|
|
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
|
|
|
|
|
|
|
while (path)
|
|
|
|
{
|
|
|
|
guint32 index = GPOINTER_TO_UINT (path->data);
|
|
|
|
|
|
|
|
xcf_write_int32_check_error (info, &index, 1);
|
|
|
|
|
|
|
|
path = g_list_next (path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2011-09-26 03:57:20 +08:00
|
|
|
|
|
|
|
case PROP_GROUP_ITEM_FLAGS:
|
|
|
|
{
|
2017-03-23 20:02:36 +08:00
|
|
|
guint32 flags = va_arg (args, guint32);
|
2011-09-26 03:57:20 +08:00
|
|
|
|
|
|
|
size = 4;
|
|
|
|
|
|
|
|
xcf_write_prop_type_check_error (info, prop_type);
|
|
|
|
xcf_write_int32_check_error (info, &size, 1);
|
|
|
|
xcf_write_int32_check_error (info, &flags, 1);
|
|
|
|
}
|
|
|
|
break;
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
va_end (args);
|
2002-12-20 14:26:34 +08:00
|
|
|
|
|
|
|
return TRUE;
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
|
2002-12-20 14:26:34 +08:00
|
|
|
static gboolean
|
2006-11-06 16:14:46 +08:00
|
|
|
xcf_save_layer (XcfInfo *info,
|
|
|
|
GimpImage *image,
|
|
|
|
GimpLayer *layer,
|
|
|
|
GError **error)
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
2017-03-23 18:44:41 +08:00
|
|
|
goffset saved_pos;
|
|
|
|
goffset offset;
|
2007-12-22 00:37:01 +08:00
|
|
|
guint32 value;
|
|
|
|
const gchar *string;
|
|
|
|
GError *tmp_error = NULL;
|
2002-12-20 14:26:34 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
/* check and see if this is the drawable that the floating
|
|
|
|
* selection is attached to.
|
|
|
|
*/
|
2003-06-24 21:59:36 +08:00
|
|
|
if (GIMP_DRAWABLE (layer) == info->floating_sel_drawable)
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
|
|
|
saved_pos = info->cp;
|
2002-12-20 14:26:34 +08:00
|
|
|
xcf_check_error (xcf_seek_pos (info, info->floating_sel_offset, error));
|
2017-03-23 18:44:41 +08:00
|
|
|
xcf_write_offset_check_error (info, &saved_pos, 1);
|
2002-12-20 14:26:34 +08:00
|
|
|
xcf_check_error (xcf_seek_pos (info, saved_pos, error));
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* write out the width, height and image type information for the layer */
|
2008-11-03 08:09:01 +08:00
|
|
|
value = gimp_item_get_width (GIMP_ITEM (layer));
|
2007-12-22 00:37:01 +08:00
|
|
|
xcf_write_int32_check_error (info, &value, 1);
|
|
|
|
|
2008-11-03 08:09:01 +08:00
|
|
|
value = gimp_item_get_height (GIMP_ITEM (layer));
|
2007-12-22 00:37:01 +08:00
|
|
|
xcf_write_int32_check_error (info, &value, 1);
|
2007-04-12 22:48:04 +08:00
|
|
|
|
2012-04-11 07:12:08 +08:00
|
|
|
value = gimp_babl_format_get_image_type (gimp_drawable_get_format (GIMP_DRAWABLE (layer)));
|
2007-04-12 22:48:04 +08:00
|
|
|
xcf_write_int32_check_error (info, &value, 1);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
/* write out the layers name */
|
2009-09-01 04:47:18 +08:00
|
|
|
string = gimp_object_get_name (layer);
|
2007-12-22 00:37:01 +08:00
|
|
|
xcf_write_string_check_error (info, (gchar **) &string, 1);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
/* write out the layer properties */
|
2006-03-29 01:08:36 +08:00
|
|
|
xcf_save_layer_props (info, image, layer, error);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2014-10-18 01:12:05 +08:00
|
|
|
/* write out the layer tile hierarchy */
|
2017-03-23 18:44:41 +08:00
|
|
|
offset = info->cp + 2 * info->bytes_per_offset;
|
|
|
|
xcf_write_offset_check_error (info, &offset, 1);
|
2014-10-16 05:15:18 +08:00
|
|
|
|
|
|
|
saved_pos = info->cp;
|
2014-10-18 01:12:05 +08:00
|
|
|
|
|
|
|
/* write a zero layer mask offset */
|
2017-03-23 18:44:41 +08:00
|
|
|
xcf_write_zero_offset_check_error (info, 1);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2012-04-03 06:00:15 +08:00
|
|
|
xcf_check_error (xcf_save_buffer (info,
|
|
|
|
gimp_drawable_get_buffer (GIMP_DRAWABLE (layer)),
|
|
|
|
error));
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2014-10-16 05:15:18 +08:00
|
|
|
offset = info->cp;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
/* write out the layer mask */
|
2007-12-22 00:37:01 +08:00
|
|
|
if (gimp_layer_get_mask (layer))
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
2007-12-22 00:37:01 +08:00
|
|
|
GimpLayerMask *mask = gimp_layer_get_mask (layer);
|
|
|
|
|
2014-10-18 01:12:05 +08:00
|
|
|
xcf_check_error (xcf_seek_pos (info, saved_pos, error));
|
2017-03-23 18:44:41 +08:00
|
|
|
xcf_write_offset_check_error (info, &offset, 1);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2014-10-18 01:12:05 +08:00
|
|
|
xcf_check_error (xcf_seek_pos (info, offset, error));
|
2007-12-22 00:37:01 +08:00
|
|
|
xcf_check_error (xcf_save_channel (info, image, GIMP_CHANNEL (mask),
|
2003-04-10 22:15:24 +08:00
|
|
|
error));
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
2002-12-20 14:26:34 +08:00
|
|
|
|
|
|
|
return TRUE;
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
|
2002-12-20 14:26:34 +08:00
|
|
|
static gboolean
|
|
|
|
xcf_save_channel (XcfInfo *info,
|
2006-04-12 20:49:29 +08:00
|
|
|
GimpImage *image,
|
|
|
|
GimpChannel *channel,
|
|
|
|
GError **error)
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
2017-03-23 18:44:41 +08:00
|
|
|
goffset saved_pos;
|
|
|
|
goffset offset;
|
2007-12-22 00:37:01 +08:00
|
|
|
guint32 value;
|
|
|
|
const gchar *string;
|
|
|
|
GError *tmp_error = NULL;
|
2002-12-20 14:26:34 +08:00
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
/* check and see if this is the drawable that the floating
|
|
|
|
* selection is attached to.
|
|
|
|
*/
|
2001-07-19 23:34:19 +08:00
|
|
|
if (GIMP_DRAWABLE (channel) == info->floating_sel_drawable)
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
|
|
|
saved_pos = info->cp;
|
2002-12-20 14:26:34 +08:00
|
|
|
xcf_check_error (xcf_seek_pos (info, info->floating_sel_offset, error));
|
2017-03-23 18:44:41 +08:00
|
|
|
xcf_write_offset_check_error (info, &saved_pos, 1);
|
2002-12-20 14:26:34 +08:00
|
|
|
xcf_check_error (xcf_seek_pos (info, saved_pos, error));
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* write out the width and height information for the channel */
|
2008-11-03 08:09:01 +08:00
|
|
|
value = gimp_item_get_width (GIMP_ITEM (channel));
|
2007-12-22 00:37:01 +08:00
|
|
|
xcf_write_int32_check_error (info, &value, 1);
|
|
|
|
|
2008-11-03 08:09:01 +08:00
|
|
|
value = gimp_item_get_height (GIMP_ITEM (channel));
|
2007-12-22 00:37:01 +08:00
|
|
|
xcf_write_int32_check_error (info, &value, 1);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
/* write out the channels name */
|
2009-09-01 04:47:18 +08:00
|
|
|
string = gimp_object_get_name (channel);
|
2007-12-22 00:37:01 +08:00
|
|
|
xcf_write_string_check_error (info, (gchar **) &string, 1);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
/* write out the channel properties */
|
2006-03-29 01:08:36 +08:00
|
|
|
xcf_save_channel_props (info, image, channel, error);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
/* write out the channel tile hierarchy */
|
2017-03-23 18:44:41 +08:00
|
|
|
offset = info->cp + info->bytes_per_offset;
|
|
|
|
xcf_write_offset_check_error (info, &offset, 1);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2012-04-03 06:00:15 +08:00
|
|
|
xcf_check_error (xcf_save_buffer (info,
|
|
|
|
gimp_drawable_get_buffer (GIMP_DRAWABLE (channel)),
|
|
|
|
error));
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2002-12-20 14:26:34 +08:00
|
|
|
return TRUE;
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
xcf_calc_levels (gint size,
|
2006-04-12 20:49:29 +08:00
|
|
|
gint tile_size)
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
2017-03-23 18:44:41 +08:00
|
|
|
gint levels;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
levels = 1;
|
|
|
|
while (size > tile_size)
|
|
|
|
{
|
|
|
|
size /= 2;
|
|
|
|
levels += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return levels;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-12-20 14:26:34 +08:00
|
|
|
static gboolean
|
2012-04-03 06:00:15 +08:00
|
|
|
xcf_save_buffer (XcfInfo *info,
|
|
|
|
GeglBuffer *buffer,
|
|
|
|
GError **error)
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
2012-04-03 06:00:15 +08:00
|
|
|
const Babl *format;
|
2017-03-23 18:44:41 +08:00
|
|
|
goffset saved_pos;
|
|
|
|
goffset offset;
|
2012-04-03 06:00:15 +08:00
|
|
|
guint32 width;
|
|
|
|
guint32 height;
|
|
|
|
guint32 bpp;
|
|
|
|
gint i;
|
|
|
|
gint nlevels;
|
|
|
|
gint tmp1, tmp2;
|
|
|
|
GError *tmp_error = NULL;
|
|
|
|
|
|
|
|
format = gegl_buffer_get_format (buffer);
|
|
|
|
|
|
|
|
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
|
|
|
|
2017-03-23 19:42:38 +08:00
|
|
|
xcf_write_int32_check_error (info, (guint32 *) &width, 1);
|
2003-09-11 00:33:59 +08:00
|
|
|
xcf_write_int32_check_error (info, (guint32 *) &height, 1);
|
2017-03-23 19:42:38 +08:00
|
|
|
xcf_write_int32_check_error (info, (guint32 *) &bpp, 1);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2012-04-03 06:00:15 +08:00
|
|
|
tmp1 = xcf_calc_levels (width, XCF_TILE_WIDTH);
|
|
|
|
tmp2 = xcf_calc_levels (height, XCF_TILE_HEIGHT);
|
2001-07-04 02:38:56 +08:00
|
|
|
nlevels = MAX (tmp1, tmp2);
|
|
|
|
|
2014-10-18 01:12:05 +08:00
|
|
|
/* 'saved_pos' is the next slot in the offset table */
|
|
|
|
saved_pos = info->cp;
|
|
|
|
|
|
|
|
/* write an empty offset table */
|
2017-03-23 18:44:41 +08:00
|
|
|
xcf_write_zero_offset_check_error (info, nlevels + 1);
|
2014-10-18 01:12:05 +08:00
|
|
|
|
|
|
|
/* 'offset' is where we will write the next level */
|
|
|
|
offset = info->cp;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2003-09-10 18:40:57 +08:00
|
|
|
for (i = 0; i < nlevels; i++)
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
2014-10-18 01:12:05 +08:00
|
|
|
/* seek back to the next slot in the offset table and write the
|
|
|
|
* offset of the level
|
|
|
|
*/
|
|
|
|
xcf_check_error (xcf_seek_pos (info, saved_pos, error));
|
2017-03-23 18:44:41 +08:00
|
|
|
xcf_write_offset_check_error (info, &offset, 1);
|
2014-10-16 05:15:18 +08:00
|
|
|
|
2014-10-18 01:12:05 +08:00
|
|
|
/* remember the next slot in the offset table */
|
2014-10-16 05:15:18 +08:00
|
|
|
saved_pos = info->cp;
|
|
|
|
|
|
|
|
/* seek to the level offset and save the level */
|
|
|
|
xcf_check_error (xcf_seek_pos (info, offset, error));
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2003-09-10 18:40:57 +08:00
|
|
|
if (i == 0)
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
|
|
|
/* write out the level. */
|
2012-04-03 06:00:15 +08:00
|
|
|
xcf_check_error (xcf_save_level (info, buffer, error));
|
2006-04-12 20:49:29 +08:00
|
|
|
}
|
2003-09-10 18:40:57 +08:00
|
|
|
else
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
|
|
|
/* fake an empty level */
|
|
|
|
tmp1 = 0;
|
|
|
|
width /= 2;
|
|
|
|
height /= 2;
|
|
|
|
xcf_write_int32_check_error (info, (guint32 *) &width, 1);
|
|
|
|
xcf_write_int32_check_error (info, (guint32 *) &height, 1);
|
2018-12-05 00:57:40 +08:00
|
|
|
|
|
|
|
/* NOTE: this should be an offset, not an int32! however...
|
|
|
|
* since there are already 64-bit-offsets XCFs out there in
|
|
|
|
* which this field is 32-bit, and since it's not actually
|
|
|
|
* being used, we're going to keep this field 32-bit for the
|
|
|
|
* dummy levels, to remain consistent. if we ever make use
|
|
|
|
* of levels above the first, we should turn this field into
|
|
|
|
* an offset, and bump the xcf version.
|
|
|
|
*/
|
2006-04-12 20:49:29 +08:00
|
|
|
xcf_write_int32_check_error (info, (guint32 *) &tmp1, 1);
|
|
|
|
}
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2014-10-16 05:15:18 +08:00
|
|
|
/* the next level's offset if after the level we just wrote */
|
|
|
|
offset = info->cp;
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
|
2014-10-18 01:12:05 +08:00
|
|
|
/* there is already a '0' at the end of the offset table to indicate
|
|
|
|
* the end of the level offsets
|
|
|
|
*/
|
2002-12-20 14:26:34 +08:00
|
|
|
|
|
|
|
return TRUE;
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
|
2002-12-20 14:26:34 +08:00
|
|
|
static gboolean
|
2012-04-03 06:00:15 +08:00
|
|
|
xcf_save_level (XcfInfo *info,
|
|
|
|
GeglBuffer *buffer,
|
|
|
|
GError **error)
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
2012-04-03 06:00:15 +08:00
|
|
|
const Babl *format;
|
2017-03-23 18:44:41 +08:00
|
|
|
goffset *offset_table;
|
|
|
|
goffset *next_offset;
|
|
|
|
goffset saved_pos;
|
|
|
|
goffset offset;
|
app: limit allowable tile data size in XCFs
When loading tiles from an XCF, reject tiles whose on-disk size is
greater than 1.5 times the size of an uncompressed tile -- a limit
that is already present for the last tile in the buffer. This
should allow for the possibility of negative compression, while
restricting placing a realistic limit.
Currently, no limit is placed on the on-disk tile data size. When
loading RLE- and zlib-compressed tiles, a buffer large enough to
hold the entire on-disk tile data, up to 2GB, is allocated on the
stack, and the data is read into it. If the file is smaller than
the reported tile data size, the area of the buffer past the end
of the file is not touched. This allows a malicious XCF to write
up to 2GB of arbitrary data, at an arbitrary offset, up to 2GB,
below the stack.
Note that a similar issue had existed for earlier versions of GIMP
(see commit d7a9e6079d3e65baa516f302eb285fb2bbd97c2f), however,
since prior to 2.9 the tile data buffer was allocated on the heap,
the potential risk is far smaller.
2017-07-10 05:20:30 +08:00
|
|
|
goffset max_data_length;
|
2012-04-03 06:00:15 +08:00
|
|
|
guint32 width;
|
|
|
|
guint32 height;
|
|
|
|
gint bpp;
|
|
|
|
gint n_tile_rows;
|
|
|
|
gint n_tile_cols;
|
|
|
|
guint ntiles;
|
|
|
|
gint i;
|
2014-10-16 05:53:59 +08:00
|
|
|
guchar *rlebuf = NULL;
|
2012-04-03 06:00:15 +08:00
|
|
|
GError *tmp_error = NULL;
|
|
|
|
|
|
|
|
format = gegl_buffer_get_format (buffer);
|
|
|
|
|
|
|
|
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
|
|
|
|
2017-03-23 19:42:38 +08:00
|
|
|
xcf_write_int32_check_error (info, (guint32 *) &width, 1);
|
2003-09-11 00:33:59 +08:00
|
|
|
xcf_write_int32_check_error (info, (guint32 *) &height, 1);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
saved_pos = info->cp;
|
|
|
|
|
app: limit allowable tile data size in XCFs
When loading tiles from an XCF, reject tiles whose on-disk size is
greater than 1.5 times the size of an uncompressed tile -- a limit
that is already present for the last tile in the buffer. This
should allow for the possibility of negative compression, while
restricting placing a realistic limit.
Currently, no limit is placed on the on-disk tile data size. When
loading RLE- and zlib-compressed tiles, a buffer large enough to
hold the entire on-disk tile data, up to 2GB, is allocated on the
stack, and the data is read into it. If the file is smaller than
the reported tile data size, the area of the buffer past the end
of the file is not touched. This allows a malicious XCF to write
up to 2GB of arbitrary data, at an arbitrary offset, up to 2GB,
below the stack.
Note that a similar issue had existed for earlier versions of GIMP
(see commit d7a9e6079d3e65baa516f302eb285fb2bbd97c2f), however,
since prior to 2.9 the tile data buffer was allocated on the heap,
the potential risk is far smaller.
2017-07-10 05:20:30 +08:00
|
|
|
/* maximal allowable size of on-disk tile data. make it somewhat bigger than
|
|
|
|
* the uncompressed tile size, to allow for the possibility of negative
|
|
|
|
* compression. xcf_load_level() enforces this limit.
|
|
|
|
*/
|
|
|
|
max_data_length = XCF_TILE_WIDTH * XCF_TILE_HEIGHT * bpp *
|
|
|
|
XCF_TILE_MAX_DATA_LENGTH_FACTOR /* = 1.5, currently */;
|
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
/* allocate a temporary buffer to store the rle data before it is
|
2012-04-03 06:00:15 +08:00
|
|
|
* written to disk
|
|
|
|
*/
|
2014-10-16 05:53:59 +08:00
|
|
|
if (info->compression == COMPRESS_RLE)
|
app: limit allowable tile data size in XCFs
When loading tiles from an XCF, reject tiles whose on-disk size is
greater than 1.5 times the size of an uncompressed tile -- a limit
that is already present for the last tile in the buffer. This
should allow for the possibility of negative compression, while
restricting placing a realistic limit.
Currently, no limit is placed on the on-disk tile data size. When
loading RLE- and zlib-compressed tiles, a buffer large enough to
hold the entire on-disk tile data, up to 2GB, is allocated on the
stack, and the data is read into it. If the file is smaller than
the reported tile data size, the area of the buffer past the end
of the file is not touched. This allows a malicious XCF to write
up to 2GB of arbitrary data, at an arbitrary offset, up to 2GB,
below the stack.
Note that a similar issue had existed for earlier versions of GIMP
(see commit d7a9e6079d3e65baa516f302eb285fb2bbd97c2f), however,
since prior to 2.9 the tile data buffer was allocated on the heap,
the potential risk is far smaller.
2017-07-10 05:20:30 +08:00
|
|
|
rlebuf = g_alloca (max_data_length);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2012-04-03 06:00:15 +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);
|
|
|
|
|
|
|
|
ntiles = n_tile_rows * n_tile_cols;
|
2014-10-16 05:15:18 +08:00
|
|
|
|
2015-04-07 02:01:39 +08:00
|
|
|
/* allocate an offset table so we don't have to seek back after each
|
|
|
|
* tile, see bug #686862. allocate ntiles + 1 slots because a zero
|
|
|
|
* offset indicates the offset table's end.
|
2021-01-21 03:56:45 +08:00
|
|
|
* Do not use g_alloca since it may cause Stack Overflow on
|
|
|
|
* large images, see issue #6138.
|
2015-04-07 02:01:39 +08:00
|
|
|
*/
|
2021-01-21 03:56:45 +08:00
|
|
|
offset_table = g_malloc0 ((ntiles + 1) * sizeof (goffset));
|
2015-04-07 02:01:39 +08:00
|
|
|
next_offset = offset_table;
|
|
|
|
|
|
|
|
/* 'saved_pos' is the offset of the tile offset table */
|
2014-10-18 01:12:05 +08:00
|
|
|
saved_pos = info->cp;
|
|
|
|
|
|
|
|
/* write an empty offset table */
|
2017-03-23 18:44:41 +08:00
|
|
|
xcf_write_zero_offset_check_error (info, ntiles + 1);
|
2014-10-18 01:12:05 +08:00
|
|
|
|
|
|
|
/* 'offset' is where we will write the next tile */
|
|
|
|
offset = info->cp;
|
2012-04-03 06:00:15 +08:00
|
|
|
|
|
|
|
for (i = 0; i < ntiles; i++)
|
2001-07-04 02:38:56 +08:00
|
|
|
{
|
2012-04-03 06:00:15 +08:00
|
|
|
GeglRectangle rect;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2015-04-07 02:01:39 +08:00
|
|
|
/* store the offset in the table and increment the next pointer */
|
|
|
|
*next_offset++ = offset;
|
2006-04-12 20:49:29 +08:00
|
|
|
|
2012-04-03 06:00:15 +08:00
|
|
|
gimp_gegl_buffer_get_tile_rect (buffer,
|
|
|
|
XCF_TILE_WIDTH, XCF_TILE_HEIGHT,
|
|
|
|
i, &rect);
|
2006-04-12 20:49:29 +08:00
|
|
|
|
2012-04-03 06:00:15 +08:00
|
|
|
/* write out the tile. */
|
|
|
|
switch (info->compression)
|
|
|
|
{
|
|
|
|
case COMPRESS_NONE:
|
2012-04-21 05:45:22 +08:00
|
|
|
xcf_check_error (xcf_save_tile (info, buffer, &rect, format,
|
|
|
|
error));
|
2012-04-03 06:00:15 +08:00
|
|
|
break;
|
|
|
|
case COMPRESS_RLE:
|
2012-04-21 05:45:22 +08:00
|
|
|
xcf_check_error (xcf_save_tile_rle (info, buffer, &rect, format,
|
2012-04-03 06:00:15 +08:00
|
|
|
rlebuf, error));
|
|
|
|
break;
|
|
|
|
case COMPRESS_ZLIB:
|
2014-09-15 21:33:22 +08:00
|
|
|
xcf_check_error (xcf_save_tile_zlib (info, buffer, &rect, format,
|
|
|
|
error));
|
2012-04-03 06:00:15 +08:00
|
|
|
break;
|
|
|
|
case COMPRESS_FRACTAL:
|
2014-09-17 06:08:33 +08:00
|
|
|
g_warning ("xcf: fractal compression unimplemented");
|
2021-01-21 03:56:45 +08:00
|
|
|
g_free (offset_table);
|
2014-09-17 06:08:33 +08:00
|
|
|
return FALSE;
|
2006-04-12 20:49:29 +08:00
|
|
|
}
|
2001-07-04 02:38:56 +08:00
|
|
|
|
app: limit allowable tile data size in XCFs
When loading tiles from an XCF, reject tiles whose on-disk size is
greater than 1.5 times the size of an uncompressed tile -- a limit
that is already present for the last tile in the buffer. This
should allow for the possibility of negative compression, while
restricting placing a realistic limit.
Currently, no limit is placed on the on-disk tile data size. When
loading RLE- and zlib-compressed tiles, a buffer large enough to
hold the entire on-disk tile data, up to 2GB, is allocated on the
stack, and the data is read into it. If the file is smaller than
the reported tile data size, the area of the buffer past the end
of the file is not touched. This allows a malicious XCF to write
up to 2GB of arbitrary data, at an arbitrary offset, up to 2GB,
below the stack.
Note that a similar issue had existed for earlier versions of GIMP
(see commit d7a9e6079d3e65baa516f302eb285fb2bbd97c2f), however,
since prior to 2.9 the tile data buffer was allocated on the heap,
the potential risk is far smaller.
2017-07-10 05:20:30 +08:00
|
|
|
/* make sure the on-disk tile data didn't end up being too big.
|
|
|
|
* xcf_load_level() would refuse to load the file if it did.
|
|
|
|
*/
|
|
|
|
if (info->cp < offset || info->cp - offset > max_data_length)
|
|
|
|
{
|
|
|
|
g_message ("xcf: invalid tile data length: %" G_GOFFSET_FORMAT,
|
|
|
|
info->cp - offset);
|
2021-01-21 03:56:45 +08:00
|
|
|
g_free (offset_table);
|
app: limit allowable tile data size in XCFs
When loading tiles from an XCF, reject tiles whose on-disk size is
greater than 1.5 times the size of an uncompressed tile -- a limit
that is already present for the last tile in the buffer. This
should allow for the possibility of negative compression, while
restricting placing a realistic limit.
Currently, no limit is placed on the on-disk tile data size. When
loading RLE- and zlib-compressed tiles, a buffer large enough to
hold the entire on-disk tile data, up to 2GB, is allocated on the
stack, and the data is read into it. If the file is smaller than
the reported tile data size, the area of the buffer past the end
of the file is not touched. This allows a malicious XCF to write
up to 2GB of arbitrary data, at an arbitrary offset, up to 2GB,
below the stack.
Note that a similar issue had existed for earlier versions of GIMP
(see commit d7a9e6079d3e65baa516f302eb285fb2bbd97c2f), however,
since prior to 2.9 the tile data buffer was allocated on the heap,
the potential risk is far smaller.
2017-07-10 05:20:30 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-10-16 05:15:18 +08:00
|
|
|
/* the next tile's offset is after the tile we just wrote */
|
|
|
|
offset = info->cp;
|
2012-04-03 06:00:15 +08:00
|
|
|
}
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2015-04-07 02:01:39 +08:00
|
|
|
/* seek back to the offset table and write it */
|
|
|
|
xcf_check_error (xcf_seek_pos (info, saved_pos, error));
|
2017-03-23 18:44:41 +08:00
|
|
|
xcf_write_offset_check_error (info, offset_table, ntiles + 1);
|
2015-04-07 02:01:39 +08:00
|
|
|
|
|
|
|
/* seek to the end of the file */
|
|
|
|
xcf_check_error (xcf_seek_pos (info, offset, error));
|
2002-12-20 14:26:34 +08:00
|
|
|
|
2021-01-21 03:56:45 +08:00
|
|
|
g_free (offset_table);
|
|
|
|
|
2002-12-20 14:26:34 +08:00
|
|
|
return TRUE;
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
|
2002-12-20 14:26:34 +08:00
|
|
|
static gboolean
|
2012-04-03 06:00:15 +08:00
|
|
|
xcf_save_tile (XcfInfo *info,
|
|
|
|
GeglBuffer *buffer,
|
|
|
|
GeglRectangle *tile_rect,
|
2012-04-21 05:45:22 +08:00
|
|
|
const Babl *format,
|
2012-04-03 06:00:15 +08:00
|
|
|
GError **error)
|
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);
|
|
|
|
GError *tmp_error = NULL;
|
2012-04-03 06:00:15 +08:00
|
|
|
|
2012-04-21 05:45:22 +08:00
|
|
|
gegl_buffer_get (buffer, tile_rect, 1.0, format, tile_data,
|
2012-04-03 06:00:15 +08:00
|
|
|
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
|
2002-12-20 14:26:34 +08:00
|
|
|
|
2017-09-17 01:03:20 +08:00
|
|
|
if (info->file_version <= 11)
|
|
|
|
{
|
|
|
|
xcf_write_int8_check_error (info, tile_data, tile_size);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gint n_components = babl_format_get_n_components (format);
|
|
|
|
|
|
|
|
xcf_write_component_check_error (info, bpp / n_components, tile_data,
|
2017-10-01 23:43:10 +08:00
|
|
|
tile_size / bpp * n_components);
|
2017-09-17 01:03:20 +08:00
|
|
|
}
|
2002-12-20 14:26:34 +08:00
|
|
|
|
|
|
|
return TRUE;
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
|
|
|
|
2002-12-20 14:26:34 +08:00
|
|
|
static gboolean
|
2012-04-03 06:00:15 +08:00
|
|
|
xcf_save_tile_rle (XcfInfo *info,
|
|
|
|
GeglBuffer *buffer,
|
|
|
|
GeglRectangle *tile_rect,
|
2012-04-21 05:45:22 +08:00
|
|
|
const Babl *format,
|
2012-04-03 06:00:15 +08:00
|
|
|
guchar *rlebuf,
|
|
|
|
GError **error)
|
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 len = 0;
|
|
|
|
gint i, j;
|
|
|
|
GError *tmp_error = NULL;
|
|
|
|
|
|
|
|
gegl_buffer_get (buffer, tile_rect, 1.0, format, tile_data,
|
2012-04-03 06:00:15 +08:00
|
|
|
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2017-09-17 01:03:20 +08:00
|
|
|
if (info->file_version >= 12)
|
|
|
|
{
|
|
|
|
gint n_components = babl_format_get_n_components (format);
|
|
|
|
|
|
|
|
xcf_write_to_be (bpp / n_components, tile_data,
|
2017-10-01 23:39:54 +08:00
|
|
|
tile_size / bpp * n_components);
|
2017-09-17 01:03:20 +08:00
|
|
|
}
|
|
|
|
|
2001-07-04 02:38:56 +08:00
|
|
|
for (i = 0; i < bpp; i++)
|
|
|
|
{
|
2012-04-03 06:00:15 +08:00
|
|
|
const guchar *data = tile_data + i;
|
|
|
|
gint state = 0;
|
|
|
|
gint length = 0;
|
|
|
|
gint count = 0;
|
|
|
|
gint size = tile_rect->width * tile_rect->height;
|
|
|
|
guint last = -1;
|
2001-07-04 02:38:56 +08:00
|
|
|
|
|
|
|
while (size > 0)
|
2006-04-12 20:49:29 +08:00
|
|
|
{
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
/* in state 0 we try to find a long sequence of
|
|
|
|
* matching values.
|
|
|
|
*/
|
|
|
|
if ((length == 32768) ||
|
|
|
|
((size - length) <= 0) ||
|
|
|
|
((length > 1) && (last != *data)))
|
|
|
|
{
|
|
|
|
count += length;
|
2006-07-12 04:21:18 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
if (length >= 128)
|
|
|
|
{
|
|
|
|
rlebuf[len++] = 127;
|
2001-07-04 02:38:56 +08:00
|
|
|
rlebuf[len++] = (length >> 8);
|
|
|
|
rlebuf[len++] = length & 0x00FF;
|
2006-04-12 20:49:29 +08:00
|
|
|
rlebuf[len++] = last;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rlebuf[len++] = length - 1;
|
|
|
|
rlebuf[len++] = last;
|
|
|
|
}
|
2006-07-12 04:21:18 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
size -= length;
|
|
|
|
length = 0;
|
|
|
|
}
|
|
|
|
else if ((length == 1) && (last != *data))
|
2006-07-12 04:21:18 +08:00
|
|
|
{
|
|
|
|
state = 1;
|
|
|
|
}
|
2006-04-12 20:49:29 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
/* in state 1 we try and find a long sequence of
|
|
|
|
* non-matching values.
|
|
|
|
*/
|
|
|
|
if ((length == 32768) ||
|
|
|
|
((size - length) == 0) ||
|
|
|
|
((length > 0) && (last == *data) &&
|
|
|
|
((size - length) == 1 || last == data[bpp])))
|
|
|
|
{
|
2006-07-12 04:21:18 +08:00
|
|
|
const guchar *t;
|
|
|
|
|
2015-11-25 16:35:57 +08:00
|
|
|
/* if we came here because of a new run, backup one */
|
|
|
|
if (!((length == 32768) || ((size - length) == 0)))
|
|
|
|
{
|
|
|
|
length--;
|
|
|
|
data -= bpp;
|
|
|
|
}
|
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
count += length;
|
|
|
|
state = 0;
|
|
|
|
|
|
|
|
if (length >= 128)
|
|
|
|
{
|
|
|
|
rlebuf[len++] = 255 - 127;
|
2001-07-04 02:38:56 +08:00
|
|
|
rlebuf[len++] = (length >> 8);
|
|
|
|
rlebuf[len++] = length & 0x00FF;
|
2006-04-12 20:49:29 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rlebuf[len++] = 255 - (length - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
t = data - length * bpp;
|
2006-07-12 04:21:18 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
for (j = 0; j < length; j++)
|
|
|
|
{
|
|
|
|
rlebuf[len++] = *t;
|
|
|
|
t += bpp;
|
|
|
|
}
|
|
|
|
|
|
|
|
size -= length;
|
|
|
|
length = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-07-12 04:21:18 +08:00
|
|
|
if (size > 0)
|
|
|
|
{
|
|
|
|
length += 1;
|
|
|
|
last = *data;
|
|
|
|
data += bpp;
|
|
|
|
}
|
2006-04-12 20:49:29 +08:00
|
|
|
}
|
2001-07-04 02:38:56 +08:00
|
|
|
|
2012-04-03 06:00:15 +08:00
|
|
|
if (count != (tile_rect->width * tile_rect->height))
|
2006-04-12 20:49:29 +08:00
|
|
|
g_message ("xcf: uh oh! xcf rle tile saving error: %d", count);
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
2006-07-12 04:21:18 +08:00
|
|
|
|
2003-09-11 00:33:59 +08:00
|
|
|
xcf_write_int8_check_error (info, rlebuf, len);
|
2002-12-20 14:26:34 +08:00
|
|
|
|
|
|
|
return TRUE;
|
2001-07-04 02:38:56 +08:00
|
|
|
}
|
2003-05-15 20:47:42 +08:00
|
|
|
|
2014-09-15 21:33:22 +08:00
|
|
|
static gboolean
|
|
|
|
xcf_save_tile_zlib (XcfInfo *info,
|
|
|
|
GeglBuffer *buffer,
|
|
|
|
GeglRectangle *tile_rect,
|
|
|
|
const Babl *format,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
/* The buffer for compressed data. */
|
|
|
|
guchar *buf = g_alloca (tile_size);
|
|
|
|
GError *tmp_error = NULL;
|
|
|
|
z_stream strm;
|
|
|
|
int action;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
gegl_buffer_get (buffer, tile_rect, 1.0, format, tile_data,
|
|
|
|
GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
|
|
|
|
|
2017-09-17 01:03:20 +08:00
|
|
|
if (info->file_version >= 12)
|
|
|
|
{
|
|
|
|
gint n_components = babl_format_get_n_components (format);
|
|
|
|
|
|
|
|
xcf_write_to_be (bpp / n_components, tile_data,
|
2017-10-01 23:39:54 +08:00
|
|
|
tile_size / bpp * n_components);
|
2017-09-17 01:03:20 +08:00
|
|
|
}
|
|
|
|
|
2014-09-15 21:33:22 +08:00
|
|
|
/* allocate deflate state */
|
|
|
|
strm.zalloc = Z_NULL;
|
|
|
|
strm.zfree = Z_NULL;
|
|
|
|
strm.opaque = Z_NULL;
|
|
|
|
|
|
|
|
status = deflateInit (&strm, Z_DEFAULT_COMPRESSION);
|
|
|
|
if (status != Z_OK)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
strm.next_in = tile_data;
|
|
|
|
strm.avail_in = tile_size;
|
|
|
|
strm.next_out = buf;
|
|
|
|
strm.avail_out = tile_size;
|
|
|
|
|
|
|
|
action = Z_NO_FLUSH;
|
|
|
|
|
|
|
|
while (status == Z_OK || status == Z_BUF_ERROR)
|
|
|
|
{
|
|
|
|
if (strm.avail_in == 0)
|
|
|
|
{
|
|
|
|
/* Finish the encoding. */
|
|
|
|
action = Z_FINISH;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = deflate (&strm, action);
|
|
|
|
|
|
|
|
if (status == Z_STREAM_END || status == Z_BUF_ERROR)
|
|
|
|
{
|
|
|
|
size_t write_size = tile_size - strm.avail_out;
|
|
|
|
|
|
|
|
xcf_write_int8_check_error (info, buf, write_size);
|
|
|
|
|
|
|
|
/* Reset next_out and avail_out. */
|
|
|
|
strm.next_out = buf;
|
|
|
|
strm.avail_out = tile_size;
|
|
|
|
}
|
|
|
|
else if (status != Z_OK)
|
|
|
|
{
|
|
|
|
g_printerr ("xcf: tile compression failed: %s", zError (status));
|
|
|
|
deflateEnd (&strm);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
deflateEnd (&strm);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-09-11 00:22:33 +08:00
|
|
|
static gboolean
|
|
|
|
xcf_save_parasite (XcfInfo *info,
|
|
|
|
GimpParasite *parasite,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
if (gimp_parasite_is_persistent (parasite))
|
|
|
|
{
|
2021-01-30 06:52:03 +08:00
|
|
|
guint32 value;
|
|
|
|
const gchar *string;
|
|
|
|
GError *tmp_error = NULL;
|
|
|
|
gconstpointer parasite_data;
|
2007-12-22 00:37:01 +08:00
|
|
|
|
2021-04-06 00:36:44 +08:00
|
|
|
string = gimp_parasite_get_name (parasite);
|
2007-12-22 00:37:01 +08:00
|
|
|
xcf_write_string_check_error (info, (gchar **) &string, 1);
|
2003-09-11 00:22:33 +08:00
|
|
|
|
2021-04-06 00:36:44 +08:00
|
|
|
value = gimp_parasite_get_flags (parasite);
|
2007-12-22 00:37:01 +08:00
|
|
|
xcf_write_int32_check_error (info, &value, 1);
|
|
|
|
|
2021-01-30 06:52:03 +08:00
|
|
|
parasite_data = gimp_parasite_get_data (parasite, &value);
|
2007-12-22 00:37:01 +08:00
|
|
|
xcf_write_int32_check_error (info, &value, 1);
|
|
|
|
|
2021-01-30 06:52:03 +08:00
|
|
|
xcf_write_int8_check_error (info, parasite_data, value);
|
2003-09-11 00:22:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
XcfInfo *info;
|
|
|
|
GError *error;
|
|
|
|
} XcfParasiteData;
|
|
|
|
|
2003-09-10 18:40:57 +08:00
|
|
|
static void
|
2003-09-11 00:22:33 +08:00
|
|
|
xcf_save_parasite_func (gchar *key,
|
|
|
|
GimpParasite *parasite,
|
|
|
|
XcfParasiteData *data)
|
2003-05-15 20:47:42 +08:00
|
|
|
{
|
2003-09-11 00:22:33 +08:00
|
|
|
if (! data->error)
|
|
|
|
xcf_save_parasite (data->info, parasite, &data->error);
|
|
|
|
}
|
2003-05-15 20:47:42 +08:00
|
|
|
|
2003-09-11 00:22:33 +08:00
|
|
|
static gboolean
|
|
|
|
xcf_save_parasite_list (XcfInfo *info,
|
|
|
|
GimpParasiteList *list,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
XcfParasiteData data;
|
|
|
|
|
|
|
|
data.info = info;
|
|
|
|
data.error = NULL;
|
2003-05-15 20:47:42 +08:00
|
|
|
|
2003-09-11 00:22:33 +08:00
|
|
|
gimp_parasite_list_foreach (list, (GHFunc) xcf_save_parasite_func, &data);
|
|
|
|
|
|
|
|
if (data.error)
|
|
|
|
{
|
|
|
|
g_propagate_error (error, data.error);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2003-05-15 20:47:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2003-05-22 01:38:14 +08:00
|
|
|
xcf_save_old_paths (XcfInfo *info,
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image,
|
2003-05-22 01:38:14 +08:00
|
|
|
GError **error)
|
2003-05-15 20:47:42 +08:00
|
|
|
{
|
2003-05-22 01:38:14 +08:00
|
|
|
GimpVectors *active_vectors;
|
|
|
|
guint32 num_paths;
|
|
|
|
guint32 active_index = 0;
|
|
|
|
GList *list;
|
|
|
|
GError *tmp_error = NULL;
|
2003-05-15 20:47:42 +08:00
|
|
|
|
|
|
|
/* Write out the following:-
|
|
|
|
*
|
|
|
|
* last_selected_row (gint)
|
|
|
|
* number_of_paths (gint)
|
|
|
|
*
|
|
|
|
* then each path:-
|
|
|
|
*/
|
|
|
|
|
2010-02-04 06:00:31 +08:00
|
|
|
num_paths = gimp_container_get_n_children (gimp_image_get_vectors (image));
|
2003-05-22 01:38:14 +08:00
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
active_vectors = gimp_image_get_active_vectors (image);
|
2003-05-15 20:47:42 +08:00
|
|
|
|
2003-05-22 01:38:14 +08:00
|
|
|
if (active_vectors)
|
2010-02-04 06:00:31 +08:00
|
|
|
active_index = gimp_container_get_child_index (gimp_image_get_vectors (image),
|
2003-05-22 01:38:14 +08:00
|
|
|
GIMP_OBJECT (active_vectors));
|
|
|
|
|
2003-09-11 00:33:59 +08:00
|
|
|
xcf_write_int32_check_error (info, &active_index, 1);
|
|
|
|
xcf_write_int32_check_error (info, &num_paths, 1);
|
2003-05-15 20:47:42 +08:00
|
|
|
|
2008-11-03 04:46:57 +08:00
|
|
|
for (list = gimp_image_get_vectors_iter (image);
|
2003-05-22 01:38:14 +08:00
|
|
|
list;
|
|
|
|
list = g_list_next (list))
|
2003-05-15 20:47:42 +08:00
|
|
|
{
|
2003-05-23 03:02:38 +08:00
|
|
|
GimpVectors *vectors = list->data;
|
|
|
|
gchar *name;
|
|
|
|
guint32 locked;
|
|
|
|
guint8 state;
|
|
|
|
guint32 version;
|
|
|
|
guint32 pathtype;
|
|
|
|
guint32 tattoo;
|
|
|
|
GimpVectorsCompatPoint *points;
|
2006-04-03 02:19:48 +08:00
|
|
|
guint32 num_points;
|
|
|
|
guint32 closed;
|
2003-05-23 03:02:38 +08:00
|
|
|
gint i;
|
2003-05-15 20:47:42 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* name (string)
|
|
|
|
* locked (gint)
|
|
|
|
* state (gchar)
|
|
|
|
* closed (gint)
|
|
|
|
* number points (gint)
|
2003-05-22 01:38:14 +08:00
|
|
|
* version (gint)
|
|
|
|
* pathtype (gint)
|
|
|
|
* tattoo (gint)
|
2003-05-15 20:47:42 +08:00
|
|
|
* then each point.
|
|
|
|
*/
|
|
|
|
|
2006-04-03 02:19:48 +08:00
|
|
|
points = gimp_vectors_compat_get_points (vectors,
|
|
|
|
(gint32 *) &num_points,
|
|
|
|
(gint32 *) &closed);
|
2003-05-22 01:38:14 +08:00
|
|
|
|
2003-09-09 23:46:59 +08:00
|
|
|
/* if no points are generated because of a faulty path we should
|
|
|
|
* skip saving the path - this is unfortunately impossible, because
|
2018-03-25 04:49:01 +08:00
|
|
|
* we already saved the number of paths and I won't start seeking
|
2003-09-09 23:46:59 +08:00
|
|
|
* around to fix that cruft */
|
|
|
|
|
2009-09-01 04:47:18 +08:00
|
|
|
name = (gchar *) gimp_object_get_name (vectors);
|
2003-05-22 01:38:14 +08:00
|
|
|
locked = gimp_item_get_linked (GIMP_ITEM (vectors));
|
2003-05-23 03:02:38 +08:00
|
|
|
state = closed ? 4 : 2; /* EDIT : ADD (editing state, 1.2 compat) */
|
2003-05-22 01:38:14 +08:00
|
|
|
version = 3;
|
2003-05-23 03:02:38 +08:00
|
|
|
pathtype = 1; /* BEZIER (1.2 compat) */
|
2003-05-22 01:38:14 +08:00
|
|
|
tattoo = gimp_item_get_tattoo (GIMP_ITEM (vectors));
|
2003-09-10 18:40:57 +08:00
|
|
|
|
2003-09-11 00:33:59 +08:00
|
|
|
xcf_write_string_check_error (info, &name, 1);
|
|
|
|
xcf_write_int32_check_error (info, &locked, 1);
|
|
|
|
xcf_write_int8_check_error (info, &state, 1);
|
|
|
|
xcf_write_int32_check_error (info, &closed, 1);
|
|
|
|
xcf_write_int32_check_error (info, &num_points, 1);
|
|
|
|
xcf_write_int32_check_error (info, &version, 1);
|
|
|
|
xcf_write_int32_check_error (info, &pathtype, 1);
|
|
|
|
xcf_write_int32_check_error (info, &tattoo, 1);
|
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:47:42 +08:00
|
|
|
{
|
2003-05-23 03:02:38 +08:00
|
|
|
gfloat x;
|
|
|
|
gfloat y;
|
|
|
|
|
|
|
|
x = points[i].x;
|
|
|
|
y = points[i].y;
|
2003-05-22 01:38:14 +08:00
|
|
|
|
2003-05-23 03:02:38 +08:00
|
|
|
/*
|
|
|
|
* type (gint)
|
|
|
|
* x (gfloat)
|
|
|
|
* y (gfloat)
|
|
|
|
*/
|
|
|
|
|
2003-09-11 00:33:59 +08:00
|
|
|
xcf_write_int32_check_error (info, &points[i].type, 1);
|
|
|
|
xcf_write_float_check_error (info, &x, 1);
|
|
|
|
xcf_write_float_check_error (info, &y, 1);
|
2003-05-15 20:47:42 +08:00
|
|
|
}
|
2003-05-23 03:02:38 +08:00
|
|
|
|
|
|
|
g_free (points);
|
2003-05-15 20:47:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2003-09-09 23:46:59 +08:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
xcf_save_vectors (XcfInfo *info,
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image,
|
2003-09-09 23:46:59 +08:00
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GimpVectors *active_vectors;
|
2003-09-11 00:22:33 +08:00
|
|
|
guint32 version = 1;
|
2003-09-09 23:46:59 +08:00
|
|
|
guint32 active_index = 0;
|
2003-09-11 00:22:33 +08:00
|
|
|
guint32 num_paths;
|
2003-09-09 23:46:59 +08:00
|
|
|
GList *list;
|
|
|
|
GList *stroke_list;
|
|
|
|
GError *tmp_error = NULL;
|
|
|
|
|
|
|
|
/* Write out the following:-
|
|
|
|
*
|
2003-09-11 00:22:33 +08:00
|
|
|
* version (gint)
|
|
|
|
* active_index (gint)
|
|
|
|
* num_paths (gint)
|
2003-09-09 23:46:59 +08:00
|
|
|
*
|
|
|
|
* then each path:-
|
|
|
|
*/
|
|
|
|
|
2006-03-29 01:08:36 +08:00
|
|
|
active_vectors = gimp_image_get_active_vectors (image);
|
2003-09-09 23:46:59 +08:00
|
|
|
|
|
|
|
if (active_vectors)
|
2010-02-04 06:00:31 +08:00
|
|
|
active_index = gimp_container_get_child_index (gimp_image_get_vectors (image),
|
2003-09-09 23:46:59 +08:00
|
|
|
GIMP_OBJECT (active_vectors));
|
|
|
|
|
2010-02-04 06:00:31 +08:00
|
|
|
num_paths = gimp_container_get_n_children (gimp_image_get_vectors (image));
|
2003-09-11 00:22:33 +08:00
|
|
|
|
2003-09-11 00:33:59 +08:00
|
|
|
xcf_write_int32_check_error (info, &version, 1);
|
|
|
|
xcf_write_int32_check_error (info, &active_index, 1);
|
|
|
|
xcf_write_int32_check_error (info, &num_paths, 1);
|
2003-09-09 23:46:59 +08:00
|
|
|
|
2008-11-03 04:46:57 +08:00
|
|
|
for (list = gimp_image_get_vectors_iter (image);
|
2003-09-09 23:46:59 +08:00
|
|
|
list;
|
|
|
|
list = g_list_next (list))
|
|
|
|
{
|
2003-09-11 00:22:33 +08:00
|
|
|
GimpVectors *vectors = list->data;
|
|
|
|
GimpParasiteList *parasites;
|
2007-12-22 00:37:01 +08:00
|
|
|
const gchar *name;
|
2003-09-11 00:22:33 +08:00
|
|
|
guint32 tattoo;
|
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;
|
2003-09-09 23:46:59 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* name (string)
|
|
|
|
* tattoo (gint)
|
2003-09-12 03:52:29 +08:00
|
|
|
* visible (gint)
|
2003-09-11 00:22:33 +08:00
|
|
|
* linked (gint)
|
|
|
|
* num_parasites (gint)
|
|
|
|
* num_strokes (gint)
|
2003-09-09 23:46:59 +08:00
|
|
|
*
|
2003-09-11 00:22:33 +08:00
|
|
|
* then each parasite
|
|
|
|
* then each stroke
|
2003-09-09 23:46:59 +08:00
|
|
|
*/
|
|
|
|
|
2009-09-01 04:47:18 +08:00
|
|
|
name = gimp_object_get_name (vectors);
|
2003-09-12 03:52:29 +08:00
|
|
|
visible = gimp_item_get_visible (GIMP_ITEM (vectors));
|
2003-09-11 00:22:33 +08:00
|
|
|
linked = gimp_item_get_linked (GIMP_ITEM (vectors));
|
|
|
|
tattoo = gimp_item_get_tattoo (GIMP_ITEM (vectors));
|
2011-02-01 06:51:18 +08:00
|
|
|
parasites = gimp_item_get_parasites (GIMP_ITEM (vectors));
|
2003-09-11 00:22:33 +08:00
|
|
|
num_parasites = gimp_parasite_list_persistent_length (parasites);
|
2016-01-25 13:21:27 +08:00
|
|
|
num_strokes = g_queue_get_length (vectors->strokes);
|
2003-09-10 18:40:57 +08:00
|
|
|
|
2007-12-22 00:37:01 +08:00
|
|
|
xcf_write_string_check_error (info, (gchar **) &name, 1);
|
|
|
|
xcf_write_int32_check_error (info, &tattoo, 1);
|
|
|
|
xcf_write_int32_check_error (info, &visible, 1);
|
|
|
|
xcf_write_int32_check_error (info, &linked, 1);
|
|
|
|
xcf_write_int32_check_error (info, &num_parasites, 1);
|
|
|
|
xcf_write_int32_check_error (info, &num_strokes, 1);
|
2003-09-09 23:46:59 +08:00
|
|
|
|
2003-09-11 00:22:33 +08:00
|
|
|
xcf_check_error (xcf_save_parasite_list (info, parasites, error));
|
2003-09-09 23:46:59 +08:00
|
|
|
|
2016-01-25 13:21:27 +08:00
|
|
|
for (stroke_list = g_list_first (vectors->strokes->head);
|
2003-09-09 23:46:59 +08:00
|
|
|
stroke_list;
|
|
|
|
stroke_list = g_list_next (stroke_list))
|
|
|
|
{
|
2007-12-22 00:37:01 +08:00
|
|
|
GimpStroke *stroke = stroke_list->data;
|
2003-09-11 00:22:33 +08:00
|
|
|
guint32 stroke_type;
|
|
|
|
guint32 closed;
|
|
|
|
guint32 num_axes;
|
|
|
|
GArray *control_points;
|
|
|
|
gint i;
|
2003-09-09 23:46:59 +08:00
|
|
|
|
2003-09-11 00:22:33 +08:00
|
|
|
guint32 type;
|
|
|
|
gfloat coords[6];
|
2003-09-09 23:46:59 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* stroke_type (gint)
|
|
|
|
* closed (gint)
|
|
|
|
* num_axes (gint)
|
|
|
|
* num_control_points (gint)
|
|
|
|
*
|
|
|
|
* then each control point.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (GIMP_IS_BEZIER_STROKE (stroke))
|
|
|
|
{
|
|
|
|
stroke_type = XCF_STROKETYPE_BEZIER_STROKE;
|
|
|
|
num_axes = 2; /* hardcoded, might be increased later */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_printerr ("Skipping unknown stroke type!\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2006-04-03 02:19:48 +08:00
|
|
|
control_points = gimp_stroke_control_points_get (stroke,
|
|
|
|
(gint32 *) &closed);
|
2003-09-09 23:46:59 +08:00
|
|
|
|
2003-09-11 00:33:59 +08:00
|
|
|
xcf_write_int32_check_error (info, &stroke_type, 1);
|
|
|
|
xcf_write_int32_check_error (info, &closed, 1);
|
|
|
|
xcf_write_int32_check_error (info, &num_axes, 1);
|
|
|
|
xcf_write_int32_check_error (info, &control_points->len, 1);
|
2003-09-09 23:46:59 +08:00
|
|
|
|
|
|
|
for (i = 0; i < control_points->len; i++)
|
|
|
|
{
|
|
|
|
GimpAnchor *anchor;
|
|
|
|
|
|
|
|
anchor = & (g_array_index (control_points, GimpAnchor, i));
|
|
|
|
|
2003-09-11 00:22:33 +08:00
|
|
|
type = anchor->type;
|
2003-09-09 23:46:59 +08:00
|
|
|
coords[0] = anchor->position.x;
|
|
|
|
coords[1] = anchor->position.y;
|
|
|
|
coords[2] = anchor->position.pressure;
|
|
|
|
coords[3] = anchor->position.xtilt;
|
|
|
|
coords[4] = anchor->position.ytilt;
|
|
|
|
coords[5] = anchor->position.wheel;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* type (gint)
|
2003-09-11 00:22:33 +08:00
|
|
|
*
|
|
|
|
* the first num_axis elements of:
|
|
|
|
* [0] x (gfloat)
|
|
|
|
* [1] y (gfloat)
|
|
|
|
* [2] pressure (gfloat)
|
|
|
|
* [3] xtilt (gfloat)
|
|
|
|
* [4] ytilt (gfloat)
|
|
|
|
* [5] wheel (gfloat)
|
2003-09-09 23:46:59 +08:00
|
|
|
*/
|
|
|
|
|
2017-03-23 19:42:38 +08:00
|
|
|
xcf_write_int32_check_error (info, &type, 1);
|
2003-09-11 00:33:59 +08:00
|
|
|
xcf_write_float_check_error (info, coords, num_axes);
|
2003-09-09 23:46:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
g_array_free (control_points, TRUE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|