|
Packit Service |
2781ba |
/* This file is part of 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
|
|
Packit Service |
2781ba |
*/
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include "config.h"
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include <glib-object.h>
|
|
Packit Service |
2781ba |
#include <string.h>
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include "gegl.h"
|
|
Packit Service |
2781ba |
#include "gegl-types-internal.h"
|
|
Packit Service |
2781ba |
#include "gegl-operation-composer.h"
|
|
Packit Service |
2781ba |
#include "gegl-utils.h"
|
|
Packit Service |
2781ba |
#include "graph/gegl-node.h"
|
|
Packit Service |
2781ba |
#include "graph/gegl-connection.h"
|
|
Packit Service |
2781ba |
#include "graph/gegl-pad.h"
|
|
Packit Service |
2781ba |
#include "buffer/gegl-region.h"
|
|
Packit Service |
2781ba |
#include "buffer/gegl-buffer.h"
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
enum
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
PROP_0,
|
|
Packit Service |
2781ba |
PROP_OUTPUT,
|
|
Packit Service |
2781ba |
PROP_INPUT,
|
|
Packit Service |
2781ba |
PROP_AUX
|
|
Packit Service |
2781ba |
};
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static void get_property (GObject *gobject,
|
|
Packit Service |
2781ba |
guint prop_id,
|
|
Packit Service |
2781ba |
GValue *value,
|
|
Packit Service |
2781ba |
GParamSpec *pspec);
|
|
Packit Service |
2781ba |
static void set_property (GObject *gobject,
|
|
Packit Service |
2781ba |
guint prop_id,
|
|
Packit Service |
2781ba |
const GValue *value,
|
|
Packit Service |
2781ba |
GParamSpec *pspec);
|
|
Packit Service |
2781ba |
static gboolean gegl_operation_composer_process (GeglOperation *operation,
|
|
Packit Service |
2781ba |
GeglOperationContext *context,
|
|
Packit Service |
2781ba |
const gchar *output_prop,
|
|
Packit Service |
2781ba |
const GeglRectangle *result,
|
|
Packit Service |
2781ba |
gint level);
|
|
Packit Service |
2781ba |
static void attach (GeglOperation *operation);
|
|
Packit Service |
2781ba |
static GeglNode*detect (GeglOperation *operation,
|
|
Packit Service |
2781ba |
gint x,
|
|
Packit Service |
2781ba |
gint y);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static GeglRectangle get_bounding_box (GeglOperation *self);
|
|
Packit Service |
2781ba |
static GeglRectangle get_required_for_output (GeglOperation *self,
|
|
Packit Service |
2781ba |
const gchar *input_pad,
|
|
Packit Service |
2781ba |
const GeglRectangle *roi);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
G_DEFINE_TYPE (GeglOperationComposer, gegl_operation_composer,
|
|
Packit Service |
2781ba |
GEGL_TYPE_OPERATION)
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static void
|
|
Packit Service |
2781ba |
gegl_operation_composer_class_init (GeglOperationComposerClass * klass)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
Packit Service |
2781ba |
GeglOperationClass *operation_class = GEGL_OPERATION_CLASS (klass);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
object_class->set_property = set_property;
|
|
Packit Service |
2781ba |
object_class->get_property = get_property;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
operation_class->process = gegl_operation_composer_process;
|
|
Packit Service |
2781ba |
operation_class->attach = attach;
|
|
Packit Service |
2781ba |
operation_class->detect = detect;
|
|
Packit Service |
2781ba |
operation_class->get_bounding_box = get_bounding_box;
|
|
Packit Service |
2781ba |
operation_class->get_required_for_output = get_required_for_output;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
g_object_class_install_property (object_class, PROP_OUTPUT,
|
|
Packit Service |
2781ba |
g_param_spec_object ("output",
|
|
Packit Service |
2781ba |
"Output",
|
|
Packit Service |
2781ba |
"Output pad for generated image buffer.",
|
|
Packit Service |
2781ba |
GEGL_TYPE_BUFFER,
|
|
Packit Service |
2781ba |
G_PARAM_READABLE |
|
|
Packit Service |
2781ba |
GEGL_PARAM_PAD_OUTPUT));
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
g_object_class_install_property (object_class, PROP_INPUT,
|
|
Packit Service |
2781ba |
g_param_spec_object ("input",
|
|
Packit Service |
2781ba |
"Input",
|
|
Packit Service |
2781ba |
"Input pad, for image buffer input.",
|
|
Packit Service |
2781ba |
GEGL_TYPE_BUFFER,
|
|
Packit Service |
2781ba |
G_PARAM_READWRITE |
|
|
Packit Service |
2781ba |
GEGL_PARAM_PAD_INPUT));
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
g_object_class_install_property (object_class, PROP_AUX,
|
|
Packit Service |
2781ba |
g_param_spec_object ("aux",
|
|
Packit Service |
2781ba |
"Input",
|
|
Packit Service |
2781ba |
"Auxiliary image buffer input pad.",
|
|
Packit Service |
2781ba |
GEGL_TYPE_BUFFER,
|
|
Packit Service |
2781ba |
G_PARAM_READWRITE |
|
|
Packit Service |
2781ba |
GEGL_PARAM_PAD_INPUT));
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static void
|
|
Packit Service |
2781ba |
gegl_operation_composer_init (GeglOperationComposer *self)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static void
|
|
Packit Service |
2781ba |
attach (GeglOperation *self)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglOperation *operation = GEGL_OPERATION (self);
|
|
Packit Service |
2781ba |
GObjectClass *object_class = G_OBJECT_GET_CLASS (self);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_operation_create_pad (operation,
|
|
Packit Service |
2781ba |
g_object_class_find_property (object_class,
|
|
Packit Service |
2781ba |
"output"));
|
|
Packit Service |
2781ba |
gegl_operation_create_pad (operation,
|
|
Packit Service |
2781ba |
g_object_class_find_property (object_class,
|
|
Packit Service |
2781ba |
"input"));
|
|
Packit Service |
2781ba |
gegl_operation_create_pad (operation,
|
|
Packit Service |
2781ba |
g_object_class_find_property (object_class,
|
|
Packit Service |
2781ba |
"aux"));
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static void
|
|
Packit Service |
2781ba |
get_property (GObject *object,
|
|
Packit Service |
2781ba |
guint prop_id,
|
|
Packit Service |
2781ba |
GValue *value,
|
|
Packit Service |
2781ba |
GParamSpec *pspec)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static void
|
|
Packit Service |
2781ba |
set_property (GObject *object,
|
|
Packit Service |
2781ba |
guint prop_id,
|
|
Packit Service |
2781ba |
const GValue *value,
|
|
Packit Service |
2781ba |
GParamSpec *pspec)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static gboolean
|
|
Packit Service |
2781ba |
gegl_operation_composer_process (GeglOperation *operation,
|
|
Packit Service |
2781ba |
GeglOperationContext *context,
|
|
Packit Service |
2781ba |
const gchar *output_prop,
|
|
Packit Service |
2781ba |
const GeglRectangle *result,
|
|
Packit Service |
2781ba |
gint level)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglOperationComposerClass *klass = GEGL_OPERATION_COMPOSER_GET_CLASS (operation);
|
|
Packit Service |
2781ba |
GeglBuffer *input;
|
|
Packit Service |
2781ba |
GeglBuffer *aux;
|
|
Packit Service |
2781ba |
GeglBuffer *output;
|
|
Packit Service |
2781ba |
gboolean success = FALSE;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (strcmp (output_prop, "output"))
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
g_warning ("requested processing of %s pad on a composer", output_prop);
|
|
Packit Service |
2781ba |
return FALSE;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
input = gegl_operation_context_get_source (context, "input");
|
|
Packit Service |
2781ba |
aux = gegl_operation_context_get_source (context, "aux");
|
|
Packit Service |
2781ba |
output = gegl_operation_context_get_target (context, "output");
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
/* A composer with a NULL aux, can still be valid, the
|
|
Packit Service |
2781ba |
* subclass has to handle it.
|
|
Packit Service |
2781ba |
*/
|
|
Packit Service |
2781ba |
if (input != NULL ||
|
|
Packit Service |
2781ba |
aux != NULL)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
success = klass->process (operation, input, aux, output, result, level);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (output == GEGL_BUFFER (operation->node->cache))
|
|
Packit Service |
2781ba |
gegl_cache_computed (operation->node->cache, result);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (input)
|
|
Packit Service |
2781ba |
g_object_unref (input);
|
|
Packit Service |
2781ba |
if (aux)
|
|
Packit Service |
2781ba |
g_object_unref (aux);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
else
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
g_warning ("%s received NULL input and aux",
|
|
Packit Service |
2781ba |
gegl_node_get_debug_name (operation->node));
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
return success;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static GeglRectangle
|
|
Packit Service |
2781ba |
get_bounding_box (GeglOperation *self)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglRectangle result = { 0, 0, 0, 0 };
|
|
Packit Service |
2781ba |
GeglRectangle *in_rect = gegl_operation_source_get_bounding_box (self, "input");
|
|
Packit Service |
2781ba |
GeglRectangle *aux_rect = gegl_operation_source_get_bounding_box (self, "aux");
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (!in_rect)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
if (aux_rect)
|
|
Packit Service |
2781ba |
return *aux_rect;
|
|
Packit Service |
2781ba |
return result;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
if (aux_rect)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gegl_rectangle_bounding_box (&result, in_rect, aux_rect);
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
else
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
return *in_rect;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
return result;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static GeglRectangle
|
|
Packit Service |
2781ba |
get_required_for_output (GeglOperation *self,
|
|
Packit Service |
2781ba |
const gchar *input_pad,
|
|
Packit Service |
2781ba |
const GeglRectangle *roi)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
return *roi;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static GeglNode *
|
|
Packit Service |
2781ba |
detect (GeglOperation *operation,
|
|
Packit Service |
2781ba |
gint x,
|
|
Packit Service |
2781ba |
gint y)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglNode *input_node = gegl_operation_get_source_node (operation, "input");
|
|
Packit Service |
2781ba |
GeglNode *aux_node = gegl_operation_get_source_node (operation, "aux");
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (input_node)
|
|
Packit Service |
2781ba |
input_node = gegl_node_detect (input_node, x, y);
|
|
Packit Service |
2781ba |
if (aux_node)
|
|
Packit Service |
2781ba |
aux_node = gegl_node_detect (aux_node, x, y);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (aux_node)
|
|
Packit Service |
2781ba |
return aux_node;
|
|
Packit Service |
2781ba |
if (input_node)
|
|
Packit Service |
2781ba |
return input_node;
|
|
Packit Service |
2781ba |
return NULL;
|
|
Packit Service |
2781ba |
}
|