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