61#include "xcf-private.h"
68static bool xcf_load_image_props (XcfInfo * info, KisImage * gimage);
69static bool xcf_load_layer_props (XcfInfo * info,
75 TQ_INT32 * text_layer_flags);
76static bool xcf_load_channel_props (XcfInfo * info,
78 GimpChannel ** channel);
79static bool xcf_load_prop (XcfInfo * info,
80 PropType * prop_type, TQ_INT32 * prop_size);
81static KisLayer *xcf_load_layer (XcfInfo * info, KisImage * gimage);
86static bool xcf_load_hierarchy (XcfInfo * info, TileManager * tiles);
87static bool xcf_load_level (XcfInfo * info, TileManager * tiles);
88static bool xcf_load_tile (XcfInfo * info, Tile * tile);
89static bool xcf_load_tile_rle (XcfInfo * info,
90 Tile * tile, TQ_INT32 data_length);
92static bool xcf_load_old_paths (XcfInfo * info, KisImage * gimage);
93static bool xcf_load_old_path (XcfInfo * info, KisImage * gimage);
94static bool xcf_load_vectors (XcfInfo * info, KisImage * gimage);
95static bool xcf_load_vector (XcfInfo * info, KisImage * gimage);
98static bool xcf_swap_func (TQ_INT32 fd,
99 Tile * tile, TQ_INT32 cmd, gpointer user_data);
104xcf_load_image (XcfInfo * info)
115 TQ_INT32 num_successful_elements = 0;
118 info->cp += xcf_read_int32 (info->fp, (TQ_INT32 *) & width, 1);
119 info->cp += xcf_read_int32 (info->fp, (TQ_INT32 *) & height, 1);
120 info->cp += xcf_read_int32 (info->fp, (TQ_INT32 *) & image_type, 1);
122 gimage = gimp_create_image (gimp, width, height, image_type, FALSE);
124 gimp_image_undo_disable (gimage);
127 if (!xcf_load_image_props (info, gimage))
131 parasite = gimp_image_parasite_find (GIMP_IMAGE (gimage),
132 gimp_grid_parasite_name ());
135 GimpGrid *grid = gimp_grid_from_parasite (parasite);
139 gimp_parasite_list_remove (GIMP_IMAGE (gimage)->parasites,
140 gimp_parasite_name (parasite));
142 gimp_image_set_grid (GIMP_IMAGE (gimage), grid,
false);
149 info->cp += xcf_read_int32 (info->fp, &offset, 1);
160 saved_pos = info->cp;
163 if (!xcf_seek_pos (info, offset, NULL))
167 layer = xcf_load_layer (info, gimage);
171 num_successful_elements++;
174 if (layer != info->floating_sel)
175 gimp_image_add_layer (gimage, layer,
176 gimp_container_num_children (gimage->layers));
181 if (!xcf_seek_pos (info, saved_pos, NULL))
188 info->cp += xcf_read_int32 (info->fp, &offset, 1);
199 saved_pos = info->cp;
202 if (!xcf_seek_pos (info, offset, NULL))
206 channel = xcf_load_channel (info, gimage);
210 num_successful_elements++;
213 if (channel != gimage->selection_mask)
214 gimp_image_add_channel (gimage, channel, -1);
219 if (!xcf_seek_pos (info, saved_pos, NULL))
223 if (info->floating_sel && info->floating_sel_drawable)
224 floating_sel_attach (info->floating_sel, info->floating_sel_drawable);
226 if (info->active_layer)
227 gimp_image_set_active_layer (gimage, info->active_layer);
229 if (info->active_channel)
230 gimp_image_set_active_channel (gimage, info->active_channel);
232 gimp_image_set_filename (gimage, info->filename);
234 if (info->tattoo_state > 0)
235 gimp_image_set_tattoo_state (gimage, info->tattoo_state);
237 gimp_image_undo_enable (gimage);
242 if (num_successful_elements == 0)
245 g_message (
"XCF: This file is corrupt! I have loaded as much\n"
246 "of it as I can, but it is incomplete.");
248 gimp_image_undo_enable (gimage);
253 g_message (
"XCF: This file is corrupt! I could not even\n"
254 "salvage any partial image data from it.");
256 g_object_unref (gimage);
262xcf_load_image_props (XcfInfo * info, KisImage * gimage)
269 if (!xcf_load_prop (info, &prop_type, &prop_size))
278 if (info->file_version == 0)
282 g_message (_(
"XCF warning: version 0 of XCF file format\n"
283 "did not save indexed colormaps correctly.\n"
284 "Substituting grayscale map."));
286 xcf_read_int32 (info->fp, (TQ_INT32 *) & gimage->num_cols, 1);
287 gimage->cmap = g_new (guchar, gimage->num_cols * 3);
288 if (!xcf_seek_pos (info, info->cp + gimage->num_cols, NULL))
291 for (i = 0; i < gimage->num_cols; i++)
293 gimage->cmap[i * 3 + 0] = i;
294 gimage->cmap[i * 3 + 1] = i;
295 gimage->cmap[i * 3 + 2] = i;
301 xcf_read_int32 (info->fp, (TQ_INT32 *) & gimage->num_cols, 1);
302 gimage->cmap = g_new (guchar, gimage->num_cols * 3);
304 xcf_read_int8 (info->fp,
305 (TQ_UINT8 *) gimage->cmap,
306 gimage->num_cols * 3);
313 if (gimp_image_base_type (gimage) != GIMP_INDEXED)
315 g_free (gimage->cmap);
317 gimage->num_cols = 0;
321 case PROP_COMPRESSION:
323 TQ_UINT8 compression;
326 xcf_read_int8 (info->fp, (TQ_UINT8 *) & compression, 1);
328 if ((compression != COMPRESS_NONE) &&
329 (compression != COMPRESS_RLE) &&
330 (compression != COMPRESS_ZLIB) &&
331 (compression != COMPRESS_FRACTAL))
333 g_message (
"unknown compression type: %d", (
int) compression);
337 info->compression = compression;
344 TQ_INT328 orientation;
347 nguides = prop_size / (4 + 1);
348 for (i = 0; i < nguides; i++)
351 xcf_read_int32 (info->fp, (TQ_INT32 *) & position, 1);
353 xcf_read_int8 (info->fp, (TQ_UINT8 *) & orientation, 1);
361 case XCF_ORIENTATION_HORIZONTAL:
362 gimp_image_add_hguide (gimage, position,
false);
365 case XCF_ORIENTATION_VERTICAL:
366 gimp_image_add_vguide (gimage, position,
false);
370 g_message (
"guide orientation out of range in XCF file");
379 gimage->guides = g_list_reverse (gimage->guides);
383 case PROP_RESOLUTION:
387 info->cp += xcf_read_float (info->fp, &xres, 1);
388 info->cp += xcf_read_float (info->fp, &yres, 1);
389 if (xres < GIMP_MIN_RESOLUTION || xres > GIMP_MAX_RESOLUTION ||
390 yres < GIMP_MIN_RESOLUTION || yres > GIMP_MAX_RESOLUTION)
392 g_message (
"Warning, resolution out of range in XCF file");
393 xres = gimage->gimp->config->default_image->xresolution;
394 yres = gimage->gimp->config->default_image->yresolution;
396 gimage->xresolution = xres;
397 gimage->yresolution = yres;
403 info->cp += xcf_read_int32 (info->fp, &info->tattoo_state, 1);
409 glong base = info->cp;
412 while (info->cp - base < prop_size)
414 p = xcf_load_parasite (info);
415 gimp_image_parasite_attach (gimage, p);
416 gimp_parasite_free (p);
418 if (info->cp - base != prop_size)
419 g_message (
"Error while loading an image's parasites");
427 info->cp += xcf_read_int32 (info->fp, &unit, 1);
429 if ((unit <= GIMP_UNIT_PIXEL) ||
431 _gimp_unit_get_number_of_built_in_units (gimage->gimp)))
433 g_message (
"Warning, unit out of range in XCF file, "
434 "falling back to inches");
435 unit = GIMP_UNIT_INCH;
438 gimage->resolution_unit = unit;
443 xcf_load_old_paths (info, gimage);
448 TQCString *unit_strings[5];
455 info->cp += xcf_read_float (info->fp, &factor, 1);
456 info->cp += xcf_read_int32 (info->fp, &digits, 1);
457 info->cp += xcf_read_string (info->fp, unit_strings, 5);
459 for (i = 0; i < 5; i++)
460 if (unit_strings[i] == NULL)
461 unit_strings[i] = g_strdup (
"");
463 num_units = _gimp_unit_get_number_of_units (gimage->gimp);
466 _gimp_unit_get_number_of_built_in_units (gimage->gimp);
467 unit < num_units; unit++)
472 if ((ABS (_gimp_unit_get_factor (gimage->gimp,
473 unit) - factor) < 1e-5) &&
474 (strcmp (unit_strings[0],
475 _gimp_unit_get_identifier (gimage->gimp,
483 if (unit == num_units)
484 unit = _gimp_unit_new (gimage->gimp,
490 unit_strings[3], unit_strings[4]);
492 gimage->resolution_unit = unit;
494 for (i = 0; i < 5; i++)
495 g_free (unit_strings[i]);
501 TQ_INT32 base = info->cp;
503 if (xcf_load_vectors (info, gimage))
505 if (base + prop_size != info->cp)
508 (
"Mismatch in PROP_VECTORS size: skipping %d bytes.",
509 base + prop_size - info->cp);
510 xcf_seek_pos (info, base + prop_size, NULL);
518 xcf_seek_pos (info, base + prop_size, NULL);
525 g_printerr (
"unexpected/unknown image property: %d (skipping)",
532 while (prop_size > 0)
534 amount = MIN (16, prop_size);
535 info->cp += xcf_read_int8 (info->fp, buf, amount);
536 prop_size -= MIN (16, amount);
547xcf_load_layer_props (XcfInfo * info,
552 bool * show_mask, TQ_INT32 * text_layer_flags)
559 if (!xcf_load_prop (info, &prop_type, &prop_size))
567 case PROP_ACTIVE_LAYER:
568 info->active_layer = layer;
571 case PROP_FLOATING_SELECTION:
572 info->floating_sel = layer;
574 xcf_read_int32 (info->fp,
575 (TQ_INT32 *) & info->floating_sel_offset, 1);
582 info->cp += xcf_read_int32 (info->fp, &opacity, 1);
583 layer->opacity = CLAMP ((gdouble) opacity / 255.0,
584 GIMP_OPACITY_TRANSPARENT,
585 GIMP_OPACITY_OPAQUE);
593 info->cp += xcf_read_int32 (info->fp, (TQ_INT32 *) & visible, 1);
594 gimp_item_set_visible (GIMP_ITEM (layer),
595 visible ?
true : false, false);
603 info->cp += xcf_read_int32 (info->fp, (TQ_INT32 *) & linked, 1);
604 gimp_item_set_linked (GIMP_ITEM (layer),
605 linked ?
true : false, false);
609 case PROP_LOCK_ALPHA:
611 xcf_read_int32 (info->fp, (TQ_INT32 *) & layer->lock_alpha, 1);
614 case PROP_APPLY_MASK:
615 info->cp += xcf_read_int32 (info->fp, (TQ_INT32 *) apply_mask, 1);
619 info->cp += xcf_read_int32 (info->fp, (TQ_INT32 *) edit_mask, 1);
623 info->cp += xcf_read_int32 (info->fp, (TQ_INT32 *) show_mask, 1);
628 xcf_read_int32 (info->fp,
629 (TQ_INT32 *) & GIMP_ITEM (layer)->offset_x, 1);
631 xcf_read_int32 (info->fp,
632 (TQ_INT32 *) & GIMP_ITEM (layer)->offset_y, 1);
636 info->cp += xcf_read_int32 (info->fp, (TQ_INT32 *) & layer->mode, 1);
640 info->cp += xcf_read_int32 (info->fp,
641 (TQ_INT32 *) & GIMP_ITEM (layer)->tattoo,
647 glong base = info->cp;
650 while (info->cp - base < prop_size)
652 p = xcf_load_parasite (info);
653 gimp_item_parasite_attach (GIMP_ITEM (layer), p);
654 gimp_parasite_free (p);
656 if (info->cp - base != prop_size)
657 g_message (
"Error while loading a layer's parasites");
661 case PROP_TEXT_LAYER_FLAGS:
662 info->cp += xcf_read_int32 (info->fp, text_layer_flags, 1);
671 g_printerr (
"unexpected/unknown layer property: %d (skipping)",
674 while (prop_size > 0)
676 amount = MIN (16, prop_size);
677 info->cp += xcf_read_int8 (info->fp, buf, amount);
678 prop_size -= MIN (16, amount);
689xcf_load_channel_props (XcfInfo * info,
690 KisImage * gimage, GimpChannel ** channel)
697 if (!xcf_load_prop (info, &prop_type, &prop_size))
705 case PROP_ACTIVE_CHANNEL:
706 info->active_channel = *channel;
710 g_object_unref (gimage->selection_mask);
711 gimage->selection_mask =
712 gimp_selection_new (gimage,
713 gimp_item_width (GIMP_ITEM (*channel)),
714 gimp_item_height (GIMP_ITEM (*channel)));
715 g_object_ref (gimage->selection_mask);
716 gimp_item_sink (GIMP_ITEM (gimage->selection_mask));
718 tile_manager_unref (GIMP_DRAWABLE (gimage->selection_mask)->tiles);
719 GIMP_DRAWABLE (gimage->selection_mask)->tiles =
720 GIMP_DRAWABLE (*channel)->tiles;
721 GIMP_DRAWABLE (*channel)->tiles = NULL;
722 g_object_unref (*channel);
723 *channel = gimage->selection_mask;
724 (*channel)->boundary_known =
false;
725 (*channel)->bounds_known =
false;
732 info->cp += xcf_read_int32 (info->fp, &opacity, 1);
733 (*channel)->color.a = opacity / 255.0;
741 info->cp += xcf_read_int32 (info->fp, (TQ_INT32 *) & visible, 1);
742 gimp_item_set_visible (GIMP_ITEM (*channel),
743 visible ?
true : false, false);
751 info->cp += xcf_read_int32 (info->fp, (TQ_INT32 *) & linked, 1);
752 gimp_item_set_linked (GIMP_ITEM (*channel),
753 linked ?
true : false, false);
757 case PROP_SHOW_MASKED:
762 xcf_read_int32 (info->fp, (TQ_INT32 *) & show_masked, 1);
763 gimp_channel_set_show_masked (*channel, show_masked);
771 info->cp += xcf_read_int8 (info->fp, (TQ_UINT8 *) col, 3);
773 gimp_rgb_set_uchar (&(*channel)->color, col[0], col[1], col[2]);
779 xcf_read_int32 (info->fp, &GIMP_ITEM (*channel)->tattoo, 1);
784 glong base = info->cp;
787 while ((info->cp - base) < prop_size)
789 p = xcf_load_parasite (info);
790 gimp_item_parasite_attach (GIMP_ITEM (*channel), p);
791 gimp_parasite_free (p);
793 if (info->cp - base != prop_size)
794 g_message (
"Error while loading a channel's parasites");
800 g_printerr (
"unexpected/unknown channel property: %d (skipping)",
808 while (prop_size > 0)
810 amount = MIN (16, prop_size);
811 info->cp += xcf_read_int8 (info->fp, buf, amount);
812 prop_size -= MIN (16, amount);
823xcf_load_prop (XcfInfo * info, PropType * prop_type, TQ_INT32 * prop_size)
825 info->cp += xcf_read_int32 (info->fp, (TQ_INT32 *) prop_type, 1);
826 info->cp += xcf_read_int32 (info->fp, (TQ_INT32 *) prop_size, 1);
831xcf_load_layer (XcfInfo * info, KisImage * gimage)
834 GimpLayerMask *layer_mask;
835 TQ_INT32 hierarchy_offset;
836 TQ_INT32 layer_mask_offset;
837 bool apply_mask =
true;
838 bool edit_mask =
false;
839 bool show_mask =
false;
842 TQ_INT32 text_layer_flags = 0;
852 is_fs_drawable = (info->cp == info->floating_sel_offset);
855 info->cp += xcf_read_int32 (info->fp, (TQ_INT32 *) & width, 1);
856 info->cp += xcf_read_int32 (info->fp, (TQ_INT32 *) & height, 1);
857 info->cp += xcf_read_int32 (info->fp, (TQ_INT32 *) & type, 1);
858 info->cp += xcf_read_string (info->fp, &name, 1);
861 layer = gimp_layer_new (gimage, width, height,
862 type, name, 255, GIMP_NORMAL_MODE);
868 if (!xcf_load_layer_props (info, gimage, layer,
869 &apply_mask, &edit_mask, &show_mask,
874 active = (info->active_layer == layer);
875 floating = (info->floating_sel == layer);
877 if (gimp_text_layer_xcf_load_hack (&layer))
879 gimp_text_layer_set_xcf_flags (GIMP_TEXT_LAYER (layer),
883 info->active_layer = layer;
885 info->floating_sel = layer;
889 info->cp += xcf_read_int32 (info->fp, &hierarchy_offset, 1);
890 info->cp += xcf_read_int32 (info->fp, &layer_mask_offset, 1);
893 if (!xcf_seek_pos (info, hierarchy_offset, NULL))
896 if (!xcf_load_hierarchy (info, GIMP_DRAWABLE (layer)->tiles))
900 if (layer_mask_offset != 0)
902 if (!xcf_seek_pos (info, layer_mask_offset, NULL))
905 layer_mask = xcf_load_layer_mask (info, gimage);
909 layer_mask->apply_mask = apply_mask;
910 layer_mask->edit_mask = edit_mask;
911 layer_mask->show_mask = show_mask;
913 gimp_layer_add_mask (layer, layer_mask,
false);
918 info->floating_sel_drawable = GIMP_DRAWABLE (layer);
923 g_object_unref (layer);
928xcf_load_channel (XcfInfo * info, KisImage * gimage)
930 GimpChannel *channel;
931 TQ_INT32 hierarchy_offset;
936 GimpRGB color = { 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE };
941 is_fs_drawable = (info->cp == info->floating_sel_offset);
944 info->cp += xcf_read_int32 (info->fp, (TQ_INT32 *) & width, 1);
945 info->cp += xcf_read_int32 (info->fp, (TQ_INT32 *) & height, 1);
946 info->cp += xcf_read_string (info->fp, &name, 1);
949 channel = gimp_channel_new (gimage, width, height, name, &color);
955 if (!xcf_load_channel_props (info, gimage, &channel))
959 info->cp += xcf_read_int32 (info->fp, &hierarchy_offset, 1);
962 if (!xcf_seek_pos (info, hierarchy_offset, NULL))
965 if (!xcf_load_hierarchy (info, GIMP_DRAWABLE (channel)->tiles))
969 info->floating_sel_drawable = GIMP_DRAWABLE (channel);
974 g_object_unref (channel);
978static GimpLayerMask *
979xcf_load_layer_mask (XcfInfo * info, KisImage * gimage)
981 GimpLayerMask *layer_mask;
982 GimpChannel *channel;
983 TQ_INT32 hierarchy_offset;
988 GimpRGB color = { 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE };
993 is_fs_drawable = (info->cp == info->floating_sel_offset);
996 info->cp += xcf_read_int32 (info->fp, (TQ_INT32 *) & width, 1);
997 info->cp += xcf_read_int32 (info->fp, (TQ_INT32 *) & height, 1);
998 info->cp += xcf_read_string (info->fp, &name, 1);
1001 layer_mask = gimp_layer_mask_new (gimage, width, height, name, &color);
1007 channel = GIMP_CHANNEL (layer_mask);
1008 if (!xcf_load_channel_props (info, gimage, &channel))
1012 info->cp += xcf_read_int32 (info->fp, &hierarchy_offset, 1);
1015 if (!xcf_seek_pos (info, hierarchy_offset, NULL))
1018 if (!xcf_load_hierarchy (info, GIMP_DRAWABLE (layer_mask)->tiles))
1023 info->floating_sel_drawable = GIMP_DRAWABLE (layer_mask);
1028 g_object_unref (layer_mask);
1033xcf_load_hierarchy (XcfInfo * info, TileManager * tiles)
1042 info->cp += xcf_read_int32 (info->fp, (TQ_INT32 *) & width, 1);
1043 info->cp += xcf_read_int32 (info->fp, (TQ_INT32 *) & height, 1);
1044 info->cp += xcf_read_int32 (info->fp, (TQ_INT32 *) & bpp, 1);
1049 if (width != tile_manager_width (tiles) ||
1050 height != tile_manager_height (tiles) ||
1051 bpp != tile_manager_bpp (tiles))
1059 info->cp += xcf_read_int32 (info->fp, &offset, 1);
1065 info->cp += xcf_read_int32 (info->fp, &junk, 1);
1072 saved_pos = info->cp;
1075 if (!xcf_seek_pos (info, offset, NULL))
1079 if (!xcf_load_level (info, tiles))
1085 if (!xcf_seek_pos (info, saved_pos, NULL))
1093xcf_load_level (XcfInfo * info, TileManager * tiles)
1096 TQ_INT32 offset, offset2;
1105 info->cp += xcf_read_int32 (info->fp, (TQ_INT32 *) & width, 1);
1106 info->cp += xcf_read_int32 (info->fp, (TQ_INT32 *) & height, 1);
1108 if (width != tile_manager_width (tiles) ||
1109 height != tile_manager_height (tiles))
1116 info->cp += xcf_read_int32 (info->fp, &offset, 1);
1124 ntiles = tiles->ntile_rows * tiles->ntile_cols;
1125 for (i = 0; i < ntiles; i++)
1131 g_message (
"not enough tiles found in level");
1138 saved_pos = info->cp;
1142 info->cp += xcf_read_int32 (info->fp, &offset2, 1);
1147 offset2 = offset + TILE_WIDTH * TILE_WIDTH * 4 * 1.5;
1152 if (!xcf_seek_pos (info, offset, NULL))
1156 tile = tile_manager_get (tiles, i,
true,
true);
1159 switch (info->compression)
1162 if (!xcf_load_tile (info, tile))
1166 if (!xcf_load_tile_rle (info, tile, offset2 - offset))
1170 g_error (
"xcf: zlib compression unimplemented");
1173 case COMPRESS_FRACTAL:
1174 g_error (
"xcf: fractal compression unimplemented");
1181 tile_release (tile,
true);
1190 if (previous != NULL)
1192 tile_lock (previous);
1193 if (tile_ewidth (tile) == tile_ewidth (previous) &&
1194 tile_eheight (tile) == tile_eheight (previous) &&
1195 tile_bpp (tile) == tile_bpp (previous) &&
1196 memcmp (tile_data_pointer (tile, 0, 0),
1197 tile_data_pointer (previous, 0, 0),
1198 tile_size (tile)) == 0)
1199 tile_manager_map (tiles, i, previous);
1200 tile_release (previous,
false);
1202 tile_release (tile,
true);
1203 previous = tile_manager_get (tiles, i,
false,
false);
1208 if (!xcf_seek_pos (info, saved_pos, NULL))
1212 info->cp += xcf_read_int32 (info->fp, &offset, 1);
1217 g_message (
"encountered garbage after reading level: %d", offset);
1225xcf_load_tile (XcfInfo * info, Tile * tile)
1227#ifdef SWAP_FROM_FILE
1229 if (!info->swap_num)
1231 info->ref_count = g_new (
int, 1);
1232 info->swap_num = tile_swap_add (info->filename,
1233 xcf_swap_func, info->ref_count);
1236 tile->swap_num = info->swap_num;
1237 tile->swap_offset = info->cp;
1238 *info->ref_count += 1;
1242 info->cp += xcf_read_int8 (info->fp, tile_data_pointer (tile, 0, 0),
1251xcf_load_tile_rle (XcfInfo * info, Tile * tile,
int data_length)
1260 TQ_INT32 nmemb_read_successfully;
1261 guchar *xcfdata, *xcfodata, *xcfdatalimit;
1263 data = tile_data_pointer (tile, 0, 0);
1264 bpp = tile_bpp (tile);
1266 xcfdata = xcfodata = g_malloc (data_length);
1270 nmemb_read_successfully = fread ((TQCString *) xcfdata,
sizeof (TQCString),
1271 data_length, info->fp);
1272 info->cp += nmemb_read_successfully;
1274 xcfdatalimit = &xcfodata[nmemb_read_successfully - 1];
1276 for (i = 0; i < bpp; i++)
1278 data = (guchar *) tile_data_pointer (tile, 0, 0) + i;
1279 size = tile_ewidth (tile) * tile_eheight (tile);
1284 if (xcfdata > xcfdatalimit)
1294 length = 255 - (length - 1);
1297 if (xcfdata >= xcfdatalimit)
1302 length = (*xcfdata << 8) + xcfdata[1];
1314 if (&xcfdata[length - 1] > xcfdatalimit)
1319 while (length-- > 0)
1330 if (xcfdata >= xcfdatalimit)
1335 length = (*xcfdata << 8) + xcfdata[1];
1347 if (xcfdata > xcfdatalimit)
1354 for (j = 0; j < length; j++)
1371static KisAnnotation *
1372xcf_load_parasite (XcfInfo * info)
1376 p = g_new (KisAnnotation, 1);
1377 info->cp += xcf_read_string (info->fp, &p->name, 1);
1378 info->cp += xcf_read_int32 (info->fp, &p->flags, 1);
1379 info->cp += xcf_read_int32 (info->fp, &p->size, 1);
1380 p->data = g_new (TQCString, p->size);
1381 info->cp += xcf_read_int8 (info->fp, p->data, p->size);
1387xcf_load_old_paths (XcfInfo * info, KisImage * gimage)
1390 TQ_INT32 last_selected_row;
1391 GimpVectors *active_vectors;
1393 info->cp += xcf_read_int32 (info->fp, &last_selected_row, 1);
1394 info->cp += xcf_read_int32 (info->fp, &num_paths, 1);
1396 while (num_paths-- > 0)
1397 xcf_load_old_path (info, gimage);
1399 active_vectors = (GimpVectors *)
1400 gimp_container_get_child_by_index (gimage->vectors, last_selected_row);
1403 gimp_image_set_active_vectors (gimage, active_vectors);
1409xcf_load_old_path (XcfInfo * info, KisImage * gimage)
1415 TQ_INT32 num_points;
1417 GimpTattoo tattoo = 0;
1418 GimpVectors *vectors;
1419 GimpVectorsCompatPoint *points;
1422 info->cp += xcf_read_string (info->fp, &name, 1);
1423 info->cp += xcf_read_int32 (info->fp, &locked, 1);
1424 info->cp += xcf_read_int8 (info->fp, &state, 1);
1425 info->cp += xcf_read_int32 (info->fp, &closed, 1);
1426 info->cp += xcf_read_int32 (info->fp, &num_points, 1);
1427 info->cp += xcf_read_int32 (info->fp, &version, 1);
1434 info->cp += xcf_read_int32 (info->fp, (TQ_INT32 *) & dummy, 1);
1436 else if (version == 3)
1441 info->cp += xcf_read_int32 (info->fp, (TQ_INT32 *) & dummy, 1);
1442 info->cp += xcf_read_int32 (info->fp, (TQ_INT32 *) & tattoo, 1);
1444 else if (version != 1)
1446 g_warning (
"Unknown path type. Possibly corrupt XCF file");
1452 if (num_points == 0)
1455 points = g_new0 (GimpVectorsCompatPoint, num_points);
1457 for (i = 0; i < num_points; i++)
1464 info->cp += xcf_read_int32 (info->fp, &points[i].type, 1);
1465 info->cp += xcf_read_int32 (info->fp, (TQ_INT32 *) & x, 1);
1466 info->cp += xcf_read_int32 (info->fp, (TQ_INT32 *) & y, 1);
1476 info->cp += xcf_read_int32 (info->fp, &points[i].type, 1);
1477 info->cp += xcf_read_float (info->fp, &x, 1);
1478 info->cp += xcf_read_float (info->fp, &y, 1);
1486 gimp_vectors_compat_new (gimage, name, points, num_points, closed);
1491 GIMP_ITEM (vectors)->linked = locked;
1494 GIMP_ITEM (vectors)->tattoo = tattoo;
1496 gimp_image_add_vectors (gimage, vectors,
1497 gimp_container_num_children (gimage->vectors));
1503xcf_load_vectors (XcfInfo * info, KisImage * gimage)
1506 TQ_INT32 active_index;
1508 GimpVectors *active_vectors;
1511#ifdef GIMP_XCF_PATH_DEBUG
1512 g_printerr (
"xcf_load_vectors\n");
1517 info->cp += xcf_read_int32 (info->fp, &version, 1);
1521 g_message (
"Unknown vectors version: %d (skipping)", version);
1525 info->cp += xcf_read_int32 (info->fp, &active_index, 1);
1526 info->cp += xcf_read_int32 (info->fp, &num_paths, 1);
1528#ifdef GIMP_XCF_PATH_DEBUG
1529 g_printerr (
"%d paths (active: %d)\n", num_paths, active_index);
1532 while (num_paths-- > 0)
1533 if (!xcf_load_vector (info, gimage))
1536 active_vectors = (GimpVectors *)
1537 gimp_container_get_child_by_index (gimage->vectors, active_index);
1540 gimp_image_set_active_vectors (gimage, active_vectors);
1542#ifdef GIMP_XCF_PATH_DEBUG
1543 g_printerr (
"xcf_load_vectors: loaded %d bytes\n", info->cp - base);
1549xcf_load_vector (XcfInfo * info, KisImage * gimage)
1552 GimpTattoo tattoo = 0;
1555 TQ_INT32 num_parasites;
1556 TQ_INT32 num_strokes;
1557 GimpVectors *vectors;
1560#ifdef GIMP_XCF_PATH_DEBUG
1561 g_printerr (
"xcf_load_vector\n");
1564 info->cp += xcf_read_string (info->fp, &name, 1);
1565 info->cp += xcf_read_int32 (info->fp, &tattoo, 1);
1566 info->cp += xcf_read_int32 (info->fp, &visible, 1);
1567 info->cp += xcf_read_int32 (info->fp, &linked, 1);
1568 info->cp += xcf_read_int32 (info->fp, &num_parasites, 1);
1569 info->cp += xcf_read_int32 (info->fp, &num_strokes, 1);
1571#ifdef GIMP_XCF_PATH_DEBUG
1573 (
"name: %s, tattoo: %d, visible: %d, linked: %d, num_parasites %d, "
1574 "num_strokes %d\n", name, tattoo, visible, linked, num_parasites,
1578 vectors = gimp_vectors_new (gimage, name);
1580 GIMP_ITEM (vectors)->visible = visible ? true :
false;
1581 GIMP_ITEM (vectors)->linked = linked ? true :
false;
1584 GIMP_ITEM (vectors)->tattoo = tattoo;
1586 for (i = 0; i < num_parasites; i++)
1588 KisAnnotation *parasite;
1590 parasite = xcf_load_parasite (info);
1595 gimp_item_parasite_attach (GIMP_ITEM (vectors), parasite);
1596 gimp_parasite_free (parasite);
1599 for (i = 0; i < num_strokes; i++)
1601 TQ_INT32 stroke_type_id;
1604 TQ_INT32 num_control_points;
1606 float coords[6] = { 0.0, 0.0, 1.0, 0.5, 0.5, 0.5 };
1610 GValueArray *control_points;
1611 GValue value = { 0, };
1615 g_value_init (&value, GIMP_TYPE_ANCHOR);
1617 info->cp += xcf_read_int32 (info->fp, &stroke_type_id, 1);
1618 info->cp += xcf_read_int32 (info->fp, &closed, 1);
1619 info->cp += xcf_read_int32 (info->fp, &num_axes, 1);
1620 info->cp += xcf_read_int32 (info->fp, &num_control_points, 1);
1622#ifdef GIMP_XCF_PATH_DEBUG
1623 g_printerr (
"stroke_type: %d, closed: %d, num_axes %d, len %d\n",
1624 stroke_type_id, closed, num_axes, num_control_points);
1627 switch (stroke_type_id)
1629 case XCF_STROKETYPE_BEZIER_STROKE:
1630 stroke_type = GIMP_TYPE_BEZIER_STROKE;
1634 g_printerr (
"skipping unknown stroke type\n");
1636 info->cp + 4 * num_axes * num_control_points, NULL);
1640 control_points = g_value_array_new (num_control_points);
1642 anchor.selected =
false;
1644 for (j = 0; j < num_control_points; j++)
1646 info->cp += xcf_read_int32 (info->fp, &type, 1);
1647 info->cp += xcf_read_float (info->fp, coords, num_axes);
1650 anchor.position.x = coords[0];
1651 anchor.position.y = coords[1];
1652 anchor.position.pressure = coords[2];
1653 anchor.position.xtilt = coords[3];
1654 anchor.position.ytilt = coords[4];
1655 anchor.position.wheel = coords[5];
1657 g_value_set_boxed (&value, &anchor);
1658 g_value_array_append (control_points, &value);
1660#ifdef GIMP_XCF_PATH_DEBUG
1661 g_printerr (
"Anchor: %d, (%f, %f, %f, %f, %f, %f)\n", type,
1662 coords[0], coords[1], coords[2], coords[3],
1663 coords[4], coords[5]);
1667 g_value_unset (&value);
1669 stroke = g_object_new (stroke_type,
1671 "control-points", control_points, NULL);
1673 gimp_vectors_stroke_add (vectors, stroke);
1676 gimp_image_add_vectors (gimage, vectors,
1677 gimp_container_num_children (gimage->vectors));
1682#ifdef SWAP_FROM_FILE
1685xcf_swap_func (TQ_INT32 fd, Tile * tile, TQ_INT32 cmd, gpointer user_data)
1690 TQ_INT32 *ref_count;
1695 lseek (fd, tile->swap_offset, SEEK_SET);
1697 bytes = tile_size (tile);
1705 err = read (fd, tile->data + bytes - nleft, nleft);
1707 while ((err == -1) && ((errno == EAGAIN) || (errno == EINTR)));
1711 g_message (
"unable to read tile data from xcf file: "
1712 "%d ( %d ) bytes read", err, nleft);
1723 ref_count = user_data;
1725 if (*ref_count == 0)
1727 tile_swap_remove (tile->swap_num);
1732 tile->swap_offset = -1;