From c1e8d3c29bde66b87e8f19bb859d074e77a9e982 Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Wed, 10 Aug 2011 21:39:47 +0200 Subject: Filters. New Blend, Extract Channel and Ink Blot custom predefined filters. (bzr r10534) --- src/extension/internal/filter/bumps.h | 3 +- src/extension/internal/filter/color.h | 103 +++++++++++++++++++++++++++ src/extension/internal/filter/filter-all.cpp | 5 +- src/extension/internal/filter/transparency.h | 68 ++++++++++++++++++ 4 files changed, 176 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/extension/internal/filter/bumps.h b/src/extension/internal/filter/bumps.h index 9d46a25b2..b8617eafc 100644 --- a/src/extension/internal/filter/bumps.h +++ b/src/extension/internal/filter/bumps.h @@ -698,13 +698,12 @@ WaxBump::get_filter_text (Inkscape::Extension::Extension * ext) _filter = g_strdup_printf( "\n" "\n" - "\n" + "\n" "\n" "\n" "\n" "\n" "\n" - "\n" "\n" "\n" diff --git a/src/extension/internal/filter/color.h b/src/extension/internal/filter/color.h index b34c2c61f..fb6ea0ab9 100644 --- a/src/extension/internal/filter/color.h +++ b/src/extension/internal/filter/color.h @@ -13,6 +13,7 @@ * Color shift * Colorize * Duochrome + * Extract channel * Greyscale * Invert * Lightness @@ -517,6 +518,108 @@ Duochrome::get_filter_text (Inkscape::Extension::Extension * ext) return _filter; }; /* Duochrome filter */ +/** + \brief Custom predefined Extract Channel filter. + + Extract color channel as a transparent image. + + Filter's parameters: + * Channel (enum, all colors, default Red) -> colormatrix (values) + * Background blend (enum, all blend modes, default Multiply) -> blend (mode) + * Channel to alpha (boolean, default false) -> colormatrix (values) + * Invert (boolean, default false) -> colormatrix (values) + +*/ +class ExtractChannel : public Inkscape::Extension::Internal::Filter::Filter { +protected: + virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext); + +public: + ExtractChannel ( ) : Filter() { }; + virtual ~ExtractChannel ( ) { if (_filter != NULL) g_free((void *)_filter); return; } + + static void init (void) { + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Extract Channel") "\n" + "org.inkscape.effect.filter.ExtractChannel\n" + "\n" + "<_item value=\"r\">" N_("Red") "\n" + "<_item value=\"g\">" N_("Green") "\n" + "<_item value=\"b\">" N_("Blue") "\n" + "\n" + "\n" + "<_item value=\"multiply\">" N_("Multiply") "\n" + "<_item value=\"normal\">" N_("Normal") "\n" + "<_item value=\"screen\">" N_("Screen") "\n" + "<_item value=\"darken\">" N_("Darken") "\n" + "<_item value=\"lighten\">" N_("Lighten") "\n" + "\n" + "false\n" + "false\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "" N_("Extract color channel as a transparent image") "\n" + "\n" + "\n", new ExtractChannel()); + }; +}; + +gchar const * +ExtractChannel::get_filter_text (Inkscape::Extension::Extension * ext) +{ + if (_filter != NULL) g_free((void *)_filter); + + std::ostringstream blend; + std::ostringstream colors; + std::ostringstream alpha; + std::ostringstream invert; + + blend << ext->get_param_enum("blend"); + + const gchar *channel = ext->get_param_enum("source"); + if (ext->get_param_bool("alpha")) { + colors << "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"; + } else if ((g_ascii_strcasecmp("r", channel) == 0)) { + colors << "0 0 0 0 1 0 0 0 0 0 0 0 0 0 0"; + } else if ((g_ascii_strcasecmp("g", channel) == 0)) { + colors << "0 0 0 0 0 0 0 0 0 1 0 0 0 0 0"; + } else { + colors << "0 0 0 0 0 0 0 0 0 0 0 0 0 0 1"; + } + + if (ext->get_param_bool("invert")) { + if ((g_ascii_strcasecmp("r", channel) == 0)) { + alpha << "-1 0 0 1"; + } else if ((g_ascii_strcasecmp("g", channel) == 0)) { + alpha << "0 -1 0 1"; + } else { + alpha << "0 0 -1 1"; + } + } else { + if ((g_ascii_strcasecmp("r", channel) == 0)) { + alpha << "1 0 0 0"; + } else if ((g_ascii_strcasecmp("g", channel) == 0)) { + alpha << "0 1 0 0"; + } else { + alpha << "0 0 1 0"; + } + } + + _filter = g_strdup_printf( + "\n" + "\n" + "\n" + "\n", colors.str().c_str(), alpha.str().c_str(), invert.str().c_str(), blend.str().c_str() ); + + return _filter; +}; /* ExtractChannel filter */ + /** \brief Custom predefined Greyscale filter. diff --git a/src/extension/internal/filter/filter-all.cpp b/src/extension/internal/filter/filter-all.cpp index dcd68b75a..30376d231 100755 --- a/src/extension/internal/filter/filter-all.cpp +++ b/src/extension/internal/filter/filter-all.cpp @@ -18,6 +18,7 @@ #include "paint.h" #include "protrusions.h" #include "shadows.h" +#include "textures.h" #include "transparency.h" namespace Inkscape { @@ -53,6 +54,7 @@ Filter::filters_all (void ) ColorShift::init(); Colorize::init(); Duochrome::init(); + ExtractChannel::init(); Greyscale::init(); Invert::init(); Lightness::init(); @@ -91,9 +93,10 @@ Filter::filters_all (void ) ColorizableDropShadow::init(); // Textures - // InkBlot::init(); + InkBlot::init(); // Fill and transparency + Blend::init(); ChannelTransparency::init(); Silhouette::init(); diff --git a/src/extension/internal/filter/transparency.h b/src/extension/internal/filter/transparency.h index f8f02575b..9fd6cac22 100644 --- a/src/extension/internal/filter/transparency.h +++ b/src/extension/internal/filter/transparency.h @@ -8,6 +8,7 @@ * Nicolas Dufour (UI) * * Fill and transparency filters + * Blend * Channel transparency * Silhouette * @@ -26,6 +27,73 @@ namespace Extension { namespace Internal { namespace Filter { +/** + \brief Custom predefined Blend filter. + + Blend objecs with background images or with themselves + + Filter's parameters: + * Source (enum [SourceGraphic,BackgroundImage], default BackgroundImage) -> blend (in2) + * Mode (enum, all blend modes, default Multiply) -> blend (mode) +*/ + +class Blend : public Inkscape::Extension::Internal::Filter::Filter { +protected: + virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext); + +public: + Blend ( ) : Filter() { }; + virtual ~Blend ( ) { if (_filter != NULL) g_free((void *)_filter); return; } + + static void init (void) { + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Blend") "\n" + "org.inkscape.effect.filter.Blend\n" + "\n" + "<_item value=\"BackgroundImage\">" N_("Background") "\n" + "<_item value=\"SourceGraphic\">" N_("Image") "\n" + "\n" + "\n" + "<_item value=\"multiply\">" N_("Multiply") "\n" + "<_item value=\"normal\">" N_("Normal") "\n" + "<_item value=\"screen\">" N_("Screen") "\n" + "<_item value=\"darken\">" N_("Darken") "\n" + "<_item value=\"lighten\">" N_("Lighten") "\n" + "\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "" N_("Blend objecs with background images or with themselves") "\n" + "\n" + "\n", new Blend()); + }; + +}; + +gchar const * +Blend::get_filter_text (Inkscape::Extension::Extension * ext) +{ + if (_filter != NULL) g_free((void *)_filter); + + std::ostringstream source; + std::ostringstream mode; + + source << ext->get_param_enum("source"); + mode << ext->get_param_enum("mode"); + + _filter = g_strdup_printf( + "\n" + "\n" + "\n", source.str().c_str(), mode.str().c_str() ); + + return _filter; +}; /* Blend filter */ + /** \brief Custom predefined Channel transparency filter. -- cgit v1.2.3