add.c 4.08 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

/* !!!! AUTOGENERATED FILE generated by math.rb !!!!!
 *
 * 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
17
 * License along with GEGL; if not, see <https://www.gnu.org/licenses/>.
18 19 20 21 22 23 24 25 26
 *
 * Copyright 2006 Øyvind Kolås <pippin@gimp.org>
 *
 * !!!! AUTOGENERATED FILE !!!!!
 */
#include "config.h"
#include <glib/gi18n-lib.h>


27
#ifdef GEGL_PROPERTIES
28

29 30
property_double (value, _("Value"), 0.0)
   description(_("global value used if aux doesn't contain data"))
31
   ui_range (-1.0, 1.0)
32 33 34

#else

35
#define GEGL_OP_POINT_COMPOSER
36
#define GEGL_OP_NAME         add
37
#define GEGL_OP_C_FILE       "add.c"
38

39
#include "gegl-op.h"
40 41 42 43 44 45 46 47 48

#include <math.h>
#ifdef _MSC_VER
#define powf(a,b) ((gfloat)pow(a,b))
#endif


static void prepare (GeglOperation *operation)
{
49 50 51
  const Babl *format = gegl_operation_get_source_format (operation, "input");
  if (!format)
    format = gegl_operation_get_source_format (operation, "aux");
52
  format = gegl_babl_variant (format, GEGL_BABL_VARIANT_LINEAR);
53 54

  gegl_operation_set_format (operation, "input", format);
55
  gegl_operation_set_format (operation, "aux", format);
56 57 58 59
  gegl_operation_set_format (operation, "output", format);
}

static gboolean
60 61 62 63 64 65 66
process (GeglOperation       *op,
         void                *in_buf,
         void                *aux_buf,
         void                *out_buf,
         glong                n_pixels,
         const GeglRectangle *roi,
         gint                 level)
67 68 69 70
{
  gfloat * GEGL_ALIGNED in = in_buf;
  gfloat * GEGL_ALIGNED out = out_buf;
  gfloat * GEGL_ALIGNED aux = aux_buf;
71 72 73
  const Babl *format = gegl_operation_get_format (op, "output");
  gint    components = babl_format_get_n_components (format);
  gint    alpha      = babl_format_has_alpha (format);
74 75 76 77
  gint    i;

  if (aux == NULL)
    {
78
      gfloat value = GEGL_PROPERTIES (op)->value;
79 80 81
      for (i=0; i<n_pixels; i++)
        {
          gint   j;
82
          for (j=0; j<components-alpha; j++)
83
            {
84 85 86 87
              gfloat result;
              gfloat input=in[j];
              result = input + value;
              out[j]=result;
88
            }
89 90 91 92
          if (alpha)
            out[components-1]=in[components-1];
          in += components;
          out+= components;
93 94 95 96 97 98 99 100
        }
    }
  else
    {
      for (i=0; i<n_pixels; i++)
        {
          gint   j;
          gfloat value;
101
          for (j=0; j<components-alpha; j++)
102
            {
103 104
              gfloat input =in[j];
              gfloat result;
105
              value=aux[j];
106 107
              result = input + value;
              out[j]=result;
108
            }
109 110 111 112 113 114
          if (alpha)
            out[components-1]=in[components-1];

          in  += components;
          aux += components;
          out += components;
115 116 117 118 119 120
        }
    }
  return TRUE;
}

static void
121
gegl_op_class_init (GeglOpClass *klass)
122 123 124 125 126 127 128 129 130 131
{
  GeglOperationClass              *operation_class;
  GeglOperationPointComposerClass *point_composer_class;

  operation_class  = GEGL_OPERATION_CLASS (klass);
  point_composer_class     = GEGL_OPERATION_POINT_COMPOSER_CLASS (klass);

  point_composer_class->process = process;
  operation_class->prepare = prepare;

132 133
  gegl_operation_class_set_keys (operation_class,
  "name"        , "gegl:add",
134
  "title"       , "Add",
135
  "categories"  , "compositors:math",
136
  "reference-hash"  , "3b665a3c7f3d3aac89c67bd7051c276f",
137
  "description" ,
138
       _("Math operation add, performs the operation per pixel, using either the constant provided in 'value' or the corresponding pixel from the buffer on aux as operands. The result is the evaluation of the expression result = input + value"),
139
       NULL);
140 141
}
#endif