gimpoperationcurves.c 4.54 KB
Newer Older
1 2 3 4 5 6
/* GIMP - The GNU Image Manipulation Program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * gimpoperationcurves.c
 * Copyright (C) 2007 Michael Natterer <mitch@gimp.org>
 *
7
 * This program is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation; either version 3 of the License, or
10 11 12 13 14 15 16 17
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 20 21 22
 */

#include "config.h"

23
#include <cairo.h>
24
#include <gdk-pixbuf/gdk-pixbuf.h>
25 26 27 28
#include <gegl.h>

#include "libgimpmath/gimpmath.h"

29
#include "operations-types.h"
30

31
#include "core/gimpcurve.h"
Sven Neumann's avatar
Sven Neumann committed
32
#include "core/gimpcurve-map.h"
33

34 35 36
#include "gimpcurvesconfig.h"
#include "gimpoperationcurves.h"

37 38
#include "gimp-intl.h"

39

40 41 42 43
static gboolean gimp_operation_curves_process (GeglOperation       *operation,
                                               void                *in_buf,
                                               void                *out_buf,
                                               glong                samples,
44 45
                                               const GeglRectangle *roi,
                                               gint                 level);
46 47 48


G_DEFINE_TYPE (GimpOperationCurves, gimp_operation_curves,
49
               GIMP_TYPE_OPERATION_POINT_FILTER)
50 51 52 53 54

#define parent_class gimp_operation_curves_parent_class


static void
55
gimp_operation_curves_class_init (GimpOperationCurvesClass *klass)
56 57 58 59 60
{
  GObjectClass                  *object_class    = G_OBJECT_CLASS (klass);
  GeglOperationClass            *operation_class = GEGL_OPERATION_CLASS (klass);
  GeglOperationPointFilterClass *point_class     = GEGL_OPERATION_POINT_FILTER_CLASS (klass);

61 62
  object_class->set_property   = gimp_operation_point_filter_set_property;
  object_class->get_property   = gimp_operation_point_filter_get_property;
63

64
  gegl_operation_class_set_keys (operation_class,
65 66
                                 "name",        "gimp:curves",
                                 "categories",  "color",
67
                                 "description", _("Adjust color curves"),
68
                                 NULL);
69

70
  point_class->process = gimp_operation_curves_process;
71

72 73 74 75 76 77 78 79
  g_object_class_install_property (object_class,
                                   GIMP_OPERATION_POINT_FILTER_PROP_LINEAR,
                                   g_param_spec_boolean ("linear",
                                                         "Linear",
                                                         "Whether to operate on linear RGB",
                                                         FALSE,
                                                         G_PARAM_READWRITE));

80 81
  g_object_class_install_property (object_class,
                                   GIMP_OPERATION_POINT_FILTER_PROP_CONFIG,
82 83 84 85 86 87 88 89 90 91 92 93 94 95
                                   g_param_spec_object ("config",
                                                        "Config",
                                                        "The config object",
                                                        GIMP_TYPE_CURVES_CONFIG,
                                                        G_PARAM_READWRITE |
                                                        G_PARAM_CONSTRUCT));
}

static void
gimp_operation_curves_init (GimpOperationCurves *self)
{
}

static gboolean
96 97 98 99
gimp_operation_curves_process (GeglOperation       *operation,
                               void                *in_buf,
                               void                *out_buf,
                               glong                samples,
100 101
                               const GeglRectangle *roi,
                               gint                 level)
102
{
103 104 105 106
  GimpOperationPointFilter *point  = GIMP_OPERATION_POINT_FILTER (operation);
  GimpCurvesConfig         *config = GIMP_CURVES_CONFIG (point->config);
  gfloat                   *src    = in_buf;
  gfloat                   *dest   = out_buf;
107 108 109 110

  if (! config)
    return FALSE;

111 112 113 114 115
  gimp_curve_map_pixels (config->curve[0],
                         config->curve[1],
                         config->curve[2],
                         config->curve[3],
                         config->curve[4], src, dest, samples);
116 117 118

  return TRUE;
}