svg-huerotate.c 3.62 KB
Newer Older
1
/* This file is an image processing operation for GEGL
2 3 4 5 6 7 8 9 10 11 12 13
 *
 * 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/>.
15 16 17
 *
 * Copyright 2006 Øyvind Kolås <pippin@gimp.org>
 * Copyright 2006 Geert Jordaens <geert.jordaens@telenet.be>
18
 */
19

20 21 22 23 24

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


25
#ifdef GEGL_PROPERTIES
26

27 28
property_string (values, _("Values"), "")
    description(_("list of <number>s"))
29

30 31
#else

32
#define GEGL_OP_POINT_FILTER
33
#define GEGL_OP_NAME     svg_huerotate
34
#define GEGL_OP_C_SOURCE svg-huerotate.c
35

36
#include "gegl-op.h"
37 38 39
#include <math.h>
#include <stdlib.h>

40
static void prepare (GeglOperation *operation)
41
{
42 43
  const Babl *space = gegl_operation_get_source_space (operation, "input");
  const Babl *format = babl_format_with_space ("RaGaBaA float", space);
44 45 46

  gegl_operation_set_format (operation, "input", format);
  gegl_operation_set_format (operation, "output", format);
47 48 49
}

static gboolean
50 51 52 53
process (GeglOperation       *op,
         void                *in_buf,
         void                *out_buf,
         glong                n_pixels,
54 55
         const GeglRectangle *roi,
         gint                 level)
56
{
57 58 59 60
  GeglProperties *o   = GEGL_PROPERTIES (op);
  gfloat         *in  = in_buf;
  gfloat         *out = out_buf;
  gfloat         *m;
61 62 63 64 65 66 67 68

  gfloat ma[25] = { 1.0, 0.0, 0.0, 0.0, 0.0,
                    0.0, 1.0, 0.0, 0.0, 0.0,
                    0.0, 0.0, 1.0, 0.0, 0.0,
                    0.0, 0.0, 0.0, 1.0, 0.0,
                    0.0, 0.0, 0.0, 0.0, 1.0};
  char        *endptr;
  gfloat       value;
69 70
  const gchar *delimiter = ",";
  const gchar *delimiters = " ";
71
  gchar      **values;
72
  glong        i;
73 74

  m = ma;
75

76
  if ( o->values != NULL )
77
    {
78
      g_strstrip(o->values);
79 80
      g_strdelimit (o->values, delimiters, *delimiter);
      values = g_strsplit (o->values, delimiter, 1);
81 82
      if ( values[0] != NULL )
        {
83
          value = g_ascii_strtod(values[0], &endptr);
84
          if (endptr != values[0])
85
            ma[0] = .213 + cos(value)*.787 - sin(value)*.213;
86 87 88
        }
      g_strfreev(values);
    }
89

90 91 92 93 94 95 96 97 98
  for (i=0; i<n_pixels; i++)
    {
      out[0] =  m[0]  * in[0] +  m[1]  * in[1] + m[2]  * in[2] + m[3]  * in[3] + m[4];
      out[1] =  m[5]  * in[0] +  m[6]  * in[1] + m[7]  * in[2] + m[8]  * in[3] + m[9];
      out[2] =  m[10] * in[0] +  m[11] * in[1] + m[12] * in[2] + m[13] * in[3] + m[14];
      out[3] =  m[15] * in[0] +  m[16] * in[1] + m[17] * in[2] + m[18] * in[3] + m[19];
      in  += 4;
      out += 4;
    }
99

100 101 102
  return TRUE;
}

103 104

static void
105
gegl_op_class_init (GeglOpClass *klass)
106 107 108 109 110 111 112 113 114 115
{
  GeglOperationClass            *operation_class;
  GeglOperationPointFilterClass *point_filter_class;

  operation_class    = GEGL_OPERATION_CLASS (klass);
  point_filter_class = GEGL_OPERATION_POINT_FILTER_CLASS (klass);

  point_filter_class->process = process;
  operation_class->prepare = prepare;

116 117 118
  gegl_operation_class_set_keys (operation_class,
    "name"       , "gegl:svg-huerotate",
    "categories" , "compositors:svgfilter",
119
    "title"      , _("SVG Hue Rotate"),
120 121
    "description", _("SVG color matrix operation svg_huerotate"),
    NULL);
122 123
}

124
#endif