|
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-filter.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 |
};
|
|
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 |
|
|
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 |
|
|
Packit Service |
2781ba |
static gboolean gegl_operation_filter_process
|
|
Packit Service |
2781ba |
(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 |
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 *operation,
|
|
Packit Service |
2781ba |
const gchar *input_pad,
|
|
Packit Service |
2781ba |
const GeglRectangle *roi);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
G_DEFINE_TYPE (GeglOperationFilter, gegl_operation_filter, GEGL_TYPE_OPERATION)
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static void
|
|
Packit Service |
2781ba |
gegl_operation_filter_class_init (GeglOperationFilterClass * 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_filter_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 |
|
|
Packit Service |
2781ba |
static void
|
|
Packit Service |
2781ba |
gegl_operation_filter_init (GeglOperationFilter *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 |
}
|
|
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;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
input_node = gegl_operation_get_source_node (operation, "input");
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (input_node)
|
|
Packit Service |
2781ba |
return gegl_operation_detect (input_node->operation, x, y);
|
|
Packit Service |
2781ba |
return operation->node;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
void babl_backtrack (void);
|
|
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 |
switch (prop_id)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
case PROP_OUTPUT:
|
|
Packit Service |
2781ba |
g_warning ("shouldn't happen");
|
|
Packit Service |
2781ba |
babl_backtrack ();
|
|
Packit Service |
2781ba |
break;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
case PROP_INPUT:
|
|
Packit Service |
2781ba |
g_warning ("shouldn't happen");
|
|
Packit Service |
2781ba |
babl_backtrack ();
|
|
Packit Service |
2781ba |
break;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
default:
|
|
Packit Service |
2781ba |
break;
|
|
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 |
switch (prop_id)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
case PROP_INPUT:
|
|
Packit Service |
2781ba |
g_warning ("shouldn't happen");
|
|
Packit Service |
2781ba |
babl_backtrack ();
|
|
Packit Service |
2781ba |
break;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
default:
|
|
Packit Service |
2781ba |
break;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static gboolean
|
|
Packit Service |
2781ba |
gegl_operation_filter_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 |
GeglOperationFilterClass *klass;
|
|
Packit Service |
2781ba |
GeglBuffer *input;
|
|
Packit Service |
2781ba |
GeglBuffer *output;
|
|
Packit Service |
2781ba |
gboolean success = FALSE;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
klass = GEGL_OPERATION_FILTER_GET_CLASS (operation);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
g_assert (klass->process);
|
|
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 filter", 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 |
output = gegl_operation_context_get_target (context, "output");
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
success = klass->process (operation, input, 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 != NULL)
|
|
Packit Service |
2781ba |
g_object_unref (input);
|
|
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;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
in_rect = gegl_operation_source_get_bounding_box (self, "input");
|
|
Packit Service |
2781ba |
if (in_rect)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
result = *in_rect;
|
|
Packit Service |
2781ba |
}
|
|
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 *operation,
|
|
Packit Service |
2781ba |
const gchar *input_pad,
|
|
Packit Service |
2781ba |
const GeglRectangle *roi)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
return *roi;
|
|
Packit Service |
2781ba |
}
|