acd258805a381183bacf1e5869c43420714a7145
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 * Drawing
13 * Posterize
14 * Posterize basic
15 *
16 * Released under GNU GPL, read the file 'COPYING' for more information
17 */
18 /* ^^^ Change the copyright to be you and your e-mail address ^^^ */
20 #include "filter.h"
22 #include "extension/internal/clear-n_.h"
23 #include "extension/system.h"
24 #include "extension/extension.h"
26 namespace Inkscape {
27 namespace Extension {
28 namespace Internal {
29 namespace Filter {
31 /**
32 \brief Custom predefined Chromolitho filter.
34 Chromo effect with customizable edge drawing and graininess
36 Filter's parameters:
37 * Drawing (boolean, default checked) -> Checked = blend1 (in="convolve1"), unchecked = blend1 (in="composite1")
38 * Transparent (boolean, default unchecked) -> Checked = colormatrix5 (in="colormatrix4"), Unchecked = colormatrix5 (in="component1")
39 * Invert (boolean, default false) -> component1 (tableValues) [adds a trailing 0]
40 * Dented (boolean, default false) -> component1 (tableValues) [adds intermediate 0s]
41 * Lightness (0.->10., default 0.) -> composite1 (k1)
42 * Saturation (0.->1., default 1.) -> colormatrix3 (values)
43 * Noise reduction (1->1000, default 20) -> convolve (kernelMatrix, central value -1001->-2000, default -1020)
44 * Drawing blend (enum, default Normal) -> blend1 (mode)
45 * Smoothness (0.01->10, default 1) -> blur1 (stdDeviation)
46 * Grain (boolean, default unchecked) -> Checked = blend2 (in="colormatrix2"), Unchecked = blend2 (in="blur1")
47 * Grain x frequency (0.->100, default 100) -> turbulence1 (baseFrequency, first value)
48 * Grain y frequency (0.->100, default 100) -> turbulence1 (baseFrequency, second value)
49 * Grain complexity (1->5, default 1) -> turbulence1 (numOctaves)
50 * Grain variation (0->1000, default 0) -> turbulence1 (seed)
51 * Grain expansion (1.->50., default 1.) -> colormatrix1 (n-1 value)
52 * Grain erosion (0.->40., default 0.) -> colormatrix1 (nth value) [inverted]
53 * Grain color (boolean, default true) -> colormatrix2 (values)
54 * Grain blend (enum, default Normal) -> blend2 (mode)
55 */
56 class Chromolitho : public Inkscape::Extension::Internal::Filter::Filter {
57 protected:
58 virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
60 public:
61 Chromolitho ( ) : Filter() { };
62 virtual ~Chromolitho ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
64 static void init (void) {
65 Inkscape::Extension::build_from_mem(
66 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
67 "<name>" N_("Chromolitho, custom") "</name>\n"
68 "<id>org.inkscape.effect.filter.Chromolitho</id>\n"
69 "<param name=\"tab\" type=\"notebook\">\n"
70 "<page name=\"optionstab\" _gui-text=\"Options\">\n"
71 "<param name=\"drawing\" gui-text=\"" N_("Drawing mode") "\" type=\"boolean\" >true</param>\n"
72 "<param name=\"dblend\" gui-text=\"" N_("Drawing blend:") "\" type=\"enum\">\n"
73 "<_item value=\"darken\">Darken</_item>\n"
74 "<_item value=\"normal\">Normal</_item>\n"
75 "<_item value=\"multiply\">Multiply</_item>\n"
76 "<_item value=\"screen\">Screen</_item>\n"
77 "<_item value=\"lighten\">Lighten</_item>\n"
78 "</param>\n"
79 "<param name=\"transparent\" gui-text=\"" N_("Transparent") "\" type=\"boolean\" >false</param>\n"
80 "<param name=\"dented\" gui-text=\"" N_("Dented") "\" type=\"boolean\" >false</param>\n"
81 "<param name=\"inverted\" gui-text=\"" N_("Inverted") "\" type=\"boolean\" >false</param>\n"
82 "<param name=\"light\" gui-text=\"" N_("Lightness:") "\" type=\"float\" min=\"0\" max=\"10\">0</param>\n"
83 "<param name=\"saturation\" gui-text=\"" N_("Saturation:") "\" type=\"float\" min=\"0\" max=\"1\">1</param>\n"
84 "<param name=\"noise\" gui-text=\"" N_("Noise reduction:") "\" type=\"int\" min=\"1\" max=\"1000\">10</param>\n"
85 "<param name=\"smooth\" gui-text=\"" N_("Smoothness:") "\" type=\"float\" min=\"0.01\" max=\"10\">1</param>\n"
86 "</page>\n"
87 "<page name=\"graintab\" _gui-text=\"Grain\">\n"
88 "<param name=\"grain\" gui-text=\"" N_("Grain mode") "\" type=\"boolean\" >true</param>\n"
89 "<param name=\"grainxf\" gui-text=\"" N_("X frequency:") "\" type=\"float\" min=\"0\" max=\"100\">100</param>\n"
90 "<param name=\"grainyf\" gui-text=\"" N_("Y frequency:") "\" type=\"float\" min=\"0\" max=\"100\">100</param>\n"
91 "<param name=\"grainc\" gui-text=\"" N_("Complexity:") "\" type=\"int\" min=\"1\" max=\"5\">1</param>\n"
92 "<param name=\"grainv\" gui-text=\"" N_("Variation:") "\" type=\"int\" min=\"0\" max=\"1000\">0</param>\n"
93 "<param name=\"grainexp\" gui-text=\"" N_("Expansion:") "\" type=\"float\" min=\"1\" max=\"50\">1</param>\n"
94 "<param name=\"grainero\" gui-text=\"" N_("Erosion:") "\" type=\"float\" min=\"0\" max=\"40\">0</param>\n"
95 "<param name=\"graincol\" gui-text=\"" N_("Color") "\" type=\"boolean\" >true</param>\n"
96 "<param name=\"gblend\" gui-text=\"" N_("Grain blend:") "\" type=\"enum\">\n"
97 "<_item value=\"normal\">Normal</_item>\n"
98 "<_item value=\"multiply\">Multiply</_item>\n"
99 "<_item value=\"screen\">Screen</_item>\n"
100 "<_item value=\"lighten\">Lighten</_item>\n"
101 "<_item value=\"darken\">Darken</_item>\n"
102 "</param>\n"
103 "</page>\n"
104 "</param>\n"
105 "<effect>\n"
106 "<object-type>all</object-type>\n"
107 "<effects-menu>\n"
108 "<submenu name=\"" N_("Filters") "\">\n"
109 "<submenu name=\"" N_("Experimental") "\"/>\n"
110 "</submenu>\n"
111 "</effects-menu>\n"
112 "<menu-tip>" N_("Chromo effect with customizable edge drawing and graininess") "</menu-tip>\n"
113 "</effect>\n"
114 "</inkscape-extension>\n", new Chromolitho());
115 };
116 };
118 gchar const *
119 Chromolitho::get_filter_text (Inkscape::Extension::Extension * ext)
120 {
121 if (_filter != NULL) g_free((void *)_filter);
123 std::ostringstream b1in;
124 std::ostringstream b2in;
125 std::ostringstream col3in;
126 std::ostringstream transf;
127 std::ostringstream light;
128 std::ostringstream saturation;
129 std::ostringstream noise;
130 std::ostringstream dblend;
131 std::ostringstream smooth;
132 std::ostringstream grain;
133 std::ostringstream grainxf;
134 std::ostringstream grainyf;
135 std::ostringstream grainc;
136 std::ostringstream grainv;
137 std::ostringstream gblend;
138 std::ostringstream grainexp;
139 std::ostringstream grainero;
140 std::ostringstream graincol;
142 if (ext->get_param_bool("drawing"))
143 b1in << "convolve1";
144 else
145 b1in << "composite1";
147 if (ext->get_param_bool("transparent"))
148 col3in << "colormatrix4";
149 else
150 col3in << "component1";
151 light << ext->get_param_float("light");
152 saturation << ext->get_param_float("saturation");
153 noise << (-1000 - ext->get_param_int("noise"));
154 dblend << ext->get_param_enum("dblend");
155 smooth << ext->get_param_float("smooth");
157 if (ext->get_param_bool("dented")) {
158 transf << "0 1 0 1";
159 } else {
160 transf << "0 1 1";
161 }
162 if (ext->get_param_bool("inverted"))
163 transf << " 0";
165 if (ext->get_param_bool("grain"))
166 b2in << "colormatrix2";
167 else
168 b2in << "blur1";
169 grainxf << (ext->get_param_float("grainxf") / 100);
170 grainyf << (ext->get_param_float("grainyf") / 100);
171 grainc << ext->get_param_int("grainc");
172 grainv << ext->get_param_int("grainv");
173 gblend << ext->get_param_enum("gblend");
174 grainexp << ext->get_param_float("grainexp");
175 grainero << (-ext->get_param_float("grainero"));
176 if (ext->get_param_bool("graincol"))
177 graincol << "1";
178 else
179 graincol << "0";
181 _filter = g_strdup_printf(
182 "<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"
183 "<feComposite stdDeviation=\"1\" in=\"SourceGraphic\" in2=\"SourceGraphic\" operator=\"arithmetic\" k1=\"%s\" k2=\"1\" result=\"composite1\" />\n"
184 "<feConvolveMatrix in=\"composite1\" kernelMatrix=\"0 250 0 250 %s 250 0 250 0 \" order=\"3 3\" stdDeviation=\"1\" result=\"convolve1\" />\n"
185 "<feBlend in=\"%s\" in2=\"composite1\" mode=\"%s\" blend=\"normal\" stdDeviation=\"1\" result=\"blend1\" />\n"
186 "<feGaussianBlur in=\"blend1\" stdDeviation=\"%s\" result=\"blur1\" />\n"
187 "<feTurbulence baseFrequency=\"%s %s\" numOctaves=\"%s\" seed=\"%s\" type=\"fractalNoise\" result=\"turbulence1\" />\n"
188 "<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"
189 "<feColorMatrix type=\"saturate\" stdDeviation=\"3\" values=\"%s\" result=\"colormatrix2\" />\n"
190 "<feBlend in=\"%s\" in2=\"blur1\" stdDeviation=\"1\" blend=\"normal\" mode=\"%s\" result=\"blend2\" />\n"
191 "<feColorMatrix in=\"blend2\" type=\"saturate\" values=\"%s\" result=\"colormatrix3\" />\n"
192 "<feComponentTransfer in=\"colormatrix3\" stdDeviation=\"2\" result=\"component1\">\n"
193 "<feFuncR type=\"discrete\" tableValues=\"%s\" />\n"
194 "<feFuncG type=\"discrete\" tableValues=\"%s\" />\n"
195 "<feFuncB type=\"discrete\" tableValues=\"%s\" />\n"
196 "</feComponentTransfer>\n"
197 "<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"
198 "<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"
199 "<feComposite in2=\"SourceGraphic\" operator=\"in\" result=\"composite2\" />\n"
200 "</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());
202 return _filter;
203 }; /* Chromolitho filter */
205 /**
206 \brief Custom predefined Drawing filter.
208 Convert images to duochrome drawings.
210 Filter's parameters:
211 * Simplification (0.01->20, default 0.6) -> blur1 (stdDeviation)
212 * Lightness (1->500, default 10) -> convolve1 (kernelMatrix, central value -1001->-1500, default -1010)
213 * Fading (0.->6., default 0) -> composite1 (k4)
214 * Smoothness (0.01->20, default 0.6) -> blur2 (stdDeviation)
215 * Dilatation (1->50, default 6) -> color2 (n-1th value)
216 * Erosion (0->50, default 3) -> color2 (nth value 0->-50)
217 * Transluscent (boolean, default false) -> composite 8 (in, true->merge1, false->composite7)
218 * Offset (-100->100, default 0) -> offset (val)
220 * Blur (0.01->20., default 1.) -> blur3 (stdDeviation)
221 * Blur spread (1->50, default 6) -> color4 (n-1th value)
222 * Blur erosion (0->50, default 3) -> color4 (nth value 0->-50)
224 * Stroke color (guint, default 64,64,64,255) -> flood2 (flood-color), composite3 (k2)
225 * Image on stroke (boolean, default false) -> composite2 (in="flood2" true-> in="SourceGraphic")
226 * Fill color (guint, default 200,200,200,255) -> flood3 (flood-opacity), composite5 (k2)
227 * Image on fill (boolean, default false) -> composite4 (in="flood3" true-> in="SourceGraphic")
229 */
231 class Drawing : public Inkscape::Extension::Internal::Filter::Filter {
232 protected:
233 virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
235 public:
236 Drawing ( ) : Filter() { };
237 virtual ~Drawing ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
239 static void init (void) {
240 Inkscape::Extension::build_from_mem(
241 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
242 "<name>" N_("Drawing, custom") "</name>\n"
243 "<id>org.inkscape.effect.filter.Drawing</id>\n"
244 "<param name=\"tab\" type=\"notebook\">\n"
245 "<page name=\"optionstab\" _gui-text=\"Options\">\n"
246 "<param name=\"simply\" gui-text=\"" N_("Simplification:") "\" type=\"float\" min=\"0.01\" max=\"20\">0.6</param>\n"
247 "<param name=\"light\" gui-text=\"" N_("Lightness:") "\" type=\"int\" min=\"0\" max=\"500\">10</param>\n"
248 "<param name=\"fade\" gui-text=\"" N_("Fading:") "\" type=\"float\" min=\"0\" max=\"60\">0</param>\n"
249 "<param name=\"smooth\" gui-text=\"" N_("Smoothness:") "\" type=\"float\" min=\"0.01\" max=\"20\">0.6</param>\n"
250 "<param name=\"dilat\" gui-text=\"" N_("Dilatation:") "\" type=\"float\" min=\"1\" max=\"50\">6</param>\n"
251 "<param name=\"erosion\" gui-text=\"" N_("Erosion:") "\" type=\"float\" min=\"0\" max=\"50\">3</param>\n"
252 "<param name=\"transluscent\" gui-text=\"" N_("Transluscent") "\" type=\"boolean\" >false</param>\n"
253 "<_param name=\"blurheader\" type=\"groupheader\">Blur</_param>\n"
254 "<param name=\"blur\" gui-text=\"" N_("Level:") "\" type=\"float\" min=\"0.01\" max=\"20\">1</param>\n"
255 "<param name=\"bdilat\" gui-text=\"" N_("Dilatation:") "\" type=\"float\" min=\"1\" max=\"50\">6</param>\n"
256 "<param name=\"berosion\" gui-text=\"" N_("Erosion:") "\" type=\"float\" min=\"0\" max=\"50\">3</param>\n"
257 "</page>\n"
258 "<page name=\"co11tab\" _gui-text=\"Fill color\">\n"
259 "<param name=\"fcolor\" gui-text=\"" N_("Fill color") "\" type=\"color\">-1515870721</param>\n"
260 "<param name=\"iof\" gui-text=\"" N_("Image on fill") "\" type=\"boolean\" >false</param>\n"
261 "</page>\n"
262 "<page name=\"co12tab\" _gui-text=\"Stroke color\">\n"
263 "<param name=\"scolor\" gui-text=\"" N_("Stroke color") "\" type=\"color\">589505535</param>\n"
264 "<param name=\"ios\" gui-text=\"" N_("Image on stroke") "\" type=\"boolean\" >false</param>\n"
265 "<param name=\"offset\" gui-text=\"" N_("Offset:") "\" type=\"int\" min=\"-100\" max=\"100\">0</param>\n"
266 "</page>\n"
267 "</param>\n"
268 "<effect>\n"
269 "<object-type>all</object-type>\n"
270 "<effects-menu>\n"
271 "<submenu name=\"" N_("Filters") "\">\n"
272 "<submenu name=\"" N_("Experimental") "\"/>\n"
273 "</submenu>\n"
274 "</effects-menu>\n"
275 "<menu-tip>" N_("Convert images to duochrome drawings") "</menu-tip>\n"
276 "</effect>\n"
277 "</inkscape-extension>\n", new Drawing());
278 };
279 };
281 gchar const *
282 Drawing::get_filter_text (Inkscape::Extension::Extension * ext)
283 {
284 if (_filter != NULL) g_free((void *)_filter);
286 std::ostringstream simply;
287 std::ostringstream light;
288 std::ostringstream fade;
289 std::ostringstream smooth;
290 std::ostringstream dilat;
291 std::ostringstream erosion;
292 std::ostringstream transluscent;
293 std::ostringstream offset;
294 std::ostringstream blur;
295 std::ostringstream bdilat;
296 std::ostringstream berosion;
297 std::ostringstream strokea;
298 std::ostringstream stroker;
299 std::ostringstream strokeg;
300 std::ostringstream strokeb;
301 std::ostringstream ios;
302 std::ostringstream filla;
303 std::ostringstream fillr;
304 std::ostringstream fillg;
305 std::ostringstream fillb;
306 std::ostringstream iof;
308 simply << ext->get_param_float("simply");
309 light << (-1000 - ext->get_param_int("light"));
310 fade << (ext->get_param_float("fade") / 10);
311 smooth << ext->get_param_float("smooth");
312 dilat << ext->get_param_float("dilat");
313 erosion << (- ext->get_param_float("erosion"));
314 if (ext->get_param_bool("transluscent"))
315 transluscent << "merge1";
316 else
317 transluscent << "composite7";
318 offset << ext->get_param_int("offset");
320 blur << ext->get_param_float("blur");
321 bdilat << ext->get_param_float("bdilat");
322 berosion << (- ext->get_param_float("berosion"));
324 guint32 fcolor = ext->get_param_color("fcolor");
325 fillr << ((fcolor >> 24) & 0xff);
326 fillg << ((fcolor >> 16) & 0xff);
327 fillb << ((fcolor >> 8) & 0xff);
328 filla << (fcolor & 0xff) / 255.0F;
329 if (ext->get_param_bool("iof"))
330 iof << "SourceGraphic";
331 else
332 iof << "flood3";
334 guint32 scolor = ext->get_param_color("scolor");
335 stroker << ((scolor >> 24) & 0xff);
336 strokeg << ((scolor >> 16) & 0xff);
337 strokeb << ((scolor >> 8) & 0xff);
338 strokea << (scolor & 0xff) / 255.0F;
339 if (ext->get_param_bool("ios"))
340 ios << "SourceGraphic";
341 else
342 ios << "flood2";
344 _filter = g_strdup_printf(
345 "<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"
346 "<feGaussianBlur in=\"SourceGraphic\" stdDeviation=\"%s\" result=\"blur1\" />\n"
347 "<feConvolveMatrix in=\"blur1\" targetX=\"1\" targetY=\"1\" order=\"3 3\" kernelMatrix=\"0 250 0 250 %s 250 0 250 0 \" result=\"convolve1\" />\n"
348 "<feComposite in=\"convolve1\" in2=\"convolve1\" k1=\"1\" k2=\"1\" k4=\"%s\" operator=\"arithmetic\" stdDeviation=\"1\" result=\"composite1\" />\n"
349 "<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"
350 "<feGaussianBlur stdDeviation=\"%s\" result=\"blur2\" />\n"
351 "<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"
352 "<feFlood flood-color=\"rgb(255,255,255)\" result=\"flood1\" />\n"
353 "<feBlend in2=\"color2\" mode=\"multiply\" blend=\"normal\" result=\"blend1\" />\n"
354 "<feComponentTransfer in=\"blend1\" stdDeviation=\"2\" result=\"component1\">\n"
355 "<feFuncR type=\"discrete\" tableValues=\"0 1 1 1\" />\n"
356 "<feFuncG type=\"discrete\" tableValues=\"0 1 1 1\" />\n"
357 "<feFuncB type=\"discrete\" tableValues=\"0 1 1 1\" />\n"
358 "</feComponentTransfer>\n"
359 "<feGaussianBlur stdDeviation=\"%s\" result=\"blur3\" />\n"
360 "<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"
361 "<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"
362 "<feFlood flood-color=\"rgb(%s,%s,%s)\" result=\"flood2\" />\n"
363 "<feComposite in=\"%s\" in2=\"color4\" operator=\"in\" result=\"composite2\" />\n"
364 "<feComposite in=\"composite2\" in2=\"composite2\" operator=\"arithmetic\" k2=\"%s\" result=\"composite3\" />\n"
365 "<feOffset dx=\"%s\" dy=\"%s\" result=\"offset1\" />\n"
366 "<feFlood in=\"color4\" flood-color=\"rgb(%s,%s,%s)\" result=\"flood3\" />\n"
367 "<feComposite in=\"%s\" in2=\"color4\" operator=\"out\" result=\"composite4\" />\n"
368 "<feComposite in=\"composite4\" in2=\"composite4\" operator=\"arithmetic\" k2=\"%s\" result=\"composite5\" />\n"
369 "<feMerge result=\"merge1\">\n"
370 "<feMergeNode in=\"composite5\" />\n"
371 "<feMergeNode in=\"offset1\" />\n"
372 "</feMerge>\n"
373 "<feComposite in=\"merge1\" in2=\"merge1\" operator=\"over\" result=\"composite6\" />\n"
374 "<feComposite in=\"composite6\" in2=\"composite6\" operator=\"over\" result=\"composite7\" />\n"
375 "<feComposite in=\"%s\" in2=\"SourceGraphic\" operator=\"in\" result=\"composite8\" />\n"
376 "</filter>\n", simply.str().c_str(), light.str().c_str(), fade.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());
378 return _filter;
379 }; /* Drawing filter */
381 /**
382 \brief Custom predefined Posterize filter.
384 Poster and painting effects.
386 Filter's parameters (not finished yet):
387 * Effect type (enum, default "Normal") ->
388 Normal = feComponentTransfer
389 Dented = Normal + intermediate values
390 * Blur (0.01->10., default 5.) -> blur3 (stdDeviation)
392 */
393 class Posterize : public Inkscape::Extension::Internal::Filter::Filter {
394 protected:
395 virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
397 public:
398 Posterize ( ) : Filter() { };
399 virtual ~Posterize ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
401 static void init (void) {
402 Inkscape::Extension::build_from_mem(
403 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
404 "<name>" N_("Poster and painting, custom") "</name>\n"
405 "<id>org.inkscape.effect.filter.Posterize</id>\n"
406 "<param name=\"type\" gui-text=\"" N_("Effect type:") "\" type=\"enum\">\n"
407 "<_item value=\"normal\">Normal</_item>\n"
408 "<_item value=\"dented\">Dented</_item>\n"
409 "</param>\n"
410 "<param name=\"table\" gui-text=\"" N_("Transfer type:") "\" type=\"enum\">\n"
411 "<_item value=\"discrete\">Poster</_item>\n"
412 "<_item value=\"table\">Painting</_item>\n"
413 "</param>\n"
414 "<param name=\"levels\" gui-text=\"" N_("Levels:") "\" type=\"int\" min=\"1\" max=\"15\">5</param>\n"
415 "<param name=\"blend\" gui-text=\"" N_("Blend mode:") "\" type=\"enum\">\n"
416 "<_item value=\"lighten\">Lighten</_item>\n"
417 "<_item value=\"normal\">Normal</_item>\n"
418 "<_item value=\"darken\">Darken</_item>\n"
419 "</param>\n"
420 "<param name=\"blur1\" gui-text=\"" N_("Primary blur:") "\" type=\"float\" min=\"0.01\" max=\"100.0\">4.0</param>\n"
421 "<param name=\"blur2\" gui-text=\"" N_("Secondary blur:") "\" type=\"float\" min=\"0.01\" max=\"100.0\">0.5</param>\n"
422 "<param name=\"presaturation\" gui-text=\"" N_("Pre-saturation:") "\" type=\"float\" min=\"0.00\" max=\"1.00\">1.00</param>\n"
423 "<param name=\"postsaturation\" gui-text=\"" N_("Post-saturation:") "\" type=\"float\" min=\"0.00\" max=\"1.00\">1.00</param>\n"
424 "<param name=\"antialiasing\" gui-text=\"" N_("Simulate antialiasing") "\" type=\"boolean\">false</param>\n"
425 "<effect>\n"
426 "<object-type>all</object-type>\n"
427 "<effects-menu>\n"
428 "<submenu name=\"" N_("Filters") "\">\n"
429 "<submenu name=\"" N_("Experimental") "\"/>\n"
430 "</submenu>\n"
431 "</effects-menu>\n"
432 "<menu-tip>" N_("Poster and painting effects") "</menu-tip>\n"
433 "</effect>\n"
434 "</inkscape-extension>\n", new Posterize());
435 };
436 };
438 gchar const *
439 Posterize::get_filter_text (Inkscape::Extension::Extension * ext)
440 {
441 if (_filter != NULL) g_free((void *)_filter);
443 std::ostringstream table;
444 std::ostringstream blendmode;
445 std::ostringstream blur1;
446 std::ostringstream blur2;
447 std::ostringstream presat;
448 std::ostringstream postsat;
449 std::ostringstream transf;
450 std::ostringstream antialias;
452 table << ext->get_param_enum("table");
453 blendmode << ext->get_param_enum("blend");
454 blur1 << ext->get_param_float("blur1");
455 blur2 << ext->get_param_float("blur2");
456 presat << ext->get_param_float("presaturation");
457 postsat << ext->get_param_float("postsaturation");
459 // TransfertComponent table values are calculated based on the poster type.
460 transf << "0";
461 int levels = ext->get_param_int("levels") + 1;
462 const gchar *effecttype = ext->get_param_enum("type");
463 float val = 0.0;
464 for ( int step = 1 ; step <= levels ; step++ ) {
465 val = (float) step / levels;
466 transf << " " << val;
467 if((g_ascii_strcasecmp("dented", effecttype) == 0)) {
468 transf << " " << (val - ((float) 1 / (3 * levels))) << " " << (val + ((float) 1 / (2 * levels)));
469 }
470 }
471 transf << " 1";
473 if (ext->get_param_bool("antialiasing"))
474 antialias << "0.5";
475 else
476 antialias << "0.01";
478 _filter = g_strdup_printf(
479 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" color-interpolation-filters=\"sRGB\" height=\"1\" width=\"1\" y=\"0\" x=\"0\" inkscape:label=\"Poster and painting, custom\">\n"
480 "<feComposite result=\"Composite1\" operator=\"arithmetic\" k2=\"1\" />\n"
481 "<feGaussianBlur stdDeviation=\"%s\" result=\"Gaussian1\" />\n"
482 "<feGaussianBlur stdDeviation=\"%s\" in=\"Composite1\" />\n"
483 "<feBlend in2=\"Gaussian1\" mode=\"%s\" />\n"
484 "<feColorMatrix type=\"saturate\" values=\"%s\" />\n"
485 "<feComponentTransfer>\n"
486 "<feFuncR type=\"%s\" tableValues=\"%s\" />\n"
487 "<feFuncG type=\"%s\" tableValues=\"%s\" />\n"
488 "<feFuncB type=\"%s\" tableValues=\"%s\" />\n"
489 "</feComponentTransfer>\n"
490 "<feColorMatrix type=\"saturate\" values=\"%s\" />\n"
491 "<feGaussianBlur stdDeviation=\"%s\" />\n"
492 "<feComposite in2=\"SourceGraphic\" operator=\"in\" />\n"
493 "</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());
495 return _filter;
496 }; /* Posterize filter */
498 /**
499 \brief Custom predefined PosterizeBasic filter.
501 Simple posterizing effect
503 Filter's parameters:
504 * Levels (1->20, default 5) -> component1 (tableValues)
505 * Blur (0.01->20., default 4.) -> blur1 (stdDeviation)
506 */
507 class PosterizeBasic : public Inkscape::Extension::Internal::Filter::Filter {
508 protected:
509 virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
511 public:
512 PosterizeBasic ( ) : Filter() { };
513 virtual ~PosterizeBasic ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
515 static void init (void) {
516 Inkscape::Extension::build_from_mem(
517 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
518 "<name>" N_("Posterize basic, custom") "</name>\n"
519 "<id>org.inkscape.effect.filter.PosterizeBasic</id>\n"
520 "<param name=\"levels\" gui-text=\"" N_("Levels:") "\" type=\"int\" min=\"1\" max=\"20\">5</param>\n"
521 "<param name=\"blur\" gui-text=\"" N_("Blur:") "\" type=\"float\" min=\"0.01\" max=\"20.0\">4.0</param>\n"
522 "<effect>\n"
523 "<object-type>all</object-type>\n"
524 "<effects-menu>\n"
525 "<submenu name=\"" N_("Filters") "\">\n"
526 "<submenu name=\"" N_("Experimental") "\"/>\n"
527 "</submenu>\n"
528 "</effects-menu>\n"
529 "<menu-tip>" N_("Simple posterizing effect") "</menu-tip>\n"
530 "</effect>\n"
531 "</inkscape-extension>\n", new PosterizeBasic());
532 };
533 };
535 gchar const *
536 PosterizeBasic::get_filter_text (Inkscape::Extension::Extension * ext)
537 {
538 if (_filter != NULL) g_free((void *)_filter);
540 std::ostringstream blur;
541 std::ostringstream transf;
543 blur << ext->get_param_float("blur");
545 transf << "0";
546 int levels = ext->get_param_int("levels") + 1;
547 float val = 0.0;
548 for ( int step = 1 ; step <= levels ; step++ ) {
549 val = (float) step / levels;
550 transf << " " << val;
551 }
552 transf << " 1";
554 _filter = g_strdup_printf(
555 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" color-interpolation-filters=\"sRGB\" height=\"1\" width=\"1\" y=\"0\" x=\"0\" inkscape:label=\"Posterize basic, custom\">\n"
556 "<feGaussianBlur stdDeviation=\"%s\" result=\"blur1\" />\n"
557 "<feComponentTransfer stdDeviation=\"2\" in=\"blur1\" result=\"component1\">\n"
558 "<feFuncR type=\"discrete\" tableValues=\"%s\" />\n"
559 "<feFuncG type=\"discrete\" tableValues=\"%s\" />\n"
560 "<feFuncB type=\"discrete\" tableValues=\"%s\" />\n"
561 "</feComponentTransfer>\n"
562 "<feComposite in=\"component1\" in2=\"SourceGraphic\" operator=\"in\" />\n"
563 "</filter>\n", blur.str().c_str(), transf.str().c_str(), transf.str().c_str(), transf.str().c_str());
565 return _filter;
566 }; /* PosterizeBasic filter */
568 }; /* namespace Filter */
569 }; /* namespace Internal */
570 }; /* namespace Extension */
571 }; /* namespace Inkscape */
573 /* Change the 'COLOR' below to be your file name */
574 #endif /* __INKSCAPE_EXTENSION_INTERNAL_FILTER_EXPERIMENTAL_H__ */