1 /* GIMP - The GNU Image Manipulation Program
2 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3 *
4 * gimpoperationcurves.c
5 * Copyright (C) 2007 Michael Natterer <mitch@gimp.org>
6 *
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 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21 #include "config.h"
22
23 #include <cairo.h>
24 #include <gdk-pixbuf/gdk-pixbuf.h>
25 #include <gegl.h>
26
27 #include "libgimpmath/gimpmath.h"
28
29 #include "operations-types.h"
30
31 #include "core/gimpcurve.h"
32 #include "core/gimpcurve-map.h"
33
34 #include "gimpcurvesconfig.h"
35 #include "gimpoperationcurves.h"
36
37 #include "gimp-intl.h"
38
39
40 static gboolean gimp_operation_curves_process (GeglOperation *operation,
41 void *in_buf,
42 void *out_buf,
43 glong samples,
44 const GeglRectangle *roi,
45 gint level);
46
47
G_DEFINE_TYPE(GimpOperationCurves,gimp_operation_curves,GIMP_TYPE_OPERATION_POINT_FILTER)48 G_DEFINE_TYPE (GimpOperationCurves, gimp_operation_curves,
49 GIMP_TYPE_OPERATION_POINT_FILTER)
50
51 #define parent_class gimp_operation_curves_parent_class
52
53
54 static void
55 gimp_operation_curves_class_init (GimpOperationCurvesClass *klass)
56 {
57 GObjectClass *object_class = G_OBJECT_CLASS (klass);
58 GeglOperationClass *operation_class = GEGL_OPERATION_CLASS (klass);
59 GeglOperationPointFilterClass *point_class = GEGL_OPERATION_POINT_FILTER_CLASS (klass);
60
61 object_class->set_property = gimp_operation_point_filter_set_property;
62 object_class->get_property = gimp_operation_point_filter_get_property;
63
64 gegl_operation_class_set_keys (operation_class,
65 "name", "gimp:curves",
66 "categories", "color",
67 "description", _("Adjust color curves"),
68 NULL);
69
70 point_class->process = gimp_operation_curves_process;
71
72 g_object_class_install_property (object_class,
73 GIMP_OPERATION_POINT_FILTER_PROP_LINEAR,
74 g_param_spec_boolean ("linear",
75 "Linear",
76 "Whether to operate on linear RGB",
77 FALSE,
78 G_PARAM_READWRITE));
79
80 g_object_class_install_property (object_class,
81 GIMP_OPERATION_POINT_FILTER_PROP_CONFIG,
82 g_param_spec_object ("config",
83 "Config",
84 "The config object",
85 GIMP_TYPE_CURVES_CONFIG,
86 G_PARAM_READWRITE |
87 G_PARAM_CONSTRUCT));
88 }
89
90 static void
gimp_operation_curves_init(GimpOperationCurves * self)91 gimp_operation_curves_init (GimpOperationCurves *self)
92 {
93 }
94
95 static gboolean
gimp_operation_curves_process(GeglOperation * operation,void * in_buf,void * out_buf,glong samples,const GeglRectangle * roi,gint level)96 gimp_operation_curves_process (GeglOperation *operation,
97 void *in_buf,
98 void *out_buf,
99 glong samples,
100 const GeglRectangle *roi,
101 gint level)
102 {
103 GimpOperationPointFilter *point = GIMP_OPERATION_POINT_FILTER (operation);
104 GimpCurvesConfig *config = GIMP_CURVES_CONFIG (point->config);
105 gfloat *src = in_buf;
106 gfloat *dest = out_buf;
107
108 if (! config)
109 return FALSE;
110
111 gimp_curve_map_pixels (config->curve[0],
112 config->curve[1],
113 config->curve[2],
114 config->curve[3],
115 config->curve[4], src, dest, samples);
116
117 return TRUE;
118 }
119