61fb8d42b747fca2848b4b5d59a3f9c2293b479b
1 #ifndef __INKSCAPE_EXTENSION_INTERNAL_FILTER_MORPHOLOGY_H__
2 #define __INKSCAPE_EXTENSION_INTERNAL_FILTER_MORPHOLOGY_H__
3 /* Change the 'MORPHOLOGY' above to be your file name */
5 /*
6 * Copyright (C) 2010 Authors:
7 * Ivan Louette (filters)
8 * Nicolas Dufour (UI) <nicoduf@yahoo.fr>
9 *
10 * Released under GNU GPL, read the file 'COPYING' for more information
11 */
12 /* ^^^ Change the copyright to be you and your e-mail address ^^^ */
14 #include "filter.h"
16 #include "extension/internal/clear-n_.h"
17 #include "extension/system.h"
18 #include "extension/extension.h"
20 namespace Inkscape {
21 namespace Extension {
22 namespace Internal {
23 namespace Filter {
25 /**
26 \brief Custom predefined Crosssmooth filter.
28 Smooth the outside of shapes and pictures.
30 Filter's parameters:
31 * Type (enum, default "Smooth all") ->
32 Smooth all = composite (in="colormatrix", in2="colormatrix")
33 Smooth edges = composite (in="SourceGraphic", in2="colormatrix")
34 * Blur (0.01->10., default 5.) -> blur (stdDeviation)
35 * Spreading (1->100, default 20) -> colormatrix (value n-1)
36 * Erosion (0->-100, default -15) -> colormatrix (value n)
37 */
39 class Crosssmooth : public Inkscape::Extension::Internal::Filter::Filter {
40 protected:
41 virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
43 public:
44 Crosssmooth ( ) : Filter() { };
45 virtual ~Crosssmooth ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
47 static void init (void) {
48 Inkscape::Extension::build_from_mem(
49 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
50 "<name>" N_("Cross-smooth, custom -EXP-") "</name>\n"
51 "<id>org.inkscape.effect.filter.Crosssmooth</id>\n"
52 "<param name=\"type\" gui-text=\"" N_("Type:") "\" type=\"enum\">\n"
53 "<_item value=\"all\">Smooth all</_item>\n"
54 "<_item value=\"edges\">Smooth edges</_item>\n"
55 "</param>\n"
56 "<param name=\"blur\" gui-text=\"" N_("Blur:") "\" type=\"float\" min=\"0.01\" max=\"10\">5</param>\n"
57 "<param name=\"spreading\" gui-text=\"" N_("Spreading:") "\" type=\"int\" min=\"1\" max=\"100\">20</param>\n"
58 "<param name=\"erosion\" gui-text=\"" N_("Erosion:") "\" type=\"int\" min=\"-100\" max=\"0\">-15</param>\n"
59 "<effect>\n"
60 "<object-type>all</object-type>\n"
61 "<effects-menu>\n"
62 "<submenu name=\"" N_("Filters") "\">\n"
63 "<submenu name=\"" N_("Experimental") "\"/>\n"
64 "</submenu>\n"
65 "</effects-menu>\n"
66 "<menu-tip>" N_("Smooth the outside of shapes and pictures without altering their contents") "</menu-tip>\n"
67 "</effect>\n"
68 "</inkscape-extension>\n", new Crosssmooth());
69 };
71 };
73 gchar const *
74 Crosssmooth::get_filter_text (Inkscape::Extension::Extension * ext)
75 {
76 if (_filter != NULL) g_free((void *)_filter);
78 std::ostringstream blur;
79 std::ostringstream spreading;
80 std::ostringstream erosion;
81 std::ostringstream cin;
83 blur << ext->get_param_float("blur");
84 spreading << ext->get_param_int("spreading");
85 erosion << ext->get_param_int("erosion");
87 const gchar *type = ext->get_param_enum("type");
88 if((g_ascii_strcasecmp("all", type) == 0)) {
89 cin << "colormatrix";
90 } else {
91 cin << "SourceGraphic";
92 }
94 _filter = g_strdup_printf(
95 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" color-interpolation-filters=\"sRGB\" height=\"1\" width=\"1\" y=\"0\" x=\"0\" inkscape:label=\"Cross-smooth, custom -EXP-\">\n"
96 "<feGaussianBlur stdDeviation=\"%s\" result=\"blur\" />\n"
97 "<feColorMatrix in=\"blur\" values=\"1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 %s %s \" result=\"colormatrix\" />\n"
98 "<feComposite in=\"%s\" in2=\"colormatrix\" operator=\"in\" />\n"
99 "</filter>\n", blur.str().c_str(), spreading.str().c_str(), erosion.str().c_str(), cin.str().c_str());
101 return _filter;
102 }; /* Crosssmooth filter */
104 }; /* namespace Filter */
105 }; /* namespace Internal */
106 }; /* namespace Extension */
107 }; /* namespace Inkscape */
109 /* Change the 'COLOR' below to be your file name */
110 #endif /* __INKSCAPE_EXTENSION_INTERNAL_FILTER_MORPHOLOGY_H__ */