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 * Released under GNU GPL, read the file 'COPYING' for more information
11 */
12 /* ^^^ Change the copyright to be you and your e-mail address ^^^ */
14 #include "filter.h"
16 #include "extension/internal/clear-n_.h"
17 #include "extension/system.h"
18 #include "extension/extension.h"
20 namespace Inkscape {
21 namespace Extension {
22 namespace Internal {
23 namespace Filter {
25 /* Custom predefined Colorize filter
27 Filter's parameters:
28 * Harsh light (0.-10., default 0) -> composite1 (k1)
29 * Normal light (0.-10., default 1) -> composite2 (k2)
30 * Duotone (boolean, default false) -> colormatrix1 (values="0")
31 * Filtered greys (boolean, default false) -> colormatrix2 (values="0")
32 * Blend mode 1 (enum, default Multiply) -> blend1 (mode)
33 * Blend mode 2 (enum, default Screen) -> blend2 (mode)
34 */
36 class Colorize : public Inkscape::Extension::Internal::Filter::Filter {
37 protected:
38 virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
40 public:
41 Colorize ( ) : Filter() { };
42 virtual ~Colorize ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
44 static void init (void) {
45 Inkscape::Extension::build_from_mem(
46 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
47 "<name>" N_("Colorize, custom -EXP-") "</name>\n"
48 "<id>org.inkscape.effect.filter.Colorize</id>\n"
49 "<param name=\"hlight\" gui-text=\"" N_("Harsh light:") "\" type=\"float\" min=\"0\" max=\"10\">0</param>\n"
50 "<param name=\"nlight\" gui-text=\"" N_("Normal light:") "\" type=\"float\" min=\"0\" max=\"10\">1</param>\n"
51 "<param name=\"duotone\" gui-text=\"" N_("Duotone") "\" type=\"boolean\" >false</param>\n"
52 "<param name=\"fg\" gui-text=\"" N_("Filtered greys") "\" type=\"boolean\" >false</param>\n"
53 "<param name=\"blend1\" gui-text=\"" N_("Blend1:") "\" type=\"enum\">\n"
54 "<_item value=\"multiply\">Multiply</_item>\n"
55 "<_item value=\"normal\">Normal</_item>\n"
56 "<_item value=\"screen\">Screen</_item>\n"
57 "<_item value=\"lighten\">Lighten</_item>\n"
58 "<_item value=\"darken\">Darken</_item>\n"
59 "</param>\n"
60 "<param name=\"blend2\" gui-text=\"" N_("Blend2:") "\" type=\"enum\">\n"
61 "<_item value=\"screen\">Screen</_item>\n"
62 "<_item value=\"multiply\">Multiply</_item>\n"
63 "<_item value=\"normal\">Normal</_item>\n"
64 "<_item value=\"lighten\">Lighten</_item>\n"
65 "<_item value=\"darken\">Darken</_item>\n"
66 "</param>\n"
67 "<param name=\"color\" gui-text=\"" N_("Color 1") "\" type=\"color\">-1639776001</param>\n"
68 "<effect>\n"
69 "<object-type>all</object-type>\n"
70 "<effects-menu>\n"
71 "<submenu name=\"" N_("Filters") "\">\n"
72 "<submenu name=\"" N_("Experimental") "\"/>\n"
73 "</submenu>\n"
74 "</effects-menu>\n"
75 "<menu-tip>" N_("Blend image or object with a flood color") "</menu-tip>\n"
76 "</effect>\n"
77 "</inkscape-extension>\n", new Colorize());
78 };
80 };
82 gchar const *
83 Colorize::get_filter_text (Inkscape::Extension::Extension * ext)
84 {
85 if (_filter != NULL) g_free((void *)_filter);
87 std::ostringstream a;
88 std::ostringstream r;
89 std::ostringstream g;
90 std::ostringstream b;
91 std::ostringstream hlight;
92 std::ostringstream nlight;
93 std::ostringstream duotone;
94 std::ostringstream fg;
95 std::ostringstream blend1;
96 std::ostringstream blend2;
98 guint32 color = ext->get_param_color("color");
99 r << ((color >> 24) & 0xff);
100 g << ((color >> 16) & 0xff);
101 b << ((color >> 8) & 0xff);
102 a << (color & 0xff) / 255.0F;
104 hlight << ext->get_param_float("hlight");
105 nlight << ext->get_param_float("nlight");
106 blend1 << ext->get_param_enum("blend1");
107 blend2 << ext->get_param_enum("blend2");
108 if (ext->get_param_bool("duotone"))
109 duotone << "0";
110 else
111 duotone << "1";
112 if (ext->get_param_bool("fg"))
113 fg << "0";
114 else
115 fg << "1";
117 _filter = g_strdup_printf(
118 "<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"
119 "<feComposite in2=\"SourceGraphic\" operator=\"arithmetic\" k1=\"%s\" k2=\"%s\" result=\"composite1\" />\n"
120 "<feColorMatrix in=\"composite1\" values=\"%s\" type=\"saturate\" result=\"colormatrix1\" />\n"
121 "<feFlood flood-opacity=\"%s\" flood-color=\"rgb(%s,%s,%s)\" result=\"flood1\" />\n"
122 "<feBlend in=\"flood1\" in2=\"colormatrix1\" mode=\"%s\" result=\"blend1\" />\n"
123 "<feBlend in2=\"blend1\" mode=\"%s\" result=\"blend2\" />\n"
124 "<feColorMatrix in=\"blend2\" values=\"%s\" type=\"saturate\" result=\"colormatrix2\" />\n"
125 "<feComposite in=\"colormatrix2\" in2=\"SourceGraphic\" operator=\"in\" k2=\"1\" result=\"composite2\" />\n"
126 "</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(), fg.str().c_str());
128 return _filter;
129 }; /* Colorize filter */
132 /* Custom predefined Duochrome filter
134 Filter's parameters:
135 * Fluorescence level (0.-2., default 0) -> composite4 (k2)
136 * Swap (enum, default "No swap") -> composite1, composite2 (operator)
137 * Color 1 (guint, default 1364325887) -> flood1 (flood-opacity, flood-color)
138 * Color 2 (guint, default -65281) -> flood2 (flood-opacity, flood-color)
139 */
141 class Duochrome : public Inkscape::Extension::Internal::Filter::Filter {
142 protected:
143 virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
145 public:
146 Duochrome ( ) : Filter() { };
147 virtual ~Duochrome ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
149 static void init (void) {
150 Inkscape::Extension::build_from_mem(
151 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
152 "<name>" N_("Duochrome, custom -EXP-") "</name>\n"
153 "<id>org.inkscape.effect.filter.Duochrome</id>\n"
154 "<param name=\"fluo\" gui-text=\"" N_("Fluorescence level:") "\" type=\"float\" min=\"0\" max=\"2\">0</param>\n"
155 "<param name=\"swap\" gui-text=\"" N_("Swap:") "\" type=\"enum\">\n"
156 "<_item value=\"none\">No swap</_item>\n"
157 "<_item value=\"full\">Color and alpha</_item>\n"
158 "<_item value=\"color\">Color only</_item>\n"
159 "<_item value=\"alpha\">Alpha only</_item>\n"
160 "</param>\n"
161 "<_param name=\"header1\" type=\"groupheader\">Color 1</_param>\n"
162 "<param name=\"color1\" gui-text=\"" N_("Color 1") "\" type=\"color\">1364325887</param>\n"
163 "<_param name=\"header2\" type=\"groupheader\">Color 2</_param>\n"
164 "<param name=\"color2\" gui-text=\"" N_("Color 2") "\" type=\"color\">-65281</param>\n"
165 "<effect>\n"
166 "<object-type>all</object-type>\n"
167 "<effects-menu>\n"
168 "<submenu name=\"" N_("Filters") "\">\n"
169 "<submenu name=\"" N_("Experimental") "\"/>\n"
170 "</submenu>\n"
171 "</effects-menu>\n"
172 "<menu-tip>" N_("Convert luminance values to a duochrome palette") "</menu-tip>\n"
173 "</effect>\n"
174 "</inkscape-extension>\n", new Duochrome());
175 };
177 };
179 gchar const *
180 Duochrome::get_filter_text (Inkscape::Extension::Extension * ext)
181 {
182 if (_filter != NULL) g_free((void *)_filter);
184 std::ostringstream a1;
185 std::ostringstream r1;
186 std::ostringstream g1;
187 std::ostringstream b1;
188 std::ostringstream a2;
189 std::ostringstream r2;
190 std::ostringstream g2;
191 std::ostringstream b2;
192 std::ostringstream fluo;
193 std::ostringstream swap1;
194 std::ostringstream swap2;
195 guint32 color1 = ext->get_param_color("color1");
196 guint32 color2 = ext->get_param_color("color2");
197 float fluorescence = ext->get_param_float("fluo");
198 const gchar *swaptype = ext->get_param_enum("swap");
200 r1 << ((color1 >> 24) & 0xff);
201 g1 << ((color1 >> 16) & 0xff);
202 b1 << ((color1 >> 8) & 0xff);
203 r2 << ((color2 >> 24) & 0xff);
204 g2 << ((color2 >> 16) & 0xff);
205 b2 << ((color2 >> 8) & 0xff);
206 fluo << fluorescence;
208 if((g_ascii_strcasecmp("full", swaptype) == 0)) {
209 swap1 << "in";
210 swap2 << "out";
211 a1 << (color1 & 0xff) / 255.0F;
212 a2 << (color2 & 0xff) / 255.0F;
213 } else if((g_ascii_strcasecmp("color", swaptype) == 0)) {
214 swap1 << "in";
215 swap2 << "out";
216 a1 << (color2 & 0xff) / 255.0F;
217 a2 << (color1 & 0xff) / 255.0F;
218 } else if((g_ascii_strcasecmp("alpha", swaptype) == 0)) {
219 swap1 << "out";
220 swap2 << "in";
221 a1 << (color2 & 0xff) / 255.0F;
222 a2 << (color1 & 0xff) / 255.0F;
223 } else {
224 swap1 << "out";
225 swap2 << "in";
226 a1 << (color1 & 0xff) / 255.0F;
227 a2 << (color2 & 0xff) / 255.0F;
228 }
230 _filter = g_strdup_printf(
231 "<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"
232 "<feColorMatrix type=\"luminanceToAlpha\" result=\"colormatrix1\" />\n"
233 "<feFlood flood-opacity=\"%s\" flood-color=\"rgb(%s,%s,%s)\" result=\"flood1\" />\n"
234 "<feComposite in2=\"colormatrix1\" operator=\"%s\" result=\"composite1\" />\n"
235 "<feFlood in=\"colormatrix1\" flood-opacity=\"%s\" flood-color=\"rgb(%s,%s,%s)\" result=\"flood2\" />\n"
236 "<feComposite in2=\"colormatrix1\" result=\"composite2\" operator=\"%s\" />\n"
237 "<feComposite in=\"composite2\" in2=\"composite1\" k2=\"1\" k3=\"1\" operator=\"arithmetic\" result=\"composite3\" />\n"
238 "<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"
239 "<feComposite in=\"colormatrix2\" in2=\"composite3\" operator=\"arithmetic\" k2=\"%s\" result=\"composite4\" />\n"
240 "<feBlend in=\"composite4\" in2=\"composite3\" blend=\"normal\" mode=\"normal\" result=\"blend\" />\n"
241 "<feComposite in2=\"SourceGraphic\" operator=\"in\" />\n"
242 "</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());
244 return _filter;
245 }; /* Duochrome filter */
248 /* Custom predefined Quadritone filter
250 Filter's parameters:
251 * Hue distribution (0-360, default 280) -> colormatrix1 (values)
252 * Colors (0-360, default 100) -> colormatrix3 (values)
253 * Blend mode 1 (enum, default Normal) -> blend1 (mode)
254 * Over-saturation (0.-1., default 0) -> composite1 (k2)
255 * Blend mode 2 (enum, default Normal) -> blend2 (mode)
256 */
258 class Quadritone : public Inkscape::Extension::Internal::Filter::Filter {
259 protected:
260 virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
262 public:
263 Quadritone ( ) : Filter() { };
264 virtual ~Quadritone ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
266 static void init (void) {
267 Inkscape::Extension::build_from_mem(
268 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
269 "<name>" N_("Quadritone fantasy, custom -EXP-") "</name>\n"
270 "<id>org.inkscape.effect.filter.Quadritone</id>\n"
271 "<param name=\"dist\" gui-text=\"" N_("Hue distribution:") "\" type=\"int\" min=\"0\" max=\"360\">280</param>\n"
272 "<param name=\"colors\" gui-text=\"" N_("Colors:") "\" type=\"int\" min=\"0\" max=\"360\">100</param>\n"
273 "<param name=\"blend1\" gui-text=\"" N_("Blend1:") "\" type=\"enum\">\n"
274 "<_item value=\"normal\">Normal</_item>\n"
275 "<_item value=\"multiply\">Multiply</_item>\n"
276 "<_item value=\"screen\">Screen</_item>\n"
277 "</param>\n"
278 "<param name=\"sat\" gui-text=\"" N_("Over-saturation:") "\" type=\"float\" min=\"0\" max=\"1\">0</param>\n"
279 "<param name=\"blend2\" gui-text=\"" N_("Blend2:") "\" type=\"enum\">\n"
280 "<_item value=\"normal\">Normal</_item>\n"
281 "<_item value=\"screen\">Screen</_item>\n"
282 "<_item value=\"multiply\">Multiply</_item>\n"
283 "<_item value=\"lighten\">Lighten</_item>\n"
284 "<_item value=\"darken\">Darken</_item>\n"
285 "</param>\n"
286 "<effect>\n"
287 "<object-type>all</object-type>\n"
288 "<effects-menu>\n"
289 "<submenu name=\"" N_("Filters") "\">\n"
290 "<submenu name=\"" N_("Experimental") "\"/>\n"
291 "</submenu>\n"
292 "</effects-menu>\n"
293 "<menu-tip>" N_("Replace hue by two colors") "</menu-tip>\n"
294 "</effect>\n"
295 "</inkscape-extension>\n", new Quadritone());
296 };
298 };
300 gchar const *
301 Quadritone::get_filter_text (Inkscape::Extension::Extension * ext)
302 {
303 if (_filter != NULL) g_free((void *)_filter);
305 std::ostringstream dist;
306 std::ostringstream colors;
307 std::ostringstream blend1;
308 std::ostringstream sat;
309 std::ostringstream blend2;
311 dist << ext->get_param_int("dist");
312 colors << ext->get_param_int("colors");
313 blend1 << ext->get_param_enum("blend1");
314 sat << ext->get_param_float("sat");
315 blend2 << ext->get_param_enum("blend2");
317 _filter = g_strdup_printf(
318 "<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"
319 "<feColorMatrix in=\"SourceGraphic\" type=\"hueRotate\" values=\"%s\" result=\"colormatrix1\" />\n"
320 "<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"
321 "<feColorMatrix type=\"hueRotate\" values=\"%s\" result=\"colormatrix3\" />\n"
322 "<feBlend in2=\"colormatrix3\" blend=\"normal\" mode=\"%s\" result=\"blend1\" />\n"
323 "<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"
324 "<feComposite in=\"colormatrix4\" in2=\"blend1\" operator=\"arithmetic\" k2=\"%s\" result=\"composite1\" />\n"
325 "<feBlend in2=\"blend1\" blend=\"normal\" mode=\"%s\" result=\"blend2\" />\n"
326 "</filter>\n", dist.str().c_str(), colors.str().c_str(), blend1.str().c_str(), sat.str().c_str(), blend2.str().c_str());
328 return _filter;
329 }; /* Quadritone filter */
332 /* Custom predefined Solarize filter
334 Filter's parameters:
335 * Type (enum, default "Solarize") ->
336 Solarize = blend1 (mode="darken"), blend2 (mode="screen")
337 Moonarize = blend1 (mode="lighten"), blend2 (mode="multiply") [No other access to the blend modes]
338 * Hue rotation (0-360, default 0) -> colormatrix1 (values)
339 */
341 class Solarize : public Inkscape::Extension::Internal::Filter::Filter {
342 protected:
343 virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
345 public:
346 Solarize ( ) : Filter() { };
347 virtual ~Solarize ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
349 static void init (void) {
350 Inkscape::Extension::build_from_mem(
351 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
352 "<name>" N_("Solarize, custom -EXP-") "</name>\n"
353 "<id>org.inkscape.effect.filter.Solarize</id>\n"
354 "<param name=\"rotate\" gui-text=\"" N_("Hue rotation:") "\" type=\"int\" min=\"0\" max=\"360\">0</param>\n"
355 "<param name=\"type\" gui-text=\"" N_("Type:") "\" type=\"enum\">\n"
356 "<_item value=\"solarize\">Solarize</_item>\n"
357 "<_item value=\"moonarize\">Moonarize</_item>\n"
358 "</param>\n"
359 "<effect>\n"
360 "<object-type>all</object-type>\n"
361 "<effects-menu>\n"
362 "<submenu name=\"" N_("Filters") "\">\n"
363 "<submenu name=\"" N_("Experimental") "\"/>\n"
364 "</submenu>\n"
365 "</effects-menu>\n"
366 "<menu-tip>" N_("Classic photographic solarization effect") "</menu-tip>\n"
367 "</effect>\n"
368 "</inkscape-extension>\n", new Solarize());
369 };
371 };
373 gchar const *
374 Solarize::get_filter_text (Inkscape::Extension::Extension * ext)
375 {
376 if (_filter != NULL) g_free((void *)_filter);
378 std::ostringstream rotate;
379 std::ostringstream blend1;
380 std::ostringstream blend2;
382 rotate << ext->get_param_int("rotate");
383 const gchar *type = ext->get_param_enum("type");
384 if((g_ascii_strcasecmp("solarize", type) == 0)) {
385 // Solarize
386 blend1 << "darken";
387 blend2 << "screen";
388 } else {
389 // Moonarize
390 blend1 << "lighten";
391 blend2 << "multiply";
392 }
394 _filter = g_strdup_printf(
395 "<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"
396 "<feColorMatrix values=\"1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 1 \" />\n"
397 "<feColorMatrix type=\"hueRotate\" values=\"%s\" result=\"colormatrix2\" />\n"
398 "<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"
399 "<feBlend in=\"colormatrix3\" in2=\"colormatrix2\" mode=\"%s\" result=\"blend1\" />\n"
400 "<feBlend in2=\"blend1\" mode=\"%s\" result=\"blend2\" />\n"
401 "<feComposite in2=\"SourceGraphic\" operator=\"in\" />\n"
402 "</filter>\n", rotate.str().c_str(), blend1.str().c_str(), blend2.str().c_str());
404 return _filter;
405 }; /* Solarize filter */
408 /* Custom predefined Tritone filter
410 Filter's parameters:
411 * Option (enum, default Normal) ->
412 Normal = composite1 (in="qminp", in2="flood"), composite2 (in="p", in2="blend6"), blend6 (in2="qminpc")
413 Enhance hue = Normal + composite2 (in="SourceGraphic")
414 Radiation = Normal + blend6 (in2="SourceGraphic") composite2 (in="blend6", in2="qminpc")
415 Hue to background = Normal + composite1 (in2="BackgroundImage") [a template with an activated background is needed, or colors become black]
416 * Hue distribution (0-360, default 0) -> colormatrix1 (values)
417 * Colors (guint, default -73203457) -> flood (flood-opacity, flood-color)
418 * Global blend (enum, default Lighten) -> blend5 (mode) [Multiply, Screen, Darken, Lighten only!]
419 * Glow (0.01-10., default 0.01) -> feGaussianBlur (stdDeviation)
420 * Glow & blend (enum, default Normal) -> blend6 (mode) [Normal, Multiply and Darken only!]
421 * Local light (0.-10., default 0) -> composite2 (k1)
422 * Global light (0.-10., default 1) -> composite2 (k3) [k2 must be fixed to 1].
423 */
425 class Tritone : public Inkscape::Extension::Internal::Filter::Filter {
426 protected:
427 virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
429 public:
430 Tritone ( ) : Filter() { };
431 virtual ~Tritone ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
433 static void init (void) {
434 Inkscape::Extension::build_from_mem(
435 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
436 "<name>" N_("Tritone, custom -EXP-") "</name>\n"
437 "<id>org.inkscape.effect.filter.Tritone</id>\n"
438 "<param name=\"type\" gui-text=\"" N_("Type:") "\" type=\"enum\">\n"
439 "<_item value=\"normal\">Normal</_item>\n"
440 "<_item value=\"enhue\">Enhance hue</_item>\n"
441 "<_item value=\"rad\">Radiation</_item>\n"
442 "<_item value=\"htb\">Hue to background</_item>\n"
443 "</param>\n"
444 "<param name=\"dist\" gui-text=\"" N_("Hue distribution:") "\" type=\"int\" min=\"0\" max=\"360\">0</param>\n"
445 "<param name=\"color\" gui-text=\"" N_("Color") "\" type=\"color\">-73203457</param>\n"
446 "<param name=\"globalblend\" gui-text=\"" N_("Global blend:") "\" type=\"enum\">\n"
447 "<_item value=\"lighten\">Lighten</_item>\n"
448 "<_item value=\"screen\">Screen</_item>\n"
449 "<_item value=\"multiply\">Multiply</_item>\n"
450 "<_item value=\"darken\">Darken</_item>\n"
451 "</param>\n"
452 "<param name=\"glow\" gui-text=\"" N_("Glow:") "\" type=\"float\" min=\"0.01\" max=\"10\">0.01</param>\n"
453 "<param name=\"glowblend\" gui-text=\"" N_("Glow blend:") "\" type=\"enum\">\n"
454 "<_item value=\"normal\">Normal</_item>\n"
455 "<_item value=\"multiply\">Multiply</_item>\n"
456 "<_item value=\"darken\">Darken</_item>\n"
457 "</param>\n"
458 "<param name=\"llight\" gui-text=\"" N_("Local light:") "\" type=\"float\" min=\"0\" max=\"10\">0</param>\n"
459 "<param name=\"glight\" gui-text=\"" N_("Global light:") "\" type=\"float\" min=\"0\" max=\"10\">1</param>\n"
460 "<effect>\n"
461 "<object-type>all</object-type>\n"
462 "<effects-menu>\n"
463 "<submenu name=\"" N_("Filters") "\">\n"
464 "<submenu name=\"" N_("Experimental") "\"/>\n"
465 "</submenu>\n"
466 "</effects-menu>\n"
467 "<menu-tip>" N_("Create a custom tritone palette with additional glow, blend modes and hue moving") "</menu-tip>\n"
468 "</effect>\n"
469 "</inkscape-extension>\n", new Tritone());
470 };
472 };
474 gchar const *
475 Tritone::get_filter_text (Inkscape::Extension::Extension * ext)
476 {
477 if (_filter != NULL) g_free((void *)_filter);
479 std::ostringstream dist;
480 std::ostringstream a;
481 std::ostringstream r;
482 std::ostringstream g;
483 std::ostringstream b;
484 std::ostringstream globalblend;
485 std::ostringstream glow;
486 std::ostringstream glowblend;
487 std::ostringstream llight;
488 std::ostringstream glight;
489 std::ostringstream c1in;
490 std::ostringstream c1in2;
491 std::ostringstream c2in;
492 std::ostringstream c2in2;
493 std::ostringstream b6in2;
495 guint32 color = ext->get_param_color("color");
496 r << ((color >> 24) & 0xff);
497 g << ((color >> 16) & 0xff);
498 b << ((color >> 8) & 0xff);
499 a << (color & 0xff) / 255.0F;
500 globalblend << ext->get_param_enum("globalblend");
501 dist << ext->get_param_int("dist");
502 glow << ext->get_param_float("glow");
503 glowblend << ext->get_param_enum("glowblend");
504 llight << ext->get_param_float("llight");
505 glight << ext->get_param_float("glight");
507 const gchar *type = ext->get_param_enum("type");
508 if((g_ascii_strcasecmp("enhue", type) == 0)) {
509 // Enhance hue
510 c1in << "qminp";
511 c1in2 << "flood";
512 c2in << "SourceGraphic";
513 c2in2 << "blend6";
514 b6in2 << "qminpc";
515 } else if((g_ascii_strcasecmp("rad", type) == 0)) {
516 // Radiation
517 c1in << "qminp";
518 c1in2 << "flood";
519 c2in << "blend6";
520 c2in2 << "qminpc";
521 b6in2 << "SourceGraphic";
522 } else if((g_ascii_strcasecmp("htb", type) == 0)) {
523 // Hue to background
524 c1in << "qminp";
525 c1in2 << "BackgroundImage";
526 c2in << "p";
527 c2in2 << "blend6";
528 b6in2 << "qminpc";
529 } else {
530 // Normal
531 c1in << "qminp";
532 c1in2 << "flood";
533 c2in << "p";
534 c2in2 << "blend6";
535 b6in2 << "qminpc";
536 }
538 _filter = g_strdup_printf(
539 "<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"
540 "<feColorMatrix type=\"hueRotate\" result=\"colormatrix1\" values=\"%s\" />\n"
541 "<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"
542 "<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"
543 "<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"
544 "<feBlend in2=\"g\" mode=\"darken\" in=\"r\" result=\"minrg\" />\n"
545 "<feBlend in2=\"b\" mode=\"darken\" in=\"minrg\" result=\"p\" />\n"
546 "<feBlend in2=\"g\" mode=\"lighten\" in=\"r\" result=\"maxrg\" />\n"
547 "<feBlend in2=\"b\" mode=\"lighten\" in=\"maxrg\" result=\"q\" />\n"
548 "<feComponentTransfer in=\"q\" result=\"q2\">\n"
549 "<feFuncR type=\"linear\" slope=\"0\" />\n"
550 "</feComponentTransfer>\n"
551 "<feBlend in2=\"q2\" mode=\"%s\" in=\"p\" result=\"pq\" />\n"
552 "<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"
553 "<feFlood in=\"qminp\" flood-opacity=\"%s\" flood-color=\"rgb(%s,%s,%s)\" result=\"flood\" />\n"
554 "<feComposite in=\"%s\" in2=\"%s\" result=\"qminpc\" operator=\"arithmetic\" k1=\"1\" />\n"
555 "<feGaussianBlur stdDeviation=\"%s\" />\n"
556 "<feBlend in2=\"%s\" blend=\"normal\" result=\"blend6\" mode=\"%s\" />\n"
557 "<feComposite in=\"%s\" in2=\"%s\" operator=\"arithmetic\" k1=\"%s\" k2=\"1\" k3=\"%s\" k4=\"0\" result=\"composite2\" />\n"
558 "<feComposite in2=\"SourceGraphic\" in=\"composite2\" operator=\"in\" />\n"
559 "</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());
561 return _filter;
562 }; /* Tritone filter */
564 }; /* namespace Filter */
565 }; /* namespace Internal */
566 }; /* namespace Extension */
567 }; /* namespace Inkscape */
569 /* Change the 'COLOR' below to be your file name */
570 #endif /* __INKSCAPE_EXTENSION_INTERNAL_FILTER_COLOR_H__ */