summaryrefslogtreecommitdiffstats
path: root/src/extension/internal/filter/protrusions.h
blob: ccf54b4763d828eb9d0609a27025258a071390d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// SPDX-License-Identifier: GPL-2.0-or-later
#ifndef SEEN_INKSCAPE_EXTENSION_INTERNAL_FILTER_PROTRUSIONS_H__
#define SEEN_INKSCAPE_EXTENSION_INTERNAL_FILTER_PROTRUSIONS_H__
/* Change the 'PROTRUSIONS' above to be your file name */

/*
 * Copyright (C) 2008 Authors:
 *   Ted Gould <ted@gould.cx>
 * Copyright (C) 2011 Authors:
 *   Ivan Louette (filters)
 *   Nicolas Dufour (UI) <nicoduf@yahoo.fr>
 *
 * Protrusion filters
 *   Snow
 *
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */
/* ^^^ Change the copyright to be you and your e-mail address ^^^ */

#include "filter.h"

#include "extension/internal/clear-n_.h"
#include "extension/system.h"
#include "extension/extension.h"

namespace Inkscape {
namespace Extension {
namespace Internal {
namespace Filter {


/**
    \brief    Custom predefined Snow filter.
    
    Snow has fallen on object.
*/
class Snow : public Inkscape::Extension::Internal::Filter::Filter {
protected:
	gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override;

public:
	Snow ( ) : Filter() { };
	~Snow ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; }

public:
	static void init () {
		// clang-format off
		Inkscape::Extension::build_from_mem(
			"<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
				"<name>" N_("Snow Crest") "</name>\n"
				"<id>org.inkscape.effect.filter.snow</id>\n"
				"<param name=\"drift\" gui-text=\"" N_("Drift Size") "\" type=\"float\" appearance=\"full\" min=\"0.0\" max=\"20.0\">3.5</param>\n"
				"<effect>\n"
					"<object-type>all</object-type>\n"
					"<effects-menu>\n"
						"<submenu name=\"" N_("Filters") "\">\n"
   						"<submenu name=\"Protrusions\"/>\n"
			      "</submenu>\n"
					"</effects-menu>\n"
					"<menu-tip>" N_("Snow has fallen on object") "</menu-tip>\n"
				"</effect>\n"
			"</inkscape-extension>\n", new Snow());
		// clang-format on
	};

};

gchar const *
Snow::get_filter_text (Inkscape::Extension::Extension * ext)
{
	if (_filter != nullptr) g_free((void *)_filter);

        std::ostringstream drift;
        drift << ext->get_param_float("drift");

	// clang-format off
	_filter = g_strdup_printf(
				"<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" style=\"color-interpolation-filters:sRGB;\" inkscape:label=\"Snow\">\n"
					"<feConvolveMatrix order=\"3 3\" kernelMatrix=\"1 1 1 0 0 0 -1 -1 -1\" preserveAlpha=\"false\" divisor=\"3\"/>\n"
					"<feMorphology operator=\"dilate\" radius=\"1 %s\"/>\n"
					"<feGaussianBlur stdDeviation=\"1.6270889487870621\" result=\"result0\"/>\n"
					"<feColorMatrix values=\"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 0\" result=\"result1\"/>\n"
					"<feOffset dx=\"0\" dy=\"1\" result=\"result5\"/>\n"
					"<feDiffuseLighting in=\"result0\" diffuseConstant=\"2.2613065326633168\" surfaceScale=\"1\">\n"
					  "<feDistantLight azimuth=\"225\" elevation=\"32\"/>\n"
					"</feDiffuseLighting>\n"
					"<feComposite in2=\"result1\" operator=\"in\" result=\"result2\"/>\n"
					"<feColorMatrix values=\"0.4 0 0 0 0.6 0 0.4 0 0 0.6 0 0 0 0 1 0 0 0 1 0\" result=\"result4\"/>\n"
					"<feComposite in2=\"result5\" in=\"result4\"/>\n"
					"<feComposite in2=\"SourceGraphic\"/>\n"
				"</filter>\n", drift.str().c_str());
	// clang-format on

	return _filter;
}; /* Snow filter */


}; /* namespace Filter */
}; /* namespace Internal */
}; /* namespace Extension */
}; /* namespace Inkscape */

/* Change the 'PROTRUSIONS' below to be your file name */
#endif /* SEEN_INKSCAPE_EXTENSION_INTERNAL_FILTER_PROTRUSIONS_H__ */