|
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 |
/* FIXME: need to make this OpenRaster inspired layer integrate better
|
|
Packit Service |
2781ba |
* with the newer caching system
|
|
Packit Service |
2781ba |
*/
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include "config.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_string(composite_op, _("Operation"), "gegl:over",
|
|
Packit Service |
2781ba |
_("Composite operation to use"))
|
|
Packit Service |
2781ba |
gegl_chant_double(opacity, _("Opacity"), 0.0, 1.0, 1.0,
|
|
Packit Service |
2781ba |
_("Opacity"))
|
|
Packit Service |
2781ba |
gegl_chant_double(x, _("X"), -G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
|
|
Packit Service |
2781ba |
_("Horizontal position"))
|
|
Packit Service |
2781ba |
gegl_chant_double(y, _("Y"), -G_MAXDOUBLE, G_MAXDOUBLE, 0.0,
|
|
Packit Service |
2781ba |
_("Vertical position"))
|
|
Packit Service |
2781ba |
gegl_chant_double(scale, _("Scale"), -G_MAXDOUBLE, G_MAXDOUBLE, 1.0,
|
|
Packit Service |
2781ba |
_("Scale 1:1 size"))
|
|
Packit Service |
2781ba |
gegl_chant_file_path(src, _("Source"), "",
|
|
Packit Service |
2781ba |
_("Source datafile (png, jpg, raw, svg, bmp, tif, ...)"))
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#else
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include <gegl-plugin.h>
|
|
Packit Service |
2781ba |
struct _GeglChant
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglOperationMeta parent_instance;
|
|
Packit Service |
2781ba |
gpointer properties;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
GeglNode *self;
|
|
Packit Service |
2781ba |
GeglNode *input;
|
|
Packit Service |
2781ba |
GeglNode *aux;
|
|
Packit Service |
2781ba |
GeglNode *output;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
GeglNode *composite_op;
|
|
Packit Service |
2781ba |
GeglNode *translate;
|
|
Packit Service |
2781ba |
GeglNode *opacity;
|
|
Packit Service |
2781ba |
GeglNode *scale;
|
|
Packit Service |
2781ba |
GeglNode *load;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gchar *cached_path;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gdouble p_opacity;
|
|
Packit Service |
2781ba |
gdouble p_scale;
|
|
Packit Service |
2781ba |
gdouble p_x;
|
|
Packit Service |
2781ba |
gdouble p_y;
|
|
Packit Service |
2781ba |
gchar *p_composite_op;
|
|
Packit Service |
2781ba |
};
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
typedef struct
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglOperationMetaClass parent_class;
|
|
Packit Service |
2781ba |
} GeglChantClass;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#define GEGL_CHANT_C_FILE "layer.c"
|
|
Packit Service |
2781ba |
#include "gegl-chant.h"
|
|
Packit Service |
2781ba |
GEGL_DEFINE_DYNAMIC_OPERATION(GEGL_TYPE_OPERATION_META)
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include <glib/gprintf.h>
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static void
|
|
Packit Service |
2781ba |
prepare (GeglOperation *operation)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
|
|
Packit Service |
2781ba |
GeglChant *self = GEGL_CHANT (operation);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* If the src is NULL, and we previously used a source, clear what we have
|
|
Packit Service |
2781ba |
* cached and directly link the input and output. We don't need a composite
|
|
Packit Service |
2781ba |
* operation if we don't have a source, so don't continue preparing.
|
|
Packit Service |
2781ba |
*/
|
|
Packit Service |
2781ba |
if (o->src[0] == 0)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
if (self->cached_path != NULL)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gegl_node_link (self->input, self->output);
|
|
Packit Service |
2781ba |
g_free(self->cached_path);
|
|
Packit Service |
2781ba |
self->cached_path = NULL;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
return;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* warning: this might trigger regeneration of the graph,
|
|
Packit Service |
2781ba |
* for now this is evaded by just ignoring additional
|
|
Packit Service |
2781ba |
* requests to be made into members of the graph
|
|
Packit Service |
2781ba |
*/
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* Check if the composite operation we're using has changed from that which
|
|
Packit Service |
2781ba |
* is already in use.
|
|
Packit Service |
2781ba |
*/
|
|
Packit Service |
2781ba |
if (!self->p_composite_op || strcmp (self->p_composite_op, o->composite_op))
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gegl_node_set (self->composite_op,
|
|
Packit Service |
2781ba |
"operation", o->composite_op,
|
|
Packit Service |
2781ba |
NULL);
|
|
Packit Service |
2781ba |
if (self->p_composite_op)
|
|
Packit Service |
2781ba |
g_free (self->p_composite_op);
|
|
Packit Service |
2781ba |
self->p_composite_op = g_strdup (o->composite_op);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
g_assert(o->src && o->src[0]);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* Load a src image, and relink the input/composite/output chain, as it
|
|
Packit Service |
2781ba |
* will currently be set to an input/output chain without a composite
|
|
Packit Service |
2781ba |
* source.
|
|
Packit Service |
2781ba |
*/
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* FIXME:
|
|
Packit Service |
2781ba |
* this reimplements the "load" op, which shouldn't be neccesary, but
|
|
Packit Service |
2781ba |
* currently seems to be neccesary since GEGL doesn't like a meta-op
|
|
Packit Service |
2781ba |
* to be implemented using another meta-op.
|
|
Packit Service |
2781ba |
*/
|
|
Packit Service |
2781ba |
if (self->cached_path == NULL || strcmp (o->src, self->cached_path))
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
const gchar *extension = strrchr (o->src, '.');
|
|
Packit Service |
2781ba |
const gchar *handler = NULL;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (!g_file_test (o->src, G_FILE_TEST_EXISTS))
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gchar *name = g_filename_display_name (o->src);
|
|
Packit Service |
2781ba |
gchar *tmp = g_strdup_printf ("File '%s' does not exist", name);
|
|
Packit Service |
2781ba |
g_free (name);
|
|
Packit Service |
2781ba |
g_warning ("load: %s", tmp);
|
|
Packit Service |
2781ba |
gegl_node_set (self->load,
|
|
Packit Service |
2781ba |
"operation", "gegl:text",
|
|
Packit Service |
2781ba |
"size", 12.0,
|
|
Packit Service |
2781ba |
"string", tmp,
|
|
Packit Service |
2781ba |
NULL);
|
|
Packit Service |
2781ba |
g_free (tmp);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
else
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
if (extension)
|
|
Packit Service |
2781ba |
handler = gegl_extension_handler_get (extension);
|
|
Packit Service |
2781ba |
gegl_node_set (self->load,
|
|
Packit Service |
2781ba |
"operation", handler,
|
|
Packit Service |
2781ba |
NULL);
|
|
Packit Service |
2781ba |
gegl_node_set (self->load,
|
|
Packit Service |
2781ba |
"path", o->src,
|
|
Packit Service |
2781ba |
NULL);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* Currently not using the composite op, reinsert it */
|
|
Packit Service |
2781ba |
if (!self->cached_path)
|
|
Packit Service |
2781ba |
gegl_node_link_many (self->input, self->composite_op, self->output, NULL);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (self->cached_path)
|
|
Packit Service |
2781ba |
g_free (self->cached_path);
|
|
Packit Service |
2781ba |
self->cached_path = g_strdup (o->src);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (o->scale != self->p_scale)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gegl_node_set (self->scale,
|
|
Packit Service |
2781ba |
"x", o->scale,
|
|
Packit Service |
2781ba |
"y", o->scale,
|
|
Packit Service |
2781ba |
NULL);
|
|
Packit Service |
2781ba |
self->p_scale= o->scale;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (o->opacity != self->p_opacity)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gegl_node_set (self->opacity,
|
|
Packit Service |
2781ba |
"value", o->opacity,
|
|
Packit Service |
2781ba |
NULL);
|
|
Packit Service |
2781ba |
self->p_opacity = o->opacity;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (o->x != self->p_x ||
|
|
Packit Service |
2781ba |
o->y != self->p_y)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gegl_node_set (self->translate,
|
|
Packit Service |
2781ba |
"x", o->x,
|
|
Packit Service |
2781ba |
"y", o->y,
|
|
Packit Service |
2781ba |
NULL);
|
|
Packit Service |
2781ba |
self->p_x = o->x;
|
|
Packit Service |
2781ba |
self->p_y = o->y;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static void attach (GeglOperation *operation)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglChant *self = GEGL_CHANT (operation);
|
|
Packit Service |
2781ba |
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
|
|
Packit Service |
2781ba |
GeglNode *gegl;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
self->self = GEGL_OPERATION (self)->node;
|
|
Packit Service |
2781ba |
gegl = self->self;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
self->input = gegl_node_get_input_proxy (gegl, "input");
|
|
Packit Service |
2781ba |
self->aux = gegl_node_get_input_proxy (gegl, "aux");
|
|
Packit Service |
2781ba |
self->output = gegl_node_get_output_proxy (gegl, "output");
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
self->composite_op = gegl_node_new_child (gegl,
|
|
Packit Service |
2781ba |
"operation", o->composite_op,
|
|
Packit Service |
2781ba |
NULL);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
self->translate = gegl_node_new_child (gegl, "operation", "gegl:translate", NULL);
|
|
Packit Service |
2781ba |
self->scale = gegl_node_new_child (gegl, "operation", "gegl:scale", NULL);
|
|
Packit Service |
2781ba |
self->opacity = gegl_node_new_child (gegl, "operation", "gegl:opacity", NULL);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
self->load = gegl_node_new_child (gegl,
|
|
Packit Service |
2781ba |
"operation", "gegl:text",
|
|
Packit Service |
2781ba |
"string", "Load operation placeholder",
|
|
Packit Service |
2781ba |
NULL);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_node_link_many (self->load, self->scale, self->opacity, self->translate,
|
|
Packit Service |
2781ba |
NULL);
|
|
Packit Service |
2781ba |
gegl_node_link_many (self->input, self->composite_op, self->output, NULL);
|
|
Packit Service |
2781ba |
gegl_node_connect_from (self->composite_op, "aux", self->translate, "output");
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static void
|
|
Packit Service |
2781ba |
finalize (GObject *object)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglChant *self = GEGL_CHANT (object);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (self->cached_path)
|
|
Packit Service |
2781ba |
g_free (self->cached_path);
|
|
Packit Service |
2781ba |
if (self->p_composite_op)
|
|
Packit Service |
2781ba |
g_free (self->p_composite_op);
|
|
Packit Service |
2781ba |
|
|
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 |
GObjectClass *object_class;
|
|
Packit Service |
2781ba |
GeglOperationClass *operation_class;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
object_class = G_OBJECT_CLASS (klass);
|
|
Packit Service |
2781ba |
operation_class = GEGL_OPERATION_CLASS (klass);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
object_class->finalize = finalize;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
operation_class->attach = attach;
|
|
Packit Service |
2781ba |
operation_class->prepare = prepare;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_operation_class_set_keys (operation_class,
|
|
Packit Service |
2781ba |
"name" , "gegl:layer",
|
|
Packit Service |
2781ba |
"categories" , "meta",
|
|
Packit Service |
2781ba |
"description", _("A layer in the traditional sense"),
|
|
Packit Service |
2781ba |
NULL);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#endif
|