|
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 |
#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_double (x, _("X"), -G_MAXFLOAT, G_MAXFLOAT, 0.0, _("X"))
|
|
Packit Service |
2781ba |
gegl_chant_double (y, _("Y"), -G_MAXFLOAT, G_MAXFLOAT, 0.0, _("Y"))
|
|
Packit Service |
2781ba |
gegl_chant_double (width, _("Width"), -G_MAXFLOAT, G_MAXFLOAT, 10.0, _("Width"))
|
|
Packit Service |
2781ba |
gegl_chant_double (height, _("Height"), -G_MAXFLOAT, G_MAXFLOAT, 10.0, _("Height"))
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#else
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#define GEGL_CHANT_TYPE_FILTER
|
|
Packit Service |
2781ba |
#define GEGL_CHANT_C_FILE "crop.c"
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include "gegl-chant.h"
|
|
Packit Service |
2781ba |
#include "graph/gegl-node.h"
|
|
Packit Service |
2781ba |
#include "buffer/gegl-buffer-cl-cache.h"
|
|
Packit Service |
2781ba |
#include <math.h>
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static GeglNode *
|
|
Packit Service |
2781ba |
gegl_crop_detect (GeglOperation *operation,
|
|
Packit Service |
2781ba |
gint x,
|
|
Packit Service |
2781ba |
gint y)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
|
|
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,
|
|
Packit Service |
2781ba |
x - floor (o->x),
|
|
Packit Service |
2781ba |
y - floor (o->y));
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
return operation->node;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static GeglRectangle
|
|
Packit Service |
2781ba |
gegl_crop_get_bounding_box (GeglOperation *operation)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
|
|
Packit Service |
2781ba |
GeglRectangle *in_rect = gegl_operation_source_get_bounding_box (operation, "input");
|
|
Packit Service |
2781ba |
GeglRectangle result = { 0, 0, 0, 0 };
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (!in_rect)
|
|
Packit Service |
2781ba |
return result;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
result.x = o->x;
|
|
Packit Service |
2781ba |
result.y = o->y;
|
|
Packit Service |
2781ba |
result.width = o->width;
|
|
Packit Service |
2781ba |
result.height = o->height;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
return result;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static GeglRectangle
|
|
Packit Service |
2781ba |
gegl_crop_get_invalidated_by_change (GeglOperation *operation,
|
|
Packit Service |
2781ba |
const gchar *input_pad,
|
|
Packit Service |
2781ba |
const GeglRectangle *input_region)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
|
|
Packit Service |
2781ba |
GeglRectangle result;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
result.x = o->x;
|
|
Packit Service |
2781ba |
result.y = o->y;
|
|
Packit Service |
2781ba |
result.width = o->width;
|
|
Packit Service |
2781ba |
result.height = o->height;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_rectangle_intersect (&result, &result, input_region);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
return result;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static GeglRectangle
|
|
Packit Service |
2781ba |
gegl_crop_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 |
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
|
|
Packit Service |
2781ba |
GeglRectangle result;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
result.x = o->x;
|
|
Packit Service |
2781ba |
result.y = o->y;
|
|
Packit Service |
2781ba |
result.width = o->width;
|
|
Packit Service |
2781ba |
result.height = o->height;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_rectangle_intersect (&result, &result, roi);
|
|
Packit Service |
2781ba |
return result;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static gboolean
|
|
Packit Service |
2781ba |
gegl_crop_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 |
GeglChantO *o = GEGL_CHANT_PROPERTIES (operation);
|
|
Packit Service |
2781ba |
GeglBuffer *input;
|
|
Packit Service |
2781ba |
gboolean success = FALSE;
|
|
Packit Service |
2781ba |
GeglRectangle extent;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
extent.x = o->x;
|
|
Packit Service |
2781ba |
extent.y = o->y;
|
|
Packit Service |
2781ba |
extent.width = o->width;
|
|
Packit Service |
2781ba |
extent.height = o->height;
|
|
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 crop", 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 |
|
|
Packit Service |
2781ba |
if (input != NULL)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglBuffer *output;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
output = gegl_buffer_create_sub_buffer (input, &extent);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (gegl_object_get_has_forked (input))
|
|
Packit Service |
2781ba |
gegl_object_set_has_forked (output);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_operation_context_take_object (context, "output", G_OBJECT (output));
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
g_object_unref (input);
|
|
Packit Service |
2781ba |
success = TRUE;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
else
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
if (!g_object_get_data (G_OBJECT (operation->node), "graph"))
|
|
Packit Service |
2781ba |
g_warning ("%s got %s",
|
|
Packit Service |
2781ba |
gegl_node_get_debug_name (operation->node),
|
|
Packit Service |
2781ba |
input==NULL?"input==NULL":"");
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
return success;
|
|
Packit Service |
2781ba |
}
|
|
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 |
|
|
Packit Service |
2781ba |
operation_class = GEGL_OPERATION_CLASS (klass);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
operation_class->process = gegl_crop_process;
|
|
Packit Service |
2781ba |
operation_class->get_bounding_box = gegl_crop_get_bounding_box;
|
|
Packit Service |
2781ba |
operation_class->detect = gegl_crop_detect;
|
|
Packit Service |
2781ba |
operation_class->get_invalidated_by_change = gegl_crop_get_invalidated_by_change;
|
|
Packit Service |
2781ba |
operation_class->get_required_for_output = gegl_crop_get_required_for_output;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
gegl_operation_class_set_keys (operation_class,
|
|
Packit Service |
2781ba |
"name", "gegl:crop",
|
|
Packit Service |
2781ba |
"categories", "core",
|
|
Packit Service |
2781ba |
"description", _("Crop a buffer"),
|
|
Packit Service |
2781ba |
NULL);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
operation_class->no_cache = TRUE;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#endif
|