From 79af2e1423d604b987e323c3a87ea755dfc4257c Mon Sep 17 00:00:00 2001 From: JazzyNico Date: Fri, 17 Sep 2010 15:02:18 +0200 Subject: [PATCH] Filters. Some experimental filters improvements. --- src/extension/internal/filter/color.h | 26 ++-- src/extension/internal/filter/experimental.h | 137 +++++++++++++++---- 2 files changed, 132 insertions(+), 31 deletions(-) diff --git a/src/extension/internal/filter/color.h b/src/extension/internal/filter/color.h index 08ba4b475..82a37a6aa 100644 --- a/src/extension/internal/filter/color.h +++ b/src/extension/internal/filter/color.h @@ -39,6 +39,7 @@ public: // "\n" // "\n" "false\n" + "false\n" "<_param name=\"header1\" type=\"groupheader\">Color 1\n" "1364325887\n" // "\n" @@ -75,10 +76,13 @@ Duochrome::get_filter_text (Inkscape::Extension::Extension * ext) std::ostringstream g2; std::ostringstream b2; std::ostringstream fluo; + std::ostringstream swapc; guint32 color1 = ext->get_param_color("color1"); guint32 color2 = ext->get_param_color("color2"); bool fluorescence = ext->get_param_bool("fluo"); + bool swapcolors = ext->get_param_bool("swapcolors"); + a1 << (color1 & 0xff) / 255.0F; r1 << ((color1 >> 24) & 0xff); g1 << ((color1 >> 16) & 0xff); @@ -87,24 +91,30 @@ Duochrome::get_filter_text (Inkscape::Extension::Extension * ext) r2 << ((color2 >> 24) & 0xff); g2 << ((color2 >> 16) & 0xff); b2 << ((color2 >> 8) & 0xff); - if (fluorescence) fluo << ""; - else fluo << " in=\"result6\""; + if (fluorescence) + fluo << ""; + else + fluo << " in=\"blend\""; + if (swapcolors) + swapc << "in"; + else + swapc << "out"; _filter = g_strdup_printf( "\n" "\n" - "\n" - "\n" + "\n" + "\n" "\n" "\n" - "\n" + "\n" "\n" "\n" "\n" - "\n" - "\n" + "\n" + "\n" "\n" - "\n", a1.str().c_str(), r1.str().c_str(), g1.str().c_str(), b1.str().c_str(), a2.str().c_str(), r2.str().c_str(), g2.str().c_str(), b2.str().c_str(), fluo.str().c_str()); + "\n", a1.str().c_str(), r1.str().c_str(), g1.str().c_str(), b1.str().c_str(), swapc.str().c_str(), a2.str().c_str(), r2.str().c_str(), g2.str().c_str(), b2.str().c_str(), fluo.str().c_str()); return _filter; }; diff --git a/src/extension/internal/filter/experimental.h b/src/extension/internal/filter/experimental.h index af5a37b45..15c97202e 100644 --- a/src/extension/internal/filter/experimental.h +++ b/src/extension/internal/filter/experimental.h @@ -33,13 +33,27 @@ public: static void init (void) { Inkscape::Extension::build_from_mem( "\n" - "" N_("Posterize, custom -EXP-") "\n" + "" N_("Poster and painting, custom -EXP-") "\n" "org.inkscape.effect.filter.Posterize\n" - "\n" + "\n" "<_item value=\"normal\">Normal\n" - "<_item value=\"contrasted\">Contrasted\n" + "<_item value=\"dented\">Dented\n" "\n" - "3\n" + "\n" + "<_item value=\"discrete\">Poster\n" + "<_item value=\"table\">Painting\n" + "\n" + "5\n" + "\n" + "<_item value=\"lighten\">Ligthen\n" + "<_item value=\"normal\">Normal\n" + "<_item value=\"darken\">Darken\n" + "\n" + "4.0\n" + "0.5\n" + "1.00\n" + "1.00\n" + "false\n" "\n" "all\n" "\n" @@ -47,7 +61,7 @@ public: "\n" "\n" "\n" - "" N_("Change colors to a two colors palette") "\n" + "" N_("Poster and painting effects") "\n" "\n" "\n", new Posterize()); }; @@ -59,35 +73,112 @@ Posterize::get_filter_text (Inkscape::Extension::Extension * ext) { if (_filter != NULL) g_free((void *)_filter); + std::ostringstream table; + std::ostringstream blendmode; + std::ostringstream blur1; + std::ostringstream blur2; + std::ostringstream presat; + std::ostringstream postsat; std::ostringstream transf; + std::ostringstream antialias; + + table << ext->get_param_enum("table"); + blendmode << ext->get_param_enum("blend"); + blur1 << ext->get_param_float("blur1") + 0.01; + blur2 << ext->get_param_float("blur2") + 0.01; + presat << ext->get_param_float("presaturation"); + postsat << ext->get_param_float("postsaturation"); - int level = ext->get_param_int("level") + 1; - const gchar *type = ext->get_param_enum("type"); - float val = 0.0; + + // TransfertComponenet table values are calculated based on the poster type. transf << "0"; - for ( int step = 1 ; step <= level ; step++ ) { - val = (float) step / level; + int levels = ext->get_param_int("levels") + 1; + const gchar *effecttype = ext->get_param_enum("type"); + float val = 0.0; + for ( int step = 1 ; step <= levels ; step++ ) { + val = (float) step / levels; transf << " " << val; - if((g_ascii_strcasecmp("contrasted", type) == 0)) { - transf << " " << (val - ((float) 1 / (3 * level))) << " " << (val + ((float) 1 / (2 * level))); + if((g_ascii_strcasecmp("dented", effecttype) == 0)) { + transf << " " << (val - ((float) 1 / (3 * levels))) << " " << (val + ((float) 1 / (2 * levels))); } } transf << " 1"; + + if (ext->get_param_bool("antialiasing")) + antialias << "0.5"; + else + antialias << "0.01"; + + + _filter = g_strdup_printf( + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "\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; +}; + +class TestFilter : public Inkscape::Extension::Internal::Filter::Filter { +protected: + virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext); + +public: + TestFilter ( ) : Filter() { }; + virtual ~TestFilter ( ) { if (_filter != NULL) g_free((void *)_filter); return; } + + static void init (void) { + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Test Filter -EXP-") "\n" + "org.inkscape.effect.filter.TestFilter\n" + "<_param name=\"header1\" type=\"groupheader\">Test filter\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "" N_("Change colors to a two colors palette") "\n" + "\n" + "\n", new TestFilter()); + }; + +}; +gchar const * +TestFilter::get_filter_text (Inkscape::Extension::Extension * ext) +{ + if (_filter != NULL) g_free((void *)_filter); + _filter = g_strdup_printf( - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "\n" + "\n" + "\n" + "\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()); + "\n" + "\n" + "\n"); return _filter; }; -- 2.30.2