Inkscape
Vector Graphics Editor
paint.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2#ifndef SEEN_INKSCAPE_EXTENSION_INTERNAL_FILTER_PAINT_H__
3#define SEEN_INKSCAPE_EXTENSION_INTERNAL_FILTER_PAINT_H__
4/* Change the 'PAINT' above to be your file name */
5
6/*
7 * Copyright (C) 2012 Authors:
8 * Ivan Louette (filters)
9 * Nicolas Dufour (UI) <nicoduf@yahoo.fr>
10 *
11 * Image paint and draw filters
12 * Chromolitho
13 * Cross engraving
14 * Drawing
15 * Electrize
16 * Neon draw
17 * Point engraving
18 * Posterize
19 * Posterize basic
20 *
21 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
22 */
23/* ^^^ Change the copyright to be you and your e-mail address ^^^ */
24
25#include "filter.h"
26
28#include "extension/system.h"
29#include "extension/extension.h"
30
31namespace Inkscape {
32namespace Extension {
33namespace Internal {
34namespace Filter {
35
62protected:
63 gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override;
64
65public:
66 Chromolitho ( ) : Filter() { };
67 ~Chromolitho ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; }
68
69 static void init () {
70 // clang-format off
72 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
73 "<name>" N_("Chromolitho") "</name>\n"
74 "<id>org.inkscape.effect.filter.Chromolitho</id>\n"
75 "<param name=\"tab\" type=\"notebook\">\n"
76 "<page name=\"optionstab\" gui-text=\"Options\">\n"
77 "<param name=\"drawing\" gui-text=\"" N_("Drawing mode") "\" type=\"bool\" >true</param>\n"
78 "<param name=\"dblend\" gui-text=\"" N_("Drawing blend:") "\" type=\"optiongroup\" appearance=\"combo\">\n"
79 "<option value=\"darken\">Darken</option>\n"
80 "<option value=\"normal\">Normal</option>\n"
81 "<option value=\"multiply\">Multiply</option>\n"
82 "<option value=\"screen\">Screen</option>\n"
83 "<option value=\"lighten\">Lighten</option>\n"
84 "</param>\n"
85 "<param name=\"transparent\" gui-text=\"" N_("Transparent") "\" type=\"bool\" >false</param>\n"
86 "<param name=\"dented\" gui-text=\"" N_("Dented") "\" type=\"bool\" >false</param>\n"
87 "<param name=\"inverted\" gui-text=\"" N_("Inverted") "\" type=\"bool\" >false</param>\n"
88 "<param name=\"light\" gui-text=\"" N_("Lightness") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0\" max=\"10\">0</param>\n"
89 "<param name=\"saturation\" gui-text=\"" N_("Saturation") "\" type=\"float\" precision=\"2\" appearance=\"full\" min=\"0\" max=\"1\">1</param>\n"
90 "<param name=\"noise\" gui-text=\"" N_("Noise reduction") "\" type=\"int\" appearance=\"full\" min=\"1\" max=\"1000\">10</param>\n"
91 "<param name=\"smooth\" gui-text=\"" N_("Smoothness") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0.01\" max=\"10.00\">1</param>\n"
92 "</page>\n"
93 "<page name=\"graintab\" gui-text=\"" N_("Grain") "\">\n"
94 "<param name=\"grain\" gui-text=\"" N_("Grain mode") "\" type=\"bool\" >true</param>\n"
95 "<param name=\"grainxf\" gui-text=\"" N_("Horizontal frequency") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0\" max=\"1000\">1000</param>\n"
96 "<param name=\"grainyf\" gui-text=\"" N_("Vertical frequency") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0\" max=\"1000\">1000</param>\n"
97 "<param name=\"grainc\" gui-text=\"" N_("Complexity") "\" type=\"int\" appearance=\"full\" min=\"1\" max=\"5\">1</param>\n"
98 "<param name=\"grainv\" gui-text=\"" N_("Variation") "\" type=\"int\" appearance=\"full\" min=\"0\" max=\"1000\">0</param>\n"
99 "<param name=\"grainexp\" gui-text=\"" N_("Expansion") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"1\" max=\"50\">1</param>\n"
100 "<param name=\"grainero\" gui-text=\"" N_("Erosion") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0\" max=\"40\">0</param>\n"
101 "<param name=\"graincol\" gui-text=\"" N_("Color") "\" type=\"bool\" >true</param>\n"
102 "<param name=\"gblend\" gui-text=\"" N_("Grain blend:") "\" type=\"optiongroup\" appearance=\"combo\">\n"
103 "<option value=\"normal\">Normal</option>\n"
104 "<option value=\"multiply\">Multiply</option>\n"
105 "<option value=\"screen\">Screen</option>\n"
106 "<option value=\"lighten\">Lighten</option>\n"
107 "<option value=\"darken\">Darken</option>\n"
108 "</param>\n"
109 "</page>\n"
110 "</param>\n"
111 "<effect>\n"
112 "<object-type>all</object-type>\n"
113 "<effects-menu>\n"
114 "<submenu name=\"" N_("Filters") "\">\n"
115 "<submenu name=\"" N_("Image Paint and Draw") "\"/>\n"
116 "</submenu>\n"
117 "</effects-menu>\n"
118 "<menu-tip>" N_("Chromo effect with customizable edge drawing and graininess") "</menu-tip>\n"
119 "</effect>\n"
120 "</inkscape-extension>\n", std::make_unique<Chromolitho>());
121 // clang-format on
122 };
123};
124
125gchar const *
127{
128 if (_filter != nullptr) g_free((void *)_filter);
129
130 std::ostringstream b1in;
131 std::ostringstream b2in;
132 std::ostringstream col3in;
133 std::ostringstream transf;
134 std::ostringstream light;
135 std::ostringstream saturation;
136 std::ostringstream noise;
137 std::ostringstream dblend;
138 std::ostringstream smooth;
139 std::ostringstream grainxf;
140 std::ostringstream grainyf;
141 std::ostringstream grainc;
142 std::ostringstream grainv;
143 std::ostringstream gblend;
144 std::ostringstream grainexp;
145 std::ostringstream grainero;
146 std::ostringstream graincol;
147
148 if (ext->get_param_bool("drawing"))
149 b1in << "convolve1";
150 else
151 b1in << "composite1";
152
153 if (ext->get_param_bool("transparent"))
154 col3in << "colormatrix4";
155 else
156 col3in << "component1";
157 light << ext->get_param_float("light");
158 saturation << ext->get_param_float("saturation");
159 noise << (-1000 - ext->get_param_int("noise"));
160 dblend << ext->get_param_optiongroup("dblend");
161 smooth << ext->get_param_float("smooth");
162
163 if (ext->get_param_bool("dented")) {
164 transf << "0 1 0 1";
165 } else {
166 transf << "0 1 1";
167 }
168 if (ext->get_param_bool("inverted"))
169 transf << " 0";
170
171 if (ext->get_param_bool("grain"))
172 b2in << "colormatrix2";
173 else
174 b2in << "blur1";
175 grainxf << (ext->get_param_float("grainxf") / 1000);
176 grainyf << (ext->get_param_float("grainyf") / 1000);
177 grainc << ext->get_param_int("grainc");
178 grainv << ext->get_param_int("grainv");
179 gblend << ext->get_param_optiongroup("gblend");
180 grainexp << ext->get_param_float("grainexp");
181 grainero << (-ext->get_param_float("grainero"));
182 if (ext->get_param_bool("graincol"))
183 graincol << "1";
184 else
185 graincol << "0";
186
187 // clang-format off
188 _filter = g_strdup_printf(
189 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" style=\"color-interpolation-filters:sRGB;\" inkscape:label=\"Chromolitho\">\n"
190 "<feComposite in=\"SourceGraphic\" in2=\"SourceGraphic\" operator=\"arithmetic\" k1=\"%s\" k2=\"1\" result=\"composite1\" />\n"
191 "<feConvolveMatrix in=\"composite1\" kernelMatrix=\"0 250 0 250 %s 250 0 250 0 \" order=\"3 3\" result=\"convolve1\" />\n"
192 "<feBlend in=\"%s\" in2=\"composite1\" mode=\"%s\" result=\"blend1\" />\n"
193 "<feGaussianBlur in=\"blend1\" stdDeviation=\"%s\" result=\"blur1\" />\n"
194 "<feTurbulence baseFrequency=\"%s %s\" numOctaves=\"%s\" seed=\"%s\" type=\"fractalNoise\" result=\"turbulence1\" />\n"
195 "<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"
196 "<feColorMatrix type=\"saturate\" values=\"%s\" result=\"colormatrix2\" />\n"
197 "<feBlend in=\"%s\" in2=\"blur1\" mode=\"%s\" result=\"blend2\" />\n"
198 "<feColorMatrix in=\"blend2\" type=\"saturate\" values=\"%s\" result=\"colormatrix3\" />\n"
199 "<feComponentTransfer in=\"colormatrix3\" result=\"component1\">\n"
200 "<feFuncR type=\"discrete\" tableValues=\"%s\" />\n"
201 "<feFuncG type=\"discrete\" tableValues=\"%s\" />\n"
202 "<feFuncB type=\"discrete\" tableValues=\"%s\" />\n"
203 "</feComponentTransfer>\n"
204 "<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"
205 "<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"
206 "<feComposite in2=\"SourceGraphic\" operator=\"in\" result=\"composite2\" />\n"
207 "</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());
208 // clang-format on
209
210 return _filter;
211}; /* Chromolitho filter */
212
227protected:
228 gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override;
229
230public:
232 ~CrossEngraving ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; }
233
234 static void init () {
235 // clang-format off
237 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
238 "<name>" N_("Cross Engraving") "</name>\n"
239 "<id>org.inkscape.effect.filter.CrossEngraving</id>\n"
240 "<param name=\"clean\" gui-text=\"" N_("Clean-up") "\" type=\"int\" appearance=\"full\" min=\"1\" max=\"500\">30</param>\n"
241 "<param name=\"dilat\" gui-text=\"" N_("Dilatation") "\" type=\"float\" appearance=\"full\" min=\"1\" max=\"50\">1</param>\n"
242 "<param name=\"erosion\" gui-text=\"" N_("Erosion") "\" type=\"float\" appearance=\"full\" min=\"0\" max=\"50\">0</param>\n"
243 "<param name=\"strength\" gui-text=\"" N_("Strength") "\" type=\"float\" appearance=\"full\" min=\"0.1\" max=\"10\">0.5</param>\n"
244 "<param name=\"length\" gui-text=\"" N_("Length") "\" type=\"float\" appearance=\"full\" min=\"0.5\" max=\"20\">4</param>\n"
245 "<param name=\"trans\" gui-text=\"" N_("Transparent") "\" type=\"bool\" >false</param>\n"
246 "<effect>\n"
247 "<object-type>all</object-type>\n"
248 "<effects-menu>\n"
249 "<submenu name=\"" N_("Filters") "\">\n"
250 "<submenu name=\"" N_("Image Paint and Draw") "\"/>\n"
251 "</submenu>\n"
252 "</effects-menu>\n"
253 "<menu-tip>" N_("Convert image to an engraving made of vertical and horizontal lines") "</menu-tip>\n"
254 "</effect>\n"
255 "</inkscape-extension>\n", std::make_unique<CrossEngraving>());
256 // clang-format on
257 };
258};
259
260gchar const *
262{
263 if (_filter != nullptr) g_free((void *)_filter);
264
265 std::ostringstream clean;
266 std::ostringstream dilat;
267 std::ostringstream erosion;
268 std::ostringstream strength;
269 std::ostringstream length;
270 std::ostringstream trans;
271
272 clean << (-1000 - ext->get_param_int("clean"));
273 dilat << ext->get_param_float("dilat");
274 erosion << (- ext->get_param_float("erosion"));
275 strength << ext->get_param_float("strength");
276 length << ext->get_param_float("length");
277 if (ext->get_param_bool("trans"))
278 trans << "composite3";
279 else
280 trans << "blend";
281
282 // clang-format off
283 _filter = g_strdup_printf(
284 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" style=\"color-interpolation-filters:sRGB;\" inkscape:label=\"Cross Engraving\">\n"
285 "<feConvolveMatrix in=\"SourceGraphic\" targetY=\"1\" targetX=\"1\" kernelMatrix=\"0 250 0 250 %s 250 0 250 0 \" order=\"3 3\" result=\"convolve\" />\n"
286 "<feComposite in=\"convolve\" in2=\"convolve\" k1=\"1\" k2=\"1\" operator=\"arithmetic\" result=\"composite1\" />\n"
287 "<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"
288 "<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"
289 "<feComposite in=\"color2\" in2=\"color2\" operator=\"arithmetic\" k2=\"%s\" result=\"composite2\" />\n"
290 "<feGaussianBlur in=\"composite2\" stdDeviation=\"%s 0.01\" result=\"blur1\" />\n"
291 "<feGaussianBlur in=\"composite2\" stdDeviation=\"0.01 %s\" result=\"blur2\" />\n"
292 "<feComposite in=\"blur2\" in2=\"blur1\" k3=\"1\" k2=\"1\" operator=\"arithmetic\" result=\"composite3\" />\n"
293 "<feFlood flood-color=\"rgb(255,255,255)\" flood-opacity=\"1\" result=\"flood\" />\n"
294 "<feBlend in=\"flood\" in2=\"composite3\" mode=\"multiply\" result=\"blend\" />\n"
295 "<feComposite in=\"%s\" in2=\"SourceGraphic\" operator=\"in\" result=\"composite4\" />\n"
296 "</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());
297 // clang-format on
298
299 return _filter;
300}; /* CrossEngraving filter */
301
330protected:
331 gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override;
332
333public:
334 Drawing ( ) : Filter() { };
335 ~Drawing ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; }
336
337 static void init () {
338 // clang-format off
340 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
341 "<name>" N_("Drawing") "</name>\n"
342 "<id>org.inkscape.effect.filter.Drawing</id>\n"
343 "<param name=\"tab\" type=\"notebook\">\n"
344 "<page name=\"optionstab\" gui-text=\"Options\">\n"
345 "<label appearance=\"header\">" N_("Simplify") "</label>\n"
346 "<param name=\"simply\" gui-text=\"" N_("Strength") "\" type=\"float\" indent=\"1\" appearance=\"full\" precision=\"2\" min=\"0.01\" max=\"20.00\">0.6</param>\n"
347 "<param name=\"clean\" gui-text=\"" N_("Clean-up") "\" type=\"int\" indent=\"1\" appearance=\"full\" min=\"1\" max=\"500\">10</param>\n"
348 "<param name=\"erase\" gui-text=\"" N_("Erase") "\" type=\"float\" indent=\"1\" appearance=\"full\" min=\"0\" max=\"60\">0</param>\n"
349 "<param name=\"translucent\" gui-text=\"" N_("Translucent") "\" indent=\"1\" type=\"bool\" >false</param>\n"
350 "<label appearance=\"header\">" N_("Smoothness") "</label>\n"
351 "<param name=\"smooth\" gui-text=\"" N_("Strength") "\" type=\"float\" indent=\"1\" appearance=\"full\" precision=\"2\" min=\"0.01\" max=\"20.00\">0.6</param>\n"
352 "<param name=\"dilat\" gui-text=\"" N_("Dilatation") "\" type=\"float\" indent=\"1\" appearance=\"full\" min=\"1\" max=\"50\">6</param>\n"
353 "<param name=\"erosion\" gui-text=\"" N_("Erosion") "\" type=\"float\" indent=\"1\" appearance=\"full\" min=\"0\" max=\"50\">2</param>\n"
354 "<label appearance=\"header\">" N_("Melt") "</label>\n"
355 "<param name=\"blur\" gui-text=\"" N_("Level") "\" type=\"float\" indent=\"1\" appearance=\"full\" precision=\"2\" min=\"0.01\" max=\"20.00\">1</param>\n"
356 "<param name=\"bdilat\" gui-text=\"" N_("Dilatation") "\" type=\"float\" indent=\"1\" appearance=\"full\" min=\"1\" max=\"50\">6</param>\n"
357 "<param name=\"berosion\" gui-text=\"" N_("Erosion") "\" type=\"float\" indent=\"1\" appearance=\"full\" min=\"0\" max=\"50\">2</param>\n"
358 "</page>\n"
359 "<page name=\"co11tab\" gui-text=\"Fill color\">\n"
360 "<param name=\"fcolor\" gui-text=\"" N_("Fill color") "\" type=\"color\">-1515870721</param>\n"
361 "<param name=\"iof\" gui-text=\"" N_("Image on fill") "\" type=\"bool\" >false</param>\n"
362 "</page>\n"
363 "<page name=\"co12tab\" gui-text=\"Stroke color\">\n"
364 "<param name=\"scolor\" gui-text=\"" N_("Stroke color") "\" type=\"color\">589505535</param>\n"
365 "<param name=\"ios\" gui-text=\"" N_("Image on stroke") "\" type=\"bool\" >false</param>\n"
366 "<param name=\"offset\" gui-text=\"" N_("Offset") "\" type=\"int\" appearance=\"full\" min=\"-100\" max=\"100\">0</param>\n"
367 "</page>\n"
368 "</param>\n"
369 "<effect>\n"
370 "<object-type>all</object-type>\n"
371 "<effects-menu>\n"
372 "<submenu name=\"" N_("Filters") "\">\n"
373 "<submenu name=\"" N_("Image Paint and Draw") "\"/>\n"
374 "</submenu>\n"
375 "</effects-menu>\n"
376 "<menu-tip>" N_("Convert images to duochrome drawings") "</menu-tip>\n"
377 "</effect>\n"
378 "</inkscape-extension>\n", std::make_unique<Drawing>());
379 // clang-format on
380 };
381};
382
383gchar const *
385{
386 if (_filter != nullptr) g_free((void *)_filter);
387
388 std::ostringstream simply;
389 std::ostringstream clean;
390 std::ostringstream erase;
391 std::ostringstream smooth;
392 std::ostringstream dilat;
393 std::ostringstream erosion;
394 std::ostringstream translucent;
395 std::ostringstream offset;
396 std::ostringstream blur;
397 std::ostringstream bdilat;
398 std::ostringstream berosion;
399 std::ostringstream strokea;
400 std::ostringstream stroker;
401 std::ostringstream strokeg;
402 std::ostringstream strokeb;
403 std::ostringstream ios;
404 std::ostringstream filla;
405 std::ostringstream fillr;
406 std::ostringstream fillg;
407 std::ostringstream fillb;
408 std::ostringstream iof;
409
410 simply << ext->get_param_float("simply");
411 clean << (-1000 - ext->get_param_int("clean"));
412 erase << (ext->get_param_float("erase") / 10);
413 smooth << ext->get_param_float("smooth");
414 dilat << ext->get_param_float("dilat");
415 erosion << (- ext->get_param_float("erosion"));
416 if (ext->get_param_bool("translucent"))
417 translucent << "merge1";
418 else
419 translucent << "color5";
420 offset << ext->get_param_int("offset");
421
422 blur << ext->get_param_float("blur");
423 bdilat << ext->get_param_float("bdilat");
424 berosion << (- ext->get_param_float("berosion"));
425
426 guint32 fcolor = ext->get_param_color("fcolor");
427 fillr << ((fcolor >> 24) & 0xff);
428 fillg << ((fcolor >> 16) & 0xff);
429 fillb << ((fcolor >> 8) & 0xff);
430 filla << (fcolor & 0xff) / 255.0F;
431 if (ext->get_param_bool("iof"))
432 iof << "SourceGraphic";
433 else
434 iof << "flood3";
435
436 guint32 scolor = ext->get_param_color("scolor");
437 stroker << ((scolor >> 24) & 0xff);
438 strokeg << ((scolor >> 16) & 0xff);
439 strokeb << ((scolor >> 8) & 0xff);
440 strokea << (scolor & 0xff) / 255.0F;
441 if (ext->get_param_bool("ios"))
442 ios << "SourceGraphic";
443 else
444 ios << "flood2";
445
446 // clang-format off
447 _filter = g_strdup_printf(
448 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" style=\"color-interpolation-filters:sRGB;\" inkscape:label=\"Drawing\">\n"
449 "<feGaussianBlur in=\"SourceGraphic\" stdDeviation=\"%s\" result=\"blur1\" />\n"
450 "<feConvolveMatrix in=\"blur1\" targetX=\"1\" targetY=\"1\" order=\"3 3\" kernelMatrix=\"0 250 0 250 %s 250 0 250 0 \" result=\"convolve1\" />\n"
451 "<feComposite in=\"convolve1\" in2=\"convolve1\" k1=\"1\" k2=\"1\" k4=\"%s\" operator=\"arithmetic\" result=\"composite1\" />\n"
452 "<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"
453 "<feGaussianBlur stdDeviation=\"%s\" result=\"blur2\" />\n"
454 "<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"
455 "<feFlood flood-color=\"rgb(255,255,255)\" result=\"flood1\" />\n"
456 "<feBlend in2=\"color2\" mode=\"multiply\" result=\"blend1\" />\n"
457 "<feComponentTransfer in=\"blend1\" result=\"component1\">\n"
458 "<feFuncR type=\"discrete\" tableValues=\"0 1 1 1\" />\n"
459 "<feFuncG type=\"discrete\" tableValues=\"0 1 1 1\" />\n"
460 "<feFuncB type=\"discrete\" tableValues=\"0 1 1 1\" />\n"
461 "</feComponentTransfer>\n"
462 "<feGaussianBlur stdDeviation=\"%s\" result=\"blur3\" />\n"
463 "<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 \" result=\"color3\" />\n"
464 "<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"
465 "<feFlood flood-color=\"rgb(%s,%s,%s)\" result=\"flood2\" />\n"
466 "<feComposite in=\"%s\" in2=\"color4\" operator=\"in\" result=\"composite2\" />\n"
467 "<feComposite in=\"composite2\" in2=\"composite2\" operator=\"arithmetic\" k2=\"%s\" result=\"composite3\" />\n"
468 "<feOffset dx=\"%s\" dy=\"%s\" result=\"offset1\" />\n"
469 "<feFlood in=\"color4\" flood-color=\"rgb(%s,%s,%s)\" result=\"flood3\" />\n"
470 "<feComposite in=\"%s\" in2=\"color4\" operator=\"out\" result=\"composite4\" />\n"
471 "<feComposite in=\"composite4\" in2=\"composite4\" operator=\"arithmetic\" k2=\"%s\" result=\"composite5\" />\n"
472 "<feMerge result=\"merge1\">\n"
473 "<feMergeNode in=\"composite5\" />\n"
474 "<feMergeNode in=\"offset1\" />\n"
475 "</feMerge>\n"
476 "<feColorMatrix values=\"1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1.3 0 \" result=\"color5\" flood-opacity=\"0.56\" />\n"
477 "<feComposite in=\"%s\" in2=\"SourceGraphic\" operator=\"in\" result=\"composite8\" />\n"
478 "</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(), translucent.str().c_str());
479 // clang-format on
480
481 return _filter;
482}; /* Drawing filter */
483
484
497protected:
498 gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override;
499
500public:
501 Electrize ( ) : Filter() { };
502 ~Electrize ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; }
503
504 static void init () {
505 // clang-format off
507 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
508 "<name>" N_("Electrize") "</name>\n"
509 "<id>org.inkscape.effect.filter.Electrize</id>\n"
510 "<param name=\"blur\" gui-text=\"" N_("Simplify") "\" type=\"float\" appearance=\"full\" min=\"0.01\" max=\"10.0\">2.0</param>\n"
511 "<param name=\"type\" gui-text=\"" N_("Effect type:") "\" type=\"optiongroup\" appearance=\"combo\">\n"
512 "<option value=\"table\">" N_("Table") "</option>\n"
513 "<option value=\"discrete\">" N_("Discrete") "</option>\n"
514 "</param>\n"
515 "<param name=\"levels\" gui-text=\"" N_("Levels") "\" type=\"int\" appearance=\"full\" min=\"0\" max=\"10\">3</param>\n"
516 "<param name=\"invert\" gui-text=\"" N_("Inverted") "\" type=\"bool\">false</param>\n"
517 "<effect>\n"
518 "<object-type>all</object-type>\n"
519 "<effects-menu>\n"
520 "<submenu name=\"" N_("Filters") "\">\n"
521 "<submenu name=\"" N_("Image Paint and Draw") "\"/>\n"
522 "</submenu>\n"
523 "</effects-menu>\n"
524 "<menu-tip>" N_("Electro solarization effects") "</menu-tip>\n"
525 "</effect>\n"
526 "</inkscape-extension>\n", std::make_unique<Electrize>());
527 // clang-format on
528 };
529};
530
531gchar const *
533{
534 if (_filter != nullptr) g_free((void *)_filter);
535
536 std::ostringstream blur;
537 std::ostringstream type;
538 std::ostringstream values;
539
540 blur << ext->get_param_float("blur");
541 type << ext->get_param_optiongroup("type");
542
543 // TransfertComponent table values are calculated based on the effect level and inverted parameters.
544 int val = 0;
545 int levels = ext->get_param_int("levels") + 1;
546 if (ext->get_param_bool("invert")) {
547 val = 1;
548 }
549 values << val;
550 for ( int step = 1 ; step <= levels ; step++ ) {
551 if (val == 1) {
552 val = 0;
553 }
554 else {
555 val = 1;
556 }
557 values << " " << val;
558 }
559
560 // clang-format off
561 _filter = g_strdup_printf(
562 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" style=\"color-interpolation-filters:sRGB;\" inkscape:label=\"Electrize\">\n"
563 "<feGaussianBlur stdDeviation=\"%s\" result=\"blur\" />\n"
564 "<feComponentTransfer in=\"blur\" result=\"component\" >\n"
565 "<feFuncR type=\"%s\" tableValues=\"%s\" />\n"
566 "<feFuncG type=\"%s\" tableValues=\"%s\" />\n"
567 "<feFuncB type=\"%s\" tableValues=\"%s\" />\n"
568 "</feComponentTransfer>\n"
569 "</filter>\n", blur.str().c_str(), type.str().c_str(), values.str().c_str(), type.str().c_str(), values.str().c_str(), type.str().c_str(), values.str().c_str());
570 // clang-format on
571
572 return _filter;
573}; /* Electrize filter */
574
591protected:
592 gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override;
593
594public:
595 NeonDraw ( ) : Filter() { };
596 ~NeonDraw ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; }
597
598 static void init () {
599 // clang-format off
601 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
602 "<name>" N_("Neon Draw") "</name>\n"
603 "<id>org.inkscape.effect.filter.NeonDraw</id>\n"
604 "<param name=\"type\" gui-text=\"" N_("Line type:") "\" type=\"optiongroup\" appearance=\"combo\">\n"
605 "<option value=\"table\">" N_("Smoothed") "</option>\n"
606 "<option value=\"discrete\">" N_("Contrasted") "</option>\n"
607 "</param>\n"
608 "<param name=\"simply\" gui-text=\"" N_("Simplify") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0.01\" max=\"20.00\">3</param>\n"
609 "<param name=\"width\" gui-text=\"" N_("Line width") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0.01\" max=\"20.00\">3</param>\n"
610 "<param name=\"lightness\" gui-text=\"" N_("Lightness") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0.00\" max=\"10.00\">1</param>\n"
611 "<param name=\"blend\" gui-text=\"" N_("Blend mode:") "\" type=\"optiongroup\" appearance=\"combo\">\n"
612 "<option value=\"normal\">Normal</option>\n"
613 "<option value=\"multiply\">Multiply</option>\n"
614 "<option value=\"screen\">Screen</option>\n"
615 "</param>\n"
616 "<effect>\n"
617 "<object-type>all</object-type>\n"
618 "<effects-menu>\n"
619 "<submenu name=\"" N_("Filters") "\">\n"
620 "<submenu name=\"" N_("Image Paint and Draw") "\"/>\n"
621 "</submenu>\n"
622 "</effects-menu>\n"
623 "<menu-tip>" N_("Posterize and draw smooth lines around color shapes") "</menu-tip>\n"
624 "</effect>\n"
625 "</inkscape-extension>\n", std::make_unique<NeonDraw>());
626 // clang-format on
627 };
628};
629
630gchar const *
632{
633 if (_filter != nullptr) g_free((void *)_filter);
634
635 std::ostringstream blend;
636 std::ostringstream simply;
637 std::ostringstream width;
638 std::ostringstream lightness;
639 std::ostringstream type;
640
641 type << ext->get_param_optiongroup("type");
642 blend << ext->get_param_optiongroup("blend");
643 simply << ext->get_param_float("simply");
644 width << ext->get_param_float("width");
645 lightness << ext->get_param_float("lightness");
646
647 // clang-format off
648 _filter = g_strdup_printf(
649 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" style=\"color-interpolation-filters:sRGB;\" inkscape:label=\"Neon Draw\">\n"
650 "<feBlend mode=\"%s\" result=\"blend\" />\n"
651 "<feGaussianBlur in=\"blend\" stdDeviation=\"%s\" result=\"blur1\" />\n"
652 "<feColorMatrix values=\"1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 50 0\" result=\"color1\" />\n"
653 "<feComponentTransfer result=\"component1\">\n"
654 "<feFuncR type=\"discrete\" tableValues=\"0 0.3 0.3 0.3 0.3 0.6 0.6 0.6 0.6 1 1\" />\n"
655 "<feFuncG type=\"discrete\" tableValues=\"0 0.3 0.3 0.3 0.3 0.6 0.6 0.6 0.6 1 1\" />\n"
656 "<feFuncB type=\"discrete\" tableValues=\"0 0.3 0.3 0.3 0.3 0.6 0.6 0.6 0.6 1 1\" />\n"
657 "</feComponentTransfer>\n"
658 "<feGaussianBlur in=\"component1\" stdDeviation=\"%s\" result=\"blur2\" />\n"
659 "<feColorMatrix values=\"1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 50 0\" result=\"color2\" />\n"
660 "<feComponentTransfer in=\"color2\" result=\"component2\">\n"
661 "<feFuncR type=\"%s\" tableValues=\"0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1\" />\n"
662 "<feFuncG type=\"%s\" tableValues=\"0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1\" />\n"
663 "<feFuncB type=\"%s\" tableValues=\"0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1\" />\n"
664 "</feComponentTransfer>\n"
665 "<feComposite in=\"component2\" in2=\"blur2\" k3=\"%s\" operator=\"arithmetic\" k2=\"1\" result=\"composite1\" />\n"
666 "<feComposite in=\"composite1\" in2=\"SourceGraphic\" operator=\"in\" result=\"composite2\" />\n"
667 "</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(), lightness.str().c_str());
668 // clang-format on
669
670 return _filter;
671}; /* NeonDraw filter */
672
698protected:
699 gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override;
700
701public:
703 ~PointEngraving ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; }
704
705 static void init () {
706 // clang-format off
708 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
709 "<name>" N_("Point Engraving") "</name>\n"
710 "<id>org.inkscape.effect.filter.PointEngraving</id>\n"
711 "<param name=\"tab\" type=\"notebook\">\n"
712 "<page name=\"optionstab\" gui-text=\"" N_("Options") "\">\n"
713 "<param name=\"type\" gui-text=\"" N_("Turbulence type:") "\" type=\"optiongroup\" appearance=\"combo\">\n"
714 "<option value=\"fractalNoise\">" N_("Fractal noise") "</option>\n"
715 "<option value=\"turbulence\">" N_("Turbulence") "</option>\n"
716 "</param>\n"
717 "<param name=\"hfreq\" gui-text=\"" N_("Horizontal frequency") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0.1\" max=\"100.00\">100</param>\n"
718 "<param name=\"vfreq\" gui-text=\"" N_("Vertical frequency") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0.1\" max=\"100.00\">100</param>\n"
719 "<param name=\"complexity\" gui-text=\"" N_("Complexity") "\" type=\"int\" appearance=\"full\" min=\"1\" max=\"5\">1</param>\n"
720 "<param name=\"variation\" gui-text=\"" N_("Variation") "\" type=\"int\" appearance=\"full\" min=\"1\" max=\"100\">0</param>\n"
721 "<param name=\"reduction\" gui-text=\"" N_("Noise reduction") "\" type=\"int\" appearance=\"full\" min=\"0\" max=\"500\">45</param>\n"
722 "<param name=\"blend\" gui-text=\"" N_("Noise blend:") "\" type=\"optiongroup\" appearance=\"combo\">\n"
723 "<option value=\"multiply\">" N_("Multiply") "</option>\n"
724 "<option value=\"normal\">" N_("Normal") "</option>\n"
725 "<option value=\"screen\">" N_("Screen") "</option>\n"
726 "<option value=\"lighten\">" N_("Lighten") "</option>\n"
727 "<option value=\"darken\">" N_("Darken") "</option>\n"
728 "</param>\n"
729 "<param name=\"lightness\" gui-text=\"" N_("Lightness") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0\" max=\"10\">2.5</param>\n"
730 "<param name=\"grain\" gui-text=\"" N_("Grain lightness") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0\" max=\"10\">1.3</param>\n"
731 "<param name=\"erase\" gui-text=\"" N_("Erase") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0\" max=\"1\">0</param>\n"
732 "<param name=\"blur\" gui-text=\"" N_("Blur") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0.01\" max=\"2\">0.5</param>\n"
733 "</page>\n"
734 "<page name=\"fcolortab\" gui-text=\"" N_("Fill color") "\">\n"
735 "<param name=\"fcolor\" gui-text=\"" N_("Color") "\" type=\"color\">-1</param>\n"
736 "<param name=\"iof\" gui-text=\"" N_("Image on fill") "\" type=\"bool\" >false</param>\n"
737 "</page>\n"
738 "<page name=\"pcolortab\" gui-text=\"" N_("Points color") "\">\n"
739 "<param name=\"pcolor\" gui-text=\"" N_("Color") "\" type=\"color\">1666789119</param>\n"
740 "<param name=\"iop\" gui-text=\"" N_("Image on points") "\" type=\"bool\" >false</param>\n"
741 "</page>\n"
742 "</param>\n"
743 "<effect>\n"
744 "<object-type>all</object-type>\n"
745 "<effects-menu>\n"
746 "<submenu name=\"" N_("Filters") "\">\n"
747 "<submenu name=\"" N_("Image Paint and Draw") "\"/>\n"
748 "</submenu>\n"
749 "</effects-menu>\n"
750 "<menu-tip>" N_("Convert image to a transparent point engraving") "</menu-tip>\n"
751 "</effect>\n"
752 "</inkscape-extension>\n", std::make_unique<PointEngraving>());
753 // clang-format on
754 };
755
756};
757
758gchar const *
760{
761 if (_filter != nullptr) g_free((void *)_filter);
762
763 std::ostringstream type;
764 std::ostringstream hfreq;
765 std::ostringstream vfreq;
766 std::ostringstream complexity;
767 std::ostringstream variation;
768 std::ostringstream reduction;
769 std::ostringstream blend;
770 std::ostringstream lightness;
771 std::ostringstream grain;
772 std::ostringstream erase;
773 std::ostringstream blur;
774 std::ostringstream r;
775 std::ostringstream g;
776 std::ostringstream b;
777 std::ostringstream a;
778 std::ostringstream br;
779 std::ostringstream bg;
780 std::ostringstream bb;
781 std::ostringstream ba;
782 std::ostringstream iof;
783 std::ostringstream iop;
784
785 type << ext->get_param_optiongroup("type");
786 hfreq << ext->get_param_float("hfreq") / 100;
787 vfreq << ext->get_param_float("vfreq") / 100;
788 complexity << ext->get_param_int("complexity");
789 variation << ext->get_param_int("variation");
790 reduction << (-1000 - ext->get_param_int("reduction"));
791 blend << ext->get_param_optiongroup("blend");
792 lightness << ext->get_param_float("lightness");
793 grain << ext->get_param_float("grain");
794 erase << ext->get_param_float("erase");
795 blur << ext->get_param_float("blur");
796
797 guint32 fcolor = ext->get_param_color("fcolor");
798 r << ((fcolor >> 24) & 0xff);
799 g << ((fcolor >> 16) & 0xff);
800 b << ((fcolor >> 8) & 0xff);
801 a << (fcolor & 0xff) / 255.0F;
802
803 guint32 pcolor = ext->get_param_color("pcolor");
804 br << ((pcolor >> 24) & 0xff);
805 bg << ((pcolor >> 16) & 0xff);
806 bb << ((pcolor >> 8) & 0xff);
807 ba << (pcolor & 0xff) / 255.0F;
808
809 if (ext->get_param_bool("iof"))
810 iof << "SourceGraphic";
811 else
812 iof << "flood2";
813
814 if (ext->get_param_bool("iop"))
815 iop << "SourceGraphic";
816 else
817 iop << "flood1";
818
819 // clang-format off
820 _filter = g_strdup_printf(
821 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" inkscape:label=\"Point Engraving\" style=\"color-interpolation-filters:sRGB;\">\n"
822 "<feConvolveMatrix in=\"SourceGraphic\" kernelMatrix=\"0 250 0 250 %s 250 0 250 0\" order=\"3 3\" result=\"convolve\" />\n"
823 "<feBlend in=\"convolve\" in2=\"SourceGraphic\" mode=\"%s\" result=\"blend\" />\n"
824 "<feTurbulence type=\"%s\" baseFrequency=\"%s %s\" numOctaves=\"%s\" seed=\"%s\" result=\"turbulence\" />\n"
825 "<feColorMatrix in=\"blend\" type=\"luminanceToAlpha\" result=\"colormatrix1\" />\n"
826 "<feComposite in=\"turbulence\" in2=\"colormatrix1\" k1=\"%s\" k2=\"%s\" k4=\"%s\" operator=\"arithmetic\" result=\"composite1\" />\n"
827 "<feColorMatrix in=\"composite1\" values=\"1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 10 -9 \" result=\"colormatrix2\" />\n"
828 "<feGaussianBlur stdDeviation=\"%s\" result=\"blur\" />\n"
829 "<feFlood flood-color=\"rgb(%s,%s,%s)\" flood-opacity=\"%s\" result=\"flood1\" />\n"
830 "<feComposite in=\"%s\" in2=\"blur\" operator=\"out\" result=\"composite2\" />\n"
831 "<feFlood flood-color=\"rgb(%s,%s,%s)\" flood-opacity=\"%s\" result=\"flood2\" />\n"
832 "<feComposite in=\"%s\" in2=\"blur\" operator=\"in\" result=\"composite3\" />\n"
833 "<feComposite in=\"composite3\" in2=\"composite2\" k2=\"%s\" k3=\"%s\" operator=\"arithmetic\" result=\"composite4\" />\n"
834 "<feComposite in2=\"SourceGraphic\" operator=\"in\" result=\"composite5\" />\n"
835 "</filter>\n", reduction.str().c_str(), blend.str().c_str(),
836 type.str().c_str(), hfreq.str().c_str(), vfreq.str().c_str(), complexity.str().c_str(), variation.str().c_str(),
837 lightness.str().c_str(), grain.str().c_str(), erase.str().c_str(), blur.str().c_str(),
838 br.str().c_str(), bg.str().c_str(), bb.str().c_str(), ba.str().c_str(), iop.str().c_str(),
839 r.str().c_str(), g.str().c_str(), b.str().c_str(), a.str().c_str(), iof.str().c_str(),
840 a.str().c_str(), ba.str().c_str() );
841 // clang-format on
842
843 return _filter;
844}; /* Point engraving filter */
845
865protected:
866 gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override;
867
868public:
869 Posterize ( ) : Filter() { };
870 ~Posterize ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; }
871
872 static void init () {
873 // clang-format off
875 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
876 "<name>" N_("Poster Paint") "</name>\n"
877 "<id>org.inkscape.effect.filter.Posterize</id>\n"
878 "<param name=\"type\" gui-text=\"" N_("Effect type:") "\" type=\"optiongroup\" appearance=\"combo\">\n"
879 "<option value=\"normal\">Normal</option>\n"
880 "<option value=\"dented\">Dented</option>\n"
881 "</param>\n"
882 "<param name=\"table\" gui-text=\"" N_("Transfer type:") "\" type=\"optiongroup\" appearance=\"combo\">\n"
883 "<option value=\"discrete\">" N_("Poster") "</option>\n"
884 "<option value=\"table\">" N_("Painting") "</option>\n"
885 "</param>\n"
886 "<param name=\"levels\" gui-text=\"" N_("Levels") "\" type=\"int\" appearance=\"full\" min=\"0\" max=\"15\">5</param>\n"
887 "<param name=\"blend\" gui-text=\"" N_("Blend mode:") "\" type=\"optiongroup\" appearance=\"combo\">\n"
888 "<option value=\"lighten\">Lighten</option>\n"
889 "<option value=\"normal\">Normal</option>\n"
890 "<option value=\"darken\">Darken</option>\n"
891 "<option value=\"multiply\">Multiply</option>\n"
892 "<option value=\"screen\">Screen</option>\n"
893 "</param>\n"
894 "<param name=\"blur1\" gui-text=\"" N_("Simplify (primary)") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0.01\" max=\"100.00\">4.0</param>\n"
895 "<param name=\"blur2\" gui-text=\"" N_("Simplify (secondary)") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0.01\" max=\"100.00\">0.5</param>\n"
896 "<param name=\"presaturation\" gui-text=\"" N_("Pre-saturation") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0.00\" max=\"1.00\">1.00</param>\n"
897 "<param name=\"postsaturation\" gui-text=\"" N_("Post-saturation") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0.00\" max=\"1.00\">1.00</param>\n"
898 "<param name=\"antialiasing\" gui-text=\"" N_("Simulate antialiasing") "\" type=\"bool\">false</param>\n"
899 "<effect>\n"
900 "<object-type>all</object-type>\n"
901 "<effects-menu>\n"
902 "<submenu name=\"" N_("Filters") "\">\n"
903 "<submenu name=\"" N_("Image Paint and Draw") "\"/>\n"
904 "</submenu>\n"
905 "</effects-menu>\n"
906 "<menu-tip>" N_("Poster and painting effects") "</menu-tip>\n"
907 "</effect>\n"
908 "</inkscape-extension>\n", std::make_unique<Posterize>());
909 // clang-format on
910 };
911};
912
913gchar const *
915{
916 if (_filter != nullptr) g_free((void *)_filter);
917
918 std::ostringstream table;
919 std::ostringstream blendmode;
920 std::ostringstream blur1;
921 std::ostringstream blur2;
922 std::ostringstream presat;
923 std::ostringstream postsat;
924 std::ostringstream transf;
925 std::ostringstream antialias;
926
927 table << ext->get_param_optiongroup("table");
928 blendmode << ext->get_param_optiongroup("blend");
929 blur1 << ext->get_param_float("blur1");
930 blur2 << ext->get_param_float("blur2");
931 presat << ext->get_param_float("presaturation");
932 postsat << ext->get_param_float("postsaturation");
933
934 // TransfertComponent table values are calculated based on the poster type.
935 transf << "0";
936 int levels = ext->get_param_int("levels") + 1;
937 const gchar *effecttype = ext->get_param_optiongroup("type");
938 if (levels == 1) {
939 if ((g_ascii_strcasecmp("dented", effecttype) == 0)) {
940 transf << " 1 0 1";
941 } else {
942 transf << " 1";
943 }
944 } else {
945 for ( int step = 1 ; step <= levels ; step++ ) {
946 float val = (float) step / levels;
947 transf << " " << val;
948 if ((g_ascii_strcasecmp("dented", effecttype) == 0)) {
949 transf << " " << (val - ((float) 1 / (3 * levels))) << " " << (val + ((float) 1 / (2 * levels)));
950 }
951 }
952 }
953 transf << " 1";
954
955 if (ext->get_param_bool("antialiasing"))
956 antialias << "0.5";
957 else
958 antialias << "0.01";
959
960 // clang-format off
961 _filter = g_strdup_printf(
962 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" style=\"color-interpolation-filters:sRGB;\" inkscape:label=\"Poster Paint\">\n"
963 "<feComposite operator=\"arithmetic\" k2=\"1\" result=\"composite1\" />\n"
964 "<feGaussianBlur stdDeviation=\"%s\" result=\"blur1\" />\n"
965 "<feGaussianBlur in=\"composite1\" stdDeviation=\"%s\" result=\"blur2\" />\n"
966 "<feBlend in2=\"blur1\" mode=\"%s\" result=\"blend\"/>\n"
967 "<feColorMatrix type=\"saturate\" values=\"%s\" result=\"color1\" />\n"
968 "<feComponentTransfer result=\"component\">\n"
969 "<feFuncR type=\"%s\" tableValues=\"%s\" />\n"
970 "<feFuncG type=\"%s\" tableValues=\"%s\" />\n"
971 "<feFuncB type=\"%s\" tableValues=\"%s\" />\n"
972 "</feComponentTransfer>\n"
973 "<feColorMatrix type=\"saturate\" values=\"%s\" result=\"color2\" />\n"
974 "<feGaussianBlur stdDeviation=\"%s\" result=\"blur3\" />\n"
975 "<feComposite in2=\"SourceGraphic\" operator=\"in\" result=\"composite3\" />\n"
976 "</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());
977 // clang-format on
978
979 return _filter;
980}; /* Posterize filter */
981
992protected:
993 gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override;
994
995public:
997 ~PosterizeBasic ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; }
998
999 static void init () {
1000 // clang-format off
1002 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
1003 "<name>" N_("Posterize Basic") "</name>\n"
1004 "<id>org.inkscape.effect.filter.PosterizeBasic</id>\n"
1005 "<param name=\"levels\" gui-text=\"" N_("Levels") "\" type=\"int\" appearance=\"full\" min=\"0\" max=\"20\">5</param>\n"
1006 "<param name=\"blur\" gui-text=\"" N_("Simplify") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0.01\" max=\"20.00\">4.0</param>\n"
1007 "<effect>\n"
1008 "<object-type>all</object-type>\n"
1009 "<effects-menu>\n"
1010 "<submenu name=\"" N_("Filters") "\">\n"
1011 "<submenu name=\"" N_("Image Paint and Draw") "\"/>\n"
1012 "</submenu>\n"
1013 "</effects-menu>\n"
1014 "<menu-tip>" N_("Simple posterizing effect") "</menu-tip>\n"
1015 "</effect>\n"
1016 "</inkscape-extension>\n", std::make_unique<PosterizeBasic>());
1017 // clang-format on
1018 };
1019};
1020
1021gchar const *
1023{
1024 if (_filter != nullptr) g_free((void *)_filter);
1025
1026 std::ostringstream blur;
1027 std::ostringstream transf;
1028
1029 blur << ext->get_param_float("blur");
1030
1031 transf << "0";
1032 int levels = ext->get_param_int("levels") + 1;
1033 for ( int step = 1 ; step <= levels ; step++ ) {
1034 const float val = (float) step / levels;
1035 transf << " " << val;
1036 }
1037 transf << " 1";
1038
1039 // clang-format off
1040 _filter = g_strdup_printf(
1041 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" style=\"color-interpolation-filters:sRGB;\" inkscape:label=\"Posterize Basic\">\n"
1042 "<feGaussianBlur stdDeviation=\"%s\" result=\"blur1\" />\n"
1043 "<feComponentTransfer in=\"blur1\" result=\"component1\">\n"
1044 "<feFuncR type=\"discrete\" tableValues=\"%s\" />\n"
1045 "<feFuncG type=\"discrete\" tableValues=\"%s\" />\n"
1046 "<feFuncB type=\"discrete\" tableValues=\"%s\" />\n"
1047 "</feComponentTransfer>\n"
1048 "<feComposite in=\"component1\" in2=\"SourceGraphic\" operator=\"in\" />\n"
1049 "</filter>\n", blur.str().c_str(), transf.str().c_str(), transf.str().c_str(), transf.str().c_str());
1050 // clang-format on
1051
1052 return _filter;
1053}; /* PosterizeBasic filter */
1054
1055}; /* namespace Filter */
1056}; /* namespace Internal */
1057}; /* namespace Extension */
1058}; /* namespace Inkscape */
1059
1060/* Change the 'PAINT' below to be your file name */
1061#endif /* SEEN_INKSCAPE_EXTENSION_INTERNAL_FILTER_PAINT_H__ */
Cairo::RefPtr< Cairo::Region > clean
Definition: canvas.cpp:184
The object that is the basis for the Extension system.
Definition: extension.h:130
char const * get_param_optiongroup(char const *name, char const *alt) const
Like get_param_optiongroup but with a default on param_not_exist error.
Definition: extension.cpp:757
int get_param_int(char const *name) const
Gets a parameter identified by name with the integer placed in value.
Definition: extension.cpp:662
double get_param_float(char const *name) const
Gets a float parameter identified by name with the double placed in value.
Definition: extension.cpp:690
std::uint32_t get_param_color(char const *name) const
Gets a parameter identified by name with the unsigned int placed in value.
Definition: extension.cpp:788
bool get_param_bool(char const *name) const
Gets a parameter identified by name with the bool placed in value.
Definition: extension.cpp:634
Custom predefined Chromolitho filter.
Definition: paint.h:61
gchar const * get_filter_text(Inkscape::Extension::Extension *ext) override
Definition: paint.h:126
Custom predefined Cross engraving filter.
Definition: paint.h:226
gchar const * get_filter_text(Inkscape::Extension::Extension *ext) override
Definition: paint.h:261
Custom predefined Drawing filter.
Definition: paint.h:329
gchar const * get_filter_text(Inkscape::Extension::Extension *ext) override
Definition: paint.h:384
Custom predefined Electrize filter.
Definition: paint.h:496
gchar const * get_filter_text(Inkscape::Extension::Extension *ext) override
Definition: paint.h:532
Custom predefined Neon draw filter.
Definition: paint.h:590
gchar const * get_filter_text(Inkscape::Extension::Extension *ext) override
Definition: paint.h:631
Custom predefined Point engraving filter.
Definition: paint.h:697
gchar const * get_filter_text(Inkscape::Extension::Extension *ext) override
Definition: paint.h:759
Custom predefined Posterize basic filter.
Definition: paint.h:991
gchar const * get_filter_text(Inkscape::Extension::Extension *ext) override
Definition: paint.h:1022
Custom predefined Poster paint filter.
Definition: paint.h:864
gchar const * get_filter_text(Inkscape::Extension::Extension *ext) override
Definition: paint.h:914
A way to clear the N_ macro, which is defined as an inline function.
unsigned int guint32
Definition: color.h:22
Inkscape::Extension::Extension: Frontend to certain, possibly pluggable, actions.
double offset
Coord length(LineSegment const &seg)
Definition: bezier-curve.h:348
void build_from_mem(gchar const *buffer, std::unique_ptr< Implementation::Implementation > in_imp)
Create a module from a buffer holding an XML description.
Definition: system.cpp:471
CMYK to sRGB conversion routines.
double width
Glib::RefPtr< Gtk::Adjustment > smooth