Update Chinese (China) translation
[gegl.git] / operations / common / svg-luminancetoalpha.c
blob36752323bb9600e55f197e12b7a1c3233a972db6
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 2006 Øyvind Kolås <pippin@gimp.org>
17 * Copyright 2006 Geert Jordaens <geert.jordaens@telenet.be>
21 #include "config.h"
22 #include <glib/gi18n-lib.h>
25 #ifdef GEGL_PROPERTIES
27 #else
29 #define GEGL_OP_POINT_FILTER
30 #define GEGL_OP_NAME svg_luminancetoalpha
31 #define GEGL_OP_C_SOURCE svg-luminancetoalpha.c
33 #include "gegl-op.h"
34 #include <stdlib.h>
36 static void prepare (GeglOperation *operation)
38 const Babl *space = gegl_operation_get_source_space (operation, "input");
39 const Babl *format = babl_format_with_space ("RaGaBaA float", space);
41 gegl_operation_set_format (operation, "input", format);
42 gegl_operation_set_format (operation, "output", format);
45 static gboolean
46 process (GeglOperation *op,
47 void *in_buf,
48 void *out_buf,
49 glong n_pixels,
50 const GeglRectangle *roi,
51 gint level)
53 gfloat *in = in_buf;
54 gfloat *out = out_buf;
55 gfloat *m;
57 gfloat ma[25] = { 0.0, 0.0, 0.0, 0.0, 0.0,
58 0.0, 0.0, 0.0, 0.0, 0.0,
59 0.0, 0.0, 0.0, 0.0, 0.0,
60 0.2125, 0.7154, 0.0721, 0.0, 0.0,
61 0.0, 0.0, 0.0, 0.0, 1.0};
62 glong i;
64 m = ma;
65 for (i=0; i<n_pixels; i++)
67 out[0] = m[0] * in[0] + m[1] * in[1] + m[2] * in[2] + m[3] * in[3] + m[4];
68 out[1] = m[5] * in[0] + m[6] * in[1] + m[7] * in[2] + m[8] * in[3] + m[9];
69 out[2] = m[10] * in[0] + m[11] * in[1] + m[12] * in[2] + m[13] * in[3] + m[14];
70 out[3] = m[15] * in[0] + m[16] * in[1] + m[17] * in[2] + m[18] * in[3] + m[19];
71 in += 4;
72 out += 4;
74 return TRUE;
78 static void
79 gegl_op_class_init (GeglOpClass *klass)
81 GeglOperationClass *operation_class;
82 GeglOperationPointFilterClass *point_filter_class;
84 operation_class = GEGL_OPERATION_CLASS (klass);
85 point_filter_class = GEGL_OPERATION_POINT_FILTER_CLASS (klass);
87 point_filter_class->process = process;
88 operation_class->prepare = prepare;
90 gegl_operation_class_set_keys (operation_class,
91 "name" , "gegl:svg-luminancetoalpha",
92 "categories" , "compositors:svgfilter",
93 "title" , _("SVG Luminance to Alpha"),
94 "needs-alpha", "true",
95 "reference-hash", "6763517c5421d736b855ffa2ebd845c9",
96 "description",
97 _("SVG color matrix operation svg_luminancetoalpha"),
98 NULL);
101 #endif