remap.c 2.89 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
 * Copyright 2006-2010 Øyvind Kolås <pippin@gimp.org>
17 18
 */

19 20 21 22
#include "config.h"
#include <glib/gi18n-lib.h>


23
#ifdef GEGL_PROPERTIES
24

25
/* no properties */
26

27
#else
28

29
#define GEGL_OP_POINT_COMPOSER3
30
#define GEGL_OP_NAME     remap
31
#define GEGL_OP_C_SOURCE remap.c
32

33
#include "gegl-op.h"
34

35
static void prepare (GeglOperation *operation)
36
{
37 38
  const Babl *space = gegl_operation_get_source_space (operation, "input");
  const Babl *format = babl_format_with_space ("RGBA float", space);
39

40 41 42 43
  gegl_operation_set_format (operation, "input",  format);
  gegl_operation_set_format (operation, "aux",    format);
  gegl_operation_set_format (operation, "aux2",   format);
  gegl_operation_set_format (operation, "output", format);
44
}
45

46
static gboolean
47 48 49 50 51 52 53 54
process (GeglOperation       *op,
         void                *in_buf,
         void                *min_buf,
         void                *max_buf,
         void                *out_buf,
         glong                n_pixels,
         const GeglRectangle *roi,
         gint                 level)
55
{
56
  gint    i;
57 58 59 60
  gfloat *in = in_buf;
  gfloat *min = min_buf;
  gfloat *max = max_buf;
  gfloat *out = out_buf;
61 62
  if (!min || !max || !out || !in)
    return FALSE;
63 64

  for (i = 0; i < n_pixels; i++)
65
    {
66 67 68 69 70 71 72 73 74 75 76 77 78
      gint c;
      for (c = 0; c < 3; c++)
        {
          gfloat delta = max[c] - min[c];

          if (delta > 0.0001 || delta < -0.0001)
            out[c] = (in[c] - min[c]) / delta;
          else
            out[c] = in[c];
        }

      out[3] = in[3];

79 80 81 82
      in  += 4;
      out += 4;
      min += 4;
      max += 4;
83
    }
84 85 86
  return TRUE;
}

87
static void
88
gegl_op_class_init (GeglOpClass *klass)
89
{
90 91
  GeglOperationClass               *operation_class;
  GeglOperationPointComposer3Class *point_composer3_class;
92

93 94
  operation_class       = GEGL_OPERATION_CLASS (klass);
  point_composer3_class = GEGL_OPERATION_POINT_COMPOSER3_CLASS (klass);
95
  operation_class->prepare = prepare;
96 97

  point_composer3_class->process = process;
98

99 100
  gegl_operation_class_set_keys (operation_class,
    "name"       , "gegl:remap",
101
    "title"      , _("Remap"),
102 103
    "description",
          _("stretch components of pixels individually based on luminance envelopes"),
104
    "categories" , "compositors",
105
    NULL);
106 107
}

108
#endif