1 // SPDX-License-Identifier: GPL-2.0-or-later
2 #ifndef SEEN_INKSCAPE_EXTENSION_INTERNAL_FILTER_OVERLAYS_H__
3 #define SEEN_INKSCAPE_EXTENSION_INTERNAL_FILTER_OVERLAYS_H__
4 /* Change the 'OVERLAYS' 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 * Overlays filters
12 * Noise fill
13 *
14 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
15 */
16 /* ^^^ Change the copyright to be you and your e-mail address ^^^ */
17
18 #include "filter.h"
19
20 #include "extension/internal/clear-n_.h"
21 #include "extension/system.h"
22 #include "extension/extension.h"
23
24 namespace Inkscape {
25 namespace Extension {
26 namespace Internal {
27 namespace Filter {
28
29 /**
30 \brief Custom predefined Noise fill filter.
31
32 Basic noise fill and transparency texture
33
34 Filter's parameters:
35 * Turbulence type (enum, default fractalNoise else turbulence) -> turbulence (type)
36 * Horizontal frequency (*1000) (0.01->10000., default 20) -> turbulence (baseFrequency [/1000])
37 * Vertical frequency (*1000) (0.01->10000., default 40) -> turbulence (baseFrequency [/1000])
38 * Complexity (1->5, default 5) -> turbulence (numOctaves)
39 * Variation (1->360, default 1) -> turbulence (seed)
40 * Dilatation (1.->50., default 3) -> color (n-1th value)
41 * Erosion (0.->50., default 1) -> color (nth value 0->-50)
42 * Color (guint, default 148,115,39,255) -> flood (flood-color, flood-opacity)
43 * Inverted (boolean, default false) -> composite1 (operator, true="in", false="out")
44 */
45
46 class NoiseFill : public Inkscape::Extension::Internal::Filter::Filter {
47 protected:
48 gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override;
49
50 public:
NoiseFill()51 NoiseFill ( ) : Filter() { };
~NoiseFill()52 ~NoiseFill ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; }
53
init()54 static void init () {
55 // clang-format off
56 Inkscape::Extension::build_from_mem(
57 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
58 "<name>" N_("Noise Fill") "</name>\n"
59 "<id>org.inkscape.effect.filter.NoiseFill</id>\n"
60 "<param name=\"tab\" type=\"notebook\">\n"
61 "<page name=\"optionstab\" gui-text=\"" N_("Options") "\">\n"
62 "<param name=\"type\" gui-text=\"" N_("Turbulence type:") "\" type=\"optiongroup\" appearance=\"combo\">\n"
63 "<option value=\"fractalNoise\">" N_("Fractal noise") "</option>\n"
64 "<option value=\"turbulence\">" N_("Turbulence") "</option>\n"
65 "</param>\n"
66 "<param name=\"hfreq\" gui-text=\"" N_("Horizontal frequency:") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0.01\" max=\"10000.00\">20</param>\n"
67 "<param name=\"vfreq\" gui-text=\"" N_("Vertical frequency:") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0.01\" max=\"10000.00\">40</param>\n"
68 "<param name=\"complexity\" gui-text=\"" N_("Complexity:") "\" type=\"int\" appearance=\"full\" min=\"1\" max=\"5\">5</param>\n"
69 "<param name=\"variation\" gui-text=\"" N_("Variation:") "\" type=\"int\" appearance=\"full\" min=\"1\" max=\"360\">0</param>\n"
70 "<param name=\"dilat\" gui-text=\"" N_("Dilatation:") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"1\" max=\"50\">3</param>\n"
71 "<param name=\"erosion\" gui-text=\"" N_("Erosion:") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0\" max=\"50\">1</param>\n"
72 "<param name=\"inverted\" gui-text=\"" N_("Inverted") "\" type=\"bool\" >false</param>\n"
73 "</page>\n"
74 "<page name=\"co11tab\" gui-text=\"" N_("Noise color") "\">\n"
75 "<param name=\"color\" gui-text=\"" N_("Color") "\" type=\"color\">354957823</param>\n"
76 "</page>\n"
77 "</param>\n"
78 "<effect>\n"
79 "<object-type>all</object-type>\n"
80 "<effects-menu>\n"
81 "<submenu name=\"" N_("Filters") "\">\n"
82 "<submenu name=\"" N_("Overlays") "\"/>\n"
83 "</submenu>\n"
84 "</effects-menu>\n"
85 "<menu-tip>" N_("Basic noise fill and transparency texture") "</menu-tip>\n"
86 "</effect>\n"
87 "</inkscape-extension>\n", new NoiseFill());
88 // clang-format on
89 };
90
91 };
92
93 gchar const *
get_filter_text(Inkscape::Extension::Extension * ext)94 NoiseFill::get_filter_text (Inkscape::Extension::Extension * ext)
95 {
96 if (_filter != nullptr) g_free((void *)_filter);
97
98 std::ostringstream type;
99 std::ostringstream hfreq;
100 std::ostringstream vfreq;
101 std::ostringstream complexity;
102 std::ostringstream variation;
103 std::ostringstream dilat;
104 std::ostringstream erosion;
105 std::ostringstream r;
106 std::ostringstream g;
107 std::ostringstream b;
108 std::ostringstream a;
109 std::ostringstream inverted;
110
111 type << ext->get_param_optiongroup("type");
112 hfreq << (ext->get_param_float("hfreq") / 1000);
113 vfreq << (ext->get_param_float("vfreq") / 1000);
114 complexity << ext->get_param_int("complexity");
115 variation << ext->get_param_int("variation");
116 dilat << ext->get_param_float("dilat");
117 erosion << (- ext->get_param_float("erosion"));
118 guint32 color = ext->get_param_color("color");
119 r << ((color >> 24) & 0xff);
120 g << ((color >> 16) & 0xff);
121 b << ((color >> 8) & 0xff);
122 a << (color & 0xff) / 255.0F;
123 if (ext->get_param_bool("inverted"))
124 inverted << "out";
125 else
126 inverted << "in";
127
128 _filter = g_strdup_printf(
129 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" style=\"color-interpolation-filters:sRGB;\" inkscape:label=\"Noise Fill\">\n"
130 "<feTurbulence type=\"%s\" baseFrequency=\"%s %s\" numOctaves=\"%s\" seed=\"%s\" result=\"turbulence\"/>\n"
131 "<feComposite in=\"SourceGraphic\" in2=\"turbulence\" operator=\"%s\" result=\"composite1\" />\n"
132 "<feColorMatrix values=\"1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 %s %s \" result=\"color\" />\n"
133 "<feFlood flood-opacity=\"%s\" flood-color=\"rgb(%s,%s,%s)\" result=\"flood\" />\n"
134 "<feMerge result=\"merge\">\n"
135 "<feMergeNode in=\"flood\" />\n"
136 "<feMergeNode in=\"color\" />\n"
137 "</feMerge>\n"
138 "<feComposite in2=\"SourceGraphic\" operator=\"in\" result=\"composite2\" />\n"
139 "</filter>\n", type.str().c_str(), hfreq.str().c_str(), vfreq.str().c_str(), complexity.str().c_str(), variation.str().c_str(), inverted.str().c_str(), dilat.str().c_str(), erosion.str().c_str(), a.str().c_str(), r.str().c_str(), g.str().c_str(), b.str().c_str());
140
141 return _filter;
142 }; /* NoiseFill filter */
143
144 }; /* namespace Filter */
145 }; /* namespace Internal */
146 }; /* namespace Extension */
147 }; /* namespace Inkscape */
148
149 /* Change the 'OVERLAYS' below to be your file name */
150 #endif /* SEEN_INKSCAPE_EXTENSION_INTERNAL_FILTER_OVERLAYS_H__ */
151