49
49
typedef GimpImage * GimpXcfLoaderFunc (Gimp *gimp,
53
static Argument * xcf_load_invoker (Gimp *gimp,
55
GimpProgress *progress,
57
static Argument * xcf_save_invoker (Gimp *gimp,
59
GimpProgress *progress,
63
static ProcArg xcf_load_args[] =
70
"The name of the file to load, in the on-disk character set and encoding" },
73
"The basename of the file, in UTF-8" }
76
static ProcArg xcf_load_return_vals[] =
83
static PlugInProcDef xcf_plug_in_load_proc =
88
GIMP_ICON_TYPE_STOCK_ID,
91
NULL, /* ignored for load */
92
0, /* ignored for load */
97
"loads file saved in the .xcf file format",
98
"The xcf file format has been designed specifically for loading and "
99
"saving tiled and layered images in the GIMP. This procedure will load "
100
"the specified file.",
101
"Spencer Kimball & Peter Mattis",
102
"Spencer Kimball & Peter Mattis",
109
xcf_load_return_vals,
110
{ { xcf_load_invoker } },
114
"0,string,gimp\\040xcf\\040",
116
NULL, /* fill me in at runtime */
117
NULL, /* fill me in at runtime */
118
NULL /* fill me in at runtime */
121
static ProcArg xcf_save_args[] =
131
"Active drawable of input image" },
134
"The name of the file to save the image in, in the on-disk character set and encoding" },
137
"The basename of the file, in UTF-8" }
140
static PlugInProcDef xcf_plug_in_save_proc =
143
N_("GIMP XCF image"),
145
GIMP_ICON_TYPE_STOCK_ID,
148
"RGB*, GRAY*, INDEXED*",
149
0, /* fill me in at runtime */
154
"saves file in the .xcf file format",
155
"The xcf file format has been designed specifically for loading and "
156
"saving tiled and layered images in the GIMP. This procedure will save "
157
"the specified image in the xcf file format.",
158
"Spencer Kimball & Peter Mattis",
159
"Spencer Kimball & Peter Mattis",
167
{ { xcf_save_invoker } },
173
NULL, /* fill me in at runtime */
174
NULL, /* fill me in at runtime */
175
NULL /* fill me in at runtime */
179
static GimpXcfLoaderFunc *xcf_loaders[] =
53
static GValueArray * xcf_load_invoker (GimpProcedure *procedure,
56
GimpProgress *progress,
57
const GValueArray *args);
58
static GValueArray * xcf_save_invoker (GimpProcedure *procedure,
61
GimpProgress *progress,
62
const GValueArray *args);
65
static GimpXcfLoaderFunc * const xcf_loaders[] =
181
67
xcf_load_image, /* version 0 */
182
68
xcf_load_image, /* version 1 */
197
86
* though they are internal. The only thing it requires is using a
198
87
* PlugInProcDef struct. -josh
200
procedural_db_register (gimp, &xcf_plug_in_save_proc.db_info);
201
xcf_plug_in_save_proc.image_types_val =
202
plug_ins_image_types_parse (xcf_plug_in_save_proc.image_types);
203
plug_ins_add_internal (gimp, &xcf_plug_in_save_proc);
205
procedural_db_register (gimp, &xcf_plug_in_load_proc.db_info);
206
xcf_plug_in_load_proc.image_types_val =
207
plug_ins_image_types_parse (xcf_plug_in_load_proc.image_types);
208
plug_ins_add_internal (gimp, &xcf_plug_in_load_proc);
91
procedure = gimp_plug_in_procedure_new (GIMP_PLUGIN, "gimp-xcf-save");
92
procedure->proc_type = GIMP_INTERNAL;
93
procedure->marshal_func = xcf_save_invoker;
95
proc = GIMP_PLUG_IN_PROCEDURE (procedure);
96
proc->menu_label = g_strdup (N_("GIMP XCF image"));
97
gimp_plug_in_procedure_set_icon (proc, GIMP_ICON_TYPE_STOCK_ID,
98
(const guint8 *) "gimp-wilber",
99
strlen ("gimp-wilber") + 1);
100
gimp_plug_in_procedure_set_image_types (proc, "RGB*, GRAY*, INDEXED*");
101
gimp_plug_in_procedure_set_file_proc (proc, "xcf", "", NULL);
102
gimp_plug_in_procedure_set_mime_type (proc, "image/xcf");
104
gimp_object_set_static_name (GIMP_OBJECT (procedure), "gimp-xcf-save");
105
gimp_procedure_set_static_strings (procedure,
107
"Saves file in the .xcf file format",
108
"The XCF file format has been designed "
109
"specifically for loading and saving "
110
"tiled and layered images in the GIMP. "
111
"This procedure will save the specified "
112
"image in the xcf file format.",
113
"Spencer Kimball & Peter Mattis",
114
"Spencer Kimball & Peter Mattis",
118
gimp_procedure_add_argument (procedure,
119
gimp_param_spec_int32 ("dummy-param",
122
G_MININT32, G_MAXINT32, 0,
123
GIMP_PARAM_READWRITE));
124
gimp_procedure_add_argument (procedure,
125
gimp_param_spec_image_id ("image",
129
GIMP_PARAM_READWRITE));
130
gimp_procedure_add_argument (procedure,
131
gimp_param_spec_drawable_id ("drawable",
133
"Active drawable of input image",
135
GIMP_PARAM_READWRITE));
136
gimp_procedure_add_argument (procedure,
137
gimp_param_spec_string ("filename",
139
"The name of the file "
140
"to save the image in, "
145
GIMP_PARAM_READWRITE));
146
gimp_procedure_add_argument (procedure,
147
gimp_param_spec_string ("raw-filename",
149
"The basename of the "
152
GIMP_PARAM_READWRITE));
153
gimp_plug_in_manager_add_procedure (gimp->plug_in_manager, proc);
154
g_object_unref (procedure);
157
procedure = gimp_plug_in_procedure_new (GIMP_PLUGIN, "gimp-xcf-load");
158
procedure->proc_type = GIMP_INTERNAL;
159
procedure->marshal_func = xcf_load_invoker;
161
proc = GIMP_PLUG_IN_PROCEDURE (procedure);
162
proc->menu_label = g_strdup (N_("GIMP XCF image"));
163
gimp_plug_in_procedure_set_icon (proc, GIMP_ICON_TYPE_STOCK_ID,
164
(const guint8 *) "gimp-wilber",
165
strlen ("gimp-wilber") + 1);
166
gimp_plug_in_procedure_set_image_types (proc, NULL);
167
gimp_plug_in_procedure_set_file_proc (proc, "xcf", "",
168
"0,string,gimp\\040xcf\\040");
169
gimp_plug_in_procedure_set_mime_type (proc, "image/xcf");
171
gimp_object_set_static_name (GIMP_OBJECT (procedure), "gimp-xcf-load");
172
gimp_procedure_set_static_strings (procedure,
174
"Loads file saved in the .xcf file format",
175
"The XCF file format has been designed "
176
"specifically for loading and saving "
177
"tiled and layered images in the GIMP. "
178
"This procedure will load the specified "
180
"Spencer Kimball & Peter Mattis",
181
"Spencer Kimball & Peter Mattis",
185
gimp_procedure_add_argument (procedure,
186
gimp_param_spec_int32 ("dummy-param",
189
G_MININT32, G_MAXINT32, 0,
190
GIMP_PARAM_READWRITE));
191
gimp_procedure_add_argument (procedure,
192
gimp_param_spec_string ("filename",
194
"The name of the file "
199
GIMP_PARAM_READWRITE));
200
gimp_procedure_add_argument (procedure,
201
gimp_param_spec_string ("raw-filename",
203
"The basename of the "
206
GIMP_PARAM_READWRITE));
208
gimp_procedure_add_return_value (procedure,
209
gimp_param_spec_image_id ("image",
213
GIMP_PARAM_READWRITE));
214
gimp_plug_in_manager_add_procedure (gimp->plug_in_manager, proc);
215
g_object_unref (procedure);
247
257
info.ref_count = NULL;
248
258
info.compression = COMPRESS_NONE;
262
gchar *name = g_filename_display_name (filename);
263
gchar *msg = g_strdup_printf (_("Opening '%s'"), name);
265
gimp_progress_start (progress, msg, FALSE);
252
info.cp += xcf_read_int8 (info.fp, (guint8*) id, 14);
273
info.cp += xcf_read_int8 (info.fp, (guint8 *) id, 14);
254
if (strncmp (id, "gimp xcf ", 9) != 0)
258
else if (strcmp (id+9, "file") == 0)
260
info.file_version = 0;
275
if (! g_str_has_prefix (id, "gimp xcf "))
279
else if (strcmp (id + 9, "file") == 0)
281
info.file_version = 0;
262
283
else if (id[9] == 'v')
264
info.file_version = atoi (id + 10);
285
info.file_version = atoi (id + 10);
273
if (info.file_version < G_N_ELEMENTS (xcf_loaders))
275
gimage = (*(xcf_loaders[info.file_version])) (gimp, &info);
294
if (info.file_version >= 0 &&
295
info.file_version < G_N_ELEMENTS (xcf_loaders))
297
image = (*(xcf_loaders[info.file_version])) (gimp, &info);
282
g_message (_("XCF error: unsupported XCF file version %d "
283
"encountered"), info.file_version);
304
gimp_message (gimp, G_OBJECT (progress), GIMP_MESSAGE_ERROR,
305
_("XCF error: unsupported XCF file version %d "
306
"encountered"), info.file_version);
288
311
fclose (info.fp);
314
gimp_progress_end (progress);
291
g_message (_("Could not open '%s' for reading: %s"),
292
gimp_filename_to_utf8 (filename), g_strerror (errno));
318
gimp_message (gimp, G_OBJECT (progress), GIMP_MESSAGE_ERROR,
319
_("Could not open '%s' for reading: %s"),
320
gimp_filename_to_utf8 (filename), g_strerror (errno));
294
return_args = procedural_db_return_args (&xcf_plug_in_load_proc.db_info,
323
return_vals = gimp_procedure_get_return_values (procedure, success);
298
return_args[1].value.pdb_int = gimp_image_get_ID (gimage);
326
gimp_value_set_image (&return_vals->values[1], image);
300
328
gimp_unset_busy (gimp);
306
xcf_save_invoker (Gimp *gimp,
307
GimpContext *context,
308
GimpProgress *progress,
334
xcf_save_invoker (GimpProcedure *procedure,
336
GimpContext *context,
337
GimpProgress *progress,
338
const GValueArray *args)
312
Argument *return_args;
341
GValueArray *return_vals;
314
343
const gchar *filename;
315
gboolean success = FALSE;
344
gboolean success = FALSE;
317
346
gimp_set_busy (gimp);
319
gimage = gimp_image_get_by_ID (gimp, args[1].value.pdb_int);
320
filename = args[3].value.pdb_pointer;
348
image = gimp_value_get_image (&args->values[1], gimp);
349
filename = g_value_get_string (&args->values[3]);
322
info.fp = fopen (filename, "wb");
351
info.fp = g_fopen (filename, "wb");
356
info.progress = progress;
327
358
info.filename = filename;
328
359
info.active_layer = NULL;
334
365
info.ref_count = NULL;
335
366
info.compression = COMPRESS_RLE;
337
xcf_save_choose_format (&info, gimage);
339
success = xcf_save_image (&info, gimage);
370
gchar *name = g_filename_display_name (filename);
371
gchar *msg = g_strdup_printf (_("Saving '%s'"), name);
373
gimp_progress_start (progress, msg, FALSE);
379
xcf_save_choose_format (&info, image);
381
success = xcf_save_image (&info, image);
340
383
if (fclose (info.fp) == EOF)
342
g_message (_("Error saving XCF file: %s"), g_strerror (errno));
385
gimp_message (gimp, G_OBJECT (progress), GIMP_MESSAGE_ERROR,
386
_("Error saving XCF file: %s"), g_strerror (errno));
392
gimp_progress_end (progress);
348
g_message (_("Could not open '%s' for writing: %s"),
349
gimp_filename_to_utf8 (filename), g_strerror (errno));
396
gimp_message (gimp, G_OBJECT (progress), GIMP_MESSAGE_ERROR,
397
_("Could not open '%s' for writing: %s"),
398
gimp_filename_to_utf8 (filename), g_strerror (errno));
351
return_args = procedural_db_return_args (&xcf_plug_in_save_proc.db_info,
401
return_vals = gimp_procedure_get_return_values (procedure, success);
354
403
gimp_unset_busy (gimp);