buffer-sink.c 2.54 KB
Newer Older
1 2 3 4 5
/* 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
6
 * version 3 of the License, or (at your option) any later version.
7 8 9 10 11 12 13
 *
 * 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/>.
15 16 17
 *
 * Copyright 2006 Øyvind Kolås <pippin@gimp.org>
 */
18 19 20 21 22

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


23
#ifdef GEGL_PROPERTIES
24

25
property_pointer (buffer, _("Buffer location"),
26
                    _("The location where to store the output GeglBuffer"))
27
property_pointer (format, _("babl format"),
28
                    _("The babl format of the output GeglBuffer, NULL to use input buffer format"))
29

30 31
#else

32
#define GEGL_OP_SINK
33
#define GEGL_OP_NAME     buffer_sink
34
#define GEGL_OP_C_SOURCE buffer-sink.c
35

36
#include "gegl-op.h"
37 38

static gboolean
39 40
process (GeglOperation       *operation,
         GeglBuffer          *input,
41 42
         const GeglRectangle *result,
         gint                 level)
43
{
44
  GeglProperties *o = GEGL_PROPERTIES (operation);
45

46 47
  if (o->buffer != NULL &&
      (o->format == NULL || o->format == gegl_buffer_get_format (input)))
Øyvind Kolås's avatar
Øyvind Kolås committed
48
    {
49
      GeglBuffer **output = o->buffer;
50

51
      *output = gegl_buffer_create_sub_buffer (input, result);
Øyvind Kolås's avatar
Øyvind Kolås committed
52
    }
53 54 55 56 57 58 59 60
  else if (o->buffer != NULL &&
           o->format != NULL)
    {
      GeglBuffer **output = o->buffer;

      *output = gegl_buffer_new (gegl_buffer_get_extent (input),
                                 o->format);

61
      gegl_buffer_copy (input, NULL, GEGL_ABYSS_NONE,
62 63
                        *output, NULL);
    }
64

Øyvind Kolås's avatar
Øyvind Kolås committed
65
  return TRUE;
66 67
}

68 69

static void
70
gegl_op_class_init (GeglOpClass *klass)
71
{
72 73 74 75 76 77 78 79 80
  GeglOperationClass     *operation_class;
  GeglOperationSinkClass *sink_class;

  operation_class = GEGL_OPERATION_CLASS (klass);
  sink_class      = GEGL_OPERATION_SINK_CLASS (klass);

  sink_class->process = process;
  sink_class->needs_full = TRUE;

81 82
  gegl_operation_class_set_keys (operation_class,
      "name",       "gegl:buffer-sink",
83
      "title",      _("Buffer Sink"),
84
      "categories", "programming:output",
85
      "description", _("Create a new GEGL buffer to write the resulting rendering."),
86
      NULL);
87 88
}

89
#endif