convert-format.c 3.2 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 2007 Étienne Bersac <bersace03@laposte.net>
 * Copyright 2006 Øyvind Kolås <pippin@gimp.org>
18
 * Copyright 2013 Daniel Sabo
19 20
 *
 */
21 22 23 24

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

25
#ifdef GEGL_PROPERTIES
26

27
property_format (format, _("Output format"), NULL)
28
  description(_("The babl format of the output"))
29

30
#else
31

32
#define GEGL_OP_FILTER
33
#define GEGL_OP_NAME     convert_format
34
#define GEGL_OP_C_SOURCE convert-format.c
35

36
#include "gegl-op.h"
37

38 39
static void
prepare (GeglOperation *self)
40
{
41
  GeglProperties *o = GEGL_PROPERTIES (self);
42

43 44 45 46
  if (o->format)
    gegl_operation_set_format (self, "output", o->format);
  else
    gegl_operation_set_format (self, "output", gegl_operation_get_source_format (self, "input"));
47 48 49
}

static gboolean
50 51 52 53 54
operation_process (GeglOperation        *operation,
                   GeglOperationContext *context,
                   const gchar          *output_prop,
                   const GeglRectangle  *roi,
                   gint                  level)
55
{
56
  GeglProperties *o = GEGL_PROPERTIES (operation);
57 58
  GeglBuffer *input;

59
  input  = (GeglBuffer*) gegl_operation_context_get_object (context, "input");
60

61
  if (! o->format || gegl_buffer_get_format (input) == o->format)
62
    {
63 64 65
      gegl_operation_context_set_object (context, "output", G_OBJECT (input));

      return TRUE;
66 67
    }

68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
  return GEGL_OPERATION_CLASS (gegl_op_parent_class)->process (operation,
                                                               context,
                                                               output_prop,
                                                               roi, level);
}

static gboolean
process (GeglOperation       *operation,
         GeglBuffer          *input,
         GeglBuffer          *output,
         const GeglRectangle *roi,
         gint                 level)
{
  gegl_buffer_copy (input, roi, GEGL_ABYSS_NONE, output, roi);

83 84 85
  return TRUE;
}

86
static void
87
gegl_op_class_init (GeglOpClass *klass)
88
{
89 90
  GeglOperationClass       *operation_class = GEGL_OPERATION_CLASS (klass);
  GeglOperationFilterClass *filter_class    = GEGL_OPERATION_FILTER_CLASS (klass);
91

92 93
  operation_class->prepare = prepare;
  operation_class->process = operation_process;
94

95
  filter_class->process    = process;
96

97 98
  gegl_operation_class_set_keys (operation_class,
                "name",       "gegl:convert-format",
99
                "title",      _("Convert Format"),
100 101 102
                "categories", "core:color",
                "description", _("Convert the data to the specified format"),
                NULL);
103 104
}

105
#endif