~centralelyon2010/inkscape/imagelinks2

« back to all changes in this revision

Viewing changes to src/extension/internal/filter/paint.h

  • Committer: JazzyNico
  • Date: 2011-08-29 20:25:30 UTC
  • Revision ID: nicoduf@yahoo.fr-20110829202530-6deuoz11q90usldv
Code refactoring and merging with trunk (revision 10599).

Show diffs side-by-side

added added

removed removed

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