shift.c 3.24 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/* This file is an image processing operation for GEGL
 *
 * GEGL is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * GEGL is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with GEGL; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 * Copyright 2006 Øyvind Kolås <pippin@gimp.org>
 */
20
#ifdef GEGL_CHANT_PROPERTIES
21
 
22 23
gegl_chant_double (x, -G_MAXDOUBLE, G_MAXDOUBLE,  0.0, "x coordinate of new origin")
gegl_chant_double (y, -G_MAXDOUBLE, G_MAXDOUBLE,  0.0, "y coordinate of new origin")
24 25 26

#else

27 28 29 30 31
#define GEGL_CHANT_FILTER
#define GEGL_CHANT_NAME            shift
#define GEGL_CHANT_DESCRIPTION     "Translate the buffer, an integer amount of pixels."
#define GEGL_CHANT_SELF            "shift.c"
#define GEGL_CHANT_CATEGORIES      "geometry"
Øyvind Kolås's avatar
Øyvind Kolås committed
32
#define GEGL_CHANT_CLASS_INIT
33 34 35 36 37
#include "gegl-chant.h"


#include <stdio.h>

38
int gegl_chant_foo = 0;
39 40 41 42
  
/* Actual image processing code
 ************************************************************************/
static gboolean
Øyvind Kolås's avatar
Øyvind Kolås committed
43
process (GeglOperation *operation,
44 45 46
          const gchar   *output_prop)
{
  GeglOperationFilter    *filter = GEGL_OPERATION_FILTER(operation);
Øyvind Kolås's avatar
Øyvind Kolås committed
47
  GeglBuffer    *input  = filter->input;
48
  GeglChantOperation *translate = (GeglChantOperation*)filter;
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69

  if(strcmp("output", output_prop))
    return FALSE;

  if (filter->output)
    g_object_unref (filter->output);

  g_assert (input);
  g_assert (gegl_buffer_get_format (input));

  filter->output = g_object_new (GEGL_TYPE_BUFFER,
                                 "source",       input,
                                 "shift-x",     (int)-translate->x,
                                 "shift-y",     (int)-translate->y,
                                 "abyss-width", -1,  /* turn of abyss (relying
                                                        on abyss of source) */
                                 NULL);
  translate = NULL;
  return  TRUE;
}

70
static GeglRect
71
get_defined_region (GeglOperation *operation)
72
{
73
  GeglRect result = {0,0,0,0};
74
  GeglChantOperation  *op_shift = (GeglChantOperation*)(operation);
75
  GeglRect *in_rect = gegl_operation_source_get_defined_region (operation, "input");
76
  if (!in_rect)
77
    return result;
78

79 80 81 82 83
  result = *in_rect;
  result.x += op_shift->x;
  result.y += op_shift->y;
 
  return result;
84 85 86
}

static gboolean
87
calc_source_regions (GeglOperation *self)
88
{
89
  GeglChantOperation  *op_shift = (GeglChantOperation*)(self);
90
  GeglRect rect = *gegl_operation_get_requested_region (self);
91

92 93 94 95
  rect.x -= op_shift->x;
  rect.y -= op_shift->y;

  gegl_operation_set_source_region (self, "input", &rect);
96 97 98 99 100
  return TRUE;
}

static void class_init (GeglOperationClass *operation_class)
{
101
  operation_class->get_defined_region = get_defined_region;
102
  operation_class->calc_source_regions = calc_source_regions;
103 104 105
}

#endif