From fbfeeabdab77219c5eacb5bc3144dc7f66de1b53 Mon Sep 17 00:00:00 2001 From: JazzyNico Date: Sun, 21 Nov 2010 11:07:00 +0100 Subject: [PATCH] Filters. New custom predefined filters (Colorize and Quadritone fantasy) and some minor fixes. --- src/extension/internal/filter/color.h | 180 +++++++++++++++++++ src/extension/internal/filter/experimental.h | 4 +- src/extension/internal/filter/filter-all.cpp | 11 +- 3 files changed, 190 insertions(+), 5 deletions(-) diff --git a/src/extension/internal/filter/color.h b/src/extension/internal/filter/color.h index 1a1644276..e13deaf2c 100644 --- a/src/extension/internal/filter/color.h +++ b/src/extension/internal/filter/color.h @@ -22,6 +22,103 @@ namespace Extension { namespace Internal { namespace Filter { +/* Custom predefined Colorize filter */ +class Colorize : public Inkscape::Extension::Internal::Filter::Filter { +protected: + virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext); + +public: + Colorize ( ) : Filter() { }; + virtual ~Colorize ( ) { if (_filter != NULL) g_free((void *)_filter); return; } + + static void init (void) { + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Colorize, custom -EXP-") "\n" + "org.inkscape.effect.filter.Colorize\n" + "0\n" + "1\n" + "false\n" + "false\n" + "\n" + "<_item value=\"multiply\">Multiply\n" + "<_item value=\"normal\">Normal\n" + "<_item value=\"screen\">Screen\n" + "<_item value=\"lighten\">Lighten\n" + "<_item value=\"darken\">Darken\n" + "\n" + "\n" + "<_item value=\"screen\">Screen\n" + "<_item value=\"multiply\">Multiply\n" + "<_item value=\"normal\">Normal\n" + "<_item value=\"lighten\">Lighten\n" + "<_item value=\"darken\">Darken\n" + "\n" + "-1639776001\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "" N_("Blend image or object with a flood color") "\n" + "\n" + "\n", new Colorize()); + }; + +}; + +gchar const * +Colorize::get_filter_text (Inkscape::Extension::Extension * ext) +{ + if (_filter != NULL) g_free((void *)_filter); + + std::ostringstream a; + std::ostringstream r; + std::ostringstream g; + std::ostringstream b; + std::ostringstream hlight; + std::ostringstream nlight; + std::ostringstream duotone; + std::ostringstream fg; + std::ostringstream blend1; + std::ostringstream blend2; + + guint32 color = ext->get_param_color("color"); + r << ((color >> 24) & 0xff); + g << ((color >> 16) & 0xff); + b << ((color >> 8) & 0xff); + a << (color & 0xff) / 255.0F; + + hlight << ext->get_param_float("hlight"); + nlight << ext->get_param_float("nlight"); + blend1 << ext->get_param_enum("blend1"); + blend2 << ext->get_param_enum("blend2"); + if (ext->get_param_bool("duotone")) + duotone << "0"; + else + duotone << "1"; + if (ext->get_param_bool("fg")) + fg << "0"; + else + fg << "1"; + + _filter = g_strdup_printf( + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n", hlight.str().c_str(), nlight.str().c_str(), duotone.str().c_str(), a.str().c_str(), r.str().c_str(), g.str().c_str(), b.str().c_str(), blend1.str().c_str(), blend2.str().c_str(), fg.str().c_str()); + + return _filter; +}; + +/* Custom predefined Duochrome filter */ class Duochrome : public Inkscape::Extension::Internal::Filter::Filter { protected: virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext); @@ -127,6 +224,89 @@ Duochrome::get_filter_text (Inkscape::Extension::Extension * ext) return _filter; }; + +/* Custom predefined Quadritone filter */ +/* +- "Répartition" = Matrice de couleurs 1 (de 0 à 360, défaut sur 280) +- "Colors" = Matrice de couleurs 3 (de 0 à 360, défaut sur 100) +- "Blend 1" = Blend 1 (Normal, Multiply et Superposition sont suffisantes) +- "Oversaturation" = Composite 1 arithmetic (K2 de 0 à 1, défaut sur 0) +- "Blend 2" = Blend 2 (les cinq options disponibles) +*/ + +class Quadritone : public Inkscape::Extension::Internal::Filter::Filter { +protected: + virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext); + +public: + Quadritone ( ) : Filter() { }; + virtual ~Quadritone ( ) { if (_filter != NULL) g_free((void *)_filter); return; } + + static void init (void) { + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Quadritone fantasy, custom -EXP-") "\n" + "org.inkscape.effect.filter.Quadritone\n" + "280\n" + "100\n" + "\n" + "<_item value=\"normal\">Normal\n" + "<_item value=\"multiply\">Multiply\n" + "<_item value=\"screen\">Screen\n" + "\n" + "0\n" + "\n" + "<_item value=\"screen\">Screen\n" + "<_item value=\"multiply\">Multiply\n" + "<_item value=\"normal\">Normal\n" + "<_item value=\"lighten\">Lighten\n" + "<_item value=\"darken\">Darken\n" + "\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "" N_("Replace hue by two colors") "\n" + "\n" + "\n", new Quadritone()); + }; + +}; + +gchar const * +Quadritone::get_filter_text (Inkscape::Extension::Extension * ext) +{ + if (_filter != NULL) g_free((void *)_filter); + + std::ostringstream dist; + std::ostringstream colors; + std::ostringstream blend1; + std::ostringstream sat; + std::ostringstream blend2; + + dist << ext->get_param_int("dist"); + colors << ext->get_param_int("colors"); + blend1 << ext->get_param_enum("blend1"); + sat << ext->get_param_float("sat"); + blend2 << ext->get_param_enum("blend2"); + + _filter = g_strdup_printf( + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n", dist.str().c_str(), colors.str().c_str(), blend1.str().c_str(), sat.str().c_str(), blend2.str().c_str()); + + return _filter; +}; + }; /* namespace Filter */ }; /* namespace Internal */ }; /* namespace Extension */ diff --git a/src/extension/internal/filter/experimental.h b/src/extension/internal/filter/experimental.h index 15c97202e..7bf27bee8 100644 --- a/src/extension/internal/filter/experimental.h +++ b/src/extension/internal/filter/experimental.h @@ -45,7 +45,7 @@ public: "\n" "5\n" "\n" - "<_item value=\"lighten\">Ligthen\n" + "<_item value=\"lighten\">Lighten\n" "<_item value=\"normal\">Normal\n" "<_item value=\"darken\">Darken\n" "\n" @@ -124,7 +124,7 @@ Posterize::get_filter_text (Inkscape::Extension::Extension * ext) "\n" "\n" "\n" - "\n" + "\n" "\n", blur1.str().c_str(), blur2.str().c_str(), blendmode.str().c_str(), presat.str().c_str(), table.str().c_str(), transf.str().c_str(), table.str().c_str(), transf.str().c_str(), table.str().c_str(), transf.str().c_str(), postsat.str().c_str(), antialias.str().c_str()); return _filter; diff --git a/src/extension/internal/filter/filter-all.cpp b/src/extension/internal/filter/filter-all.cpp index 6920e1bac..04e760de1 100644 --- a/src/extension/internal/filter/filter-all.cpp +++ b/src/extension/internal/filter/filter-all.cpp @@ -23,13 +23,18 @@ void Filter::filters_all (void ) { // Here come the filters which are coded in C++ in order to present a parameters dialog - Duochrome::init(); DropShadow::init(); DropGlow::init(); - ColorizableDropShadow::init(); Snow::init(); - // Experimental! + // Experimental + // Color + Colorize::init(); + Duochrome::init(); + Quadritone::init(); + // Shadows and glows + ColorizableDropShadow::init(); + // TDB Posterize::init(); // Here come the rest of the filters that are read from SVG files in share/filters and -- 2.30.2