1 /* This file is an image processing operation for GEGL
3 * GEGL is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 3 of the License, or (at your option) any later version.
8 * GEGL is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * 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/>.
16 * Copyright 2017 Elle Stone <ellestone@ninedegreesbelow.com>
17 * Michael Natterer <mitch@gimp.org>
21 #include <glib/gi18n-lib.h>
23 #ifdef GEGL_PROPERTIES
25 property_double (hue
, _("Hue"), 0.0)
26 description (_("Hue adjustment"))
27 value_range (-180.0, 180.0)
29 property_double (chroma
, _("Chroma"), 0.0)
30 description (_("Chroma adjustment"))
31 value_range (-100.0, 100.0)
33 property_double (lightness
, _("Lightness"), 0.0)
34 description (_("Lightness adjustment"))
35 value_range (-100.0, 100.0)
39 #define GEGL_OP_POINT_FILTER
41 #define GEGL_OP_NAME hue_chroma
42 #define GEGL_OP_C_SOURCE hue-chroma.c
49 prepare (GeglOperation
*operation
)
51 const Babl
*space
= gegl_operation_get_source_space (operation
, "input");
52 gegl_operation_set_format (operation
, "input",
53 babl_format_with_space ("CIE LCH(ab) alpha float", space
));
54 gegl_operation_set_format (operation
, "output",
55 babl_format_with_space ("CIE LCH(ab) alpha float", space
));
59 process (GeglOperation
*op
,
63 const GeglRectangle
*roi
,
66 GeglProperties
*o
= GEGL_PROPERTIES (op
);
67 gfloat
*GEGL_ALIGNED in_pixel
;
68 gfloat
*GEGL_ALIGNED out_pixel
;
78 lightness
= o
->lightness
;
82 if ((fabsf(in_pixel
[1])>EPSILON
))
84 out_pixel
[0] = in_pixel
[0] + lightness
;
85 out_pixel
[1] = in_pixel
[1] + chroma
;
86 out_pixel
[2] = in_pixel
[2] + hue
;
90 out_pixel
[0] = in_pixel
[0] + lightness
;
91 out_pixel
[1] = in_pixel
[1];
92 out_pixel
[2] = in_pixel
[2];
95 out_pixel
[1] = CLAMP (out_pixel
[1], 0, 300.0);
96 out_pixel
[3] = in_pixel
[3];
104 #include "opencl/hue-chroma.cl.h"
107 gegl_op_class_init (GeglOpClass
*klass
)
109 GeglOperationClass
*operation_class
;
110 GeglOperationPointFilterClass
*point_filter_class
;
112 operation_class
= GEGL_OPERATION_CLASS (klass
);
113 point_filter_class
= GEGL_OPERATION_POINT_FILTER_CLASS (klass
);
115 operation_class
->prepare
= prepare
;
116 point_filter_class
->process
= process
;
118 gegl_operation_class_set_keys (operation_class
,
119 "name", "gegl:hue-chroma",
120 "title", _("Hue-Chroma"),
121 "categories", "color",
122 "reference-hash", "ffb9e86edb25bc92e8d4e68f59bbb04b",
123 "cl-source", hue_chroma_cl_source
,
124 "description", _("Adjust LCH Hue, Chroma, and Lightness"),