3
* XJT (JPEG-TAR fileformat) loading and saving file filter for GIMP
4
* -hof (Wolfgang Hofer)
6
* This filter requires UNIX tar and the "jpeglib" Library to run.
7
* For optional further compression you also should install
8
* gzip and bzip2 compression Programs.
11
* This plugin needs GIMP 1.1.18 or newer versions of the GIMP-core to run.
14
/* GIMP - The GNU Image Manipulation Program
15
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
17
* This program is free software; you can redistribute it and/or modify
18
* it under the terms of the GNU General Public License as published by
19
* the Free Software Foundation; either version 2 of the License, or
20
* (at your option) any later version.
22
* This program is distributed in the hope that it will be useful,
23
* but WITHOUT ANY WARRANTY; without even the implied warranty of
24
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
* GNU General Public License for more details.
27
* You should have received a copy of the GNU General Public License
28
* along with this program; if not, write to the Free Software
29
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33
* - support user units
34
* - show continous progress while loading/saving
38
* version 1.3.14a; 2003/06/03 hof: bugfix: using setlocale independent float conversion procedures
39
* p_my_ascii_strtod (g_ascii_strtod()) and g_ascii_formatd()
40
* version 1.1.18a; 2000/03/07 hof: tattoo_state
41
* version 1.1.16a; 2000/02/04 hof: load paths continued, load tattos, load/save unit
42
* version 1.1.15b; 2000/01/28 hof: save/load paths (load is not activated PDB-bug)
43
* continued save/load parasites,
44
* replaced static buffers by dynamic allocated memory (goodbye to sprintf)
45
* version 1.1.15a; 2000/01/23 hof: NLS_macros, save/load parasites, \" and \n characters in names
46
* use G_DIR_SEPARATOR (but you still need UNIX tar to run this plugin)
47
* older gimp releases (prior to 1.1.15) are not supported any more.
48
* version 1.02.00; 1999/03/16 hof: - save layer/channel Tattoos
49
* - load/save image resolution added
50
* - tolerate unknown properties with warnings
51
* version 1.01.00; 1998/11/22 hof: added load/save of guides
52
* (you need gimp 1.1 to use this feature)
53
* version 1.00.00; 1998/10/29 hof: 1.st (pre) release
61
#include <sys/types.h>
68
#include <glib/gstdio.h>
71
#warning GIMP_DISABLE_DEPRECATED
73
#undef GIMP_DISABLE_DEPRECATED
75
#include <libgimp/gimp.h>
76
#include <libgimp/gimpui.h>
78
#include "libgimp/stdplugins-intl.h"
81
#include <process.h> /* getpid() */
87
#define LOAD_PROC "file-xjt-load"
88
#define SAVE_PROC "file-xjt-save"
94
#define GIMP_XJ_IMAGE "GIMP_XJ_IMAGE"
96
#define SCALE_WIDTH 125
98
#define XJT_ORIENTATION_HORIZONTAL 0
99
#define XJT_ORIENTATION_VERTICAL 1
101
gint xjt_debug = FALSE;
103
static gchar *global_parasite_prop_lines = NULL;
104
static gint global_parasite_id = 0;
108
* (0-21 are ident with PropType values as used in xcf.c
109
* the rest was added for xjt
115
PROP_ACTIVE_LAYER = 2,
116
PROP_ACTIVE_CHANNEL = 3,
118
PROP_FLOATING_SELECTION = 5,
123
PROP_LOCK_ALPHA = 10,
124
PROP_APPLY_MASK = 11,
127
PROP_SHOW_MASKED = 14,
130
PROP_COMPRESSION = 17,
132
PROP_RESOLUTION = 19,
139
PROP_TATTOO_STATE = 85,
140
PROP_PATH_LOCKED = 86,
141
PROP_PATH_CURRENT = 87,
143
PROP_PATH_POINTS = 89,
148
PROP_FLOATING_ATTACHED = 94,
149
PROP_PARASITE_FLAGS = 95,
150
PROP_GIMP_VERSION = 96,
152
PROP_SYNTAX_ERROR = 99
157
PTYP_NOT_SUPPORTED = 0,
171
XJT_IMAGE_PARASITE = 0,
172
XJT_LAYER_PARASITE = 1,
173
XJT_LAYER_MASK_PARASITE = 2,
174
XJT_CHANNEL_PARASITE = 3
181
/* XJT_INDEXED = 2 */ /* xjt does not support indexed images */
186
XJT_PATHTYPE_UNDEF = 0,
187
XJT_PATHTYPE_BEZIER = 1
202
XJT_DISSOLVE_MODE = 1,
204
XJT_MULTIPLY_MODE = 3,
206
XJT_OVERLAY_MODE = 5,
207
XJT_DIFFERENCE_MODE = 6,
208
XJT_ADDITION_MODE = 7,
209
XJT_SUBTRACT_MODE = 8,
210
XJT_DARKEN_ONLY_MODE = 9,
211
XJT_LIGHTEN_ONLY_MODE = 10,
213
XJT_SATURATION_MODE = 12,
216
XJT_DIVIDE_MODE = 15,
219
XJT_HARDLIGHT_MODE = 18,
220
XJT_SOFTLIGHT_MODE = 19,
221
XJT_GRAIN_EXTRACT_MODE = 20,
222
XJT_GRAIN_MERGE_MODE = 21,
223
XJT_COLOR_ERASE_MODE = 22
224
} XJTLayerModeEffects;
229
gchar *prop_mnemonic;
230
t_param_typ param_typ;
231
gdouble default_val1;
232
gdouble default_val2;
233
gdouble default_val3;
246
gdouble *flt_val_list;
252
t_parasitetype parasite_type;
269
gdouble *path_points;
277
gint floating_attached;
284
gint32 offx; /* do channels have offset ?? */
296
gint floating_selection;
297
gint floating_attached;
328
gint gimp_major_version;
329
gint gimp_minor_version;
330
gint gimp_micro_version;
331
GimpImageBaseType image_type;
341
t_layer_props *layer_props;
342
t_channel_props *channel_props;
343
t_channel_props *mask_props;
344
t_guide_props *guide_props;
345
t_parasite_props *parasite_props;
346
t_path_props *path_props;
350
#define PROP_TABLE_ENTRIES 35
351
t_prop_table g_prop_table[PROP_TABLE_ENTRIES] = {
352
/* t_proptype mnemonic t_paramtyp default values */
353
{ PROP_END, "*", PTYP_NOT_SUPPORTED, 0.0, 0.0, 0.0 } ,
354
{ PROP_COLORMAP, "*", PTYP_NOT_SUPPORTED, 0.0, 0.0, 0.0 } ,
355
{ PROP_ACTIVE_LAYER, "acl", PTYP_BOOLEAN, 0.0, 0.0, 0.0 } ,
356
{ PROP_ACTIVE_CHANNEL, "acc", PTYP_BOOLEAN, 0.0, 0.0, 0.0 } ,
357
{ PROP_SELECTION, "sel", PTYP_BOOLEAN, 0.0, 0.0, 0.0 } ,
358
{ PROP_FLOATING_SELECTION, "fsl", PTYP_BOOLEAN, 0.0, 0.0, 0.0 } ,
359
{ PROP_OPACITY, "op", PTYP_FLT, 100.0, 0.0, 0.0 } ,
360
{ PROP_MODE, "md", PTYP_INT, 0.0, 0.0, 0.0 } ,
361
{ PROP_VISIBLE, "iv", PTYP_BOOLEAN, 0.0, 0.0, 0.0 } ,
362
{ PROP_LINKED, "ln", PTYP_BOOLEAN, 0.0, 0.0, 0.0 } ,
363
{ PROP_LOCK_ALPHA, "pt", PTYP_BOOLEAN, 0.0, 0.0, 0.0 } ,
364
{ PROP_APPLY_MASK, "aml", PTYP_BOOLEAN, 0.0, 0.0, 0.0 } ,
365
{ PROP_EDIT_MASK, "eml", PTYP_BOOLEAN, 0.0, 0.0, 0.0 } ,
366
{ PROP_SHOW_MASK, "sml", PTYP_BOOLEAN, 0.0, 0.0, 0.0 } ,
367
{ PROP_SHOW_MASKED, "smc", PTYP_BOOLEAN, 0.0, 0.0, 0.0 } ,
368
{ PROP_OFFSETS, "o", PTYP_2xINT, 0.0, 0.0, 0.0 } ,
369
{ PROP_COLOR, "c", PTYP_3xINT, 0.0, 0.0, 0.0 } ,
370
{ PROP_COMPRESSION, "*", PTYP_NOT_SUPPORTED, 0.0, 0.0, 0.0 } ,
371
{ PROP_GUIDES, "g", PTYP_2xINT, 0.0, 0.0, 0.0 } ,
372
{ PROP_RESOLUTION, "res", PTYP_2xFLT, 72.0, 72.0, 0.0 } ,
373
{ PROP_UNIT, "unt", PTYP_INT, 0.0, 0.0, 0.0 } ,
374
{ PROP_TATTOO, "tto", PTYP_INT, -1.0, 0.0, 0.0 } ,
375
{ PROP_TATTOO_STATE, "tts", PTYP_INT, -1.0, 0.0, 0.0 } ,
376
{ PROP_PARASITES, "pte", PTYP_INT, 0.0, 0.0, 0.0 } ,
378
{ PROP_PATH_POINTS, "php", PTYP_FLIST, 0.0, 0.0, 0.0 } ,
379
{ PROP_PATH_TYPE, "pht", PTYP_INT, 1.0, 0.0, 0.0 } ,
380
{ PROP_PATH_CURRENT, "pha", PTYP_INT, 0.0, 0.0, 0.0 } ,
381
{ PROP_PATH_LOCKED, "phl", PTYP_BOOLEAN, 0.0, 0.0, 0.0 } ,
382
{ PROP_PARASITE_FLAGS, "ptf", PTYP_INT, 1.0, 0.0, 0.0 } ,
383
{ PROP_FLOATING_ATTACHED, "fa", PTYP_BOOLEAN, 0.0, 0.0, 0.0 } ,
384
{ PROP_NAME, "n", PTYP_STRING, 0.0, 0.0, 0.0 } ,
385
{ PROP_DIMENSION, "w/h", PTYP_2xINT, 0.0, 0.0, 0.0 } ,
386
{ PROP_TYPE, "typ", PTYP_INT, 0.0, 0.0, 0.0 } ,
387
{ PROP_GIMP_VERSION, "gimp", PTYP_3xINT, 0.0, 0.0, 0.0 } ,
388
{ PROP_VERSION, "ver", PTYP_STRING, 0.0, 0.0, 0.0 }
392
/* Declare local functions.
394
static void query (void);
395
static void run (const gchar *name,
397
const GimpParam *param,
399
GimpParam **return_vals);
401
static gint32 load_xjt_image (const gchar *filename);
402
static gint save_xjt_image (const gchar *filename,
406
static gboolean save_dialog (void);
409
const GimpPlugInInfo PLUG_IN_INFO =
411
NULL, /* init_proc */
412
NULL, /* quit_proc */
413
query, /* query_proc */
417
static t_JpegSaveVals jsvals =
422
0 /* clr_transparent */
428
return (value) ? FALSE : TRUE;
432
int p_system(const gchar *cmd)
437
if(xjt_debug) printf("CMD: %s\n", cmd);
442
/* Shift 8 Bits gets Retcode of the executed Program */
444
g_printerr ("ERROR system: %s\nreturncodes %d %d", cmd, l_rc, l_rc2);
455
static const GimpParamDef load_args[] =
457
{ GIMP_PDB_INT32, "run-mode", "Interactive, non-interactive" },
458
{ GIMP_PDB_STRING, "filename", "The name of the file to load" },
459
{ GIMP_PDB_STRING, "raw-filename", "The name of the file to load" },
461
static const GimpParamDef load_return_vals[] =
463
{ GIMP_PDB_IMAGE, "image", "Output image" },
466
static const GimpParamDef save_args[] =
468
{ GIMP_PDB_INT32, "run-mode", "Interactive, non-interactive" },
469
{ GIMP_PDB_IMAGE, "image", "Input image" },
470
{ GIMP_PDB_DRAWABLE, "drawable", "is ignored" },
471
{ GIMP_PDB_STRING, "filename", "The name of the file to save the image in" },
472
{ GIMP_PDB_STRING, "raw-filename", "The name of the file to save the image in" },
473
{ GIMP_PDB_FLOAT, "quality", "Quality of saved image (0 <= quality <= 1)" },
474
{ GIMP_PDB_FLOAT, "smoothing", "Smoothing factor for saved image (0 <= smoothing <= 1)" },
475
{ GIMP_PDB_INT32, "optimize", "Optimization of entropy encoding parameters" },
476
{ GIMP_PDB_INT32, "clr-transparent", "set all full-transparent pixels to 0" },
479
gimp_install_procedure (LOAD_PROC,
480
"loads files of the jpeg-tar file format",
481
"loads files of the jpeg-tar file format",
485
N_("GIMP compressed XJT image"),
488
G_N_ELEMENTS (load_args),
489
G_N_ELEMENTS (load_return_vals),
490
load_args, load_return_vals);
492
gimp_register_magic_load_handler (LOAD_PROC,
497
gimp_install_procedure (SAVE_PROC,
498
"saves files in the jpeg-tar file format",
499
"saves files in the jpeg-tar file format",
503
N_("GIMP compressed XJT image"),
506
G_N_ELEMENTS (save_args), 0,
509
gimp_register_save_handler (SAVE_PROC, "xjt,xjtgz,xjtbz2", "");
513
run (const gchar *name,
515
const GimpParam *param,
517
GimpParam **return_vals)
519
static GimpParam values[2];
520
GimpRunMode run_mode;
521
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
530
l_env = getenv("XJT_DEBUG");
533
if((*l_env != 'n') && (*l_env != 'N')) xjt_debug = TRUE;
536
run_mode = param[0].data.d_int32;
539
*return_vals = values;
540
values[0].type = GIMP_PDB_STATUS;
541
values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
543
if (strcmp (name, LOAD_PROC) == 0)
545
image_ID = load_xjt_image (param[1].data.d_string);
550
values[1].type = GIMP_PDB_IMAGE;
551
values[1].data.d_image = image_ID;
555
status = GIMP_PDB_EXECUTION_ERROR;
558
else if (strcmp (name, SAVE_PROC) == 0)
562
case GIMP_RUN_INTERACTIVE:
563
/* Possibly retrieve data */
564
gimp_get_data (SAVE_PROC, &jsvals);
566
/* First acquire information with a dialog */
567
if (! save_dialog ())
569
status = GIMP_PDB_CANCEL;
573
case GIMP_RUN_NONINTERACTIVE:
574
/* Make sure all the arguments are there! */
577
status = GIMP_PDB_CALLING_ERROR;
581
jsvals.quality = param[5].data.d_float;
582
jsvals.smoothing = param[6].data.d_float;
583
jsvals.optimize = param[7].data.d_int32;
584
jsvals.clr_transparent = param[8].data.d_int32;
586
if (jsvals.quality < 0.0 || jsvals.quality > 1.0)
588
status = GIMP_PDB_CALLING_ERROR;
590
else if (jsvals.smoothing < 0.0 || jsvals.smoothing > 1.0)
592
status = GIMP_PDB_CALLING_ERROR;
597
case GIMP_RUN_WITH_LAST_VALS:
598
/* Possibly retrieve data */
599
gimp_get_data (SAVE_PROC, &jsvals);
606
if (status == GIMP_PDB_SUCCESS)
608
if (save_xjt_image (param[3].data.d_string,
609
param[1].data.d_int32,
610
param[2].data.d_int32) <0)
612
status = GIMP_PDB_EXECUTION_ERROR;
616
/* Store mvals data */
617
gimp_set_data (SAVE_PROC, &jsvals, sizeof (t_JpegSaveVals));
623
status = GIMP_PDB_CALLING_ERROR;
626
values[0].data.d_status = status;
630
/* ------------------------
632
* ------------------------
633
* call g_ascii_strtod
634
* with XJT private modification:
635
* g_ascii_strtod accepts both "." and "," as radix character (decimalpoint)
636
* for float numbers (at least for GERMAN LANG)
637
* because XJT PRP files have comma (,) seperated lists of float numbers this cant be accepted here.
638
* the private version substitutes a '\0' character for the next comma
639
* before calling g_ascii_strtod, and puts back the comma after the call
642
p_my_ascii_strtod (gchar *nptr,
649
/* check for comma (is a terminating character for the NON locale float string)
658
nptr[ii] = '\0'; /* temporary use 0 as terminator for the call of g_ascii_strtod */
661
if ((nptr[ii] == '\0')
663
|| (nptr[ii] == '\n'))
670
l_rc = g_ascii_strtod(nptr, endptr);
674
nptr[ii] = ','; /* restore the comma */
678
} /* end p_my_ascii_strtod */
680
/* -- type transformer routines XJT -- GIMP internal enums ----------------- */
683
p_to_GimpOrientation(gint32 orientation)
685
return (orientation == XJT_ORIENTATION_VERTICAL)
686
? GIMP_ORIENTATION_VERTICAL : GIMP_ORIENTATION_HORIZONTAL;
689
p_to_XJTOrientation(gint32 orientation)
691
return (orientation == GIMP_ORIENTATION_VERTICAL)
692
? XJT_ORIENTATION_VERTICAL : XJT_ORIENTATION_HORIZONTAL;
695
static GimpLayerModeEffects
696
p_to_GimpLayerModeEffects(XJTLayerModeEffects intype)
700
case XJT_NORMAL_MODE: return GIMP_NORMAL_MODE;
701
case XJT_DISSOLVE_MODE: return GIMP_DISSOLVE_MODE;
702
case XJT_BEHIND_MODE: return GIMP_BEHIND_MODE;
703
case XJT_MULTIPLY_MODE: return GIMP_MULTIPLY_MODE;
704
case XJT_SCREEN_MODE: return GIMP_SCREEN_MODE;
705
case XJT_OVERLAY_MODE: return GIMP_OVERLAY_MODE;
706
case XJT_DIFFERENCE_MODE: return GIMP_DIFFERENCE_MODE;
707
case XJT_ADDITION_MODE: return GIMP_ADDITION_MODE;
708
case XJT_SUBTRACT_MODE: return GIMP_SUBTRACT_MODE;
709
case XJT_DARKEN_ONLY_MODE: return GIMP_DARKEN_ONLY_MODE;
710
case XJT_LIGHTEN_ONLY_MODE: return GIMP_LIGHTEN_ONLY_MODE;
711
case XJT_HUE_MODE: return GIMP_HUE_MODE;
712
case XJT_SATURATION_MODE: return GIMP_SATURATION_MODE;
713
case XJT_COLOR_MODE: return GIMP_COLOR_MODE;
714
case XJT_VALUE_MODE: return GIMP_VALUE_MODE;
715
case XJT_DIVIDE_MODE: return GIMP_DIVIDE_MODE;
716
case XJT_DODGE_MODE: return GIMP_DODGE_MODE;
717
case XJT_BURN_MODE: return GIMP_BURN_MODE;
718
case XJT_HARDLIGHT_MODE: return GIMP_HARDLIGHT_MODE;
719
case XJT_SOFTLIGHT_MODE: return GIMP_SOFTLIGHT_MODE;
720
case XJT_GRAIN_EXTRACT_MODE: return GIMP_GRAIN_EXTRACT_MODE;
721
case XJT_GRAIN_MERGE_MODE: return GIMP_GRAIN_MERGE_MODE;
722
case XJT_COLOR_ERASE_MODE: return GIMP_COLOR_ERASE_MODE;
724
printf (_("XJT file contains unknown layermode %d"), (int)intype);
725
if((gint32)intype > (gint32)XJT_DIVIDE_MODE)
727
return (GimpLayerModeEffects)intype;
729
return GIMP_NORMAL_MODE;
732
static XJTLayerModeEffects
733
p_to_XJTLayerModeEffects(GimpLayerModeEffects intype)
737
case GIMP_NORMAL_MODE: return XJT_NORMAL_MODE;
738
case GIMP_DISSOLVE_MODE: return XJT_DISSOLVE_MODE;
739
case GIMP_BEHIND_MODE: return XJT_BEHIND_MODE;
740
case GIMP_MULTIPLY_MODE: return XJT_MULTIPLY_MODE;
741
case GIMP_SCREEN_MODE: return XJT_SCREEN_MODE;
742
case GIMP_OVERLAY_MODE: return XJT_OVERLAY_MODE;
743
case GIMP_DIFFERENCE_MODE: return XJT_DIFFERENCE_MODE;
744
case GIMP_ADDITION_MODE: return XJT_ADDITION_MODE;
745
case GIMP_SUBTRACT_MODE: return XJT_SUBTRACT_MODE;
746
case GIMP_DARKEN_ONLY_MODE: return XJT_DARKEN_ONLY_MODE;
747
case GIMP_LIGHTEN_ONLY_MODE: return XJT_LIGHTEN_ONLY_MODE;
748
case GIMP_HUE_MODE: return XJT_HUE_MODE;
749
case GIMP_SATURATION_MODE: return XJT_SATURATION_MODE;
750
case GIMP_COLOR_MODE: return XJT_COLOR_MODE;
751
case GIMP_VALUE_MODE: return XJT_VALUE_MODE;
752
case GIMP_DIVIDE_MODE: return XJT_DIVIDE_MODE;
753
case GIMP_DODGE_MODE: return XJT_DODGE_MODE;
754
case GIMP_BURN_MODE: return XJT_BURN_MODE;
755
case GIMP_HARDLIGHT_MODE: return XJT_HARDLIGHT_MODE;
756
case GIMP_SOFTLIGHT_MODE: return XJT_SOFTLIGHT_MODE;
757
case GIMP_GRAIN_EXTRACT_MODE: return XJT_GRAIN_EXTRACT_MODE;
758
case GIMP_GRAIN_MERGE_MODE: return XJT_GRAIN_MERGE_MODE;
759
case GIMP_COLOR_ERASE_MODE: return XJT_COLOR_ERASE_MODE;
761
printf (_("Warning: unsupported layermode %d saved to XJT"), (int)intype);
762
if ((gint32)intype > (gint32)XJT_DIVIDE_MODE)
764
return (XJTLayerModeEffects)intype;
766
return XJT_NORMAL_MODE;
770
p_to_GimpPathType(XJTPathType intype)
774
case XJT_PATHTYPE_UNDEF: return 0;
775
case XJT_PATHTYPE_BEZIER: return 1;
777
printf (_("XJT file contains unknown pathtype %d"), (int)intype);
778
if ((gint32)intype > (gint32)XJT_PATHTYPE_BEZIER)
780
return (gint32)intype;
786
p_to_XJTPathType(gint32 intype)
790
case 0: return XJT_PATHTYPE_UNDEF;
791
case 1: return XJT_PATHTYPE_BEZIER;
793
printf (_("Warning: unsupported pathtype %d saved to XJT"), (int)intype);
794
if((gint32)intype > (gint32)XJT_PATHTYPE_BEZIER)
796
return((XJTPathType)intype);
798
return(XJT_PATHTYPE_UNDEF);
802
p_to_GimpUnit(XJTUnitType intype)
806
case XJT_UNIT_PIXEL: return(GIMP_UNIT_PIXEL);
807
case XJT_UNIT_INCH: return(GIMP_UNIT_INCH);
808
case XJT_UNIT_MM: return(GIMP_UNIT_MM);
809
case XJT_UNIT_POINT: return(GIMP_UNIT_POINT);
810
case XJT_UNIT_PICA: return(GIMP_UNIT_PICA);
812
printf (_("XJT file contains unknown unittype %d"), (int)intype);
813
if((gint32)intype > (gint32)XJT_UNIT_PICA)
815
return((GimpUnit)intype);
817
return(GIMP_UNIT_PIXEL);
821
p_to_XJTUnitType(GimpUnit intype)
825
case GIMP_UNIT_PIXEL: return(XJT_UNIT_PIXEL);
826
case GIMP_UNIT_INCH: return(XJT_UNIT_INCH);
827
case GIMP_UNIT_MM: return(XJT_UNIT_MM);
828
case GIMP_UNIT_POINT: return(XJT_UNIT_POINT);
829
case GIMP_UNIT_PICA: return(XJT_UNIT_PICA);
830
case GIMP_UNIT_END: break;
831
case GIMP_UNIT_PERCENT: break;
833
printf (_("Warning: unsupported unittype %d saved to XJT"), (int)intype);
834
if((gint32)intype > (gint32)XJT_UNIT_PICA)
836
return((XJTUnitType)intype);
838
return(XJT_UNIT_PIXEL);
841
/* ---------------------- SAVE DIALOG procedures -------------------------- */
849
GtkObject *scale_data;
852
gimp_ui_init ("xjt", FALSE);
854
dlg = gimp_dialog_new (_("Save as XJT"), "xjt",
856
gimp_standard_help_func, "file-xjt-save",
858
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
859
GTK_STOCK_SAVE, GTK_RESPONSE_OK,
863
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dlg),
868
gimp_window_set_transient (GTK_WINDOW (dlg));
870
table = gtk_table_new (4, 3, FALSE);
871
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
872
gtk_table_set_row_spacings (GTK_TABLE (table), 6);
873
gtk_container_set_border_width (GTK_CONTAINER (table), 12);
874
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), table, TRUE, TRUE, 0);
875
gtk_widget_show (table);
877
toggle = gtk_check_button_new_with_label (_("Optimize"));
878
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), jsvals.optimize);
879
gtk_table_attach (GTK_TABLE (table), toggle, 0, 3, 0, 1,
881
gtk_widget_show (toggle);
883
g_signal_connect (toggle, "toggled",
884
G_CALLBACK (gimp_toggle_button_update),
887
toggle = gtk_check_button_new_with_label (_("Clear transparent"));
888
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
889
jsvals.clr_transparent);
890
gtk_table_attach (GTK_TABLE (table), toggle, 0, 3, 1, 2,
892
gtk_widget_show (toggle);
894
g_signal_connect (toggle, "toggled",
895
G_CALLBACK (gimp_toggle_button_update),
896
&jsvals.clr_transparent);
898
scale_data = gimp_scale_entry_new (GTK_TABLE (table), 0, 2,
899
_("Quality:"), SCALE_WIDTH, 0,
900
jsvals.quality, 0.0, 1.0, 0.01, 0.11, 2,
903
g_signal_connect (scale_data, "value-changed",
904
G_CALLBACK (gimp_double_adjustment_update),
907
scale_data = gimp_scale_entry_new (GTK_TABLE (table), 0, 3,
908
_("Smoothing:"), SCALE_WIDTH, 0,
909
jsvals.smoothing, 0.0, 1.0, 0.01, 0.1, 2,
912
g_signal_connect (scale_data, "value-changed",
913
G_CALLBACK (gimp_double_adjustment_update),
916
gtk_widget_show (dlg);
918
run = (gimp_dialog_run (GIMP_DIALOG (dlg)) == GTK_RESPONSE_OK);
920
gtk_widget_destroy (dlg);
925
/* ---------------------- SAVE WORKER procedures -------------------------- */
927
/* ============================================================================
928
* p_get_property_index
929
* get index in g_prop_table by proptype (id)
930
* ============================================================================
934
p_get_property_index(t_proptype proptype)
938
for (l_idx = 0; l_idx < PROP_TABLE_ENTRIES; l_idx++)
940
if (g_prop_table[l_idx].prop_id == proptype)
945
return 0; /* index of PROP_END -- not supported */
946
} /* end p_get_property_index */
948
/* ============================================================================
950
* create string from float.
951
* ============================================================================
954
p_float_to_str(gdouble flt_val)
956
gchar l_dbl_str[G_ASCII_DTOSTR_BUF_SIZE];
960
/* XJT float precision is limited to 5 digits */
961
/* print setlocale independent float string */
962
g_ascii_formatd(&l_dbl_str[0]
963
,G_ASCII_DTOSTR_BUF_SIZE
967
l_str = g_strdup(l_dbl_str);
969
/* delete trailing '0' and '.' characters */
970
l_idx = strlen(l_str) -1;
973
if(l_str[l_idx] != '0')
980
if(l_str[l_idx] == '.')
987
/* ============================================================================
989
* copy name and make sure that double quote backslash and newline
990
* characters are escaped by a backslash
991
* ============================================================================
994
p_namedup(const gchar *name)
1003
while(*l_str != '\0')
1007
|| (*l_str == '\\'))
1015
l_name = g_malloc(l_len+2);
1018
while(*l_str != '\0')
1022
|| (*l_str == '\\'))
1026
if(*l_str == '\n') { *l_ptr = 'n'; }
1027
else { *l_ptr = *l_str; }
1040
/* ============================================================================
1041
* p_write_prop_string
1042
* allocate buffer and
1043
* write out the property mnemonic to buffer
1044
* and parameter(s) according to the property type
1046
* wr_all_prp is used for debug only and causes to write out all properties
1047
* Normally (wr_all_prp == FALSE) properties are NOT written, if they are
1048
* equal to their default value.
1049
* ============================================================================
1053
p_write_prop_string(t_proptype proptype, t_param_prop *param, gint wr_all_prp)
1064
l_prop_idx = p_get_property_index(proptype);
1066
switch (g_prop_table[l_prop_idx].param_typ)
1069
/* boolean properties are written if they are not FALSE */
1072
buffer = g_strdup_printf(" %s", g_prop_table[l_prop_idx].prop_mnemonic);
1078
buffer = g_strdup_printf(" %s!", g_prop_table[l_prop_idx].prop_mnemonic);
1083
/* int properties are written if they are not equal to default */
1084
if((param->int_val1 != g_prop_table[l_prop_idx].default_val1)
1087
buffer = g_strdup_printf(" %s:%d", g_prop_table[l_prop_idx].prop_mnemonic,
1088
(int)param->int_val1);
1092
if((param->flt_val1 != g_prop_table[l_prop_idx].default_val1)
1095
l_f1 = p_float_to_str(param->flt_val1);
1096
buffer = g_strdup_printf(" %s:%s", g_prop_table[l_prop_idx].prop_mnemonic, l_f1);
1101
if((param->flt_val1 != g_prop_table[l_prop_idx].default_val1)
1102
|| (param->flt_val2 != g_prop_table[l_prop_idx].default_val2)
1105
l_f1 = p_float_to_str(param->flt_val1);
1106
l_f2 = p_float_to_str(param->flt_val2);
1107
buffer = g_strdup_printf(" %s:%s,%s", g_prop_table[l_prop_idx].prop_mnemonic, l_f1, l_f2);
1113
if((param->flt_val1 != g_prop_table[l_prop_idx].default_val1)
1114
|| (param->flt_val2 != g_prop_table[l_prop_idx].default_val2)
1115
|| (param->flt_val3 != g_prop_table[l_prop_idx].default_val3)
1118
l_f1 = p_float_to_str(param->flt_val1);
1119
l_f2 = p_float_to_str(param->flt_val2);
1120
l_f3 = p_float_to_str(param->flt_val3);
1121
buffer = g_strdup_printf(" %s:%s,%s,%s", g_prop_table[l_prop_idx].prop_mnemonic, l_f1, l_f2, l_f3);
1128
if(param->num_fvals > 0)
1130
l_f1 = p_float_to_str(param->flt_val_list[0]);
1131
buffer = g_strdup_printf(" %s:%s", g_prop_table[l_prop_idx].prop_mnemonic, l_f1);
1133
for(l_idp = 1; l_idp < param->num_fvals; l_idp++)
1135
l_f1 = p_float_to_str(param->flt_val_list[l_idp]);
1136
l_str = g_strdup_printf("%s,%s", buffer, l_f1);
1144
if(param->string_val != NULL)
1146
if((*param->string_val != '\0')
1149
l_str = p_namedup(param->string_val);
1152
buffer = g_strdup_printf(" %s:\"%s\"", g_prop_table[l_prop_idx].prop_mnemonic, l_str);
1159
if((param->int_val1 != g_prop_table[l_prop_idx].default_val1)
1160
|| (param->int_val2 != g_prop_table[l_prop_idx].default_val2)
1163
buffer = g_strdup_printf(" %s:%d,%d", g_prop_table[l_prop_idx].prop_mnemonic,
1164
(int)param->int_val1, (int)param->int_val2);
1168
if((param->int_val1 != g_prop_table[l_prop_idx].default_val1)
1169
|| (param->int_val2 != g_prop_table[l_prop_idx].default_val2)
1170
|| (param->int_val3 != g_prop_table[l_prop_idx].default_val3)
1173
buffer = g_strdup_printf(" %s:%d,%d,%d", g_prop_table[l_prop_idx].prop_mnemonic,
1174
(int)param->int_val1,
1175
(int)param->int_val2,
1176
(int)param->int_val3);
1179
default: /* PTYP_NOT_SUPPORTED */
1185
buffer = g_strdup("\0");
1188
} /* end p_write_prop_string */
1190
/* ============================================================================
1192
* write out the property mnemonic to file
1193
* and parameter(s) according to the property type
1195
* wr_all_prp is used for debug only and causes to write out all properties
1196
* Normally (wr_all_prp == FALSE) properties are NOT written, if they are
1197
* equal to their default value.
1198
* ============================================================================
1202
p_write_prop(FILE *fp, t_proptype proptype, t_param_prop *param, gint wr_all_prp)
1205
l_buff = p_write_prop_string(proptype, param, wr_all_prp);
1207
if (l_buff[0] != '\0')
1209
fprintf(fp, "%s", l_buff);
1212
} /* end p_write_prop */
1215
/* ============================================================================
1217
* write out one parasite by
1218
* - write property to PRP file
1219
* - write parasite data to parasite_file
1220
* - and prepare global_parasite_prop_lines
1221
* ============================================================================
1225
p_write_parasite(const gchar *dirname,
1227
GimpParasite *parasite,
1230
gchar *l_new_parasite_prop_lines;
1231
gchar *l_parasite_buff;
1232
gchar *l_parasite_file;
1236
t_param_prop l_param;
1238
if(parasite->flags & GIMP_PARASITE_PERSISTENT) /* check if GimpParasite should be saved */
1240
global_parasite_id++;
1242
l_param.int_val1 = global_parasite_id;
1243
p_write_prop (fp, PROP_PARASITES, &l_param, TRUE);
1245
/* add parasite line like this:
1246
* p2 n:"layer parasite A" ptf:1
1247
* to global_parasite_prop_lines buffer.
1248
* (the buffer is written as last block to the PRP file)
1250
l_param.string_val = parasite->name;
1251
l_buff = p_write_prop_string(PROP_NAME, &l_param, wr_all_prp);
1253
l_param.int_val1 = parasite->flags;
1254
l_buff2 = p_write_prop_string(PROP_PARASITE_FLAGS, &l_param, wr_all_prp);
1256
l_parasite_buff = g_strdup_printf("p%d%s%s\n"
1257
, (int)global_parasite_id
1263
if (global_parasite_prop_lines == NULL)
1265
global_parasite_prop_lines = g_strdup(l_parasite_buff);
1269
l_new_parasite_prop_lines = g_strdup_printf("%s%s", global_parasite_prop_lines, l_parasite_buff);
1270
g_free(global_parasite_prop_lines);
1271
global_parasite_prop_lines = l_new_parasite_prop_lines;
1273
g_free(l_parasite_buff);
1275
/* write the parasite data to a file named p1.pte */
1276
l_parasite_file = g_strdup_printf("%s%cp%d.pte", dirname, G_DIR_SEPARATOR, (int)global_parasite_id);
1277
l_fp_pte = g_fopen(l_parasite_file, "wb");
1278
if(l_fp_pte == NULL)
1280
g_message (_("Could not open '%s' for writing: %s"),
1281
gimp_filename_to_utf8 (l_parasite_file), g_strerror (errno));
1282
g_free(l_parasite_file);
1287
fwrite(parasite->data, parasite->size, 1, l_fp_pte);
1289
g_free(l_parasite_file);
1296
p_write_image_paths(FILE *fp, gint32 image_id, gint wr_all_prp)
1299
gchar **l_path_names = NULL;
1300
gchar *l_current_pathname = NULL;
1301
gint32 l_num_paths = 0;
1302
gdouble *l_path_points;
1304
gint32 l_path_closed;
1305
gint32 l_num_points = 0;
1306
t_param_prop l_param;
1308
l_path_names = gimp_path_list(image_id, &l_num_paths);
1309
if(l_path_names == NULL) return;
1311
l_current_pathname = gimp_path_get_current(image_id);
1313
for(l_idx = 0; l_idx < l_num_paths; l_idx++)
1315
if(xjt_debug) printf("p_write_image_paths NAME:%s:\n", l_path_names[l_idx]);
1317
l_path_type = gimp_path_get_points(image_id, l_path_names[l_idx],
1318
&l_path_closed, &l_num_points, &l_path_points);
1321
/* write PATH line identifier */
1322
fprintf(fp, "PATH");
1324
l_param.int_val1 = p_to_XJTPathType(l_path_type);
1325
p_write_prop (fp, PROP_PATH_TYPE, &l_param, wr_all_prp);
1327
l_param.int_val1 = gimp_path_get_tattoo(image_id, l_path_names[l_idx]);
1328
p_write_prop (fp, PROP_TATTOO, &l_param, wr_all_prp);
1330
l_param.int_val1 = gimp_path_get_locked(image_id, l_path_names[l_idx]);
1331
p_write_prop (fp, PROP_PATH_LOCKED, &l_param, wr_all_prp);
1333
l_param.string_val = l_path_names[l_idx];
1334
p_write_prop (fp, PROP_NAME, &l_param, wr_all_prp);
1336
/* current path flag */
1337
l_param.int_val1 = FALSE;
1338
if(l_current_pathname)
1340
if(strcmp(l_current_pathname, l_path_names[l_idx]) == 0)
1342
l_param.int_val1 = TRUE;
1343
p_write_prop (fp, PROP_PATH_CURRENT, &l_param, wr_all_prp);
1347
l_param.num_fvals = l_num_points;
1348
l_param.flt_val_list = l_path_points;
1349
p_write_prop (fp, PROP_PATH_POINTS, &l_param, wr_all_prp);
1352
g_free(l_path_points);
1356
g_free(l_current_pathname);
1357
g_free(l_path_names);
1361
p_write_image_parasites(const gchar *dirname,
1366
GimpParasite *l_parasite;
1368
gchar **l_parasite_names = NULL;
1369
gint32 l_num_parasites = 0;
1371
if (!gimp_image_parasite_list (image_id, &l_num_parasites, &l_parasite_names))
1374
for(l_idx = 0; l_idx < l_num_parasites; l_idx++)
1376
l_parasite = gimp_image_parasite_find(image_id, l_parasite_names[l_idx]);
1379
if(xjt_debug) printf("p_write_image_parasites NAME:%s:\n", l_parasite_names[l_idx]);
1380
p_write_parasite(dirname, fp, l_parasite, wr_all_prp);
1383
g_free(l_parasite_names);
1387
p_write_drawable_parasites (const gchar *dirname,
1392
GimpParasite *l_parasite;
1394
gchar **l_parasite_names = NULL;
1395
gint32 l_num_parasites = 0;
1397
if (!gimp_drawable_parasite_list (drawable_id, &l_num_parasites, &l_parasite_names))
1400
for(l_idx = 0; l_idx < l_num_parasites; l_idx++)
1402
l_parasite = gimp_drawable_parasite_find(drawable_id, l_parasite_names[l_idx]);
1405
if(xjt_debug) printf("p_write_drawable_parasites NAME:%s:\n", l_parasite_names[l_idx]);
1406
p_write_parasite(dirname, fp, l_parasite, wr_all_prp);
1409
g_free(l_parasite_names);
1412
/* ============================================================================
1414
* write out all properties of the given layer
1415
* ============================================================================
1419
p_write_layer_prp(const gchar *dirname,
1421
const gchar *layer_shortname,
1426
t_param_prop l_param;
1427
gint l_ofsx, l_ofsy;
1429
fprintf(fp, "%s", layer_shortname);
1431
l_param.int_val1 = (layer_id == gimp_image_get_active_layer(image_id)); /* TRUE/FALSE */
1432
p_write_prop (fp, PROP_ACTIVE_LAYER, &l_param, wr_all_prp);
1434
l_param.int_val1 = gimp_layer_is_floating_sel(layer_id); /* TRUE/FALSE */
1435
p_write_prop (fp, PROP_FLOATING_SELECTION, &l_param, wr_all_prp);
1437
/* check if floating selection is attached to this layer */
1438
l_param.int_val1 = (layer_id == gimp_image_floating_sel_attached_to(image_id));
1439
p_write_prop (fp, PROP_FLOATING_ATTACHED, &l_param, wr_all_prp);
1441
l_param.flt_val1 = gimp_layer_get_opacity(layer_id);
1442
p_write_prop (fp, PROP_OPACITY, &l_param, wr_all_prp);
1444
l_param.int_val1 = (gint32)p_to_XJTLayerModeEffects(gimp_layer_get_mode(layer_id));
1445
p_write_prop (fp, PROP_MODE, &l_param, wr_all_prp);
1447
l_param.int_val1 = p_invert(gimp_drawable_get_visible(layer_id));
1448
p_write_prop (fp, PROP_VISIBLE, &l_param, wr_all_prp);
1450
l_param.int_val1 = gimp_drawable_get_linked (layer_id);
1451
p_write_prop (fp, PROP_LINKED, &l_param, wr_all_prp);
1453
l_param.int_val1 = gimp_layer_get_lock_alpha (layer_id);
1454
p_write_prop (fp, PROP_LOCK_ALPHA, &l_param, wr_all_prp);
1456
l_param.int_val1 = gimp_layer_get_apply_mask(layer_id);
1457
p_write_prop (fp, PROP_APPLY_MASK, &l_param, wr_all_prp);
1459
l_param.int_val1 = gimp_layer_get_edit_mask(layer_id);
1460
p_write_prop (fp, PROP_EDIT_MASK, &l_param, wr_all_prp);
1462
l_param.int_val1 = gimp_layer_get_show_mask(layer_id);
1463
p_write_prop (fp, PROP_SHOW_MASK, &l_param, wr_all_prp);
1465
gimp_drawable_offsets(layer_id, &l_ofsx, &l_ofsy);
1466
l_param.int_val1 = l_ofsx;
1467
l_param.int_val2 = l_ofsy;
1468
p_write_prop (fp, PROP_OFFSETS, &l_param, wr_all_prp);
1470
l_param.int_val1 = gimp_drawable_get_tattoo(layer_id);
1471
p_write_prop (fp, PROP_TATTOO, &l_param, wr_all_prp);
1473
l_param.string_val = gimp_drawable_get_name(layer_id);
1474
p_write_prop (fp, PROP_NAME, &l_param, wr_all_prp);
1476
p_write_drawable_parasites(dirname, fp, layer_id, wr_all_prp);
1480
} /* end p_write_layer_prp */
1483
/* ============================================================================
1484
* p_write_channel_prp
1485
* write out all properties of the given channel
1486
* ============================================================================
1490
p_write_channel_prp(const gchar *dirname,
1492
const gchar *channel_shortname,
1497
t_param_prop l_param;
1498
gint l_ofsx, l_ofsy;
1500
guchar l_r, l_g, l_b;
1502
fprintf(fp, "%s", channel_shortname);
1504
l_param.int_val1 = (channel_id == gimp_image_get_active_channel(image_id)); /* TRUE/FALSE */
1505
p_write_prop (fp, PROP_ACTIVE_CHANNEL, &l_param, wr_all_prp);
1507
l_param.int_val1 = (channel_id == gimp_image_get_selection (image_id)); /* TRUE/FALSE */
1508
p_write_prop (fp, PROP_SELECTION, &l_param, wr_all_prp);
1510
/* check if floating selection is attached to this channel */
1511
l_param.int_val1 = (channel_id == gimp_image_floating_sel_attached_to(image_id));
1512
p_write_prop (fp, PROP_FLOATING_ATTACHED, &l_param, wr_all_prp);
1514
l_param.flt_val1 = gimp_channel_get_opacity(channel_id);
1515
p_write_prop (fp, PROP_OPACITY, &l_param, wr_all_prp);
1517
l_param.int_val1 = p_invert(gimp_drawable_get_visible(channel_id));
1518
p_write_prop (fp, PROP_VISIBLE, &l_param, wr_all_prp);
1520
l_param.int_val1 = gimp_channel_get_show_masked(channel_id);
1521
p_write_prop (fp, PROP_SHOW_MASKED, &l_param, wr_all_prp);
1523
gimp_channel_get_color(channel_id, &color);
1524
gimp_rgb_get_uchar (&color, &l_r, &l_g, &l_b);
1525
l_param.int_val1 = l_r;
1526
l_param.int_val2 = l_g;
1527
l_param.int_val3 = l_b;
1528
p_write_prop (fp, PROP_COLOR, &l_param, wr_all_prp);
1530
gimp_drawable_offsets(channel_id, &l_ofsx, &l_ofsy);
1531
l_param.int_val1 = l_ofsx;
1532
l_param.int_val2 = l_ofsy;
1533
p_write_prop (fp, PROP_OFFSETS, &l_param, wr_all_prp);
1535
l_param.int_val1 = gimp_drawable_get_tattoo (channel_id);
1536
p_write_prop (fp, PROP_TATTOO, &l_param, wr_all_prp);
1538
l_param.string_val = gimp_drawable_get_name(channel_id);
1539
p_write_prop (fp, PROP_NAME, &l_param, wr_all_prp);
1541
p_write_drawable_parasites(dirname, fp, channel_id, wr_all_prp);
1545
} /* end p_write_channel_prp */
1547
/* ============================================================================
1549
* write out the properties of the image
1550
* ============================================================================
1554
p_write_image_prp (const gchar *dirname,
1559
GimpImageBaseType l_image_type;
1560
guint l_width, l_height;
1561
gdouble l_xresolution, l_yresolution;
1562
t_param_prop l_param;
1565
/* get info about the image */
1566
l_width = gimp_image_width(image_id);
1567
l_height = gimp_image_height(image_id);
1568
l_image_type = gimp_image_base_type(image_id);
1570
fprintf(fp, "%s", GIMP_XJ_IMAGE);
1572
l_param.string_val = "1.3.11";
1573
p_write_prop (fp, PROP_VERSION, &l_param, wr_all_prp);
1575
l_param.int_val1 = GIMP_MAJOR_VERSION;
1576
l_param.int_val2 = GIMP_MINOR_VERSION;
1577
l_param.int_val3 = GIMP_MICRO_VERSION;
1578
p_write_prop (fp, PROP_GIMP_VERSION, &l_param, wr_all_prp);
1580
l_param.int_val1 = l_width;
1581
l_param.int_val2 = l_height;
1582
p_write_prop (fp, PROP_DIMENSION, &l_param, wr_all_prp);
1584
gimp_image_get_resolution(image_id, &l_xresolution, &l_yresolution);
1585
l_param.flt_val1 = l_xresolution;
1586
l_param.flt_val2 = l_yresolution;
1587
p_write_prop (fp, PROP_RESOLUTION, &l_param, wr_all_prp);
1590
l_param.int_val1 = p_to_XJTUnitType(gimp_image_get_unit(image_id));
1591
p_write_prop (fp, PROP_UNIT, &l_param, wr_all_prp);
1593
/* write tattoo_state */
1594
l_param.int_val1 = gimp_image_get_tattoo_state(image_id);
1595
if (l_param.int_val1 > 0)
1597
p_write_prop (fp, PROP_TATTOO_STATE, &l_param, wr_all_prp);
1601
l_guide_id = gimp_image_find_next_guide(image_id, 0); /* get 1.st guide */
1602
while (l_guide_id > 0)
1604
/* get position and orientation for the current guide ID */
1606
l_param.int_val1 = gimp_image_get_guide_position(image_id, l_guide_id);
1607
l_param.int_val2 = p_to_XJTOrientation(gimp_image_get_guide_orientation(image_id, l_guide_id));
1608
p_write_prop (fp, PROP_GUIDES, &l_param, wr_all_prp);
1610
/* findnext returns 0 if no (more) guides there
1611
* (or -1 if no PDB interface is available)
1613
l_guide_id = gimp_image_find_next_guide(image_id, l_guide_id);
1616
if (l_image_type == GIMP_GRAY)
1618
l_param.int_val1 = (gint32)XJT_GRAY;
1622
l_param.int_val1 = (gint32)XJT_RGB;
1624
p_write_prop (fp, PROP_TYPE, &l_param, wr_all_prp);
1626
p_write_image_parasites(dirname, fp, image_id, wr_all_prp);
1630
p_write_image_paths(fp, image_id, wr_all_prp);
1631
} /* end p_write_image_prp */
1634
/* ---------------------- SAVE -------------------------- */
1637
save_xjt_image (const gchar *filename,
1650
GimpImageBaseType l_image_type;
1651
gint32 *l_layers_list;
1652
gint32 *l_channels_list;
1656
gint32 l_channel_id;
1657
gint32 l_floating_layer_id;
1658
gint32 l_selection_channel_id;
1660
gint32 l_x1, l_x2, l_y1, l_y2;
1665
l_rc = -1; /* init retcode to Errorstate */
1666
l_floating_layer_id = -1;
1668
l_layers_list = NULL;
1669
l_channels_list = NULL;
1673
l_wr_all_prp = FALSE; /* FALSE write only non-default properties
1674
* TRUE write all properties (should be used for DEBUG only)
1676
global_parasite_id = 0;
1677
global_parasite_prop_lines = NULL;
1680
/* get info about the image */
1681
l_image_type = gimp_image_base_type(image_id);
1682
switch (l_image_type)
1688
g_message (_("Cannot operate on indexed color images."));
1692
g_message (_("Cannot operate on unknown image types."));
1697
gimp_progress_init_printf (_("Saving '%s'"),
1698
gimp_filename_to_utf8 (filename));
1700
/* create temporary directory */
1701
l_dirname = gimp_temp_name (".tmpdir");
1702
l_prop_file = g_strdup_printf ("%s%cPRP", l_dirname, G_DIR_SEPARATOR);
1703
if (g_mkdir (l_dirname, 0777) != 0)
1705
g_message (_("Could not create working folder '%s': %s"),
1706
gimp_filename_to_utf8 (l_dirname), g_strerror (errno));
1710
/* create property file PRP */
1711
l_fp_prp = g_fopen (l_prop_file, "wb");
1712
if (l_fp_prp == NULL)
1714
g_message (_("Could not open '%s' for writing: %s"),
1715
gimp_filename_to_utf8 (l_prop_file), g_strerror (errno));
1719
/* write image properties */
1720
p_write_image_prp (l_dirname, l_fp_prp, image_id, l_wr_all_prp);
1723
l_floating_layer_id = gimp_image_get_floating_sel (image_id);
1724
if (l_floating_layer_id >= 0)
1726
if (xjt_debug) printf ("XJT-DEBUG: call floating_sel_relax fsel_id=%d\n",
1727
(int) l_floating_layer_id);
1729
gimp_floating_sel_relax (l_floating_layer_id, FALSE);
1732
l_layers_list = gimp_image_get_layers (image_id, &l_nlayers);
1734
/* foreach layer do */
1735
for (l_idx = 0; l_idx < l_nlayers; l_idx++)
1737
l_layer_id = l_layers_list[l_idx];
1739
if (xjt_debug) printf ("Layer [%d] id=%d\n", (int)l_idx, (int)l_layer_id);
1741
/* save layer as jpeg file */
1742
l_jpg_file = g_strdup_printf ("%s%cl%d.jpg", l_dirname,
1743
G_DIR_SEPARATOR, l_idx);
1744
if (xjt_debug) printf ("XJT-DEBUG: saving layer to file %s\n", l_jpg_file);
1746
if (TRUE != xjpg_save_drawable (l_jpg_file,
1754
g_free (l_jpg_file);
1756
/* write out the layer properties */
1757
if(gimp_drawable_has_alpha(l_layer_id)) { l_jpg_file = g_strdup_printf("L%d", l_idx); }
1758
else { l_jpg_file = g_strdup_printf("l%d", l_idx); }
1759
p_write_layer_prp(l_dirname, l_fp_prp, l_jpg_file, image_id, l_layer_id, l_wr_all_prp);
1762
/* check, and save alpha channel */
1763
if(gimp_drawable_has_alpha(l_layer_id))
1765
l_jpg_file = g_strdup_printf("%s%cla%d.jpg", l_dirname, G_DIR_SEPARATOR, l_idx);
1766
if(xjt_debug) printf("XJT-DEBUG: saving alpha-channel to file %s\n", l_jpg_file);
1768
if(TRUE != xjpg_save_drawable(l_jpg_file,
1778
/* check and save layer_mask channel */
1779
l_channel_id = gimp_layer_get_mask (l_layer_id);
1780
if(l_channel_id >= 0)
1782
l_jpg_file = g_strdup_printf("%s%clm%d.jpg", l_dirname, G_DIR_SEPARATOR, l_idx);
1783
if(xjt_debug) printf("XJT-DEBUG: saving layer-mask to file %s\n", l_jpg_file);
1785
if(TRUE != xjpg_save_drawable(l_jpg_file,
1794
/* write out the layer_mask (== channel) properties */
1795
l_jpg_file = g_strdup_printf("m%d", l_idx);
1796
p_write_channel_prp(l_dirname, l_fp_prp, l_jpg_file, image_id, l_channel_id, l_wr_all_prp);
1799
} /* end foreach layer */
1802
/* check and see if we have to save out the selection */
1804
l_selection_channel_id = gimp_image_get_selection(image_id);
1805
if ((gimp_selection_bounds(image_id, &non_empty, &l_x1, &l_y1, &l_x2, &l_y2))
1806
&& (l_selection_channel_id >= 0))
1811
l_channels_list = gimp_image_get_channels(image_id, &l_nchannels);
1813
/* foreach channel do */
1814
for(l_idx = 0; l_idx < l_nchannels + l_sel; l_idx++)
1816
if(l_idx < l_nchannels) l_channel_id = l_channels_list[l_idx];
1817
else l_channel_id = l_selection_channel_id;
1819
if(xjt_debug) printf("channel [%d] id=%d\n", (int)l_idx, (int)l_channel_id);
1821
/* save channel as jpeg file */
1822
l_jpg_file = g_strdup_printf ("%s%cc%d.jpg", l_dirname, G_DIR_SEPARATOR, l_idx);
1823
if(xjt_debug) printf("XJT-DEBUG: saving channel to file %s\n", l_jpg_file);
1825
if(TRUE != xjpg_save_drawable(l_jpg_file,
1834
/* write out the channel properties */
1835
l_jpg_file = g_strdup_printf ("c%d", l_idx);
1836
p_write_channel_prp(l_dirname, l_fp_prp, l_jpg_file, image_id, l_channel_id, l_wr_all_prp);
1839
} /* end foreach channel */
1842
if(global_parasite_prop_lines != NULL)
1844
/* have to add parasite lines at end of PRP file */
1845
fprintf(l_fp_prp, "%s", global_parasite_prop_lines);
1850
/* store properties and all layers and cannels in a
1851
* tar archive with filename.tar
1853
l_cmd = g_strdup_printf("cd %s; tar -cf \"%s\" *; cd ..", l_dirname, filename);
1854
l_rc = p_system(l_cmd);
1857
l_len = strlen(filename);
1858
if((l_len > 3) && (l_rc == 0))
1860
/* call optional extracompression programs gzip or bzip2
1861
* (depends on filename's extension)
1863
* used gzip options: (bzip2 uses the same options)
1864
* -c --stdout --to-stdout
1865
* Write output on standard output
1867
* Force compression or decompression even if the file
1869
if(strcmp(&filename[l_len - 3], "bz2") == 0)
1871
l_cmd = g_strdup_printf("bzip2 -cf \"%s\" >\"%s.tmp_bz2\"",filename , filename);
1872
l_rc = p_system(l_cmd);
1874
l_cmd = g_strdup_printf("mv \"%s.tmp_bz2\" \"%s\"" ,filename , filename);
1875
l_rc = p_system(l_cmd);
1878
else if(strcmp(&filename[l_len - 2], "gz") == 0)
1880
l_cmd = g_strdup_printf("gzip -cf <\"%s\" >\"%s.tmp_gz\"",filename , filename);
1881
l_rc = p_system(l_cmd);
1883
l_cmd = g_strdup_printf("mv \"%s.tmp_gz\" \"%s\"" ,filename , filename);
1884
l_rc = p_system(l_cmd);
1895
if (l_floating_layer_id >= 0)
1898
printf("XJT-DEBUG: here we should call floating_sel_rigor sel_id=%d\n",
1899
(int)l_floating_layer_id);
1900
gimp_floating_sel_rigor (l_floating_layer_id, FALSE);
1903
g_free (l_layers_list);
1904
g_free (l_channels_list);
1906
/* remove the temorary directory */
1907
l_cmd = g_strdup_printf("rm -rf \"%s\"", l_dirname);
1909
if(!xjt_debug) p_system(l_cmd);
1913
g_free (l_prop_file);
1914
g_free (l_jpg_file);
1919
/* ---------------------- LOAD WORKER procedures -------------------------- */
1922
/* ============================================================================
1924
* allocate new layer_properties element and init with default values
1925
* ============================================================================
1927
static t_layer_props *
1928
p_new_layer_prop(void)
1930
t_layer_props *l_new_prop;
1932
l_new_prop = g_malloc(sizeof(t_layer_props));
1933
l_new_prop->active_layer = g_prop_table[p_get_property_index(PROP_ACTIVE_LAYER)].default_val1;
1934
l_new_prop->floating_selection = g_prop_table[p_get_property_index(PROP_FLOATING_SELECTION)].default_val1;
1935
l_new_prop->floating_attached = g_prop_table[p_get_property_index(PROP_FLOATING_ATTACHED)].default_val1;
1936
l_new_prop->opacity = g_prop_table[p_get_property_index(PROP_OPACITY)].default_val1;
1937
l_new_prop->mode = g_prop_table[p_get_property_index(PROP_MODE)].default_val1;
1938
l_new_prop->visible = p_invert(g_prop_table[p_get_property_index(PROP_VISIBLE)].default_val1);
1939
l_new_prop->linked = g_prop_table[p_get_property_index(PROP_LINKED)].default_val1;
1940
l_new_prop->lock_alpha = g_prop_table[p_get_property_index(PROP_LOCK_ALPHA)].default_val1;
1941
l_new_prop->apply_mask = g_prop_table[p_get_property_index(PROP_APPLY_MASK)].default_val1;
1942
l_new_prop->edit_mask = g_prop_table[p_get_property_index(PROP_EDIT_MASK)].default_val1;
1943
l_new_prop->show_mask = g_prop_table[p_get_property_index(PROP_SHOW_MASK)].default_val1;
1944
l_new_prop->offx = g_prop_table[p_get_property_index(PROP_OFFSETS)].default_val1;
1945
l_new_prop->offy = g_prop_table[p_get_property_index(PROP_OFFSETS)].default_val2;
1946
l_new_prop->tattoo = g_prop_table[p_get_property_index(PROP_TATTOO)].default_val1;
1947
l_new_prop->name = NULL;
1949
l_new_prop->layer_pos = -1;
1950
l_new_prop->has_alpha = FALSE;
1951
l_new_prop->next = NULL;
1953
} /* end p_new_layer_prop */
1956
/* ============================================================================
1957
* p_new_channel_prop
1958
* allocate new channel_properties element and init with default values
1959
* ============================================================================
1961
static t_channel_props *
1962
p_new_channel_prop(void)
1964
t_channel_props *l_new_prop;
1966
l_new_prop = g_malloc(sizeof(t_channel_props));
1967
l_new_prop->active_channel = g_prop_table[p_get_property_index(PROP_ACTIVE_CHANNEL)].default_val1;
1968
l_new_prop->selection = g_prop_table[p_get_property_index(PROP_SELECTION)].default_val1;
1969
l_new_prop->floating_attached = g_prop_table[p_get_property_index(PROP_FLOATING_ATTACHED)].default_val1;
1970
l_new_prop->opacity = g_prop_table[p_get_property_index(PROP_OPACITY)].default_val1;
1971
l_new_prop->visible = p_invert(g_prop_table[p_get_property_index(PROP_VISIBLE)].default_val1);
1972
l_new_prop->show_masked = g_prop_table[p_get_property_index(PROP_SHOW_MASKED)].default_val1;
1973
l_new_prop->offx = g_prop_table[p_get_property_index(PROP_OFFSETS)].default_val1;
1974
l_new_prop->offy = g_prop_table[p_get_property_index(PROP_OFFSETS)].default_val2;
1975
l_new_prop->color_r = g_prop_table[p_get_property_index(PROP_COLOR)].default_val1;
1976
l_new_prop->color_g = g_prop_table[p_get_property_index(PROP_COLOR)].default_val2;
1977
l_new_prop->color_b = g_prop_table[p_get_property_index(PROP_COLOR)].default_val3;
1978
l_new_prop->tattoo = g_prop_table[p_get_property_index(PROP_TATTOO)].default_val1;
1979
l_new_prop->name = NULL;
1981
l_new_prop->channel_pos = -1;
1982
l_new_prop->next = NULL;
1984
} /* end p_new_channel_prop */
1987
/* ============================================================================
1989
* allocate new guide_properties element and init with default values
1990
* ============================================================================
1992
static t_guide_props *
1993
p_new_guide_prop(void)
1995
t_guide_props *l_new_prop;
1997
l_new_prop = g_malloc(sizeof(t_guide_props));
1998
l_new_prop->position = 0;
1999
l_new_prop->orientation = 0;
2000
l_new_prop->next = NULL;
2002
} /* end p_new_guide_prop */
2004
/* ============================================================================
2005
* p_new_parasite_prop
2006
* allocate new parasite_properties element and init with default values
2007
* ============================================================================
2009
static t_parasite_props *
2010
p_new_parasite_prop(void)
2012
t_parasite_props *l_new_prop;
2014
l_new_prop = g_malloc(sizeof(t_parasite_props));
2015
l_new_prop->parasite_type = XJT_IMAGE_PARASITE;
2016
l_new_prop->parasite_id = -1;
2017
l_new_prop->name = NULL;
2018
l_new_prop->obj_pos = -1;
2019
l_new_prop->flags = GIMP_PARASITE_PERSISTENT;
2020
l_new_prop->next = NULL;
2022
} /* end p_new_parasite_prop */
2024
/* ============================================================================
2026
* allocate new parasite_properties element and init with default values
2027
* ============================================================================
2029
static t_path_props *
2030
p_new_path_prop(void)
2032
t_path_props *l_new_prop;
2034
l_new_prop = g_malloc(sizeof(t_path_props));
2035
l_new_prop->path_type = p_to_GimpPathType(XJT_PATHTYPE_BEZIER);
2036
l_new_prop->tattoo = g_prop_table[p_get_property_index(PROP_TATTOO)].default_val1;
2037
l_new_prop->path_locked = FALSE;
2038
l_new_prop->path_closed = FALSE;
2039
l_new_prop->current_flag = FALSE;
2040
l_new_prop->name = NULL;
2041
l_new_prop->num_points = 0;
2042
l_new_prop->path_points = NULL;
2043
l_new_prop->next = NULL;
2045
} /* end p_new_path_prop */
2047
/* ============================================================================
2049
* allocate new layer_properties element and init with default values
2050
* ============================================================================
2052
static t_image_props *
2053
p_new_image_prop(void)
2055
t_image_props *l_new_prop;
2057
l_new_prop = g_malloc(sizeof(t_image_props));
2058
l_new_prop->image_type = g_prop_table[p_get_property_index(PROP_TYPE)].default_val1;
2059
l_new_prop->image_width = g_prop_table[p_get_property_index(PROP_DIMENSION)].default_val1;
2060
l_new_prop->image_height = g_prop_table[p_get_property_index(PROP_DIMENSION)].default_val2;
2061
l_new_prop->xresolution = g_prop_table[p_get_property_index(PROP_RESOLUTION)].default_val1;
2062
l_new_prop->yresolution = g_prop_table[p_get_property_index(PROP_RESOLUTION)].default_val2;
2063
l_new_prop->unit = p_to_GimpUnit(g_prop_table[p_get_property_index(PROP_UNIT)].default_val1);
2064
l_new_prop->tattoo = g_prop_table[p_get_property_index(PROP_TATTOO)].default_val1;
2065
l_new_prop->tattoo_state = g_prop_table[p_get_property_index(PROP_TATTOO_STATE)].default_val1;
2066
l_new_prop->n_layers = 0;
2067
l_new_prop->n_channels = 0;
2068
l_new_prop->layer_props = NULL;
2069
l_new_prop->channel_props = NULL;
2070
l_new_prop->mask_props = NULL;
2071
l_new_prop->guide_props = NULL;
2072
l_new_prop->parasite_props = NULL;
2073
l_new_prop->path_props = NULL;
2075
} /* end p_new_image_prop */
2078
/* ============================================================================
2081
* ============================================================================
2084
p_skip_blanks(gchar* scan_ptr)
2086
while((*scan_ptr == ' ') || (*scan_ptr == '\t'))
2093
/* ============================================================================
2095
* scan one token with its parameter(s)
2096
* return pointer to character behind the last scanned byte.
2098
* Check prop_id for PROP_END (no more tokens found)
2099
* for PROP_SYNTAX_ERROR (illegal token/params detected)
2100
* ============================================================================
2104
p_scann_token(gchar *scan_ptr,
2105
t_param_prop *param,
2106
t_proptype *prop_id)
2113
gchar *l_string_buff;
2118
/* check for end of property line */
2119
if((*scan_ptr == '\0') || (*scan_ptr == '\n'))
2121
*prop_id = PROP_END;
2125
*prop_id = PROP_SYNTAX_ERROR;
2127
l_max_line_len = strlen(scan_ptr);
2128
l_token = g_malloc(l_max_line_len + 1);
2130
/* extract current token at scann_ptr position */
2132
for (l_idx = 0; l_idx < (l_max_line_len -1); l_idx++)
2144
l_token[l_idx] = (*l_ptr);
2147
l_token[l_idx] = '\0';
2149
if(xjt_debug) printf("XJT:TOKEN:%s:", l_token);
2151
/* check if token is one of the supported mnemonics */
2152
for (l_idx = 0; l_idx < PROP_TABLE_ENTRIES; l_idx++)
2154
if(g_prop_table[l_idx].param_typ == PTYP_NOT_SUPPORTED)
2159
if(0 != strcmp(l_token, g_prop_table[l_idx].prop_mnemonic))
2164
*prop_id = g_prop_table[l_idx].prop_id;
2166
/* scann parameters according to detected property type */
2167
switch(g_prop_table[l_idx].param_typ)
2170
param->int_val1 = TRUE;
2173
g_printerr ("XJT: PRP syntax error (bool property %s terminated with :)\n",
2175
*prop_id = PROP_SYNTAX_ERROR;
2178
if(*l_ptr == '!') /* inverter character */
2180
param->int_val1 = FALSE;
2183
if(xjt_debug) printf("%d", (int)param->int_val1);
2190
g_printerr ("XJT: PRP syntax error (int property %s not terminated with :)\n",
2192
*prop_id = PROP_SYNTAX_ERROR;
2197
param->int_val1 = strtol(l_ptr, &l_ptr2, 10); /* Scan 1.st integer (base = 10) */
2198
if (l_ptr == l_ptr2 )
2200
g_printerr ("XJT: PRP syntax error (int property %s :integer value missing)\n",
2202
*prop_id = PROP_SYNTAX_ERROR;
2206
if(xjt_debug) printf("%d", (int)param->int_val1);
2208
if((PTYP_2xINT == g_prop_table[l_idx].param_typ)
2209
|| (PTYP_3xINT == g_prop_table[l_idx].param_typ))
2213
g_printerr ("XJT: PRP syntax error (int property %s comma missing)\n",
2215
*prop_id = PROP_SYNTAX_ERROR;
2219
param->int_val2 = strtol(l_ptr, &l_ptr2, 10); /* Scan 2.nd integer (base = 10) */
2220
if (l_ptr == l_ptr2 )
2222
g_printerr ("XJT: PRP syntax error (int property %s : 2.nd integer value missing)\n",
2224
*prop_id = PROP_SYNTAX_ERROR;
2228
if(xjt_debug) printf(",%d", (int)param->int_val2);
2230
if(PTYP_3xINT == g_prop_table[l_idx].param_typ)
2234
g_printerr ("XJT: PRP syntax error (int property %s comma missing)\n",
2236
*prop_id = PROP_SYNTAX_ERROR;
2240
param->int_val3 = strtol(l_ptr, &l_ptr2, 10); /* Scan 3.rd integer (base = 10) */
2241
if (l_ptr == l_ptr2 )
2243
g_printerr ("XJT: PRP syntax error (int property %s : 3.rd integer value missing)\n",
2245
*prop_id = PROP_SYNTAX_ERROR;
2249
if(xjt_debug) printf(",%d", (int)param->int_val3);
2259
g_printerr ("XJT: PRP syntax error (float property %s not terminated with :)\n",
2261
*prop_id = PROP_SYNTAX_ERROR;
2266
param->flt_val1 = p_my_ascii_strtod(l_ptr, &l_ptr2);
2267
if (l_ptr == l_ptr2 )
2269
g_printerr ("XJT: PRP syntax error (float property %s :float value missing)\n",
2271
*prop_id = PROP_SYNTAX_ERROR;
2275
if(xjt_debug) printf("%f", param->flt_val1);
2277
if((PTYP_2xFLT == g_prop_table[l_idx].param_typ)
2278
|| (PTYP_3xFLT == g_prop_table[l_idx].param_typ))
2282
g_printerr ("XJT: PRP syntax error (float property %s comma missing)\n",
2284
*prop_id = PROP_SYNTAX_ERROR;
2288
param->flt_val2 = p_my_ascii_strtod(l_ptr, &l_ptr2);
2289
if (l_ptr == l_ptr2 )
2291
g_printerr ("XJT: PRP syntax error (float property %s : 2.nd float value missing)\n",
2293
*prop_id = PROP_SYNTAX_ERROR;
2297
if(xjt_debug) printf(",%f", param->flt_val2);
2299
if(PTYP_3xFLT == g_prop_table[l_idx].param_typ)
2303
g_printerr ("XJT: PRP syntax error (float property %s comma missing)\n",
2305
*prop_id = PROP_SYNTAX_ERROR;
2309
param->flt_val3 = p_my_ascii_strtod(l_ptr, &l_ptr2);
2310
if (l_ptr == l_ptr2 )
2312
g_printerr ("XJT: PRP syntax error (float property %s : 3.rd float value missing)\n",
2314
*prop_id = PROP_SYNTAX_ERROR;
2318
if(xjt_debug) printf(",%f", param->flt_val3);
2326
g_printerr ("XJT: PRP syntax error (floatlist property %s not terminated with :)\n",
2328
*prop_id = PROP_SYNTAX_ERROR;
2333
/* counting ',' to guess how much values are in the list */
2338
if((*l_ptr2 == '\0')
2339
|| (*l_ptr2 == '\n'))
2350
param->num_fvals = 0;
2351
param->flt_val_list = g_malloc0(sizeof(gdouble) * l_num_fvals);
2354
param->flt_val_list[param->num_fvals] = p_my_ascii_strtod(l_ptr, &l_ptr2);
2355
if (l_ptr == l_ptr2 )
2357
if(param->num_fvals == 0)
2359
g_printerr ("XJT: PRP syntax error (floatlist property %s :no float value found)\n",
2361
*prop_id = PROP_SYNTAX_ERROR;
2367
if(xjt_debug) printf("%f char:%c\n", param->flt_val_list[param->num_fvals], *l_ptr);
2371
if((*l_ptr2 != '\0')
2372
&& (*l_ptr2 != '\n'))
2374
g_printerr ("XJT: PRP syntax error (floatlist property %s :list contains illegal character: %c)\n",
2376
*prop_id = PROP_SYNTAX_ERROR;
2388
g_printerr ("XJT: PRP syntax error (string property %s not terminated with :)\n",
2390
*prop_id = PROP_SYNTAX_ERROR;
2396
g_printerr ("XJT: PRP syntax error (string property %s starting \" is missing)\n",
2398
*prop_id = PROP_SYNTAX_ERROR;
2402
l_string_buff = g_malloc(l_max_line_len + 2);
2403
for(l_ids= 0; l_ids < (l_max_line_len -2); l_ids++)
2411
if(l_ptr[1] == '\"')
2413
l_string_buff[l_ids] = '\"';
2420
l_string_buff[l_ids] = '\n';
2425
if(l_ptr[1] == '\\')
2427
l_string_buff[l_ids] = '\\';
2434
if((*l_ptr == '\"') ||
2439
l_string_buff[l_ids] = *l_ptr;
2442
l_string_buff[l_ids] = '\0';
2446
param->string_val = g_strdup (l_string_buff);
2447
if(xjt_debug) printf("%s", param->string_val);
2451
g_printerr ("XJT: PRP syntax error (string property %s terminating \" is missing)\n",
2453
*prop_id = PROP_SYNTAX_ERROR;
2455
g_free(l_string_buff);
2458
g_printerr ("XJT: ** Warning ** PRP file with unsupported property %s\n",
2460
*prop_id = PROP_SYNTAX_ERROR;
2467
if(xjt_debug) printf("\n");
2469
/* advance l_ptr to next Blank
2470
* (this is needed to skip unknown tokens
2477
|| (*l_ptr == '\0'))
2485
if(*prop_id == PROP_SYNTAX_ERROR)
2487
g_printerr ("XJT: ** Warning ** PRP file skipping property: %s\n", l_token);
2492
} /* end p_scann_token */
2495
/* ============================================================================
2497
* if the parasite_props list has an item with parasite_id
2498
* return the pointer to the matching item,
2499
* else return NULL (no matching item found)
2500
* ============================================================================
2502
static t_parasite_props *
2503
p_find_parasite(t_parasite_props *parasite_props, gint32 parasite_id)
2505
t_parasite_props *l_prop;
2507
if(xjt_debug) printf("XJT: p_find_parasite search parasite_id (1): %d\n", (int)parasite_id );
2509
l_prop = parasite_props;
2512
if(xjt_debug) printf("XJT: p_find_parasite (2) listid=%d\n", (int)l_prop->parasite_id );
2513
if(l_prop->parasite_id == parasite_id)
2515
if(xjt_debug) printf("XJT: p_find_parasite (3) listid=%d\n", (int)l_prop->parasite_id );
2518
l_prop = (t_parasite_props *)l_prop->next;
2521
if(xjt_debug) printf("XJT: p_find_parasite (4) NULL\n");
2525
/* ============================================================================
2526
* p_create_and_attach_parasite
2527
* ============================================================================
2530
p_create_and_attach_parasite (gint32 gimp_obj_id,
2531
const gchar *dirname,
2532
t_parasite_props *parasite_props)
2534
gchar *l_parasite_file;
2535
GimpParasite l_parasite;
2536
struct stat l_stat_buf;
2539
/* create filename dirname/p1.pte 1 == parasite_id */
2540
l_parasite_file = g_strdup_printf("%s%cp%d.pte", dirname, G_DIR_SEPARATOR, (int)parasite_props->parasite_id);
2542
if (0 != g_stat(l_parasite_file, &l_stat_buf))
2544
/* stat error (file does not exist) */
2545
g_message (_("Could not open '%s' for reading: %s"),
2546
gimp_filename_to_utf8 (l_parasite_file), g_strerror (errno));
2550
l_fp_pte = g_fopen(l_parasite_file, "rb");
2551
if(l_fp_pte == NULL)
2553
g_message (_("Could not open '%s' for reading: %s"),
2554
gimp_filename_to_utf8 (l_parasite_file), g_strerror (errno));
2558
g_free(l_parasite_file);
2560
l_parasite.size = l_stat_buf.st_size;
2561
l_parasite.data = g_malloc(l_parasite.size);
2562
l_parasite.flags = parasite_props->flags | GIMP_PARASITE_PERSISTENT;
2563
if(parasite_props->name)
2565
l_parasite.name = g_strdup(parasite_props->name);
2569
l_parasite.name = g_strdup("\0");
2572
/* read the parasitedata from file */
2573
fread(l_parasite.data, l_parasite.size, 1, l_fp_pte);
2577
/* attach the parasite to gimp_obj_id
2578
* (is an Image or drawable id depending on parasite_type)
2580
if(parasite_props->parasite_type == XJT_IMAGE_PARASITE)
2582
if(xjt_debug) printf("XJT: gimp_image_parasite_attach name:%s\n", l_parasite.name);
2583
gimp_image_parasite_attach(gimp_obj_id, &l_parasite);
2588
if(xjt_debug) printf("XJT: gimp_drawable_parasite_attach name:%s\n", l_parasite.name);
2589
gimp_drawable_parasite_attach(gimp_obj_id, &l_parasite);
2592
if(l_parasite.data) g_free(l_parasite.data);
2593
if(l_parasite.name) g_free(l_parasite.name);
2596
} /* end p_create_and_attach_parasite */
2598
/* ============================================================================
2599
* p_check_and_add_parasite
2600
* find parasite by type and pos (obj_pos)
2601
* ============================================================================
2604
p_check_and_add_parasite (gint32 gimp_obj_id,
2605
const gchar *dirname,
2606
t_parasite_props *parasite_props,
2608
t_parasitetype parasite_type)
2610
t_parasite_props *l_prop;
2612
l_prop = parasite_props;
2615
if((l_prop->parasite_type == parasite_type)
2616
&& (l_prop->obj_pos == pos))
2618
p_create_and_attach_parasite(gimp_obj_id, dirname, l_prop);
2620
l_prop = (t_parasite_props *)l_prop->next;
2622
} /* end p_check_and_add_parasite */
2624
/* ============================================================================
2625
* p_scann_layer_prop
2626
* scann one inputline for layer properties (also used for layer_mask props)
2627
* ============================================================================
2630
p_scann_layer_prop (gchar *scan_ptr,
2631
t_image_props *image_prop)
2634
t_layer_props *l_new_prop;
2635
t_parasite_props *l_parasite_prop;
2637
t_param_prop l_param;
2638
t_proptype l_prop_id;
2640
l_new_prop = p_new_layer_prop();
2642
/* add the new element to the layer_props list */
2643
l_new_prop->next = image_prop->layer_props;
2644
image_prop->layer_props = l_new_prop;
2646
if(*scan_ptr == 'L')
2648
l_new_prop->has_alpha = TRUE;
2651
l_new_prop->layer_pos = strtol(&scan_ptr[1], &l_ptr, 10); /* Scan integer (base = 10) */
2652
if(l_ptr == scan_ptr)
2654
g_printerr ("XJT: PRP file layer# missing, scanned bad line:\n%s\n", scan_ptr);
2660
l_ptr = p_skip_blanks(l_ptr);
2661
l_ptr = p_scann_token(l_ptr, &l_param, &l_prop_id);
2668
case PROP_ACTIVE_LAYER:
2669
l_new_prop->active_layer = l_param.int_val1;
2671
case PROP_FLOATING_SELECTION:
2672
l_new_prop->floating_selection = l_param.int_val1;
2674
case PROP_FLOATING_ATTACHED:
2675
l_new_prop->floating_attached = l_param.int_val1;
2678
l_new_prop->opacity = l_param.flt_val1;
2681
l_new_prop->mode = p_to_GimpLayerModeEffects(l_param.int_val1);
2684
l_new_prop->visible = p_invert(l_param.int_val1);
2687
l_new_prop->linked = l_param.int_val1;
2689
case PROP_LOCK_ALPHA:
2690
l_new_prop->lock_alpha = l_param.int_val1;
2692
case PROP_APPLY_MASK:
2693
l_new_prop->apply_mask = l_param.int_val1;
2695
case PROP_EDIT_MASK:
2696
l_new_prop->edit_mask = l_param.int_val1;
2698
case PROP_SHOW_MASK:
2699
l_new_prop->show_mask = l_param.int_val1;
2702
l_new_prop->offx = l_param.int_val1;
2703
l_new_prop->offy = l_param.int_val2;
2706
l_new_prop->name = l_param.string_val;
2709
l_new_prop->tattoo = l_param.int_val1;
2711
case PROP_PARASITES:
2712
l_parasite_prop = p_find_parasite(image_prop->parasite_props, l_param.int_val1);
2713
if(l_parasite_prop == NULL)
2715
l_parasite_prop = p_new_parasite_prop();
2716
l_parasite_prop->next = image_prop->parasite_props;
2717
image_prop->parasite_props = l_parasite_prop;
2722
l_parasite_prop->parasite_id = l_param.int_val1;
2723
l_parasite_prop->parasite_type = XJT_LAYER_PARASITE;
2724
l_parasite_prop->obj_pos = l_new_prop->layer_pos;
2728
/* g_printerr ("XJT: PRP file scanned bad line:\n%s\n", scan_ptr); */
2729
/* return -1; */ /* skip unknow tokens */
2734
} /* end p_scann_layer_prop */
2737
/* ============================================================================
2738
* p_scann_channel_prop
2739
* scann one inputline for channel properties (also used for layer_mask props)
2740
* ============================================================================
2743
p_scann_channel_prop (const gchar *scan_ptr,
2744
t_image_props *image_prop)
2747
t_channel_props *l_new_prop;
2748
t_parasite_props *l_parasite_prop;
2750
t_param_prop l_param;
2751
t_proptype l_prop_id;
2752
t_parasitetype l_parasite_type;
2754
l_new_prop = p_new_channel_prop();
2756
l_new_prop->channel_pos = strtol(&scan_ptr[1], &l_ptr, 10); /* Scan integer (base = 10) */
2757
if(l_ptr == scan_ptr)
2759
g_printerr ("XJT: PRP file channel# missing, scanned bad line:\n%s\n",
2764
/* check if it is layer_mask or channel */
2765
if(*scan_ptr == 'm')
2767
/* add the new element to the mask_props list of the image */
2768
l_new_prop->next = image_prop->mask_props;
2769
image_prop->mask_props = l_new_prop;
2770
l_parasite_type = XJT_LAYER_MASK_PARASITE;
2774
/* add the new element to the channel_props list of the image */
2775
l_new_prop->next = image_prop->channel_props;
2776
image_prop->channel_props = l_new_prop;
2777
l_parasite_type = XJT_CHANNEL_PARASITE;
2783
l_ptr = p_skip_blanks(l_ptr);
2784
l_ptr = p_scann_token(l_ptr, &l_param, &l_prop_id);
2791
case PROP_ACTIVE_CHANNEL:
2792
l_new_prop->active_channel = l_param.int_val1;
2794
case PROP_SELECTION:
2795
l_new_prop->selection = l_param.int_val1;
2797
case PROP_FLOATING_ATTACHED:
2798
l_new_prop->floating_attached = l_param.int_val1;
2801
l_new_prop->opacity = l_param.flt_val1;
2804
l_new_prop->visible = p_invert(l_param.int_val1);
2806
case PROP_SHOW_MASKED:
2807
l_new_prop->show_masked = l_param.int_val1;
2810
l_new_prop->offx = l_param.int_val1;
2811
l_new_prop->offy = l_param.int_val2;
2814
l_new_prop->color_r = l_param.int_val1;
2815
l_new_prop->color_g = l_param.int_val2;
2816
l_new_prop->color_b = l_param.int_val3;
2819
l_new_prop->name = l_param.string_val;
2822
l_new_prop->tattoo = l_param.int_val1;
2824
case PROP_PARASITES:
2825
l_parasite_prop = p_find_parasite(image_prop->parasite_props, l_param.int_val1);
2826
if(l_parasite_prop == NULL)
2828
l_parasite_prop = p_new_parasite_prop();
2829
l_parasite_prop->next = image_prop->parasite_props;
2830
image_prop->parasite_props = l_parasite_prop;
2835
l_parasite_prop->parasite_id = l_param.int_val1;
2836
l_parasite_prop->parasite_type = l_parasite_type;
2837
l_parasite_prop->obj_pos = l_new_prop->channel_pos;
2841
/* g_printerr ("XJT: PRP file scanned bad line:\n%s\n", scan_ptr); */
2842
/* return -1; */ /* skip unknow tokens */
2847
} /* end p_scann_channel_prop */
2849
/* ============================================================================
2850
* p_scann_image_prop
2852
* ============================================================================
2855
p_scann_image_prop (gchar *scan_ptr,
2856
t_image_props *image_prop)
2859
t_param_prop l_param;
2860
t_proptype l_prop_id;
2861
t_guide_props *l_guide_prop;
2862
t_parasite_props *l_parasite_prop;
2864
if(strncmp(scan_ptr, GIMP_XJ_IMAGE, strlen(GIMP_XJ_IMAGE)) != 0)
2866
g_printerr ("XJT: PRP file %s identstring missing, scanned bad line:\n%s\n",
2867
GIMP_XJ_IMAGE, scan_ptr);
2871
l_ptr = &scan_ptr[strlen(GIMP_XJ_IMAGE)];
2875
l_ptr = p_skip_blanks(l_ptr);
2876
l_ptr = p_scann_token(l_ptr, &l_param, &l_prop_id);
2884
image_prop->version = l_param.string_val;
2886
case PROP_GIMP_VERSION:
2887
image_prop->gimp_major_version = l_param.int_val1;
2888
image_prop->gimp_minor_version = l_param.int_val2;
2889
image_prop->gimp_micro_version = l_param.int_val3;
2892
switch(l_param.int_val1)
2895
image_prop->image_type = GIMP_RGB;
2898
image_prop->image_type = GIMP_GRAY;
2901
g_printerr ("XJT: PRP unsupported image_type %d\n",
2902
(int)l_param.int_val1);
2907
case PROP_DIMENSION:
2908
image_prop->image_width = l_param.int_val1;
2909
image_prop->image_height = l_param.int_val2;
2912
image_prop->unit = p_to_GimpUnit(l_param.int_val1);
2915
l_guide_prop = p_new_guide_prop();
2918
l_guide_prop->next = image_prop->guide_props;
2919
image_prop->guide_props = l_guide_prop;
2921
l_guide_prop->position = l_param.int_val1;
2922
l_guide_prop->orientation = p_to_GimpOrientation(l_param.int_val2);
2925
case PROP_PARASITES:
2926
l_parasite_prop = p_find_parasite(image_prop->parasite_props, l_param.int_val1);
2927
if(l_parasite_prop == NULL)
2929
l_parasite_prop = p_new_parasite_prop();
2930
l_parasite_prop->next = image_prop->parasite_props;
2931
image_prop->parasite_props = l_parasite_prop;
2936
l_parasite_prop->parasite_id = l_param.int_val1;
2937
l_parasite_prop->parasite_type = XJT_IMAGE_PARASITE;
2938
l_parasite_prop->obj_pos = 0;
2941
case PROP_RESOLUTION:
2942
image_prop->xresolution = l_param.flt_val1;
2943
image_prop->yresolution = l_param.flt_val2;
2946
image_prop->tattoo = l_param.int_val1;
2948
case PROP_TATTOO_STATE:
2949
image_prop->tattoo_state = l_param.int_val1;
2952
/* g_printerr ("XJT: Warning PRP unexpected token in line:\n%s\n", scan_ptr); */
2953
/* return -1; */ /* skip unknow tokens */
2957
} /* end p_scann_image_prop */
2960
/* ============================================================================
2961
* p_scann_parasite_prop
2962
* scann one inputline for parasite properties
2963
* ============================================================================
2966
p_scann_parasite_prop (const gchar *scan_ptr,
2967
t_image_props *image_prop)
2970
t_parasite_props *l_new_prop;
2972
t_param_prop l_param;
2973
t_proptype l_prop_id;
2974
gint32 l_parasite_id;
2976
l_parasite_id = strtol(&scan_ptr[1], &l_ptr, 10); /* Scan integer (base = 10) */
2977
if(l_ptr == scan_ptr)
2979
g_printerr ("XJT: PRP file parasite# missing, scanned bad line:\n%s\n",
2984
l_new_prop = p_find_parasite(image_prop->parasite_props, l_parasite_id);
2985
if(l_new_prop == NULL)
2987
l_new_prop = p_new_parasite_prop();
2988
/* add the new element to the parasite_props list of the image */
2989
l_new_prop->next = image_prop->parasite_props;
2990
image_prop->parasite_props = l_new_prop;
2993
if(l_new_prop == NULL)
2998
l_new_prop->parasite_id = l_parasite_id;
3002
l_ptr = p_skip_blanks(l_ptr);
3003
l_ptr = p_scann_token(l_ptr, &l_param, &l_prop_id);
3011
l_new_prop->name = l_param.string_val;
3013
case PROP_PARASITE_FLAGS:
3014
l_new_prop->flags = l_param.int_val1;
3017
/* g_printerr ("XJT: PRP file scanned bad line:\n%s\n", scan_ptr); */
3018
/* return -1; */ /* skip unknow tokens */
3022
} /* end p_scann_parasite_prop */
3025
/* ============================================================================
3027
* scann one inputline for path properties
3028
* ============================================================================
3031
p_scann_path_prop (gchar *scan_ptr,
3032
t_image_props *image_prop)
3034
t_path_props *l_new_prop;
3036
t_param_prop l_param;
3037
t_proptype l_prop_id;
3039
l_new_prop = p_new_path_prop ();
3041
/* add the new element to the path_props list */
3042
l_new_prop->next = image_prop->path_props;
3043
image_prop->path_props = l_new_prop;
3045
if (strncmp (scan_ptr, "PATH", strlen ("PATH")) != 0)
3047
g_printerr ("XJT: PRP scanned bad line:\n%s\n", scan_ptr);
3050
l_ptr = scan_ptr + strlen ("PATH");
3054
l_ptr = p_skip_blanks (l_ptr);
3055
l_ptr = p_scann_token (l_ptr, &l_param, &l_prop_id);
3062
case PROP_PATH_TYPE:
3063
l_new_prop->path_type = p_to_GimpPathType(l_param.int_val1);
3065
case PROP_PATH_LOCKED:
3066
l_new_prop->path_locked = l_param.int_val1;
3069
l_new_prop->tattoo = l_param.int_val1;
3072
l_new_prop->name = l_param.string_val;
3074
case PROP_PATH_CURRENT:
3075
l_new_prop->current_flag = l_param.int_val1;
3077
case PROP_PATH_POINTS:
3078
l_new_prop->num_points = l_param.num_fvals;
3079
l_new_prop->path_points = l_param.flt_val_list;
3082
/* g_printerr ("XJT: PRP file scanned bad line:\n%s\n", scan_ptr); */
3083
/* return -1; */ /* skip unknow tokens */
3088
} /* end p_scann_path_prop */
3091
/* ============================================================================
3093
* ============================================================================
3096
p_add_paths (gint32 image_id,
3097
t_path_props *path_props)
3099
gchar *l_current_pathname = NULL;
3100
t_path_props *l_prop;
3102
l_prop = path_props;
3105
if(l_prop->num_points > 0)
3108
printf("XJT: p_add_path name:%s num_points:%d\n", l_prop->name,
3109
(int)l_prop->num_points);
3110
if(xjt_debug) printf("XJT: :path_type %d point[0]:%f\n",
3111
(int)l_prop->path_type, (float)l_prop->path_points[0]);
3112
if(l_prop->current_flag)
3114
l_current_pathname = l_prop->name;
3116
gimp_path_set_points(image_id, l_prop->name,
3117
l_prop->path_type, l_prop->num_points, l_prop->path_points);
3118
gimp_path_set_locked(image_id, l_prop->name, l_prop->path_locked);
3119
if(l_prop->tattoo >= 0)
3121
gimp_path_set_tattoo(image_id, l_prop->name, l_prop->tattoo);
3124
l_prop = (t_path_props *)l_prop->next;
3127
if(l_current_pathname)
3129
if(xjt_debug) printf("XJT: p_add_path current:%s\n", l_current_pathname);
3130
gimp_path_set_current(image_id, l_current_pathname);
3132
} /* end p_add_paths */
3136
p_load_linefile (const gchar *filename,
3140
struct stat stat_buf;
3145
/* get file length */
3146
if (0 != g_stat(filename, &stat_buf))
3150
*len = stat_buf.st_size;
3152
l_file_buff = g_malloc0(*len +1);
3154
/* read file into buffer */
3155
l_fp = g_fopen(filename, "rb");
3160
fread(l_file_buff, *len, 1, l_fp);
3163
/* replace all '\n' characters by '\0' */
3164
for(l_idx = 0; l_idx < *len; l_idx++)
3166
if(l_file_buff[l_idx] == '\n')
3168
l_file_buff[l_idx] = '\0';
3172
return(l_file_buff);
3177
p_next_lineindex (const gchar *file_buff,
3184
while (pos < max_len)
3186
if (file_buff[pos] == '\0')
3193
return (pos >= max_len) ? -1 : pos;
3196
/* ============================================================================
3198
* read all properties from file "PRP"
3199
* and return the information in a t_image_props stucture
3200
* ============================================================================
3203
static t_image_props *
3204
p_load_prop_file (const gchar *prop_filename)
3211
t_image_props *l_image_prop;
3214
if(xjt_debug) printf("p_load_prop_file: %s\n", prop_filename);
3217
l_image_prop = p_new_image_prop();
3219
l_file_buff = p_load_linefile(prop_filename, &l_filesize);
3220
if(l_file_buff == NULL)
3222
g_message(_("Error: Could not read XJT property file '%s'."),
3223
gimp_filename_to_utf8 (prop_filename));
3228
g_message(_("Error: XJT property file '%s' is empty."),
3229
gimp_filename_to_utf8 (prop_filename));
3233
/* parse 1.st line (image properties) */
3235
l_line_ptr = l_file_buff;
3237
if(xjt_debug) printf("\nXJT:PRP_LINE:%s:\n", l_line_ptr);
3238
l_rc = p_scann_image_prop(l_line_ptr, l_image_prop);
3246
l_line_idx = p_next_lineindex(l_file_buff, l_filesize, l_line_idx);
3250
break; /* end of file */
3252
l_line_ptr = &l_file_buff[l_line_idx];
3254
if(xjt_debug) printf("\nXJT:PRP_LINE:%s:\n", l_line_ptr);
3256
l_ptr = p_skip_blanks(&l_line_ptr[0]);
3258
if(*l_ptr == '#') continue; /* skip commentlines */
3259
if(*l_ptr == '\n') continue; /* skip empty lines */
3260
if(*l_ptr == '\0') continue; /* skip empty lines */
3262
if((*l_ptr == 'l') || (*l_ptr == 'L'))
3264
l_rc = p_scann_layer_prop(l_line_ptr, l_image_prop);
3265
l_image_prop->n_layers++;
3269
if((*l_ptr == 'c') || (*l_ptr == 'm'))
3271
l_rc = p_scann_channel_prop(l_line_ptr, l_image_prop);
3272
l_image_prop->n_channels++;
3278
l_rc = p_scann_parasite_prop(l_line_ptr, l_image_prop);
3284
l_rc = p_scann_path_prop(l_line_ptr, l_image_prop);
3288
g_printerr ("XJT: Warning, undefined PRP line scanned:\n%s\n",
3299
g_free(l_file_buff);
3301
return (l_rc) ? NULL : l_image_prop;
3302
} /* end p_load_prop_file */
3305
/* ---------------------- LOAD -------------------------- */
3308
load_xjt_image (const gchar *filename)
3317
gint32 *l_layers_list;
3318
gint32 *l_channels_list;
3320
gint32 l_channel_id;
3322
gint32 l_fsel_attached_to_id; /* the drawable id where the floating selection is attached to */
3323
gint32 l_fsel_id; /* the drawable id of the floating selection itself */
3324
gint32 l_active_layer_id;
3325
gint32 l_active_channel_id;
3326
t_image_props *l_image_prp_ptr;
3327
t_layer_props *l_layer_prp_ptr;
3328
t_channel_props *l_channel_prp_ptr;
3329
t_guide_props *l_guide_prp_ptr;
3331
l_rc = -1; /* init retcode to Errorstate */
3333
l_layers_list = NULL;
3334
l_channels_list = NULL;
3335
l_image_prp_ptr = NULL;
3339
l_active_layer_id = -1;
3340
l_active_channel_id = -1;
3341
l_fsel_attached_to_id = -1; /* -1 assume fsel is not available (and not attached to any drawable) */
3342
l_fsel_id = -1; /* -1 assume there is no floating selection */
3344
gimp_progress_init_printf (_("Opening '%s'"),
3345
gimp_filename_to_utf8 (filename));
3347
/* create temporary directory */
3348
l_dirname = gimp_temp_name (".tmpdir");
3349
l_prop_file = g_strdup_printf("%s%cPRP", l_dirname, G_DIR_SEPARATOR);
3351
if(g_mkdir(l_dirname, 0777) != 0)
3353
g_message (_("Could not create working folder '%s': %s"),
3354
gimp_filename_to_utf8 (l_dirname), g_strerror (errno));
3359
/* prepare for extract tar files directly from filename into l_dirname */
3360
if((*filename == G_DIR_SEPARATOR)
3361
|| (filename[1] == ':'))
3363
/* filename with absolute path */
3364
l_cmd = g_strdup_printf("cd %s; tar -xf \"%s\"; cd ..", l_dirname, filename);
3368
/* filename with relative path */
3369
l_cmd = g_strdup_printf("cd %s; tar -xf \"..%c%s\" *; cd ..", l_dirname, G_DIR_SEPARATOR, filename);
3372
l_len = strlen(filename);
3375
/* call optional extracompression programs gzip or bzip2
3376
* (depends on filename's extension)
3378
* used gzip options: (bzip2 uses the same options)
3379
* -c --stdout --to-stdout
3380
* Write output on standard output
3381
* -d --decompress --uncompress
3384
* Force compression or decompression even if the file
3386
if(strcmp(&filename[l_len - 3], "bz2") == 0)
3389
l_cmd = g_strdup_printf("bunzip2 <\"%s\" >\"%s%carc.tar\"",filename , l_dirname, G_DIR_SEPARATOR);
3390
l_rc = p_system(l_cmd);
3392
l_cmd = g_strdup_printf("cd %s; tar -xf arc.tar; cd ..", l_dirname);
3394
else if(strcmp(&filename[l_len - 2], "gz") == 0)
3397
l_cmd = g_strdup_printf("gzip -cdf <\"%s\" >\"%s%carc.tar\"",filename , l_dirname, G_DIR_SEPARATOR);
3398
l_rc = p_system(l_cmd);
3400
l_cmd = g_strdup_printf("cd %s; tar -xf arc.tar; cd ..", l_dirname);
3405
/* now we can extract the unpacked tar archive */
3406
l_rc = p_system(l_cmd);
3412
/* check and read Property file (PRP must exist in each xjt archive) */
3413
l_image_prp_ptr = p_load_prop_file(l_prop_file);
3414
if (l_image_prp_ptr == NULL)
3420
/* create new image (with type and size values from the Property file) */
3421
l_image_id = gimp_image_new (l_image_prp_ptr->image_width,
3422
l_image_prp_ptr->image_height,
3423
l_image_prp_ptr->image_type);
3429
gimp_image_set_filename (l_image_id, filename);
3430
gimp_image_set_resolution (l_image_id,
3431
l_image_prp_ptr->xresolution,
3432
l_image_prp_ptr->yresolution);
3433
gimp_image_set_unit(l_image_id, l_image_prp_ptr->unit);
3435
p_check_and_add_parasite(l_image_id,
3437
l_image_prp_ptr->parasite_props,
3439
XJT_IMAGE_PARASITE);
3440
/* load all layers */
3442
for(l_layer_prp_ptr = l_image_prp_ptr->layer_props;
3443
l_layer_prp_ptr != NULL;
3444
l_layer_prp_ptr = (t_layer_props *)l_layer_prp_ptr->next)
3446
l_jpg_file = g_strdup_printf("%s%cl%d.jpg", l_dirname, G_DIR_SEPARATOR, (int)l_layer_prp_ptr->layer_pos);
3447
if(xjt_debug) printf("XJT-DEBUG: loading layer from file %s\n", l_jpg_file);
3449
l_layer_id = xjpg_load_layer (l_jpg_file,
3451
l_image_prp_ptr->image_type,
3452
l_layer_prp_ptr->name,
3453
l_layer_prp_ptr->opacity,
3454
l_layer_prp_ptr->mode);
3463
if(l_layer_prp_ptr->floating_selection)
3465
l_fsel_id = l_layer_id; /* this layer is the floating selection */
3469
/* add the layer on top of the images layerstak */
3470
gimp_image_add_layer (l_image_id, l_layer_id, 0);
3472
if(l_layer_prp_ptr->floating_attached)
3474
l_fsel_attached_to_id = l_layer_id; /* the floating selection is attached to this layer */
3478
/* check for alpha channel */
3479
if(l_layer_prp_ptr->has_alpha)
3481
l_jpg_file = g_strdup_printf("%s%cla%d.jpg", l_dirname, G_DIR_SEPARATOR, (int)l_layer_prp_ptr->layer_pos);
3482
if(xjt_debug) printf("XJT-DEBUG: loading alpha-channel from file %s\n", l_jpg_file);
3484
if( xjpg_load_layer_alpha (l_jpg_file, l_image_id, l_layer_id) != 0)
3492
/* adjust offsets and other layerproperties */
3493
gimp_layer_set_offsets(l_layer_id, l_layer_prp_ptr->offx, l_layer_prp_ptr->offy);
3494
gimp_drawable_set_visible (l_layer_id, l_layer_prp_ptr->visible);
3495
gimp_drawable_set_linked (l_layer_id, l_layer_prp_ptr->linked);
3496
gimp_layer_set_lock_alpha (l_layer_id, l_layer_prp_ptr->lock_alpha);
3497
if (l_layer_prp_ptr->tattoo >= 0)
3499
gimp_drawable_set_tattoo (l_layer_id, l_layer_prp_ptr->tattoo);
3502
if (l_layer_prp_ptr->active_layer)
3504
l_active_layer_id = l_layer_id;
3507
/* Handle layer parasites */
3508
p_check_and_add_parasite (l_layer_id,
3510
l_image_prp_ptr->parasite_props,
3511
l_layer_prp_ptr->layer_pos,
3512
XJT_LAYER_PARASITE);
3515
/* search for the properties of the layermask */
3516
for (l_channel_prp_ptr = l_image_prp_ptr->mask_props;
3517
l_channel_prp_ptr != NULL;
3518
l_channel_prp_ptr = (t_channel_props *) l_channel_prp_ptr->next)
3520
if (l_channel_prp_ptr->channel_pos == l_layer_prp_ptr->layer_pos)
3522
/* layermask properties found: load the layermask */
3523
l_jpg_file = g_strdup_printf ("%s%clm%d.jpg", l_dirname, G_DIR_SEPARATOR, (int)l_layer_prp_ptr->layer_pos);
3524
if(xjt_debug) printf("XJT-DEBUG: loading layer-mask from file %s\n", l_jpg_file);
3526
l_channel_id = gimp_layer_create_mask (l_layer_id, 0 /* mask_type 0 = WHITE_MASK */ );
3528
/* load should overwrite the layer_mask with data from jpeg file */
3530
l_channel_id = xjpg_load_channel (l_jpg_file,
3533
l_channel_prp_ptr->name,
3534
l_channel_prp_ptr->opacity,
3535
l_channel_prp_ptr->color_r,
3536
l_channel_prp_ptr->color_g,
3537
l_channel_prp_ptr->color_b);
3539
if(l_channel_id >= 0)
3542
/* attach the layer_mask to the layer (with identical offsets) */
3543
gimp_layer_add_mask (l_layer_id, l_channel_id);
3545
if (l_channel_prp_ptr->floating_attached)
3547
l_fsel_attached_to_id = l_channel_id; /* the floating selection is attached to this layer_mask */
3550
if (l_channel_prp_ptr->tattoo >= 0)
3552
gimp_drawable_set_tattoo (l_channel_id,
3553
l_channel_prp_ptr->tattoo);
3556
/* gimp_layer_set_offsets(l_channel_id, l_layer_prp_ptr->offx, l_layer_prp_ptr->offy); */
3558
gimp_layer_set_apply_mask (l_layer_id, l_layer_prp_ptr->apply_mask);
3559
gimp_layer_set_edit_mask (l_layer_id, l_layer_prp_ptr->edit_mask);
3560
gimp_layer_set_show_mask (l_layer_id, l_layer_prp_ptr->show_mask);
3562
/* Handle layermask parasites */
3563
p_check_and_add_parasite (l_channel_id,
3565
l_image_prp_ptr->parasite_props,
3566
l_channel_prp_ptr->channel_pos,
3567
XJT_LAYER_MASK_PARASITE);
3571
} /* end search for layermask */
3574
/* load all channels */
3575
for (l_channel_prp_ptr = l_image_prp_ptr->channel_props;
3576
l_channel_prp_ptr != NULL;
3577
l_channel_prp_ptr = (t_channel_props *) l_channel_prp_ptr->next)
3579
l_jpg_file = g_strdup_printf ("%s%cc%d.jpg", l_dirname, G_DIR_SEPARATOR,
3580
(int) l_channel_prp_ptr->channel_pos);
3581
if (xjt_debug) printf ("XJT-DEBUG: loading channel from file %s\n",
3584
l_channel_id = xjpg_load_channel (l_jpg_file,
3587
l_channel_prp_ptr->name,
3588
l_channel_prp_ptr->opacity,
3589
l_channel_prp_ptr->color_r,
3590
l_channel_prp_ptr->color_g,
3591
l_channel_prp_ptr->color_b);
3593
g_free (l_jpg_file);
3594
if (l_channel_id < 0)
3600
/* Handle channel parasites */
3601
p_check_and_add_parasite (l_channel_id,
3603
l_image_prp_ptr->parasite_props,
3604
l_channel_prp_ptr->channel_pos,
3605
XJT_CHANNEL_PARASITE);
3607
if (l_channel_prp_ptr->tattoo >= 0)
3609
gimp_drawable_set_tattoo (l_channel_id, l_channel_prp_ptr->tattoo);
3612
if (l_channel_prp_ptr->selection)
3614
if (xjt_debug) printf ("XJT-DEBUG: SELECTION loaded channel id = %d\n",
3615
(int) l_channel_id);
3617
gimp_selection_load (l_channel_id);
3619
/* delete the channel after load into selection */
3620
gimp_drawable_delete (l_channel_id);
3624
/* add channel on top of the channelstack */
3625
gimp_image_add_channel (l_image_id, l_channel_id, 0);
3627
/* adjust offsets and other channelproperties */
3628
gimp_drawable_set_visible (l_channel_id, l_channel_prp_ptr->visible);
3629
gimp_channel_set_show_masked (l_channel_id, l_channel_prp_ptr->show_masked);
3631
if (l_channel_prp_ptr->floating_attached)
3633
l_fsel_attached_to_id = l_channel_id; /* the floating_selection is attached to this channel */
3636
if (l_channel_prp_ptr->active_channel)
3638
l_active_channel_id = l_channel_id;
3643
/* attach the floating selection... */
3644
if ((l_fsel_id >= 0) && (l_fsel_attached_to_id >= 0))
3646
if (xjt_debug) printf("XJT-DEBUG: attaching floating_selection id=%d to id %d\n",
3647
(int)l_fsel_id, (int)l_fsel_attached_to_id);
3648
if (gimp_floating_sel_attach (l_fsel_id, l_fsel_attached_to_id) < 0)
3650
/* in case of error add floating_selection like an ordinary layer
3651
* (if patches are not installed you'll get the error for sure)
3653
printf("XJT: floating_selection is added as top-layer (attach failed)\n");
3654
gimp_image_add_layer (l_image_id, l_fsel_id, 0);
3658
/* set active layer/channel */
3659
if (l_active_channel_id >= 0)
3661
if (xjt_debug) printf("SET active channel\n");
3663
gimp_image_set_active_channel (l_image_id, l_active_channel_id);
3666
if (l_active_layer_id >= 0)
3668
if (xjt_debug) printf("SET active layer\n");
3670
gimp_image_set_active_layer (l_image_id, l_active_layer_id);
3674
for (l_guide_prp_ptr = l_image_prp_ptr->guide_props;
3675
l_guide_prp_ptr != NULL;
3676
l_guide_prp_ptr = (t_guide_props *) l_guide_prp_ptr->next)
3678
if (l_guide_prp_ptr->orientation == GIMP_ORIENTATION_HORIZONTAL)
3679
gimp_image_add_hguide (l_image_id, l_guide_prp_ptr->position);
3681
gimp_image_add_vguide (l_image_id, l_guide_prp_ptr->position);
3685
if (l_image_prp_ptr->path_props)
3687
p_add_paths (l_image_id, l_image_prp_ptr->path_props);
3690
/* set tattoo_state */
3691
if (l_image_prp_ptr->tattoo_state > 0)
3693
gimp_image_set_tattoo_state (l_image_id, l_image_prp_ptr->tattoo_state);
3698
g_free (l_layers_list);
3699
g_free (l_channels_list);
3701
/* remove the temorary directory */
3702
l_cmd = g_strdup_printf ("rm -rf \"%s\"", l_dirname);
3707
g_free (l_prop_file);
3708
g_free (l_jpg_file);
3712
return l_image_id; /* all done OK */
3715
/* destroy the tmp image */
3716
gimp_image_delete (l_image_id);