~ubuntu-branches/ubuntu/vivid/gimp/vivid

« back to all changes in this revision

Viewing changes to app/xcf/xcf-load.c

  • Committer: Package Import Robot
  • Author(s): Jordi Mallach
  • Date: 2012-05-08 18:50:03 UTC
  • mto: (1.1.26) (0.5.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 71.
  • Revision ID: package-import@ubuntu.com-20120508185003-tltkvbaysf8d2426
ImportĀ upstreamĀ versionĀ 2.8.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
 *
4
 
 * This program is free software; you can redistribute it and/or modify
 
4
 * This program is free software: you can redistribute it and/or modify
5
5
 * it under the terms of the GNU General Public License as published by
6
 
 * the Free Software Foundation; either version 2 of the License, or
 
6
 * the Free Software Foundation; either version 3 of the License, or
7
7
 * (at your option) any later version.
8
8
 *
9
9
 * This program is distributed in the hope that it will be useful,
12
12
 * GNU General Public License for more details.
13
13
 *
14
14
 * You should have received a copy of the GNU General Public License
15
 
 * along with this program; if not, write to the Free Software
16
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
16
 */
18
17
 
19
18
#include "config.h"
20
19
 
21
20
#include <stdio.h>
22
 
#include <string.h> /* strcmp, memcmp */
 
21
#include <string.h>
23
22
 
24
 
#include <glib-object.h>
 
23
#include <cairo.h>
 
24
#include <gegl.h>
25
25
 
26
26
#include "libgimpbase/gimpbase.h"
27
27
#include "libgimpcolor/gimpcolor.h"
36
36
 
37
37
#include "core/gimp.h"
38
38
#include "core/gimpcontainer.h"
39
 
#include "core/gimpdrawable.h"
 
39
#include "core/gimpdrawable-private.h" /* eek */
40
40
#include "core/gimpgrid.h"
 
41
#include "core/gimpgrouplayer.h"
41
42
#include "core/gimpimage.h"
42
43
#include "core/gimpimage-colormap.h"
43
44
#include "core/gimpimage-grid.h"
44
45
#include "core/gimpimage-guides.h"
 
46
#include "core/gimpimage-private.h"
45
47
#include "core/gimpimage-sample-points.h"
46
 
#include "core/gimplayer.h"
 
48
#include "core/gimpimage-undo.h"
 
49
#include "core/gimpitemstack.h"
47
50
#include "core/gimplayer-floating-sel.h"
48
51
#include "core/gimplayermask.h"
49
52
#include "core/gimpparasitelist.h"
50
53
#include "core/gimpprogress.h"
51
54
#include "core/gimpselection.h"
52
55
#include "core/gimptemplate.h"
53
 
#include "core/gimpunit.h"
54
56
 
55
57
#include "text/gimptextlayer.h"
56
58
#include "text/gimptextlayer-xcf.h"
71
73
 
72
74
/* #define GIMP_XCF_PATH_DEBUG */
73
75
 
 
76
static void            xcf_load_add_masks     (GimpImage    *image);
74
77
static gboolean        xcf_load_image_props   (XcfInfo      *info,
75
78
                                               GimpImage    *image);
76
79
static gboolean        xcf_load_layer_props   (XcfInfo      *info,
77
80
                                               GimpImage    *image,
78
 
                                               GimpLayer    *layer,
 
81
                                               GimpLayer   **layer,
 
82
                                               GList       **item_path,
79
83
                                               gboolean     *apply_mask,
80
84
                                               gboolean     *edit_mask,
81
85
                                               gboolean     *show_mask,
82
 
                                               guint32      *text_layer_flags);
 
86
                                               guint32      *text_layer_flags,
 
87
                                               guint32      *group_layer_flags);
83
88
static gboolean        xcf_load_channel_props (XcfInfo      *info,
84
89
                                               GimpImage    *image,
85
90
                                               GimpChannel **channel);
87
92
                                               PropType     *prop_type,
88
93
                                               guint32      *prop_size);
89
94
static GimpLayer     * xcf_load_layer         (XcfInfo      *info,
90
 
                                               GimpImage    *image);
 
95
                                               GimpImage    *image,
 
96
                                               GList       **item_path);
91
97
static GimpChannel   * xcf_load_channel       (XcfInfo      *info,
92
98
                                               GimpImage    *image);
93
99
static GimpLayerMask * xcf_load_layer_mask    (XcfInfo      *info,
111
117
static gboolean        xcf_load_vector        (XcfInfo      *info,
112
118
                                               GimpImage    *image);
113
119
 
 
120
static gboolean        xcf_skip_unknown_prop  (XcfInfo      *info,
 
121
                                               gsize         size);
 
122
 
114
123
 
115
124
#define xcf_progress_update(info) G_STMT_START  \
116
125
  {                                             \
125
134
                GError  **error)
126
135
{
127
136
  GimpImage          *image;
128
 
  GimpLayer          *layer;
129
 
  GimpChannel        *channel;
130
137
  const GimpParasite *parasite;
131
138
  guint32             saved_pos;
132
139
  guint32             offset;
159
166
 
160
167
      if (grid)
161
168
        {
162
 
          gimp_parasite_list_remove (GIMP_IMAGE (image)->parasites,
 
169
          GimpImagePrivate *private = GIMP_IMAGE_GET_PRIVATE (image);
 
170
 
 
171
          gimp_parasite_list_remove (private->parasites,
163
172
                                     gimp_parasite_name (parasite));
164
173
 
165
174
          gimp_image_set_grid (GIMP_IMAGE (image), grid, FALSE);
171
180
 
172
181
  while (TRUE)
173
182
    {
 
183
      GimpLayer *layer;
 
184
      GList     *item_path = NULL;
 
185
 
174
186
      /* read in the offset of the next layer */
175
187
      info->cp += xcf_read_int32 (info->fp, &offset, 1);
176
188
 
190
202
        goto error;
191
203
 
192
204
      /* read in the layer */
193
 
      layer = xcf_load_layer (info, image);
 
205
      layer = xcf_load_layer (info, image, &item_path);
194
206
      if (!layer)
195
207
        goto error;
196
208
 
200
212
 
201
213
      /* add the layer to the image if its not the floating selection */
202
214
      if (layer != info->floating_sel)
203
 
        gimp_image_add_layer (image, layer,
204
 
                              gimp_container_num_children (image->layers));
 
215
        {
 
216
          GimpContainer *layers = gimp_image_get_layers (image);
 
217
          GimpContainer *container;
 
218
          GimpLayer     *parent;
 
219
 
 
220
          if (item_path)
 
221
            {
 
222
              if (info->floating_sel)
 
223
                {
 
224
                  /* there is a floating selection, but it will get
 
225
                   * added after all layers are loaded, so toplevel
 
226
                   * layer indices are off-by-one. Adjust item paths
 
227
                   * accordingly:
 
228
                   */
 
229
                  gint toplevel_index;
 
230
 
 
231
                  toplevel_index = GPOINTER_TO_UINT (item_path->data);
 
232
 
 
233
                  toplevel_index--;
 
234
 
 
235
                  item_path->data = GUINT_TO_POINTER (toplevel_index);
 
236
                }
 
237
 
 
238
              parent = GIMP_LAYER
 
239
                (gimp_item_stack_get_parent_by_path (GIMP_ITEM_STACK (layers),
 
240
                                                     item_path,
 
241
                                                     NULL));
 
242
 
 
243
              container = gimp_viewable_get_children (GIMP_VIEWABLE (parent));
 
244
 
 
245
              g_list_free (item_path);
 
246
            }
 
247
          else
 
248
            {
 
249
              parent    = NULL;
 
250
              container = layers;
 
251
            }
 
252
 
 
253
          gimp_image_add_layer (image, layer,
 
254
                                parent,
 
255
                                gimp_container_get_n_children (container),
 
256
                                FALSE);
 
257
        }
205
258
 
206
259
      /* restore the saved position so we'll be ready to
207
260
       *  read the next offset.
212
265
 
213
266
  while (TRUE)
214
267
    {
 
268
      GimpChannel *channel;
 
269
 
215
270
      /* read in the offset of the next channel */
216
271
      info->cp += xcf_read_int32 (info->fp, &offset, 1);
217
272
 
230
285
      if (! xcf_seek_pos (info, offset, NULL))
231
286
        goto error;
232
287
 
233
 
      /* read in the layer */
 
288
      /* read in the channel */
234
289
      channel = xcf_load_channel (info, image);
235
290
      if (!channel)
236
291
        goto error;
242
297
      /* add the channel to the image if its not the selection */
243
298
      if (channel != gimp_image_get_mask (image))
244
299
        gimp_image_add_channel (image, channel,
245
 
                                gimp_container_num_children (image->channels));
 
300
                                NULL, /* FIXME tree */
 
301
                                gimp_container_get_n_children (gimp_image_get_channels (image)),
 
302
                                FALSE);
246
303
 
247
304
      /* restore the saved position so we'll be ready to
248
305
       *  read the next offset.
251
308
        goto error;
252
309
    }
253
310
 
 
311
  xcf_load_add_masks (image);
 
312
 
254
313
  if (info->floating_sel && info->floating_sel_drawable)
255
314
    floating_sel_attach (info->floating_sel, info->floating_sel_drawable);
256
315
 
273
332
  if (num_successful_elements == 0)
274
333
    goto hard_error;
275
334
 
276
 
  gimp_message (gimp, G_OBJECT (info->progress), GIMP_MESSAGE_WARNING,
277
 
                _("This XCF file is corrupt!  I have loaded as much "
278
 
                  "of it as I can, but it is incomplete."));
 
335
  gimp_message_literal (gimp, G_OBJECT (info->progress), GIMP_MESSAGE_WARNING,
 
336
                        _("This XCF file is corrupt!  I have loaded as much "
 
337
                          "of it as I can, but it is incomplete."));
 
338
 
 
339
  xcf_load_add_masks (image);
279
340
 
280
341
  gimp_image_undo_enable (image);
281
342
 
282
343
  return image;
283
344
 
284
345
 hard_error:
285
 
  g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
286
 
               _("This XCF file is corrupt!  I could not even "
287
 
                 "salvage any partial image data from it."));
 
346
  g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_FAILED,
 
347
                       _("This XCF file is corrupt!  I could not even "
 
348
                         "salvage any partial image data from it."));
288
349
 
289
350
  g_object_unref (image);
290
351
 
291
352
  return NULL;
292
353
}
293
354
 
 
355
static void
 
356
xcf_load_add_masks (GimpImage *image)
 
357
{
 
358
  GList *layers;
 
359
  GList *list;
 
360
 
 
361
  layers = gimp_image_get_layer_list (image);
 
362
 
 
363
  for (list = layers; list; list = g_list_next (list))
 
364
    {
 
365
      GimpLayer     *layer = list->data;
 
366
      GimpLayerMask *mask;
 
367
 
 
368
      mask = g_object_get_data (G_OBJECT (layer), "gimp-layer-mask");
 
369
 
 
370
      if (mask)
 
371
        {
 
372
          gimp_layer_add_mask (layer, mask, FALSE, NULL);
 
373
 
 
374
          g_object_set_data (G_OBJECT (layer), "gimp-layer-mask", NULL);
 
375
        }
 
376
    }
 
377
 
 
378
  g_list_free (layers);
 
379
}
 
380
 
294
381
static gboolean
295
382
xcf_load_image_props (XcfInfo   *info,
296
383
                      GimpImage *image)
315
402
 
316
403
            info->cp += xcf_read_int32 (info->fp, &n_colors, 1);
317
404
 
 
405
            if (n_colors > (GIMP_IMAGE_COLORMAP_SIZE / 3))
 
406
              {
 
407
                gimp_message (info->gimp, G_OBJECT (info->progress),
 
408
                              GIMP_MESSAGE_ERROR,
 
409
                              "Maximum colormap size (%d) exceeded",
 
410
                              GIMP_IMAGE_COLORMAP_SIZE);
 
411
                return FALSE;
 
412
              }
 
413
 
318
414
            if (info->file_version == 0)
319
415
              {
320
416
                gint i;
321
417
 
322
 
                gimp_message (info->gimp, G_OBJECT (info->progress),
323
 
                              GIMP_MESSAGE_WARNING,
324
 
                              _("XCF warning: version 0 of XCF file format\n"
325
 
                                "did not save indexed colormaps correctly.\n"
326
 
                                "Substituting grayscale map."));
 
418
                gimp_message_literal (info->gimp, G_OBJECT (info->progress),
 
419
                                      GIMP_MESSAGE_WARNING,
 
420
                                      _("XCF warning: version 0 of XCF file format\n"
 
421
                                        "did not save indexed colormaps correctly.\n"
 
422
                                        "Substituting grayscale map."));
327
423
 
328
424
                if (! xcf_seek_pos (info, info->cp + n_colors, NULL))
329
425
                  return FALSE;
363
459
                gimp_message (info->gimp, G_OBJECT (info->progress),
364
460
                              GIMP_MESSAGE_ERROR,
365
461
                              "Unknown compression type: %d",
366
 
                              (int) compression);
 
462
                              (gint) compression);
367
463
                return FALSE;
368
464
              }
369
465
 
373
469
 
374
470
        case PROP_GUIDES:
375
471
          {
376
 
            gint32 position;
377
 
            gint8  orientation;
378
 
            gint   i, nguides;
 
472
            GimpImagePrivate *private = GIMP_IMAGE_GET_PRIVATE (image);
 
473
            gint32            position;
 
474
            gint8             orientation;
 
475
            gint              i, nguides;
379
476
 
380
477
            nguides = prop_size / (4 + 1);
381
478
            for (i = 0; i < nguides; i++)
400
497
                    break;
401
498
 
402
499
                  default:
403
 
                    gimp_message (info->gimp, G_OBJECT (info->progress),
404
 
                                  GIMP_MESSAGE_WARNING,
405
 
                                  "Guide orientation out of range in XCF file");
 
500
                    gimp_message_literal (info->gimp, G_OBJECT (info->progress),
 
501
                                          GIMP_MESSAGE_WARNING,
 
502
                                          "Guide orientation out of range in XCF file");
406
503
                    continue;
407
504
                  }
408
505
              }
409
506
 
410
507
            /*  this is silly as the order of guides doesn't really matter,
411
 
             *  but it restores the list to it's original order, which
 
508
             *  but it restores the list to its original order, which
412
509
             *  cannot be wrong  --Mitch
413
510
             */
414
 
            image->guides = g_list_reverse (image->guides);
 
511
            private->guides = g_list_reverse (private->guides);
415
512
          }
416
513
          break;
417
514
 
441
538
            if (xres < GIMP_MIN_RESOLUTION || xres > GIMP_MAX_RESOLUTION ||
442
539
                yres < GIMP_MIN_RESOLUTION || yres > GIMP_MAX_RESOLUTION)
443
540
              {
444
 
                gimp_message (info->gimp, G_OBJECT (info->progress),
445
 
                              GIMP_MESSAGE_WARNING,
446
 
                              "Warning, resolution out of range in XCF file");
447
 
                xres = image->gimp->config->default_image->xresolution;
448
 
                yres = image->gimp->config->default_image->yresolution;
 
541
                GimpTemplate *template = image->gimp->config->default_image;
 
542
 
 
543
                gimp_message_literal (info->gimp, G_OBJECT (info->progress),
 
544
                                      GIMP_MESSAGE_WARNING,
 
545
                                      "Warning, resolution out of range in XCF file");
 
546
                xres = gimp_template_get_resolution_x (template);
 
547
                yres = gimp_template_get_resolution_y (template);
449
548
              }
450
549
 
451
550
            gimp_image_set_resolution (image, xres, yres);
471
570
              }
472
571
 
473
572
            if (info->cp - base != prop_size)
474
 
              gimp_message (info->gimp, G_OBJECT (info->progress),
475
 
                            GIMP_MESSAGE_WARNING,
476
 
                            "Error while loading an image's parasites");
 
573
              gimp_message_literal (info->gimp, G_OBJECT (info->progress),
 
574
                                    GIMP_MESSAGE_WARNING,
 
575
                                    "Error while loading an image's parasites");
477
576
          }
478
577
          break;
479
578
 
484
583
            info->cp += xcf_read_int32 (info->fp, &unit, 1);
485
584
 
486
585
            if ((unit <= GIMP_UNIT_PIXEL) ||
487
 
                (unit >= _gimp_unit_get_number_of_built_in_units (image->gimp)))
 
586
                (unit >= gimp_unit_get_number_of_built_in_units ()))
488
587
              {
489
 
                gimp_message (info->gimp, G_OBJECT (info->progress),
490
 
                              GIMP_MESSAGE_WARNING,
491
 
                              "Warning, unit out of range in XCF file, "
492
 
                              "falling back to inches");
 
588
                gimp_message_literal (info->gimp, G_OBJECT (info->progress),
 
589
                                      GIMP_MESSAGE_WARNING,
 
590
                                      "Warning, unit out of range in XCF file, "
 
591
                                      "falling back to inches");
493
592
                unit = GIMP_UNIT_INCH;
494
593
              }
495
594
 
496
 
            image->resolution_unit = unit;
 
595
            gimp_image_set_unit (image, unit);
497
596
          }
498
597
          break;
499
598
 
518
617
              if (unit_strings[i] == NULL)
519
618
                unit_strings[i] = g_strdup ("");
520
619
 
521
 
            num_units = _gimp_unit_get_number_of_units (image->gimp);
 
620
            num_units = gimp_unit_get_number_of_units ();
522
621
 
523
 
            for (unit = _gimp_unit_get_number_of_built_in_units (image->gimp);
 
622
            for (unit = gimp_unit_get_number_of_built_in_units ();
524
623
                 unit < num_units; unit++)
525
624
              {
526
625
                /* if the factor and the identifier match some unit
527
626
                 * in unitrc, use the unitrc unit
528
627
                 */
529
 
                if ((ABS (_gimp_unit_get_factor (image->gimp,
530
 
                                                 unit) - factor) < 1e-5) &&
 
628
                if ((ABS (gimp_unit_get_factor (unit) - factor) < 1e-5) &&
531
629
                    (strcmp (unit_strings[0],
532
 
                             _gimp_unit_get_identifier (image->gimp,
533
 
                                                        unit)) == 0))
 
630
                             gimp_unit_get_identifier (unit)) == 0))
534
631
                  {
535
632
                    break;
536
633
                  }
538
635
 
539
636
            /* no match */
540
637
            if (unit == num_units)
541
 
              unit = _gimp_unit_new (image->gimp,
542
 
                                     unit_strings[0],
543
 
                                     factor,
544
 
                                     digits,
545
 
                                     unit_strings[1],
546
 
                                     unit_strings[2],
547
 
                                     unit_strings[3],
548
 
                                     unit_strings[4]);
 
638
              unit = gimp_unit_new (unit_strings[0],
 
639
                                    factor,
 
640
                                    digits,
 
641
                                    unit_strings[1],
 
642
                                    unit_strings[2],
 
643
                                    unit_strings[3],
 
644
                                    unit_strings[4]);
549
645
 
550
 
            image->resolution_unit = unit;
 
646
            gimp_image_set_unit (image, unit);
551
647
 
552
648
            for (i = 0; i < 5; i++)
553
649
              g_free (unit_strings[i]);
583
679
          g_printerr ("unexpected/unknown image property: %d (skipping)\n",
584
680
                      prop_type);
585
681
#endif
586
 
          {
587
 
            gsize  size = prop_size;
588
 
            guint8 buf[16];
589
 
            guint  amount;
590
 
 
591
 
            while (size > 0)
592
 
              {
593
 
                if (feof (info->fp))
594
 
                  return FALSE;
595
 
 
596
 
                amount = MIN (16, size);
597
 
                info->cp += xcf_read_int8 (info->fp, buf, amount);
598
 
                size -= MIN (16, amount);
599
 
              }
600
 
          }
 
682
          if (! xcf_skip_unknown_prop (info, prop_size))
 
683
            return FALSE;
601
684
          break;
602
685
        }
603
686
    }
606
689
}
607
690
 
608
691
static gboolean
609
 
xcf_load_layer_props (XcfInfo   *info,
610
 
                      GimpImage *image,
611
 
                      GimpLayer *layer,
612
 
                      gboolean  *apply_mask,
613
 
                      gboolean  *edit_mask,
614
 
                      gboolean  *show_mask,
615
 
                      guint32   *text_layer_flags)
 
692
xcf_load_layer_props (XcfInfo    *info,
 
693
                      GimpImage  *image,
 
694
                      GimpLayer **layer,
 
695
                      GList     **item_path,
 
696
                      gboolean   *apply_mask,
 
697
                      gboolean   *edit_mask,
 
698
                      gboolean   *show_mask,
 
699
                      guint32    *text_layer_flags,
 
700
                      guint32    *group_layer_flags)
616
701
{
617
702
  PropType prop_type;
618
703
  guint32  prop_size;
628
713
          return TRUE;
629
714
 
630
715
        case PROP_ACTIVE_LAYER:
631
 
          info->active_layer = layer;
 
716
          info->active_layer = *layer;
632
717
          break;
633
718
 
634
719
        case PROP_FLOATING_SELECTION:
635
 
          info->floating_sel = layer;
 
720
          info->floating_sel = *layer;
636
721
          info->cp +=
637
722
            xcf_read_int32 (info->fp,
638
723
                            (guint32 *) &info->floating_sel_offset, 1);
643
728
            guint32 opacity;
644
729
 
645
730
            info->cp += xcf_read_int32 (info->fp, &opacity, 1);
646
 
            gimp_layer_set_opacity (layer, (gdouble) opacity / 255.0, FALSE);
 
731
            gimp_layer_set_opacity (*layer, (gdouble) opacity / 255.0, FALSE);
647
732
          }
648
733
          break;
649
734
 
652
737
            gboolean visible;
653
738
 
654
739
            info->cp += xcf_read_int32 (info->fp, (guint32 *) &visible, 1);
655
 
            gimp_item_set_visible (GIMP_ITEM (layer), visible, FALSE);
 
740
            gimp_item_set_visible (GIMP_ITEM (*layer), visible, FALSE);
656
741
          }
657
742
          break;
658
743
 
661
746
            gboolean linked;
662
747
 
663
748
            info->cp += xcf_read_int32 (info->fp, (guint32 *) &linked, 1);
664
 
            gimp_item_set_linked (GIMP_ITEM (layer), linked, FALSE);
 
749
            gimp_item_set_linked (GIMP_ITEM (*layer), linked, FALSE);
 
750
          }
 
751
          break;
 
752
 
 
753
        case PROP_LOCK_CONTENT:
 
754
          {
 
755
            gboolean lock_content;
 
756
 
 
757
            info->cp += xcf_read_int32 (info->fp, (guint32 *) &lock_content, 1);
 
758
 
 
759
            if (gimp_item_can_lock_content (GIMP_ITEM (*layer)))
 
760
              gimp_item_set_lock_content (GIMP_ITEM (*layer),
 
761
                                          lock_content, FALSE);
665
762
          }
666
763
          break;
667
764
 
670
767
            gboolean lock_alpha;
671
768
 
672
769
            info->cp += xcf_read_int32 (info->fp, (guint32 *) &lock_alpha, 1);
673
 
            gimp_layer_set_lock_alpha (layer, lock_alpha, FALSE);
 
770
 
 
771
            if (gimp_layer_can_lock_alpha (*layer))
 
772
              gimp_layer_set_lock_alpha (*layer, lock_alpha, FALSE);
674
773
          }
675
774
          break;
676
775
 
687
786
          break;
688
787
 
689
788
        case PROP_OFFSETS:
690
 
          info->cp +=
691
 
            xcf_read_int32 (info->fp,
692
 
                            (guint32 *) &GIMP_ITEM (layer)->offset_x, 1);
693
 
          info->cp +=
694
 
            xcf_read_int32 (info->fp,
695
 
                            (guint32 *) &GIMP_ITEM (layer)->offset_y, 1);
 
789
          {
 
790
            guint32 offset_x;
 
791
            guint32 offset_y;
 
792
 
 
793
            info->cp += xcf_read_int32 (info->fp, &offset_x, 1);
 
794
            info->cp += xcf_read_int32 (info->fp, &offset_y, 1);
 
795
 
 
796
            gimp_item_set_offset (GIMP_ITEM (*layer), offset_x, offset_y);
 
797
          }
696
798
          break;
697
799
 
698
800
        case PROP_MODE:
700
802
            guint32 mode;
701
803
 
702
804
            info->cp += xcf_read_int32 (info->fp, &mode, 1);
703
 
            gimp_layer_set_mode (layer, (GimpLayerModeEffects) mode, FALSE);
 
805
            gimp_layer_set_mode (*layer, (GimpLayerModeEffects) mode, FALSE);
704
806
          }
705
807
          break;
706
808
 
709
811
            GimpTattoo tattoo;
710
812
 
711
813
            info->cp += xcf_read_int32 (info->fp, (guint32 *) &tattoo, 1);
712
 
            gimp_item_set_tattoo (GIMP_ITEM (layer), tattoo);
 
814
            gimp_item_set_tattoo (GIMP_ITEM (*layer), tattoo);
713
815
          }
714
816
          break;
715
817
 
721
823
            while (info->cp - base < prop_size)
722
824
              {
723
825
                p = xcf_load_parasite (info);
724
 
                gimp_item_parasite_attach (GIMP_ITEM (layer), p);
 
826
                gimp_item_parasite_attach (GIMP_ITEM (*layer), p, FALSE);
725
827
                gimp_parasite_free (p);
726
828
              }
727
829
 
728
830
            if (info->cp - base != prop_size)
729
 
              gimp_message (info->gimp, G_OBJECT (info->progress),
730
 
                            GIMP_MESSAGE_WARNING,
731
 
                            "Error while loading a layer's parasites");
 
831
              gimp_message_literal (info->gimp, G_OBJECT (info->progress),
 
832
                                    GIMP_MESSAGE_WARNING,
 
833
                                    "Error while loading a layer's parasites");
732
834
          }
733
835
          break;
734
836
 
736
838
          info->cp += xcf_read_int32 (info->fp, text_layer_flags, 1);
737
839
          break;
738
840
 
 
841
        case PROP_GROUP_ITEM:
 
842
          {
 
843
            GimpLayer *group;
 
844
 
 
845
            group = gimp_group_layer_new (image);
 
846
 
 
847
            gimp_object_set_name (GIMP_OBJECT (group),
 
848
                                  gimp_object_get_name (*layer));
 
849
 
 
850
            GIMP_DRAWABLE (group)->private->type =
 
851
              gimp_drawable_type (GIMP_DRAWABLE (*layer));
 
852
 
 
853
            g_object_ref_sink (*layer);
 
854
            g_object_unref (*layer);
 
855
            *layer = group;
 
856
          }
 
857
          break;
 
858
 
 
859
        case PROP_ITEM_PATH:
 
860
          {
 
861
            glong  base = info->cp;
 
862
            GList *path = NULL;
 
863
 
 
864
            while (info->cp - base < prop_size)
 
865
              {
 
866
                guint32 index;
 
867
 
 
868
                info->cp += xcf_read_int32 (info->fp, &index, 1);
 
869
 
 
870
                path = g_list_append (path, GUINT_TO_POINTER (index));
 
871
              }
 
872
 
 
873
            *item_path = path;
 
874
          }
 
875
          break;
 
876
 
 
877
        case PROP_GROUP_ITEM_FLAGS:
 
878
          info->cp += xcf_read_int32 (info->fp, group_layer_flags, 1);
 
879
          break;
 
880
 
739
881
        default:
740
882
#ifdef GIMP_UNSTABLE
741
883
          g_printerr ("unexpected/unknown layer property: %d (skipping)\n",
742
884
                      prop_type);
743
885
#endif
744
 
          {
745
 
            gsize  size = prop_size;
746
 
            guint8 buf[16];
747
 
            guint  amount;
748
 
 
749
 
            while (size > 0)
750
 
              {
751
 
                if (feof (info->fp))
752
 
                  return FALSE;
753
 
 
754
 
                amount = MIN (16, size);
755
 
                info->cp += xcf_read_int8 (info->fp, buf, amount);
756
 
                size -= MIN (16, amount);
757
 
              }
758
 
          }
 
886
          if (! xcf_skip_unknown_prop (info, prop_size))
 
887
            return FALSE;
759
888
          break;
760
889
        }
761
890
    }
787
916
 
788
917
        case PROP_SELECTION:
789
918
          {
790
 
            GimpChannel *mask;
 
919
            GimpImagePrivate *private = GIMP_IMAGE_GET_PRIVATE (image);
 
920
            GimpChannel      *mask;
791
921
 
792
922
            g_object_unref (gimp_image_get_mask (image));
793
923
 
794
 
            mask = image->selection_mask =
 
924
            mask = private->selection_mask =
795
925
              gimp_selection_new (image,
796
 
                                  gimp_item_width (GIMP_ITEM (*channel)),
797
 
                                  gimp_item_height (GIMP_ITEM (*channel)));
 
926
                                  gimp_item_get_width  (GIMP_ITEM (*channel)),
 
927
                                  gimp_item_get_height (GIMP_ITEM (*channel)));
798
928
            g_object_ref_sink (mask);
799
929
 
800
 
            tile_manager_unref (GIMP_DRAWABLE (mask)->tiles);
801
 
            GIMP_DRAWABLE (mask)->tiles =
802
 
              GIMP_DRAWABLE (*channel)->tiles;
803
 
            GIMP_DRAWABLE (*channel)->tiles = NULL;
 
930
            tile_manager_unref (GIMP_DRAWABLE (mask)->private->tiles);
 
931
            GIMP_DRAWABLE (mask)->private->tiles =
 
932
              GIMP_DRAWABLE (*channel)->private->tiles;
 
933
            GIMP_DRAWABLE (*channel)->private->tiles = NULL;
804
934
            g_object_unref (*channel);
805
935
            *channel = mask;
806
936
            (*channel)->boundary_known = FALSE;
837
967
          }
838
968
          break;
839
969
 
 
970
        case PROP_LOCK_CONTENT:
 
971
          {
 
972
            gboolean lock_content;
 
973
 
 
974
            info->cp += xcf_read_int32 (info->fp, (guint32 *) &lock_content, 1);
 
975
            gimp_item_set_lock_content (GIMP_ITEM (*channel),
 
976
                                        lock_content ? TRUE : FALSE, FALSE);
 
977
          }
 
978
          break;
 
979
 
840
980
        case PROP_SHOW_MASKED:
841
981
          {
842
982
            gboolean show_masked;
872
1012
            while ((info->cp - base) < prop_size)
873
1013
              {
874
1014
                p = xcf_load_parasite (info);
875
 
                gimp_item_parasite_attach (GIMP_ITEM (*channel), p);
 
1015
                gimp_item_parasite_attach (GIMP_ITEM (*channel), p, FALSE);
876
1016
                gimp_parasite_free (p);
877
1017
              }
878
1018
 
879
1019
            if (info->cp - base != prop_size)
880
 
              gimp_message (info->gimp, G_OBJECT (info->progress),
881
 
                            GIMP_MESSAGE_WARNING,
882
 
                            "Error while loading a channel's parasites");
 
1020
              gimp_message_literal (info->gimp, G_OBJECT (info->progress),
 
1021
                                    GIMP_MESSAGE_WARNING,
 
1022
                                    "Error while loading a channel's parasites");
883
1023
          }
884
1024
          break;
885
1025
 
888
1028
          g_printerr ("unexpected/unknown channel property: %d (skipping)\n",
889
1029
                      prop_type);
890
1030
#endif
891
 
          {
892
 
            gsize  size = prop_size;
893
 
            guint8 buf[16];
894
 
            guint  amount;
895
 
 
896
 
            while (size > 0)
897
 
              {
898
 
                if (feof (info->fp))
899
 
                  return FALSE;
900
 
 
901
 
                amount = MIN (16, size);
902
 
                info->cp += xcf_read_int8 (info->fp, buf, amount);
903
 
                size -= MIN (16, amount);
904
 
              }
905
 
          }
 
1031
          if (! xcf_skip_unknown_prop (info, prop_size))
 
1032
            return FALSE;
906
1033
          break;
907
1034
        }
908
1035
    }
929
1056
}
930
1057
 
931
1058
static GimpLayer *
932
 
xcf_load_layer (XcfInfo   *info,
933
 
                GimpImage *image)
 
1059
xcf_load_layer (XcfInfo    *info,
 
1060
                GimpImage  *image,
 
1061
                GList     **item_path)
934
1062
{
935
1063
  GimpLayer     *layer;
936
1064
  GimpLayerMask *layer_mask;
941
1069
  gboolean       show_mask  = FALSE;
942
1070
  gboolean       active;
943
1071
  gboolean       floating;
 
1072
  guint32        group_layer_flags = 0;
944
1073
  guint32        text_layer_flags = 0;
945
1074
  gint           width;
946
1075
  gint           height;
967
1096
    return NULL;
968
1097
 
969
1098
  /* read in the layer properties */
970
 
  if (! xcf_load_layer_props (info, image, layer,
 
1099
  if (! xcf_load_layer_props (info, image, &layer, item_path,
971
1100
                              &apply_mask, &edit_mask, &show_mask,
972
 
                              &text_layer_flags))
 
1101
                              &text_layer_flags, &group_layer_flags))
973
1102
    goto error;
974
1103
 
975
1104
  xcf_progress_update (info);
993
1122
  info->cp += xcf_read_int32 (info->fp, &hierarchy_offset, 1);
994
1123
  info->cp += xcf_read_int32 (info->fp, &layer_mask_offset, 1);
995
1124
 
996
 
  /* read in the hierarchy */
997
 
  if (! xcf_seek_pos (info, hierarchy_offset, NULL))
998
 
    goto error;
999
 
 
1000
 
  if (! xcf_load_hierarchy (info,
1001
 
                            gimp_drawable_get_tiles (GIMP_DRAWABLE (layer))))
1002
 
    goto error;
1003
 
 
1004
 
  xcf_progress_update (info);
 
1125
  /* read in the hierarchy (ignore it for group layers, both as an
 
1126
   * optimization and because the hierarchy's extents don't match
 
1127
   * the group layer's tiles)
 
1128
   */
 
1129
  if (! gimp_viewable_get_children (GIMP_VIEWABLE (layer)))
 
1130
    {
 
1131
      if (! xcf_seek_pos (info, hierarchy_offset, NULL))
 
1132
        goto error;
 
1133
 
 
1134
      if (! xcf_load_hierarchy (info,
 
1135
                                gimp_drawable_get_tiles (GIMP_DRAWABLE (layer))))
 
1136
        goto error;
 
1137
 
 
1138
      xcf_progress_update (info);
 
1139
    }
 
1140
  else
 
1141
    {
 
1142
      gboolean expanded = group_layer_flags & XCF_GROUP_ITEM_EXPANDED;
 
1143
 
 
1144
      gimp_viewable_set_expanded (GIMP_VIEWABLE (layer), expanded);
 
1145
    }
1005
1146
 
1006
1147
  /* read in the layer mask */
1007
1148
  if (layer_mask_offset != 0)
1019
1160
      gimp_layer_mask_set_edit  (layer_mask, edit_mask);
1020
1161
      gimp_layer_mask_set_show  (layer_mask, show_mask, FALSE);
1021
1162
 
1022
 
      gimp_layer_add_mask (layer, layer_mask, FALSE, NULL);
 
1163
      /* don't add the layer mask yet, that won't work for group
 
1164
       * layers which update their size automatically; instead
 
1165
       * attach it so it can be added when all layers are loaded
 
1166
       */
 
1167
      g_object_set_data_full (G_OBJECT (layer), "gimp-layer-mask",
 
1168
                              g_object_ref_sink (layer_mask),
 
1169
                              (GDestroyNotify) g_object_unref);
1023
1170
    }
1024
1171
 
1025
1172
  /* attach the floating selection... */
1251
1398
 
1252
1399
      if (offset == 0)
1253
1400
        {
1254
 
          gimp_message (info->gimp, G_OBJECT (info->progress),
1255
 
                        GIMP_MESSAGE_ERROR,
1256
 
                        "not enough tiles found in level");
 
1401
          gimp_message_literal (info->gimp, G_OBJECT (info->progress),
 
1402
                                GIMP_MESSAGE_ERROR,
 
1403
                                "not enough tiles found in level");
1257
1404
          return FALSE;
1258
1405
        }
1259
1406
 
1381
1528
  if (data_length <= 0)
1382
1529
    return TRUE;
1383
1530
 
1384
 
  data = tile_data_pointer (tile, 0, 0);
1385
1531
  bpp = tile_bpp (tile);
1386
1532
 
1387
1533
  xcfdata = xcfodata = g_malloc (data_length);
1527
1673
  while (num_paths-- > 0)
1528
1674
    xcf_load_old_path (info, image);
1529
1675
 
1530
 
  active_vectors = (GimpVectors *)
1531
 
    gimp_container_get_child_by_index (image->vectors, last_selected_row);
 
1676
  active_vectors =
 
1677
    GIMP_VECTORS (gimp_container_get_child_by_index (gimp_image_get_vectors (image),
 
1678
                                                     last_selected_row));
1532
1679
 
1533
1680
  if (active_vectors)
1534
1681
    gimp_image_set_active_vectors (image, active_vectors);
1582
1729
 
1583
1730
  /* skip empty compatibility paths */
1584
1731
  if (num_points == 0)
1585
 
    return FALSE;
 
1732
    {
 
1733
      g_free (name);
 
1734
      return FALSE;
 
1735
    }
1586
1736
 
1587
1737
  points = g_new0 (GimpVectorsCompatPoint, num_points);
1588
1738
 
1625
1775
    gimp_item_set_tattoo (GIMP_ITEM (vectors), tattoo);
1626
1776
 
1627
1777
  gimp_image_add_vectors (image, vectors,
1628
 
                          gimp_container_num_children (image->vectors));
 
1778
                          NULL, /* can't be a tree */
 
1779
                          gimp_container_get_n_children (gimp_image_get_vectors (image)),
 
1780
                          FALSE);
1629
1781
 
1630
1782
  return TRUE;
1631
1783
}
1638
1790
  guint32      active_index;
1639
1791
  guint32      num_paths;
1640
1792
  GimpVectors *active_vectors;
1641
 
  guint32      base;
1642
1793
 
1643
1794
#ifdef GIMP_XCF_PATH_DEBUG
1644
1795
  g_printerr ("xcf_load_vectors\n");
1645
1796
#endif
1646
1797
 
1647
 
  base = info->cp;
1648
 
 
1649
1798
  info->cp += xcf_read_int32  (info->fp, &version, 1);
1650
1799
 
1651
1800
  if (version != 1)
1667
1816
    if (! xcf_load_vector (info, image))
1668
1817
      return FALSE;
1669
1818
 
1670
 
  active_vectors = (GimpVectors *)
1671
 
    gimp_container_get_child_by_index (image->vectors, active_index);
 
1819
  /* FIXME tree */
 
1820
  active_vectors =
 
1821
    GIMP_VECTORS (gimp_container_get_child_by_index (gimp_image_get_vectors (image),
 
1822
                                                     active_index));
1672
1823
 
1673
1824
  if (active_vectors)
1674
1825
    gimp_image_set_active_vectors (image, active_vectors);
1710
1861
#endif
1711
1862
 
1712
1863
  vectors = gimp_vectors_new (image, name);
 
1864
  g_free (name);
1713
1865
 
1714
1866
  gimp_item_set_visible (GIMP_ITEM (vectors), visible, FALSE);
1715
1867
  gimp_item_set_linked (GIMP_ITEM (vectors), linked, FALSE);
1724
1876
      if (! parasite)
1725
1877
        return FALSE;
1726
1878
 
1727
 
      gimp_item_parasite_attach (GIMP_ITEM (vectors), parasite);
 
1879
      gimp_item_parasite_attach (GIMP_ITEM (vectors), parasite, FALSE);
1728
1880
      gimp_parasite_free (parasite);
1729
1881
    }
1730
1882
 
1735
1887
      guint32      num_axes;
1736
1888
      guint32      num_control_points;
1737
1889
      guint32      type;
1738
 
      gfloat       coords[7] = GIMP_COORDS_DEFAULT_VALUES;
 
1890
      gfloat       coords[8] = GIMP_COORDS_DEFAULT_VALUES;
1739
1891
      GimpStroke  *stroke;
1740
1892
      gint         j;
1741
1893
 
1742
1894
      GValueArray *control_points;
1743
1895
      GValue       value = { 0, };
1744
 
      GimpAnchor   anchor;
 
1896
      GimpAnchor   anchor = { { 0, } };
1745
1897
      GType        stroke_type;
1746
1898
 
1747
1899
      g_value_init (&value, GIMP_TYPE_ANCHOR);
1811
1963
                             NULL);
1812
1964
 
1813
1965
      gimp_vectors_stroke_add (vectors, stroke);
 
1966
 
 
1967
      g_object_unref (stroke);
 
1968
      g_value_array_free (control_points);
1814
1969
    }
1815
1970
 
1816
1971
  gimp_image_add_vectors (image, vectors,
1817
 
                          gimp_container_num_children (image->vectors));
 
1972
                          NULL, /* FIXME tree */
 
1973
                          gimp_container_get_n_children (gimp_image_get_vectors (image)),
 
1974
                          FALSE);
 
1975
 
 
1976
  return TRUE;
 
1977
}
 
1978
 
 
1979
static gboolean
 
1980
xcf_skip_unknown_prop (XcfInfo *info,
 
1981
                       gsize   size)
 
1982
{
 
1983
  guint8 buf[16];
 
1984
  guint  amount;
 
1985
 
 
1986
  while (size > 0)
 
1987
    {
 
1988
      if (feof (info->fp))
 
1989
        return FALSE;
 
1990
 
 
1991
      amount = MIN (16, size);
 
1992
      info->cp += xcf_read_int8 (info->fp, buf, amount);
 
1993
      size -= MIN (16, amount);
 
1994
    }
1818
1995
 
1819
1996
  return TRUE;
1820
1997
}