Update Chinese (China) translation
[gegl.git] / operations / common / hue-chroma.c
blobcec117a25d056a7396c1dbab3c170973007f378e
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>
20 #include "config.h"
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)
37 #else
39 #define GEGL_OP_POINT_FILTER
41 #define GEGL_OP_NAME hue_chroma
42 #define GEGL_OP_C_SOURCE hue-chroma.c
44 #include "gegl-op.h"
46 #define EPSILON 1e-4f
48 static void
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));
58 static gboolean
59 process (GeglOperation *op,
60 void *in_buf,
61 void *out_buf,
62 glong n_pixels,
63 const GeglRectangle *roi,
64 gint level)
66 GeglProperties *o = GEGL_PROPERTIES (op);
67 gfloat *GEGL_ALIGNED in_pixel;
68 gfloat *GEGL_ALIGNED out_pixel;
69 gfloat hue;
70 gfloat chroma;
71 gfloat lightness;
73 in_pixel = in_buf;
74 out_pixel = out_buf;
76 hue = o->hue;
77 chroma = o->chroma;
78 lightness = o->lightness;
80 while (n_pixels--)
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;
88 else
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];
98 in_pixel += 4;
99 out_pixel += 4;
101 return TRUE;
104 #include "opencl/hue-chroma.cl.h"
106 static void
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"),
125 NULL);
128 #endif