|
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 2007 Øyvind Kolås
|
|
Packit Service |
2781ba |
*/
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include "config.h"
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include <math.h>
|
|
Packit Service |
2781ba |
#include <string.h>
|
|
Packit Service |
2781ba |
#include <glib-object.h>
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
#include "gegl.h"
|
|
Packit Service |
2781ba |
#include "gegl-types-internal.h"
|
|
Packit Service |
2781ba |
#include "gegl-operation-area-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 |
|
|
Packit Service |
2781ba |
static void prepare (GeglOperation *operation);
|
|
Packit Service |
2781ba |
static GeglRectangle get_bounding_box (GeglOperation *operation);
|
|
Packit Service |
2781ba |
static GeglRectangle get_required_for_output (GeglOperation *operation,
|
|
Packit Service |
2781ba |
const gchar *input_pad,
|
|
Packit Service |
2781ba |
const GeglRectangle *region);
|
|
Packit Service |
2781ba |
static GeglRectangle 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 |
G_DEFINE_TYPE (GeglOperationAreaFilter, gegl_operation_area_filter,
|
|
Packit Service |
2781ba |
GEGL_TYPE_OPERATION_FILTER)
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static void
|
|
Packit Service |
2781ba |
gegl_operation_area_filter_class_init (GeglOperationAreaFilterClass *klass)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglOperationClass *operation_class = GEGL_OPERATION_CLASS (klass);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
operation_class->prepare = prepare;
|
|
Packit Service |
2781ba |
operation_class->get_bounding_box = get_bounding_box;
|
|
Packit Service |
2781ba |
operation_class->get_invalidated_by_change = get_invalidated_by_change;
|
|
Packit Service |
2781ba |
operation_class->get_required_for_output = get_required_for_output;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static void
|
|
Packit Service |
2781ba |
gegl_operation_area_filter_init (GeglOperationAreaFilter *self)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
self->left=0;
|
|
Packit Service |
2781ba |
self->right=0;
|
|
Packit Service |
2781ba |
self->bottom=0;
|
|
Packit Service |
2781ba |
self->top=0;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static void prepare (GeglOperation *operation)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
gegl_operation_set_format (operation, "input", babl_format ("RGBA float"));
|
|
Packit Service |
2781ba |
gegl_operation_set_format (operation, "output", babl_format ("RGBA float"));
|
|
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 |
GeglOperationAreaFilter *area = GEGL_OPERATION_AREA_FILTER (operation);
|
|
Packit Service |
2781ba |
GeglRectangle result = { 0, };
|
|
Packit Service |
2781ba |
GeglRectangle *in_rect;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
in_rect = gegl_operation_source_get_bounding_box (operation,"input");
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (!in_rect)
|
|
Packit Service |
2781ba |
return result;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
result = *in_rect;
|
|
Packit Service |
2781ba |
if (result.width != 0 &&
|
|
Packit Service |
2781ba |
result.height != 0)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
result.x-= area->left;
|
|
Packit Service |
2781ba |
result.y-= area->top;
|
|
Packit Service |
2781ba |
result.width += area->left + area->right;
|
|
Packit Service |
2781ba |
result.height += area->top + area->bottom;
|
|
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 *region)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
GeglOperationAreaFilter *area = GEGL_OPERATION_AREA_FILTER (operation);
|
|
Packit Service |
2781ba |
GeglRectangle rect;
|
|
Packit Service |
2781ba |
GeglRectangle defined;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
defined = get_bounding_box (operation);
|
|
Packit Service |
2781ba |
gegl_rectangle_intersect (&rect, region, &defined);
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
if (rect.width != 0 &&
|
|
Packit Service |
2781ba |
rect.height != 0)
|
|
Packit Service |
2781ba |
{
|
|
Packit Service |
2781ba |
rect.x -= area->left;
|
|
Packit Service |
2781ba |
rect.y -= area->top;
|
|
Packit Service |
2781ba |
rect.width += area->left + area->right;
|
|
Packit Service |
2781ba |
rect.height += area->top + area->bottom;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
return rect;
|
|
Packit Service |
2781ba |
}
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
static GeglRectangle
|
|
Packit Service |
2781ba |
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 |
GeglOperationAreaFilter *area = GEGL_OPERATION_AREA_FILTER (operation);
|
|
Packit Service |
2781ba |
GeglRectangle retval;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
retval.x = input_region->x - area->left;
|
|
Packit Service |
2781ba |
retval.y = input_region->y - area->top;
|
|
Packit Service |
2781ba |
retval.width = input_region->width + area->left + area->right;
|
|
Packit Service |
2781ba |
retval.height = input_region->height + area->top + area->bottom;
|
|
Packit Service |
2781ba |
|
|
Packit Service |
2781ba |
return retval;
|
|
Packit Service |
2781ba |
}
|