Inkscape
Vector Graphics Editor
textures.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2#ifndef SEEN_INKSCAPE_EXTENSION_INTERNAL_FILTER_TEXTURES_H__
3#define SEEN_INKSCAPE_EXTENSION_INTERNAL_FILTER_TEXTURES_H__
4/* Change the 'TEXTURES' 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 * Protrusion filters
12 * Ink blot
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
21#include "extension/system.h"
22#include "extension/extension.h"
23
24namespace Inkscape {
25namespace Extension {
26namespace Internal {
27namespace Filter {
28
29
52protected:
53 gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override;
54
55public:
56 InkBlot ( ) : Filter() { };
57 ~InkBlot ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; }
58
59public:
60 static void init () {
61 // clang-format off
63 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
64 "<name>" N_("Ink Blot") "</name>\n"
65 "<id>org.inkscape.effect.filter.InkBlot</id>\n"
66 "<param name=\"type\" gui-text=\"" N_("Turbulence type:") "\" type=\"optiongroup\" appearance=\"combo\">\n"
67 "<option value=\"fractalNoise\">Fractal noise</option>\n"
68 "<option value=\"turbulence\">Turbulence</option>\n"
69 "</param>\n"
70 "<param name=\"freq\" gui-text=\"" N_("Frequency:") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0.01\" max=\"100.00\">4</param>\n"
71 "<param name=\"complexity\" gui-text=\"" N_("Complexity:") "\" type=\"int\" appearance=\"full\" min=\"1\" max=\"5\">3</param>\n"
72 "<param name=\"variation\" gui-text=\"" N_("Variation:") "\" type=\"int\" appearance=\"full\" min=\"0\" max=\"100\">0</param>\n"
73 "<param name=\"hblur\" gui-text=\"" N_("Horizontal inlay:") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0.01\" max=\"30.00\">10</param>\n"
74 "<param name=\"vblur\" gui-text=\"" N_("Vertical inlay:") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0.01\" max=\"30.00\">10</param>\n"
75 "<param name=\"displacement\" gui-text=\"" N_("Displacement:") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0.\" max=\"100.00\">50</param>\n"
76 "<param name=\"blend\" gui-text=\"" N_("Blend:") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0.01\" max=\"30.00\">5</param>\n"
77 "<param name=\"stroke\" gui-text=\"" N_("Stroke:") "\" type=\"optiongroup\" appearance=\"combo\">\n"
78 "<option value=\"over\">" N_("Wide") "</option>\n"
79 "<option value=\"atop\">" N_("Normal") "</option>\n"
80 "<option value=\"in\">" N_("Narrow") "</option>\n"
81 "<option value=\"xor\">" N_("Overlapping") "</option>\n"
82 "<option value=\"out\">" N_("External") "</option>\n"
83 "<option value=\"arithmetic\">" N_("Custom") "</option>\n"
84 "</param>\n"
85 "<label appearance=\"header\">" N_("Custom stroke options") "</label>\n"
86 "<param name=\"k1\" gui-text=\"" N_("k1:") "\" type=\"float\" indent=\"1\" appearance=\"full\" precision=\"2\" min=\"-10.\" max=\"10.\">1.5</param>\n"
87 "<param name=\"k2\" gui-text=\"" N_("k2:") "\" type=\"float\" indent=\"1\" appearance=\"full\" precision=\"2\" min=\"-10.\" max=\"10.\">-0.25</param>\n"
88 "<param name=\"k3\" gui-text=\"" N_("k3:") "\" type=\"float\" indent=\"1\" appearance=\"full\" precision=\"2\" min=\"-10.\" max=\"10.\">0.5</param>\n"
89 "<effect>\n"
90 "<object-type>all</object-type>\n"
91 "<effects-menu>\n"
92 "<submenu name=\"" N_("Filters") "\">\n"
93 "<submenu name=\"Textures\"/>\n"
94 "</submenu>\n"
95 "</effects-menu>\n"
96 "<menu-tip>" N_("Inkblot on tissue or rough paper") "</menu-tip>\n"
97 "</effect>\n"
98 "</inkscape-extension>\n", std::make_unique<InkBlot>());
99 // clang-format on
100 };
101
102};
103
104gchar const *
106{
107 if (_filter != nullptr) g_free((void *)_filter);
108
109 std::ostringstream type;
110 std::ostringstream freq;
111 std::ostringstream complexity;
112 std::ostringstream variation;
113 std::ostringstream hblur;
114 std::ostringstream vblur;
115 std::ostringstream displacement;
116 std::ostringstream blend;
117 std::ostringstream stroke;
118 std::ostringstream custom;
119
120 type << ext->get_param_optiongroup("type");
121 freq << ext->get_param_float("freq") / 100;
122 complexity << ext->get_param_int("complexity");
123 variation << ext->get_param_int("variation");
124 hblur << ext->get_param_float("hblur");
125 vblur << ext->get_param_float("vblur");
126 displacement << ext->get_param_float("displacement");
127 blend << ext->get_param_float("blend");
128
129 const gchar *ope = ext->get_param_optiongroup("stroke");
130 if (g_ascii_strcasecmp("arithmetic", ope) == 0) {
131 custom << "k1=\"" << ext->get_param_float("k1") << "\" k2=\"" << ext->get_param_float("k2") << "\" k3=\"" << ext->get_param_float("k3") << "\"";
132 } else {
133 custom << "";
134 }
135
136 stroke << ext->get_param_optiongroup("stroke");
137
138 // clang-format off
139 _filter = g_strdup_printf(
140 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" style=\"color-interpolation-filters:sRGB;\" x=\"-0.15\" width=\"1.3\" y=\"-0.15\" height=\"1.3\" inkscape:label=\"Ink Blot\" >\n"
141 "<feGaussianBlur in=\"SourceGraphic\" stdDeviation=\"%s %s\" result=\"blur1\" />\n"
142 "<feTurbulence type=\"%s\" baseFrequency=\"%s\" numOctaves=\"%s\" seed=\"%s\" result=\"turbulence\" />\n"
143 "<feDisplacementMap in=\"blur1\" in2=\"turbulence\" xChannelSelector=\"R\" yChannelSelector=\"G\" scale=\"%s\" result=\"map\" />\n"
144 "<feGaussianBlur in=\"map\" stdDeviation=\"%s\" result=\"blur2\" />\n"
145 "<feComposite in=\"blur2\" in2=\"map\" %s operator=\"%s\" result=\"composite\" />\n"
146 "</filter>\n", hblur.str().c_str(), vblur.str().c_str(), type.str().c_str(),
147 freq.str().c_str(), complexity.str().c_str(), variation.str().c_str(),
148 displacement.str().c_str(), blend.str().c_str(),
149 custom.str().c_str(), stroke.str().c_str() );
150 // clang-format on
151
152 return _filter;
153
154}; /* Ink Blot filter */
155
156
157}; /* namespace Filter */
158}; /* namespace Internal */
159}; /* namespace Extension */
160}; /* namespace Inkscape */
161
162/* Change the 'TEXTURES' below to be your file name */
163#endif /* SEEN_INKSCAPE_EXTENSION_INTERNAL_FILTER_TEXTURES_H__ */
The object that is the basis for the Extension system.
Definition: extension.h:130
char const * get_param_optiongroup(char const *name, char const *alt) const
Like get_param_optiongroup but with a default on param_not_exist error.
Definition: extension.cpp:757
int get_param_int(char const *name) const
Gets a parameter identified by name with the integer placed in value.
Definition: extension.cpp:662
double get_param_float(char const *name) const
Gets a float parameter identified by name with the double placed in value.
Definition: extension.cpp:690
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 Ink Blot filter.
Definition: textures.h:51
gchar const * get_filter_text(Inkscape::Extension::Extension *ext) override
Definition: textures.h:105
A way to clear the N_ macro, which is defined as an inline function.
bool custom
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:471
CMYK to sRGB conversion routines.