Code

Filters. New custom predefined filters (all ABCs, Neon draw, Color shilf, Silhouette...
[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) 2011 Authors:
7  *   Ivan Louette (filters)
8  *   Nicolas Dufour (UI) <nicoduf@yahoo.fr>
9  *
10  * Color filters
11  *   Colorize
12  *   Duochrome
13  *   Electrize
14  *   Quadritone
15  *   Solarize
16  *   Tritone
17  *
18  * Released under GNU GPL, read the file 'COPYING' for more information
19  */
20 /* ^^^ Change the copyright to be you and your e-mail address ^^^ */
22 #include "filter.h"
24 #include "extension/internal/clear-n_.h"
25 #include "extension/system.h"
26 #include "extension/extension.h"
28 namespace Inkscape {
29 namespace Extension {
30 namespace Internal {
31 namespace Filter {
33 /**
34     \brief    Custom predefined Colorize filter.
35     
36     Blend image or object with a flood color.
38     Filter's parameters:
39     * Harsh light (0.->10., default 0) -> composite1 (k1)
40     * Normal light (0.->10., default 1) -> composite2 (k2)
41     * Duotone (boolean, default false) -> colormatrix1 (values="0")
42     * Filtered greys (boolean, default false) -> colormatrix2 (values="0")
43     * Blend mode 1 (enum, default Multiply) -> blend1 (mode)
44     * Blend mode 2 (enum, default Screen) -> blend2 (mode)
45 */
47 class Colorize : public Inkscape::Extension::Internal::Filter::Filter {
48 protected:
49     virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
51 public:
52     Colorize ( ) : Filter() { };
53     virtual ~Colorize ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
55     static void init (void) {
56         Inkscape::Extension::build_from_mem(
57             "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
58                 "<name>" N_("Colorize, custom (Color)") "</name>\n"
59                 "<id>org.inkscape.effect.filter.Colorize</id>\n"
60                 "<param name=\"tab\" type=\"notebook\">\n"
61                   "<page name=\"optionstab\" _gui-text=\"Options\">\n"
62                     "<param name=\"hlight\" gui-text=\"" N_("Harsh light:") "\" type=\"float\" min=\"0\" max=\"10\">0</param>\n"
63                     "<param name=\"nlight\" gui-text=\"" N_("Normal light:") "\" type=\"float\" min=\"0\" max=\"10\">1</param>\n"
64                     "<param name=\"duotone\" gui-text=\"" N_("Duotone") "\" type=\"boolean\" >false</param>\n"
65                     "<param name=\"blend1\" gui-text=\"" N_("Blend 1:") "\" type=\"enum\">\n"
66                       "<_item value=\"multiply\">Multiply</_item>\n"
67                       "<_item value=\"normal\">Normal</_item>\n"
68                       "<_item value=\"screen\">Screen</_item>\n"
69                       "<_item value=\"lighten\">Lighten</_item>\n"
70                       "<_item value=\"darken\">Darken</_item>\n"
71                     "</param>\n"
72                     "<param name=\"blend2\" gui-text=\"" N_("Blend 2:") "\" type=\"enum\">\n"
73                       "<_item value=\"screen\">Screen</_item>\n"
74                       "<_item value=\"multiply\">Multiply</_item>\n"
75                       "<_item value=\"normal\">Normal</_item>\n"
76                       "<_item value=\"lighten\">Lighten</_item>\n"
77                       "<_item value=\"darken\">Darken</_item>\n"
78                     "</param>\n"
79                   "</page>\n"
80                   "<page name=\"colortab\" _gui-text=\"Color\">\n"
81                     "<param name=\"color\" gui-text=\"" N_("Color") "\" type=\"color\">-1639776001</param>\n"
82                   "</page>\n"
83                 "</param>\n"
84                 "<effect>\n"
85                 "<object-type>all</object-type>\n"
86                 "<effects-menu>\n"
87                   "<submenu name=\"" N_("Filters") "\">\n"
88                     "<submenu name=\"" N_("Experimental") "\"/>\n"
89                   "</submenu>\n"
90                   "</effects-menu>\n"
91                 "<menu-tip>" N_("Blend image or object with a flood color") "</menu-tip>\n"
92               "</effect>\n"
93             "</inkscape-extension>\n", new Colorize());
94     };
96 };
98 gchar const *
99 Colorize::get_filter_text (Inkscape::Extension::Extension * ext)
101     if (_filter != NULL) g_free((void *)_filter);
103     std::ostringstream a;
104     std::ostringstream r;
105     std::ostringstream g;
106     std::ostringstream b;
107     std::ostringstream hlight;
108     std::ostringstream nlight;
109     std::ostringstream duotone;
110     std::ostringstream blend1;
111     std::ostringstream blend2;
113     guint32 color = ext->get_param_color("color");
114     r << ((color >> 24) & 0xff);
115     g << ((color >> 16) & 0xff);
116     b << ((color >>  8) & 0xff);
117     a << (color & 0xff) / 255.0F;
119     hlight << ext->get_param_float("hlight");
120     nlight << ext->get_param_float("nlight");
121     blend1 << ext->get_param_enum("blend1");
122     blend2 << ext->get_param_enum("blend2");
123     if (ext->get_param_bool("duotone"))
124         duotone << "0";
125     else
126         duotone << "1";
128     _filter = g_strdup_printf(
129         "<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\">\n"
130           "<feComposite in2=\"SourceGraphic\" operator=\"arithmetic\" k1=\"%s\" k2=\"%s\" result=\"composite1\" />\n"
131           "<feColorMatrix in=\"composite1\" values=\"%s\" type=\"saturate\" result=\"colormatrix1\" />\n"
132           "<feFlood flood-opacity=\"%s\" flood-color=\"rgb(%s,%s,%s)\" result=\"flood1\" />\n"
133           "<feBlend in=\"flood1\" in2=\"colormatrix1\" mode=\"%s\" result=\"blend1\" />\n"
134           "<feBlend in2=\"blend1\" mode=\"%s\" result=\"blend2\" />\n"
135           "<feColorMatrix in=\"blend2\" values=\"1\" type=\"saturate\" result=\"colormatrix2\" />\n"
136           "<feComposite in=\"colormatrix2\" in2=\"SourceGraphic\" operator=\"in\" k2=\"1\" result=\"composite2\" />\n"
137         "</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());
139     return _filter;
140 }; /* Colorize filter */
143 /**
144     \brief    Custom predefined Duochrome filter.
145     
146     Convert luminance values to a duochrome palette.
148     Filter's parameters:
149     * Fluorescence level (0.->2., default 0) -> composite4 (k2)
150     * Swap (enum, default "No swap") -> composite1, composite2 (operator)
151     * Color 1 (guint, default 1364325887) -> flood1 (flood-opacity, flood-color)
152     * Color 2 (guint, default -65281) -> flood2 (flood-opacity, flood-color)
153 */
155 class Duochrome : public Inkscape::Extension::Internal::Filter::Filter {
156 protected:
157     virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
159 public:
160     Duochrome ( ) : Filter() { };
161     virtual ~Duochrome ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
163     static void init (void) {
164         Inkscape::Extension::build_from_mem(
165             "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
166               "<name>" N_("Duochrome, custom (Color)") "</name>\n"
167               "<id>org.inkscape.effect.filter.Duochrome</id>\n"
168               "<param name=\"tab\" type=\"notebook\">\n"
169                 "<page name=\"optionstab\" _gui-text=\"Options\">\n"
170                   "<param name=\"fluo\" gui-text=\"" N_("Fluorescence level:") "\" type=\"float\" min=\"0\" max=\"2\">0</param>\n"
171                   "<param name=\"swap\" gui-text=\"" N_("Swap:") "\" type=\"enum\">\n"
172                     "<_item value=\"none\">No swap</_item>\n"
173                     "<_item value=\"full\">Color and alpha</_item>\n"
174                     "<_item value=\"color\">Color only</_item>\n"
175                     "<_item value=\"alpha\">Alpha only</_item>\n"
176                   "</param>\n"
177                 "</page>\n"
178                 "<page name=\"co11tab\" _gui-text=\"Color 1\">\n"
179                   "<param name=\"color1\" gui-text=\"" N_("Color 1") "\" type=\"color\">1364325887</param>\n"
180                 "</page>\n"
181                 "<page name=\"co12tab\" _gui-text=\"Color 2\">\n"
182                   "<param name=\"color2\" gui-text=\"" N_("Color 2") "\" type=\"color\">-65281</param>\n"
183                 "</page>\n"
184               "</param>\n"
185               "<effect>\n"
186                 "<object-type>all</object-type>\n"
187                 "<effects-menu>\n"
188                   "<submenu name=\"" N_("Filters") "\">\n"
189                     "<submenu name=\"" N_("Experimental") "\"/>\n"
190                   "</submenu>\n"
191                 "</effects-menu>\n"
192                 "<menu-tip>" N_("Convert luminance values to a duochrome palette") "</menu-tip>\n"
193               "</effect>\n"
194             "</inkscape-extension>\n", new Duochrome());
195     };
197 };
199 gchar const *
200 Duochrome::get_filter_text (Inkscape::Extension::Extension * ext)
202     if (_filter != NULL) g_free((void *)_filter);
204     std::ostringstream a1;
205     std::ostringstream r1;
206     std::ostringstream g1;
207     std::ostringstream b1;
208     std::ostringstream a2;
209     std::ostringstream r2;
210     std::ostringstream g2;
211     std::ostringstream b2;
212     std::ostringstream fluo;
213     std::ostringstream swap1;
214     std::ostringstream swap2;
215     guint32 color1 = ext->get_param_color("color1");
216     guint32 color2 = ext->get_param_color("color2");
217     float fluorescence = ext->get_param_float("fluo");
218     const gchar *swaptype = ext->get_param_enum("swap");
220     r1 << ((color1 >> 24) & 0xff);
221     g1 << ((color1 >> 16) & 0xff);
222     b1 << ((color1 >>  8) & 0xff);
223     r2 << ((color2 >> 24) & 0xff);
224     g2 << ((color2 >> 16) & 0xff);
225     b2 << ((color2 >>  8) & 0xff);
226     fluo << fluorescence;
228     if((g_ascii_strcasecmp("full", swaptype) == 0)) {
229         swap1 << "in";
230         swap2 << "out";
231         a1 << (color1 & 0xff) / 255.0F;
232         a2 << (color2 & 0xff) / 255.0F;
233     } else if((g_ascii_strcasecmp("color", swaptype) == 0)) {
234         swap1 << "in";
235         swap2 << "out";
236         a1 << (color2 & 0xff) / 255.0F;
237         a2 << (color1 & 0xff) / 255.0F;
238     } else if((g_ascii_strcasecmp("alpha", swaptype) == 0)) {
239         swap1 << "out";
240         swap2 << "in";
241         a1 << (color2 & 0xff) / 255.0F;
242         a2 << (color1 & 0xff) / 255.0F;
243     } else {
244         swap1 << "out";
245         swap2 << "in";
246         a1 << (color1 & 0xff) / 255.0F;
247         a2 << (color2 & 0xff) / 255.0F;
248     }
250     _filter = g_strdup_printf(
251         "<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\">\n"
252           "<feColorMatrix type=\"luminanceToAlpha\" result=\"colormatrix1\" />\n"
253           "<feFlood flood-opacity=\"%s\" flood-color=\"rgb(%s,%s,%s)\" result=\"flood1\" />\n"
254           "<feComposite in2=\"colormatrix1\" operator=\"%s\" result=\"composite1\" />\n"
255           "<feFlood in=\"colormatrix1\" flood-opacity=\"%s\" flood-color=\"rgb(%s,%s,%s)\" result=\"flood2\" />\n"
256           "<feComposite in2=\"colormatrix1\" result=\"composite2\" operator=\"%s\" />\n"
257           "<feComposite in=\"composite2\" in2=\"composite1\" k2=\"1\"  k3=\"1\" operator=\"arithmetic\" result=\"composite3\" />\n"
258           "<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"
259           "<feComposite in=\"colormatrix2\" in2=\"composite3\" operator=\"arithmetic\" k2=\"%s\" result=\"composite4\" />\n"
260           "<feBlend in=\"composite4\" in2=\"composite3\" blend=\"normal\" mode=\"normal\" result=\"blend\" />\n"
261           "<feComposite in2=\"SourceGraphic\" operator=\"in\" />\n"
262         "</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());
264     return _filter;
265 }; /* Duochrome filter */
267 /**
268     \brief    Custom predefined Electrize filter.
269     
270     Electro solarization effects.
272     Filter's parameters:
273     * Simplify (0.01->10., default 2.) -> blur (stdDeviation)
274     * Effect type (enum: table or discrete, default "table") -> component (type)
275     * Level (0->10, default 3) -> component (tableValues)
276     * Inverted (boolean, default false) -> component (tableValues)
277 */
278 class Electrize : public Inkscape::Extension::Internal::Filter::Filter {
279 protected:
280     virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
282 public:
283     Electrize ( ) : Filter() { };
284     virtual ~Electrize ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
286     static void init (void) {
287         Inkscape::Extension::build_from_mem(
288             "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
289               "<name>" N_("Electrize, custom (Color)") "</name>\n"
290               "<id>org.inkscape.effect.filter.Electrize</id>\n"
291               "<param name=\"blur\" gui-text=\"" N_("Simplify:") "\" type=\"float\" min=\"0.01\" max=\"10.0\">2.0</param>\n"
292               "<param name=\"type\" gui-text=\"" N_("Effect type:") "\" type=\"enum\">\n"
293                 "<_item value=\"table\">Table</_item>\n"
294                 "<_item value=\"discrete\">Discrete</_item>\n"
295               "</param>\n"
296               "<param name=\"levels\" gui-text=\"" N_("Levels:") "\" type=\"int\" min=\"0\" max=\"10\">3</param>\n"
297               "<param name=\"invert\" gui-text=\"" N_("Inverted") "\" type=\"boolean\">false</param>\n"
298               "<effect>\n"
299                 "<object-type>all</object-type>\n"
300                 "<effects-menu>\n"
301                   "<submenu name=\"" N_("Filters") "\">\n"
302                     "<submenu name=\"" N_("Experimental") "\"/>\n"
303                   "</submenu>\n"
304                 "</effects-menu>\n"
305                 "<menu-tip>" N_("Electro solarization effects") "</menu-tip>\n"
306               "</effect>\n"
307             "</inkscape-extension>\n", new Electrize());
308     };
309 };
311 gchar const *
312 Electrize::get_filter_text (Inkscape::Extension::Extension * ext)
314     if (_filter != NULL) g_free((void *)_filter);
316     std::ostringstream blur;
317     std::ostringstream type;
318     std::ostringstream values;
320     blur << ext->get_param_float("blur");
321     type << ext->get_param_enum("type");
323     // TransfertComponent table values are calculated based on the effect level and inverted parameters.
324     int val = 0;
325     int levels = ext->get_param_int("levels") + 1;
326     if (ext->get_param_bool("invert"))
327         val = 1;
328     values << val;
329     for ( int step = 1 ; step <= levels ; step++ ) {
330         if (val == 1) {
331             val = 0;
332         }
333         else {
334             val = 1;
335         }
336         values << " " << val;
337     }
338   
339     _filter = g_strdup_printf(
340         "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" color-interpolation-filters=\"sRGB\" height=\"1\" width=\"1\" y=\"0\" x=\"0\" inkscape:label=\"Electrize, custom\">\n"
341           "<feGaussianBlur stdDeviation=\"%s\" result=\"blur\" />\n"
342           "<feComponentTransfer in=\"blur\" stdDeviation=\"2\" result=\"component\" >\n"
343             "<feFuncR type=\"%s\" tableValues=\"%s\" />\n"
344             "<feFuncG type=\"%s\" tableValues=\"%s\" />\n"
345             "<feFuncB type=\"%s\" tableValues=\"%s\" />\n"
346           "</feComponentTransfer>\n"
347         "</filter>\n", blur.str().c_str(), type.str().c_str(), values.str().c_str(), type.str().c_str(), values.str().c_str(), type.str().c_str(), values.str().c_str());
349     return _filter;
350 }; /* Electrize filter */
352 /**
353     \brief    Custom predefined Quadritone filter.
354     
355     Replace hue by two colors.
357     Filter's parameters:
358     * Hue distribution (0->360, default 280) -> colormatrix1 (values)
359     * Colors (0->360, default 100) -> colormatrix3 (values)
360     * Blend mode 1 (enum, default Normal) -> blend1 (mode)
361     * Over-saturation (0.->1., default 0) -> composite1 (k2)
362     * Blend mode 2 (enum, default Normal) -> blend2 (mode)
363 */
365 class Quadritone : public Inkscape::Extension::Internal::Filter::Filter {
366 protected:
367     virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
369 public:
370     Quadritone ( ) : Filter() { };
371     virtual ~Quadritone ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
373     static void init (void) {
374         Inkscape::Extension::build_from_mem(
375             "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
376               "<name>" N_("Quadritone fantasy, custom (Color)") "</name>\n"
377               "<id>org.inkscape.effect.filter.Quadritone</id>\n"
378                 "<param name=\"dist\" gui-text=\"" N_("Hue distribution:") "\" type=\"int\" min=\"0\" max=\"360\">280</param>\n"
379                 "<param name=\"colors\" gui-text=\"" N_("Colors:") "\" type=\"int\" min=\"0\" max=\"360\">100</param>\n"
380                 "<param name=\"blend1\" gui-text=\"" N_("Blend 1:") "\" type=\"enum\">\n"
381                   "<_item value=\"normal\">Normal</_item>\n"
382                   "<_item value=\"multiply\">Multiply</_item>\n"
383                   "<_item value=\"screen\">Screen</_item>\n"
384                 "</param>\n"
385                 "<param name=\"sat\" gui-text=\"" N_("Over-saturation:") "\" type=\"float\" min=\"0\" max=\"1\">0</param>\n"
386                 "<param name=\"blend2\" gui-text=\"" N_("Blend 2:") "\" type=\"enum\">\n"
387                   "<_item value=\"normal\">Normal</_item>\n"
388                   "<_item value=\"screen\">Screen</_item>\n"
389                   "<_item value=\"multiply\">Multiply</_item>\n"
390                   "<_item value=\"lighten\">Lighten</_item>\n"
391                   "<_item value=\"darken\">Darken</_item>\n"
392                 "</param>\n"
393                 "<effect>\n"
394                   "<object-type>all</object-type>\n"
395                   "<effects-menu>\n"
396                     "<submenu name=\"" N_("Filters") "\">\n"
397                       "<submenu name=\"" N_("Experimental") "\"/>\n"
398                     "</submenu>\n"
399                   "</effects-menu>\n"
400                 "<menu-tip>" N_("Replace hue by two colors") "</menu-tip>\n"
401               "</effect>\n"
402             "</inkscape-extension>\n", new Quadritone());
403     };
405 };
407 gchar const *
408 Quadritone::get_filter_text (Inkscape::Extension::Extension * ext)
410     if (_filter != NULL) g_free((void *)_filter);
412     std::ostringstream dist;
413     std::ostringstream colors;
414     std::ostringstream blend1;
415     std::ostringstream sat;
416     std::ostringstream blend2;
418     dist << ext->get_param_int("dist");
419     colors << ext->get_param_int("colors");
420     blend1 << ext->get_param_enum("blend1");
421     sat << ext->get_param_float("sat");
422     blend2 << ext->get_param_enum("blend2");
424     _filter = g_strdup_printf(
425         "<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\">\n"
426           "<feColorMatrix in=\"SourceGraphic\" type=\"hueRotate\" values=\"%s\" result=\"colormatrix1\" />\n"
427           "<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"
428           "<feColorMatrix type=\"hueRotate\" values=\"%s\" result=\"colormatrix3\" />\n"
429           "<feBlend in2=\"colormatrix3\" blend=\"normal\" mode=\"%s\" result=\"blend1\" />\n"
430           "<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"
431           "<feComposite in=\"colormatrix4\" in2=\"blend1\" operator=\"arithmetic\" k2=\"%s\" result=\"composite1\" />\n"
432           "<feBlend in2=\"blend1\" blend=\"normal\" mode=\"%s\" result=\"blend2\" />\n"
433         "</filter>\n", dist.str().c_str(), colors.str().c_str(), blend1.str().c_str(), sat.str().c_str(), blend2.str().c_str());
435     return _filter;
436 }; /* Quadritone filter */
439 /**
440     \brief    Custom predefined Solarize filter.
441     
442     Classic photographic solarization effect.
444     Filter's parameters:
445     * Type (enum, default "Solarize") ->
446         Solarize = blend1 (mode="darken"), blend2 (mode="screen")
447         Moonarize = blend1 (mode="lighten"), blend2 (mode="multiply") [No other access to the blend modes]
448     * Hue rotation (0->360, default 0) -> colormatrix1 (values)
449 */
452 class Solarize : public Inkscape::Extension::Internal::Filter::Filter {
453 protected:
454     virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
456 public:
457     Solarize ( ) : Filter() { };
458     virtual ~Solarize ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
460     static void init (void) {
461         Inkscape::Extension::build_from_mem(
462             "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
463               "<name>" N_("Solarize, custom (Color)") "</name>\n"
464               "<id>org.inkscape.effect.filter.Solarize</id>\n"
465               "<param name=\"rotate\" gui-text=\"" N_("Hue rotation:") "\" type=\"int\" min=\"0\" max=\"360\">0</param>\n"
466               "<param name=\"type\" gui-text=\"" N_("Type:") "\" type=\"enum\">\n"
467                 "<_item value=\"solarize\">Solarize</_item>\n"
468                 "<_item value=\"moonarize\">Moonarize</_item>\n"
469               "</param>\n"
470               "<effect>\n"
471                 "<object-type>all</object-type>\n"
472                 "<effects-menu>\n"
473                   "<submenu name=\"" N_("Filters") "\">\n"
474                     "<submenu name=\"" N_("Experimental") "\"/>\n"
475                   "</submenu>\n"
476                 "</effects-menu>\n"
477                 "<menu-tip>" N_("Classic photographic solarization effect") "</menu-tip>\n"
478               "</effect>\n"
479             "</inkscape-extension>\n", new Solarize());
480     };
482 };
484 gchar const *
485 Solarize::get_filter_text (Inkscape::Extension::Extension * ext)
487     if (_filter != NULL) g_free((void *)_filter);
489     std::ostringstream rotate;
490     std::ostringstream blend1;
491     std::ostringstream blend2;
493     rotate << ext->get_param_int("rotate");
494     const gchar *type = ext->get_param_enum("type");
495     if((g_ascii_strcasecmp("solarize", type) == 0)) {
496     // Solarize
497         blend1 << "darken";
498         blend2 << "screen";
499     } else {
500     // Moonarize
501         blend1 << "lighten";
502         blend2 << "multiply";
503     }
505     _filter = g_strdup_printf(
506         "<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\">\n"
507           "<feColorMatrix values=\"1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 1 \" />\n"
508           "<feColorMatrix type=\"hueRotate\" values=\"%s\" result=\"colormatrix2\" />\n"
509           "<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"
510           "<feBlend in=\"colormatrix3\" in2=\"colormatrix2\" mode=\"%s\" result=\"blend1\" />\n"
511           "<feBlend in2=\"blend1\" mode=\"%s\" result=\"blend2\" />\n"
512           "<feComposite in2=\"SourceGraphic\" operator=\"in\" />\n"
513         "</filter>\n", rotate.str().c_str(), blend1.str().c_str(), blend2.str().c_str());
515     return _filter;
516 }; /* Solarize filter */
519 /**
520     \brief    Custom predefined Tritone filter.
521     
522     Create a custom tritone palette with additional glow, blend modes and hue moving.
524     Filter's parameters:
525     * Option (enum, default Normal) ->
526         Normal = composite1 (in="qminp", in2="flood"), composite2 (in="p", in2="blend6"), blend6 (in2="qminpc")
527         Enhance hue = Normal + composite2 (in="SourceGraphic")
528         Radiation = Normal + blend6 (in2="SourceGraphic") composite2 (in="blend6", in2="qminpc")
529         Hue to background = Normal + composite1 (in2="BackgroundImage") [a template with an activated background is needed, or colors become black]
530     * Hue distribution (0->360, default 0) -> colormatrix1 (values)
531     * Colors (guint, default -73203457) -> flood (flood-opacity, flood-color)
532     * Global blend (enum, default Lighten) -> blend5 (mode) [Multiply, Screen, Darken, Lighten only!]
533     * Glow (0.01->10., default 0.01) -> feGaussianBlur (stdDeviation)
534     * Glow & blend (enum, default Normal) -> blend6 (mode) [Normal, Multiply and Darken only!]
535     * Local light (0.->10., default 0) -> composite2 (k1)
536     * Global light (0.->10., default 1) -> composite2 (k3) [k2 must be fixed to 1].
537 */
539 class Tritone : public Inkscape::Extension::Internal::Filter::Filter {
540 protected:
541     virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
543 public:
544     Tritone ( ) : Filter() { };
545     virtual ~Tritone ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
547     static void init (void) {
548         Inkscape::Extension::build_from_mem(
549             "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
550               "<name>" N_("Tritone, custom (Color)") "</name>\n"
551               "<id>org.inkscape.effect.filter.Tritone</id>\n"
552               "<param name=\"tab\" type=\"notebook\">\n"
553                 "<page name=\"optionstab\" _gui-text=\"Options\">\n"
554                   "<param name=\"type\" gui-text=\"" N_("Type:") "\" type=\"enum\">\n"
555                     "<_item value=\"normal\">Normal</_item>\n"
556                     "<_item value=\"enhue\">Enhance hue</_item>\n"
557                     "<_item value=\"rad\">Radiation</_item>\n"
558                     "<_item value=\"htb\">Hue to background</_item>\n"
559                   "</param>\n"
560                   "<param name=\"globalblend\" gui-text=\"" N_("Global blend:") "\" type=\"enum\">\n"
561                     "<_item value=\"lighten\">Lighten</_item>\n"
562                     "<_item value=\"screen\">Screen</_item>\n"
563                     "<_item value=\"multiply\">Multiply</_item>\n"
564                     "<_item value=\"darken\">Darken</_item>\n"
565                   "</param>\n"
566                   "<param name=\"glow\" gui-text=\"" N_("Glow:") "\" type=\"float\" min=\"0.01\" max=\"10\">0.01</param>\n"
567                   "<param name=\"glowblend\" gui-text=\"" N_("Glow blend:") "\" type=\"enum\">\n"
568                     "<_item value=\"normal\">Normal</_item>\n"
569                     "<_item value=\"multiply\">Multiply</_item>\n"
570                     "<_item value=\"darken\">Darken</_item>\n"
571                   "</param>\n"
572                   "<param name=\"llight\" gui-text=\"" N_("Local light:") "\" type=\"float\" min=\"0\" max=\"10\">0</param>\n"
573                   "<param name=\"glight\" gui-text=\"" N_("Global light:") "\" type=\"float\" min=\"0\" max=\"10\">1</param>\n"
574                 "</page>\n"
575                 "<page name=\"co1tab\" _gui-text=\"Color\">\n"
576                   "<param name=\"dist\" gui-text=\"" N_("Hue distribution:") "\" type=\"int\" min=\"0\" max=\"360\">0</param>\n"
577                   "<param name=\"color\" gui-text=\"" N_("Color") "\" type=\"color\">-73203457</param>\n"
578                 "</page>\n"
579               "</param>\n"
580               "<effect>\n"
581                 "<object-type>all</object-type>\n"
582                 "<effects-menu>\n"
583                   "<submenu name=\"" N_("Filters") "\">\n"
584                     "<submenu name=\"" N_("Experimental") "\"/>\n"
585                   "</submenu>\n"
586                 "</effects-menu>\n"
587                 "<menu-tip>" N_("Create a custom tritone palette with additional glow, blend modes and hue moving") "</menu-tip>\n"
588               "</effect>\n"
589             "</inkscape-extension>\n", new Tritone());
590     };
592 };
594 gchar const *
595 Tritone::get_filter_text (Inkscape::Extension::Extension * ext)
597     if (_filter != NULL) g_free((void *)_filter);
598     
599     std::ostringstream dist;
600     std::ostringstream a;
601     std::ostringstream r;
602     std::ostringstream g;
603     std::ostringstream b;
604     std::ostringstream globalblend;
605     std::ostringstream glow;
606     std::ostringstream glowblend;
607     std::ostringstream llight;
608     std::ostringstream glight;
609     std::ostringstream c1in;
610     std::ostringstream c1in2;
611     std::ostringstream c2in;
612     std::ostringstream c2in2;
613     std::ostringstream b6in2;
614     
615     guint32 color = ext->get_param_color("color");
616     r << ((color >> 24) & 0xff);
617     g << ((color >> 16) & 0xff);
618     b << ((color >>  8) & 0xff);
619     a << (color & 0xff) / 255.0F;
620     globalblend << ext->get_param_enum("globalblend");
621     dist << ext->get_param_int("dist");
622     glow << ext->get_param_float("glow");
623     glowblend << ext->get_param_enum("glowblend");
624     llight << ext->get_param_float("llight");
625     glight << ext->get_param_float("glight");
626     
627     const gchar *type = ext->get_param_enum("type");
628     if((g_ascii_strcasecmp("enhue", type) == 0)) {
629     // Enhance hue
630         c1in << "qminp";
631         c1in2 << "flood";
632         c2in << "SourceGraphic";
633         c2in2 << "blend6";
634         b6in2 << "qminpc";
635     } else if((g_ascii_strcasecmp("rad", type) == 0)) {
636     // Radiation
637         c1in << "qminp";
638         c1in2 << "flood";
639         c2in << "blend6";
640         c2in2 << "qminpc";
641         b6in2 << "SourceGraphic";
642     } else if((g_ascii_strcasecmp("htb", type) == 0)) {
643     // Hue to background
644         c1in << "qminp";
645         c1in2 << "BackgroundImage";
646         c2in << "p";
647         c2in2 << "blend6";
648         b6in2 << "qminpc";
649     } else {
650     // Normal
651         c1in << "qminp";
652         c1in2 << "flood";
653         c2in << "p";
654         c2in2 << "blend6";
655         b6in2 << "qminpc";
656     }
657     
658     _filter = g_strdup_printf(
659         "<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\">\n"
660           "<feColorMatrix type=\"hueRotate\" result=\"colormatrix1\" values=\"%s\" />\n"
661           "<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"
662           "<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"
663           "<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"
664           "<feBlend in2=\"g\" mode=\"darken\" in=\"r\" result=\"minrg\" />\n"
665           "<feBlend in2=\"b\" mode=\"darken\" in=\"minrg\" result=\"p\" />\n"
666           "<feBlend in2=\"g\" mode=\"lighten\" in=\"r\" result=\"maxrg\" />\n"
667           "<feBlend in2=\"b\" mode=\"lighten\" in=\"maxrg\" result=\"q\" />\n"
668           "<feComponentTransfer in=\"q\" result=\"q2\">\n"
669             "<feFuncR type=\"linear\" slope=\"0\" />\n"
670           "</feComponentTransfer>\n"
671           "<feBlend in2=\"q2\" mode=\"%s\" in=\"p\" result=\"pq\" />\n"
672           "<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"
673           "<feFlood in=\"qminp\" flood-opacity=\"%s\" flood-color=\"rgb(%s,%s,%s)\" result=\"flood\" />\n"
674           "<feComposite in=\"%s\" in2=\"%s\" result=\"qminpc\" operator=\"arithmetic\" k1=\"1\" />\n"
675           "<feGaussianBlur stdDeviation=\"%s\" />\n"
676           "<feBlend in2=\"%s\" blend=\"normal\" result=\"blend6\" mode=\"%s\" />\n"
677           "<feComposite in=\"%s\" in2=\"%s\" operator=\"arithmetic\" k1=\"%s\" k2=\"1\" k3=\"%s\" k4=\"0\" result=\"composite2\" />\n"
678           "<feComposite in2=\"SourceGraphic\" in=\"composite2\" operator=\"in\" />\n"
679         "</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());
681     return _filter;
682 }; /* Tritone filter */
684 }; /* namespace Filter */
685 }; /* namespace Internal */
686 }; /* namespace Extension */
687 }; /* namespace Inkscape */
689 /* Change the 'COLOR' below to be your file name */
690 #endif /* __INKSCAPE_EXTENSION_INTERNAL_FILTER_COLOR_H__ */