crop.c 3.36 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_SELF
21

22 23 24 25
gegl_chant_double (x,      -G_MAXDOUBLE, G_MAXDOUBLE,  0.0, "left most pixel coordinate")
gegl_chant_double (y,      -G_MAXDOUBLE, G_MAXDOUBLE,  0.0, "top pixel coordinate")
gegl_chant_double (width,  -G_MAXDOUBLE, G_MAXDOUBLE, 10.0, "width in pixels")
gegl_chant_double (height, -G_MAXDOUBLE, G_MAXDOUBLE, 10.0, "height in pixels")
26 27 28

#else

29 30 31 32
#define GEGL_CHANT_FILTER
#define GEGL_CHANT_NAME            crop
#define GEGL_CHANT_SELF            "crop.c"
#define GEGL_CHANT_DESCRIPTION     "crops the image, can be used to rectangulary" \
Øyvind Kolås's avatar
Øyvind Kolås committed
33 34
                              "clip buffers, as well as specifying what " \
                              "portion of a composition to render to file"
35 36
#define GEGL_CHANT_CATEGORIES      "geometry"
#define GEGL_CHANT_CLASS_CONSTRUCT
37 38 39 40 41
#include "gegl-chant.h"


#include <stdio.h>

42
int gegl_chant_foo = 0;
43

44 45 46 47 48 49 50 51
/* Actual image processing code
 ************************************************************************/
static gboolean
evaluate (GeglOperation *operation,
          const gchar   *output_prop)
{
  GeglOperationFilter    *filter = GEGL_OPERATION_FILTER(operation);
  GeglBuffer  *input  = filter->input;
52
  ChantInstance *crop = GEGL_CHANT_INSTANCE (operation);
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76

  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,
                                 "x",     (int)crop->x,
                                 "y",     (int)crop->y,
                                 "width",  (int)crop->width,
                                 "height", (int)crop->height,
                                 NULL);
  crop = NULL;
  return  TRUE;
}

static gboolean
calc_have_rect (GeglOperation *operation)
{
Øyvind Kolås's avatar
Øyvind Kolås committed
77
  ChantInstance  *op_crop = (ChantInstance*)(operation);
78 79 80 81
  GeglRect *in_rect = gegl_operation_get_have_rect (operation, "input");
  if (!in_rect)
    return FALSE;

82
  gegl_operation_set_have_rect (operation,
83
     op_crop->x, op_crop->y,
84
     op_crop->width, op_crop->height);
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
  return TRUE;
}

static gboolean
calc_need_rect (GeglOperation *self)
{
  GeglRect *requested    = gegl_operation_need_rect (self);

  gegl_operation_set_need_rect (self, "input",
     requested->x,
     requested->y,
     requested->w, requested->h);
  return TRUE;
}

static void class_init (GeglOperationClass *operation_class)
{
  operation_class->calc_have_rect = calc_have_rect;
  operation_class->calc_need_rect = calc_need_rect;
}

#endif