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=\"blend1\" gui-text=\"" N_("Blend1:") "\" type=\"enum\">\n"
56 "<_item value=\"multiply\">Multiply</_item>\n"
57 "<_item value=\"normal\">Normal</_item>\n"
58 "<_item value=\"screen\">Screen</_item>\n"
59 "<_item value=\"lighten\">Lighten</_item>\n"
60 "<_item value=\"darken\">Darken</_item>\n"
61 "</param>\n"
62 "<param name=\"blend2\" gui-text=\"" N_("Blend2:") "\" type=\"enum\">\n"
63 "<_item value=\"screen\">Screen</_item>\n"
64 "<_item value=\"multiply\">Multiply</_item>\n"
65 "<_item value=\"normal\">Normal</_item>\n"
66 "<_item value=\"lighten\">Lighten</_item>\n"
67 "<_item value=\"darken\">Darken</_item>\n"
68 "</param>\n"
69 "<param name=\"color\" gui-text=\"" N_("Color 1") "\" type=\"color\">-1639776001</param>\n"
70 "<effect>\n"
71 "<object-type>all</object-type>\n"
72 "<effects-menu>\n"
73 "<submenu name=\"" N_("Filters") "\">\n"
74 "<submenu name=\"" N_("Experimental") "\"/>\n"
75 "</submenu>\n"
76 "</effects-menu>\n"
77 "<menu-tip>" N_("Blend image or object with a flood color") "</menu-tip>\n"
78 "</effect>\n"
79 "</inkscape-extension>\n", new Colorize());
80 };
82 };
84 gchar const *
85 Colorize::get_filter_text (Inkscape::Extension::Extension * ext)
86 {
87 if (_filter != NULL) g_free((void *)_filter);
89 std::ostringstream a;
90 std::ostringstream r;
91 std::ostringstream g;
92 std::ostringstream b;
93 std::ostringstream hlight;
94 std::ostringstream nlight;
95 std::ostringstream duotone;
96 std::ostringstream blend1;
97 std::ostringstream blend2;
99 guint32 color = ext->get_param_color("color");
100 r << ((color >> 24) & 0xff);
101 g << ((color >> 16) & 0xff);
102 b << ((color >> 8) & 0xff);
103 a << (color & 0xff) / 255.0F;
105 hlight << ext->get_param_float("hlight");
106 nlight << ext->get_param_float("nlight");
107 blend1 << ext->get_param_enum("blend1");
108 blend2 << ext->get_param_enum("blend2");
109 if (ext->get_param_bool("duotone"))
110 duotone << "0";
111 else
112 duotone << "1";
114 _filter = g_strdup_printf(
115 "<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"
116 "<feComposite in2=\"SourceGraphic\" operator=\"arithmetic\" k1=\"%s\" k2=\"%s\" result=\"composite1\" />\n"
117 "<feColorMatrix in=\"composite1\" values=\"%s\" type=\"saturate\" result=\"colormatrix1\" />\n"
118 "<feFlood flood-opacity=\"%s\" flood-color=\"rgb(%s,%s,%s)\" result=\"flood1\" />\n"
119 "<feBlend in=\"flood1\" in2=\"colormatrix1\" mode=\"%s\" result=\"blend1\" />\n"
120 "<feBlend in2=\"blend1\" mode=\"%s\" result=\"blend2\" />\n"
121 "<feColorMatrix in=\"blend2\" values=\"1\" type=\"saturate\" result=\"colormatrix2\" />\n"
122 "<feComposite in=\"colormatrix2\" in2=\"SourceGraphic\" operator=\"in\" k2=\"1\" result=\"composite2\" />\n"
123 "</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());
125 return _filter;
126 }; /* Colorize filter */
129 /**
130 \brief Custom predefined Duochrome filter.
132 Convert luminance values to a duochrome palette.
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 /**
249 \brief Custom predefined Quadritone filter.
251 Replace hue by two colors.
253 Filter's parameters:
254 * Hue distribution (0->360, default 280) -> colormatrix1 (values)
255 * Colors (0->360, default 100) -> colormatrix3 (values)
256 * Blend mode 1 (enum, default Normal) -> blend1 (mode)
257 * Over-saturation (0.->1., default 0) -> composite1 (k2)
258 * Blend mode 2 (enum, default Normal) -> blend2 (mode)
259 */
261 class Quadritone : public Inkscape::Extension::Internal::Filter::Filter {
262 protected:
263 virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
265 public:
266 Quadritone ( ) : Filter() { };
267 virtual ~Quadritone ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
269 static void init (void) {
270 Inkscape::Extension::build_from_mem(
271 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
272 "<name>" N_("Quadritone fantasy, custom -EXP-") "</name>\n"
273 "<id>org.inkscape.effect.filter.Quadritone</id>\n"
274 "<param name=\"dist\" gui-text=\"" N_("Hue distribution:") "\" type=\"int\" min=\"0\" max=\"360\">280</param>\n"
275 "<param name=\"colors\" gui-text=\"" N_("Colors:") "\" type=\"int\" min=\"0\" max=\"360\">100</param>\n"
276 "<param name=\"blend1\" gui-text=\"" N_("Blend1:") "\" type=\"enum\">\n"
277 "<_item value=\"normal\">Normal</_item>\n"
278 "<_item value=\"multiply\">Multiply</_item>\n"
279 "<_item value=\"screen\">Screen</_item>\n"
280 "</param>\n"
281 "<param name=\"sat\" gui-text=\"" N_("Over-saturation:") "\" type=\"float\" min=\"0\" max=\"1\">0</param>\n"
282 "<param name=\"blend2\" gui-text=\"" N_("Blend2:") "\" type=\"enum\">\n"
283 "<_item value=\"normal\">Normal</_item>\n"
284 "<_item value=\"screen\">Screen</_item>\n"
285 "<_item value=\"multiply\">Multiply</_item>\n"
286 "<_item value=\"lighten\">Lighten</_item>\n"
287 "<_item value=\"darken\">Darken</_item>\n"
288 "</param>\n"
289 "<effect>\n"
290 "<object-type>all</object-type>\n"
291 "<effects-menu>\n"
292 "<submenu name=\"" N_("Filters") "\">\n"
293 "<submenu name=\"" N_("Experimental") "\"/>\n"
294 "</submenu>\n"
295 "</effects-menu>\n"
296 "<menu-tip>" N_("Replace hue by two colors") "</menu-tip>\n"
297 "</effect>\n"
298 "</inkscape-extension>\n", new Quadritone());
299 };
301 };
303 gchar const *
304 Quadritone::get_filter_text (Inkscape::Extension::Extension * ext)
305 {
306 if (_filter != NULL) g_free((void *)_filter);
308 std::ostringstream dist;
309 std::ostringstream colors;
310 std::ostringstream blend1;
311 std::ostringstream sat;
312 std::ostringstream blend2;
314 dist << ext->get_param_int("dist");
315 colors << ext->get_param_int("colors");
316 blend1 << ext->get_param_enum("blend1");
317 sat << ext->get_param_float("sat");
318 blend2 << ext->get_param_enum("blend2");
320 _filter = g_strdup_printf(
321 "<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"
322 "<feColorMatrix in=\"SourceGraphic\" type=\"hueRotate\" values=\"%s\" result=\"colormatrix1\" />\n"
323 "<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"
324 "<feColorMatrix type=\"hueRotate\" values=\"%s\" result=\"colormatrix3\" />\n"
325 "<feBlend in2=\"colormatrix3\" blend=\"normal\" mode=\"%s\" result=\"blend1\" />\n"
326 "<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"
327 "<feComposite in=\"colormatrix4\" in2=\"blend1\" operator=\"arithmetic\" k2=\"%s\" result=\"composite1\" />\n"
328 "<feBlend in2=\"blend1\" blend=\"normal\" mode=\"%s\" result=\"blend2\" />\n"
329 "</filter>\n", dist.str().c_str(), colors.str().c_str(), blend1.str().c_str(), sat.str().c_str(), blend2.str().c_str());
331 return _filter;
332 }; /* Quadritone filter */
335 /**
336 \brief Custom predefined Solarize filter.
338 Classic photographic solarization effect.
340 Filter's parameters:
341 * Type (enum, default "Solarize") ->
342 Solarize = blend1 (mode="darken"), blend2 (mode="screen")
343 Moonarize = blend1 (mode="lighten"), blend2 (mode="multiply") [No other access to the blend modes]
344 * Hue rotation (0->360, default 0) -> colormatrix1 (values)
345 */
348 class Solarize : public Inkscape::Extension::Internal::Filter::Filter {
349 protected:
350 virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
352 public:
353 Solarize ( ) : Filter() { };
354 virtual ~Solarize ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
356 static void init (void) {
357 Inkscape::Extension::build_from_mem(
358 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
359 "<name>" N_("Solarize, custom -EXP-") "</name>\n"
360 "<id>org.inkscape.effect.filter.Solarize</id>\n"
361 "<param name=\"rotate\" gui-text=\"" N_("Hue rotation:") "\" type=\"int\" min=\"0\" max=\"360\">0</param>\n"
362 "<param name=\"type\" gui-text=\"" N_("Type:") "\" type=\"enum\">\n"
363 "<_item value=\"solarize\">Solarize</_item>\n"
364 "<_item value=\"moonarize\">Moonarize</_item>\n"
365 "</param>\n"
366 "<effect>\n"
367 "<object-type>all</object-type>\n"
368 "<effects-menu>\n"
369 "<submenu name=\"" N_("Filters") "\">\n"
370 "<submenu name=\"" N_("Experimental") "\"/>\n"
371 "</submenu>\n"
372 "</effects-menu>\n"
373 "<menu-tip>" N_("Classic photographic solarization effect") "</menu-tip>\n"
374 "</effect>\n"
375 "</inkscape-extension>\n", new Solarize());
376 };
378 };
380 gchar const *
381 Solarize::get_filter_text (Inkscape::Extension::Extension * ext)
382 {
383 if (_filter != NULL) g_free((void *)_filter);
385 std::ostringstream rotate;
386 std::ostringstream blend1;
387 std::ostringstream blend2;
389 rotate << ext->get_param_int("rotate");
390 const gchar *type = ext->get_param_enum("type");
391 if((g_ascii_strcasecmp("solarize", type) == 0)) {
392 // Solarize
393 blend1 << "darken";
394 blend2 << "screen";
395 } else {
396 // Moonarize
397 blend1 << "lighten";
398 blend2 << "multiply";
399 }
401 _filter = g_strdup_printf(
402 "<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"
403 "<feColorMatrix values=\"1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 1 \" />\n"
404 "<feColorMatrix type=\"hueRotate\" values=\"%s\" result=\"colormatrix2\" />\n"
405 "<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"
406 "<feBlend in=\"colormatrix3\" in2=\"colormatrix2\" mode=\"%s\" result=\"blend1\" />\n"
407 "<feBlend in2=\"blend1\" mode=\"%s\" result=\"blend2\" />\n"
408 "<feComposite in2=\"SourceGraphic\" operator=\"in\" />\n"
409 "</filter>\n", rotate.str().c_str(), blend1.str().c_str(), blend2.str().c_str());
411 return _filter;
412 }; /* Solarize filter */
415 /**
416 \brief Custom predefined Tritone filter.
418 Create a custom tritone palette with additional glow, blend modes and hue moving.
420 Filter's parameters:
421 * Option (enum, default Normal) ->
422 Normal = composite1 (in="qminp", in2="flood"), composite2 (in="p", in2="blend6"), blend6 (in2="qminpc")
423 Enhance hue = Normal + composite2 (in="SourceGraphic")
424 Radiation = Normal + blend6 (in2="SourceGraphic") composite2 (in="blend6", in2="qminpc")
425 Hue to background = Normal + composite1 (in2="BackgroundImage") [a template with an activated background is needed, or colors become black]
426 * Hue distribution (0->360, default 0) -> colormatrix1 (values)
427 * Colors (guint, default -73203457) -> flood (flood-opacity, flood-color)
428 * Global blend (enum, default Lighten) -> blend5 (mode) [Multiply, Screen, Darken, Lighten only!]
429 * Glow (0.01->10., default 0.01) -> feGaussianBlur (stdDeviation)
430 * Glow & blend (enum, default Normal) -> blend6 (mode) [Normal, Multiply and Darken only!]
431 * Local light (0.->10., default 0) -> composite2 (k1)
432 * Global light (0.->10., default 1) -> composite2 (k3) [k2 must be fixed to 1].
433 */
435 class Tritone : public Inkscape::Extension::Internal::Filter::Filter {
436 protected:
437 virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
439 public:
440 Tritone ( ) : Filter() { };
441 virtual ~Tritone ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
443 static void init (void) {
444 Inkscape::Extension::build_from_mem(
445 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
446 "<name>" N_("Tritone, custom -EXP-") "</name>\n"
447 "<id>org.inkscape.effect.filter.Tritone</id>\n"
448 "<param name=\"type\" gui-text=\"" N_("Type:") "\" type=\"enum\">\n"
449 "<_item value=\"normal\">Normal</_item>\n"
450 "<_item value=\"enhue\">Enhance hue</_item>\n"
451 "<_item value=\"rad\">Radiation</_item>\n"
452 "<_item value=\"htb\">Hue to background</_item>\n"
453 "</param>\n"
454 "<param name=\"dist\" gui-text=\"" N_("Hue distribution:") "\" type=\"int\" min=\"0\" max=\"360\">0</param>\n"
455 "<param name=\"color\" gui-text=\"" N_("Color") "\" type=\"color\">-73203457</param>\n"
456 "<param name=\"globalblend\" gui-text=\"" N_("Global blend:") "\" type=\"enum\">\n"
457 "<_item value=\"lighten\">Lighten</_item>\n"
458 "<_item value=\"screen\">Screen</_item>\n"
459 "<_item value=\"multiply\">Multiply</_item>\n"
460 "<_item value=\"darken\">Darken</_item>\n"
461 "</param>\n"
462 "<param name=\"glow\" gui-text=\"" N_("Glow:") "\" type=\"float\" min=\"0.01\" max=\"10\">0.01</param>\n"
463 "<param name=\"glowblend\" gui-text=\"" N_("Glow blend:") "\" type=\"enum\">\n"
464 "<_item value=\"normal\">Normal</_item>\n"
465 "<_item value=\"multiply\">Multiply</_item>\n"
466 "<_item value=\"darken\">Darken</_item>\n"
467 "</param>\n"
468 "<param name=\"llight\" gui-text=\"" N_("Local light:") "\" type=\"float\" min=\"0\" max=\"10\">0</param>\n"
469 "<param name=\"glight\" gui-text=\"" N_("Global light:") "\" type=\"float\" min=\"0\" max=\"10\">1</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_("Create a custom tritone palette with additional glow, blend modes and hue moving") "</menu-tip>\n"
478 "</effect>\n"
479 "</inkscape-extension>\n", new Tritone());
480 };
482 };
484 gchar const *
485 Tritone::get_filter_text (Inkscape::Extension::Extension * ext)
486 {
487 if (_filter != NULL) g_free((void *)_filter);
489 std::ostringstream dist;
490 std::ostringstream a;
491 std::ostringstream r;
492 std::ostringstream g;
493 std::ostringstream b;
494 std::ostringstream globalblend;
495 std::ostringstream glow;
496 std::ostringstream glowblend;
497 std::ostringstream llight;
498 std::ostringstream glight;
499 std::ostringstream c1in;
500 std::ostringstream c1in2;
501 std::ostringstream c2in;
502 std::ostringstream c2in2;
503 std::ostringstream b6in2;
505 guint32 color = ext->get_param_color("color");
506 r << ((color >> 24) & 0xff);
507 g << ((color >> 16) & 0xff);
508 b << ((color >> 8) & 0xff);
509 a << (color & 0xff) / 255.0F;
510 globalblend << ext->get_param_enum("globalblend");
511 dist << ext->get_param_int("dist");
512 glow << ext->get_param_float("glow");
513 glowblend << ext->get_param_enum("glowblend");
514 llight << ext->get_param_float("llight");
515 glight << ext->get_param_float("glight");
517 const gchar *type = ext->get_param_enum("type");
518 if((g_ascii_strcasecmp("enhue", type) == 0)) {
519 // Enhance hue
520 c1in << "qminp";
521 c1in2 << "flood";
522 c2in << "SourceGraphic";
523 c2in2 << "blend6";
524 b6in2 << "qminpc";
525 } else if((g_ascii_strcasecmp("rad", type) == 0)) {
526 // Radiation
527 c1in << "qminp";
528 c1in2 << "flood";
529 c2in << "blend6";
530 c2in2 << "qminpc";
531 b6in2 << "SourceGraphic";
532 } else if((g_ascii_strcasecmp("htb", type) == 0)) {
533 // Hue to background
534 c1in << "qminp";
535 c1in2 << "BackgroundImage";
536 c2in << "p";
537 c2in2 << "blend6";
538 b6in2 << "qminpc";
539 } else {
540 // Normal
541 c1in << "qminp";
542 c1in2 << "flood";
543 c2in << "p";
544 c2in2 << "blend6";
545 b6in2 << "qminpc";
546 }
548 _filter = g_strdup_printf(
549 "<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"
550 "<feColorMatrix type=\"hueRotate\" result=\"colormatrix1\" values=\"%s\" />\n"
551 "<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"
552 "<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"
553 "<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"
554 "<feBlend in2=\"g\" mode=\"darken\" in=\"r\" result=\"minrg\" />\n"
555 "<feBlend in2=\"b\" mode=\"darken\" in=\"minrg\" result=\"p\" />\n"
556 "<feBlend in2=\"g\" mode=\"lighten\" in=\"r\" result=\"maxrg\" />\n"
557 "<feBlend in2=\"b\" mode=\"lighten\" in=\"maxrg\" result=\"q\" />\n"
558 "<feComponentTransfer in=\"q\" result=\"q2\">\n"
559 "<feFuncR type=\"linear\" slope=\"0\" />\n"
560 "</feComponentTransfer>\n"
561 "<feBlend in2=\"q2\" mode=\"%s\" in=\"p\" result=\"pq\" />\n"
562 "<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"
563 "<feFlood in=\"qminp\" flood-opacity=\"%s\" flood-color=\"rgb(%s,%s,%s)\" result=\"flood\" />\n"
564 "<feComposite in=\"%s\" in2=\"%s\" result=\"qminpc\" operator=\"arithmetic\" k1=\"1\" />\n"
565 "<feGaussianBlur stdDeviation=\"%s\" />\n"
566 "<feBlend in2=\"%s\" blend=\"normal\" result=\"blend6\" mode=\"%s\" />\n"
567 "<feComposite in=\"%s\" in2=\"%s\" operator=\"arithmetic\" k1=\"%s\" k2=\"1\" k3=\"%s\" k4=\"0\" result=\"composite2\" />\n"
568 "<feComposite in2=\"SourceGraphic\" in=\"composite2\" operator=\"in\" />\n"
569 "</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());
571 return _filter;
572 }; /* Tritone filter */
574 }; /* namespace Filter */
575 }; /* namespace Internal */
576 }; /* namespace Extension */
577 }; /* namespace Inkscape */
579 /* Change the 'COLOR' below to be your file name */
580 #endif /* __INKSCAPE_EXTENSION_INTERNAL_FILTER_COLOR_H__ */