diff options
| author | Nicolas Dufour <nicoduf@yahoo.fr> | 2010-09-14 18:21:32 +0000 |
|---|---|---|
| committer | JazzyNico <nicoduf@yahoo.fr> | 2010-09-14 18:21:32 +0000 |
| commit | 4f73d97fb70c0ff427ae85afc5fecd6095c7097b (patch) | |
| tree | c4d91904a3de168d6d23cf106fd6416c87ad3d72 /src | |
| parent | Filters. Experimental filters improvements (new default values and options). (diff) | |
| download | inkscape-4f73d97fb70c0ff427ae85afc5fecd6095c7097b.tar.gz inkscape-4f73d97fb70c0ff427ae85afc5fecd6095c7097b.zip | |
Filters. New customizable Poster effect (experimental).
(bzr r9761)
Diffstat (limited to 'src')
| -rw-r--r-- | src/extension/internal/filter/experimental.h | 100 | ||||
| -rw-r--r-- | src/extension/internal/filter/filter-all.cpp | 4 |
2 files changed, 104 insertions, 0 deletions
diff --git a/src/extension/internal/filter/experimental.h b/src/extension/internal/filter/experimental.h new file mode 100644 index 000000000..af5a37b45 --- /dev/null +++ b/src/extension/internal/filter/experimental.h @@ -0,0 +1,100 @@ +#ifndef __INKSCAPE_EXTENSION_INTERNAL_FILTER_EXPERIMENTAL_H__ +#define __INKSCAPE_EXTENSION_INTERNAL_FILTER_EXPERIMENTAL_H__ +/* Change the 'EXPERIMENTAL' above to be your file name */ + +/* + * Copyright (C) 2010 Authors: + * Ivan Louette (filters) + * Nicolas Dufour (UI) <nicoduf@yahoo.fr> + * + * Released under GNU GPL, 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 { + +class Posterize : public Inkscape::Extension::Internal::Filter::Filter { +protected: + virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext); + +public: + Posterize ( ) : Filter() { }; + virtual ~Posterize ( ) { if (_filter != NULL) g_free((void *)_filter); return; } + + static void init (void) { + Inkscape::Extension::build_from_mem( + "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n" + "<name>" N_("Posterize, custom -EXP-") "</name>\n" + "<id>org.inkscape.effect.filter.Posterize</id>\n" + "<param name=\"type\" gui-text=\"" N_("Type:") "\" type=\"enum\">\n" + "<_item value=\"normal\">Normal</_item>\n" + "<_item value=\"contrasted\">Contrasted</_item>\n" + "</param>\n" + "<param name=\"level\" gui-text=\"" N_("Level:") "\" type=\"int\" min=\"1\" max=\"10\">3</param>\n" + "<effect>\n" + "<object-type>all</object-type>\n" + "<effects-menu>\n" + "<submenu name=\"" N_("Filters") "\">\n" + "<submenu name=\"" N_("Experimental") "\"/>\n" + "</submenu>\n" + "</effects-menu>\n" + "<menu-tip>" N_("Change colors to a two colors palette") "</menu-tip>\n" + "</effect>\n" + "</inkscape-extension>\n", new Posterize()); + }; + +}; + +gchar const * +Posterize::get_filter_text (Inkscape::Extension::Extension * ext) +{ + if (_filter != NULL) g_free((void *)_filter); + + std::ostringstream transf; + + int level = ext->get_param_int("level") + 1; + const gchar *type = ext->get_param_enum("type"); + float val = 0.0; + transf << "0"; + for ( int step = 1 ; step <= level ; step++ ) { + val = (float) step / level; + transf << " " << val; + if((g_ascii_strcasecmp("contrasted", type) == 0)) { + transf << " " << (val - ((float) 1 / (3 * level))) << " " << (val + ((float) 1 / (2 * level))); + } + } + transf << " 1"; + + _filter = g_strdup_printf( + "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" color-interpolation-filters=\"sRGB\" height=\"1\" width=\"1\" y=\"0\" x=\"0\" inkscape:label=\"Posterize, custom -EXP-\">\n" + "<feGaussianBlur stdDeviation=\"1.5\" result=\"result3\" />\n" + "<feGaussianBlur stdDeviation=\"1.5\" in=\"SourceGraphic\" result=\"result4\" />\n" + "<feBlend in2=\"result3\" blend=\"normal\" mode=\"lighten\" />\n" + "<feComponentTransfer result=\"result1\">\n" + "<feFuncR type=\"discrete\" tableValues=\"%s\" />\n" + "<feFuncG type=\"discrete\" tableValues=\"%s\" />\n" + "<feFuncB type=\"discrete\" tableValues=\"%s\" />\n" + "</feComponentTransfer>\n" + "<feColorMatrix type=\"saturate\" values=\"1\" />\n" + "<feGaussianBlur stdDeviation=\"0.01\" />\n" + "<feComposite in2=\"SourceGraphic\" operator=\"atop\" result=\"result2\" />\n" + "</filter>\n", transf.str().c_str(), transf.str().c_str(), transf.str().c_str()); + + return _filter; +}; +}; /* namespace Filter */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ + +/* Change the 'COLOR' below to be your file name */ +#endif /* __INKSCAPE_EXTENSION_INTERNAL_FILTER_EXPERIMENTAL_H__ */ diff --git a/src/extension/internal/filter/filter-all.cpp b/src/extension/internal/filter/filter-all.cpp index ef168e09e..6920e1bac 100644 --- a/src/extension/internal/filter/filter-all.cpp +++ b/src/extension/internal/filter/filter-all.cpp @@ -11,6 +11,7 @@ #include "color.h" #include "drop-shadow.h" #include "snow.h" +#include "experimental.h" namespace Inkscape { namespace Extension { @@ -27,6 +28,9 @@ Filter::filters_all (void ) DropGlow::init(); ColorizableDropShadow::init(); Snow::init(); + + // Experimental! + Posterize::init(); // Here come the rest of the filters that are read from SVG files in share/filters and // .config/Inkscape/filters |
