From: JazzyNico Date: Tue, 14 Sep 2010 18:21:32 +0000 (+0200) Subject: Filters. New customizable Poster effect (experimental). X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=0747a715dfb923b3830645003fd63749786d6c09;p=inkscape.git Filters. New customizable Poster effect (experimental). --- 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) + * + * 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( + "\n" + "" N_("Posterize, custom -EXP-") "\n" + "org.inkscape.effect.filter.Posterize\n" + "\n" + "<_item value=\"normal\">Normal\n" + "<_item value=\"contrasted\">Contrasted\n" + "\n" + "3\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "" N_("Change colors to a two colors palette") "\n" + "\n" + "\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( + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\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