1 #ifndef __INKSCAPE_EXTENSION_INTERNAL_FILTER_EXPERIMENTAL_H__
2 #define __INKSCAPE_EXTENSION_INTERNAL_FILTER_EXPERIMENTAL_H__
3 /* Change the 'EXPERIMENTAL' 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 * Experimental filters (no assigned menu)
11 * Chromolitho
12 * Cross engraving
13 * Drawing
14 * Neon draw
15 * Posterize
16 * Posterize basic
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 Chromolitho filter.
36 Chromo effect with customizable edge drawing and graininess
38 Filter's parameters:
39 * Drawing (boolean, default checked) -> Checked = blend1 (in="convolve1"), unchecked = blend1 (in="composite1")
40 * Transparent (boolean, default unchecked) -> Checked = colormatrix5 (in="colormatrix4"), Unchecked = colormatrix5 (in="component1")
41 * Invert (boolean, default false) -> component1 (tableValues) [adds a trailing 0]
42 * Dented (boolean, default false) -> component1 (tableValues) [adds intermediate 0s]
43 * Lightness (0.->10., default 0.) -> composite1 (k1)
44 * Saturation (0.->1., default 1.) -> colormatrix3 (values)
45 * Noise reduction (1->1000, default 20) -> convolve (kernelMatrix, central value -1001->-2000, default -1020)
46 * Drawing blend (enum, default Normal) -> blend1 (mode)
47 * Smoothness (0.01->10, default 1) -> blur1 (stdDeviation)
48 * Grain (boolean, default unchecked) -> Checked = blend2 (in="colormatrix2"), Unchecked = blend2 (in="blur1")
49 * Grain x frequency (0.->100, default 100) -> turbulence1 (baseFrequency, first value)
50 * Grain y frequency (0.->100, default 100) -> turbulence1 (baseFrequency, second value)
51 * Grain complexity (1->5, default 1) -> turbulence1 (numOctaves)
52 * Grain variation (0->1000, default 0) -> turbulence1 (seed)
53 * Grain expansion (1.->50., default 1.) -> colormatrix1 (n-1 value)
54 * Grain erosion (0.->40., default 0.) -> colormatrix1 (nth value) [inverted]
55 * Grain color (boolean, default true) -> colormatrix2 (values)
56 * Grain blend (enum, default Normal) -> blend2 (mode)
57 */
58 class Chromolitho : public Inkscape::Extension::Internal::Filter::Filter {
59 protected:
60 virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
62 public:
63 Chromolitho ( ) : Filter() { };
64 virtual ~Chromolitho ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
66 static void init (void) {
67 Inkscape::Extension::build_from_mem(
68 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
69 "<name>" N_("Chromolitho, custom") "</name>\n"
70 "<id>org.inkscape.effect.filter.Chromolitho</id>\n"
71 "<param name=\"tab\" type=\"notebook\">\n"
72 "<page name=\"optionstab\" _gui-text=\"Options\">\n"
73 "<param name=\"drawing\" gui-text=\"" N_("Drawing mode") "\" type=\"boolean\" >true</param>\n"
74 "<param name=\"dblend\" gui-text=\"" N_("Drawing blend:") "\" type=\"enum\">\n"
75 "<_item value=\"darken\">Darken</_item>\n"
76 "<_item value=\"normal\">Normal</_item>\n"
77 "<_item value=\"multiply\">Multiply</_item>\n"
78 "<_item value=\"screen\">Screen</_item>\n"
79 "<_item value=\"lighten\">Lighten</_item>\n"
80 "</param>\n"
81 "<param name=\"transparent\" gui-text=\"" N_("Transparent") "\" type=\"boolean\" >false</param>\n"
82 "<param name=\"dented\" gui-text=\"" N_("Dented") "\" type=\"boolean\" >false</param>\n"
83 "<param name=\"inverted\" gui-text=\"" N_("Inverted") "\" type=\"boolean\" >false</param>\n"
84 "<param name=\"light\" gui-text=\"" N_("Lightness:") "\" type=\"float\" min=\"0\" max=\"10\">0</param>\n"
85 "<param name=\"saturation\" gui-text=\"" N_("Saturation:") "\" type=\"float\" min=\"0\" max=\"1\">1</param>\n"
86 "<param name=\"noise\" gui-text=\"" N_("Noise reduction:") "\" type=\"int\" min=\"1\" max=\"1000\">10</param>\n"
87 "<param name=\"smooth\" gui-text=\"" N_("Smoothness:") "\" type=\"float\" min=\"0.01\" max=\"10\">1</param>\n"
88 "</page>\n"
89 "<page name=\"graintab\" _gui-text=\"Grain\">\n"
90 "<param name=\"grain\" gui-text=\"" N_("Grain mode") "\" type=\"boolean\" >true</param>\n"
91 "<param name=\"grainxf\" gui-text=\"" N_("X frequency:") "\" type=\"float\" min=\"0\" max=\"100\">100</param>\n"
92 "<param name=\"grainyf\" gui-text=\"" N_("Y frequency:") "\" type=\"float\" min=\"0\" max=\"100\">100</param>\n"
93 "<param name=\"grainc\" gui-text=\"" N_("Complexity:") "\" type=\"int\" min=\"1\" max=\"5\">1</param>\n"
94 "<param name=\"grainv\" gui-text=\"" N_("Variation:") "\" type=\"int\" min=\"0\" max=\"1000\">0</param>\n"
95 "<param name=\"grainexp\" gui-text=\"" N_("Expansion:") "\" type=\"float\" min=\"1\" max=\"50\">1</param>\n"
96 "<param name=\"grainero\" gui-text=\"" N_("Erosion:") "\" type=\"float\" min=\"0\" max=\"40\">0</param>\n"
97 "<param name=\"graincol\" gui-text=\"" N_("Color") "\" type=\"boolean\" >true</param>\n"
98 "<param name=\"gblend\" gui-text=\"" N_("Grain blend:") "\" type=\"enum\">\n"
99 "<_item value=\"normal\">Normal</_item>\n"
100 "<_item value=\"multiply\">Multiply</_item>\n"
101 "<_item value=\"screen\">Screen</_item>\n"
102 "<_item value=\"lighten\">Lighten</_item>\n"
103 "<_item value=\"darken\">Darken</_item>\n"
104 "</param>\n"
105 "</page>\n"
106 "</param>\n"
107 "<effect>\n"
108 "<object-type>all</object-type>\n"
109 "<effects-menu>\n"
110 "<submenu name=\"" N_("Filters") "\">\n"
111 "<submenu name=\"" N_("Experimental") "\"/>\n"
112 "</submenu>\n"
113 "</effects-menu>\n"
114 "<menu-tip>" N_("Chromo effect with customizable edge drawing and graininess") "</menu-tip>\n"
115 "</effect>\n"
116 "</inkscape-extension>\n", new Chromolitho());
117 };
118 };
120 gchar const *
121 Chromolitho::get_filter_text (Inkscape::Extension::Extension * ext)
122 {
123 if (_filter != NULL) g_free((void *)_filter);
125 std::ostringstream b1in;
126 std::ostringstream b2in;
127 std::ostringstream col3in;
128 std::ostringstream transf;
129 std::ostringstream light;
130 std::ostringstream saturation;
131 std::ostringstream noise;
132 std::ostringstream dblend;
133 std::ostringstream smooth;
134 std::ostringstream grain;
135 std::ostringstream grainxf;
136 std::ostringstream grainyf;
137 std::ostringstream grainc;
138 std::ostringstream grainv;
139 std::ostringstream gblend;
140 std::ostringstream grainexp;
141 std::ostringstream grainero;
142 std::ostringstream graincol;
144 if (ext->get_param_bool("drawing"))
145 b1in << "convolve1";
146 else
147 b1in << "composite1";
149 if (ext->get_param_bool("transparent"))
150 col3in << "colormatrix4";
151 else
152 col3in << "component1";
153 light << ext->get_param_float("light");
154 saturation << ext->get_param_float("saturation");
155 noise << (-1000 - ext->get_param_int("noise"));
156 dblend << ext->get_param_enum("dblend");
157 smooth << ext->get_param_float("smooth");
159 if (ext->get_param_bool("dented")) {
160 transf << "0 1 0 1";
161 } else {
162 transf << "0 1 1";
163 }
164 if (ext->get_param_bool("inverted"))
165 transf << " 0";
167 if (ext->get_param_bool("grain"))
168 b2in << "colormatrix2";
169 else
170 b2in << "blur1";
171 grainxf << (ext->get_param_float("grainxf") / 100);
172 grainyf << (ext->get_param_float("grainyf") / 100);
173 grainc << ext->get_param_int("grainc");
174 grainv << ext->get_param_int("grainv");
175 gblend << ext->get_param_enum("gblend");
176 grainexp << ext->get_param_float("grainexp");
177 grainero << (-ext->get_param_float("grainero"));
178 if (ext->get_param_bool("graincol"))
179 graincol << "1";
180 else
181 graincol << "0";
183 _filter = g_strdup_printf(
184 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" color-interpolation-filters=\"sRGB\" height=\"1\" width=\"1\" y=\"0\" x=\"0\" inkscape:label=\"Chromolitho, custom\">\n"
185 "<feComposite stdDeviation=\"1\" in=\"SourceGraphic\" in2=\"SourceGraphic\" operator=\"arithmetic\" k1=\"%s\" k2=\"1\" result=\"composite1\" />\n"
186 "<feConvolveMatrix in=\"composite1\" kernelMatrix=\"0 250 0 250 %s 250 0 250 0 \" order=\"3 3\" stdDeviation=\"1\" result=\"convolve1\" />\n"
187 "<feBlend in=\"%s\" in2=\"composite1\" mode=\"%s\" blend=\"normal\" stdDeviation=\"1\" result=\"blend1\" />\n"
188 "<feGaussianBlur in=\"blend1\" stdDeviation=\"%s\" result=\"blur1\" />\n"
189 "<feTurbulence baseFrequency=\"%s %s\" numOctaves=\"%s\" seed=\"%s\" type=\"fractalNoise\" result=\"turbulence1\" />\n"
190 "<feColorMatrix values=\"1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 %s %s \" result=\"colormatrix1\" />\n"
191 "<feColorMatrix type=\"saturate\" stdDeviation=\"3\" values=\"%s\" result=\"colormatrix2\" />\n"
192 "<feBlend in=\"%s\" in2=\"blur1\" stdDeviation=\"1\" blend=\"normal\" mode=\"%s\" result=\"blend2\" />\n"
193 "<feColorMatrix in=\"blend2\" type=\"saturate\" values=\"%s\" result=\"colormatrix3\" />\n"
194 "<feComponentTransfer in=\"colormatrix3\" stdDeviation=\"2\" result=\"component1\">\n"
195 "<feFuncR type=\"discrete\" tableValues=\"%s\" />\n"
196 "<feFuncG type=\"discrete\" tableValues=\"%s\" />\n"
197 "<feFuncB type=\"discrete\" tableValues=\"%s\" />\n"
198 "</feComponentTransfer>\n"
199 "<feColorMatrix values=\"1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 -0.2125 -0.7154 -0.0721 1 0 \" result=\"colormatrix4\" />\n"
200 "<feColorMatrix in=\"%s\" values=\"1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 15 0 \" result=\"colormatrix5\" />\n"
201 "<feComposite in2=\"SourceGraphic\" operator=\"in\" result=\"composite2\" />\n"
202 "</filter>\n", light.str().c_str(), noise.str().c_str(), b1in.str().c_str(), dblend.str().c_str(), smooth.str().c_str(), grainxf.str().c_str(), grainyf.str().c_str(), grainc.str().c_str(), grainv.str().c_str(), grainexp.str().c_str(), grainero.str().c_str(), graincol.str().c_str(), b2in.str().c_str(), gblend.str().c_str(), saturation.str().c_str(), transf.str().c_str(), transf.str().c_str(), transf.str().c_str(), col3in.str().c_str());
204 return _filter;
205 }; /* Chromolitho filter */
207 /**
208 \brief Custom predefined Cross engraving filter.
210 Convert image to an engraving made of vertical and horizontal lines
212 Filter's parameters:
213 * Clean-up (1->500, default 30) -> convolve1 (kernelMatrix, central value -1001->-1500, default -1030)
214 * Dilatation (1.->50., default 1) -> color2 (n-1th value)
215 * Erosion (0.->50., default 0) -> color2 (nth value 0->-50)
216 * Strength (0.->10., default 0.5) -> composite2 (k2)
217 * Length (0.5->20, default 4) -> blur1 (stdDeviation x), blur2 (stdDeviation y)
218 * Transparent (boolean, default false) -> composite 4 (in, true->composite3, false->blend)
219 */
220 class CrossEngraving : public Inkscape::Extension::Internal::Filter::Filter {
221 protected:
222 virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
224 public:
225 CrossEngraving ( ) : Filter() { };
226 virtual ~CrossEngraving ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
228 static void init (void) {
229 Inkscape::Extension::build_from_mem(
230 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
231 "<name>" N_("Cross engraving, custom") "</name>\n"
232 "<id>org.inkscape.effect.filter.CrossEngraving</id>\n"
233 "<param name=\"clean\" gui-text=\"" N_("Clean-up:") "\" type=\"int\" min=\"1\" max=\"500\">30</param>\n"
234 "<param name=\"dilat\" gui-text=\"" N_("Dilatation:") "\" type=\"float\" min=\"1\" max=\"50\">1</param>\n"
235 "<param name=\"erosion\" gui-text=\"" N_("Erosion:") "\" type=\"float\" min=\"0\" max=\"50\">0</param>\n"
236 "<param name=\"strength\" gui-text=\"" N_("Strength:") "\" type=\"float\" min=\"0.1\" max=\"10\">0.5</param>\n"
237 "<param name=\"length\" gui-text=\"" N_("Length:") "\" type=\"float\" min=\"0.5\" max=\"20\">4</param>\n"
238 "<param name=\"trans\" gui-text=\"" N_("Transparent") "\" type=\"boolean\" >false</param>\n"
239 "<effect>\n"
240 "<object-type>all</object-type>\n"
241 "<effects-menu>\n"
242 "<submenu name=\"" N_("Filters") "\">\n"
243 "<submenu name=\"" N_("Experimental") "\"/>\n"
244 "</submenu>\n"
245 "</effects-menu>\n"
246 "<menu-tip>" N_("Convert image to an engraving made of vertical and horizontal lines") "</menu-tip>\n"
247 "</effect>\n"
248 "</inkscape-extension>\n", new CrossEngraving());
249 };
250 };
252 gchar const *
253 CrossEngraving::get_filter_text (Inkscape::Extension::Extension * ext)
254 {
255 if (_filter != NULL) g_free((void *)_filter);
257 std::ostringstream clean;
258 std::ostringstream dilat;
259 std::ostringstream erosion;
260 std::ostringstream strength;
261 std::ostringstream length;
262 std::ostringstream trans;
264 clean << (-1000 - ext->get_param_int("clean"));
265 dilat << ext->get_param_float("dilat");
266 erosion << (- ext->get_param_float("erosion"));
267 strength << ext->get_param_float("strength");
268 length << ext->get_param_float("length");
269 if (ext->get_param_bool("trans"))
270 trans << "composite3";
271 else
272 trans << "blend";
274 _filter = g_strdup_printf(
275 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" color-interpolation-filters=\"sRGB\" height=\"1\" width=\"1\" y=\"0\" x=\"0\" inkscape:label=\"Cross engraving, custom\">\n"
276 "<feConvolveMatrix in=\"SourceGraphic\" targetY=\"1\" targetX=\"1\" kernelMatrix=\"0 250 0 250 %s 250 0 250 0 \" order=\"3 3\" result=\"convolve\" />\n"
277 "<feComposite in=\"convolve\" in2=\"convolve\" k1=\"1\" k2=\"1\" operator=\"arithmetic\" result=\"composite1\" />\n"
278 "<feColorMatrix in=\"composite1\" values=\"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.2125 -0.7154 -0.0721 1 0 \" result=\"color1\" />\n"
279 "<feColorMatrix in=\"color1\" values=\"1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 %s %s \" result=\"color2\" />\n"
280 "<feComposite in=\"color2\" in2=\"color2\" operator=\"arithmetic\" k2=\"%s\" result=\"composite2\" />\n"
281 "<feGaussianBlur in=\"composite2\" stdDeviation=\"%s 0.01\" result=\"blur1\" />\n"
282 "<feGaussianBlur in=\"composite2\" stdDeviation=\"0.01 %s\" result=\"blur2\" />\n"
283 "<feComposite in=\"blur2\" in2=\"blur1\" k3=\"1\" k2=\"1\" operator=\"arithmetic\" result=\"composite3\" />\n"
284 "<feFlood flood-color=\"rgb(255,255,255)\" flood-opacity=\"1\" result=\"flood\" />\n"
285 "<feBlend in=\"flood\" in2=\"composite3\" blend=\"normal\" mode=\"multiply\" result=\"blend\" />\n"
286 "<feComposite in=\"%s\" in2=\"SourceGraphic\" operator=\"in\" result=\"composite4\" />\n"
287 "</filter>\n", clean.str().c_str(), dilat.str().c_str(), erosion.str().c_str(), strength.str().c_str(), length.str().c_str(), length.str().c_str(), trans.str().c_str());
289 return _filter;
290 }; /* CrossEngraving filter */
292 /**
293 \brief Custom predefined Drawing filter.
295 Convert images to duochrome drawings.
297 Filter's parameters:
298 * Simplification strength (0.01->20, default 0.6) -> blur1 (stdDeviation)
299 * Clean-up (1->500, default 10) -> convolve1 (kernelMatrix, central value -1001->-1500, default -1010)
300 * Erase (0.->6., default 0) -> composite1 (k4)
301 * Smoothness strength (0.01->20, default 0.6) -> blur2 (stdDeviation)
302 * Dilatation (1.->50., default 6) -> color2 (n-1th value)
303 * Erosion (0.->50., default 3) -> color2 (nth value 0->-50)
304 * Transluscent (boolean, default false) -> composite 8 (in, true->merge1, false->composite7)
306 * Blur strength (0.01->20., default 1.) -> blur3 (stdDeviation)
307 * Blur dilatation (1.->50., default 6) -> color4 (n-1th value)
308 * Blur erosion (0.->50., default 3) -> color4 (nth value 0->-50)
310 * Stroke color (guint, default 64,64,64,255) -> flood2 (flood-color), composite3 (k2)
311 * Image on stroke (boolean, default false) -> composite2 (in="flood2" true-> in="SourceGraphic")
312 * Offset (-100->100, default 0) -> offset (val)
314 * Fill color (guint, default 200,200,200,255) -> flood3 (flood-opacity), composite5 (k2)
315 * Image on fill (boolean, default false) -> composite4 (in="flood3" true-> in="SourceGraphic")
317 */
319 class Drawing : public Inkscape::Extension::Internal::Filter::Filter {
320 protected:
321 virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
323 public:
324 Drawing ( ) : Filter() { };
325 virtual ~Drawing ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
327 static void init (void) {
328 Inkscape::Extension::build_from_mem(
329 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
330 "<name>" N_("Drawing, custom") "</name>\n"
331 "<id>org.inkscape.effect.filter.Drawing</id>\n"
332 "<param name=\"tab\" type=\"notebook\">\n"
333 "<page name=\"optionstab\" _gui-text=\"Options\">\n"
334 "<_param name=\"simplifyheader\" type=\"groupheader\">Simplify</_param>\n"
335 "<param name=\"simply\" gui-text=\"" N_("Strength:") "\" type=\"float\" min=\"0.01\" max=\"20\">0.6</param>\n"
336 "<param name=\"clean\" gui-text=\"" N_("Clean-up:") "\" type=\"int\" min=\"1\" max=\"500\">10</param>\n"
337 "<param name=\"erase\" gui-text=\"" N_("Erase:") "\" type=\"float\" min=\"0\" max=\"60\">0</param>\n"
338 "<param name=\"transluscent\" gui-text=\"" N_("Transluscent") "\" type=\"boolean\" >false</param>\n"
339 "<_param name=\"smoothheader\" type=\"groupheader\">Smoothness</_param>\n"
340 "<param name=\"smooth\" gui-text=\"" N_("Strength:") "\" type=\"float\" min=\"0.01\" max=\"20\">0.6</param>\n"
341 "<param name=\"dilat\" gui-text=\"" N_("Dilatation:") "\" type=\"float\" min=\"1\" max=\"50\">6</param>\n"
342 "<param name=\"erosion\" gui-text=\"" N_("Erosion:") "\" type=\"float\" min=\"0\" max=\"50\">3</param>\n"
343 "<_param name=\"meltheader\" type=\"groupheader\">Melt</_param>\n"
344 "<param name=\"blur\" gui-text=\"" N_("Level:") "\" type=\"float\" min=\"0.01\" max=\"20\">1</param>\n"
345 "<param name=\"bdilat\" gui-text=\"" N_("Dilatation:") "\" type=\"float\" min=\"1\" max=\"50\">6</param>\n"
346 "<param name=\"berosion\" gui-text=\"" N_("Erosion:") "\" type=\"float\" min=\"0\" max=\"50\">3</param>\n"
347 "</page>\n"
348 "<page name=\"co11tab\" _gui-text=\"Fill color\">\n"
349 "<param name=\"fcolor\" gui-text=\"" N_("Fill color") "\" type=\"color\">-1515870721</param>\n"
350 "<param name=\"iof\" gui-text=\"" N_("Image on fill") "\" type=\"boolean\" >false</param>\n"
351 "</page>\n"
352 "<page name=\"co12tab\" _gui-text=\"Stroke color\">\n"
353 "<param name=\"scolor\" gui-text=\"" N_("Stroke color") "\" type=\"color\">589505535</param>\n"
354 "<param name=\"ios\" gui-text=\"" N_("Image on stroke") "\" type=\"boolean\" >false</param>\n"
355 "<param name=\"offset\" gui-text=\"" N_("Offset:") "\" type=\"int\" min=\"-100\" max=\"100\">0</param>\n"
356 "</page>\n"
357 "</param>\n"
358 "<effect>\n"
359 "<object-type>all</object-type>\n"
360 "<effects-menu>\n"
361 "<submenu name=\"" N_("Filters") "\">\n"
362 "<submenu name=\"" N_("Experimental") "\"/>\n"
363 "</submenu>\n"
364 "</effects-menu>\n"
365 "<menu-tip>" N_("Convert images to duochrome drawings") "</menu-tip>\n"
366 "</effect>\n"
367 "</inkscape-extension>\n", new Drawing());
368 };
369 };
371 gchar const *
372 Drawing::get_filter_text (Inkscape::Extension::Extension * ext)
373 {
374 if (_filter != NULL) g_free((void *)_filter);
376 std::ostringstream simply;
377 std::ostringstream clean;
378 std::ostringstream erase;
379 std::ostringstream smooth;
380 std::ostringstream dilat;
381 std::ostringstream erosion;
382 std::ostringstream transluscent;
383 std::ostringstream offset;
384 std::ostringstream blur;
385 std::ostringstream bdilat;
386 std::ostringstream berosion;
387 std::ostringstream strokea;
388 std::ostringstream stroker;
389 std::ostringstream strokeg;
390 std::ostringstream strokeb;
391 std::ostringstream ios;
392 std::ostringstream filla;
393 std::ostringstream fillr;
394 std::ostringstream fillg;
395 std::ostringstream fillb;
396 std::ostringstream iof;
398 simply << ext->get_param_float("simply");
399 clean << (-1000 - ext->get_param_int("clean"));
400 erase << (ext->get_param_float("erase") / 10);
401 smooth << ext->get_param_float("smooth");
402 dilat << ext->get_param_float("dilat");
403 erosion << (- ext->get_param_float("erosion"));
404 if (ext->get_param_bool("transluscent"))
405 transluscent << "merge1";
406 else
407 transluscent << "composite7";
408 offset << ext->get_param_int("offset");
410 blur << ext->get_param_float("blur");
411 bdilat << ext->get_param_float("bdilat");
412 berosion << (- ext->get_param_float("berosion"));
414 guint32 fcolor = ext->get_param_color("fcolor");
415 fillr << ((fcolor >> 24) & 0xff);
416 fillg << ((fcolor >> 16) & 0xff);
417 fillb << ((fcolor >> 8) & 0xff);
418 filla << (fcolor & 0xff) / 255.0F;
419 if (ext->get_param_bool("iof"))
420 iof << "SourceGraphic";
421 else
422 iof << "flood3";
424 guint32 scolor = ext->get_param_color("scolor");
425 stroker << ((scolor >> 24) & 0xff);
426 strokeg << ((scolor >> 16) & 0xff);
427 strokeb << ((scolor >> 8) & 0xff);
428 strokea << (scolor & 0xff) / 255.0F;
429 if (ext->get_param_bool("ios"))
430 ios << "SourceGraphic";
431 else
432 ios << "flood2";
434 _filter = g_strdup_printf(
435 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" color-interpolation-filters=\"sRGB\" height=\"1\" width=\"1\" y=\"0\" x=\"0\" inkscape:label=\"Drawing, custom\">\n"
436 "<feGaussianBlur in=\"SourceGraphic\" stdDeviation=\"%s\" result=\"blur1\" />\n"
437 "<feConvolveMatrix in=\"blur1\" targetX=\"1\" targetY=\"1\" order=\"3 3\" kernelMatrix=\"0 250 0 250 %s 250 0 250 0 \" result=\"convolve1\" />\n"
438 "<feComposite in=\"convolve1\" in2=\"convolve1\" k1=\"1\" k2=\"1\" k4=\"%s\" operator=\"arithmetic\" stdDeviation=\"1\" result=\"composite1\" />\n"
439 "<feColorMatrix in=\"composite1\" values=\"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.2125 -0.7154 -0.0721 1 0 \" result=\"color1\" />\n"
440 "<feGaussianBlur stdDeviation=\"%s\" result=\"blur2\" />\n"
441 "<feColorMatrix values=\"1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 %s %s \" result=\"color2\" />\n"
442 "<feFlood flood-color=\"rgb(255,255,255)\" result=\"flood1\" />\n"
443 "<feBlend in2=\"color2\" mode=\"multiply\" blend=\"normal\" result=\"blend1\" />\n"
444 "<feComponentTransfer in=\"blend1\" stdDeviation=\"2\" result=\"component1\">\n"
445 "<feFuncR type=\"discrete\" tableValues=\"0 1 1 1\" />\n"
446 "<feFuncG type=\"discrete\" tableValues=\"0 1 1 1\" />\n"
447 "<feFuncB type=\"discrete\" tableValues=\"0 1 1 1\" />\n"
448 "</feComponentTransfer>\n"
449 "<feGaussianBlur stdDeviation=\"%s\" result=\"blur3\" />\n"
450 "<feColorMatrix in=\"blur3\" values=\"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.2125 -0.7154 -0.0721 1 0 \" stdDeviation=\"1\" result=\"color3\" />\n"
451 "<feColorMatrix values=\"1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 %s %s \" result=\"color4\" />\n"
452 "<feFlood flood-color=\"rgb(%s,%s,%s)\" result=\"flood2\" />\n"
453 "<feComposite in=\"%s\" in2=\"color4\" operator=\"in\" result=\"composite2\" />\n"
454 "<feComposite in=\"composite2\" in2=\"composite2\" operator=\"arithmetic\" k2=\"%s\" result=\"composite3\" />\n"
455 "<feOffset dx=\"%s\" dy=\"%s\" result=\"offset1\" />\n"
456 "<feFlood in=\"color4\" flood-color=\"rgb(%s,%s,%s)\" result=\"flood3\" />\n"
457 "<feComposite in=\"%s\" in2=\"color4\" operator=\"out\" result=\"composite4\" />\n"
458 "<feComposite in=\"composite4\" in2=\"composite4\" operator=\"arithmetic\" k2=\"%s\" result=\"composite5\" />\n"
459 "<feMerge result=\"merge1\">\n"
460 "<feMergeNode in=\"composite5\" />\n"
461 "<feMergeNode in=\"offset1\" />\n"
462 "</feMerge>\n"
463 "<feComposite in=\"merge1\" in2=\"merge1\" operator=\"over\" result=\"composite6\" />\n"
464 "<feComposite in=\"composite6\" in2=\"composite6\" operator=\"over\" result=\"composite7\" />\n"
465 "<feComposite in=\"%s\" in2=\"SourceGraphic\" operator=\"in\" result=\"composite8\" />\n"
466 "</filter>\n", simply.str().c_str(), clean.str().c_str(), erase.str().c_str(), smooth.str().c_str(), dilat.str().c_str(), erosion.str().c_str(), blur.str().c_str(), bdilat.str().c_str(), berosion.str().c_str(), stroker.str().c_str(), strokeg.str().c_str(), strokeb.str().c_str(), ios.str().c_str(), strokea.str().c_str(), offset.str().c_str(), offset.str().c_str(), fillr.str().c_str(), fillg.str().c_str(), fillb.str().c_str(), iof.str().c_str(), filla.str().c_str(), transluscent.str().c_str());
468 return _filter;
469 }; /* Drawing filter */
472 /**
473 \brief Custom predefined Neon draw filter.
475 Posterize and draw smooth lines around color shapes
477 Filter's parameters:
478 * Lines type (enum, default smooth) ->
479 smooth = component1 (type="table"), component2 (type="table"), composite1 (in2="blur2")
480 hard = component1 (type="discrete"), component2 (type="discrete"), composite1 (in2="component1")
481 * Simplify (0.01->20., default 1.5) -> blur1 (stdDeviation)
482 * Line width (0.01->20., default 1.5) -> blur2 (stdDeviation)
483 * Lightness (0.->10., default 5) -> composite1 (k3)
484 * Blend (enum [normal, multiply, screen], default normal) -> blend (mode)
485 * Dark mode (boolean, default false) -> composite1 (true: in2="component2")
486 */
487 class NeonDraw : public Inkscape::Extension::Internal::Filter::Filter {
488 protected:
489 virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
491 public:
492 NeonDraw ( ) : Filter() { };
493 virtual ~NeonDraw ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
495 static void init (void) {
496 Inkscape::Extension::build_from_mem(
497 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
498 "<name>" N_("Neon draw, custom") "</name>\n"
499 "<id>org.inkscape.effect.filter.NeonDraw</id>\n"
500 "<param name=\"type\" gui-text=\"" N_("Line type:") "\" type=\"enum\">\n"
501 "<_item value=\"table\">Smoothed</_item>\n"
502 "<_item value=\"discrete\">Contrasted</_item>\n"
503 "</param>\n"
504 "<param name=\"simply\" gui-text=\"" N_("Simplify:") "\" type=\"float\" min=\"0.01\" max=\"20.0\">1.5</param>\n"
505 "<param name=\"width\" gui-text=\"" N_("Line width:") "\" type=\"float\" min=\"0.01\" max=\"20.0\">1.5</param>\n"
506 "<param name=\"lightness\" gui-text=\"" N_("Lightness:") "\" type=\"float\" min=\"0.\" max=\"10.0\">5</param>\n"
507 "<param name=\"blend\" gui-text=\"" N_("Blend mode:") "\" type=\"enum\">\n"
508 "<_item value=\"normal\">Normal</_item>\n"
509 "<_item value=\"multiply\">Multiply</_item>\n"
510 "<_item value=\"screen\">Screen</_item>\n"
511 "</param>\n"
512 "<param name=\"dark\" gui-text=\"" N_("Dark mode") "\" type=\"boolean\" >false</param>\n"
513 "<effect>\n"
514 "<object-type>all</object-type>\n"
515 "<effects-menu>\n"
516 "<submenu name=\"" N_("Filters") "\">\n"
517 "<submenu name=\"" N_("Experimental") "\"/>\n"
518 "</submenu>\n"
519 "</effects-menu>\n"
520 "<menu-tip>" N_("Posterize and draw smooth lines around color shapes") "</menu-tip>\n"
521 "</effect>\n"
522 "</inkscape-extension>\n", new NeonDraw());
523 };
524 };
526 gchar const *
527 NeonDraw::get_filter_text (Inkscape::Extension::Extension * ext)
528 {
529 if (_filter != NULL) g_free((void *)_filter);
531 std::ostringstream blend;
532 std::ostringstream simply;
533 std::ostringstream width;
534 std::ostringstream lightness;
535 std::ostringstream type;
536 std::ostringstream dark;
538 type << ext->get_param_enum("type");
539 blend << ext->get_param_enum("blend");
540 simply << ext->get_param_float("simply");
541 width << ext->get_param_float("width");
542 lightness << ext->get_param_float("lightness");
544 const gchar *typestr = ext->get_param_enum("type");
545 if (ext->get_param_bool("dark"))
546 dark << "component2";
547 else if ((g_ascii_strcasecmp("table", typestr) == 0))
548 dark << "blur2";
549 else
550 dark << "component1";
552 _filter = g_strdup_printf(
553 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" color-interpolation-filters=\"sRGB\" height=\"1\" width=\"1\" y=\"0\" x=\"0\" inkscape:label=\"Neon draw, custom\">\n"
554 "<feBlend blend=\"normal\" mode=\"%s\" result=\"blend\" />\n"
555 "<feGaussianBlur in=\"blend\" stdDeviation=\"%s\" result=\"blur1\" />\n"
556 "<feComponentTransfer result=\"component1\">\n"
557 "<feFuncR type=\"discrete\" tableValues=\"0 0.3 0.6 1 1\" />\n"
558 "<feFuncG type=\"discrete\" tableValues=\"0 0.3 0.6 1 1\" />\n"
559 "<feFuncB type=\"discrete\" tableValues=\"0 0.3 0.6 1 1\" />\n"
560 "</feComponentTransfer>\n"
561 "<feGaussianBlur in=\"component1\" stdDeviation=\"%s\" result=\"blur2\" />\n"
562 "<feComponentTransfer in=\"blur2\" result=\"component2\">\n"
563 "<feFuncR type=\"%s\" tableValues=\"0 1 0 1 0 1 0 1\" />\n"
564 "<feFuncG type=\"%s\" tableValues=\"0 1 0 1 0 1 0 1\" />\n"
565 "<feFuncB type=\"%s\" tableValues=\"0 1 0 1 0 1 0 1\" />\n"
566 "</feComponentTransfer>\n"
567 "<feComposite in=\"component2\" in2=\"%s\" k3=\"%s\" operator=\"arithmetic\" k2=\"1\" result=\"composite1\" />\n"
568 "<feComposite in=\"composite1\" in2=\"SourceGraphic\" operator=\"in\" result=\"composite2\" />\n"
569 "</filter>\n", blend.str().c_str(), simply.str().c_str(), width.str().c_str(), type.str().c_str(), type.str().c_str(), type.str().c_str(), dark.str().c_str(), lightness.str().c_str());
571 return _filter;
572 }; /* NeonDraw filter */
574 /**
575 \brief Custom predefined Poster paint filter.
577 Poster and painting effects.
579 Filter's parameters:
580 * Effect type (enum, default "Normal") ->
581 Normal = feComponentTransfer
582 Dented = Normal + intermediate values
583 * Transfer type (enum, default "descrete") -> component (type)
584 * Levels (1->15, default 5) -> component (tableValues)
585 * Blend mode (enum, default "Lighten") -> blend (mode)
586 * Primary blur (0.01->100., default 4.) -> blur1 (stdDeviation)
587 * Secondary blur (0.01->100., default 0.5) -> blur2 (stdDeviation)
588 * Pre-saturation (0.->1., default 1.) -> color1 (values)
589 * Post-saturation (0.->1., default 1.) -> color2 (values)
590 * Simulate antialiasing (boolean, default false) -> blur3 (true->stdDeviation=0.5, false->stdDeviation=0.01)
591 */
592 class Posterize : public Inkscape::Extension::Internal::Filter::Filter {
593 protected:
594 virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
596 public:
597 Posterize ( ) : Filter() { };
598 virtual ~Posterize ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
600 static void init (void) {
601 Inkscape::Extension::build_from_mem(
602 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
603 "<name>" N_("Poster paint, custom") "</name>\n"
604 "<id>org.inkscape.effect.filter.Posterize</id>\n"
605 "<param name=\"type\" gui-text=\"" N_("Effect type:") "\" type=\"enum\">\n"
606 "<_item value=\"normal\">Normal</_item>\n"
607 "<_item value=\"dented\">Dented</_item>\n"
608 "</param>\n"
609 "<param name=\"table\" gui-text=\"" N_("Transfer type:") "\" type=\"enum\">\n"
610 "<_item value=\"discrete\">Poster</_item>\n"
611 "<_item value=\"table\">Painting</_item>\n"
612 "</param>\n"
613 "<param name=\"levels\" gui-text=\"" N_("Levels:") "\" type=\"int\" min=\"1\" max=\"15\">5</param>\n"
614 "<param name=\"blend\" gui-text=\"" N_("Blend mode:") "\" type=\"enum\">\n"
615 "<_item value=\"lighten\">Lighten</_item>\n"
616 "<_item value=\"normal\">Normal</_item>\n"
617 "<_item value=\"darken\">Darken</_item>\n"
618 "</param>\n"
619 "<param name=\"blur1\" gui-text=\"" N_("Primary blur:") "\" type=\"float\" min=\"0.01\" max=\"100.0\">4.0</param>\n"
620 "<param name=\"blur2\" gui-text=\"" N_("Secondary blur:") "\" type=\"float\" min=\"0.01\" max=\"100.0\">0.5</param>\n"
621 "<param name=\"presaturation\" gui-text=\"" N_("Pre-saturation:") "\" type=\"float\" min=\"0.00\" max=\"1.00\">1.00</param>\n"
622 "<param name=\"postsaturation\" gui-text=\"" N_("Post-saturation:") "\" type=\"float\" min=\"0.00\" max=\"1.00\">1.00</param>\n"
623 "<param name=\"antialiasing\" gui-text=\"" N_("Simulate antialiasing") "\" type=\"boolean\">false</param>\n"
624 "<effect>\n"
625 "<object-type>all</object-type>\n"
626 "<effects-menu>\n"
627 "<submenu name=\"" N_("Filters") "\">\n"
628 "<submenu name=\"" N_("Experimental") "\"/>\n"
629 "</submenu>\n"
630 "</effects-menu>\n"
631 "<menu-tip>" N_("Poster and painting effects") "</menu-tip>\n"
632 "</effect>\n"
633 "</inkscape-extension>\n", new Posterize());
634 };
635 };
637 gchar const *
638 Posterize::get_filter_text (Inkscape::Extension::Extension * ext)
639 {
640 if (_filter != NULL) g_free((void *)_filter);
642 std::ostringstream table;
643 std::ostringstream blendmode;
644 std::ostringstream blur1;
645 std::ostringstream blur2;
646 std::ostringstream presat;
647 std::ostringstream postsat;
648 std::ostringstream transf;
649 std::ostringstream antialias;
651 table << ext->get_param_enum("table");
652 blendmode << ext->get_param_enum("blend");
653 blur1 << ext->get_param_float("blur1");
654 blur2 << ext->get_param_float("blur2");
655 presat << ext->get_param_float("presaturation");
656 postsat << ext->get_param_float("postsaturation");
658 // TransfertComponent table values are calculated based on the poster type.
659 transf << "0";
660 int levels = ext->get_param_int("levels") + 1;
661 const gchar *effecttype = ext->get_param_enum("type");
662 float val = 0.0;
663 for ( int step = 1 ; step <= levels ; step++ ) {
664 val = (float) step / levels;
665 transf << " " << val;
666 if((g_ascii_strcasecmp("dented", effecttype) == 0)) {
667 transf << " " << (val - ((float) 1 / (3 * levels))) << " " << (val + ((float) 1 / (2 * levels)));
668 }
669 }
670 transf << " 1";
672 if (ext->get_param_bool("antialiasing"))
673 antialias << "0.5";
674 else
675 antialias << "0.01";
677 _filter = g_strdup_printf(
678 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" color-interpolation-filters=\"sRGB\" height=\"1\" width=\"1\" y=\"0\" x=\"0\" inkscape:label=\"Poster paint, custom\">\n"
679 "<feComposite operator=\"arithmetic\" k2=\"1\" result=\"composite1\" />\n"
680 "<feGaussianBlur stdDeviation=\"%s\" result=\"blur1\" />\n"
681 "<feGaussianBlur in=\"composite1\" stdDeviation=\"%s\" result=\"blur2\" />\n"
682 "<feBlend in2=\"blur1\" mode=\"%s\" result=\"blend\"/>\n"
683 "<feColorMatrix type=\"saturate\" values=\"%s\" result=\"color1\" />\n"
684 "<feComponentTransfer result=\"component\">\n"
685 "<feFuncR type=\"%s\" tableValues=\"%s\" />\n"
686 "<feFuncG type=\"%s\" tableValues=\"%s\" />\n"
687 "<feFuncB type=\"%s\" tableValues=\"%s\" />\n"
688 "</feComponentTransfer>\n"
689 "<feColorMatrix type=\"saturate\" values=\"%s\" result=\"color2\" />\n"
690 "<feGaussianBlur stdDeviation=\"%s\" result=\"blur3\" />\n"
691 "<feComposite in2=\"SourceGraphic\" operator=\"in\" result=\"composite3\" />\n"
692 "</filter>\n", blur1.str().c_str(), blur2.str().c_str(), blendmode.str().c_str(), presat.str().c_str(), table.str().c_str(), transf.str().c_str(), table.str().c_str(), transf.str().c_str(), table.str().c_str(), transf.str().c_str(), postsat.str().c_str(), antialias.str().c_str());
694 return _filter;
695 }; /* Posterize filter */
697 /**
698 \brief Custom predefined Posterize basic filter.
700 Simple posterizing effect
702 Filter's parameters:
703 * Levels (1->20, default 5) -> component1 (tableValues)
704 * Blur (0.01->20., default 4.) -> blur1 (stdDeviation)
705 */
706 class PosterizeBasic : public Inkscape::Extension::Internal::Filter::Filter {
707 protected:
708 virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
710 public:
711 PosterizeBasic ( ) : Filter() { };
712 virtual ~PosterizeBasic ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
714 static void init (void) {
715 Inkscape::Extension::build_from_mem(
716 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
717 "<name>" N_("Posterize basic, custom") "</name>\n"
718 "<id>org.inkscape.effect.filter.PosterizeBasic</id>\n"
719 "<param name=\"levels\" gui-text=\"" N_("Levels:") "\" type=\"int\" min=\"1\" max=\"20\">5</param>\n"
720 "<param name=\"blur\" gui-text=\"" N_("Blur:") "\" type=\"float\" min=\"0.01\" max=\"20.0\">4.0</param>\n"
721 "<effect>\n"
722 "<object-type>all</object-type>\n"
723 "<effects-menu>\n"
724 "<submenu name=\"" N_("Filters") "\">\n"
725 "<submenu name=\"" N_("Experimental") "\"/>\n"
726 "</submenu>\n"
727 "</effects-menu>\n"
728 "<menu-tip>" N_("Simple posterizing effect") "</menu-tip>\n"
729 "</effect>\n"
730 "</inkscape-extension>\n", new PosterizeBasic());
731 };
732 };
734 gchar const *
735 PosterizeBasic::get_filter_text (Inkscape::Extension::Extension * ext)
736 {
737 if (_filter != NULL) g_free((void *)_filter);
739 std::ostringstream blur;
740 std::ostringstream transf;
742 blur << ext->get_param_float("blur");
744 transf << "0";
745 int levels = ext->get_param_int("levels") + 1;
746 float val = 0.0;
747 for ( int step = 1 ; step <= levels ; step++ ) {
748 val = (float) step / levels;
749 transf << " " << val;
750 }
751 transf << " 1";
753 _filter = g_strdup_printf(
754 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" color-interpolation-filters=\"sRGB\" height=\"1\" width=\"1\" y=\"0\" x=\"0\" inkscape:label=\"Posterize basic, custom\">\n"
755 "<feGaussianBlur stdDeviation=\"%s\" result=\"blur1\" />\n"
756 "<feComponentTransfer stdDeviation=\"2\" in=\"blur1\" result=\"component1\">\n"
757 "<feFuncR type=\"discrete\" tableValues=\"%s\" />\n"
758 "<feFuncG type=\"discrete\" tableValues=\"%s\" />\n"
759 "<feFuncB type=\"discrete\" tableValues=\"%s\" />\n"
760 "</feComponentTransfer>\n"
761 "<feComposite in=\"component1\" in2=\"SourceGraphic\" operator=\"in\" />\n"
762 "</filter>\n", blur.str().c_str(), transf.str().c_str(), transf.str().c_str(), transf.str().c_str());
764 return _filter;
765 }; /* PosterizeBasic filter */
767 }; /* namespace Filter */
768 }; /* namespace Internal */
769 }; /* namespace Extension */
770 }; /* namespace Inkscape */
772 /* Change the 'EXPERIMENTAL' below to be your file name */
773 #endif /* __INKSCAPE_EXTENSION_INTERNAL_FILTER_EXPERIMENTAL_H__ */