Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
distort.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2#ifndef SEEN_INKSCAPE_EXTENSION_INTERNAL_FILTER_DISTORT_H__
3#define SEEN_INKSCAPE_EXTENSION_INTERNAL_FILTER_DISTORT_H__
4/* Change the 'DISTORT' above to be your file name */
5
6/*
7 * Copyright (C) 2011 Authors:
8 * Ivan Louette (filters)
9 * Nicolas Dufour (UI) <nicoduf@yahoo.fr>
10 *
11 * Distort filters
12 * Felt Feather
13 * Roughen
14 *
15 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
16 */
17/* ^^^ Change the copyright to be you and your e-mail address ^^^ */
18
19#include "filter.h"
20
22#include "extension/system.h"
23#include "extension/extension.h"
24
25namespace Inkscape {
26namespace Extension {
27namespace Internal {
28namespace Filter {
29
58protected:
59 gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override;
60
61public:
62 FeltFeather ( ) : Filter() { };
63 ~FeltFeather ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; }
64
65 static void init () {
66 // clang-format off
68 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
69 "<name>" N_("Felt Feather") "</name>\n"
70 "<id>org.inkscape.effect.filter.FeltFeather</id>\n"
71 "<param name=\"type\" gui-text=\"" N_("Type:") "\" type=\"optiongroup\" appearance=\"combo\">\n"
72 "<option value=\"in\">" N_("In") "</option>\n"
73 "<option value=\"out\">" N_("Out") "</option>\n"
74 "</param>\n"
75 "<param name=\"hblur\" gui-text=\"" N_("Horizontal blur") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0.01\" max=\"30.00\">15</param>\n"
76 "<param name=\"vblur\" gui-text=\"" N_("Vertical blur") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0.01\" max=\"30.00\">15</param>\n"
77 "<param name=\"dilat\" gui-text=\"" N_("Dilatation") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0\" max=\"100\">1</param>\n"
78 "<param name=\"erosion\" gui-text=\"" N_("Erosion") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0\" max=\"100\">0</param>\n"
79 "<param name=\"stroke\" gui-text=\"" N_("Stroke:") "\" type=\"optiongroup\" appearance=\"combo\">\n"
80 "<option value=\"atop\">" N_("Normal") "</option>\n"
81 "<option value=\"over\">" N_("Wide") "</option>\n"
82 "<option value=\"in\">" N_("Narrow") "</option>\n"
83 "<option value=\"xor\">" N_("No fill") "</option>\n"
84 "</param>\n"
85 "<param name=\"turbulence\" indent=\"1\" gui-text=\"" N_("Turbulence:") "\" type=\"optiongroup\" appearance=\"combo\">\n"
86 "<option value=\"fractalNoise\">" N_("Fractal noise") "</option>\n"
87 "<option value=\"turbulence\">" N_("Turbulence") "</option>\n"
88 "</param>\n"
89 "<param name=\"hfreq\" gui-text=\"" N_("Horizontal frequency") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0.01\" max=\"100.\">5</param>\n"
90 "<param name=\"vfreq\" gui-text=\"" N_("Vertical frequency") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0.01\" max=\"100.\">5</param>\n"
91 "<param name=\"complexity\" gui-text=\"" N_("Complexity") "\" type=\"int\" appearance=\"full\" min=\"1\" max=\"5\">3</param>\n"
92 "<param name=\"variation\" gui-text=\"" N_("Variation") "\" type=\"int\" appearance=\"full\" min=\"1\" max=\"100\">0</param>\n"
93 "<param name=\"intensity\" gui-text=\"" N_("Intensity") "\" type=\"float\" appearance=\"full\" min=\"0.0\" max=\"100\">30</param>\n"
94 "<effect>\n"
95 "<object-type>all</object-type>\n"
96 "<effects-menu>\n"
97 "<submenu name=\"" N_("Filters") "\">\n"
98 "<submenu name=\"" N_("Distort") "\"/>\n"
99 "</submenu>\n"
100 "</effects-menu>\n"
101 "<menu-tip>" N_("Blur and displace edges of shapes and pictures") "</menu-tip>\n"
102 "</effect>\n"
103 "</inkscape-extension>\n", std::make_unique<FeltFeather>());
104 // clang-format on
105 };
106
107};
108
109gchar const *
111{
112 if (_filter != nullptr) g_free((void *)_filter);
113
114
115 std::ostringstream hblur;
116 std::ostringstream vblur;
117 std::ostringstream dilat;
118 std::ostringstream erosion;
119
120 std::ostringstream turbulence;
121 std::ostringstream hfreq;
122 std::ostringstream vfreq;
123 std::ostringstream complexity;
124 std::ostringstream variation;
125 std::ostringstream intensity;
126
127 std::ostringstream map;
128 std::ostringstream stroke;
129
130 hblur << ext->get_param_float("hblur");
131 vblur << ext->get_param_float("vblur");
132 dilat << ext->get_param_float("dilat");
133 erosion << -ext->get_param_float("erosion");
134
135 turbulence << ext->get_param_optiongroup("turbulence");
136 hfreq << ext->get_param_float("hfreq") / 100;
137 vfreq << ext->get_param_float("vfreq") / 100;
138 complexity << ext->get_param_int("complexity");
139 variation << ext->get_param_int("variation");
140 intensity << ext->get_param_float("intensity");
141
142 stroke << ext->get_param_optiongroup("stroke");
143
144 const gchar *maptype = ext->get_param_optiongroup("type");
145 if (g_ascii_strcasecmp("in", maptype) == 0) {
146 map << "composite3";
147 } else {
148 map << "blur";
149 }
150
151 // clang-format off
152 _filter = g_strdup_printf(
153 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" x=\"-0.3\" width=\"1.6\" y=\"-0.3\" height=\"1.6\" style=\"color-interpolation-filters:sRGB;\" inkscape:label=\"Felt Feather\">\n"
154 "<feGaussianBlur stdDeviation=\"%s %s\" result=\"blur\" />\n"
155 "<feComposite in=\"SourceGraphic\" in2=\"blur\" operator=\"atop\" result=\"composite1\" />\n"
156 "<feComposite in2=\"composite1\" operator=\"in\" result=\"composite2\" />\n"
157 "<feComposite in2=\"composite2\" operator=\"in\" result=\"composite3\" />\n"
158 "<feTurbulence type=\"%s\" numOctaves=\"%s\" seed=\"%s\" baseFrequency=\"%s %s\" result=\"turbulence\" />\n"
159 "<feDisplacementMap in=\"%s\" in2=\"turbulence\" xChannelSelector=\"R\" scale=\"%s\" yChannelSelector=\"G\" result=\"map\" />\n"
160 "<feColorMatrix values=\"1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 %s %s \" result=\"colormatrix\" />\n"
161 "<feComposite in=\"composite3\" in2=\"colormatrix\" operator=\"%s\" result=\"composite4\" />\n"
162 "</filter>\n", hblur.str().c_str(), vblur.str().c_str(),
163 turbulence.str().c_str(), complexity.str().c_str(), variation.str().c_str(), hfreq.str().c_str(), vfreq.str().c_str(),
164 map.str().c_str(), intensity.str().c_str(), dilat.str().c_str(), erosion.str().c_str(), stroke.str().c_str() );
165 // clang-format on
166
167 return _filter;
168}; /* Felt feather filter */
169
185protected:
186 gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override;
187
188public:
189 Roughen ( ) : Filter() { };
190 ~Roughen ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; }
191
192 static void init () {
193 // clang-format off
195 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
196 "<name>" N_("Roughen") "</name>\n"
197 "<id>org.inkscape.effect.filter.Roughen</id>\n"
198 "<param name=\"type\" gui-text=\"" N_("Turbulence type:") "\" type=\"optiongroup\" appearance=\"combo\">\n"
199 "<option value=\"fractalNoise\">" N_("Fractal noise") "</option>\n"
200 "<option value=\"turbulence\">" N_("Turbulence") "</option>\n"
201 "</param>\n"
202 "<param name=\"hfreq\" gui-text=\"" N_("Horizontal frequency") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0.1\" max=\"1000.00\">1.3</param>\n"
203 "<param name=\"vfreq\" gui-text=\"" N_("Vertical frequency") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0.1\" max=\"1000.00\">1.3</param>\n"
204 "<param name=\"complexity\" gui-text=\"" N_("Complexity") "\" type=\"int\" appearance=\"full\" min=\"1\" max=\"5\">5</param>\n"
205 "<param name=\"variation\" gui-text=\"" N_("Variation") "\" type=\"int\" appearance=\"full\" min=\"1\" max=\"360\">0</param>\n"
206 "<param name=\"intensity\" gui-text=\"" N_("Intensity") "\" type=\"float\" appearance=\"full\" min=\"0.0\" max=\"50\">6.6</param>\n"
207 "<effect>\n"
208 "<object-type>all</object-type>\n"
209 "<effects-menu>\n"
210 "<submenu name=\"" N_("Filters") "\">\n"
211 "<submenu name=\"" N_("Distort") "\"/>\n"
212 "</submenu>\n"
213 "</effects-menu>\n"
214 "<menu-tip>" N_("Small-scale roughening to edges and content") "</menu-tip>\n"
215 "</effect>\n"
216 "</inkscape-extension>\n", std::make_unique<Roughen>());
217 // clang-format on
218 };
219
220};
221
222gchar const *
224{
225 if (_filter != nullptr) g_free((void *)_filter);
226
227 std::ostringstream type;
228 std::ostringstream hfreq;
229 std::ostringstream vfreq;
230 std::ostringstream complexity;
231 std::ostringstream variation;
232 std::ostringstream intensity;
233
234 type << ext->get_param_optiongroup("type");
235 hfreq << ext->get_param_float("hfreq") / 100;
236 vfreq << ext->get_param_float("vfreq") / 100;
237 complexity << ext->get_param_int("complexity");
238 variation << ext->get_param_int("variation");
239 intensity << ext->get_param_float("intensity");
240
241 // clang-format off
242 _filter = g_strdup_printf(
243 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" style=\"color-interpolation-filters:sRGB;\" inkscape:label=\"Roughen\">\n"
244 "<feTurbulence type=\"%s\" numOctaves=\"%s\" seed=\"%s\" baseFrequency=\"%s %s\" result=\"turbulence\" />\n"
245 "<feDisplacementMap in=\"SourceGraphic\" in2=\"turbulence\" scale=\"%s\" yChannelSelector=\"G\" xChannelSelector=\"R\" />\n"
246 "</filter>\n", type.str().c_str(), complexity.str().c_str(), variation.str().c_str(), hfreq.str().c_str(), vfreq.str().c_str(), intensity.str().c_str());
247 // clang-format on
248
249 return _filter;
250}; /* Roughen filter */
251
252}; /* namespace Filter */
253}; /* namespace Internal */
254}; /* namespace Extension */
255}; /* namespace Inkscape */
256
257/* Change the 'DISTORT' below to be your file name */
258#endif /* SEEN_INKSCAPE_EXTENSION_INTERNAL_FILTER_DISTORT_H__ */
The object that is the basis for the Extension system.
Definition extension.h:133
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.
int get_param_int(char const *name) const
Gets a parameter identified by name with the integer placed in value.
double get_param_float(char const *name) const
Gets a float parameter identified by name with the double placed in value.
virtual unsigned stroke(Inkscape::Extension::Print *, Geom::PathVector const &, Geom::Affine const &, SPStyle const *, Geom::OptRect const &, Geom::OptRect const &, Geom::OptRect const &)
Custom predefined FeltFeather filter.
Definition distort.h:57
gchar const * get_filter_text(Inkscape::Extension::Extension *ext) override
Definition distort.h:110
Custom predefined Roughen filter.
Definition distort.h:184
gchar const * get_filter_text(Inkscape::Extension::Extension *ext) override
Definition distort.h:223
A way to clear the N_ macro, which is defined as an inline function.
Inkscape::Extension::Extension: Frontend to certain, possibly pluggable, actions.
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:459
Helper class to stream background task notifications as a series of messages.