1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
|
# GIMP - The GNU Image Manipulation Program
# Copyright (C) 1995, 1996, 1997 Spencer Kimball and Peter Mattis
# Copyright (C) 1997 Josh MacDonald
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# "Perlized" from C source by Manish Singh <yosh@gimp.org>
sub file_load {
$blurb = 'Loads an image file by invoking the right load handler.';
$help = <<'HELP';
This procedure invokes the correct file load handler using magic if
possible, and falling back on the file's extension and/or prefix if
not. The name of the file to load is typically a full pathname, and
the name entered is what the user actually typed before prepending a
directory path. The reason for this is that if the user types
https://www.gimp.org/foo.png he wants to fetch a URL, and the full
pathname will not look like a URL.
HELP
&josh_pdb_misc('1997');
@inargs = (
{ name => 'run_mode',
type => 'enum GimpRunMode (no GIMP_RUN_WITH_LAST_VALS)',
desc => 'The run mode' },
{ name => 'filename', type => 'string', allow_non_utf8 => 1,
desc => 'The name of the file to load' },
{ name => 'raw_filename', type => 'string', allow_non_utf8 => 1,
desc => 'The name as entered by the user' }
);
@outargs = (
{ name => 'image', type => 'image',
desc => 'The output image' }
);
%invoke = (
no_marshalling => 1,
code => <<'CODE'
{
GimpValueArray *new_args;
GimpValueArray *return_vals;
GimpPlugInProcedure *file_proc;
GimpProcedure *proc;
GFile *file;
gint i;
file = file_utils_filename_to_file (gimp,
g_value_get_string (gimp_value_array_index (args, 1)),
error);
if (! file)
return gimp_procedure_get_return_values (procedure, FALSE,
error ? *error : NULL);
file_proc = gimp_plug_in_manager_file_procedure_find (gimp->plug_in_manager,
GIMP_FILE_PROCEDURE_GROUP_OPEN,
file, error);
if (! file_proc)
{
g_object_unref (file);
return gimp_procedure_get_return_values (procedure, FALSE,
error ? *error : NULL);
}
proc = GIMP_PROCEDURE (file_proc);
new_args = gimp_procedure_get_arguments (proc);
g_value_transform (gimp_value_array_index (args, 0),
gimp_value_array_index (new_args, 0));
if (file_proc->handles_uri)
g_value_take_string (gimp_value_array_index (new_args, 1),
g_file_get_uri (file));
else
g_value_transform (gimp_value_array_index (args, 1),
gimp_value_array_index (new_args, 1));
g_value_transform (gimp_value_array_index (args, 2),
gimp_value_array_index (new_args, 2));
for (i = 3; i < proc->num_args; i++)
if (G_IS_PARAM_SPEC_STRING (proc->args[i]))
g_value_set_static_string (gimp_value_array_index (new_args, i), "");
return_vals =
gimp_pdb_execute_procedure_by_name_args (gimp->pdb,
context, progress, error,
gimp_object_get_name (proc),
new_args);
gimp_value_array_unref (new_args);
if (g_value_get_enum (gimp_value_array_index (return_vals, 0)) ==
GIMP_PDB_SUCCESS)
{
if (gimp_value_array_length (return_vals) > 1 &&
GIMP_VALUE_HOLDS_IMAGE_ID (gimp_value_array_index (return_vals, 1)))
{
GimpImage *image =
gimp_value_get_image (gimp_value_array_index (return_vals, 1),
gimp);
gimp_image_set_load_proc (image, file_proc);
}
}
g_object_unref (file);
return return_vals;
}
CODE
);
}
sub file_load_layer {
$blurb = 'Loads an image file as a layer for an existing image.';
$help = <<'HELP';
This procedure behaves like the file-load procedure but opens the specified
image as a layer for an existing image. The returned layer needs to be
added to the existing image with gimp_image_insert_layer().
HELP
&neo_pdb_misc('2005', '2.4');
@inargs = (
{ name => 'run_mode',
type => 'enum GimpRunMode (no GIMP_RUN_WITH_LAST_VALS)',
desc => 'The run mode' },
{ name => 'image', type => 'image',
desc => 'Destination image' },
{ name => 'filename', type => 'string', allow_non_utf8 => 1,
desc => 'The name of the file to load' }
);
@outargs = (
{ name => 'layer', type => 'layer',
desc => 'The layer created when loading the image file' }
);
%invoke = (
code => <<'CODE'
{
GFile *file = file_utils_filename_to_file (gimp, filename, error);
if (file)
{
GList *layers;
GimpPDBStatusType status;
layers = file_open_layers (gimp, context, progress,
image, FALSE,
file, run_mode, NULL, &status, error);
g_object_unref (file);
if (layers)
{
layer = layers->data;
g_list_free (layers);
}
else
success = FALSE;
}
else
success = FALSE;
}
CODE
);
}
sub file_load_layers {
$blurb = 'Loads an image file as layers for an existing image.';
$help = <<'HELP';
This procedure behaves like the file-load procedure but opens the specified
image as layers for an existing image. The returned layers needs to be
added to the existing image with gimp_image_insert_layer().
HELP
&mitch_pdb_misc('2006', '2.4');
@inargs = (
{ name => 'run_mode',
type => 'enum GimpRunMode (no GIMP_RUN_WITH_LAST_VALS)',
desc => 'The run mode' },
{ name => 'image', type => 'image',
desc => 'Destination image' },
{ name => 'filename', type => 'string', allow_non_utf8 => 1,
desc => 'The name of the file to load' }
);
@outargs = (
{ name => 'layer_ids', type => 'int32array',
desc => 'The list of loaded layers',
array => { name => 'num_layers',
desc => 'The number of loaded layers' } }
);
%invoke = (
code => <<'CODE'
{
GFile *file = file_utils_filename_to_file (gimp, filename, error);
if (file)
{
GList *layers;
GimpPDBStatusType status;
layers = file_open_layers (gimp, context, progress,
image, FALSE,
file, run_mode, NULL, &status, error);
g_object_unref (file);
if (layers)
{
GList *list;
gint i;
num_layers = g_list_length (layers);
layer_ids = g_new (gint32, num_layers);
for (i = 0, list = layers;
i < num_layers;
i++, list = g_list_next (list))
layer_ids[i] = gimp_item_get_ID (GIMP_ITEM (list->data));
g_list_free (layers);
}
else
success = FALSE;
}
else
success = FALSE;
}
CODE
);
}
sub file_save {
$blurb = 'Saves a file by extension.';
$help = <<'HELP';
This procedure invokes the correct file save handler according to the
file's extension and/or prefix. The name of the file to save is
typically a full pathname, and the name entered is what the user
actually typed before prepending a directory path. The reason for this
is that if the user types https://www.gimp.org/foo.png she wants to
fetch a URL, and the full pathname will not look like a URL.
HELP
&josh_pdb_misc('1997');
@inargs = (
{ name => 'run_mode', type => 'enum GimpRunMode',
desc => 'The run mode' },
{ name => 'image', type => 'image',
desc => 'Input image' },
{ name => 'drawable', type => 'drawable',
desc => 'Drawable to save' },
{ name => 'filename', type => 'string', allow_non_utf8 => 1,
desc => 'The name of the file to save the image in' },
{ name => 'raw_filename', type => 'string', allow_non_utf8 => 1,
desc => 'The name as entered by the user' }
);
%invoke = (
headers => [ qw(<string.h>) ],
no_marshalling => 1,
code => <<'CODE'
{
GimpValueArray *new_args;
GimpValueArray *return_vals;
GimpPlugInProcedure *file_proc;
GimpProcedure *proc;
GFile *file;
gint i;
file = file_utils_filename_to_file (gimp,
g_value_get_string (gimp_value_array_index (args, 3)),
error);
if (! file)
return gimp_procedure_get_return_values (procedure, FALSE,
error ? *error : NULL);
file_proc = gimp_plug_in_manager_file_procedure_find (gimp->plug_in_manager,
GIMP_FILE_PROCEDURE_GROUP_SAVE,
file, NULL);
if (! file_proc)
file_proc = gimp_plug_in_manager_file_procedure_find (gimp->plug_in_manager,
GIMP_FILE_PROCEDURE_GROUP_EXPORT,
file, error);
if (! file_proc)
{
g_object_unref (file);
return gimp_procedure_get_return_values (procedure, FALSE,
error ? *error : NULL);
}
proc = GIMP_PROCEDURE (file_proc);
new_args = gimp_procedure_get_arguments (proc);
g_value_transform (gimp_value_array_index (args, 0),
gimp_value_array_index (new_args, 0));
g_value_transform (gimp_value_array_index (args, 1),
gimp_value_array_index (new_args, 1));
g_value_transform (gimp_value_array_index (args, 2),
gimp_value_array_index (new_args, 2));
if (file_proc->handles_uri)
g_value_take_string (gimp_value_array_index (new_args, 3),
g_file_get_uri (file));
else
g_value_transform (gimp_value_array_index (args, 3),
gimp_value_array_index (new_args, 3));
g_value_transform (gimp_value_array_index (args, 4),
gimp_value_array_index (new_args, 4));
for (i = 5; i < proc->num_args; i++)
if (G_IS_PARAM_SPEC_STRING (proc->args[i]))
g_value_set_static_string (gimp_value_array_index (new_args, i), "");
return_vals =
gimp_pdb_execute_procedure_by_name_args (gimp->pdb,
context, progress, error,
gimp_object_get_name (proc),
new_args);
gimp_value_array_unref (new_args);
g_object_unref (file);
return return_vals;
}
CODE
);
}
sub file_load_thumbnail {
$blurb = 'Loads the thumbnail for a file.';
$help = <<'HELP';
This procedure tries to load a thumbnail that belongs to the file with
the given filename. This name is a full pathname. The returned data is
an array of colordepth 3 (RGB), regardless of the image type. Width and
height of the thumbnail are also returned. Don't use this function if
you need a thumbnail of an already opened image, use gimp_image_thumbnail()
instead.
HELP
$author = $copyright = 'Adam D. Moss, Sven Neumann';
$date = '1999-2003';
@inargs = (
{ name => 'filename', type => 'string', allow_non_utf8 => 1,
desc => 'The name of the file that owns the thumbnail to load' }
);
@outargs = (
{ name => 'width', type => 'int32',
desc => 'The width of the thumbnail' },
{ name => 'height', type => 'int32',
desc => 'The height of the thumbnail' },
{ name => 'thumb_data', type => 'int8array',
desc => 'The thumbnail data',
array => { name => 'thumb_data_count',
desc => 'The number of bytes in thumbnail data' } }
);
%invoke = (
code => <<'CODE'
{
GdkPixbuf *pixbuf = file_utils_load_thumbnail (filename);
if (pixbuf)
{
width = gdk_pixbuf_get_width (pixbuf);
height = gdk_pixbuf_get_height (pixbuf);
thumb_data_count = 3 * width * height;
thumb_data = g_memdup (gdk_pixbuf_get_pixels (pixbuf),
thumb_data_count);
g_object_unref (pixbuf);
}
else
success = FALSE;
}
CODE
);
}
sub file_save_thumbnail {
$blurb = 'Saves a thumbnail for the given image';
$help = <<'HELP';
This procedure saves a thumbnail for the given image according to the
Free Desktop Thumbnail Managing Standard. The thumbnail is saved so
that it belongs to the file with the given filename. This means you
have to save the image under this name first, otherwise this procedure
will fail. This procedure may become useful if you want to
explicitly save a thumbnail with a file.
HELP
&josh_pdb_misc('1997');
@inargs = (
{ name => 'image', type => 'image',
desc => 'The image' },
{ name => 'filename', type => 'string', allow_non_utf8 => 1,
desc => 'The name of the file the thumbnail belongs to' },
);
%invoke = (
code => <<'CODE'
{
success = file_utils_save_thumbnail (image, filename);
}
CODE
);
}
sub register_magic_load_handler {
$blurb = 'Registers a file load handler procedure.';
$help = <<'HELP';
Registers a procedural database procedure to be called to load files of a
particular file format using magic file information.
HELP
&std_pdb_misc;
@inargs = (
{ name => 'procedure_name', type => 'string', non_empty => 1,
desc => 'The name of the procedure to be used for loading' },
{ name => 'extensions', type => 'string', no_validate => 1,
desc => 'comma separated list of extensions this handler
can load (i.e. "jpg,jpeg")' },
{ name => 'prefixes', type => 'string', no_validate => 1,
desc => 'comma separated list of prefixes this handler
can load (i.e. "http:,ftp:")' },
{ name => 'magics', type => 'string', no_validate => 1,
desc => 'comma separated list of magic file information
this handler can load (i.e. "0,string,GIF")' }
);
%invoke = (
code => <<'CODE'
{
gchar *canonical = gimp_canonicalize_identifier (procedure_name);
success = gimp_plug_in_manager_register_load_handler (gimp->plug_in_manager,
canonical,
extensions, prefixes, magics);
g_free (canonical);
}
CODE
);
}
sub register_load_handler {
$blurb = 'Registers a file load handler procedure.';
$help = <<'HELP';
Registers a procedural database procedure to be called to load files of a
particular file format.
HELP
&std_pdb_misc;
@inargs = (
{ name => 'procedure_name', type => 'string', non_empty => 1,
desc => 'The name of the procedure to be used for loading' },
{ name => 'extensions', type => 'string', no_validate => 1,
desc => 'comma separated list of extensions this handler
can load (i.e. "jpg,jpeg")' },
{ name => 'prefixes', type => 'string', no_validate => 1,
desc => 'comma separated list of prefixes this handler
can load (i.e. "http:,ftp:")' }
);
%invoke = (
code => <<'CODE'
{
gchar *canonical = gimp_canonicalize_identifier (procedure_name);
success = gimp_plug_in_manager_register_load_handler (gimp->plug_in_manager,
canonical,
extensions, prefixes, NULL);
g_free (canonical);
}
CODE
);
}
sub register_save_handler {
$blurb = 'Registers a file save handler procedure.';
$help = <<'HELP';
Registers a procedural database procedure to be called to save files in a
particular file format.
HELP
&std_pdb_misc;
@inargs = (
{ name => 'procedure_name', type => 'string', non_empty => 1,
desc => 'The name of the procedure to be used for saving' },
{ name => 'extensions', type => 'string', no_validate => 1,
desc => 'comma separated list of extensions this handler
can save (i.e. "jpg,jpeg")' },
{ name => 'prefixes', type => 'string', no_validate => 1,
desc => 'comma separated list of prefixes this handler
can save (i.e. "http:,ftp:")' }
);
%invoke = (
code => <<'CODE'
{
gchar *canonical = gimp_canonicalize_identifier (procedure_name);
success = gimp_plug_in_manager_register_save_handler (gimp->plug_in_manager,
canonical,
extensions, prefixes);
g_free (canonical);
}
CODE
);
}
sub register_file_handler_priority {
$blurb = 'Sets the priority of a file handler procedure.';
$help = <<'HELP';
Sets the priority of a file handler procedure. When more than one
procedure matches a given file, the procedure with the lowest priority
is used; if more than one procedure has the lowest priority, it is
unspecified which one of them is used. The default priority for file
handler procedures is 0.
HELP
&ell_pdb_misc('2018', '2.10.6');
@inargs = (
{ name => 'procedure_name', type => 'string', non_empty => 1,
desc => "The name of the procedure to set the priority of." },
{ name => 'priority', type => 'int32',
desc => "The procedure priority." }
);
%invoke = (
code => <<'CODE'
{
gchar *canonical = gimp_canonicalize_identifier (procedure_name);
success = gimp_plug_in_manager_register_priority (gimp->plug_in_manager,
canonical, priority);
g_free (canonical);
}
CODE
);
}
sub register_file_handler_uri {
$blurb = 'Registers a file handler procedure as capable of handling URIs.';
$help = <<'HELP';
Registers a file handler procedure as capable of handling URIs. This
allows GIMP to call the procedure directly for all kinds of URIs, and
the 'filename' traditionally passed to file procedures turns into an
URI.
HELP
&mitch_pdb_misc('2012', '2.10');
@inargs = (
{ name => 'procedure_name', type => 'string', non_empty => 1,
desc => "The name of the procedure to enable URIs for." }
);
%invoke = (
code => <<'CODE'
{
gchar *canonical = gimp_canonicalize_identifier (procedure_name);
success = gimp_plug_in_manager_register_handles_uri (gimp->plug_in_manager,
canonical);
g_free (canonical);
}
CODE
);
}
sub register_file_handler_mime {
$blurb = 'Associates MIME types with a file handler procedure.';
$help = <<'HELP';
Registers MIME types for a file handler procedure. This allows GIMP to
determine the MIME type of the file opened or saved using this
procedure. It is recommended that only one MIME type is registered per
file procedure; when registering more than one MIME type, GIMP will
associate the first one with files opened or saved with this procedure.
HELP
&neo_pdb_misc('2004', '2.2');
@inargs = (
{ name => 'procedure_name', type => 'string', non_empty => 1,
desc => "The name of the procedure to associate a MIME type with." },
{ name => 'mime_types', type => 'string',
desc => 'A comma-separated list of MIME types, such as "image/jpeg".' }
);
%invoke = (
code => <<'CODE'
{
gchar *canonical = gimp_canonicalize_identifier (procedure_name);
success = gimp_plug_in_manager_register_mime_types (gimp->plug_in_manager,
canonical, mime_types);
g_free (canonical);
}
CODE
);
}
sub register_file_handler_raw {
$blurb = 'Registers a file handler procedure as capable of handling raw camera files.';
$help = <<'HELP';
Registers a file handler procedure as capable of handling raw digital
camera files. Use this procedure only to register raw load handlers,
calling it on a save handler will generate an error.
HELP
&mitch_pdb_misc('2017', '2.10');
@inargs = (
{ name => 'procedure_name', type => 'string', non_empty => 1,
desc => "The name of the procedure to enable raw handling for." }
);
%invoke = (
code => <<'CODE'
{
gchar *canonical = gimp_canonicalize_identifier (procedure_name);
success = gimp_plug_in_manager_register_handles_raw (gimp->plug_in_manager,
canonical);
g_free (canonical);
}
CODE
);
}
sub register_thumbnail_loader {
$blurb = 'Associates a thumbnail loader with a file load procedure.';
$help = <<'HELP';
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.
HELP
&neo_pdb_misc('2004', '2.2');
@inargs = (
{ name => 'load_proc', type => 'string', non_empty => 1,
desc => "The name of the procedure the thumbnail loader with." },
{ name => 'thumb_proc', type => 'string', non_empty => 1,
desc => "The name of the thumbnail load procedure." }
);
%invoke = (
code => <<'CODE'
{
gchar *canonical = gimp_canonicalize_identifier (load_proc);
gchar *canon_thumb = gimp_canonicalize_identifier (thumb_proc);
success = gimp_plug_in_manager_register_thumb_loader (gimp->plug_in_manager,
canonical, canon_thumb);
g_free (canonical);
g_free (canon_thumb);
}
CODE
);
}
@headers = qw("libgimpbase/gimpbase.h"
"libgimpconfig/gimpconfig.h"
"core/gimp.h"
"core/gimp-utils.h"
"plug-in/gimppluginmanager-file.h"
"plug-in/gimppluginprocedure.h"
"file/file-open.h"
"file/file-save.h"
"file/file-utils.h");
@procs = qw(file_load
file_load_layer
file_load_layers
file_save
file_load_thumbnail
file_save_thumbnail
register_magic_load_handler
register_load_handler
register_save_handler
register_file_handler_priority
register_file_handler_mime
register_file_handler_uri
register_file_handler_raw
register_thumbnail_loader);
%exports = (app => [@procs], lib => [@procs[0..3,5..13]]);
$desc = 'File Operations';
$doc_title = 'gimpfileops';
$doc_short_desc = 'Image file operations (load, save, etc.)';
$doc_long_desc = 'Image file operations (load, save, etc.)';
1;
|