19
19
# "Perlized" from C source by Manish Singh <yosh@gimp.org>
22
$author = $copyright = 'Josh MacDonald';
27
my ($type, $name, $desc, $example) = @_;
28
push @inargs, { name => $name, type => 'string', no_success => 1,
29
desc => qq/comma separated list of $desc this handler
30
can $type (i.e. "$example")/ }
40
push @inargs, { name => 'procedure_name', type => 'string',
41
desc => "The name of the procedure to be used for $action",
44
foreach ([ 'extensions', 'jpg,jpeg' ], [ 'prefixes', 'http:,ftp:' ]) {
45
&list_arg($type, $_->[0], @$_);
52
$blurb = 'Loads a file by invoking the right load handler.';
22
$blurb = 'Loads an image file by invoking the right load handler.';
55
25
This procedure invokes the correct file load handler using magic if possible,
60
30
and the full pathname will not look like a URL."
33
&josh_pdb_misc('1997');
67
type => 'enum GimpRunMode (no GIMP_RUN_WITH_LAST_VALS)',
68
desc => 'The run mode: %%desc%%' },
69
{ name => 'filename', type => 'string', no_validate => 1,
70
desc => 'The name of the file to load' },
71
{ name => 'raw_filename', type => 'string', no_validate => 1,
72
desc => 'The name as entered by the user' }
37
type => 'enum GimpRunMode (no GIMP_RUN_WITH_LAST_VALS)',
38
desc => 'The run mode' },
39
{ name => 'filename', type => 'string', no_validate => 1,
40
desc => 'The name of the file to load' },
41
{ name => 'raw_filename', type => 'string', no_validate => 1,
42
desc => 'The name as entered by the user' }
75
@outargs = ( &std_image_arg );
76
$outargs[0]->{desc} = 'The output image';
46
{ name => 'image', type => 'image',
47
desc => 'The output image' }
79
proc => [ 'proc->name', 'new_args' ],
80
args => [ 'new_args', 'return_vals' ],
81
vars => [ 'PlugInProcDef *file_proc', 'const ProcRecord *proc',
82
'gchar *uri', 'gint i' ],
85
uri = file_utils_filename_to_uri (gimp->load_procs, %%filename%%, NULL);
54
GValueArray *new_args;
55
GValueArray *return_vals;
56
GimpPlugInProcedure *file_proc;
61
uri = file_utils_filename_to_uri (gimp,
62
g_value_get_string (&args->values[1]),
66
return gimp_procedure_get_return_values (procedure, FALSE);
90
file_proc = file_utils_find_proc (gimp->load_procs, uri);
69
file_utils_find_proc (gimp->plug_in_manager->load_procs, uri, NULL);
97
proc = plug_in_proc_def_get_proc (file_proc);
99
new_args = g_new0 (%%argtype%%, proc->num_args);
100
memcpy (new_args, args, sizeof (%%argtype%%) * 3);
74
return gimp_procedure_get_return_values (procedure, FALSE);
76
proc = GIMP_PROCEDURE (file_proc);
78
new_args = gimp_procedure_get_arguments (proc);
80
for (i = 0; i < 3; i++)
81
g_value_transform (&args->values[i], &new_args->values[i]);
102
83
for (i = 3; i < proc->num_args; i++)
104
new_args[i].arg_type = proc->args[i].arg_type;
105
if (proc->args[i].arg_type == GIMP_PDB_STRING)
106
new_args[i].value.pdb_pointer = g_strdup ("");
109
return_vals = %%exec%%;
84
if (G_IS_PARAM_SPEC_STRING (proc->args[i]))
85
g_value_set_static_string (&new_args->values[i], "");
88
gimp_pdb_execute_procedure_by_name_args (gimp->pdb,
90
GIMP_OBJECT (proc)->name,
93
g_value_array_free (new_args);
112
95
return return_vals;
101
sub file_load_layer {
102
$blurb = 'Loads an image file as a layer for an existing image.';
105
This procedure behaves like the file-load procedure but opens the specified
106
image as a layer for an existing image. The returned layer needs to be
107
added to the existing image with gimp_image_add_layer().
110
&neo_pdb_misc('2005', '2.4');
113
{ name => 'run_mode',
114
type => 'enum GimpRunMode (no GIMP_RUN_WITH_LAST_VALS)',
115
desc => 'The run mode' },
116
{ name => 'image', type => 'image',
117
desc => 'Destination image' },
118
{ name => 'filename', type => 'string', no_validate => 1,
119
desc => 'The name of the file to load' }
123
{ name => 'layer', type => 'layer',
124
desc => 'The layer created when loading the image file' }
130
gchar *uri = file_utils_filename_to_uri (gimp, filename, NULL);
135
GimpPDBStatusType status;
137
layers = file_open_layers (gimp, context, progress,
139
uri, run_mode, NULL, &status, NULL);
143
layer = layers->data;
144
g_list_free (layers);
156
sub file_load_layers {
157
$blurb = 'Loads an image file as layers for an existing image.';
160
This procedure behaves like the file-load procedure but opens the specified
161
image as layers for an existing image. The returned layers needs to be
162
added to the existing image with gimp_image_add_layer().
165
&mitch_pdb_misc('2006', '2.4');
168
{ name => 'run_mode',
169
type => 'enum GimpRunMode (no GIMP_RUN_WITH_LAST_VALS)',
170
desc => 'The run mode' },
171
{ name => 'image', type => 'image',
172
desc => 'Destination image' },
173
{ name => 'filename', type => 'string', no_validate => 1,
174
desc => 'The name of the file to load' }
178
{ name => 'layer_ids', type => 'int32array',
179
desc => 'The list of loaded layers',
180
array => { name => 'num_layers',
181
desc => 'The number of loaded layers' } }
187
gchar *uri = file_utils_filename_to_uri (gimp, filename, NULL);
192
GimpPDBStatusType status;
194
layers = file_open_layers (gimp, context, progress,
196
uri, run_mode, NULL, &status, NULL);
203
num_layers = g_list_length (layers);
205
layer_ids = g_new (gint32, num_layers);
207
for (i = 0, list = layers;
209
i++, list = g_list_next (list))
210
layer_ids[i] = gimp_item_get_ID (GIMP_ITEM (list->data));
212
g_list_free (layers);
119
225
$blurb = 'Saves a file by extension.';
236
&josh_pdb_misc('1997');
133
{ name => 'run_mode',
134
type => 'enum GimpRunMode (no GIMP_RUN_WITH_LAST_VALS)',
135
desc => 'The run mode: %%desc%%' },
136
{ name => 'image', type => 'image',
137
desc => 'Input image' },
138
{ name => 'drawable', type => 'drawable',
139
desc => 'Drawable to save' },
140
{ name => 'filename', type => 'string', no_validate => 1,
141
desc => 'The name of the file to save the image in' },
142
{ name => 'raw_filename', type => 'string', no_validate => 1,
143
desc => 'The name as entered by the user' }
239
{ name => 'run_mode', type => 'enum GimpRunMode',
240
desc => 'The run mode' },
241
{ name => 'image', type => 'image',
242
desc => 'Input image' },
243
{ name => 'drawable', type => 'drawable',
244
desc => 'Drawable to save' },
245
{ name => 'filename', type => 'string', no_validate => 1,
246
desc => 'The name of the file to save the image in' },
247
{ name => 'raw_filename', type => 'string', no_validate => 1,
248
desc => 'The name as entered by the user' }
148
headers => [ qw(<string.h>) ],
149
proc => [ 'proc->name', 'new_args' ],
150
args => [ 'new_args', 'return_vals' ],
151
vars => [ 'PlugInProcDef *file_proc', 'const ProcRecord *proc',
152
'gchar *uri', 'gint i' ],
252
headers => [ qw(<string.h>) ],
155
uri = file_utils_filename_to_uri (gimp->load_procs, %%filename%%, NULL);
256
GValueArray *new_args;
257
GValueArray *return_vals;
258
GimpPlugInProcedure *file_proc;
263
uri = file_utils_filename_to_uri (gimp,
264
g_value_get_string (&args->values[3]),
268
return gimp_procedure_get_return_values (procedure, FALSE);
160
file_proc = file_utils_find_proc (gimp->save_procs, uri);
271
file_utils_find_proc (gimp->plug_in_manager->save_procs, uri, NULL);
167
proc = plug_in_proc_def_get_proc (file_proc);
169
new_args = g_new0 (%%argtype%%, proc->num_args);
170
memcpy (new_args, args, sizeof (%%argtype%%) * 5);
276
return gimp_procedure_get_return_values (procedure, FALSE);
278
proc = GIMP_PROCEDURE (file_proc);
280
new_args = gimp_procedure_get_arguments (proc);
282
for (i = 0; i < 5; i++)
283
g_value_transform (&args->values[i], &new_args->values[i]);
172
285
for (i = 5; i < proc->num_args; i++)
174
new_args[i].arg_type = proc->args[i].arg_type;
175
if (proc->args[i].arg_type == GIMP_PDB_STRING)
176
new_args[i].value.pdb_pointer = g_strdup ("");
179
return_vals = %%exec%%;
286
if (G_IS_PARAM_SPEC_STRING (proc->args[i]))
287
g_value_set_static_string (&new_args->values[i], "");
289
return_vals = gimp_pdb_execute_procedure_by_name_args (gimp->pdb,
291
GIMP_OBJECT (proc)->name,
294
g_value_array_free (new_args);
182
296
return return_vals;
201
315
$date = '1999-2003';
204
{ name => 'filename', type => 'string', no_validate => 1,
205
desc => 'The name of the file that owns the thumbnail to load' },
318
{ name => 'filename', type => 'string', no_validate => 1,
319
desc => 'The name of the file that owns the thumbnail to load' }
209
{ name => 'width', type => 'int32', init => 1,
210
desc => 'The width of the thumbnail' },
211
{ name => 'height', type => 'int32', init => 1,
212
desc => 'The height of the thumbnail' },
213
{ name => 'thumb_data', type => 'int8array', init => 1,
214
desc => 'The thumbnail data',
215
array => { name => 'thumbnail_data_count',
216
desc => 'The number of bytes in thumbnail data',
217
alias => 'num_bytes', init => 1 } },
323
{ name => 'width', type => 'int32',
324
desc => 'The width of the thumbnail' },
325
{ name => 'height', type => 'int32',
326
desc => 'The height of the thumbnail' },
327
{ name => 'thumb_data', type => 'int8array',
328
desc => 'The thumbnail data',
329
array => { name => 'thumb_data_count',
330
desc => 'The number of bytes in thumbnail data' } }
221
vars => [ 'gchar *uri',
222
'GimpThumbnail *thumbnail = NULL',
223
'GdkPixbuf *pixbuf = NULL' ],
226
uri = g_filename_to_uri (filename, NULL, NULL);
230
thumbnail = gimp_thumbnail_new ();
231
gimp_thumbnail_set_uri (thumbnail, uri);
233
pixbuf = gimp_thumbnail_load_thumb (thumbnail,
234
GIMP_THUMBNAIL_SIZE_NORMAL,
336
GdkPixbuf *pixbuf = file_utils_load_thumbnail (filename);
240
width = gdk_pixbuf_get_width (pixbuf);
241
height = gdk_pixbuf_get_height (pixbuf);
243
if (gdk_pixbuf_get_n_channels (pixbuf) != 3)
245
GdkPixbuf *tmp = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8,
248
gdk_pixbuf_composite_color (pixbuf, tmp,
249
0, 0, width, height, 0, 0, 1.0, 1.0,
250
GDK_INTERP_NEAREST, 255,
251
0, 0, GIMP_CHECK_SIZE_SM,
252
0x66666666, 0x99999999);
254
g_object_unref (pixbuf);
258
num_bytes = 3 * width * height;
259
thumb_data = g_memdup (gdk_pixbuf_get_pixels (pixbuf), num_bytes);
340
width = gdk_pixbuf_get_width (pixbuf);
341
height = gdk_pixbuf_get_height (pixbuf);
342
thumb_data_count = 3 * width * height;
343
thumb_data = g_memdup (gdk_pixbuf_get_pixels (pixbuf),
261
346
g_object_unref (pixbuf);
285
364
explicitely save a thumbnail with a file.
367
&josh_pdb_misc('1997');
292
{ name => 'filename', type => 'string', no_validate => 1,
293
desc => 'The name of the file the thumbnail belongs to' },
370
{ name => 'image', type => 'image',
371
desc => 'The image' },
372
{ name => 'filename', type => 'string', no_validate => 1,
373
desc => 'The name of the file the thumbnail belongs to' },
297
vars => [ 'GimpImagefile *imagefile', 'gchar *uri',
298
'const gchar *image_uri' ],
301
image_uri = gimp_object_get_name (GIMP_OBJECT (gimage));
307
uri = g_filename_to_uri (filename, NULL, NULL);
313
if (strcmp (uri, image_uri))
318
imagefile = gimp_imagefile_new (gimp, uri);
319
success = gimp_imagefile_save_thumbnail (imagefile, NULL, gimage);
320
g_object_unref (imagefile);
379
success = file_utils_save_thumbnail (image, filename);
335
389
Generates a unique filename using the temp path supplied in the user's gimprc.
392
&josh_pdb_misc('1997');
341
{ name => 'extension', type => 'string', no_validate => 1,
342
desc => 'The extension the file will have' }
395
{ name => 'extension', type => 'string', no_validate => 1,
396
desc => 'The extension the file will have' }
346
{ name => 'name', type => 'string', init => 1,
347
desc => 'The new temp filename' }
400
{ name => 'name', type => 'string',
401
desc => 'The new temp filename' }
351
headers => [ qw(<process.h>
352
"config/gimpbaseconfig.h"
353
"config/gimpconfig-path.h") ],
354
vars => [ 'static gint id = 0', 'static gint pid',
355
'gchar *filename', 'gchar *path' ],
361
filename = g_strdup_printf ("gimp_temp_%d%d.%s",
362
pid, id++, extension);
364
path = gimp_config_path_expand (GIMP_BASE_CONFIG (gimp->config)->temp_path,
367
name = g_build_filename (path, filename, NULL);
407
name = gimp_get_temp_filename (gimp, extension);
386
&handler_args('load');
387
&list_arg('load', 'magics', 'magic file information', '0,string,GIF');
424
{ name => 'procedure_name', type => 'string',
425
desc => 'The name of the procedure to be used for loading' },
426
{ name => 'extensions', type => 'string', no_success => 1,
427
desc => 'comma separated list of extensions this handler
428
can load (i.e. "jpg,jpeg")' },
429
{ name => 'prefixes', type => 'string', no_success => 1,
430
desc => 'comma separated list of prefixes this handler
431
can load (i.e. "http:,ftp:")' },
432
{ name => 'magics', type => 'string', no_success => 1,
433
desc => 'comma separated list of magic file information
434
this handler can load (i.e. "0,string,GIF")' }
390
vars => [ 'ProcRecord *proc', 'PlugInProcDef *file_proc' ],
395
proc = procedural_db_lookup (gimp, name);
397
if (proc && ((proc->num_args < 3) ||
398
(proc->num_values < 1) ||
399
(proc->args[0].arg_type != GIMP_PDB_INT32) ||
400
(proc->args[1].arg_type != GIMP_PDB_STRING) ||
401
(proc->args[2].arg_type != GIMP_PDB_STRING) ||
402
(proc->values[0].arg_type != GIMP_PDB_IMAGE)))
404
g_message ("load handler \"%s\" does not take the standard load handler args",
409
file_proc = plug_ins_file_register_magic (gimp, name,
410
extensions, prefixes, magics);
414
g_message ("attempt to register non-existant load handler \"%s\"",
419
if (! g_slist_find (gimp->load_procs, file_proc))
420
gimp->load_procs = g_slist_prepend (gimp->load_procs, file_proc);
440
gchar *canonical = gimp_canonicalize_identifier (procedure_name);
442
success = gimp_plug_in_manager_register_load_handler (gimp->plug_in_manager,
444
extensions, prefixes, magics);
440
&handler_args('load');
463
{ name => 'procedure_name', type => 'string',
464
desc => 'The name of the procedure to be used for loading' },
465
{ name => 'extensions', type => 'string', no_success => 1,
466
desc => 'comma separated list of extensions this handler
467
can load (i.e. "jpg,jpeg")' },
468
{ name => 'prefixes', type => 'string', no_success => 1,
469
desc => 'comma separated list of prefixes this handler
470
can load (i.e. "http:,ftp:")' }
443
pass_through => 'register_magic_load_handler',
444
pass_args => [ 0..2 ],
445
make_args => [ { type => 'string', code => '%%arg%% = NULL;' } ]
477
gchar *canonical = gimp_canonicalize_identifier (procedure_name);
479
success = gimp_plug_in_manager_register_load_handler (gimp->plug_in_manager,
481
extensions, prefixes, NULL);
459
&handler_args('save');
500
{ name => 'procedure_name', type => 'string',
501
desc => 'The name of the procedure to be used for saving' },
502
{ name => 'extensions', type => 'string', no_success => 1,
503
desc => 'comma separated list of extensions this handler
504
can save (i.e. "jpg,jpeg")' },
505
{ name => 'prefixes', type => 'string', no_success => 1,
506
desc => 'comma separated list of prefixes this handler
507
can save (i.e. "http:,ftp:")' }
462
vars => [ 'ProcRecord *proc', 'PlugInProcDef *file_proc' ],
467
proc = procedural_db_lookup (gimp, name);
469
if (proc && ((proc->num_args < 5) ||
470
(proc->args[0].arg_type != GIMP_PDB_INT32) ||
471
(proc->args[1].arg_type != GIMP_PDB_IMAGE) ||
472
(proc->args[2].arg_type != GIMP_PDB_DRAWABLE) ||
473
(proc->args[3].arg_type != GIMP_PDB_STRING) ||
474
(proc->args[4].arg_type != GIMP_PDB_STRING)))
476
g_message ("save handler \"%s\" does not take the standard save handler args",
481
file_proc = plug_ins_file_register_magic (gimp, name,
482
extensions, prefixes, NULL);
486
g_message ("attempt to register non-existant save handler \"%s\"",
491
if (! g_slist_find (gimp->save_procs, file_proc))
492
gimp->save_procs = g_slist_prepend (gimp->save_procs, file_proc);
513
gchar *canonical = gimp_canonicalize_identifier (procedure_name);
515
success = gimp_plug_in_manager_register_save_handler (gimp->plug_in_manager,
517
extensions, prefixes);
511
$author = $copyright = 'Sven Neumann';
534
&neo_pdb_misc('2004', '2.2');
516
{ name => 'procedure_name', type => 'string', alias => 'name',
517
desc => "The name of the procedure to associate a MIME type with." },
518
{ name => 'mime_type', type => 'string',
519
desc => "A single MIME type, like for example \"image/jpeg\"." }
537
{ name => 'procedure_name', type => 'string',
538
desc => "The name of the procedure to associate a MIME type with." },
539
{ name => 'mime_type', type => 'string',
540
desc => "A single MIME type, like for example \"image/jpeg\"." }
525
success = (plug_ins_file_register_mime (gimp, name, mime_type) != NULL);
546
gchar *canonical = gimp_canonicalize_identifier (procedure_name);
548
success = gimp_plug_in_manager_register_mime_type (gimp->plug_in_manager,
549
canonical, mime_type);
532
558
$blurb = 'Associates a thumbnail loader with a file load procedure.';
534
560
$help = <<'HELP';
535
Some file formats allow for embedded thumbnails, other file formats contain a scalable image or provide the image data in different resolutions. A file plug-in for such a format may register a special procedure that allows GIMP to load a thumbnail preview of the image. This procedure is then associated with the standard load procedure using this function.
561
Some file formats allow for embedded thumbnails, other file formats
562
contain a scalable image or provide the image data in different
563
resolutions. A file plug-in for such a format may register a special
564
procedure that allows GIMP to load a thumbnail preview of the
565
image. This procedure is then associated with the standard load
566
procedure using this function.
538
$author = $copyright = 'Sven Neumann';
569
&neo_pdb_misc('2004', '2.2');
543
{ name => 'load_proc', type => 'string',
544
desc => "The name of the procedure the thumbnail loader with." },
545
{ name => 'thumb_proc', type => 'string',
546
desc => "The name of the thumbnail load procedure." }
572
{ name => 'load_proc', type => 'string',
573
desc => "The name of the procedure the thumbnail loader with." },
574
{ name => 'thumb_proc', type => 'string',
575
desc => "The name of the thumbnail load procedure." }
551
success = (plug_ins_file_register_thumb_loader (gimp,
553
thumb_proc) != NULL);
580
gchar *canonical = gimp_canonicalize_identifier (load_proc);
582
success = gimp_plug_in_manager_register_thumb_loader (gimp->plug_in_manager,
583
canonical, thumb_proc);
559
@headers = qw(<sys/types.h> <unistd.h> <gdk-pixbuf/gdk-pixbuf.h>
560
"libgimpbase/gimpbase.h" "libgimpthumb/gimpthumb.h"
561
"core/gimp.h" "core/gimpimagefile.h"
562
"plug-in/plug-in.h" "plug-in/plug-ins.h"
563
"plug-in/plug-in-proc-def.h"
592
@headers = qw("libgimpbase/gimpbase.h"
593
"libgimpconfig/gimpconfig.h"
596
"plug-in/gimppluginmanager.h"
597
"plug-in/gimppluginmanager-file.h"
564
600
"file/file-utils.h");
566
@procs = qw(file_load file_save file_load_thumbnail file_save_thumbnail
567
temp_name register_magic_load_handler register_load_handler
568
register_save_handler register_file_handler_mime
602
@procs = qw(file_load file_load_layer file_load_layers
604
file_load_thumbnail file_save_thumbnail
606
register_magic_load_handler register_load_handler
607
register_save_handler
608
register_file_handler_mime
569
609
register_thumbnail_loader);
570
%exports = (app => [@procs], lib => [@procs[0,1,4..9]]);
611
%exports = (app => [@procs], lib => [@procs[0..3,5..11]]);
572
613
$desc = 'File Operations';