src-out.c 4.01 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

/* !!!! AUTOGENERATED FILE generated by svg-12-porter-duff.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
 *
 *  Copyright 2006, 2007 Øyvind Kolås <pippin@gimp.org>
 *            2007 John Marshall
21
 *            2013 Daniel Sabo
22 23 24 25 26 27 28 29 30 31 32 33 34 35
 *
 * SVG rendering modes; see:
 *     http://www.w3.org/TR/SVG12/rendering.html
 *     http://www.w3.org/TR/2004/WD-SVG12-20041027/rendering.html#comp-op-prop
 *
 *     aA = aux(src) alpha      aB = in(dst) alpha      aD = out alpha
 *     cA = aux(src) colour     cB = in(dst) colour     cD = out colour
 *
 * !!!! AUTOGENERATED FILE !!!!!
 */
#include "config.h"
#include <glib/gi18n-lib.h>


36
#ifdef GEGL_PROPERTIES
37

38 39
property_boolean (srgb, _("sRGB"), FALSE)
    description (_("Use sRGB gamma instead of linear"))
40 41 42

#else

43
#define GEGL_OP_POINT_COMPOSER
44
#define GEGL_OP_NAME         src_out
45
#define GEGL_OP_C_FILE        "src-out.c"
46

47
#include "gegl-op.h"
48 49 50

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

55 56
  if(GEGL_PROPERTIES (operation)->srgb)
    format = gegl_babl_variant (format, GEGL_BABL_VARIANT_PERCEPTUAL_PREMULTIPLIED);
57
  else
58
    format = gegl_babl_variant (format, GEGL_BABL_VARIANT_LINEAR_PREMULTIPLIED);
59

60 61
  gegl_operation_set_format (operation, "input",  format);
  gegl_operation_set_format (operation, "aux",    format);
62 63 64 65 66
  gegl_operation_set_format (operation, "output", format);
}

static gboolean
process (GeglOperation        *op,
67 68 69 70 71 72
         void                *in_buf,
         void                *aux_buf,
         void                *out_buf,
         glong                n_pixels,
         const GeglRectangle *roi,
         gint                 level)
73 74 75 76 77
{
  gint i;
  gfloat * GEGL_ALIGNED in = in_buf;
  gfloat * GEGL_ALIGNED aux = aux_buf;
  gfloat * GEGL_ALIGNED out = out_buf;
78 79
  const Babl *format = gegl_operation_get_format (op, "output");
  gint    components = babl_format_get_n_components (format);
80
  gint    alpha      = components-1;
81

82
  if (!aux)
83
    return TRUE;
84
  else
85
    {
86
      for (i = 0; i < n_pixels; i++)
87
        {
88 89 90
          gint   j;
          gfloat aA G_GNUC_UNUSED, aB G_GNUC_UNUSED, aD G_GNUC_UNUSED;

91 92
          aB = in[alpha];
          aA = aux[alpha];
93 94
          aD = aA * (1.0f - aB);

95
          for (j = 0; j < alpha; j++)
96 97 98 99 100 101 102
            {
              gfloat cA G_GNUC_UNUSED, cB G_GNUC_UNUSED;

              cB = in[j];
              cA = aux[j];
              out[j] = cA * (1.0f - aB);
            }
103
          out[alpha] = aD;
104 105 106
          in  += components;
          aux += components;
          out += components;
107 108 109 110 111 112 113
        }
    }
  return TRUE;
}


static void
114
gegl_op_class_init (GeglOpClass *klass)
115 116 117 118 119 120 121 122 123 124 125
{
  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;


126
  gegl_operation_class_set_keys (operation_class,
127 128
    "name"       , "svg:src-out",
    "compat-name", "gegl:src-out",
129
    "title"      , "Src-out",
130
    "reference-hash" , "64265021e1681dfc4485349cfe4f8a9e",
131
    "categories" , "compositors:porter-duff",
132 133 134 135 136
    "description",
        _("Porter Duff operation src-out (d = cA * (1.0f - aB))"),
        NULL);
 

137 138 139
}

#endif