Code

54312685c387396a7024b6f9dd3025fdb209e296
[inkscape.git] / src / extension / internal / filter / color.h
1 #ifndef __INKSCAPE_EXTENSION_INTERNAL_FILTER_COLOR_H__
2 #define __INKSCAPE_EXTENSION_INTERNAL_FILTER_COLOR_H__
3 /* Change the 'COLOR' above to be your file name */
5 /*
6  * Copyright (C) 2010 Authors:
7  *   Ivan Louette (filters)
8  *   Nicolas Dufour (UI) <nicoduf@yahoo.fr>
9  *
10  * Color filters
11  *   Colorize
12  *   Duochrome
13  *   Quadritone
14  *   Solarize
15  *   Tritone
16  *
17  * Released under GNU GPL, read the file 'COPYING' for more information
18  */
19 /* ^^^ Change the copyright to be you and your e-mail address ^^^ */
21 #include "filter.h"
23 #include "extension/internal/clear-n_.h"
24 #include "extension/system.h"
25 #include "extension/extension.h"
27 namespace Inkscape {
28 namespace Extension {
29 namespace Internal {
30 namespace Filter {
32 /**
33     \brief    Custom predefined Colorize filter.
34     
35     Blend image or object with a flood color.
37     Filter's parameters:
38     * Harsh light (0.->10., default 0) -> composite1 (k1)
39     * Normal light (0.->10., default 1) -> composite2 (k2)
40     * Duotone (boolean, default false) -> colormatrix1 (values="0")
41     * Filtered greys (boolean, default false) -> colormatrix2 (values="0")
42     * Blend mode 1 (enum, default Multiply) -> blend1 (mode)
43     * Blend mode 2 (enum, default Screen) -> blend2 (mode)
44 */
46 class Colorize : public Inkscape::Extension::Internal::Filter::Filter {
47 protected:
48         virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
50 public:
51         Colorize ( ) : Filter() { };
52         virtual ~Colorize ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
54         static void init (void) {
55                 Inkscape::Extension::build_from_mem(
56                         "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
57                                 "<name>" N_("Colorize, custom -EXP-") "</name>\n"
58                                 "<id>org.inkscape.effect.filter.Colorize</id>\n"
59                         "<param name=\"hlight\" gui-text=\"" N_("Harsh light:") "\" type=\"float\" min=\"0\" max=\"10\">0</param>\n"
60                         "<param name=\"nlight\" gui-text=\"" N_("Normal light:") "\" type=\"float\" min=\"0\" max=\"10\">1</param>\n"
61                         "<param name=\"duotone\" gui-text=\"" N_("Duotone") "\" type=\"boolean\" >false</param>\n"
62                         "<param name=\"blend1\" gui-text=\"" N_("Blend1:") "\" type=\"enum\">\n"
63                             "<_item value=\"multiply\">Multiply</_item>\n"
64                             "<_item value=\"normal\">Normal</_item>\n"
65                             "<_item value=\"screen\">Screen</_item>\n"
66                             "<_item value=\"lighten\">Lighten</_item>\n"
67                             "<_item value=\"darken\">Darken</_item>\n"
68                         "</param>\n"
69                         "<param name=\"blend2\" gui-text=\"" N_("Blend2:") "\" type=\"enum\">\n"
70                             "<_item value=\"screen\">Screen</_item>\n"
71                             "<_item value=\"multiply\">Multiply</_item>\n"
72                             "<_item value=\"normal\">Normal</_item>\n"
73                             "<_item value=\"lighten\">Lighten</_item>\n"
74                             "<_item value=\"darken\">Darken</_item>\n"
75                         "</param>\n"
76                                         "<param name=\"color\" gui-text=\"" N_("Color 1") "\" type=\"color\">-1639776001</param>\n"
77                                 "<effect>\n"
78                                         "<object-type>all</object-type>\n"
79                                         "<effects-menu>\n"
80                                                 "<submenu name=\"" N_("Filters") "\">\n"
81                                                 "<submenu name=\"" N_("Experimental") "\"/>\n"
82                               "</submenu>\n"
83                                         "</effects-menu>\n"
84                                         "<menu-tip>" N_("Blend image or object with a flood color") "</menu-tip>\n"
85                                 "</effect>\n"
86                         "</inkscape-extension>\n", new Colorize());
87         };
89 };
91 gchar const *
92 Colorize::get_filter_text (Inkscape::Extension::Extension * ext)
93 {
94         if (_filter != NULL) g_free((void *)_filter);
96     std::ostringstream a;
97     std::ostringstream r;
98     std::ostringstream g;
99     std::ostringstream b;
100     std::ostringstream hlight;
101     std::ostringstream nlight;
102     std::ostringstream duotone;
103     std::ostringstream blend1;
104     std::ostringstream blend2;
106     guint32 color = ext->get_param_color("color");
107     r << ((color >> 24) & 0xff);
108     g << ((color >> 16) & 0xff);
109     b << ((color >>  8) & 0xff);
110     a << (color & 0xff) / 255.0F;
112     hlight << ext->get_param_float("hlight");
113     nlight << ext->get_param_float("nlight");
114     blend1 << ext->get_param_enum("blend1");
115     blend2 << ext->get_param_enum("blend2");
116     if (ext->get_param_bool("duotone"))
117         duotone << "0";
118     else
119         duotone << "1";
121         _filter = g_strdup_printf(
122                 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" color-interpolation-filters=\"sRGB\" height=\"1\" width=\"1\" y=\"0\" x=\"0\" inkscape:label=\"Colorize, custom -EXP-\">\n"
123             "<feComposite in2=\"SourceGraphic\" operator=\"arithmetic\" k1=\"%s\" k2=\"%s\" result=\"composite1\" />\n"
124             "<feColorMatrix in=\"composite1\" values=\"%s\" type=\"saturate\" result=\"colormatrix1\" />\n"
125             "<feFlood flood-opacity=\"%s\" flood-color=\"rgb(%s,%s,%s)\" result=\"flood1\" />\n"
126             "<feBlend in=\"flood1\" in2=\"colormatrix1\" mode=\"%s\" result=\"blend1\" />\n"
127             "<feBlend in2=\"blend1\" mode=\"%s\" result=\"blend2\" />\n"
128             "<feColorMatrix in=\"blend2\" values=\"1\" type=\"saturate\" result=\"colormatrix2\" />\n"
129             "<feComposite in=\"colormatrix2\" in2=\"SourceGraphic\" operator=\"in\" k2=\"1\" result=\"composite2\" />\n"
130         "</filter>\n", hlight.str().c_str(), nlight.str().c_str(), duotone.str().c_str(), a.str().c_str(), r.str().c_str(), g.str().c_str(), b.str().c_str(), blend1.str().c_str(), blend2.str().c_str());
132         return _filter;
133 }; /* Colorize filter */
136 /**
137     \brief    Custom predefined Duochrome filter.
138     
139     Convert luminance values to a duochrome palette.
141     Filter's parameters:
142     * Fluorescence level (0.->2., default 0) -> composite4 (k2)
143     * Swap (enum, default "No swap") -> composite1, composite2 (operator)
144     * Color 1 (guint, default 1364325887) -> flood1 (flood-opacity, flood-color)
145     * Color 2 (guint, default -65281) -> flood2 (flood-opacity, flood-color)
146 */
148 class Duochrome : public Inkscape::Extension::Internal::Filter::Filter {
149 protected:
150         virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
152 public:
153         Duochrome ( ) : Filter() { };
154         virtual ~Duochrome ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
156         static void init (void) {
157                 Inkscape::Extension::build_from_mem(
158                         "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
159                                 "<name>" N_("Duochrome, custom -EXP-") "</name>\n"
160                                 "<id>org.inkscape.effect.filter.Duochrome</id>\n"
161                     "<param name=\"tab\" type=\"notebook\">\n"
162                     "<page name=\"optionstab\" _gui-text=\"Options\">\n"
163                         "<param name=\"fluo\" gui-text=\"" N_("Fluorescence level:") "\" type=\"float\" min=\"0\" max=\"2\">0</param>\n"
164                         "<param name=\"swap\" gui-text=\"" N_("Swap:") "\" type=\"enum\">\n"
165                             "<_item value=\"none\">No swap</_item>\n"
166                             "<_item value=\"full\">Color and alpha</_item>\n"
167                             "<_item value=\"color\">Color only</_item>\n"
168                             "<_item value=\"alpha\">Alpha only</_item>\n"
169                         "</param>\n"
170                     "</page>\n"
171                     "<page name=\"co11tab\" _gui-text=\"Color 1\">\n"
172                                         "<param name=\"color1\" gui-text=\"" N_("Color 1") "\" type=\"color\">1364325887</param>\n"
173                     "</page>\n"
174                     "<page name=\"co12tab\" _gui-text=\"Color 2\">\n"
175                                         "<param name=\"color2\" gui-text=\"" N_("Color 2") "\" type=\"color\">-65281</param>\n"
176                     "</page>\n"
177                 "</param>\n"
178                                 "<effect>\n"
179                                         "<object-type>all</object-type>\n"
180                                         "<effects-menu>\n"
181                                                 "<submenu name=\"" N_("Filters") "\">\n"
182                                                 "<submenu name=\"" N_("Experimental") "\"/>\n"
183                               "</submenu>\n"
184                                         "</effects-menu>\n"
185                                         "<menu-tip>" N_("Convert luminance values to a duochrome palette") "</menu-tip>\n"
186                                 "</effect>\n"
187                         "</inkscape-extension>\n", new Duochrome());
188         };
190 };
192 gchar const *
193 Duochrome::get_filter_text (Inkscape::Extension::Extension * ext)
195         if (_filter != NULL) g_free((void *)_filter);
197     std::ostringstream a1;
198     std::ostringstream r1;
199     std::ostringstream g1;
200     std::ostringstream b1;
201     std::ostringstream a2;
202     std::ostringstream r2;
203     std::ostringstream g2;
204     std::ostringstream b2;
205     std::ostringstream fluo;
206     std::ostringstream swap1;
207     std::ostringstream swap2;
208     guint32 color1 = ext->get_param_color("color1");
209     guint32 color2 = ext->get_param_color("color2");
210     float fluorescence = ext->get_param_float("fluo");
211     const gchar *swaptype = ext->get_param_enum("swap");
213     r1 << ((color1 >> 24) & 0xff);
214     g1 << ((color1 >> 16) & 0xff);
215     b1 << ((color1 >>  8) & 0xff);
216     r2 << ((color2 >> 24) & 0xff);
217     g2 << ((color2 >> 16) & 0xff);
218     b2 << ((color2 >>  8) & 0xff);
219     fluo << fluorescence;
221     if((g_ascii_strcasecmp("full", swaptype) == 0)) {
222         swap1 << "in";
223         swap2 << "out";
224         a1 << (color1 & 0xff) / 255.0F;
225         a2 << (color2 & 0xff) / 255.0F;
226     } else if((g_ascii_strcasecmp("color", swaptype) == 0)) {
227         swap1 << "in";
228         swap2 << "out";
229         a1 << (color2 & 0xff) / 255.0F;
230         a2 << (color1 & 0xff) / 255.0F;
231     } else if((g_ascii_strcasecmp("alpha", swaptype) == 0)) {
232         swap1 << "out";
233         swap2 << "in";
234         a1 << (color2 & 0xff) / 255.0F;
235         a2 << (color1 & 0xff) / 255.0F;
236     } else {
237         swap1 << "out";
238         swap2 << "in";
239         a1 << (color1 & 0xff) / 255.0F;
240         a2 << (color2 & 0xff) / 255.0F;
241     }
243         _filter = g_strdup_printf(
244                 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" color-interpolation-filters=\"sRGB\" height=\"1\" width=\"1\" y=\"0\" x=\"0\" inkscape:label=\"Duochrome, custom -EXP-\">\n"
245             "<feColorMatrix type=\"luminanceToAlpha\" result=\"colormatrix1\" />\n"
246             "<feFlood flood-opacity=\"%s\" flood-color=\"rgb(%s,%s,%s)\" result=\"flood1\" />\n"
247             "<feComposite in2=\"colormatrix1\" operator=\"%s\" result=\"composite1\" />\n"
248             "<feFlood in=\"colormatrix1\" flood-opacity=\"%s\" flood-color=\"rgb(%s,%s,%s)\" result=\"flood2\" />\n"
249             "<feComposite in2=\"colormatrix1\" result=\"composite2\" operator=\"%s\" />\n"
250             "<feComposite in=\"composite2\" in2=\"composite1\" k2=\"1\"  k3=\"1\" operator=\"arithmetic\" result=\"composite3\" />\n"
251             "<feColorMatrix in=\"composite3\" type=\"matrix\" values=\"2 -1 0 0 0 0 2 -1 0 0 -1 0 2 0 0 0 0 0 1 0 \" result=\"colormatrix2\" />\n"
252             "<feComposite in=\"colormatrix2\" in2=\"composite3\" operator=\"arithmetic\" k2=\"%s\" result=\"composite4\" />\n"
253             "<feBlend in=\"composite4\" in2=\"composite3\" blend=\"normal\" mode=\"normal\" result=\"blend\" />\n"
254             "<feComposite in2=\"SourceGraphic\" operator=\"in\" />\n"
255         "</filter>\n", a1.str().c_str(), r1.str().c_str(), g1.str().c_str(), b1.str().c_str(), swap1.str().c_str(), a2.str().c_str(), r2.str().c_str(), g2.str().c_str(), b2.str().c_str(), swap2.str().c_str(), fluo.str().c_str());
257         return _filter;
258 }; /* Duochrome filter */
261 /**
262     \brief    Custom predefined Quadritone filter.
263     
264     Replace hue by two colors.
266     Filter's parameters:
267     * Hue distribution (0->360, default 280) -> colormatrix1 (values)
268     * Colors (0->360, default 100) -> colormatrix3 (values)
269     * Blend mode 1 (enum, default Normal) -> blend1 (mode)
270     * Over-saturation (0.->1., default 0) -> composite1 (k2)
271     * Blend mode 2 (enum, default Normal) -> blend2 (mode)
272 */
274 class Quadritone : public Inkscape::Extension::Internal::Filter::Filter {
275 protected:
276         virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
278 public:
279         Quadritone ( ) : Filter() { };
280         virtual ~Quadritone ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
282         static void init (void) {
283                 Inkscape::Extension::build_from_mem(
284                         "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
285                                 "<name>" N_("Quadritone fantasy, custom -EXP-") "</name>\n"
286                                 "<id>org.inkscape.effect.filter.Quadritone</id>\n"
287                         "<param name=\"dist\" gui-text=\"" N_("Hue distribution:") "\" type=\"int\" min=\"0\" max=\"360\">280</param>\n"
288                         "<param name=\"colors\" gui-text=\"" N_("Colors:") "\" type=\"int\" min=\"0\" max=\"360\">100</param>\n"
289                         "<param name=\"blend1\" gui-text=\"" N_("Blend1:") "\" type=\"enum\">\n"
290                             "<_item value=\"normal\">Normal</_item>\n"
291                             "<_item value=\"multiply\">Multiply</_item>\n"
292                             "<_item value=\"screen\">Screen</_item>\n"
293                         "</param>\n"
294                         "<param name=\"sat\" gui-text=\"" N_("Over-saturation:") "\" type=\"float\" min=\"0\" max=\"1\">0</param>\n"
295                         "<param name=\"blend2\" gui-text=\"" N_("Blend2:") "\" type=\"enum\">\n"
296                             "<_item value=\"normal\">Normal</_item>\n"
297                             "<_item value=\"screen\">Screen</_item>\n"
298                             "<_item value=\"multiply\">Multiply</_item>\n"
299                             "<_item value=\"lighten\">Lighten</_item>\n"
300                             "<_item value=\"darken\">Darken</_item>\n"
301                         "</param>\n"
302                                 "<effect>\n"
303                                         "<object-type>all</object-type>\n"
304                                         "<effects-menu>\n"
305                                                 "<submenu name=\"" N_("Filters") "\">\n"
306                                                 "<submenu name=\"" N_("Experimental") "\"/>\n"
307                               "</submenu>\n"
308                                         "</effects-menu>\n"
309                                         "<menu-tip>" N_("Replace hue by two colors") "</menu-tip>\n"
310                                 "</effect>\n"
311                         "</inkscape-extension>\n", new Quadritone());
312         };
314 };
316 gchar const *
317 Quadritone::get_filter_text (Inkscape::Extension::Extension * ext)
319         if (_filter != NULL) g_free((void *)_filter);
321     std::ostringstream dist;
322     std::ostringstream colors;
323     std::ostringstream blend1;
324     std::ostringstream sat;
325     std::ostringstream blend2;
327     dist << ext->get_param_int("dist");
328     colors << ext->get_param_int("colors");
329     blend1 << ext->get_param_enum("blend1");
330     sat << ext->get_param_float("sat");
331     blend2 << ext->get_param_enum("blend2");
333         _filter = g_strdup_printf(
334                 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" color-interpolation-filters=\"sRGB\" height=\"1\" width=\"1\" y=\"0\" x=\"0\" inkscape:label=\"Quadritone fantasy, custom -EXP-\">\n"
335             "<feColorMatrix in=\"SourceGraphic\" type=\"hueRotate\" values=\"%s\" result=\"colormatrix1\" />\n"
336             "<feColorMatrix type=\"matrix\" values=\"0.5 0 0.5 0 0 0 1 0 0 0 0.5 0 0.5 0 0 0 0 0 1 0 \" result=\"colormatrix2\" />\n"
337             "<feColorMatrix type=\"hueRotate\" values=\"%s\" result=\"colormatrix3\" />\n"
338             "<feBlend in2=\"colormatrix3\" blend=\"normal\" mode=\"%s\" result=\"blend1\" />\n"
339             "<feColorMatrix type=\"matrix\" values=\"2.5 -0.75 -0.75 0 0 -0.75 2.5 -0.75 0 0 -0.75 -0.75 2.5 0 0 0 0 0 1 0 \" result=\"colormatrix4\" />\n"
340             "<feComposite in=\"colormatrix4\" in2=\"blend1\" operator=\"arithmetic\" k2=\"%s\" result=\"composite1\" />\n"
341             "<feBlend in2=\"blend1\" blend=\"normal\" mode=\"%s\" result=\"blend2\" />\n"
342         "</filter>\n", dist.str().c_str(), colors.str().c_str(), blend1.str().c_str(), sat.str().c_str(), blend2.str().c_str());
344         return _filter;
345 }; /* Quadritone filter */
348 /**
349     \brief    Custom predefined Solarize filter.
350     
351     Classic photographic solarization effect.
353     Filter's parameters:
354     * Type (enum, default "Solarize") ->
355         Solarize = blend1 (mode="darken"), blend2 (mode="screen")
356         Moonarize = blend1 (mode="lighten"), blend2 (mode="multiply") [No other access to the blend modes]
357     * Hue rotation (0->360, default 0) -> colormatrix1 (values)
358 */
361 class Solarize : public Inkscape::Extension::Internal::Filter::Filter {
362 protected:
363         virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
365 public:
366         Solarize ( ) : Filter() { };
367         virtual ~Solarize ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
369         static void init (void) {
370                 Inkscape::Extension::build_from_mem(
371                         "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
372                                 "<name>" N_("Solarize, custom -EXP-") "</name>\n"
373                                 "<id>org.inkscape.effect.filter.Solarize</id>\n"
374                         "<param name=\"rotate\" gui-text=\"" N_("Hue rotation:") "\" type=\"int\" min=\"0\" max=\"360\">0</param>\n"
375                         "<param name=\"type\" gui-text=\"" N_("Type:") "\" type=\"enum\">\n"
376                             "<_item value=\"solarize\">Solarize</_item>\n"
377                             "<_item value=\"moonarize\">Moonarize</_item>\n"
378                         "</param>\n"
379                                 "<effect>\n"
380                                         "<object-type>all</object-type>\n"
381                                         "<effects-menu>\n"
382                                                 "<submenu name=\"" N_("Filters") "\">\n"
383                                                 "<submenu name=\"" N_("Experimental") "\"/>\n"
384                               "</submenu>\n"
385                                         "</effects-menu>\n"
386                                         "<menu-tip>" N_("Classic photographic solarization effect") "</menu-tip>\n"
387                                 "</effect>\n"
388                         "</inkscape-extension>\n", new Solarize());
389         };
391 };
393 gchar const *
394 Solarize::get_filter_text (Inkscape::Extension::Extension * ext)
396         if (_filter != NULL) g_free((void *)_filter);
398     std::ostringstream rotate;
399     std::ostringstream blend1;
400     std::ostringstream blend2;
402     rotate << ext->get_param_int("rotate");
403     const gchar *type = ext->get_param_enum("type");
404     if((g_ascii_strcasecmp("solarize", type) == 0)) {
405     // Solarize
406         blend1 << "darken";
407         blend2 << "screen";
408     } else {
409     // Moonarize
410         blend1 << "lighten";
411         blend2 << "multiply";
412     }
414         _filter = g_strdup_printf(
415                 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" color-interpolation-filters=\"sRGB\" height=\"1\" width=\"1\" y=\"0\" x=\"0\" inkscape:label=\"Solarize, custom -EXP-\">\n"
416         "<feColorMatrix values=\"1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 1 \" />\n"
417         "<feColorMatrix type=\"hueRotate\" values=\"%s\" result=\"colormatrix2\" />\n"
418         "<feColorMatrix in=\"colormatrix2\" values=\"-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 1 0 \" result=\"colormatrix3\" />\n"
419         "<feBlend in=\"colormatrix3\" in2=\"colormatrix2\" mode=\"%s\" result=\"blend1\" />\n"
420         "<feBlend in2=\"blend1\" mode=\"%s\" result=\"blend2\" />\n"
421         "<feComposite in2=\"SourceGraphic\" operator=\"in\" />\n"
422         "</filter>\n", rotate.str().c_str(), blend1.str().c_str(), blend2.str().c_str());
424         return _filter;
425 }; /* Solarize filter */
428 /**
429     \brief    Custom predefined Tritone filter.
430     
431     Create a custom tritone palette with additional glow, blend modes and hue moving.
433     Filter's parameters:
434     * Option (enum, default Normal) ->
435         Normal = composite1 (in="qminp", in2="flood"), composite2 (in="p", in2="blend6"), blend6 (in2="qminpc")
436         Enhance hue = Normal + composite2 (in="SourceGraphic")
437         Radiation = Normal + blend6 (in2="SourceGraphic") composite2 (in="blend6", in2="qminpc")
438         Hue to background = Normal + composite1 (in2="BackgroundImage") [a template with an activated background is needed, or colors become black]
439     * Hue distribution (0->360, default 0) -> colormatrix1 (values)
440     * Colors (guint, default -73203457) -> flood (flood-opacity, flood-color)
441     * Global blend (enum, default Lighten) -> blend5 (mode) [Multiply, Screen, Darken, Lighten only!]
442     * Glow (0.01->10., default 0.01) -> feGaussianBlur (stdDeviation)
443     * Glow & blend (enum, default Normal) -> blend6 (mode) [Normal, Multiply and Darken only!]
444     * Local light (0.->10., default 0) -> composite2 (k1)
445     * Global light (0.->10., default 1) -> composite2 (k3) [k2 must be fixed to 1].
446 */
448 class Tritone : public Inkscape::Extension::Internal::Filter::Filter {
449 protected:
450         virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
452 public:
453         Tritone ( ) : Filter() { };
454         virtual ~Tritone ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
456         static void init (void) {
457                 Inkscape::Extension::build_from_mem(
458                         "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
459                                 "<name>" N_("Tritone, custom -EXP-") "</name>\n"
460                                 "<id>org.inkscape.effect.filter.Tritone</id>\n"
461                     "<param name=\"tab\" type=\"notebook\">\n"
462                     "<page name=\"optionstab\" _gui-text=\"Options\">\n"
463                         "<param name=\"type\" gui-text=\"" N_("Type:") "\" type=\"enum\">\n"
464                             "<_item value=\"normal\">Normal</_item>\n"
465                             "<_item value=\"enhue\">Enhance hue</_item>\n"
466                             "<_item value=\"rad\">Radiation</_item>\n"
467                             "<_item value=\"htb\">Hue to background</_item>\n"
468                         "</param>\n"
469                         "<param name=\"globalblend\" gui-text=\"" N_("Global blend:") "\" type=\"enum\">\n"
470                             "<_item value=\"lighten\">Lighten</_item>\n"
471                             "<_item value=\"screen\">Screen</_item>\n"
472                             "<_item value=\"multiply\">Multiply</_item>\n"
473                             "<_item value=\"darken\">Darken</_item>\n"
474                         "</param>\n"
475                         "<param name=\"glow\" gui-text=\"" N_("Glow:") "\" type=\"float\" min=\"0.01\" max=\"10\">0.01</param>\n"
476                          "<param name=\"glowblend\" gui-text=\"" N_("Glow blend:") "\" type=\"enum\">\n"
477                             "<_item value=\"normal\">Normal</_item>\n"
478                             "<_item value=\"multiply\">Multiply</_item>\n"
479                             "<_item value=\"darken\">Darken</_item>\n"
480                         "</param>\n"
481                         "<param name=\"llight\" gui-text=\"" N_("Local light:") "\" type=\"float\" min=\"0\" max=\"10\">0</param>\n"
482                         "<param name=\"glight\" gui-text=\"" N_("Global light:") "\" type=\"float\" min=\"0\" max=\"10\">1</param>\n"
483                     "</page>\n"
484                     "<page name=\"co1tab\" _gui-text=\"Color\">\n"
485                         "<param name=\"dist\" gui-text=\"" N_("Hue distribution:") "\" type=\"int\" min=\"0\" max=\"360\">0</param>\n"
486                                         "<param name=\"color\" gui-text=\"" N_("Color") "\" type=\"color\">-73203457</param>\n"
487                     "</page>\n"
488                 "</param>\n"
489                                 "<effect>\n"
490                                         "<object-type>all</object-type>\n"
491                                         "<effects-menu>\n"
492                                                 "<submenu name=\"" N_("Filters") "\">\n"
493                                                 "<submenu name=\"" N_("Experimental") "\"/>\n"
494                               "</submenu>\n"
495                                         "</effects-menu>\n"
496                                         "<menu-tip>" N_("Create a custom tritone palette with additional glow, blend modes and hue moving") "</menu-tip>\n"
497                                 "</effect>\n"
498                         "</inkscape-extension>\n", new Tritone());
499         };
501 };
503 gchar const *
504 Tritone::get_filter_text (Inkscape::Extension::Extension * ext)
506         if (_filter != NULL) g_free((void *)_filter);
507     
508     std::ostringstream dist;
509     std::ostringstream a;
510     std::ostringstream r;
511     std::ostringstream g;
512     std::ostringstream b;
513     std::ostringstream globalblend;
514     std::ostringstream glow;
515     std::ostringstream glowblend;
516     std::ostringstream llight;
517     std::ostringstream glight;
518     std::ostringstream c1in;
519     std::ostringstream c1in2;
520     std::ostringstream c2in;
521     std::ostringstream c2in2;
522     std::ostringstream b6in2;
523     
524     guint32 color = ext->get_param_color("color");
525     r << ((color >> 24) & 0xff);
526     g << ((color >> 16) & 0xff);
527     b << ((color >>  8) & 0xff);
528     a << (color & 0xff) / 255.0F;
529     globalblend << ext->get_param_enum("globalblend");
530     dist << ext->get_param_int("dist");
531     glow << ext->get_param_float("glow");
532     glowblend << ext->get_param_enum("glowblend");
533     llight << ext->get_param_float("llight");
534     glight << ext->get_param_float("glight");
535     
536     const gchar *type = ext->get_param_enum("type");
537     if((g_ascii_strcasecmp("enhue", type) == 0)) {
538     // Enhance hue
539         c1in << "qminp";
540         c1in2 << "flood";
541         c2in << "SourceGraphic";
542         c2in2 << "blend6";
543         b6in2 << "qminpc";
544     } else if((g_ascii_strcasecmp("rad", type) == 0)) {
545     // Radiation
546         c1in << "qminp";
547         c1in2 << "flood";
548         c2in << "blend6";
549         c2in2 << "qminpc";
550         b6in2 << "SourceGraphic";
551     } else if((g_ascii_strcasecmp("htb", type) == 0)) {
552     // Hue to background
553         c1in << "qminp";
554         c1in2 << "BackgroundImage";
555         c2in << "p";
556         c2in2 << "blend6";
557         b6in2 << "qminpc";
558     } else {
559     // Normal
560         c1in << "qminp";
561         c1in2 << "flood";
562         c2in << "p";
563         c2in2 << "blend6";
564         b6in2 << "qminpc";
565     }
566     
567         _filter = g_strdup_printf(
568                 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" color-interpolation-filters=\"sRGB\" height=\"1\" width=\"1\" y=\"0\" x=\"0\" inkscape:label=\"Tritone, custom -EXP-\">\n"
569         "<feColorMatrix type=\"hueRotate\" result=\"colormatrix1\" values=\"%s\" />\n"
570         "<feColorMatrix in=\"colormatrix1\" result=\"r\" type=\"matrix\" values=\"1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 \" />\n"
571         "<feColorMatrix in=\"colormatrix1\" result=\"g\" type=\"matrix\" values=\"0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 1 \" />\n"
572         "<feColorMatrix in=\"colormatrix1\" result=\"b\" type=\"matrix\" values=\"0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 \" />\n"
573         "<feBlend in2=\"g\" mode=\"darken\" in=\"r\" result=\"minrg\" />\n"
574         "<feBlend in2=\"b\" mode=\"darken\" in=\"minrg\" result=\"p\" />\n"
575         "<feBlend in2=\"g\" mode=\"lighten\" in=\"r\" result=\"maxrg\" />\n"
576         "<feBlend in2=\"b\" mode=\"lighten\" in=\"maxrg\" result=\"q\" />\n"
577         "<feComponentTransfer in=\"q\" result=\"q2\">\n"
578             "<feFuncR type=\"linear\" slope=\"0\" />\n"
579         "</feComponentTransfer>\n"
580         "<feBlend in2=\"q2\" mode=\"%s\" in=\"p\" result=\"pq\" />\n"
581         "<feColorMatrix in=\"pq\" result=\"qminp\" type=\"matrix\" values=\"-1 1 0 0 0 -1 1 0 0 0 -1 1 0 0 0 0 0 0 0 1 \" />\n"
582         "<feFlood in=\"qminp\" flood-opacity=\"%s\" flood-color=\"rgb(%s,%s,%s)\" result=\"flood\" />\n"
583         "<feComposite in=\"%s\" in2=\"%s\" result=\"qminpc\" operator=\"arithmetic\" k1=\"1\" />\n"
584         "<feGaussianBlur stdDeviation=\"%s\" />\n"
585         "<feBlend in2=\"%s\" blend=\"normal\" result=\"blend6\" mode=\"%s\" />\n"
586         "<feComposite in=\"%s\" in2=\"%s\" operator=\"arithmetic\" k1=\"%s\" k2=\"1\" k3=\"%s\" k4=\"0\" result=\"composite2\" />\n"
587         "<feComposite in2=\"SourceGraphic\" in=\"composite2\" operator=\"in\" />\n"
588         "</filter>\n", dist.str().c_str(), globalblend.str().c_str(), a.str().c_str(), r.str().c_str(), g.str().c_str(), b.str().c_str(), c1in.str().c_str(), c1in2.str().c_str(), glow.str().c_str(), b6in2.str().c_str(), glowblend.str().c_str(), c2in.str().c_str(), c2in2.str().c_str(), llight.str().c_str(), glight.str().c_str());
590         return _filter;
591 }; /* Tritone filter */
593 }; /* namespace Filter */
594 }; /* namespace Internal */
595 }; /* namespace Extension */
596 }; /* namespace Inkscape */
598 /* Change the 'COLOR' below to be your file name */
599 #endif /* __INKSCAPE_EXTENSION_INTERNAL_FILTER_COLOR_H__ */