~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to plug-ins/xjt/xjt.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2008-10-06 13:30:41 UTC
  • mto: This revision was merged to the branch mainline in revision 35.
  • Revision ID: james.westby@ubuntu.com-20081006133041-3panbkcanaymfsmp
Tags: upstream-2.6.0
ImportĀ upstreamĀ versionĀ 2.6.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* xjt.c
2
 
 *
3
 
 * XJT (JPEG-TAR fileformat) loading and saving file filter for GIMP
4
 
 *  -hof (Wolfgang Hofer)
5
 
 *
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.
9
 
 *
10
 
 * IMPORTANT NOTE:
11
 
 *   This plugin needs GIMP 1.1.18 or newer versions of the GIMP-core to run.
12
 
 */
13
 
 
14
 
/* GIMP - The GNU Image Manipulation Program
15
 
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
16
 
 *
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.
21
 
 *
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.
26
 
 *
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.
30
 
 */
31
 
 
32
 
/* TODO:
33
 
 *  - support user units
34
 
 *  - show continous progress while loading/saving
35
 
 */
36
 
 
37
 
/* revision history:
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
54
 
 */
55
 
 
56
 
#include "config.h"
57
 
 
58
 
#include <errno.h>
59
 
#include <stdlib.h>
60
 
#include <string.h>
61
 
#include <sys/types.h>
62
 
#include <sys/stat.h>
63
 
#include <fcntl.h>
64
 
#ifdef HAVE_UNISTD_H
65
 
#include <unistd.h>
66
 
#endif
67
 
 
68
 
#include <glib/gstdio.h>
69
 
 
70
 
#ifdef __GNUC__
71
 
#warning GIMP_DISABLE_DEPRECATED
72
 
#endif
73
 
#undef GIMP_DISABLE_DEPRECATED
74
 
 
75
 
#include <libgimp/gimp.h>
76
 
#include <libgimp/gimpui.h>
77
 
 
78
 
#include "libgimp/stdplugins-intl.h"
79
 
 
80
 
#ifdef G_OS_WIN32
81
 
#include <process.h> /* getpid() */
82
 
#endif
83
 
 
84
 
/* XJT includes */
85
 
#include "xjpeg.h"
86
 
 
87
 
#define LOAD_PROC      "file-xjt-load"
88
 
#define SAVE_PROC      "file-xjt-save"
89
 
 
90
 
#ifdef _MSC_VER
91
 
typedef int pid_t;
92
 
#endif
93
 
 
94
 
#define GIMP_XJ_IMAGE  "GIMP_XJ_IMAGE"
95
 
 
96
 
#define SCALE_WIDTH 125
97
 
 
98
 
#define XJT_ORIENTATION_HORIZONTAL 0
99
 
#define XJT_ORIENTATION_VERTICAL   1
100
 
 
101
 
       gint     xjt_debug = FALSE;
102
 
static pid_t    g_pid;
103
 
static gchar   *global_parasite_prop_lines = NULL;
104
 
static gint     global_parasite_id = 0;
105
 
 
106
 
 
107
 
/* PROPERTY enums
108
 
 *  (0-21 are ident with PropType values as used in xcf.c
109
 
 *   the rest was added for xjt
110
 
 */
111
 
typedef enum
112
 
{
113
 
  PROP_END = 0,
114
 
  PROP_COLORMAP = 1,
115
 
  PROP_ACTIVE_LAYER = 2,
116
 
  PROP_ACTIVE_CHANNEL = 3,
117
 
  PROP_SELECTION = 4,
118
 
  PROP_FLOATING_SELECTION = 5,
119
 
  PROP_OPACITY = 6,
120
 
  PROP_MODE = 7,
121
 
  PROP_VISIBLE = 8,
122
 
  PROP_LINKED = 9,
123
 
  PROP_LOCK_ALPHA = 10,
124
 
  PROP_APPLY_MASK = 11,
125
 
  PROP_EDIT_MASK = 12,
126
 
  PROP_SHOW_MASK = 13,
127
 
  PROP_SHOW_MASKED = 14,
128
 
  PROP_OFFSETS = 15,
129
 
  PROP_COLOR = 16,
130
 
  PROP_COMPRESSION = 17,
131
 
  PROP_GUIDES = 18,
132
 
  PROP_RESOLUTION = 19,
133
 
  PROP_TATTOO = 20,
134
 
  PROP_PARASITES = 21,
135
 
  PROP_UNIT = 22,
136
 
  PROP_PATHS = 23,
137
 
  PROP_USER_UNIT = 24,
138
 
 
139
 
  PROP_TATTOO_STATE = 85,
140
 
  PROP_PATH_LOCKED = 86,
141
 
  PROP_PATH_CURRENT = 87,
142
 
  PROP_PATH_TYPE = 88,
143
 
  PROP_PATH_POINTS = 89,
144
 
  PROP_NAME = 90,
145
 
  PROP_DIMENSION = 91,
146
 
  PROP_TYPE = 92,
147
 
  PROP_VERSION = 93,
148
 
  PROP_FLOATING_ATTACHED = 94,
149
 
  PROP_PARASITE_FLAGS = 95,
150
 
  PROP_GIMP_VERSION = 96,
151
 
 
152
 
  PROP_SYNTAX_ERROR = 99
153
 
} t_proptype;
154
 
 
155
 
typedef enum
156
 
{
157
 
  PTYP_NOT_SUPPORTED = 0,
158
 
  PTYP_BOOLEAN = 1,
159
 
  PTYP_INT = 2,
160
 
  PTYP_FLT = 3,
161
 
  PTYP_STRING = 4,
162
 
  PTYP_2xINT = 5,
163
 
  PTYP_3xINT = 6,
164
 
  PTYP_2xFLT = 7,
165
 
  PTYP_3xFLT = 8,
166
 
  PTYP_FLIST = 9
167
 
} t_param_typ;
168
 
 
169
 
typedef enum
170
 
{
171
 
  XJT_IMAGE_PARASITE = 0,
172
 
  XJT_LAYER_PARASITE = 1,
173
 
  XJT_LAYER_MASK_PARASITE = 2,
174
 
  XJT_CHANNEL_PARASITE = 3
175
 
} t_parasitetype;
176
 
 
177
 
typedef enum
178
 
{
179
 
  XJT_RGB = 0,
180
 
  XJT_GRAY = 1
181
 
  /* XJT_INDEXED = 2 */  /* xjt does not support indexed images */
182
 
} XJTImageBaseType;
183
 
 
184
 
typedef enum
185
 
{
186
 
  XJT_PATHTYPE_UNDEF = 0,
187
 
  XJT_PATHTYPE_BEZIER = 1
188
 
} XJTPathType;
189
 
 
190
 
typedef enum
191
 
{
192
 
  XJT_UNIT_PIXEL = 0,
193
 
  XJT_UNIT_INCH  = 1,
194
 
  XJT_UNIT_MM    = 2,
195
 
  XJT_UNIT_POINT = 3,
196
 
  XJT_UNIT_PICA  = 4
197
 
} XJTUnitType;
198
 
 
199
 
typedef enum
200
 
{
201
 
  XJT_NORMAL_MODE = 0,
202
 
  XJT_DISSOLVE_MODE = 1,
203
 
  XJT_BEHIND_MODE = 2,
204
 
  XJT_MULTIPLY_MODE = 3,
205
 
  XJT_SCREEN_MODE = 4,
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,
212
 
  XJT_HUE_MODE = 11,
213
 
  XJT_SATURATION_MODE = 12,
214
 
  XJT_COLOR_MODE = 13,
215
 
  XJT_VALUE_MODE = 14,
216
 
  XJT_DIVIDE_MODE = 15,
217
 
  XJT_DODGE_MODE = 16,
218
 
  XJT_BURN_MODE = 17,
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;
225
 
 
226
 
typedef struct
227
 
{
228
 
  t_proptype   prop_id;
229
 
  gchar       *prop_mnemonic;
230
 
  t_param_typ  param_typ;
231
 
  gdouble      default_val1;
232
 
  gdouble      default_val2;
233
 
  gdouble      default_val3;
234
 
} t_prop_table;
235
 
 
236
 
 
237
 
typedef struct
238
 
{
239
 
  gint32   int_val1;
240
 
  gint32   int_val2;
241
 
  gint32   int_val3;
242
 
  gdouble  flt_val1;
243
 
  gdouble  flt_val2;
244
 
  gdouble  flt_val3;
245
 
  gint32   num_fvals;
246
 
  gdouble *flt_val_list;
247
 
  gchar   *string_val;
248
 
}  t_param_prop;
249
 
 
250
 
typedef struct
251
 
{
252
 
  t_parasitetype  parasite_type;
253
 
  gint32          parasite_id;
254
 
  gint32          flags;
255
 
  gchar          *name;
256
 
  gint32          obj_pos;
257
 
  void           *next;
258
 
} t_parasite_props;
259
 
 
260
 
typedef struct
261
 
{
262
 
  gint32          path_type;
263
 
  gint32          path_locked;
264
 
  gint32          path_closed;
265
 
  gint32          current_flag;
266
 
  gint32          tattoo;
267
 
  gchar          *name;
268
 
  gint32          num_points;
269
 
  gdouble        *path_points;
270
 
  void           *next;
271
 
} t_path_props;
272
 
 
273
 
typedef struct
274
 
{
275
 
  gint     active_channel;
276
 
  gint     selection;
277
 
  gint     floating_attached;
278
 
  gdouble  opacity;
279
 
  gint     visible;
280
 
  gint     show_masked;
281
 
  guchar   color_r;
282
 
  guchar   color_g;
283
 
  guchar   color_b;
284
 
  gint32   offx;            /* do channels have offset ?? */
285
 
  gint32   offy;
286
 
  gchar   *name;
287
 
  gint32   tattoo;
288
 
 
289
 
  gint     channel_pos;
290
 
  void    *next;
291
 
}  t_channel_props;
292
 
 
293
 
typedef struct
294
 
{
295
 
  gint     active_layer;
296
 
  gint     floating_selection;
297
 
  gint     floating_attached;
298
 
  gdouble  opacity;
299
 
  gint32   mode;
300
 
  gint     visible;
301
 
  gint     linked;
302
 
  gint     lock_alpha;
303
 
  gint     apply_mask;
304
 
  gint     edit_mask;
305
 
  gint     show_mask;
306
 
  gint32   offx;
307
 
  gint32   offy;
308
 
  gchar   *name;
309
 
  gint32   tattoo;
310
 
 
311
 
  gint     layer_pos;
312
 
  gint     has_alpha;
313
 
  void    *next;
314
 
} t_layer_props;
315
 
 
316
 
 
317
 
typedef struct
318
 
{
319
 
  gint32   position;
320
 
  gint8    orientation;
321
 
  void    *next;
322
 
}  t_guide_props;
323
 
 
324
 
 
325
 
typedef struct
326
 
{
327
 
  gchar            *version;
328
 
  gint              gimp_major_version;
329
 
  gint              gimp_minor_version;
330
 
  gint              gimp_micro_version;
331
 
  GimpImageBaseType        image_type;
332
 
  gint              image_width;
333
 
  gint              image_height;
334
 
  gfloat            xresolution;
335
 
  gfloat            yresolution;
336
 
  GimpUnit          unit;
337
 
  gint32            tattoo;
338
 
  gint32            tattoo_state;
339
 
  gint              n_layers;
340
 
  gint              n_channels;
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;
347
 
} t_image_props;
348
 
 
349
 
 
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 } ,
377
 
 
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 }
389
 
};
390
 
 
391
 
 
392
 
/* Declare local functions.
393
 
 */
394
 
static void      query            (void);
395
 
static void      run              (const gchar      *name,
396
 
                                   gint              nparams,
397
 
                                   const GimpParam  *param,
398
 
                                   gint             *nreturn_vals,
399
 
                                   GimpParam       **return_vals);
400
 
 
401
 
static gint32    load_xjt_image   (const gchar      *filename);
402
 
static gint      save_xjt_image   (const gchar      *filename,
403
 
                                   gint32            image_ID,
404
 
                                   gint32            drawable_ID);
405
 
 
406
 
static gboolean  save_dialog      (void);
407
 
 
408
 
 
409
 
const GimpPlugInInfo PLUG_IN_INFO =
410
 
{
411
 
  NULL,  /* init_proc  */
412
 
  NULL,  /* quit_proc  */
413
 
  query, /* query_proc */
414
 
  run,   /* run_proc   */
415
 
};
416
 
 
417
 
static t_JpegSaveVals jsvals =
418
 
{
419
 
  0.75,  /*  quality  */
420
 
  0.0,   /*  smoothing  */
421
 
  1,     /*  optimize  */
422
 
  0      /*  clr_transparent */
423
 
};
424
 
 
425
 
static gint
426
 
p_invert(gint value)
427
 
{
428
 
  return (value) ? FALSE : TRUE;
429
 
}
430
 
 
431
 
static
432
 
int p_system(const gchar *cmd)
433
 
{
434
 
  int l_rc;
435
 
  int l_rc2;
436
 
 
437
 
  if(xjt_debug) printf("CMD: %s\n", cmd);
438
 
 
439
 
  l_rc = system(cmd);
440
 
  if(l_rc != 0)
441
 
  {
442
 
     /* Shift 8 Bits gets Retcode of the executed Program */
443
 
     l_rc2 = l_rc >> 8;
444
 
     g_printerr ("ERROR system: %s\nreturncodes %d %d", cmd, l_rc, l_rc2);
445
 
     return -1;
446
 
  }
447
 
  return 0;
448
 
}
449
 
 
450
 
MAIN ()
451
 
 
452
 
static void
453
 
query (void)
454
 
{
455
 
  static const GimpParamDef load_args[] =
456
 
  {
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" },
460
 
  };
461
 
  static const GimpParamDef load_return_vals[] =
462
 
  {
463
 
    { GIMP_PDB_IMAGE, "image", "Output image" },
464
 
  };
465
 
 
466
 
  static const GimpParamDef save_args[] =
467
 
  {
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" },
477
 
  };
478
 
 
479
 
  gimp_install_procedure (LOAD_PROC,
480
 
                          "loads files of the jpeg-tar file format",
481
 
                          "loads files of the jpeg-tar file format",
482
 
                          "Wolfgang Hofer",
483
 
                          "Wolfgang Hofer",
484
 
                          "2000-Mar-07",
485
 
                          N_("GIMP compressed XJT image"),
486
 
                          NULL,
487
 
                          GIMP_PLUGIN,
488
 
                          G_N_ELEMENTS (load_args),
489
 
                          G_N_ELEMENTS (load_return_vals),
490
 
                          load_args, load_return_vals);
491
 
 
492
 
  gimp_register_magic_load_handler (LOAD_PROC,
493
 
                                    "xjt,xjtgz,xjtbz2",
494
 
                                    "",
495
 
                                    "");
496
 
 
497
 
  gimp_install_procedure (SAVE_PROC,
498
 
                          "saves files in the jpeg-tar file format",
499
 
                          "saves files in the jpeg-tar file format",
500
 
                          "Wolfgang Hofer",
501
 
                          "Wolfgang Hofer",
502
 
                          "2000-Mar-07",
503
 
                          N_("GIMP compressed XJT image"),
504
 
                          "RGB*, GRAY*",
505
 
                          GIMP_PLUGIN,
506
 
                          G_N_ELEMENTS (save_args), 0,
507
 
                          save_args, NULL);
508
 
 
509
 
  gimp_register_save_handler (SAVE_PROC, "xjt,xjtgz,xjtbz2", "");
510
 
}
511
 
 
512
 
static void
513
 
run (const gchar      *name,
514
 
     gint              nparams,
515
 
     const GimpParam  *param,
516
 
     gint             *nreturn_vals,
517
 
     GimpParam       **return_vals)
518
 
{
519
 
  static GimpParam values[2];
520
 
  GimpRunMode  run_mode;
521
 
  GimpPDBStatusType   status = GIMP_PDB_SUCCESS;
522
 
  gint32        image_ID;
523
 
  gchar        *l_env;
524
 
 
525
 
  g_pid = getpid ();
526
 
  xjt_debug = FALSE;
527
 
 
528
 
  INIT_I18N ();
529
 
 
530
 
  l_env = getenv("XJT_DEBUG");
531
 
  if(l_env != NULL)
532
 
    {
533
 
      if((*l_env != 'n') && (*l_env != 'N')) xjt_debug = TRUE;
534
 
    }
535
 
 
536
 
  run_mode = param[0].data.d_int32;
537
 
 
538
 
  *nreturn_vals = 1;
539
 
  *return_vals  = values;
540
 
  values[0].type          = GIMP_PDB_STATUS;
541
 
  values[0].data.d_status = GIMP_PDB_EXECUTION_ERROR;
542
 
 
543
 
  if (strcmp (name, LOAD_PROC) == 0)
544
 
    {
545
 
      image_ID = load_xjt_image (param[1].data.d_string);
546
 
 
547
 
      if (image_ID != -1)
548
 
        {
549
 
          *nreturn_vals = 2;
550
 
          values[1].type         = GIMP_PDB_IMAGE;
551
 
          values[1].data.d_image = image_ID;
552
 
        }
553
 
      else
554
 
        {
555
 
          status = GIMP_PDB_EXECUTION_ERROR;
556
 
        }
557
 
    }
558
 
  else if (strcmp (name, SAVE_PROC) == 0)
559
 
    {
560
 
      switch (run_mode)
561
 
        {
562
 
        case GIMP_RUN_INTERACTIVE:
563
 
          /*  Possibly retrieve data  */
564
 
          gimp_get_data (SAVE_PROC, &jsvals);
565
 
 
566
 
          /*  First acquire information with a dialog  */
567
 
          if (! save_dialog ())
568
 
            {
569
 
              status = GIMP_PDB_CANCEL;
570
 
            }
571
 
          break;
572
 
 
573
 
        case GIMP_RUN_NONINTERACTIVE:
574
 
          /*  Make sure all the arguments are there!  */
575
 
          if (nparams != 8)
576
 
            {
577
 
              status = GIMP_PDB_CALLING_ERROR;
578
 
            }
579
 
          else
580
 
            {
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;
585
 
 
586
 
              if (jsvals.quality < 0.0 || jsvals.quality > 1.0)
587
 
                {
588
 
                  status = GIMP_PDB_CALLING_ERROR;
589
 
                }
590
 
              else if (jsvals.smoothing < 0.0 || jsvals.smoothing > 1.0)
591
 
                {
592
 
                  status = GIMP_PDB_CALLING_ERROR;
593
 
                }
594
 
            }
595
 
          break;
596
 
 
597
 
        case GIMP_RUN_WITH_LAST_VALS:
598
 
          /*  Possibly retrieve data  */
599
 
          gimp_get_data (SAVE_PROC, &jsvals);
600
 
          break;
601
 
 
602
 
        default:
603
 
          break;
604
 
        }
605
 
 
606
 
      if (status == GIMP_PDB_SUCCESS)
607
 
        {
608
 
          if (save_xjt_image (param[3].data.d_string,
609
 
                              param[1].data.d_int32,
610
 
                              param[2].data.d_int32) <0)
611
 
            {
612
 
              status = GIMP_PDB_EXECUTION_ERROR;
613
 
            }
614
 
          else
615
 
            {
616
 
              /*  Store mvals data  */
617
 
              gimp_set_data (SAVE_PROC, &jsvals, sizeof (t_JpegSaveVals));
618
 
            }
619
 
        }
620
 
    }
621
 
  else
622
 
    {
623
 
      status = GIMP_PDB_CALLING_ERROR;
624
 
    }
625
 
 
626
 
  values[0].data.d_status = status;
627
 
}
628
 
 
629
 
 
630
 
/* ------------------------
631
 
 * p_my_ascii_strtod
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
640
 
 */
641
 
static gdouble
642
 
p_my_ascii_strtod (gchar  *nptr,
643
 
                   gchar **endptr)
644
 
{
645
 
   gint ii;
646
 
   gint ic;
647
 
   gdouble l_rc;
648
 
 
649
 
   /* check for comma (is a terminating character for the NON locale float string)
650
 
    */
651
 
   ii=0;
652
 
   ic = -1;
653
 
   while (nptr)
654
 
   {
655
 
     if (nptr[ii] == ',')
656
 
     {
657
 
       ic = ii;
658
 
       nptr[ii] = '\0';  /* temporary use 0 as terminator for the call of g_ascii_strtod */
659
 
       break;
660
 
     }
661
 
     if ((nptr[ii] == '\0')
662
 
     ||  (nptr[ii] == ' ')
663
 
     ||  (nptr[ii] == '\n'))
664
 
     {
665
 
       break;
666
 
     }
667
 
     ii++;
668
 
   }
669
 
 
670
 
   l_rc = g_ascii_strtod(nptr, endptr);
671
 
 
672
 
   if (ic >= 0)
673
 
   {
674
 
       nptr[ii] = ',';   /* restore the comma */
675
 
   }
676
 
 
677
 
   return l_rc;
678
 
}  /* end p_my_ascii_strtod */
679
 
 
680
 
/* -- type transformer routines XJT -- GIMP internal enums ----------------- */
681
 
 
682
 
static gint32
683
 
p_to_GimpOrientation(gint32 orientation)
684
 
{
685
 
  return (orientation == XJT_ORIENTATION_VERTICAL)
686
 
    ? GIMP_ORIENTATION_VERTICAL : GIMP_ORIENTATION_HORIZONTAL;
687
 
}
688
 
static gint32
689
 
p_to_XJTOrientation(gint32 orientation)
690
 
{
691
 
  return (orientation == GIMP_ORIENTATION_VERTICAL)
692
 
    ? XJT_ORIENTATION_VERTICAL : XJT_ORIENTATION_HORIZONTAL;
693
 
}
694
 
 
695
 
static GimpLayerModeEffects
696
 
p_to_GimpLayerModeEffects(XJTLayerModeEffects intype)
697
 
{
698
 
  switch(intype)
699
 
  {
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;
723
 
  }
724
 
  printf (_("XJT file contains unknown layermode %d"), (int)intype);
725
 
  if((gint32)intype > (gint32)XJT_DIVIDE_MODE)
726
 
  {
727
 
    return (GimpLayerModeEffects)intype;
728
 
  }
729
 
  return GIMP_NORMAL_MODE;
730
 
}
731
 
 
732
 
static XJTLayerModeEffects
733
 
p_to_XJTLayerModeEffects(GimpLayerModeEffects intype)
734
 
{
735
 
  switch(intype)
736
 
  {
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;
760
 
  }
761
 
  printf (_("Warning: unsupported layermode %d saved to XJT"), (int)intype);
762
 
  if ((gint32)intype > (gint32)XJT_DIVIDE_MODE)
763
 
  {
764
 
    return (XJTLayerModeEffects)intype;
765
 
  }
766
 
  return XJT_NORMAL_MODE;
767
 
}
768
 
 
769
 
static gint32
770
 
p_to_GimpPathType(XJTPathType intype)
771
 
{
772
 
  switch(intype)
773
 
  {
774
 
    case XJT_PATHTYPE_UNDEF:      return 0;
775
 
    case XJT_PATHTYPE_BEZIER:     return 1;
776
 
  }
777
 
  printf (_("XJT file contains unknown pathtype %d"), (int)intype);
778
 
  if ((gint32)intype > (gint32)XJT_PATHTYPE_BEZIER)
779
 
  {
780
 
    return (gint32)intype;
781
 
  }
782
 
  return 0;
783
 
}
784
 
 
785
 
static XJTPathType
786
 
p_to_XJTPathType(gint32 intype)
787
 
{
788
 
  switch(intype)
789
 
  {
790
 
    case 0:      return XJT_PATHTYPE_UNDEF;
791
 
    case 1:      return XJT_PATHTYPE_BEZIER;
792
 
  }
793
 
  printf (_("Warning: unsupported pathtype %d saved to XJT"), (int)intype);
794
 
  if((gint32)intype > (gint32)XJT_PATHTYPE_BEZIER)
795
 
  {
796
 
    return((XJTPathType)intype);
797
 
  }
798
 
  return(XJT_PATHTYPE_UNDEF);
799
 
}
800
 
 
801
 
static GimpUnit
802
 
p_to_GimpUnit(XJTUnitType intype)
803
 
{
804
 
  switch(intype)
805
 
  {
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);
811
 
  }
812
 
  printf (_("XJT file contains unknown unittype %d"), (int)intype);
813
 
  if((gint32)intype > (gint32)XJT_UNIT_PICA)
814
 
  {
815
 
    return((GimpUnit)intype);
816
 
  }
817
 
  return(GIMP_UNIT_PIXEL);
818
 
}
819
 
 
820
 
static XJTUnitType
821
 
p_to_XJTUnitType(GimpUnit intype)
822
 
{
823
 
  switch(intype)
824
 
  {
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;
832
 
  }
833
 
  printf (_("Warning: unsupported unittype %d saved to XJT"), (int)intype);
834
 
  if((gint32)intype > (gint32)XJT_UNIT_PICA)
835
 
  {
836
 
    return((XJTUnitType)intype);
837
 
  }
838
 
  return(XJT_UNIT_PIXEL);
839
 
}
840
 
 
841
 
/* ---------------------- SAVE DIALOG procedures  -------------------------- */
842
 
 
843
 
static gboolean
844
 
save_dialog (void)
845
 
{
846
 
  GtkWidget *dlg;
847
 
  GtkWidget *table;
848
 
  GtkWidget *toggle;
849
 
  GtkObject *scale_data;
850
 
  gboolean   run;
851
 
 
852
 
  gimp_ui_init ("xjt", FALSE);
853
 
 
854
 
  dlg = gimp_dialog_new (_("Save as XJT"), "xjt",
855
 
                         NULL, 0,
856
 
                         gimp_standard_help_func, "file-xjt-save",
857
 
 
858
 
                         GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
859
 
                         GTK_STOCK_SAVE,   GTK_RESPONSE_OK,
860
 
 
861
 
                         NULL);
862
 
 
863
 
  gtk_dialog_set_alternative_button_order (GTK_DIALOG (dlg),
864
 
                                           GTK_RESPONSE_OK,
865
 
                                           GTK_RESPONSE_CANCEL,
866
 
                                           -1);
867
 
 
868
 
  gimp_window_set_transient (GTK_WINDOW (dlg));
869
 
 
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);
876
 
 
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,
880
 
                    GTK_FILL, 0, 0, 0);
881
 
  gtk_widget_show (toggle);
882
 
 
883
 
  g_signal_connect (toggle, "toggled",
884
 
                    G_CALLBACK (gimp_toggle_button_update),
885
 
                    &jsvals.optimize);
886
 
 
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,
891
 
                    GTK_FILL, 0, 0, 0);
892
 
  gtk_widget_show (toggle);
893
 
 
894
 
  g_signal_connect (toggle, "toggled",
895
 
                    G_CALLBACK (gimp_toggle_button_update),
896
 
                    &jsvals.clr_transparent);
897
 
 
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,
901
 
                                     TRUE, 0, 0,
902
 
                                     NULL, NULL);
903
 
  g_signal_connect (scale_data, "value-changed",
904
 
                    G_CALLBACK (gimp_double_adjustment_update),
905
 
                    &jsvals.quality);
906
 
 
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,
910
 
                                     TRUE, 0, 0,
911
 
                                     NULL, NULL);
912
 
  g_signal_connect (scale_data, "value-changed",
913
 
                    G_CALLBACK (gimp_double_adjustment_update),
914
 
                    &jsvals.smoothing);
915
 
 
916
 
  gtk_widget_show (dlg);
917
 
 
918
 
  run = (gimp_dialog_run (GIMP_DIALOG (dlg)) == GTK_RESPONSE_OK);
919
 
 
920
 
  gtk_widget_destroy (dlg);
921
 
 
922
 
  return run;
923
 
}
924
 
 
925
 
/* ---------------------- SAVE WORKER procedures  -------------------------- */
926
 
 
927
 
/* ============================================================================
928
 
 * p_get_property_index
929
 
 *   get index in g_prop_table by proptype (id)
930
 
 * ============================================================================
931
 
 */
932
 
 
933
 
static int
934
 
p_get_property_index(t_proptype proptype)
935
 
{
936
 
  int l_idx;
937
 
 
938
 
  for (l_idx = 0; l_idx < PROP_TABLE_ENTRIES; l_idx++)
939
 
    {
940
 
      if (g_prop_table[l_idx].prop_id == proptype)
941
 
        {
942
 
          return l_idx;
943
 
        }
944
 
    }
945
 
  return 0;  /* index of PROP_END -- not supported */
946
 
}       /* end p_get_property_index */
947
 
 
948
 
/* ============================================================================
949
 
 * p_float_to_str
950
 
 *   create string from float.
951
 
 * ============================================================================
952
 
 */
953
 
static gchar *
954
 
p_float_to_str(gdouble  flt_val)
955
 
{
956
 
   gchar l_dbl_str[G_ASCII_DTOSTR_BUF_SIZE];
957
 
   gchar *l_str;
958
 
   gint  l_idx;
959
 
 
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
964
 
                  ,"%.5f"
965
 
                  ,flt_val
966
 
                  );
967
 
   l_str = g_strdup(l_dbl_str);
968
 
 
969
 
   /* delete trailing '0' and '.' characters */
970
 
   l_idx = strlen(l_str) -1;
971
 
   while(l_idx > 0)
972
 
   {
973
 
     if(l_str[l_idx] != '0')
974
 
     {
975
 
       break;
976
 
     }
977
 
     l_str[l_idx] = '\0';
978
 
     l_idx--;
979
 
   }
980
 
   if(l_str[l_idx] == '.')
981
 
   {
982
 
     l_str[l_idx] = '\0';
983
 
   }
984
 
   return(l_str);
985
 
}
986
 
 
987
 
/* ============================================================================
988
 
 * p_namedup
989
 
 *   copy name and make sure that double quote backslash and newline
990
 
 *   characters are escaped by a backslash
991
 
 * ============================================================================
992
 
 */
993
 
static gchar *
994
 
p_namedup(const gchar *name)
995
 
{
996
 
  const gchar *l_str;
997
 
  gchar       *l_name;
998
 
  gchar       *l_ptr;
999
 
  gint         l_len;
1000
 
 
1001
 
  l_str = name;
1002
 
  l_len = 0;
1003
 
  while(*l_str != '\0')
1004
 
  {
1005
 
       if((*l_str == '\"')
1006
 
       || (*l_str == '\n')
1007
 
       || (*l_str == '\\'))
1008
 
       {
1009
 
         l_len++;
1010
 
       }
1011
 
       l_str++;
1012
 
       l_len++;
1013
 
  }
1014
 
 
1015
 
  l_name = g_malloc(l_len+2);
1016
 
  l_str = name;
1017
 
  l_ptr = l_name;
1018
 
  while(*l_str != '\0')
1019
 
  {
1020
 
       if((*l_str == '\"')
1021
 
       || (*l_str == '\n')
1022
 
       || (*l_str == '\\'))
1023
 
       {
1024
 
         *l_ptr = '\\';
1025
 
         l_ptr++;
1026
 
         if(*l_str == '\n') { *l_ptr = 'n'; }
1027
 
         else               { *l_ptr = *l_str; }
1028
 
       }
1029
 
       else
1030
 
       {
1031
 
         *l_ptr = *l_str;
1032
 
       }
1033
 
       l_ptr++;
1034
 
       l_str++;
1035
 
  }
1036
 
  *l_ptr = '\0';
1037
 
  return(l_name);
1038
 
}
1039
 
 
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
1045
 
 *
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
 
 * ============================================================================
1050
 
 */
1051
 
 
1052
 
static gchar *
1053
 
p_write_prop_string(t_proptype proptype, t_param_prop *param, gint wr_all_prp)
1054
 
{
1055
 
  int l_prop_idx;
1056
 
  int l_idp;
1057
 
  gchar *l_f1;
1058
 
  gchar *l_f2;
1059
 
  gchar *l_f3;
1060
 
  gchar *l_str;
1061
 
  gchar *buffer;
1062
 
 
1063
 
  buffer = NULL;
1064
 
  l_prop_idx = p_get_property_index(proptype);
1065
 
 
1066
 
  switch (g_prop_table[l_prop_idx].param_typ)
1067
 
  {
1068
 
     case PTYP_BOOLEAN:
1069
 
         /* boolean properties are written if they are not FALSE */
1070
 
         if(param->int_val1)
1071
 
         {
1072
 
            buffer = g_strdup_printf(" %s", g_prop_table[l_prop_idx].prop_mnemonic);
1073
 
         }
1074
 
         else
1075
 
         {
1076
 
           if(wr_all_prp)
1077
 
           {
1078
 
              buffer = g_strdup_printf(" %s!", g_prop_table[l_prop_idx].prop_mnemonic);
1079
 
           }
1080
 
         }
1081
 
         break;
1082
 
     case PTYP_INT:
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)
1085
 
         || (wr_all_prp))
1086
 
         {
1087
 
           buffer = g_strdup_printf(" %s:%d", g_prop_table[l_prop_idx].prop_mnemonic,
1088
 
                                 (int)param->int_val1);
1089
 
         }
1090
 
         break;
1091
 
     case PTYP_FLT:
1092
 
         if((param->flt_val1 != g_prop_table[l_prop_idx].default_val1)
1093
 
         || (wr_all_prp))
1094
 
         {
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);
1097
 
           g_free(l_f1);
1098
 
         }
1099
 
         break;
1100
 
     case PTYP_2xFLT:
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)
1103
 
         || (wr_all_prp))
1104
 
         {
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);
1108
 
           g_free(l_f1);
1109
 
           g_free(l_f2);
1110
 
         }
1111
 
         break;
1112
 
     case PTYP_3xFLT:
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)
1116
 
         || (wr_all_prp))
1117
 
         {
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);
1122
 
           g_free(l_f1);
1123
 
           g_free(l_f2);
1124
 
           g_free(l_f3);
1125
 
         }
1126
 
         break;
1127
 
     case PTYP_FLIST:
1128
 
         if(param->num_fvals > 0)
1129
 
         {
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);
1132
 
           g_free(l_f1);
1133
 
           for(l_idp = 1; l_idp < param->num_fvals; l_idp++)
1134
 
           {
1135
 
              l_f1 = p_float_to_str(param->flt_val_list[l_idp]);
1136
 
              l_str = g_strdup_printf("%s,%s", buffer, l_f1);
1137
 
              g_free(buffer);
1138
 
              buffer = l_str;
1139
 
              g_free(l_f1);
1140
 
           }
1141
 
         }
1142
 
         break;
1143
 
     case PTYP_STRING:
1144
 
         if(param->string_val != NULL)
1145
 
         {
1146
 
           if((*param->string_val != '\0')
1147
 
           || (wr_all_prp))
1148
 
           {
1149
 
              l_str = p_namedup(param->string_val);
1150
 
              if(l_str)
1151
 
              {
1152
 
                buffer = g_strdup_printf(" %s:\"%s\"", g_prop_table[l_prop_idx].prop_mnemonic, l_str);
1153
 
                g_free(l_str);
1154
 
              }
1155
 
           }
1156
 
         }
1157
 
         break;
1158
 
     case PTYP_2xINT:
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)
1161
 
         || (wr_all_prp))
1162
 
         {
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);
1165
 
         }
1166
 
         break;
1167
 
      case PTYP_3xINT:
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)
1171
 
         || (wr_all_prp))
1172
 
         {
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);
1177
 
         }
1178
 
         break;
1179
 
    default:  /*  PTYP_NOT_SUPPORTED */
1180
 
         break;
1181
 
  }
1182
 
 
1183
 
  if(buffer == NULL)
1184
 
  {
1185
 
    buffer = g_strdup("\0");
1186
 
  }
1187
 
  return (buffer);
1188
 
}       /* end p_write_prop_string */
1189
 
 
1190
 
/* ============================================================================
1191
 
 * p_write_prop
1192
 
 *   write out the property mnemonic to file
1193
 
 *   and parameter(s) according to the property type
1194
 
 *
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
 
 * ============================================================================
1199
 
 */
1200
 
 
1201
 
static void
1202
 
p_write_prop(FILE *fp, t_proptype proptype, t_param_prop *param, gint wr_all_prp)
1203
 
{
1204
 
  gchar    *l_buff;
1205
 
  l_buff = p_write_prop_string(proptype, param, wr_all_prp);
1206
 
 
1207
 
  if (l_buff[0] != '\0')
1208
 
    {
1209
 
      fprintf(fp, "%s", l_buff);
1210
 
    }
1211
 
  g_free(l_buff);
1212
 
}       /* end p_write_prop */
1213
 
 
1214
 
 
1215
 
/* ============================================================================
1216
 
 * p_write_parasite
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
 
 * ============================================================================
1222
 
 */
1223
 
 
1224
 
static gint
1225
 
p_write_parasite(const gchar  *dirname,
1226
 
                 FILE         *fp,
1227
 
                 GimpParasite *parasite,
1228
 
                 gint          wr_all_prp)
1229
 
{
1230
 
  gchar *l_new_parasite_prop_lines;
1231
 
  gchar *l_parasite_buff;
1232
 
  gchar *l_parasite_file;
1233
 
  gchar *l_buff;
1234
 
  gchar *l_buff2;
1235
 
  FILE *l_fp_pte;
1236
 
  t_param_prop   l_param;
1237
 
 
1238
 
  if(parasite->flags & GIMP_PARASITE_PERSISTENT)  /* check if GimpParasite should be saved */
1239
 
  {
1240
 
     global_parasite_id++;
1241
 
 
1242
 
     l_param.int_val1 = global_parasite_id;
1243
 
     p_write_prop (fp, PROP_PARASITES, &l_param, TRUE);
1244
 
 
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)
1249
 
      */
1250
 
     l_param.string_val = parasite->name;
1251
 
     l_buff = p_write_prop_string(PROP_NAME, &l_param, wr_all_prp);
1252
 
 
1253
 
     l_param.int_val1 = parasite->flags;
1254
 
     l_buff2 = p_write_prop_string(PROP_PARASITE_FLAGS, &l_param, wr_all_prp);
1255
 
 
1256
 
     l_parasite_buff = g_strdup_printf("p%d%s%s\n"
1257
 
                                       , (int)global_parasite_id
1258
 
                                       , l_buff
1259
 
                                       , l_buff2);
1260
 
     g_free(l_buff);
1261
 
     g_free(l_buff2);
1262
 
 
1263
 
     if (global_parasite_prop_lines == NULL)
1264
 
     {
1265
 
       global_parasite_prop_lines = g_strdup(l_parasite_buff);
1266
 
     }
1267
 
     else
1268
 
     {
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;
1272
 
     }
1273
 
     g_free(l_parasite_buff);
1274
 
 
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)
1279
 
     {
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);
1283
 
       return -1;
1284
 
     }
1285
 
     else
1286
 
     {
1287
 
       fwrite(parasite->data, parasite->size, 1, l_fp_pte);
1288
 
       fclose(l_fp_pte);
1289
 
       g_free(l_parasite_file);
1290
 
     }
1291
 
  }
1292
 
  return 0;
1293
 
}
1294
 
 
1295
 
static void
1296
 
p_write_image_paths(FILE *fp, gint32 image_id, gint wr_all_prp)
1297
 
{
1298
 
  gint32     l_idx;
1299
 
  gchar    **l_path_names = NULL;
1300
 
  gchar     *l_current_pathname = NULL;
1301
 
  gint32     l_num_paths = 0;
1302
 
  gdouble   *l_path_points;
1303
 
  gint32     l_path_type;
1304
 
  gint32     l_path_closed;
1305
 
  gint32     l_num_points = 0;
1306
 
  t_param_prop   l_param;
1307
 
 
1308
 
  l_path_names = gimp_path_list(image_id, &l_num_paths);
1309
 
  if(l_path_names == NULL) return;
1310
 
 
1311
 
  l_current_pathname = gimp_path_get_current(image_id);
1312
 
 
1313
 
  for(l_idx = 0; l_idx < l_num_paths; l_idx++)
1314
 
  {
1315
 
    if(xjt_debug) printf("p_write_image_paths NAME:%s:\n",  l_path_names[l_idx]);
1316
 
 
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);
1319
 
    if (l_path_points)
1320
 
    {
1321
 
       /* write PATH line identifier */
1322
 
      fprintf(fp, "PATH");
1323
 
 
1324
 
      l_param.int_val1 = p_to_XJTPathType(l_path_type);
1325
 
      p_write_prop (fp, PROP_PATH_TYPE, &l_param, wr_all_prp);
1326
 
 
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);
1329
 
 
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);
1332
 
 
1333
 
      l_param.string_val = l_path_names[l_idx];
1334
 
      p_write_prop (fp, PROP_NAME, &l_param, wr_all_prp);
1335
 
 
1336
 
      /* current path flag */
1337
 
      l_param.int_val1 = FALSE;
1338
 
      if(l_current_pathname)
1339
 
      {
1340
 
        if(strcmp(l_current_pathname, l_path_names[l_idx]) == 0)
1341
 
        {
1342
 
           l_param.int_val1 = TRUE;
1343
 
           p_write_prop (fp, PROP_PATH_CURRENT, &l_param, wr_all_prp);
1344
 
        }
1345
 
      }
1346
 
 
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);
1350
 
 
1351
 
      fprintf(fp, "\n");
1352
 
      g_free(l_path_points);
1353
 
    }
1354
 
  }
1355
 
 
1356
 
  g_free(l_current_pathname);
1357
 
  g_free(l_path_names);
1358
 
}
1359
 
 
1360
 
static void
1361
 
p_write_image_parasites(const gchar *dirname,
1362
 
                        FILE        *fp,
1363
 
                        gint32       image_id,
1364
 
                        gint         wr_all_prp)
1365
 
{
1366
 
  GimpParasite  *l_parasite;
1367
 
  gint32         l_idx;
1368
 
  gchar        **l_parasite_names = NULL;
1369
 
  gint32         l_num_parasites = 0;
1370
 
 
1371
 
  if (!gimp_image_parasite_list (image_id, &l_num_parasites, &l_parasite_names))
1372
 
    return;
1373
 
 
1374
 
  for(l_idx = 0; l_idx < l_num_parasites; l_idx++)
1375
 
  {
1376
 
    l_parasite = gimp_image_parasite_find(image_id, l_parasite_names[l_idx]);
1377
 
    if(l_parasite)
1378
 
    {
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);
1381
 
    }
1382
 
  }
1383
 
  g_free(l_parasite_names);
1384
 
}
1385
 
 
1386
 
static void
1387
 
p_write_drawable_parasites (const gchar *dirname,
1388
 
                            FILE        *fp,
1389
 
                            gint32       drawable_id,
1390
 
                            gint         wr_all_prp)
1391
 
{
1392
 
  GimpParasite  *l_parasite;
1393
 
  gint32         l_idx;
1394
 
  gchar        **l_parasite_names = NULL;
1395
 
  gint32         l_num_parasites = 0;
1396
 
 
1397
 
  if (!gimp_drawable_parasite_list (drawable_id, &l_num_parasites, &l_parasite_names))
1398
 
    return;
1399
 
 
1400
 
  for(l_idx = 0; l_idx < l_num_parasites; l_idx++)
1401
 
  {
1402
 
    l_parasite = gimp_drawable_parasite_find(drawable_id, l_parasite_names[l_idx]);
1403
 
    if(l_parasite)
1404
 
    {
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);
1407
 
    }
1408
 
  }
1409
 
  g_free(l_parasite_names);
1410
 
}
1411
 
 
1412
 
/* ============================================================================
1413
 
 * p_write_layer_prp
1414
 
 *   write out all properties of the given layer
1415
 
 * ============================================================================
1416
 
 */
1417
 
 
1418
 
static void
1419
 
p_write_layer_prp(const gchar *dirname,
1420
 
                  FILE        *fp,
1421
 
                  const gchar *layer_shortname,
1422
 
                  gint32       image_id,
1423
 
                  gint32       layer_id,
1424
 
                  gint         wr_all_prp)
1425
 
{
1426
 
  t_param_prop   l_param;
1427
 
  gint           l_ofsx, l_ofsy;
1428
 
 
1429
 
  fprintf(fp, "%s", layer_shortname);
1430
 
 
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);
1433
 
 
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);
1436
 
 
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);
1440
 
 
1441
 
  l_param.flt_val1 = gimp_layer_get_opacity(layer_id);
1442
 
  p_write_prop (fp, PROP_OPACITY, &l_param, wr_all_prp);
1443
 
 
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);
1446
 
 
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);
1449
 
 
1450
 
  l_param.int_val1 = gimp_drawable_get_linked (layer_id);
1451
 
  p_write_prop (fp, PROP_LINKED, &l_param, wr_all_prp);
1452
 
 
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);
1455
 
 
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);
1458
 
 
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);
1461
 
 
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);
1464
 
 
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);
1469
 
 
1470
 
  l_param.int_val1 = gimp_drawable_get_tattoo(layer_id);
1471
 
  p_write_prop (fp, PROP_TATTOO, &l_param, wr_all_prp);
1472
 
 
1473
 
  l_param.string_val = gimp_drawable_get_name(layer_id);
1474
 
  p_write_prop (fp, PROP_NAME, &l_param, wr_all_prp);
1475
 
 
1476
 
  p_write_drawable_parasites(dirname, fp, layer_id, wr_all_prp);
1477
 
 
1478
 
 
1479
 
  fprintf(fp, "\n");
1480
 
}       /* end p_write_layer_prp */
1481
 
 
1482
 
 
1483
 
/* ============================================================================
1484
 
 * p_write_channel_prp
1485
 
 *   write out all properties of the given channel
1486
 
 * ============================================================================
1487
 
 */
1488
 
 
1489
 
static void
1490
 
p_write_channel_prp(const gchar *dirname,
1491
 
                    FILE        *fp,
1492
 
                    const gchar *channel_shortname,
1493
 
                    gint32       image_id,
1494
 
                    gint32       channel_id,
1495
 
                    gint         wr_all_prp)
1496
 
{
1497
 
  t_param_prop   l_param;
1498
 
  gint           l_ofsx, l_ofsy;
1499
 
  GimpRGB        color;
1500
 
  guchar         l_r, l_g, l_b;
1501
 
 
1502
 
  fprintf(fp, "%s", channel_shortname);
1503
 
 
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);
1506
 
 
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);
1509
 
 
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);
1513
 
 
1514
 
  l_param.flt_val1 = gimp_channel_get_opacity(channel_id);
1515
 
  p_write_prop (fp, PROP_OPACITY, &l_param, wr_all_prp);
1516
 
 
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);
1519
 
 
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);
1522
 
 
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);
1529
 
 
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);
1534
 
 
1535
 
  l_param.int_val1 = gimp_drawable_get_tattoo (channel_id);
1536
 
  p_write_prop (fp, PROP_TATTOO, &l_param, wr_all_prp);
1537
 
 
1538
 
  l_param.string_val = gimp_drawable_get_name(channel_id);
1539
 
  p_write_prop (fp, PROP_NAME, &l_param, wr_all_prp);
1540
 
 
1541
 
  p_write_drawable_parasites(dirname, fp, channel_id, wr_all_prp);
1542
 
 
1543
 
 
1544
 
  fprintf(fp, "\n");
1545
 
}       /* end p_write_channel_prp */
1546
 
 
1547
 
/* ============================================================================
1548
 
 * p_write_image_prp
1549
 
 *   write out the properties of the image
1550
 
 * ============================================================================
1551
 
 */
1552
 
 
1553
 
static void
1554
 
p_write_image_prp (const gchar *dirname,
1555
 
                   FILE        *fp,
1556
 
                   gint32       image_id,
1557
 
                   gint         wr_all_prp)
1558
 
{
1559
 
   GimpImageBaseType l_image_type;
1560
 
   guint   l_width, l_height;
1561
 
   gdouble l_xresolution, l_yresolution;
1562
 
   t_param_prop   l_param;
1563
 
   gint32 l_guide_id;
1564
 
 
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);
1569
 
 
1570
 
   fprintf(fp, "%s", GIMP_XJ_IMAGE);
1571
 
 
1572
 
   l_param.string_val = "1.3.11";
1573
 
   p_write_prop (fp, PROP_VERSION, &l_param, wr_all_prp);
1574
 
 
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);
1579
 
 
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);
1583
 
 
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);
1588
 
 
1589
 
   /* write unit */
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);
1592
 
 
1593
 
   /* write tattoo_state */
1594
 
   l_param.int_val1 = gimp_image_get_tattoo_state(image_id);
1595
 
   if (l_param.int_val1 > 0)
1596
 
   {
1597
 
     p_write_prop (fp, PROP_TATTOO_STATE, &l_param, wr_all_prp);
1598
 
   }
1599
 
 
1600
 
   /* write guides */
1601
 
   l_guide_id = gimp_image_find_next_guide(image_id, 0);  /* get 1.st guide */
1602
 
   while (l_guide_id > 0)
1603
 
   {
1604
 
      /* get position and orientation for the current guide ID */
1605
 
 
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);
1609
 
 
1610
 
     /* findnext returns 0 if no (more) guides there
1611
 
      * (or -1 if no PDB interface is available)
1612
 
      */
1613
 
     l_guide_id = gimp_image_find_next_guide(image_id, l_guide_id);
1614
 
   }
1615
 
 
1616
 
   if (l_image_type == GIMP_GRAY)
1617
 
   {
1618
 
     l_param.int_val1 = (gint32)XJT_GRAY;
1619
 
   }
1620
 
   else
1621
 
   {
1622
 
     l_param.int_val1 = (gint32)XJT_RGB;
1623
 
   }
1624
 
   p_write_prop (fp, PROP_TYPE, &l_param, wr_all_prp);
1625
 
 
1626
 
   p_write_image_parasites(dirname, fp, image_id, wr_all_prp);
1627
 
 
1628
 
   fprintf(fp, "\n");
1629
 
 
1630
 
   p_write_image_paths(fp, image_id, wr_all_prp);
1631
 
}       /* end p_write_image_prp */
1632
 
 
1633
 
 
1634
 
/* ---------------------- SAVE  -------------------------- */
1635
 
 
1636
 
static gint
1637
 
save_xjt_image (const gchar *filename,
1638
 
                gint32       image_id,
1639
 
                gint32       drawable_id)
1640
 
{
1641
 
  int     l_rc;
1642
 
  int     l_len;
1643
 
  int     l_idx;
1644
 
  gchar  *l_dirname;
1645
 
  gchar  *l_prop_file;
1646
 
  gchar  *l_jpg_file;
1647
 
  gchar  *l_cmd;
1648
 
  FILE   *l_fp_prp;
1649
 
 
1650
 
  GimpImageBaseType l_image_type;
1651
 
  gint32 *l_layers_list;
1652
 
  gint32 *l_channels_list;
1653
 
  gint    l_nlayers;
1654
 
  gint    l_nchannels;
1655
 
  gint32  l_layer_id;
1656
 
  gint32  l_channel_id;
1657
 
  gint32  l_floating_layer_id;
1658
 
  gint32  l_selection_channel_id;
1659
 
  int     l_sel;
1660
 
  gint32  l_x1, l_x2, l_y1, l_y2;
1661
 
  gboolean non_empty;
1662
 
 
1663
 
  gint    l_wr_all_prp;
1664
 
 
1665
 
  l_rc = -1;  /* init retcode to Errorstate */
1666
 
  l_floating_layer_id = -1;
1667
 
  l_fp_prp = NULL;
1668
 
  l_layers_list = NULL;
1669
 
  l_channels_list = NULL;
1670
 
  l_dirname = NULL;
1671
 
  l_prop_file = NULL;
1672
 
  l_jpg_file = NULL;
1673
 
  l_wr_all_prp = FALSE;     /* FALSE write only non-default properties
1674
 
                              * TRUE  write all properties (should be used for DEBUG only)
1675
 
                              */
1676
 
  global_parasite_id = 0;
1677
 
  global_parasite_prop_lines = NULL;
1678
 
 
1679
 
 
1680
 
  /* get info about the image */
1681
 
  l_image_type = gimp_image_base_type(image_id);
1682
 
  switch (l_image_type)
1683
 
    {
1684
 
    case GIMP_RGB:
1685
 
    case GIMP_GRAY:
1686
 
      break;
1687
 
    case GIMP_INDEXED:
1688
 
      g_message (_("Cannot operate on indexed color images."));
1689
 
      return -1;
1690
 
      break;
1691
 
    default:
1692
 
      g_message (_("Cannot operate on unknown image types."));
1693
 
      return -1;
1694
 
      break;
1695
 
    }
1696
 
 
1697
 
  gimp_progress_init_printf (_("Saving '%s'"),
1698
 
                             gimp_filename_to_utf8 (filename));
1699
 
 
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)
1704
 
    {
1705
 
      g_message (_("Could not create working folder '%s': %s"),
1706
 
                 gimp_filename_to_utf8 (l_dirname), g_strerror (errno));
1707
 
      goto cleanup;
1708
 
    }
1709
 
 
1710
 
  /* create property file PRP */
1711
 
  l_fp_prp = g_fopen (l_prop_file, "wb");
1712
 
  if (l_fp_prp == NULL)
1713
 
    {
1714
 
      g_message (_("Could not open '%s' for writing: %s"),
1715
 
                 gimp_filename_to_utf8 (l_prop_file), g_strerror (errno));
1716
 
      goto cleanup;
1717
 
    }
1718
 
 
1719
 
  /* write image properties */
1720
 
  p_write_image_prp (l_dirname, l_fp_prp, image_id, l_wr_all_prp);
1721
 
 
1722
 
 
1723
 
  l_floating_layer_id = gimp_image_get_floating_sel (image_id);
1724
 
  if (l_floating_layer_id >= 0)
1725
 
    {
1726
 
      if (xjt_debug) printf ("XJT-DEBUG: call floating_sel_relax fsel_id=%d\n",
1727
 
                             (int) l_floating_layer_id);
1728
 
 
1729
 
      gimp_floating_sel_relax (l_floating_layer_id, FALSE);
1730
 
    }
1731
 
 
1732
 
  l_layers_list = gimp_image_get_layers (image_id, &l_nlayers);
1733
 
 
1734
 
  /* foreach layer do */
1735
 
  for (l_idx = 0; l_idx < l_nlayers; l_idx++)
1736
 
    {
1737
 
      l_layer_id = l_layers_list[l_idx];
1738
 
 
1739
 
      if (xjt_debug) printf ("Layer [%d] id=%d\n", (int)l_idx, (int)l_layer_id);
1740
 
 
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);
1745
 
 
1746
 
      if (TRUE != xjpg_save_drawable (l_jpg_file,
1747
 
                                      image_id,
1748
 
                                      l_layer_id,
1749
 
                                      JSVM_DRAWABLE,
1750
 
                                      &jsvals))
1751
 
        {
1752
 
          goto cleanup;
1753
 
        }
1754
 
      g_free (l_jpg_file);
1755
 
 
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);
1760
 
      g_free(l_jpg_file);
1761
 
 
1762
 
      /* check, and save alpha channel */
1763
 
      if(gimp_drawable_has_alpha(l_layer_id))
1764
 
      {
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);
1767
 
 
1768
 
         if(TRUE != xjpg_save_drawable(l_jpg_file,
1769
 
                                    image_id,
1770
 
                                    l_layer_id,
1771
 
                                    JSVM_ALPHA,
1772
 
                                    &jsvals ))
1773
 
         { goto cleanup;
1774
 
         }
1775
 
         g_free(l_jpg_file);
1776
 
      }
1777
 
 
1778
 
      /* check and save layer_mask channel */
1779
 
       l_channel_id = gimp_layer_get_mask (l_layer_id);
1780
 
       if(l_channel_id >= 0)
1781
 
       {
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);
1784
 
 
1785
 
          if(TRUE != xjpg_save_drawable(l_jpg_file,
1786
 
                                        image_id,
1787
 
                                        l_channel_id,
1788
 
                                        JSVM_DRAWABLE,
1789
 
                                        &jsvals))
1790
 
          {   goto cleanup;
1791
 
          }
1792
 
          g_free(l_jpg_file);
1793
 
 
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);
1797
 
          g_free(l_jpg_file);
1798
 
       }
1799
 
   }    /* end foreach layer */
1800
 
 
1801
 
 
1802
 
   /* check and see if we have to save out the selection */
1803
 
   l_sel = 0;
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))
1807
 
   {
1808
 
      l_sel = 1;
1809
 
   }
1810
 
 
1811
 
   l_channels_list = gimp_image_get_channels(image_id, &l_nchannels);
1812
 
 
1813
 
   /* foreach channel do */
1814
 
   for(l_idx = 0; l_idx < l_nchannels + l_sel; l_idx++)
1815
 
   {
1816
 
      if(l_idx < l_nchannels)  l_channel_id = l_channels_list[l_idx];
1817
 
      else                     l_channel_id = l_selection_channel_id;
1818
 
 
1819
 
      if(xjt_debug) printf("channel [%d] id=%d\n", (int)l_idx, (int)l_channel_id);
1820
 
 
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);
1824
 
 
1825
 
      if(TRUE != xjpg_save_drawable(l_jpg_file,
1826
 
                                    image_id,
1827
 
                                    l_channel_id,
1828
 
                                    JSVM_DRAWABLE,
1829
 
                                    &jsvals))
1830
 
      {   goto cleanup;
1831
 
      }
1832
 
      g_free(l_jpg_file);
1833
 
 
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);
1837
 
      g_free(l_jpg_file);
1838
 
 
1839
 
   }            /* end foreach channel */
1840
 
 
1841
 
 
1842
 
   if(global_parasite_prop_lines != NULL)
1843
 
   {
1844
 
     /* have to add parasite lines at end of PRP file */
1845
 
     fprintf(l_fp_prp, "%s", global_parasite_prop_lines);
1846
 
   }
1847
 
   fclose( l_fp_prp );
1848
 
   l_fp_prp = NULL;
1849
 
 
1850
 
   /* store properties and  all layers and cannels in a
1851
 
    * tar archive with filename.tar
1852
 
    */
1853
 
   l_cmd = g_strdup_printf("cd %s; tar -cf \"%s\" *; cd ..", l_dirname, filename);
1854
 
   l_rc = p_system(l_cmd);
1855
 
   g_free(l_cmd);
1856
 
 
1857
 
   l_len = strlen(filename);
1858
 
   if((l_len > 3) && (l_rc == 0))
1859
 
   {
1860
 
     /* call optional extracompression programs gzip or bzip2
1861
 
      * (depends on filename's extension)
1862
 
      *
1863
 
      * used gzip options: (bzip2 uses the same options)
1864
 
      *     -c --stdout --to-stdout
1865
 
      *          Write  output  on  standard  output
1866
 
      *     -f --force
1867
 
      *           Force compression or decompression even if the file
1868
 
      */
1869
 
     if(strcmp(&filename[l_len - 3], "bz2") == 0)
1870
 
     {
1871
 
       l_cmd = g_strdup_printf("bzip2 -cf \"%s\" >\"%s.tmp_bz2\"",filename , filename);
1872
 
       l_rc = p_system(l_cmd);
1873
 
       g_free(l_cmd);
1874
 
       l_cmd = g_strdup_printf("mv \"%s.tmp_bz2\" \"%s\"" ,filename , filename);
1875
 
       l_rc = p_system(l_cmd);
1876
 
       g_free(l_cmd);
1877
 
     }
1878
 
     else if(strcmp(&filename[l_len - 2], "gz") == 0)
1879
 
     {
1880
 
       l_cmd = g_strdup_printf("gzip -cf <\"%s\" >\"%s.tmp_gz\"",filename , filename);
1881
 
       l_rc = p_system(l_cmd);
1882
 
       g_free(l_cmd);
1883
 
       l_cmd = g_strdup_printf("mv \"%s.tmp_gz\" \"%s\"" ,filename , filename);
1884
 
       l_rc = p_system(l_cmd);
1885
 
       g_free(l_cmd);
1886
 
     }
1887
 
   }
1888
 
 
1889
 
cleanup:
1890
 
   if (l_fp_prp)
1891
 
     {
1892
 
       fclose (l_fp_prp);
1893
 
     }
1894
 
 
1895
 
   if (l_floating_layer_id >= 0)
1896
 
     {
1897
 
       if (xjt_debug)
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);
1901
 
     }
1902
 
 
1903
 
   g_free (l_layers_list);
1904
 
   g_free (l_channels_list);
1905
 
 
1906
 
   /* remove the temorary directory */
1907
 
   l_cmd = g_strdup_printf("rm -rf \"%s\"", l_dirname);
1908
 
 
1909
 
   if(!xjt_debug) p_system(l_cmd);
1910
 
   g_free(l_cmd);
1911
 
 
1912
 
   g_free (l_dirname);
1913
 
   g_free (l_prop_file);
1914
 
   g_free (l_jpg_file);
1915
 
 
1916
 
   return l_rc;
1917
 
}
1918
 
 
1919
 
/* ---------------------- LOAD WORKER procedures  -------------------------- */
1920
 
 
1921
 
 
1922
 
/* ============================================================================
1923
 
 * p_new_layer_prop
1924
 
 *   allocate new layer_properties element and init with default values
1925
 
 * ============================================================================
1926
 
 */
1927
 
static t_layer_props *
1928
 
p_new_layer_prop(void)
1929
 
{
1930
 
  t_layer_props  *l_new_prop;
1931
 
 
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;
1948
 
 
1949
 
  l_new_prop->layer_pos = -1;
1950
 
  l_new_prop->has_alpha = FALSE;
1951
 
  l_new_prop->next = NULL;
1952
 
  return l_new_prop;
1953
 
}       /* end p_new_layer_prop */
1954
 
 
1955
 
 
1956
 
/* ============================================================================
1957
 
 * p_new_channel_prop
1958
 
 *   allocate new channel_properties element and init with default values
1959
 
 * ============================================================================
1960
 
 */
1961
 
static t_channel_props *
1962
 
p_new_channel_prop(void)
1963
 
{
1964
 
  t_channel_props  *l_new_prop;
1965
 
 
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;
1980
 
 
1981
 
  l_new_prop->channel_pos = -1;
1982
 
  l_new_prop->next = NULL;
1983
 
  return l_new_prop;
1984
 
}       /* end p_new_channel_prop */
1985
 
 
1986
 
 
1987
 
/* ============================================================================
1988
 
 * p_new_guide_prop
1989
 
 *   allocate new guide_properties element and init with default values
1990
 
 * ============================================================================
1991
 
 */
1992
 
static t_guide_props *
1993
 
p_new_guide_prop(void)
1994
 
{
1995
 
  t_guide_props  *l_new_prop;
1996
 
 
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;
2001
 
  return l_new_prop;
2002
 
}       /* end p_new_guide_prop */
2003
 
 
2004
 
/* ============================================================================
2005
 
 * p_new_parasite_prop
2006
 
 *   allocate new parasite_properties element and init with default values
2007
 
 * ============================================================================
2008
 
 */
2009
 
static t_parasite_props *
2010
 
p_new_parasite_prop(void)
2011
 
{
2012
 
  t_parasite_props  *l_new_prop;
2013
 
 
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;
2021
 
  return l_new_prop;
2022
 
}       /* end p_new_parasite_prop */
2023
 
 
2024
 
/* ============================================================================
2025
 
 * p_new_path_prop
2026
 
 *   allocate new parasite_properties element and init with default values
2027
 
 * ============================================================================
2028
 
 */
2029
 
static t_path_props *
2030
 
p_new_path_prop(void)
2031
 
{
2032
 
  t_path_props  *l_new_prop;
2033
 
 
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;
2044
 
  return l_new_prop;
2045
 
}       /* end p_new_path_prop */
2046
 
 
2047
 
/* ============================================================================
2048
 
 * p_new_image_prop
2049
 
 *   allocate new layer_properties element and init with default values
2050
 
 * ============================================================================
2051
 
 */
2052
 
static t_image_props *
2053
 
p_new_image_prop(void)
2054
 
{
2055
 
  t_image_props  *l_new_prop;
2056
 
 
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;
2074
 
  return l_new_prop;
2075
 
}       /* end p_new_image_prop */
2076
 
 
2077
 
 
2078
 
/* ============================================================================
2079
 
 * p_skip_blanks
2080
 
 *
2081
 
 * ============================================================================
2082
 
 */
2083
 
static gchar *
2084
 
p_skip_blanks(gchar* scan_ptr)
2085
 
{
2086
 
  while((*scan_ptr == ' ') || (*scan_ptr == '\t'))
2087
 
  {
2088
 
     scan_ptr++;
2089
 
  }
2090
 
  return(scan_ptr);
2091
 
}
2092
 
 
2093
 
/* ============================================================================
2094
 
 * p_scann_token
2095
 
 *   scan one token with its parameter(s)
2096
 
 *   return pointer to character behind the last scanned byte.
2097
 
 *
2098
 
 * Check prop_id for PROP_END             (no more tokens found)
2099
 
 *               for PROP_SYNTAX_ERROR    (illegal token/params detected)
2100
 
 * ============================================================================
2101
 
 */
2102
 
 
2103
 
static gchar *
2104
 
p_scann_token(gchar        *scan_ptr,
2105
 
              t_param_prop *param,
2106
 
              t_proptype   *prop_id)
2107
 
{
2108
 
  int    l_idx;
2109
 
  int    l_ids;
2110
 
  int    l_max_line_len;
2111
 
  int    l_num_fvals;
2112
 
  gchar *l_token;
2113
 
  gchar *l_string_buff;
2114
 
  gchar *l_ptr;
2115
 
  gchar *l_ptr2;
2116
 
 
2117
 
 
2118
 
  /* check for end of property line */
2119
 
  if((*scan_ptr == '\0') || (*scan_ptr == '\n'))
2120
 
  {
2121
 
    *prop_id  = PROP_END;
2122
 
    return(scan_ptr);
2123
 
  }
2124
 
 
2125
 
  *prop_id  = PROP_SYNTAX_ERROR;
2126
 
 
2127
 
  l_max_line_len = strlen(scan_ptr);
2128
 
  l_token = g_malloc(l_max_line_len + 1);
2129
 
 
2130
 
  /* extract current token at scann_ptr position */
2131
 
  l_ptr = scan_ptr;
2132
 
  for (l_idx = 0; l_idx < (l_max_line_len -1); l_idx++)
2133
 
  {
2134
 
     if ((*l_ptr == ' ')
2135
 
     ||  (*l_ptr == '\n')
2136
 
     ||  (*l_ptr == '\t')
2137
 
     ||  (*l_ptr == '\0')
2138
 
     ||  (*l_ptr == '!')
2139
 
     ||  (*l_ptr == ':'))
2140
 
     {
2141
 
        break;
2142
 
     }
2143
 
 
2144
 
     l_token[l_idx] = (*l_ptr);
2145
 
     l_ptr++;
2146
 
  }
2147
 
  l_token[l_idx] = '\0';
2148
 
 
2149
 
  if(xjt_debug) printf("XJT:TOKEN:%s:", l_token);
2150
 
 
2151
 
  /* check if token is one of the supported mnemonics */
2152
 
  for (l_idx = 0; l_idx < PROP_TABLE_ENTRIES; l_idx++)
2153
 
  {
2154
 
    if(g_prop_table[l_idx].param_typ == PTYP_NOT_SUPPORTED)
2155
 
    {
2156
 
      continue;
2157
 
    }
2158
 
 
2159
 
    if(0 != strcmp(l_token, g_prop_table[l_idx].prop_mnemonic))
2160
 
    {
2161
 
      continue;
2162
 
    }
2163
 
 
2164
 
    *prop_id = g_prop_table[l_idx].prop_id;
2165
 
 
2166
 
    /* scann parameters according to detected property type */
2167
 
    switch(g_prop_table[l_idx].param_typ)
2168
 
    {
2169
 
       case PTYP_BOOLEAN:
2170
 
           param->int_val1 = TRUE;
2171
 
           if(*l_ptr == ':')
2172
 
           {
2173
 
              g_printerr ("XJT: PRP syntax error (bool property %s terminated with :)\n",
2174
 
                          l_token);
2175
 
              *prop_id  = PROP_SYNTAX_ERROR;
2176
 
              return (l_ptr);
2177
 
           }
2178
 
           if(*l_ptr == '!')   /* inverter character */
2179
 
           {
2180
 
              param->int_val1 = FALSE;
2181
 
              l_ptr++;
2182
 
           }
2183
 
           if(xjt_debug) printf("%d", (int)param->int_val1);
2184
 
           break;
2185
 
       case PTYP_3xINT:
2186
 
       case PTYP_2xINT:
2187
 
       case PTYP_INT:
2188
 
           if(*l_ptr != ':')
2189
 
           {
2190
 
              g_printerr ("XJT: PRP syntax error (int property %s not terminated with :)\n",
2191
 
                          l_token);
2192
 
              *prop_id  = PROP_SYNTAX_ERROR;
2193
 
           }
2194
 
           else
2195
 
           {
2196
 
              l_ptr++;
2197
 
              param->int_val1 = strtol(l_ptr, &l_ptr2, 10);   /* Scan 1.st integer (base = 10) */
2198
 
              if (l_ptr == l_ptr2 )
2199
 
              {
2200
 
                 g_printerr ("XJT: PRP syntax error (int property %s :integer value missing)\n",
2201
 
                             l_token);
2202
 
                 *prop_id  = PROP_SYNTAX_ERROR;
2203
 
                 return(l_ptr);
2204
 
              }
2205
 
              l_ptr = l_ptr2;
2206
 
              if(xjt_debug) printf("%d", (int)param->int_val1);
2207
 
 
2208
 
              if((PTYP_2xINT == g_prop_table[l_idx].param_typ)
2209
 
              || (PTYP_3xINT == g_prop_table[l_idx].param_typ))
2210
 
              {
2211
 
                 if(*l_ptr != ',')
2212
 
                 {
2213
 
                    g_printerr ("XJT: PRP syntax error (int property %s comma missing)\n",
2214
 
                                l_token);
2215
 
                    *prop_id  = PROP_SYNTAX_ERROR;
2216
 
                    return(l_ptr);
2217
 
                 }
2218
 
                 l_ptr++;
2219
 
                 param->int_val2 = strtol(l_ptr, &l_ptr2, 10);   /*  Scan 2.nd integer (base = 10)  */
2220
 
                 if (l_ptr == l_ptr2 )
2221
 
                 {
2222
 
                    g_printerr ("XJT: PRP syntax error (int property %s : 2.nd integer value missing)\n",
2223
 
                                l_token);
2224
 
                    *prop_id  = PROP_SYNTAX_ERROR;
2225
 
                    return(l_ptr);
2226
 
                 }
2227
 
                 l_ptr = l_ptr2;
2228
 
                 if(xjt_debug) printf(",%d", (int)param->int_val2);
2229
 
 
2230
 
                 if(PTYP_3xINT == g_prop_table[l_idx].param_typ)
2231
 
                 {
2232
 
                    if(*l_ptr != ',')
2233
 
                    {
2234
 
                       g_printerr ("XJT: PRP syntax error (int property %s comma missing)\n",
2235
 
                                   l_token);
2236
 
                       *prop_id  = PROP_SYNTAX_ERROR;
2237
 
                       return(l_ptr);
2238
 
                    }
2239
 
                    l_ptr++;
2240
 
                    param->int_val3 = strtol(l_ptr, &l_ptr2, 10);   /*  Scan 3.rd integer (base = 10)  */
2241
 
                    if (l_ptr == l_ptr2 )
2242
 
                    {
2243
 
                       g_printerr ("XJT: PRP syntax error (int property %s : 3.rd integer value missing)\n",
2244
 
                                   l_token);
2245
 
                       *prop_id  = PROP_SYNTAX_ERROR;
2246
 
                       return(l_ptr);
2247
 
                    }
2248
 
                    l_ptr = l_ptr2;
2249
 
                    if(xjt_debug) printf(",%d", (int)param->int_val3);
2250
 
                 }
2251
 
              }
2252
 
           }
2253
 
           break;
2254
 
       case PTYP_3xFLT:
2255
 
       case PTYP_2xFLT:
2256
 
       case PTYP_FLT:
2257
 
           if(*l_ptr != ':')
2258
 
           {
2259
 
              g_printerr ("XJT: PRP syntax error (float property %s not terminated with :)\n",
2260
 
                          l_token);
2261
 
              *prop_id  = PROP_SYNTAX_ERROR;
2262
 
           }
2263
 
           else
2264
 
           {
2265
 
              l_ptr++;
2266
 
              param->flt_val1 = p_my_ascii_strtod(l_ptr, &l_ptr2);
2267
 
              if (l_ptr == l_ptr2 )
2268
 
              {
2269
 
                 g_printerr ("XJT: PRP syntax error (float property %s :float value missing)\n",
2270
 
                             l_token);
2271
 
                 *prop_id  = PROP_SYNTAX_ERROR;
2272
 
                 return(l_ptr);
2273
 
              }
2274
 
              l_ptr = l_ptr2;
2275
 
              if(xjt_debug)    printf("%f", param->flt_val1);
2276
 
 
2277
 
              if((PTYP_2xFLT == g_prop_table[l_idx].param_typ)
2278
 
              || (PTYP_3xFLT == g_prop_table[l_idx].param_typ))
2279
 
              {
2280
 
                 if(*l_ptr != ',')
2281
 
                 {
2282
 
                    g_printerr ("XJT: PRP syntax error (float property %s comma missing)\n",
2283
 
                                l_token);
2284
 
                    *prop_id  = PROP_SYNTAX_ERROR;
2285
 
                    return(l_ptr);
2286
 
                 }
2287
 
                 l_ptr++;
2288
 
                 param->flt_val2 = p_my_ascii_strtod(l_ptr, &l_ptr2);
2289
 
                 if (l_ptr == l_ptr2 )
2290
 
                 {
2291
 
                    g_printerr ("XJT: PRP syntax error (float property %s : 2.nd float value missing)\n",
2292
 
                                l_token);
2293
 
                    *prop_id  = PROP_SYNTAX_ERROR;
2294
 
                    return(l_ptr);
2295
 
                 }
2296
 
                 l_ptr = l_ptr2;
2297
 
                 if(xjt_debug) printf(",%f", param->flt_val2);
2298
 
 
2299
 
                 if(PTYP_3xFLT == g_prop_table[l_idx].param_typ)
2300
 
                 {
2301
 
                    if(*l_ptr != ',')
2302
 
                    {
2303
 
                       g_printerr ("XJT: PRP syntax error (float property %s comma missing)\n",
2304
 
                                   l_token);
2305
 
                       *prop_id  = PROP_SYNTAX_ERROR;
2306
 
                       return(l_ptr);
2307
 
                    }
2308
 
                    l_ptr++;
2309
 
                    param->flt_val3 = p_my_ascii_strtod(l_ptr, &l_ptr2);
2310
 
                    if (l_ptr == l_ptr2 )
2311
 
                    {
2312
 
                       g_printerr ("XJT: PRP syntax error (float property %s : 3.rd float value missing)\n",
2313
 
                                   l_token);
2314
 
                       *prop_id  = PROP_SYNTAX_ERROR;
2315
 
                       return(l_ptr);
2316
 
                    }
2317
 
                    l_ptr = l_ptr2;
2318
 
                    if(xjt_debug) printf(",%f", param->flt_val3);
2319
 
                 }
2320
 
              }
2321
 
           }
2322
 
           break;
2323
 
       case PTYP_FLIST:
2324
 
           if(*l_ptr != ':')
2325
 
           {
2326
 
              g_printerr ("XJT: PRP syntax error (floatlist property %s not terminated with :)\n",
2327
 
                          l_token);
2328
 
              *prop_id  = PROP_SYNTAX_ERROR;
2329
 
           }
2330
 
           else
2331
 
           {
2332
 
              l_ptr++;
2333
 
              /* counting ',' to guess how much values are in the list */
2334
 
              l_num_fvals = 1;
2335
 
              l_ptr2 = l_ptr;
2336
 
              while(1)
2337
 
              {
2338
 
                if((*l_ptr2 == '\0')
2339
 
                || (*l_ptr2 == '\n'))
2340
 
                {
2341
 
                  break;
2342
 
                }
2343
 
                if(*l_ptr2 == ',')
2344
 
                {
2345
 
                  l_num_fvals++;
2346
 
                }
2347
 
                l_ptr2++;
2348
 
              }
2349
 
 
2350
 
              param->num_fvals = 0;
2351
 
              param->flt_val_list = g_malloc0(sizeof(gdouble) * l_num_fvals);
2352
 
              while(1)
2353
 
              {
2354
 
                param->flt_val_list[param->num_fvals] = p_my_ascii_strtod(l_ptr, &l_ptr2);
2355
 
                if (l_ptr == l_ptr2 )
2356
 
                {
2357
 
                   if(param->num_fvals == 0)
2358
 
                   {
2359
 
                     g_printerr ("XJT: PRP syntax error (floatlist property %s :no float value found)\n",
2360
 
                                 l_token);
2361
 
                     *prop_id  = PROP_SYNTAX_ERROR;
2362
 
                     return(l_ptr);
2363
 
                   }
2364
 
                   break;
2365
 
                }
2366
 
                l_ptr = l_ptr2;
2367
 
                if(xjt_debug)    printf("%f char:%c\n", param->flt_val_list[param->num_fvals], *l_ptr);
2368
 
                param->num_fvals++;
2369
 
                if(*l_ptr != ',')
2370
 
                {
2371
 
                  if((*l_ptr2 != '\0')
2372
 
                  && (*l_ptr2 != '\n'))
2373
 
                  {
2374
 
                     g_printerr ("XJT: PRP syntax error (floatlist property %s :list contains illegal character: %c)\n",
2375
 
                                 l_token, *l_ptr);
2376
 
                     *prop_id  = PROP_SYNTAX_ERROR;
2377
 
                     return(l_ptr);
2378
 
                  }
2379
 
                  break;
2380
 
                }
2381
 
                l_ptr++;
2382
 
              }
2383
 
           }
2384
 
           break;
2385
 
       case PTYP_STRING:
2386
 
           if(*l_ptr != ':')
2387
 
           {
2388
 
              g_printerr ("XJT: PRP syntax error (string property %s not terminated with :)\n",
2389
 
                          l_token);
2390
 
              *prop_id  = PROP_SYNTAX_ERROR;
2391
 
              return (l_ptr);
2392
 
           }
2393
 
           l_ptr++;
2394
 
           if(*l_ptr != '\"')
2395
 
           {
2396
 
              g_printerr ("XJT: PRP syntax error (string property %s starting \" is missing)\n",
2397
 
                          l_token);
2398
 
              *prop_id  = PROP_SYNTAX_ERROR;
2399
 
               return (l_ptr);
2400
 
           }
2401
 
           l_ptr++;
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++)
2404
 
           {
2405
 
              if(*l_ptr == '\0')
2406
 
              {
2407
 
                 break;
2408
 
              }
2409
 
              if(*l_ptr == '\\')
2410
 
              {
2411
 
                 if(l_ptr[1] == '\"')
2412
 
                 {
2413
 
                     l_string_buff[l_ids] = '\"';
2414
 
                     l_ptr++;
2415
 
                     l_ptr++;
2416
 
                     continue;
2417
 
                 }
2418
 
                 if(l_ptr[1] == 'n')
2419
 
                 {
2420
 
                     l_string_buff[l_ids] = '\n';
2421
 
                     l_ptr++;
2422
 
                     l_ptr++;
2423
 
                     continue;
2424
 
                 }
2425
 
                 if(l_ptr[1] == '\\')
2426
 
                 {
2427
 
                     l_string_buff[l_ids] = '\\';
2428
 
                     l_ptr++;
2429
 
                     l_ptr++;
2430
 
                     continue;
2431
 
                 }
2432
 
                 l_ptr++;
2433
 
              }
2434
 
              if((*l_ptr == '\"') ||
2435
 
                 (*l_ptr == '\n'))
2436
 
              {
2437
 
                 break;
2438
 
              }
2439
 
              l_string_buff[l_ids] = *l_ptr;
2440
 
              l_ptr++;
2441
 
           }
2442
 
           l_string_buff[l_ids] = '\0';
2443
 
           if (*l_ptr == '\"')
2444
 
           {
2445
 
             l_ptr++;
2446
 
             param->string_val = g_strdup (l_string_buff);
2447
 
             if(xjt_debug) printf("%s", param->string_val);
2448
 
          }
2449
 
           else
2450
 
           {
2451
 
             g_printerr ("XJT: PRP syntax error (string property %s terminating \" is missing)\n",
2452
 
                         l_token);
2453
 
             *prop_id  = PROP_SYNTAX_ERROR;
2454
 
           }
2455
 
           g_free(l_string_buff);
2456
 
           break;
2457
 
       default:
2458
 
           g_printerr ("XJT: ** Warning ** PRP file with unsupported property %s\n",
2459
 
                       l_token);
2460
 
           *prop_id  = PROP_SYNTAX_ERROR;
2461
 
           break;
2462
 
    }
2463
 
 
2464
 
    break;
2465
 
  }
2466
 
 
2467
 
  if(xjt_debug) printf("\n");
2468
 
 
2469
 
  /* advance l_ptr to next Blank
2470
 
   * (this is needed to skip unknown tokens
2471
 
   */
2472
 
  while(1)
2473
 
  {
2474
 
     if ((*l_ptr == ' ')
2475
 
     ||  (*l_ptr == '\n')
2476
 
     ||  (*l_ptr == '\t')
2477
 
     ||  (*l_ptr == '\0'))
2478
 
     {
2479
 
        break;
2480
 
     }
2481
 
 
2482
 
     l_ptr++;
2483
 
  }
2484
 
 
2485
 
  if(*prop_id  == PROP_SYNTAX_ERROR)
2486
 
  {
2487
 
    g_printerr ("XJT: ** Warning ** PRP file skipping property: %s\n", l_token);
2488
 
  }
2489
 
 
2490
 
  g_free(l_token);
2491
 
  return(l_ptr);
2492
 
}       /* end p_scann_token */
2493
 
 
2494
 
 
2495
 
/* ============================================================================
2496
 
 * p_find_parasite
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
 
 * ============================================================================
2501
 
 */
2502
 
static t_parasite_props *
2503
 
p_find_parasite(t_parasite_props *parasite_props, gint32 parasite_id)
2504
 
{
2505
 
  t_parasite_props  *l_prop;
2506
 
 
2507
 
  if(xjt_debug) printf("XJT: p_find_parasite search parasite_id (1): %d\n", (int)parasite_id );
2508
 
 
2509
 
  l_prop = parasite_props;
2510
 
  while(l_prop)
2511
 
  {
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)
2514
 
     {
2515
 
       if(xjt_debug) printf("XJT: p_find_parasite (3) listid=%d\n", (int)l_prop->parasite_id );
2516
 
       return(l_prop);
2517
 
     }
2518
 
     l_prop = (t_parasite_props *)l_prop->next;
2519
 
  }
2520
 
 
2521
 
  if(xjt_debug) printf("XJT: p_find_parasite (4) NULL\n");
2522
 
  return(NULL);
2523
 
}
2524
 
 
2525
 
/* ============================================================================
2526
 
 * p_create_and_attach_parasite
2527
 
 * ============================================================================
2528
 
 */
2529
 
static gint
2530
 
p_create_and_attach_parasite (gint32            gimp_obj_id,
2531
 
                              const gchar      *dirname,
2532
 
                              t_parasite_props *parasite_props)
2533
 
{
2534
 
  gchar            *l_parasite_file;
2535
 
  GimpParasite      l_parasite;
2536
 
  struct stat       l_stat_buf;
2537
 
  FILE *l_fp_pte;
2538
 
 
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);
2541
 
 
2542
 
  if (0 != g_stat(l_parasite_file, &l_stat_buf))
2543
 
  {
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));
2547
 
     return(-1);
2548
 
  }
2549
 
 
2550
 
  l_fp_pte = g_fopen(l_parasite_file, "rb");
2551
 
  if(l_fp_pte == NULL)
2552
 
  {
2553
 
     g_message (_("Could not open '%s' for reading: %s"),
2554
 
                 gimp_filename_to_utf8 (l_parasite_file), g_strerror (errno));
2555
 
     return(-1);
2556
 
  }
2557
 
 
2558
 
  g_free(l_parasite_file);
2559
 
 
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)
2564
 
  {
2565
 
     l_parasite.name = g_strdup(parasite_props->name);
2566
 
  }
2567
 
  else
2568
 
  {
2569
 
     l_parasite.name = g_strdup("\0");
2570
 
  }
2571
 
 
2572
 
  /* read the parasitedata from file */
2573
 
  fread(l_parasite.data, l_parasite.size, 1, l_fp_pte);
2574
 
  fclose(l_fp_pte);
2575
 
 
2576
 
 
2577
 
  /* attach the parasite to gimp_obj_id
2578
 
   * (is an Image or drawable id depending on parasite_type)
2579
 
   */
2580
 
  if(parasite_props->parasite_type == XJT_IMAGE_PARASITE)
2581
 
  {
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);
2584
 
 
2585
 
  }
2586
 
  else
2587
 
  {
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);
2590
 
  }
2591
 
 
2592
 
  if(l_parasite.data) g_free(l_parasite.data);
2593
 
  if(l_parasite.name) g_free(l_parasite.name);
2594
 
 
2595
 
  return (0); /*OK */
2596
 
}       /* end p_create_and_attach_parasite */
2597
 
 
2598
 
/* ============================================================================
2599
 
 * p_check_and_add_parasite
2600
 
 *   find parasite by type and pos (obj_pos)
2601
 
 * ============================================================================
2602
 
 */
2603
 
static void
2604
 
p_check_and_add_parasite (gint32            gimp_obj_id,
2605
 
                          const gchar      *dirname,
2606
 
                          t_parasite_props *parasite_props,
2607
 
                          gint32            pos,
2608
 
                          t_parasitetype    parasite_type)
2609
 
{
2610
 
  t_parasite_props  *l_prop;
2611
 
 
2612
 
  l_prop = parasite_props;
2613
 
  while(l_prop)
2614
 
  {
2615
 
     if((l_prop->parasite_type == parasite_type)
2616
 
     && (l_prop->obj_pos == pos))
2617
 
     {
2618
 
        p_create_and_attach_parasite(gimp_obj_id, dirname, l_prop);
2619
 
     }
2620
 
     l_prop = (t_parasite_props *)l_prop->next;
2621
 
  }
2622
 
}       /* end p_check_and_add_parasite */
2623
 
 
2624
 
/* ============================================================================
2625
 
 * p_scann_layer_prop
2626
 
 *   scann one inputline for layer properties (also used for layer_mask props)
2627
 
 * ============================================================================
2628
 
 */
2629
 
static gint
2630
 
p_scann_layer_prop (gchar         *scan_ptr,
2631
 
                    t_image_props *image_prop)
2632
 
{
2633
 
 
2634
 
  t_layer_props  *l_new_prop;
2635
 
  t_parasite_props *l_parasite_prop;
2636
 
  gchar          *l_ptr;
2637
 
  t_param_prop    l_param;
2638
 
  t_proptype      l_prop_id;
2639
 
 
2640
 
  l_new_prop = p_new_layer_prop();
2641
 
 
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;
2645
 
 
2646
 
  if(*scan_ptr == 'L')
2647
 
  {
2648
 
    l_new_prop->has_alpha = TRUE;
2649
 
  }
2650
 
 
2651
 
  l_new_prop->layer_pos = strtol(&scan_ptr[1], &l_ptr, 10);   /*  Scan integer (base = 10)  */
2652
 
  if(l_ptr == scan_ptr)
2653
 
  {
2654
 
     g_printerr ("XJT: PRP file layer# missing, scanned bad line:\n%s\n", scan_ptr);
2655
 
     return -1;
2656
 
  }
2657
 
 
2658
 
  while(1)
2659
 
  {
2660
 
     l_ptr = p_skip_blanks(l_ptr);
2661
 
     l_ptr = p_scann_token(l_ptr, &l_param, &l_prop_id);
2662
 
 
2663
 
     switch(l_prop_id)
2664
 
     {
2665
 
       case PROP_END:
2666
 
            return 0;
2667
 
            break;
2668
 
       case PROP_ACTIVE_LAYER:
2669
 
            l_new_prop->active_layer = l_param.int_val1;
2670
 
            break;
2671
 
       case PROP_FLOATING_SELECTION:
2672
 
            l_new_prop->floating_selection = l_param.int_val1;
2673
 
            break;
2674
 
       case PROP_FLOATING_ATTACHED:
2675
 
            l_new_prop->floating_attached = l_param.int_val1;
2676
 
            break;
2677
 
       case PROP_OPACITY:
2678
 
            l_new_prop->opacity = l_param.flt_val1;
2679
 
            break;
2680
 
       case PROP_MODE:
2681
 
            l_new_prop->mode = p_to_GimpLayerModeEffects(l_param.int_val1);
2682
 
            break;
2683
 
       case PROP_VISIBLE:
2684
 
            l_new_prop->visible = p_invert(l_param.int_val1);
2685
 
            break;
2686
 
       case PROP_LINKED:
2687
 
            l_new_prop->linked = l_param.int_val1;
2688
 
            break;
2689
 
       case PROP_LOCK_ALPHA:
2690
 
            l_new_prop->lock_alpha = l_param.int_val1;
2691
 
            break;
2692
 
       case PROP_APPLY_MASK:
2693
 
            l_new_prop->apply_mask = l_param.int_val1;
2694
 
            break;
2695
 
       case PROP_EDIT_MASK:
2696
 
            l_new_prop->edit_mask = l_param.int_val1;
2697
 
            break;
2698
 
       case PROP_SHOW_MASK:
2699
 
            l_new_prop->show_mask = l_param.int_val1;
2700
 
            break;
2701
 
       case PROP_OFFSETS:
2702
 
            l_new_prop->offx = l_param.int_val1;
2703
 
            l_new_prop->offy = l_param.int_val2;
2704
 
            break;
2705
 
       case PROP_NAME:
2706
 
            l_new_prop->name  = l_param.string_val;
2707
 
            break;
2708
 
       case PROP_TATTOO:
2709
 
            l_new_prop->tattoo = l_param.int_val1;
2710
 
            break;
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)
2714
 
            {
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;
2718
 
            }
2719
 
 
2720
 
            if(l_parasite_prop)
2721
 
            {
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;
2725
 
            }
2726
 
            break;
2727
 
       default :
2728
 
            /* g_printerr ("XJT: PRP file scanned bad line:\n%s\n", scan_ptr); */
2729
 
            /* return -1; */ /* skip unknow tokens */
2730
 
            break;
2731
 
     }
2732
 
  }
2733
 
 
2734
 
}       /* end p_scann_layer_prop */
2735
 
 
2736
 
 
2737
 
/* ============================================================================
2738
 
 * p_scann_channel_prop
2739
 
 *   scann one inputline for channel properties (also used for layer_mask props)
2740
 
 * ============================================================================
2741
 
 */
2742
 
static gint
2743
 
p_scann_channel_prop (const gchar   *scan_ptr,
2744
 
                      t_image_props *image_prop)
2745
 
{
2746
 
 
2747
 
  t_channel_props  *l_new_prop;
2748
 
  t_parasite_props *l_parasite_prop;
2749
 
  gchar          *l_ptr;
2750
 
  t_param_prop    l_param;
2751
 
  t_proptype      l_prop_id;
2752
 
  t_parasitetype  l_parasite_type;
2753
 
 
2754
 
  l_new_prop = p_new_channel_prop();
2755
 
 
2756
 
  l_new_prop->channel_pos = strtol(&scan_ptr[1], &l_ptr, 10);   /*  Scan integer (base = 10)  */
2757
 
  if(l_ptr == scan_ptr)
2758
 
  {
2759
 
     g_printerr ("XJT: PRP file channel# missing, scanned bad line:\n%s\n",
2760
 
                 scan_ptr);
2761
 
     return -1;
2762
 
  }
2763
 
 
2764
 
  /* check if it is layer_mask or channel */
2765
 
  if(*scan_ptr == 'm')
2766
 
  {
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;
2771
 
  }
2772
 
  else
2773
 
  {
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;
2778
 
  }
2779
 
 
2780
 
 
2781
 
  while(1)
2782
 
  {
2783
 
     l_ptr = p_skip_blanks(l_ptr);
2784
 
     l_ptr = p_scann_token(l_ptr, &l_param, &l_prop_id);
2785
 
 
2786
 
     switch(l_prop_id)
2787
 
     {
2788
 
       case PROP_END:
2789
 
            return 0;
2790
 
            break;
2791
 
       case PROP_ACTIVE_CHANNEL:
2792
 
            l_new_prop->active_channel = l_param.int_val1;
2793
 
            break;
2794
 
       case PROP_SELECTION:
2795
 
            l_new_prop->selection = l_param.int_val1;
2796
 
            break;
2797
 
       case PROP_FLOATING_ATTACHED:
2798
 
            l_new_prop->floating_attached = l_param.int_val1;
2799
 
            break;
2800
 
       case PROP_OPACITY:
2801
 
            l_new_prop->opacity = l_param.flt_val1;
2802
 
            break;
2803
 
       case PROP_VISIBLE:
2804
 
            l_new_prop->visible = p_invert(l_param.int_val1);
2805
 
            break;
2806
 
       case PROP_SHOW_MASKED:
2807
 
            l_new_prop->show_masked = l_param.int_val1;
2808
 
            break;
2809
 
       case PROP_OFFSETS:
2810
 
            l_new_prop->offx = l_param.int_val1;
2811
 
            l_new_prop->offy = l_param.int_val2;
2812
 
            break;
2813
 
       case PROP_COLOR:
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;
2817
 
            break;
2818
 
       case PROP_NAME:
2819
 
            l_new_prop->name  = l_param.string_val;
2820
 
            break;
2821
 
       case PROP_TATTOO:
2822
 
            l_new_prop->tattoo = l_param.int_val1;
2823
 
            break;
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)
2827
 
            {
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;
2831
 
            }
2832
 
 
2833
 
            if(l_parasite_prop)
2834
 
            {
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;
2838
 
            }
2839
 
            break;
2840
 
       default :
2841
 
            /* g_printerr ("XJT: PRP file scanned bad line:\n%s\n", scan_ptr); */
2842
 
            /* return -1; */ /* skip unknow tokens */
2843
 
            break;
2844
 
     }
2845
 
  }
2846
 
 
2847
 
}       /* end p_scann_channel_prop */
2848
 
 
2849
 
/* ============================================================================
2850
 
 * p_scann_image_prop
2851
 
 *
2852
 
 * ============================================================================
2853
 
 */
2854
 
static gint
2855
 
p_scann_image_prop (gchar         *scan_ptr,
2856
 
                    t_image_props *image_prop)
2857
 
{
2858
 
  gchar            *l_ptr;
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;
2863
 
 
2864
 
  if(strncmp(scan_ptr, GIMP_XJ_IMAGE, strlen(GIMP_XJ_IMAGE)) != 0)
2865
 
  {
2866
 
    g_printerr ("XJT: PRP file %s identstring missing, scanned bad line:\n%s\n",
2867
 
                GIMP_XJ_IMAGE, scan_ptr);
2868
 
    return -1;
2869
 
  }
2870
 
 
2871
 
  l_ptr = &scan_ptr[strlen(GIMP_XJ_IMAGE)];
2872
 
 
2873
 
  while(1)
2874
 
  {
2875
 
     l_ptr = p_skip_blanks(l_ptr);
2876
 
     l_ptr = p_scann_token(l_ptr, &l_param, &l_prop_id);
2877
 
 
2878
 
     switch(l_prop_id)
2879
 
     {
2880
 
       case PROP_END:
2881
 
            return 0;
2882
 
            break;
2883
 
       case PROP_VERSION:
2884
 
            image_prop->version = l_param.string_val;
2885
 
            break;
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;
2890
 
            break;
2891
 
       case PROP_TYPE:
2892
 
            switch(l_param.int_val1)
2893
 
            {
2894
 
              case XJT_RGB:
2895
 
                image_prop->image_type = GIMP_RGB;
2896
 
                break;
2897
 
              case XJT_GRAY:
2898
 
                image_prop->image_type = GIMP_GRAY;
2899
 
                break;
2900
 
              default:
2901
 
                g_printerr ("XJT: PRP unsupported image_type %d\n",
2902
 
                            (int)l_param.int_val1);
2903
 
                return -1;
2904
 
                break;
2905
 
            }
2906
 
            break;
2907
 
       case PROP_DIMENSION:
2908
 
            image_prop->image_width = l_param.int_val1;
2909
 
            image_prop->image_height = l_param.int_val2;
2910
 
            break;
2911
 
       case PROP_UNIT:
2912
 
            image_prop->unit = p_to_GimpUnit(l_param.int_val1);
2913
 
            break;
2914
 
       case PROP_GUIDES:
2915
 
            l_guide_prop = p_new_guide_prop();
2916
 
            if(l_guide_prop)
2917
 
            {
2918
 
              l_guide_prop->next = image_prop->guide_props;
2919
 
              image_prop->guide_props = l_guide_prop;
2920
 
 
2921
 
              l_guide_prop->position = l_param.int_val1;
2922
 
              l_guide_prop->orientation = p_to_GimpOrientation(l_param.int_val2);
2923
 
            }
2924
 
            break;
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)
2928
 
            {
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;
2932
 
            }
2933
 
 
2934
 
            if(l_parasite_prop)
2935
 
            {
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;
2939
 
            }
2940
 
            break;
2941
 
       case PROP_RESOLUTION:
2942
 
            image_prop->xresolution = l_param.flt_val1;
2943
 
            image_prop->yresolution = l_param.flt_val2;
2944
 
            break;
2945
 
       case PROP_TATTOO:
2946
 
            image_prop->tattoo = l_param.int_val1;
2947
 
            break;
2948
 
       case PROP_TATTOO_STATE:
2949
 
            image_prop->tattoo_state = l_param.int_val1;
2950
 
            break;
2951
 
       default :
2952
 
            /* g_printerr ("XJT: Warning PRP unexpected token in line:\n%s\n", scan_ptr); */
2953
 
            /* return -1; */ /* skip unknow tokens */
2954
 
            break;
2955
 
     }
2956
 
  }
2957
 
}       /* end p_scann_image_prop */
2958
 
 
2959
 
 
2960
 
/* ============================================================================
2961
 
 * p_scann_parasite_prop
2962
 
 *   scann one inputline for parasite properties
2963
 
 * ============================================================================
2964
 
 */
2965
 
static gint
2966
 
p_scann_parasite_prop (const gchar   *scan_ptr,
2967
 
                       t_image_props *image_prop)
2968
 
{
2969
 
 
2970
 
  t_parasite_props  *l_new_prop;
2971
 
  gchar          *l_ptr;
2972
 
  t_param_prop    l_param;
2973
 
  t_proptype      l_prop_id;
2974
 
  gint32          l_parasite_id;
2975
 
 
2976
 
  l_parasite_id = strtol(&scan_ptr[1], &l_ptr, 10);   /*  Scan integer (base = 10)  */
2977
 
  if(l_ptr == scan_ptr)
2978
 
  {
2979
 
     g_printerr ("XJT: PRP file parasite# missing, scanned bad line:\n%s\n",
2980
 
                 scan_ptr);
2981
 
     return -1;
2982
 
  }
2983
 
 
2984
 
  l_new_prop = p_find_parasite(image_prop->parasite_props, l_parasite_id);
2985
 
  if(l_new_prop == NULL)
2986
 
  {
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;
2991
 
  }
2992
 
 
2993
 
  if(l_new_prop == NULL)
2994
 
  {
2995
 
     return -1;
2996
 
  }
2997
 
 
2998
 
  l_new_prop->parasite_id = l_parasite_id;
2999
 
 
3000
 
  while(1)
3001
 
  {
3002
 
     l_ptr = p_skip_blanks(l_ptr);
3003
 
     l_ptr = p_scann_token(l_ptr, &l_param, &l_prop_id);
3004
 
 
3005
 
     switch(l_prop_id)
3006
 
     {
3007
 
       case PROP_END:
3008
 
            return 0;
3009
 
            break;
3010
 
       case PROP_NAME:
3011
 
            l_new_prop->name  = l_param.string_val;
3012
 
            break;
3013
 
       case PROP_PARASITE_FLAGS:
3014
 
            l_new_prop->flags = l_param.int_val1;
3015
 
            break;
3016
 
       default :
3017
 
            /* g_printerr ("XJT: PRP file scanned bad line:\n%s\n", scan_ptr); */
3018
 
            /* return -1; */ /* skip unknow tokens */
3019
 
            break;
3020
 
     }
3021
 
  }
3022
 
}       /* end p_scann_parasite_prop */
3023
 
 
3024
 
 
3025
 
/* ============================================================================
3026
 
 * p_scann_path_prop
3027
 
 *   scann one inputline for path properties
3028
 
 * ============================================================================
3029
 
 */
3030
 
static gint
3031
 
p_scann_path_prop (gchar         *scan_ptr,
3032
 
                   t_image_props *image_prop)
3033
 
{
3034
 
  t_path_props  *l_new_prop;
3035
 
  gchar          *l_ptr;
3036
 
  t_param_prop    l_param;
3037
 
  t_proptype      l_prop_id;
3038
 
 
3039
 
  l_new_prop = p_new_path_prop ();
3040
 
 
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;
3044
 
 
3045
 
  if (strncmp (scan_ptr, "PATH", strlen ("PATH")) != 0)
3046
 
    {
3047
 
      g_printerr ("XJT: PRP scanned bad line:\n%s\n", scan_ptr);
3048
 
      return -1;
3049
 
    }
3050
 
  l_ptr = scan_ptr + strlen ("PATH");
3051
 
 
3052
 
  while (1)
3053
 
    {
3054
 
      l_ptr = p_skip_blanks (l_ptr);
3055
 
      l_ptr = p_scann_token (l_ptr, &l_param, &l_prop_id);
3056
 
 
3057
 
      switch (l_prop_id)
3058
 
        {
3059
 
        case PROP_END:
3060
 
          return 0;
3061
 
          break;
3062
 
        case PROP_PATH_TYPE:
3063
 
          l_new_prop->path_type = p_to_GimpPathType(l_param.int_val1);
3064
 
          break;
3065
 
        case PROP_PATH_LOCKED:
3066
 
          l_new_prop->path_locked = l_param.int_val1;
3067
 
          break;
3068
 
        case PROP_TATTOO:
3069
 
          l_new_prop->tattoo = l_param.int_val1;
3070
 
          break;
3071
 
        case PROP_NAME:
3072
 
          l_new_prop->name  = l_param.string_val;
3073
 
          break;
3074
 
        case PROP_PATH_CURRENT:
3075
 
          l_new_prop->current_flag = l_param.int_val1;
3076
 
          break;
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;
3080
 
          break;
3081
 
        default :
3082
 
          /* g_printerr ("XJT: PRP file scanned bad line:\n%s\n", scan_ptr); */
3083
 
          /* return -1; */ /* skip unknow tokens */
3084
 
          break;
3085
 
        }
3086
 
    }
3087
 
 
3088
 
}       /* end p_scann_path_prop */
3089
 
 
3090
 
 
3091
 
/* ============================================================================
3092
 
 * p_add_paths
3093
 
 * ============================================================================
3094
 
 */
3095
 
static void
3096
 
p_add_paths (gint32        image_id,
3097
 
             t_path_props *path_props)
3098
 
{
3099
 
  gchar     *l_current_pathname = NULL;
3100
 
  t_path_props  *l_prop;
3101
 
 
3102
 
  l_prop = path_props;
3103
 
  while (l_prop)
3104
 
    {
3105
 
      if(l_prop->num_points > 0)
3106
 
        {
3107
 
          if(xjt_debug)
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)
3113
 
            {
3114
 
              l_current_pathname = l_prop->name;
3115
 
            }
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)
3120
 
            {
3121
 
              gimp_path_set_tattoo(image_id, l_prop->name, l_prop->tattoo);
3122
 
            }
3123
 
        }
3124
 
      l_prop = (t_path_props *)l_prop->next;
3125
 
    }
3126
 
 
3127
 
  if(l_current_pathname)
3128
 
    {
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);
3131
 
    }
3132
 
}       /* end p_add_paths */
3133
 
 
3134
 
 
3135
 
static gchar *
3136
 
p_load_linefile (const gchar *filename,
3137
 
                 gint32      *len)
3138
 
{
3139
 
  FILE *l_fp;
3140
 
  struct stat  stat_buf;
3141
 
  gchar  *l_file_buff;
3142
 
  gint32  l_idx;
3143
 
 
3144
 
  *len = 0;
3145
 
  /* get file length */
3146
 
  if (0 != g_stat(filename, &stat_buf))
3147
 
  {
3148
 
    return(NULL);
3149
 
  }
3150
 
  *len = stat_buf.st_size;
3151
 
 
3152
 
  l_file_buff = g_malloc0(*len +1);
3153
 
 
3154
 
  /* read file into buffer */
3155
 
  l_fp = g_fopen(filename, "rb");
3156
 
  if(l_fp == NULL)
3157
 
  {
3158
 
    return(NULL);
3159
 
  }
3160
 
  fread(l_file_buff, *len, 1, l_fp);
3161
 
  fclose(l_fp);
3162
 
 
3163
 
  /* replace all '\n' characters by '\0' */
3164
 
  for(l_idx = 0; l_idx < *len; l_idx++)
3165
 
  {
3166
 
    if(l_file_buff[l_idx] == '\n')
3167
 
    {
3168
 
      l_file_buff[l_idx] = '\0';
3169
 
    }
3170
 
  }
3171
 
 
3172
 
  return(l_file_buff);
3173
 
}
3174
 
 
3175
 
 
3176
 
static gint32
3177
 
p_next_lineindex (const gchar *file_buff,
3178
 
                  gint32       max_len,
3179
 
                  gint32       pos)
3180
 
{
3181
 
  if (pos < 0)
3182
 
    return (-1);
3183
 
 
3184
 
  while (pos < max_len)
3185
 
    {
3186
 
      if (file_buff[pos] == '\0')
3187
 
        {
3188
 
          pos++;
3189
 
          break;
3190
 
        }
3191
 
      pos++;
3192
 
    }
3193
 
  return (pos >= max_len) ? -1 : pos;
3194
 
}
3195
 
 
3196
 
/* ============================================================================
3197
 
 * p_load_prop_file
3198
 
 *   read all properties from file "PRP"
3199
 
 *   and return the information in a t_image_props stucture
3200
 
 * ============================================================================
3201
 
 */
3202
 
 
3203
 
static t_image_props *
3204
 
p_load_prop_file (const gchar *prop_filename)
3205
 
{
3206
 
  gint32 l_filesize;
3207
 
  gint32 l_line_idx;
3208
 
  gchar *l_file_buff;
3209
 
  gchar *l_line_ptr;
3210
 
  gchar *l_ptr;
3211
 
  t_image_props *l_image_prop;
3212
 
  gint  l_rc;
3213
 
 
3214
 
  if(xjt_debug) printf("p_load_prop_file: %s\n", prop_filename);
3215
 
 
3216
 
  l_rc = -1;
3217
 
  l_image_prop = p_new_image_prop();
3218
 
 
3219
 
  l_file_buff = p_load_linefile(prop_filename, &l_filesize);
3220
 
  if(l_file_buff == NULL)
3221
 
  {
3222
 
    g_message(_("Error: Could not read XJT property file '%s'."),
3223
 
               gimp_filename_to_utf8 (prop_filename));
3224
 
    goto cleanup;
3225
 
  }
3226
 
  if(l_filesize == 0)
3227
 
  {
3228
 
    g_message(_("Error: XJT property file '%s' is empty."),
3229
 
               gimp_filename_to_utf8 (prop_filename));
3230
 
    goto cleanup;
3231
 
  }
3232
 
 
3233
 
  /* parse 1.st line (image properties) */
3234
 
  l_line_idx = 0;
3235
 
  l_line_ptr = l_file_buff;
3236
 
 
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);
3239
 
  if(l_rc != 0)
3240
 
  {
3241
 
    goto cleanup;
3242
 
  }
3243
 
 
3244
 
  while(1)
3245
 
  {
3246
 
     l_line_idx = p_next_lineindex(l_file_buff, l_filesize, l_line_idx);
3247
 
 
3248
 
     if(l_line_idx < 0)
3249
 
     {
3250
 
        break;   /* end of file */
3251
 
     }
3252
 
     l_line_ptr = &l_file_buff[l_line_idx];
3253
 
 
3254
 
     if(xjt_debug) printf("\nXJT:PRP_LINE:%s:\n", l_line_ptr);
3255
 
 
3256
 
     l_ptr = p_skip_blanks(&l_line_ptr[0]);
3257
 
 
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 */
3261
 
 
3262
 
     if((*l_ptr == 'l') || (*l_ptr == 'L'))
3263
 
     {
3264
 
         l_rc = p_scann_layer_prop(l_line_ptr, l_image_prop);
3265
 
         l_image_prop->n_layers++;
3266
 
     }
3267
 
     else
3268
 
     {
3269
 
       if((*l_ptr == 'c') || (*l_ptr == 'm'))
3270
 
       {
3271
 
         l_rc = p_scann_channel_prop(l_line_ptr, l_image_prop);
3272
 
         l_image_prop->n_channels++;
3273
 
       }
3274
 
       else
3275
 
       {
3276
 
         if(*l_ptr == 'p')
3277
 
         {
3278
 
           l_rc = p_scann_parasite_prop(l_line_ptr, l_image_prop);
3279
 
         }
3280
 
         else
3281
 
         {
3282
 
           if(*l_ptr == 'P')
3283
 
           {
3284
 
             l_rc = p_scann_path_prop(l_line_ptr, l_image_prop);
3285
 
           }
3286
 
           else
3287
 
           {
3288
 
             g_printerr ("XJT: Warning, undefined PRP line scanned:\n%s\n",
3289
 
                         l_line_ptr);
3290
 
             /* goto cleanup; */
3291
 
           }
3292
 
         }
3293
 
       }
3294
 
     }
3295
 
  }
3296
 
 
3297
 
 
3298
 
cleanup:
3299
 
  g_free(l_file_buff);
3300
 
 
3301
 
  return (l_rc) ? NULL : l_image_prop;
3302
 
}       /* end p_load_prop_file */
3303
 
 
3304
 
 
3305
 
/* ---------------------- LOAD  -------------------------- */
3306
 
 
3307
 
static gint32
3308
 
load_xjt_image (const gchar *filename)
3309
 
{
3310
 
  int     l_rc;
3311
 
  int     l_len;
3312
 
  gchar  *l_dirname;
3313
 
  gchar  *l_prop_file;
3314
 
  gchar  *l_jpg_file;
3315
 
  gchar  *l_cmd;
3316
 
 
3317
 
  gint32 *l_layers_list;
3318
 
  gint32 *l_channels_list;
3319
 
  gint32  l_layer_id;
3320
 
  gint32  l_channel_id;
3321
 
  gint32  l_image_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;
3330
 
 
3331
 
  l_rc = -1;  /* init retcode to Errorstate */
3332
 
  l_image_id = -1;
3333
 
  l_layers_list = NULL;
3334
 
  l_channels_list = NULL;
3335
 
  l_image_prp_ptr = NULL;
3336
 
  l_dirname = NULL;
3337
 
  l_prop_file = NULL;
3338
 
  l_jpg_file = 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 */
3343
 
 
3344
 
  gimp_progress_init_printf (_("Opening '%s'"),
3345
 
                             gimp_filename_to_utf8 (filename));
3346
 
 
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);
3350
 
 
3351
 
  if(g_mkdir(l_dirname, 0777) != 0)
3352
 
    {
3353
 
      g_message (_("Could not create working folder '%s': %s"),
3354
 
                  gimp_filename_to_utf8 (l_dirname), g_strerror (errno));
3355
 
      goto cleanup;
3356
 
    }
3357
 
 
3358
 
 
3359
 
  /* prepare for extract tar files directly from filename into l_dirname */
3360
 
  if((*filename == G_DIR_SEPARATOR)
3361
 
     || (filename[1] == ':'))
3362
 
    {
3363
 
      /* filename with absolute path */
3364
 
      l_cmd = g_strdup_printf("cd %s; tar -xf \"%s\"; cd ..", l_dirname, filename);
3365
 
    }
3366
 
  else
3367
 
    {
3368
 
      /* filename with relative path */
3369
 
      l_cmd = g_strdup_printf("cd %s; tar -xf \"..%c%s\" *; cd ..", l_dirname, G_DIR_SEPARATOR, filename);
3370
 
    }
3371
 
 
3372
 
  l_len = strlen(filename);
3373
 
  if(l_len > 3)
3374
 
    {
3375
 
      /* call optional extracompression programs gzip or bzip2
3376
 
       * (depends on filename's extension)
3377
 
       *
3378
 
       * used gzip options: (bzip2 uses the same options)
3379
 
       *     -c --stdout --to-stdout
3380
 
       *          Write  output  on  standard  output
3381
 
       *     -d --decompress --uncompress
3382
 
       *          Decompress.
3383
 
       *     -f --force
3384
 
       *           Force compression or decompression even if the file
3385
 
       */
3386
 
      if(strcmp(&filename[l_len - 3], "bz2") == 0)
3387
 
        {
3388
 
          g_free(l_cmd);
3389
 
          l_cmd = g_strdup_printf("bunzip2 <\"%s\" >\"%s%carc.tar\"",filename , l_dirname, G_DIR_SEPARATOR);
3390
 
          l_rc = p_system(l_cmd);
3391
 
          g_free(l_cmd);
3392
 
          l_cmd = g_strdup_printf("cd %s; tar -xf arc.tar; cd ..", l_dirname);
3393
 
        }
3394
 
      else if(strcmp(&filename[l_len - 2], "gz") == 0)
3395
 
        {
3396
 
          g_free(l_cmd);
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);
3399
 
          g_free(l_cmd);
3400
 
          l_cmd = g_strdup_printf("cd %s; tar -xf arc.tar; cd ..", l_dirname);
3401
 
        }
3402
 
    }
3403
 
 
3404
 
 
3405
 
  /* now we can extract the unpacked tar archive */
3406
 
  l_rc = p_system(l_cmd);
3407
 
  g_free(l_cmd);
3408
 
 
3409
 
  if (l_rc != 0)
3410
 
    goto cleanup;
3411
 
 
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)
3415
 
    {  l_rc = -1;
3416
 
    goto cleanup;
3417
 
    }
3418
 
 
3419
 
 
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);
3424
 
  if(l_image_id < 0)
3425
 
    { l_rc = -1;
3426
 
    goto cleanup;
3427
 
    }
3428
 
 
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);
3434
 
 
3435
 
  p_check_and_add_parasite(l_image_id,
3436
 
                           l_dirname,
3437
 
                           l_image_prp_ptr->parasite_props,
3438
 
                           0,
3439
 
                           XJT_IMAGE_PARASITE);
3440
 
  /* load all layers */
3441
 
 
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)
3445
 
    {
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);
3448
 
 
3449
 
      l_layer_id = xjpg_load_layer (l_jpg_file,
3450
 
                                    l_image_id,
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);
3455
 
 
3456
 
      g_free(l_jpg_file);
3457
 
      if(l_layer_id < 0)
3458
 
        {
3459
 
          l_rc = -1;
3460
 
          break;
3461
 
        }
3462
 
 
3463
 
      if(l_layer_prp_ptr->floating_selection)
3464
 
        {
3465
 
          l_fsel_id = l_layer_id;    /* this layer is the floating selection */
3466
 
        }
3467
 
      else
3468
 
        {
3469
 
          /* add the layer on top of the images layerstak */
3470
 
          gimp_image_add_layer (l_image_id, l_layer_id, 0);
3471
 
 
3472
 
          if(l_layer_prp_ptr->floating_attached)
3473
 
            {
3474
 
              l_fsel_attached_to_id = l_layer_id;    /* the floating selection is attached to this layer */
3475
 
            }
3476
 
        }
3477
 
 
3478
 
      /* check for alpha channel */
3479
 
      if(l_layer_prp_ptr->has_alpha)
3480
 
        {
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);
3483
 
 
3484
 
          if( xjpg_load_layer_alpha (l_jpg_file, l_image_id, l_layer_id) != 0)
3485
 
            {
3486
 
              l_rc = -1;
3487
 
              break;
3488
 
            }
3489
 
          g_free(l_jpg_file);
3490
 
        }
3491
 
 
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)
3498
 
        {
3499
 
         gimp_drawable_set_tattoo (l_layer_id, l_layer_prp_ptr->tattoo);
3500
 
        }
3501
 
 
3502
 
      if (l_layer_prp_ptr->active_layer)
3503
 
        {
3504
 
          l_active_layer_id = l_layer_id;
3505
 
        }
3506
 
 
3507
 
      /* Handle layer parasites */
3508
 
      p_check_and_add_parasite (l_layer_id,
3509
 
                                l_dirname,
3510
 
                                l_image_prp_ptr->parasite_props,
3511
 
                                l_layer_prp_ptr->layer_pos,
3512
 
                                XJT_LAYER_PARASITE);
3513
 
 
3514
 
 
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)
3519
 
        {
3520
 
          if (l_channel_prp_ptr->channel_pos == l_layer_prp_ptr->layer_pos)
3521
 
            {
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);
3525
 
 
3526
 
              l_channel_id = gimp_layer_create_mask (l_layer_id, 0 /* mask_type 0 = WHITE_MASK */ );
3527
 
 
3528
 
              /* load should overwrite the layer_mask with data from jpeg file */
3529
 
 
3530
 
              l_channel_id = xjpg_load_channel (l_jpg_file,
3531
 
                                                l_image_id,
3532
 
                                                l_channel_id,
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);
3538
 
              g_free(l_jpg_file);
3539
 
              if(l_channel_id >= 0)
3540
 
                {
3541
 
 
3542
 
                  /* attach the layer_mask to the layer (with identical offsets) */
3543
 
                  gimp_layer_add_mask (l_layer_id, l_channel_id);
3544
 
 
3545
 
                  if (l_channel_prp_ptr->floating_attached)
3546
 
                    {
3547
 
                      l_fsel_attached_to_id = l_channel_id;    /* the floating selection is attached to this layer_mask */
3548
 
                    }
3549
 
 
3550
 
                  if (l_channel_prp_ptr->tattoo >= 0)
3551
 
                    {
3552
 
                      gimp_drawable_set_tattoo (l_channel_id,
3553
 
                                                l_channel_prp_ptr->tattoo);
3554
 
                    }
3555
 
 
3556
 
                  /* gimp_layer_set_offsets(l_channel_id, l_layer_prp_ptr->offx, l_layer_prp_ptr->offy); */
3557
 
 
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);
3561
 
 
3562
 
                  /* Handle layermask parasites */
3563
 
                  p_check_and_add_parasite (l_channel_id,
3564
 
                                            l_dirname,
3565
 
                                            l_image_prp_ptr->parasite_props,
3566
 
                                            l_channel_prp_ptr->channel_pos,
3567
 
                                            XJT_LAYER_MASK_PARASITE);
3568
 
                }
3569
 
              break;
3570
 
            }
3571
 
        }    /* end search for layermask */
3572
 
    }
3573
 
 
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)
3578
 
    {
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",
3582
 
                             l_jpg_file);
3583
 
 
3584
 
      l_channel_id = xjpg_load_channel (l_jpg_file,
3585
 
                                        l_image_id,
3586
 
                                        -1,
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);
3592
 
 
3593
 
      g_free (l_jpg_file);
3594
 
      if (l_channel_id < 0)
3595
 
        {
3596
 
          l_rc = -1;
3597
 
          break;
3598
 
        }
3599
 
 
3600
 
      /* Handle channel parasites */
3601
 
      p_check_and_add_parasite (l_channel_id,
3602
 
                                l_dirname,
3603
 
                                l_image_prp_ptr->parasite_props,
3604
 
                                l_channel_prp_ptr->channel_pos,
3605
 
                                XJT_CHANNEL_PARASITE);
3606
 
 
3607
 
      if (l_channel_prp_ptr->tattoo >= 0)
3608
 
        {
3609
 
          gimp_drawable_set_tattoo (l_channel_id, l_channel_prp_ptr->tattoo);
3610
 
        }
3611
 
 
3612
 
      if (l_channel_prp_ptr->selection)
3613
 
        {
3614
 
          if (xjt_debug) printf ("XJT-DEBUG: SELECTION loaded channel id = %d\n",
3615
 
                                 (int) l_channel_id);
3616
 
 
3617
 
          gimp_selection_load (l_channel_id);
3618
 
 
3619
 
          /* delete the channel after load into selection */
3620
 
          gimp_drawable_delete (l_channel_id);
3621
 
        }
3622
 
      else
3623
 
        {
3624
 
          /* add channel on top of the channelstack */
3625
 
          gimp_image_add_channel (l_image_id, l_channel_id, 0);
3626
 
 
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);
3630
 
 
3631
 
          if (l_channel_prp_ptr->floating_attached)
3632
 
            {
3633
 
              l_fsel_attached_to_id = l_channel_id;    /* the floating_selection is attached to this channel */
3634
 
            }
3635
 
 
3636
 
          if (l_channel_prp_ptr->active_channel)
3637
 
            {
3638
 
              l_active_channel_id = l_channel_id;
3639
 
            }
3640
 
        }
3641
 
    }
3642
 
 
3643
 
  /* attach the floating selection... */
3644
 
  if ((l_fsel_id >= 0) && (l_fsel_attached_to_id >= 0))
3645
 
    {
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)
3649
 
        {
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)
3652
 
           */
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);
3655
 
        }
3656
 
    }
3657
 
 
3658
 
  /* set active layer/channel */
3659
 
  if (l_active_channel_id >= 0)
3660
 
    {
3661
 
      if (xjt_debug) printf("SET active channel\n");
3662
 
 
3663
 
      gimp_image_set_active_channel (l_image_id, l_active_channel_id);
3664
 
    }
3665
 
 
3666
 
  if (l_active_layer_id >= 0)
3667
 
    {
3668
 
      if (xjt_debug) printf("SET active layer\n");
3669
 
 
3670
 
      gimp_image_set_active_layer (l_image_id, l_active_layer_id);
3671
 
    }
3672
 
 
3673
 
  /* set guides */
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)
3677
 
    {
3678
 
      if (l_guide_prp_ptr->orientation == GIMP_ORIENTATION_HORIZONTAL)
3679
 
        gimp_image_add_hguide (l_image_id, l_guide_prp_ptr->position);
3680
 
      else
3681
 
        gimp_image_add_vguide (l_image_id, l_guide_prp_ptr->position);
3682
 
    }
3683
 
 
3684
 
  /* create paths */
3685
 
  if (l_image_prp_ptr->path_props)
3686
 
    {
3687
 
      p_add_paths (l_image_id, l_image_prp_ptr->path_props);
3688
 
    }
3689
 
 
3690
 
  /* set tattoo_state */
3691
 
  if (l_image_prp_ptr->tattoo_state > 0)
3692
 
    {
3693
 
      gimp_image_set_tattoo_state (l_image_id, l_image_prp_ptr->tattoo_state);
3694
 
    }
3695
 
 
3696
 
 cleanup:
3697
 
 
3698
 
  g_free (l_layers_list);
3699
 
  g_free (l_channels_list);
3700
 
 
3701
 
  /* remove the temorary directory */
3702
 
  l_cmd = g_strdup_printf ("rm -rf \"%s\"", l_dirname);
3703
 
  p_system (l_cmd);
3704
 
  g_free (l_cmd);
3705
 
 
3706
 
  g_free (l_dirname);
3707
 
  g_free (l_prop_file);
3708
 
  g_free (l_jpg_file);
3709
 
 
3710
 
  if (l_rc == 0)
3711
 
    {
3712
 
      return l_image_id;             /* all done OK */
3713
 
    }
3714
 
 
3715
 
  /* destroy the tmp image */
3716
 
  gimp_image_delete (l_image_id);
3717
 
  return -1;
3718
 
}