tile.c 4.02 KB
Newer Older
Ville Sokk's avatar
Ville Sokk committed
1 2 3 4 5 6 7 8 9 10 11 12 13
/* 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 3 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
14
 * License along with GEGL; if not, see <https://www.gnu.org/licenses/>.
Ville Sokk's avatar
Ville Sokk committed
15 16 17 18 19 20 21
 *
 * Copyright 2012 Ville Sokk <ville.sokk@gmail.com>
 */

#include "config.h"
#include <glib/gi18n-lib.h>

22
#ifdef GEGL_PROPERTIES
23

24 25 26 27
property_int (offset_x, _("Horizontal offset"), 0)
    ui_range (0, 1024)
    ui_meta  ("unit", "pixel-coordinate")
    ui_meta  ("axis", "x")
28

29 30 31 32
property_int (offset_y, _("Vertical offset"), 0)
    ui_range (0, 1024)
    ui_meta  ("unit", "pixel-coordinate")
    ui_meta  ("axis", "y")
33 34

#else
Ville Sokk's avatar
Ville Sokk committed
35

36
#define GEGL_OP_FILTER
37
#define GEGL_OP_NAME     tile
38
#define GEGL_OP_C_SOURCE tile.c
Ville Sokk's avatar
Ville Sokk committed
39

40
#include "gegl-op.h"
Ville Sokk's avatar
Ville Sokk committed
41 42 43 44

static void
prepare (GeglOperation *operation)
{
45 46 47 48 49 50
  const Babl *format;

  format = gegl_operation_get_source_format (operation, "input");

  gegl_operation_set_format (operation, "input", format);
  gegl_operation_set_format (operation, "output", format);
Ville Sokk's avatar
Ville Sokk committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
}

static GeglRectangle
get_bounding_box (GeglOperation *operation)
{
  return gegl_rectangle_infinite_plane ();
}

static GeglRectangle
get_required_for_output (GeglOperation       *operation,
                         const gchar         *input_pad,
                         const GeglRectangle *roi)
{
  GeglRectangle *rect = gegl_operation_source_get_bounding_box (operation, input_pad);

  if (rect)
    {
      return *rect;
    }
  else
    {
      GeglRectangle empty = {0,};
      return empty;
    }
}

static GeglRectangle
get_invalidated_by_change (GeglOperation       *operation,
                           const gchar         *input_pad,
                           const GeglRectangle *input_roi)
{
  return gegl_rectangle_infinite_plane ();
}

static gboolean
process (GeglOperation       *operation,
         GeglBuffer          *input,
         GeglBuffer          *output,
         const GeglRectangle *result,
         gint                 level)
{
92
  GeglProperties *o = GEGL_PROPERTIES (operation);
Ville Sokk's avatar
Ville Sokk committed
93

94 95 96
  gegl_buffer_set_pattern (output, result, input,
                           o->offset_x,
                           o->offset_y);
Ville Sokk's avatar
Ville Sokk committed
97

98
  return TRUE;
Ville Sokk's avatar
Ville Sokk committed
99 100 101
}

static void
102
gegl_op_class_init (GeglOpClass *klass)
Ville Sokk's avatar
Ville Sokk committed
103 104 105
{
  GeglOperationClass       *operation_class;
  GeglOperationFilterClass *filter_class;
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
  gchar                    *composition = "<?xml version='1.0' encoding='UTF-8'?>"
    "<gegl>"
    "<node operation='gegl:crop'>"
    "  <params>"
    "    <param name='width'>200.0</param>"
    "    <param name='height'>200.0</param>"
    "  </params>"
    "</node>"
    "<node operation='gegl:tile'>"
    "</node>"
    "<node operation='gegl:load'>"
    "  <params>"
    "    <param name='path'>standard-aux.png</param>"
    "  </params>"
    "</node>"
    "</gegl>";
Ville Sokk's avatar
Ville Sokk committed
122 123 124 125 126 127 128 129 130 131 132

  operation_class  = GEGL_OPERATION_CLASS (klass);
  filter_class     = GEGL_OPERATION_FILTER_CLASS (klass);

  filter_class->process                      = process;
  operation_class->prepare                   = prepare;
  operation_class->get_bounding_box          = get_bounding_box;
  operation_class->get_required_for_output   = get_required_for_output;
  operation_class->get_invalidated_by_change = get_invalidated_by_change;

  gegl_operation_class_set_keys (operation_class,
133
      "name",                 "gegl:tile",
134
      "title",                _("Tile"),
135
      "categories",           "tile",
136
      "position-dependent",   "true",
137
      "reference-hash",       "166a4c955bb10d0a8472a2d8892baf39",
138 139 140 141
      "reference-composition", composition,
      "description",
      _("Infinitely repeats the input image."),
      NULL);
Ville Sokk's avatar
Ville Sokk committed
142 143
}
#endif