24#include <glib-object.h>
26#include "libgimpbase/gimpbase.h"
27#include "libgimpcolor/gimpcolor.h"
29#include "core/core-types.h"
32#include "base/tile-manager.h"
33#include "base/tile-manager-private.h"
35#include "core/gimpchannel.h"
36#include "core/gimpdrawable.h"
37#include "core/gimpgrid.h"
38#include "core/gimpimage.h"
39#include "core/gimpimage-grid.h"
40#include "core/gimpimage-guides.h"
41#include "core/gimplayer.h"
42#include "core/gimplayer-floating-sel.h"
43#include "core/gimplayermask.h"
44#include "core/gimplist.h"
45#include "core/gimpparasitelist.h"
46#include "core/gimpunit.h"
48#include "text/gimptextlayer.h"
49#include "text/gimptextlayer-xcf.h"
51#include "vectors/gimpanchor.h"
52#include "vectors/gimpstroke.h"
53#include "vectors/gimpbezierstroke.h"
54#include "vectors/gimpvectors.h"
55#include "vectors/gimpvectors-compat.h"
57#include "xcf-private.h"
65static bool xcf_save_image_props (XcfInfo *info,
68static bool xcf_save_layer_props (XcfInfo *info,
72static bool xcf_save_channel_props (XcfInfo *info,
76static bool xcf_save_prop (XcfInfo *info,
81static bool xcf_save_layer (XcfInfo *info,
85static bool xcf_save_channel (XcfInfo *info,
89static bool xcf_save_hierarchy (XcfInfo *info,
92static bool xcf_save_level (XcfInfo *info,
95static bool xcf_save_tile (XcfInfo *info,
98static bool xcf_save_tile_rle (XcfInfo *info,
102static bool xcf_save_parasite (XcfInfo *info,
103 KisAnnotation *parasite,
105static bool xcf_save_parasite_list (XcfInfo *info,
106 KisAnnotationList *parasite,
108static bool xcf_save_old_paths (XcfInfo *info,
111static bool xcf_save_vectors (XcfInfo *info,
117#define xcf_write_int32_check_error(info, data, count) G_STMT_START { \
118 info->cp += xcf_write_int32 (info->fp, data, count, &tmp_error); \
121 g_propagate_error (error, tmp_error); \
126#define xcf_write_int8_check_error(info, data, count) G_STMT_START { \
127 info->cp += xcf_write_int8 (info->fp, data, count, &tmp_error); \
130 g_propagate_error (error, tmp_error); \
135#define xcf_write_float_check_error(info, data, count) G_STMT_START { \
136 info->cp += xcf_write_float (info->fp, data, count, &tmp_error); \
139 g_propagate_error (error, tmp_error); \
144#define xcf_write_string_check_error(info, data, count) G_STMT_START { \
145 info->cp += xcf_write_string (info->fp, data, count, &tmp_error); \
148 g_propagate_error (error, tmp_error); \
153#define xcf_write_int32_print_error(info, data, count) G_STMT_START { \
154 info->cp += xcf_write_int32 (info->fp, data, count, &error); \
157 g_message (_("Error saving XCF file: %s"), \
163#define xcf_write_int8_print_error(info, data, count) G_STMT_START { \
164 info->cp += xcf_write_int8 (info->fp, data, count, &error); \
167 g_message (_("Error saving XCF file: %s"), \
173#define xcf_write_float_print_error(info, data, count) G_STMT_START { \
174 info->cp += xcf_write_float (info->fp, data, count, &error); \
177 g_message (_("Error saving XCF file: %s"), \
183#define xcf_write_string_print_error(info, data, count) G_STMT_START { \
184 info->cp += xcf_write_string (info->fp, data, count, &error); \
187 g_message (_("Error saving XCF file: %s"), \
193#define xcf_write_prop_type_check_error(info, prop_type) G_STMT_START { \
194 TQ_INT32 _prop_int32 = prop_type; \
195 xcf_write_int32_check_error (info, &_prop_int32, 1); \
198#define xcf_write_prop_type_print_error(info, prop_type) G_STMT_START { \
199 TQ_INT32 _prop_int32 = prop_type; \
200 xcf_write_int32_print_error (info, &_prop_int32, 1); \
203#define xcf_check_error(x) G_STMT_START { \
208#define xcf_print_error(x) G_STMT_START { \
211 g_message (_("Error saving XCF file: %s"), \
219xcf_save_choose_format (XcfInfo *info,
225 TQ_INT32 save_version = 0;
230 for (list = GIMP_LIST (gimage->layers)->list;
231 list && save_version < 2;
232 list = g_list_next (list))
234 layer = GIMP_LAYER (list->data);
239 case GIMP_SOFTLIGHT_MODE:
240 case GIMP_GRAIN_EXTRACT_MODE:
241 case GIMP_GRAIN_MERGE_MODE:
242 case GIMP_COLOR_ERASE_MODE:
251 info->file_version = save_version;
255xcf_save_image (XcfInfo *info,
259 KisLayer *floating_layer;
260 GimpChannel *channel;
267 TQ_INT32 t1, t2, t3, t4;
268 TQCString version_tag[14];
269 GError *error = NULL;
271 floating_layer = gimp_image_floating_sel (gimage);
273 floating_sel_relax (floating_layer, FALSE);
276 if (info->file_version > 0)
278 sprintf (version_tag,
"gimp xcf v%03d", info->file_version);
282 strcpy (version_tag,
"gimp xcf file");
284 xcf_write_int8_print_error (info, (TQ_UINT8 *) version_tag, 14);
287 xcf_write_int32_print_error (info, (TQ_INT32 *) &gimage->width, 1);
288 xcf_write_int32_print_error (info, (TQ_INT32 *) &gimage->height, 1);
289 xcf_write_int32_print_error (info, (TQ_INT32 *) &gimage->base_type, 1);
292 nlayers = (TQ_UINT32) gimp_container_num_children (gimage->layers);
293 nchannels = (TQ_UINT32) gimp_container_num_children (gimage->channels);
296 have_selection = gimp_channel_bounds (gimp_image_get_mask (gimage),
304 xcf_print_error (xcf_save_image_props (info, gimage, &error));
309 saved_pos = info->cp;
312 xcf_print_error (xcf_seek_pos (info,
313 info->cp + (nlayers + nchannels + 2) * 4,
316 for (list = GIMP_LIST (gimage->layers)->list;
318 list = g_list_next (list))
320 layer = (KisLayer *) list->data;
328 xcf_print_error (xcf_save_layer (info, gimage, layer, &error));
333 xcf_print_error (xcf_seek_pos (info, saved_pos, &error));
334 xcf_write_int32_print_error (info, &offset, 1);
339 saved_pos = info->cp;
344 xcf_print_error (xcf_seek_end (info, &error));
351 xcf_print_error (xcf_seek_pos (info, saved_pos, &error));
352 xcf_write_int32_print_error (info, &offset, 1);
353 saved_pos = info->cp;
354 xcf_print_error (xcf_seek_end (info, &error));
356 list = GIMP_LIST (gimage->channels)->list;
358 while (list || have_selection)
362 channel = (GimpChannel *) list->data;
364 list = g_list_next (list);
368 channel = gimage->selection_mask;
369 have_selection =
false;
378 xcf_print_error (xcf_save_channel (info, gimage, channel, &error));
383 xcf_print_error (xcf_seek_pos (info, saved_pos, &error));
384 xcf_write_int32_print_error (info, &offset, 1);
389 saved_pos = info->cp;
394 xcf_print_error (xcf_seek_end (info, &error));
401 xcf_print_error (xcf_seek_pos (info, saved_pos, &error));
402 xcf_write_int32_print_error (info, &offset, 1);
403 saved_pos = info->cp;
406 floating_sel_rigor (floating_layer, FALSE);
408 return !ferror(info->fp);
412xcf_save_image_props (XcfInfo *info,
416 KisAnnotation *parasite = NULL;
417 GimpUnit unit = gimp_image_get_unit (gimage);
421 xcf_check_error (xcf_save_prop (info, gimage, PROP_COLORMAP, error,
422 gimage->num_cols, gimage->cmap));
424 if (info->compression != COMPRESS_NONE)
425 xcf_check_error (xcf_save_prop (info, gimage, PROP_COMPRESSION,
426 error, info->compression));
429 xcf_check_error (xcf_save_prop (info, gimage, PROP_GUIDES,
430 error, gimage->guides));
432 xcf_check_error (xcf_save_prop (info, gimage, PROP_RESOLUTION, error,
433 gimage->xresolution, gimage->yresolution));
435 xcf_check_error (xcf_save_prop (info, gimage, PROP_TATTOO, error,
436 gimage->tattoo_state));
438 if (gimp_parasite_list_length (gimage->parasites) > 0)
439 xcf_check_error (xcf_save_prop (info, gimage, PROP_PARASITES,
440 error, gimage->parasites));
442 if (unit < _gimp_unit_get_number_of_built_in_units (gimage->gimp))
443 xcf_check_error (xcf_save_prop (info, gimage, PROP_UNIT, error, unit));
445 if (gimp_container_num_children (gimage->vectors) > 0)
447 if (gimp_vectors_compat_is_compatible (gimage))
448 xcf_check_error (xcf_save_prop (info, gimage, PROP_PATHS, error));
450 xcf_check_error (xcf_save_prop (info, gimage, PROP_VECTORS, error));
453 if (unit >= _gimp_unit_get_number_of_built_in_units (gimage->gimp))
454 xcf_check_error (xcf_save_prop (info, gimage, PROP_USER_UNIT, error, unit));
456 if (GIMP_IS_GRID (gimage->grid))
458 GimpGrid *grid = gimp_image_get_grid (gimage);
460 parasite = gimp_grid_to_parasite (grid);
461 gimp_parasite_list_add (GIMP_IMAGE (gimage)->parasites, parasite);
464 if (gimp_parasite_list_length (GIMP_IMAGE (gimage)->parasites) > 0)
466 xcf_check_error (xcf_save_prop (info, gimage, PROP_PARASITES, error,
467 GIMP_IMAGE (gimage)->parasites));
472 gimp_parasite_list_remove (GIMP_IMAGE (gimage)->parasites,
473 gimp_parasite_name (parasite));
474 gimp_parasite_free (parasite);
477 xcf_check_error (xcf_save_prop (info, gimage, PROP_END, error));
483xcf_save_layer_props (XcfInfo *info,
488 KisAnnotation *parasite = NULL;
490 if (layer == gimp_image_get_active_layer (gimage))
491 xcf_check_error (xcf_save_prop (info, gimage, PROP_ACTIVE_LAYER, error));
493 if (layer == gimp_image_floating_sel (gimage))
495 info->floating_sel_drawable = layer->fs.drawable;
496 xcf_check_error (xcf_save_prop (info, gimage, PROP_FLOATING_SELECTION,
500 xcf_check_error (xcf_save_prop (info, gimage, PROP_OPACITY, error,
502 xcf_check_error (xcf_save_prop (info, gimage, PROP_VISIBLE, error,
503 gimp_item_get_visible (GIMP_ITEM (layer))));
504 xcf_check_error (xcf_save_prop (info, gimage, PROP_LINKED, error,
505 gimp_item_get_linked (GIMP_ITEM (layer))));
506 xcf_check_error (xcf_save_prop (info, gimage, PROP_LOCK_ALPHA,
507 error, layer->lock_alpha));
511 xcf_check_error (xcf_save_prop (info, gimage, PROP_APPLY_MASK,
512 error, layer->mask->apply_mask));
513 xcf_check_error (xcf_save_prop (info, gimage, PROP_EDIT_MASK,
514 error, layer->mask->edit_mask));
515 xcf_check_error (xcf_save_prop (info, gimage, PROP_SHOW_MASK,
516 error, layer->mask->show_mask));
520 xcf_check_error (xcf_save_prop (info, gimage, PROP_APPLY_MASK,
522 xcf_check_error (xcf_save_prop (info, gimage, PROP_EDIT_MASK,
524 xcf_check_error (xcf_save_prop (info, gimage, PROP_SHOW_MASK,
528 xcf_check_error (xcf_save_prop (info, gimage, PROP_OFFSETS, error,
529 GIMP_ITEM (layer)->offset_x,
530 GIMP_ITEM (layer)->offset_y));
531 xcf_check_error (xcf_save_prop (info, gimage, PROP_MODE, error,
533 xcf_check_error (xcf_save_prop (info, gimage, PROP_TATTOO, error,
534 GIMP_ITEM (layer)->tattoo));
536 if (GIMP_IS_TEXT_LAYER (layer) && GIMP_TEXT_LAYER (layer)->text)
538 GimpTextLayer *text_layer = GIMP_TEXT_LAYER (layer);
539 TQ_INT32 flags = gimp_text_layer_get_xcf_flags (text_layer);
541 gimp_text_layer_xcf_save_prepare (text_layer);
544 xcf_check_error (xcf_save_prop (info,
545 gimage, PROP_TEXT_LAYER_FLAGS, error,
549 if (gimp_parasite_list_length (GIMP_ITEM (layer)->parasites) > 0)
551 xcf_check_error (xcf_save_prop (info, gimage, PROP_PARASITES, error,
552 GIMP_ITEM (layer)->parasites));
557 gimp_parasite_list_remove (GIMP_ITEM (layer)->parasites,
558 gimp_parasite_name (parasite));
559 gimp_parasite_free (parasite);
562 xcf_check_error (xcf_save_prop (info, gimage, PROP_END, error));
568xcf_save_channel_props (XcfInfo *info,
570 GimpChannel *channel,
575 if (channel == gimp_image_get_active_channel (gimage))
576 xcf_check_error (xcf_save_prop (info, gimage, PROP_ACTIVE_CHANNEL, error));
578 if (channel == gimage->selection_mask)
579 xcf_check_error (xcf_save_prop (info, gimage, PROP_SELECTION, error));
581 xcf_check_error (xcf_save_prop (info, gimage, PROP_OPACITY, error,
583 xcf_check_error (xcf_save_prop (info, gimage, PROP_VISIBLE, error,
584 gimp_item_get_visible (GIMP_ITEM (channel))));
585 xcf_check_error (xcf_save_prop (info, gimage, PROP_LINKED, error,
586 gimp_item_get_linked (GIMP_ITEM (channel))));
587 xcf_check_error (xcf_save_prop (info, gimage, PROP_SHOW_MASKED, error,
588 channel->show_masked));
590 gimp_rgb_get_uchar (&channel->color, &col[0], &col[1], &col[2]);
591 xcf_check_error (xcf_save_prop (info, gimage, PROP_COLOR, error, col));
593 xcf_check_error (xcf_save_prop (info, gimage, PROP_TATTOO, error,
594 GIMP_ITEM (channel)->tattoo));
596 if (gimp_parasite_list_length (GIMP_ITEM (channel)->parasites) > 0)
597 xcf_check_error (xcf_save_prop (info, gimage, PROP_PARASITES, error,
598 GIMP_ITEM (channel)->parasites));
600 xcf_check_error (xcf_save_prop (info, gimage, PROP_END, error));
606xcf_save_prop (XcfInfo *info,
615 GError *tmp_error = NULL;
617 va_start (args, error);
624 xcf_write_prop_type_check_error (info, prop_type);
625 xcf_write_int32_check_error (info, &size, 1);
633 ncolors = va_arg (args, TQ_INT32);
634 colors = va_arg (args, guchar*);
635 size = 4 + ncolors * 3;
637 xcf_write_prop_type_check_error (info, prop_type);
638 xcf_write_int32_check_error (info, &size, 1);
639 xcf_write_int32_check_error (info, &ncolors, 1);
640 xcf_write_int8_check_error (info, colors, ncolors * 3);
644 case PROP_ACTIVE_LAYER:
645 case PROP_ACTIVE_CHANNEL:
649 xcf_write_prop_type_check_error (info, prop_type);
650 xcf_write_int32_check_error (info, &size, 1);
653 case PROP_FLOATING_SELECTION:
660 xcf_write_prop_type_check_error (info, prop_type);
661 xcf_write_int32_check_error (info, &size, 1);
662 info->floating_sel_offset = info->cp;
663 xcf_write_int32_check_error (info, &dummy, 1);
670 TQ_INT32 uint_opacity;
672 opacity = va_arg (args, gdouble);
674 uint_opacity = opacity * 255.999;
678 xcf_write_prop_type_check_error (info, prop_type);
679 xcf_write_int32_check_error (info, &size, 1);
680 xcf_write_int32_check_error (info, &uint_opacity, 1);
688 mode = va_arg (args, TQ_INT3232);
691 xcf_write_prop_type_check_error (info, prop_type);
692 xcf_write_int32_check_error (info, &size, 1);
693 xcf_write_int32_check_error (info, (TQ_INT32 *) &mode, 1);
701 visible = va_arg (args, TQ_INT32);
704 xcf_write_prop_type_check_error (info, prop_type);
705 xcf_write_int32_check_error (info, &size, 1);
706 xcf_write_int32_check_error (info, &visible, 1);
714 linked = va_arg (args, TQ_INT32);
717 xcf_write_prop_type_check_error (info, prop_type);
718 xcf_write_int32_check_error (info, &size, 1);
719 xcf_write_int32_check_error (info, &linked, 1);
723 case PROP_LOCK_ALPHA:
727 lock_alpha = va_arg (args, TQ_INT32);
730 xcf_write_prop_type_check_error (info, prop_type);
731 xcf_write_int32_check_error (info, &size, 1);
732 xcf_write_int32_check_error (info, &lock_alpha, 1);
736 case PROP_APPLY_MASK:
740 apply_mask = va_arg (args, TQ_INT32);
743 xcf_write_prop_type_check_error (info, prop_type);
744 xcf_write_int32_check_error (info, &size, 1);
745 xcf_write_int32_check_error (info, &apply_mask, 1);
753 edit_mask = va_arg (args, TQ_INT32);
756 xcf_write_prop_type_check_error (info, prop_type);
757 xcf_write_int32_check_error (info, &size, 1);
758 xcf_write_int32_check_error (info, &edit_mask, 1);
766 show_mask = va_arg (args, TQ_INT32);
769 xcf_write_prop_type_check_error (info, prop_type);
770 xcf_write_int32_check_error (info, &size, 1);
771 xcf_write_int32_check_error (info, &show_mask, 1);
775 case PROP_SHOW_MASKED:
777 TQ_INT32 show_masked;
779 show_masked = va_arg (args, TQ_INT32);
782 xcf_write_prop_type_check_error (info, prop_type);
783 xcf_write_int32_check_error (info, &size, 1);
784 xcf_write_int32_check_error (info, &show_masked, 1);
790 TQ_INT3232 offsets[2];
792 offsets[0] = va_arg (args, TQ_INT3232);
793 offsets[1] = va_arg (args, TQ_INT3232);
796 xcf_write_prop_type_check_error (info, prop_type);
797 xcf_write_int32_check_error (info, &size, 1);
798 xcf_write_int32_check_error (info, (TQ_INT32 *) offsets, 2);
806 color = va_arg (args, guchar*);
809 xcf_write_prop_type_check_error (info, prop_type);
810 xcf_write_int32_check_error (info, &size, 1);
811 xcf_write_int8_check_error (info, color, 3);
815 case PROP_COMPRESSION:
817 TQ_UINT8 compression;
819 compression = (TQ_UINT8) va_arg (args, TQ_INT32);
822 xcf_write_prop_type_check_error (info, prop_type);
823 xcf_write_int32_check_error (info, &size, 1);
824 xcf_write_int8_check_error (info, &compression, 1);
833 TQ_INT328 orientation;
836 guides = va_arg (args, GList *);
837 nguides = g_list_length (guides);
839 size = nguides * (4 + 1);
841 xcf_write_prop_type_check_error (info, prop_type);
842 xcf_write_int32_check_error (info, &size, 1);
844 for (; guides; guides = g_list_next (guides))
846 guide = (GimpGuide *) guides->data;
848 position = guide->position;
850 switch (guide->orientation)
852 case GIMP_ORIENTATION_HORIZONTAL:
853 orientation = XCF_ORIENTATION_HORIZONTAL;
856 case GIMP_ORIENTATION_VERTICAL:
857 orientation = XCF_ORIENTATION_VERTICAL;
861 g_warning (
"%s: skipping guide with bad orientation",
866 xcf_write_int32_check_error (info, (TQ_INT32 *) &position, 1);
867 xcf_write_int8_check_error (info, (TQ_UINT8 *) &orientation, 1);
872 case PROP_RESOLUTION:
874 float xresolution, yresolution;
878 xresolution = va_arg (args,
double);
879 yresolution = va_arg (args,
double);
883 xcf_write_prop_type_check_error (info, prop_type);
884 xcf_write_int32_check_error (info, &size, 1);
886 xcf_write_float_check_error (info, &xresolution, 1);
887 xcf_write_float_check_error (info, &yresolution, 1);
895 tattoo = va_arg (args, TQ_INT32);
898 xcf_write_prop_type_check_error (info, prop_type);
899 xcf_write_int32_check_error (info, &size, 1);
900 xcf_write_int32_check_error (info, &tattoo, 1);
906 KisAnnotationList *list;
907 TQ_INT32 base, length;
910 list = va_arg (args, KisAnnotationList *);
912 if (gimp_parasite_list_persistent_length (list) > 0)
914 xcf_write_prop_type_check_error (info, prop_type);
920 xcf_write_int32_check_error (info, &length, 1);
923 xcf_check_error (xcf_save_parasite_list (info, list, error));
925 length = info->cp - base;
927 xcf_check_error (xcf_seek_pos (info, pos, error));
928 xcf_write_int32 (info->fp, &length, 1, &tmp_error);
931 g_propagate_error (error, tmp_error);
935 xcf_check_error (xcf_seek_end (info, error));
944 unit = va_arg (args, TQ_INT32);
948 xcf_write_prop_type_check_error (info, prop_type);
949 xcf_write_int32_check_error (info, &size, 1);
950 xcf_write_int32_check_error (info, &unit, 1);
956 TQ_INT32 base, length;
959 xcf_write_prop_type_check_error (info, prop_type);
965 xcf_write_int32_check_error (info, &length, 1);
969 xcf_check_error (xcf_save_old_paths (info, gimage, error));
971 length = info->cp - base;
974 xcf_check_error (xcf_seek_pos (info, pos, error));
975 xcf_write_int32 (info->fp, &length, 1, &tmp_error);
978 g_propagate_error (error, tmp_error);
982 xcf_check_error (xcf_seek_end (info, error));
989 const TQCString *unit_strings[5];
993 unit = va_arg (args, TQ_INT32);
996 unit_strings[0] = _gimp_unit_get_identifier (gimage->gimp, unit);
997 factor = _gimp_unit_get_factor (gimage->gimp, unit);
998 digits = _gimp_unit_get_digits (gimage->gimp, unit);
999 unit_strings[1] = _gimp_unit_get_symbol (gimage->gimp, unit);
1000 unit_strings[2] = _gimp_unit_get_abbreviation (gimage->gimp, unit);
1001 unit_strings[3] = _gimp_unit_get_singular (gimage->gimp, unit);
1002 unit_strings[4] = _gimp_unit_get_plural (gimage->gimp, unit);
1006 strlen (unit_strings[0]) ? strlen (unit_strings[0]) + 5 : 4 +
1007 strlen (unit_strings[1]) ? strlen (unit_strings[1]) + 5 : 4 +
1008 strlen (unit_strings[2]) ? strlen (unit_strings[2]) + 5 : 4 +
1009 strlen (unit_strings[3]) ? strlen (unit_strings[3]) + 5 : 4 +
1010 strlen (unit_strings[4]) ? strlen (unit_strings[4]) + 5 : 4;
1012 xcf_write_prop_type_check_error (info, prop_type);
1013 xcf_write_int32_check_error (info, &size, 1);
1014 xcf_write_float_check_error (info, &factor, 1);
1015 xcf_write_int32_check_error (info, &digits, 1);
1016 xcf_write_string_check_error (info, (TQCString **) unit_strings, 5);
1022 TQ_INT32 base, length;
1025 xcf_write_prop_type_check_error (info, prop_type);
1031 xcf_write_int32_check_error (info, &length, 1);
1035 xcf_check_error (xcf_save_vectors (info, gimage, error));
1037 length = info->cp - base;
1040 xcf_check_error (xcf_seek_pos (info, pos, error));
1041 xcf_write_int32 (info->fp, &length, 1, &tmp_error);
1044 g_propagate_error (error, tmp_error);
1048 xcf_check_error (xcf_seek_end (info, error));
1052 case PROP_TEXT_LAYER_FLAGS:
1056 flags = va_arg (args, TQ_INT32);
1059 xcf_write_prop_type_check_error (info, prop_type);
1060 xcf_write_int32_check_error (info, &size, 1);
1061 xcf_write_int32_check_error (info, &flags, 1);
1072xcf_save_layer (XcfInfo *info,
1080 GError *tmp_error = NULL;
1085 if (GIMP_DRAWABLE (layer) == info->floating_sel_drawable)
1087 saved_pos = info->cp;
1088 xcf_check_error (xcf_seek_pos (info, info->floating_sel_offset, error));
1089 xcf_write_int32_check_error (info, &saved_pos, 1);
1090 xcf_check_error (xcf_seek_pos (info, saved_pos, error));
1094 xcf_write_int32_check_error (info,
1095 (TQ_INT32 *) &GIMP_ITEM (layer)->width, 1);
1096 xcf_write_int32_check_error (info,
1097 (TQ_INT32 *) &GIMP_ITEM (layer)->height, 1);
1098 xcf_write_int32_check_error (info,
1099 (TQ_INT32 *) &GIMP_DRAWABLE (layer)->type, 1);
1102 xcf_write_string_check_error (info, &GIMP_OBJECT (layer)->name, 1);
1105 xcf_save_layer_props (info, gimage, layer, error);
1110 saved_pos = info->cp;
1113 xcf_check_error (xcf_seek_pos (info, info->cp + 8, error));
1116 xcf_check_error (xcf_save_hierarchy (info,
1117 GIMP_DRAWABLE(layer)->tiles, error));
1119 xcf_check_error (xcf_seek_pos (info, saved_pos, error));
1120 xcf_write_int32_check_error (info, &offset, 1);
1121 saved_pos = info->cp;
1126 xcf_check_error (xcf_seek_end (info, error));
1129 xcf_check_error (xcf_save_channel (info,
1130 gimage, GIMP_CHANNEL(layer->mask),
1136 xcf_check_error (xcf_seek_pos (info, saved_pos, error));
1137 xcf_write_int32_check_error (info, &offset, 1);
1143xcf_save_channel (XcfInfo *info,
1145 GimpChannel *channel,
1151 GError *tmp_error = NULL;
1156 if (GIMP_DRAWABLE (channel) == info->floating_sel_drawable)
1158 saved_pos = info->cp;
1159 xcf_check_error (xcf_seek_pos (info, info->floating_sel_offset, error));
1160 xcf_write_int32_check_error (info, &saved_pos, 1);
1161 xcf_check_error (xcf_seek_pos (info, saved_pos, error));
1165 xcf_write_int32_check_error (info,
1166 (TQ_INT32 *) &GIMP_ITEM (channel)->width, 1);
1167 xcf_write_int32_check_error (info,
1168 (TQ_INT32 *) &GIMP_ITEM (channel)->height, 1);
1171 xcf_write_string_check_error (info, &GIMP_OBJECT (channel)->name, 1);
1174 xcf_save_channel_props (info, gimage, channel, error);
1179 saved_pos = info->cp;
1182 xcf_check_error (xcf_seek_pos (info, info->cp + 4, error));
1185 xcf_check_error (xcf_save_hierarchy (info,
1186 GIMP_DRAWABLE (channel)->tiles, error));
1188 xcf_check_error (xcf_seek_pos (info, saved_pos, error));
1189 xcf_write_int32_check_error (info, &offset, 1);
1190 saved_pos = info->cp;
1196xcf_calc_levels (TQ_INT32 size,
1202 while (size > tile_size)
1213xcf_save_hierarchy (XcfInfo *info,
1224 TQ_INT32 tmp1, tmp2;
1226 GError *tmp_error = NULL;
1228 width = tile_manager_width (tiles);
1229 height = tile_manager_height (tiles);
1230 bpp = tile_manager_bpp (tiles);
1232 xcf_write_int32_check_error (info, (TQ_INT32 *) &width, 1);
1233 xcf_write_int32_check_error (info, (TQ_INT32 *) &height, 1);
1234 xcf_write_int32_check_error (info, (TQ_INT32 *) &bpp, 1);
1236 saved_pos = info->cp;
1238 tmp1 = xcf_calc_levels (width, TILE_WIDTH);
1239 tmp2 = xcf_calc_levels (height, TILE_HEIGHT);
1240 nlevels = MAX (tmp1, tmp2);
1242 xcf_check_error (xcf_seek_pos (info, info->cp + (1 + nlevels) * 4, error));
1244 for (i = 0; i < nlevels; i++)
1251 xcf_check_error (xcf_save_level (info, tiles, error));
1259 xcf_write_int32_check_error (info, (TQ_INT32 *) &width, 1);
1260 xcf_write_int32_check_error (info, (TQ_INT32 *) &height, 1);
1261 xcf_write_int32_check_error (info, (TQ_INT32 *) &tmp1, 1);
1267 xcf_check_error (xcf_seek_pos (info, saved_pos, error));
1268 xcf_write_int32_check_error (info, &offset, 1);
1273 saved_pos = info->cp;
1278 xcf_check_error (xcf_seek_end (info, error));
1285 xcf_check_error (xcf_seek_pos (info, saved_pos, error));
1286 xcf_write_int32_check_error (info, &offset, 1);
1292xcf_save_level (XcfInfo *info,
1304 GError *tmp_error = NULL;
1306 width = tile_manager_width (level);
1307 height = tile_manager_height (level);
1309 xcf_write_int32_check_error (info, (TQ_INT32 *) &width, 1);
1310 xcf_write_int32_check_error (info, (TQ_INT32 *) &height, 1);
1312 saved_pos = info->cp;
1317 g_malloc (TILE_WIDTH * TILE_HEIGHT * tile_manager_bpp (level) * 1.5);
1321 ntiles = level->ntile_rows * level->ntile_cols;
1322 xcf_check_error (xcf_seek_pos (info, info->cp + (ntiles + 1) * 4, error));
1324 for (i = 0; i < ntiles; i++)
1332 switch (info->compression)
1335 xcf_check_error(xcf_save_tile (info, level->tiles[i], error));
1338 xcf_check_error (xcf_save_tile_rle (info, level->tiles[i],
1342 g_error (
"xcf: zlib compression unimplemented");
1344 case COMPRESS_FRACTAL:
1345 g_error (
"xcf: fractal compression unimplemented");
1352 xcf_check_error (xcf_seek_pos (info, saved_pos, error));
1353 xcf_write_int32_check_error (info, &offset, 1);
1358 saved_pos = info->cp;
1363 xcf_check_error (xcf_seek_end (info, error));
1373 xcf_check_error (xcf_seek_pos (info, saved_pos, error));
1374 xcf_write_int32_check_error (info, &offset, 1);
1381xcf_save_tile (XcfInfo *info,
1385 GError *tmp_error = NULL;
1388 xcf_write_int8_check_error (info, tile_data_pointer (tile, 0, 0),
1390 tile_release (tile,
false);
1396xcf_save_tile_rle (XcfInfo *info,
1411 GError *tmp_error = NULL;
1415 bpp = tile_bpp (tile);
1417 for (i = 0; i < bpp; i++)
1419 data = (guchar*) tile_data_pointer (tile, 0, 0) + i;
1424 size = tile_ewidth(tile) * tile_eheight(tile);
1435 if ((length == 32768) ||
1436 ((size - length) <= 0) ||
1437 ((length > 1) && (last != *data)))
1442 rlebuf[len++] = 127;
1443 rlebuf[len++] = (length >> 8);
1444 rlebuf[len++] = length & 0x00FF;
1445 rlebuf[len++] = last;
1449 rlebuf[len++] = length - 1;
1450 rlebuf[len++] = last;
1455 else if ((length == 1) && (last != *data))
1463 if ((length == 32768) ||
1464 ((size - length) == 0) ||
1465 ((length > 0) && (last == *data) &&
1466 ((size - length) == 1 || last == data[bpp])))
1473 rlebuf[len++] = 255 - 127;
1474 rlebuf[len++] = (length >> 8);
1475 rlebuf[len++] = length & 0x00FF;
1479 rlebuf[len++] = 255 - (length - 1);
1482 t = data - length * bpp;
1483 for (j = 0; j < length; j++)
1502 if (count != (tile_ewidth (tile) * tile_eheight (tile)))
1503 g_message (
"xcf: uh oh! xcf rle tile saving error: %d", count);
1505 xcf_write_int8_check_error (info, rlebuf, len);
1506 tile_release (tile,
false);
1512xcf_save_parasite (XcfInfo *info,
1513 KisAnnotation *parasite,
1516 if (gimp_parasite_is_persistent (parasite))
1518 GError *tmp_error = NULL;
1520 xcf_write_string_check_error (info, ¶site->name, 1);
1521 xcf_write_int32_check_error (info, ¶site->flags, 1);
1522 xcf_write_int32_check_error (info, ¶site->size, 1);
1523 xcf_write_int8_check_error (info, parasite->data, parasite->size);
1536xcf_save_parasite_func (TQCString *key,
1537 KisAnnotation *parasite,
1538 XcfParasiteData *data)
1541 xcf_save_parasite (data->info, parasite, &data->error);
1545xcf_save_parasite_list (XcfInfo *info,
1546 KisAnnotationList *list,
1549 XcfParasiteData data;
1554 gimp_parasite_list_foreach (list, (GHFunc) xcf_save_parasite_func, &data);
1558 g_propagate_error (error, data.error);
1566xcf_save_old_paths (XcfInfo *info,
1570 GimpVectors *active_vectors;
1572 TQ_INT32 active_index = 0;
1574 GError *tmp_error = NULL;
1584 num_paths = gimp_container_num_children (gimage->vectors);
1586 active_vectors = gimp_image_get_active_vectors (gimage);
1589 active_index = gimp_container_get_child_index (gimage->vectors,
1590 GIMP_OBJECT (active_vectors));
1592 xcf_write_int32_check_error (info, &active_index, 1);
1593 xcf_write_int32_check_error (info, &num_paths, 1);
1595 for (list = GIMP_LIST (gimage->vectors)->list;
1597 list = g_list_next (list))
1599 GimpVectors *vectors = list->data;
1606 GimpVectorsCompatPoint *points;
1607 TQ_INT3232 num_points;
1623 points = gimp_vectors_compat_get_points (vectors, &num_points, &closed);
1630 name = (TQCString *) gimp_object_get_name (GIMP_OBJECT (vectors));
1631 locked = gimp_item_get_linked (GIMP_ITEM (vectors));
1632 state = closed ? 4 : 2;
1635 tattoo = gimp_item_get_tattoo (GIMP_ITEM (vectors));
1637 xcf_write_string_check_error (info, &name, 1);
1638 xcf_write_int32_check_error (info, &locked, 1);
1639 xcf_write_int8_check_error (info, &state, 1);
1640 xcf_write_int32_check_error (info, &closed, 1);
1641 xcf_write_int32_check_error (info, &num_points, 1);
1642 xcf_write_int32_check_error (info, &version, 1);
1643 xcf_write_int32_check_error (info, &pathtype, 1);
1644 xcf_write_int32_check_error (info, &tattoo, 1);
1646 for (i = 0; i < num_points; i++)
1660 xcf_write_int32_check_error (info, &points[i].type, 1);
1661 xcf_write_float_check_error (info, &x, 1);
1662 xcf_write_float_check_error (info, &y, 1);
1672xcf_save_vectors (XcfInfo *info,
1676 GimpVectors *active_vectors;
1677 TQ_INT32 version = 1;
1678 TQ_INT32 active_index = 0;
1682 GError *tmp_error = NULL;
1693 active_vectors = gimp_image_get_active_vectors (gimage);
1696 active_index = gimp_container_get_child_index (gimage->vectors,
1697 GIMP_OBJECT (active_vectors));
1699 num_paths = gimp_container_num_children (gimage->vectors);
1701 xcf_write_int32_check_error (info, &version, 1);
1702 xcf_write_int32_check_error (info, &active_index, 1);
1703 xcf_write_int32_check_error (info, &num_paths, 1);
1705 for (list = GIMP_LIST (gimage->vectors)->list;
1707 list = g_list_next (list))
1709 GimpVectors *vectors = list->data;
1710 KisAnnotationList *parasites;
1715 TQ_INT32 num_parasites;
1716 TQ_INT32 num_strokes;
1730 parasites = GIMP_ITEM (vectors)->parasites;
1732 name = (TQCString *) gimp_object_get_name (GIMP_OBJECT (vectors));
1733 visible = gimp_item_get_visible (GIMP_ITEM (vectors));
1734 linked = gimp_item_get_linked (GIMP_ITEM (vectors));
1735 tattoo = gimp_item_get_tattoo (GIMP_ITEM (vectors));
1736 num_parasites = gimp_parasite_list_persistent_length (parasites);
1737 num_strokes = g_list_length (vectors->strokes);
1739 xcf_write_string_check_error (info, &name, 1);
1740 xcf_write_int32_check_error (info, &tattoo, 1);
1741 xcf_write_int32_check_error (info, &visible, 1);
1742 xcf_write_int32_check_error (info, &linked, 1);
1743 xcf_write_int32_check_error (info, &num_parasites, 1);
1744 xcf_write_int32_check_error (info, &num_strokes, 1);
1746 xcf_check_error (xcf_save_parasite_list (info, parasites, error));
1748 for (stroke_list = g_list_first (vectors->strokes);
1750 stroke_list = g_list_next (stroke_list))
1753 TQ_INT32 stroke_type;
1756 GArray *control_points;
1771 stroke = GIMP_STROKE (stroke_list->data);
1773 if (GIMP_IS_BEZIER_STROKE (stroke))
1775 stroke_type = XCF_STROKETYPE_BEZIER_STROKE;
1780 g_printerr (
"Skipping unknown stroke type!\n");
1784 control_points = gimp_stroke_control_points_get (stroke, &closed);
1786 xcf_write_int32_check_error (info, &stroke_type, 1);
1787 xcf_write_int32_check_error (info, &closed, 1);
1788 xcf_write_int32_check_error (info, &num_axes, 1);
1789 xcf_write_int32_check_error (info, &control_points->len, 1);
1791 for (i = 0; i < control_points->len; i++)
1795 anchor = & (g_array_index (control_points, GimpAnchor, i));
1797 type = anchor->type;
1798 coords[0] = anchor->position.x;
1799 coords[1] = anchor->position.y;
1800 coords[2] = anchor->position.pressure;
1801 coords[3] = anchor->position.xtilt;
1802 coords[4] = anchor->position.ytilt;
1803 coords[5] = anchor->position.wheel;
1817 xcf_write_int32_check_error (info, &type, 1);
1818 xcf_write_float_check_error (info, coords, num_axes);
1821 g_array_free (control_points,
true);