|
Packit Service |
2781ba |
/* This file is an image processing operation for GEGL
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* GEGL is free software; you can redistribute it and/or
|
|
Packit Service |
2781ba |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
2781ba |
* License as published by the Free Software Foundation; either
|
|
Packit Service |
2781ba |
* version 3 of the License, or (at your option) any later version.
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* GEGL is distributed in the hope that it will be useful,
|
|
Packit Service |
2781ba |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
2781ba |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
2781ba |
* Lesser General Public License for more details.
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
2781ba |
* License along with GEGL; if not, see <http://www.gnu.org/licenses/>.
|
|
Packit Service |
2781ba |
*
|
|
Packit Service |
2781ba |
* Copyright 2006 Øyvind Kolås <pippin@gimp.org>
|
|
Packit Service |
2781ba |
*/
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include "config.h"
|
|
Packit Service |
2781ba |
#include <stdlib.h>
|
|
Packit Service |
2781ba |
#include <glib/gi18n-lib.h>
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#ifdef GEGL_CHANT_PROPERTIES
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_chant_file_path (path, _("File"), "/tmp/gegl-logo.svg", _("Path of file to load."))
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#else
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#define GEGL_CHANT_TYPE_SOURCE
|
|
Packit Service |
2781ba |
#define GEGL_CHANT_C_FILE "magick-load.c"
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include "gegl-chant.h"
|
|
Packit Service |
2781ba |
#include <stdio.h>
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static void
|
|
Packit Service |
2781ba |
load_cache (GeglChantO *op_magick_load)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
if (!op_magick_load->chant_data)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gchar *filename;
|
|
Packit Service |
2781ba |
gchar *cmd;
|
|
Packit Service |
2781ba |
GeglNode *graph, *sink;
|
|
Packit Service |
2781ba |
GeglBuffer *newbuf = NULL;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* ImageMagick backed fallback FIXME: make this robust.
|
|
Packit Service |
2781ba |
* maybe use pipes in a manner similar to the raw loader,
|
|
Packit Service |
2781ba |
* or at least use a properly unique filename */
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
filename = g_build_filename (g_get_tmp_dir (), "gegl-magick.png", NULL);
|
|
Packit Service |
2781ba |
cmd = g_strdup_printf ("convert \"%s\"'[0]' \"%s\"",
|
|
Packit Service |
2781ba |
op_magick_load->path, filename);
|
|
Packit Service |
2781ba |
if (system (cmd) == -1)
|
|
Packit Service |
2781ba |
g_warning ("Error executing ImageMagick convert program");
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
graph = gegl_graph (sink=gegl_node ("gegl:buffer-sink", "buffer", &newbuf, NULL,
|
|
Packit Service |
2781ba |
gegl_node ("gegl:png-load", "path", filename, NULL)));
|
|
Packit Service |
2781ba |
gegl_node_process (sink);
|
|
Packit Service |
2781ba |
op_magick_load->chant_data = (gpointer) newbuf;
|
|
Packit Service |
2781ba |
g_object_unref (graph);
|
|
Packit Service |
2781ba |
g_free (cmd);
|
|
Packit Service |
2781ba |
g_free (filename);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static GeglRectangle
|
|
Packit Service |
2781ba |
get_bounding_box (GeglOperation *operation)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglRectangle result = {0,0,0,0};
|
|
Packit Service |
2781ba |
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
|
|
Packit Service |
2781ba |
gint width, height;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
load_cache (o);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
g_object_get (o->chant_data, "width", &width,
|
|
Packit Service |
2781ba |
"height", &height, NULL);
|
|
Packit Service |
2781ba |
result.width = width;
|
|
Packit Service |
2781ba |
result.height = height;
|
|
Packit Service |
2781ba |
return result;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static GeglRectangle
|
|
Packit Service |
2781ba |
get_cached_region (GeglOperation *operation,
|
|
Packit Service |
2781ba |
const GeglRectangle *roi)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
return get_bounding_box (operation);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static gboolean
|
|
Packit Service |
2781ba |
process (GeglOperation *operation,
|
|
Packit Service |
2781ba |
GeglOperationContext *context,
|
|
Packit Service |
2781ba |
const gchar *output_pad,
|
|
Packit Service |
2781ba |
const GeglRectangle *result,
|
|
Packit Service |
2781ba |
gint level)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (!o->chant_data)
|
|
Packit Service |
2781ba |
return FALSE;
|
|
Packit Service |
2781ba |
/* overriding the predefined behavior */
|
|
Packit Service |
2781ba |
g_object_ref (o->chant_data);
|
|
Packit Service |
2781ba |
gegl_operation_context_take_object (context, "output", G_OBJECT (o->chant_data));
|
|
Packit Service |
2781ba |
return TRUE;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static void finalize (GObject *object)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglOperation *op = (void*) object;
|
|
Packit Service |
2781ba |
GeglChantO *o = GEGL_CHANT_PROPERTIES (op);
|
|
Packit Service |
2781ba |
if (o->chant_data)
|
|
Packit Service |
2781ba |
g_object_unref (o->chant_data);
|
|
Packit Service |
2781ba |
o->chant_data = NULL;
|
|
Packit Service |
2781ba |
G_OBJECT_CLASS (gegl_chant_parent_class)->finalize (object);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static void
|
|
Packit Service |
2781ba |
gegl_chant_class_init (GeglChantClass *klass)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglOperationClass *operation_class;
|
|
Packit Service |
2781ba |
GObjectClass *object_class;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
operation_class = GEGL_OPERATION_CLASS (klass);
|
|
Packit Service |
2781ba |
object_class = G_OBJECT_CLASS (klass);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
object_class->finalize = finalize;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
operation_class->process = process;
|
|
Packit Service |
2781ba |
operation_class->get_bounding_box = get_bounding_box;
|
|
Packit Service |
2781ba |
operation_class->get_cached_region = get_cached_region;;
|
|
Packit Service |
2781ba |
operation_class->no_cache = FALSE;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_operation_class_set_keys (operation_class,
|
|
Packit Service |
2781ba |
"name" , "gegl:magick-load",
|
|
Packit Service |
2781ba |
"categories" , "hidden",
|
|
Packit Service |
2781ba |
"description",
|
|
Packit Service |
2781ba |
_("Image Magick wrapper using the png op."),
|
|
Packit Service |
2781ba |
NULL);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#endif
|