Gimp/tools/pdbgen/pdb/fileops.pdb
Michael Natterer 35a8308d25 tools/pdbgen/pdb/fileops.pdb fixed includes after libgimpconfig file
2005-01-26  Michael Natterer  <mitch@gimp.org>

	* tools/pdbgen/pdb/fileops.pdb
	* tools/pdbgen/pdb/gimprc.pdb: fixed includes after libgimpconfig
	file moving. Reported by Volker Sturm.

	* app/pdb/gimprc_cmds.c: regenerated.
2005-01-26 13:59:15 +00:00

574 lines
16 KiB
Text

# The GIMP -- an 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 2 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# "Perlized" from C source by Manish Singh <yosh@gimp.org>
sub pdb_misc {
$author = $copyright = 'Josh MacDonald';
$date = '1997';
}
sub list_arg {
my ($type, $name, $desc, $example) = @_;
push @inargs, { name => $name, type => 'string', no_success => 1,
desc => qq/comma separated list of $desc this handler
can $type (i.e. "$example")/ }
}
sub handler_args {
my $type = shift;
my $action = $type;
$action =~ s/e$//;
$action .= 'ing';
push @inargs, { name => 'procedure_name', type => 'string',
desc => "The name of the procedure to be used for $action",
alias => 'name' };
foreach ([ 'extensions', 'jpg,jpeg' ], [ 'prefixes', 'http:,ftp:' ]) {
&list_arg($type, $_->[0], @$_);
}
}
# The defs
sub file_load {
$blurb = 'Loads a 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 http://www.xcf/~gimp/ he wants to fetch a URL,
and the full pathname will not look like a URL."
HELP
&pdb_misc;
@inargs = (
{ name => 'run_mode',
type => 'enum GimpRunMode (no GIMP_RUN_WITH_LAST_VALS)',
desc => 'The run mode: %%desc%%' },
{ name => 'filename', type => 'string', no_validate => 1,
desc => 'The name of the file to load' },
{ name => 'raw_filename', type => 'string', no_validate => 1,
desc => 'The name as entered by the user' }
);
@outargs = ( &std_image_arg );
$outargs[0]->{desc} = 'The output image';
%invoke = (
proc => [ 'proc->name', 'new_args' ],
args => [ 'new_args', 'return_vals' ],
vars => [ 'PlugInProcDef *file_proc', 'const ProcRecord *proc',
'gchar *uri', 'gint i' ],
code => <<'CODE'
{
uri = file_utils_filename_to_uri (gimp->load_procs, %%filename%%, NULL);
if (! uri)
return %%fail%%;
file_proc = file_utils_find_proc (gimp->load_procs, uri);
g_free (uri);
if (! file_proc)
return %%fail%%;
proc = plug_in_proc_def_get_proc (file_proc);
new_args = g_new0 (%%argtype%%, proc->num_args);
memcpy (new_args, args, sizeof (%%argtype%%) * 3);
for (i = 3; i < proc->num_args; i++)
{
new_args[i].arg_type = proc->args[i].arg_type;
if (proc->args[i].arg_type == GIMP_PDB_STRING)
new_args[i].value.pdb_pointer = g_strdup ("");
}
return_vals = %%exec%%;
g_free (new_args);
return return_vals;
}
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
http://www.xcf/~gimp/ she wants to fetch a URL, and the full pathname will not
look like a URL.
HELP
&pdb_misc;
@inargs = (
{ name => 'run_mode',
type => 'enum GimpRunMode (no GIMP_RUN_WITH_LAST_VALS)',
desc => 'The run mode: %%desc%%' },
{ name => 'image', type => 'image',
desc => 'Input image' },
{ name => 'drawable', type => 'drawable',
desc => 'Drawable to save' },
{ name => 'filename', type => 'string', no_validate => 1,
desc => 'The name of the file to save the image in' },
{ name => 'raw_filename', type => 'string', no_validate => 1,
desc => 'The name as entered by the user' }
);
%invoke = (
headers => [ qw(<string.h>) ],
proc => [ 'proc->name', 'new_args' ],
args => [ 'new_args', 'return_vals' ],
vars => [ 'PlugInProcDef *file_proc', 'const ProcRecord *proc',
'gchar *uri', 'gint i' ],
code => <<'CODE'
{
uri = file_utils_filename_to_uri (gimp->load_procs, %%filename%%, NULL);
if (! uri)
return %%fail%%;
file_proc = file_utils_find_proc (gimp->save_procs, uri);
g_free (uri);
if (! file_proc)
return %%fail%%;
proc = plug_in_proc_def_get_proc (file_proc);
new_args = g_new0 (%%argtype%%, proc->num_args);
memcpy (new_args, args, sizeof (%%argtype%%) * 5);
for (i = 5; i < proc->num_args; i++)
{
new_args[i].arg_type = proc->args[i].arg_type;
if (proc->args[i].arg_type == GIMP_PDB_STRING)
new_args[i].value.pdb_pointer = g_strdup ("");
}
return_vals = %%exec%%;
g_free (new_args);
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', no_validate => 1,
desc => 'The name of the file that owns the thumbnail to load' },
);
@outargs = (
{ name => 'width', type => 'int32', init => 1,
desc => 'The width of the thumbnail' },
{ name => 'height', type => 'int32', init => 1,
desc => 'The height of the thumbnail' },
{ name => 'thumb_data', type => 'int8array', init => 1,
desc => 'The thumbnail data',
array => { name => 'thumbnail_data_count',
desc => 'The number of bytes in thumbnail data',
alias => 'num_bytes', init => 1 } },
);
%invoke = (
vars => [ 'gchar *uri',
'GimpThumbnail *thumbnail = NULL',
'GdkPixbuf *pixbuf = NULL' ],
code => <<'CODE'
{
uri = g_filename_to_uri (filename, NULL, NULL);
if (uri)
{
thumbnail = gimp_thumbnail_new ();
gimp_thumbnail_set_uri (thumbnail, uri);
pixbuf = gimp_thumbnail_load_thumb (thumbnail,
GIMP_THUMBNAIL_SIZE_NORMAL,
NULL);
}
if (pixbuf)
{
width = gdk_pixbuf_get_width (pixbuf);
height = gdk_pixbuf_get_height (pixbuf);
if (gdk_pixbuf_get_n_channels (pixbuf) != 3)
{
GdkPixbuf *tmp = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8,
width, height);
gdk_pixbuf_composite_color (pixbuf, tmp,
0, 0, width, height, 0, 0, 1.0, 1.0,
GDK_INTERP_NEAREST, 255,
0, 0, GIMP_CHECK_SIZE_SM,
0x66666666, 0x99999999);
g_object_unref (pixbuf);
pixbuf = tmp;
}
num_bytes = 3 * width * height;
thumb_data = g_memdup (gdk_pixbuf_get_pixels (pixbuf), num_bytes);
g_object_unref (pixbuf);
success = TRUE;
}
else
{
success = FALSE;
}
g_free (uri);
}
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
explicitely save a thumbnail with a file.
HELP
&pdb_misc;
@inargs = (
&std_image_arg,
{ name => 'filename', type => 'string', no_validate => 1,
desc => 'The name of the file the thumbnail belongs to' },
);
%invoke = (
vars => [ 'GimpImagefile *imagefile', 'gchar *uri',
'const gchar *image_uri' ],
code => <<'CODE'
{
image_uri = gimp_object_get_name (GIMP_OBJECT (gimage));
if (! image_uri)
success = FALSE;
if (success)
{
uri = g_filename_to_uri (filename, NULL, NULL);
if (! uri)
success = FALSE;
if (success)
{
if (strcmp (uri, image_uri))
success = FALSE;
if (success)
{
imagefile = gimp_imagefile_new (gimp, uri);
success = gimp_imagefile_save_thumbnail (imagefile, NULL, gimage);
g_object_unref (imagefile);
}
g_free (uri);
}
}
}
CODE
);
}
sub temp_name {
$blurb = 'Generates a unique filename.';
$help = <<'HELP';
Generates a unique filename using the temp path supplied in the user's gimprc.
HELP
&pdb_misc;
@inargs = (
{ name => 'extension', type => 'string', no_validate => 1,
desc => 'The extension the file will have' }
);
@outargs = (
{ name => 'name', type => 'string', init => 1,
desc => 'The new temp filename' }
);
%invoke = (
headers => [ qw(<process.h>
"config/gimpbaseconfig.h") ],
vars => [ 'static gint id = 0', 'static gint pid',
'gchar *filename', 'gchar *path' ],
code => <<'CODE'
{
if (id == 0)
pid = getpid ();
filename = g_strdup_printf ("gimp_temp_%d%d.%s",
pid, id++, extension);
path = gimp_config_path_expand (GIMP_BASE_CONFIG (gimp->config)->temp_path,
TRUE, NULL);
name = g_build_filename (path, filename, NULL);
g_free (path);
g_free (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;
&handler_args('load');
&list_arg('load', 'magics', 'magic file information', '0,string,GIF');
%invoke = (
vars => [ 'ProcRecord *proc', 'PlugInProcDef *file_proc' ],
code => <<'CODE'
{
success = FALSE;
proc = procedural_db_lookup (gimp, name);
if (proc && ((proc->num_args < 3) ||
(proc->num_values < 1) ||
(proc->args[0].arg_type != GIMP_PDB_INT32) ||
(proc->args[1].arg_type != GIMP_PDB_STRING) ||
(proc->args[2].arg_type != GIMP_PDB_STRING) ||
(proc->values[0].arg_type != GIMP_PDB_IMAGE)))
{
g_message ("load handler \"%s\" does not take the standard load handler args",
name);
goto done;
}
file_proc = plug_ins_file_register_magic (gimp, name,
extensions, prefixes, magics);
if (! file_proc)
{
g_message ("attempt to register non-existant load handler \"%s\"",
name);
goto done;
}
if (! g_slist_find (gimp->load_procs, file_proc))
gimp->load_procs = g_slist_prepend (gimp->load_procs, file_proc);
success = TRUE;
done: ;
}
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;
&handler_args('load');
%invoke = (
pass_through => 'register_magic_load_handler',
pass_args => [ 0..2 ],
make_args => [ { type => 'string', code => '%%arg%% = NULL;' } ]
);
}
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;
&handler_args('save');
%invoke = (
vars => [ 'ProcRecord *proc', 'PlugInProcDef *file_proc' ],
code => <<'CODE'
{
success = FALSE;
proc = procedural_db_lookup (gimp, name);
if (proc && ((proc->num_args < 5) ||
(proc->args[0].arg_type != GIMP_PDB_INT32) ||
(proc->args[1].arg_type != GIMP_PDB_IMAGE) ||
(proc->args[2].arg_type != GIMP_PDB_DRAWABLE) ||
(proc->args[3].arg_type != GIMP_PDB_STRING) ||
(proc->args[4].arg_type != GIMP_PDB_STRING)))
{
g_message ("save handler \"%s\" does not take the standard save handler args",
name);
goto done;
}
file_proc = plug_ins_file_register_magic (gimp, name,
extensions, prefixes, NULL);
if (! file_proc)
{
g_message ("attempt to register non-existant save handler \"%s\"",
name);
goto done;
}
if (! g_slist_find (gimp->save_procs, file_proc))
gimp->save_procs = g_slist_prepend (gimp->save_procs, file_proc);
success = TRUE;
done: ;
}
CODE
);
}
sub register_file_handler_mime {
$blurb = 'Associates a MIME type with a file handler procedure.';
$help = <<'HELP';
Registers a MIME type for a file handler procedure. This allows GIMP
to determine the MIME type of the file opened or saved using this
procedure.
HELP
$author = $copyright = 'Sven Neumann';
$date = '2004';
$since = '2.2';
@inargs = (
{ name => 'procedure_name', type => 'string', alias => 'name',
desc => "The name of the procedure to associate a MIME type with." },
{ name => 'mime_type', type => 'string',
desc => "A single MIME type, like for example \"image/jpeg\"." }
);
%invoke = (
code => <<'CODE'
{
success = (plug_ins_file_register_mime (gimp, name, mime_type) != NULL);
}
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
$author = $copyright = 'Sven Neumann';
$date = '2004';
$since = '2.2';
@inargs = (
{ name => 'load_proc', type => 'string',
desc => "The name of the procedure the thumbnail loader with." },
{ name => 'thumb_proc', type => 'string',
desc => "The name of the thumbnail load procedure." }
);
%invoke = (
code => <<'CODE'
{
success = (plug_ins_file_register_thumb_loader (gimp,
load_proc,
thumb_proc) != NULL);
}
CODE
);
}
@headers = qw(<sys/types.h> <unistd.h> <gdk-pixbuf/gdk-pixbuf.h>
"libgimpbase/gimpbase.h" "libgimpconfig/gimpconfig.h"
"libgimpthumb/gimpthumb.h"
"core/gimp.h" "core/gimpimagefile.h"
"plug-in/plug-in.h" "plug-in/plug-ins.h"
"plug-in/plug-in-proc-def.h"
"file/file-utils.h");
@procs = qw(file_load file_save file_load_thumbnail file_save_thumbnail
temp_name register_magic_load_handler register_load_handler
register_save_handler register_file_handler_mime
register_thumbnail_loader);
%exports = (app => [@procs], lib => [@procs[0,1,4..9]]);
$desc = 'File Operations';
1;