From 73d0ee81f6d941489cab1ecd5fd8a4fdb5a192e9 Mon Sep 17 00:00:00 2001 From: JazzyNico Date: Sun, 28 Nov 2010 20:09:00 +0100 Subject: [PATCH] Filters. New custom predefined Drawing filter (experimental, and currently a bit tall), and some tweaks and fixes. --- src/extension/internal/filter/color.h | 10 +- src/extension/internal/filter/experimental.h | 168 ++++++++++++++++++- src/extension/internal/filter/filter-all.cpp | 3 +- src/extension/internal/filter/morphology.h | 36 ++-- 4 files changed, 185 insertions(+), 32 deletions(-) diff --git a/src/extension/internal/filter/color.h b/src/extension/internal/filter/color.h index d9720b05c..3bf2f6307 100644 --- a/src/extension/internal/filter/color.h +++ b/src/extension/internal/filter/color.h @@ -52,7 +52,6 @@ public: "0\n" "1\n" "false\n" - "false\n" "\n" "<_item value=\"multiply\">Multiply\n" "<_item value=\"normal\">Normal\n" @@ -94,7 +93,6 @@ Colorize::get_filter_text (Inkscape::Extension::Extension * ext) std::ostringstream hlight; std::ostringstream nlight; std::ostringstream duotone; - std::ostringstream fg; std::ostringstream blend1; std::ostringstream blend2; @@ -112,10 +110,6 @@ Colorize::get_filter_text (Inkscape::Extension::Extension * ext) duotone << "0"; else duotone << "1"; - if (ext->get_param_bool("fg")) - fg << "0"; - else - fg << "1"; _filter = g_strdup_printf( "\n" @@ -124,9 +118,9 @@ Colorize::get_filter_text (Inkscape::Extension::Extension * ext) "\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()); + "\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()); return _filter; }; /* Colorize filter */ diff --git a/src/extension/internal/filter/experimental.h b/src/extension/internal/filter/experimental.h index 7bf27bee8..6acf59f82 100644 --- a/src/extension/internal/filter/experimental.h +++ b/src/extension/internal/filter/experimental.h @@ -22,6 +22,169 @@ namespace Extension { namespace Internal { namespace Filter { +/** + \brief Custom predefined Drawing filter. + + Convert images to duochrome drawings. + + Filter's parameters: + * Simplification (0.01->10, default 0.7) -> blur1 (stdDeviation) + * Lightness (0->50, default 5) -> convolve (kernelMatrix, central value -1000->-1050, default -1005) + * Smoothness (0.01->10, default 0.7) -> blur2 (stdDeviation) + * Dilatation (3->100, default 6) -> colormatrix3 (n-1th value) + + * Blur (0.01->10., default 5.) -> blur3 (stdDeviation) + * Blur spread (3->20, default 6) -> colormatrix5 (n-1th value) + * Blur erosion (-2->0, default -2) -> colormatrix5 (nth value) + + * Stroke color (guint, default 205,0,0) -> flood2 (flood-opacity, flood-color) + * Image on stroke (boolean, default false) -> composite1 (in="flood2" true-> in="SourceGraphic") + * Image on stroke opacity (0.->1., default 1) -> composite3 (k3) + * Fill color (guint, default 255,203,0) -> flood3 (flood-opacity, flood-color) + * Image on fill (boolean, default false) -> composite2 (in="flood3" true-> in="SourceGraphic") + * Image on fill opacity (0.->1., default 1) -> composite3 (k2) +*/ + +class Drawing : public Inkscape::Extension::Internal::Filter::Filter { +protected: + virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext); + +public: + Drawing ( ) : Filter() { }; + virtual ~Drawing ( ) { if (_filter != NULL) g_free((void *)_filter); return; } + + static void init (void) { + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Drawing, custom -EXP-") "\n" + "org.inkscape.effect.filter.Drawing\n" + "0.7\n" + "5\n" + "0.7\n" + "6\n" + "5\n" + "6\n" + "-2\n" + "<_param name=\"fillcolorheader\" type=\"groupheader\">Fill color\n" + "-3473153\n" + "false\n" + "1\n" + "<_param name=\"strokecolorheader\" type=\"groupheader\">Stroke color\n" + "-855637761\n" + "false\n" + "1\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "" N_("Convert images to duochrome drawings") "\n" + "\n" + "\n", new Drawing()); + }; + +}; + +gchar const * +Drawing::get_filter_text (Inkscape::Extension::Extension * ext) +{ + if (_filter != NULL) g_free((void *)_filter); + + std::ostringstream simply; + std::ostringstream light; + std::ostringstream smooth; + std::ostringstream dilat; + std::ostringstream blur; + std::ostringstream spread; + std::ostringstream erosion; + std::ostringstream strokea; + std::ostringstream stroker; + std::ostringstream strokeg; + std::ostringstream strokeb; + std::ostringstream ios; + std::ostringstream ioso; + std::ostringstream filla; + std::ostringstream fillr; + std::ostringstream fillg; + std::ostringstream fillb; + std::ostringstream iof; + std::ostringstream iofo; + + simply << ext->get_param_float("simply"); + light << (-1000 - ext->get_param_int("light")); + smooth << ext->get_param_float("smooth"); + dilat << ext->get_param_int("dilat"); + + blur << ext->get_param_float("blur"); + spread << ext->get_param_int("spread"); + erosion << ext->get_param_int("erosion"); + + guint32 fcolor = ext->get_param_color("fcolor"); + fillr << ((fcolor >> 24) & 0xff); + fillg << ((fcolor >> 16) & 0xff); + fillb << ((fcolor >> 8) & 0xff); + filla << (fcolor & 0xff) / 255.0F; + if (ext->get_param_bool("iof")) + iof << "SourceGraphic"; + else + iof << "flood3"; + iofo << ext->get_param_float("iofo"); + + guint32 scolor = ext->get_param_color("scolor"); + stroker << ((scolor >> 24) & 0xff); + strokeg << ((scolor >> 16) & 0xff); + strokeb << ((scolor >> 8) & 0xff); + strokea << (scolor & 0xff) / 255.0F; + if (ext->get_param_bool("ios")) + ios << "SourceGraphic"; + else + ios << "flood2"; + ioso << ext->get_param_float("ioso"); + + _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" + "\n" + "\n", simply.str().c_str(), light.str().c_str(), smooth.str().c_str(), dilat.str().c_str(), blur.str().c_str(), spread.str().c_str(), erosion.str().c_str(), strokea.str().c_str(), stroker.str().c_str(), strokeg.str().c_str(), strokeb.str().c_str(), ios.str().c_str(), filla.str().c_str(), fillr.str().c_str(), fillg.str().c_str(), fillb.str().c_str(), iof.str().c_str(), iofo.str().c_str(), ioso.str().c_str()); + + return _filter; +}; /* Drawing filter */ + +/** + \brief Custom predefined Posterize filter. + + Poster and painting effects. + + Filter's parameters: + * Type (enum, default "Normal") -> + Normal = feComponentTransfer + Dented = Normal + intermediate values + * Blur (0.01->10., default 5.) -> blur3 (stdDeviation) + +*/ class Posterize : public Inkscape::Extension::Internal::Filter::Filter { protected: virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext); @@ -90,7 +253,7 @@ Posterize::get_filter_text (Inkscape::Extension::Extension * ext) postsat << ext->get_param_float("postsaturation"); - // TransfertComponenet table values are calculated based on the poster type. + // TransfertComponent table values are calculated based on the poster type. transf << "0"; int levels = ext->get_param_int("levels") + 1; const gchar *effecttype = ext->get_param_enum("type"); @@ -128,7 +291,8 @@ Posterize::get_filter_text (Inkscape::Extension::Extension * ext) "\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; -}; +}; /* Posterize filter */ + class TestFilter : public Inkscape::Extension::Internal::Filter::Filter { protected: diff --git a/src/extension/internal/filter/filter-all.cpp b/src/extension/internal/filter/filter-all.cpp index 80fa7c69e..d04e423ff 100644 --- a/src/extension/internal/filter/filter-all.cpp +++ b/src/extension/internal/filter/filter-all.cpp @@ -37,7 +37,7 @@ Filter::filters_all (void ) Quadritone::init(); Solarize::init(); Tritone::init(); - + // Morphology Crosssmooth::init(); @@ -45,6 +45,7 @@ Filter::filters_all (void ) ColorizableDropShadow::init(); // TDB + Drawing::init(); Posterize::init(); // Here come the rest of the filters that are read from SVG files in share/filters and diff --git a/src/extension/internal/filter/morphology.h b/src/extension/internal/filter/morphology.h index 61fb8d42b..e0f544c76 100644 --- a/src/extension/internal/filter/morphology.h +++ b/src/extension/internal/filter/morphology.h @@ -28,12 +28,10 @@ namespace Filter { Smooth the outside of shapes and pictures. Filter's parameters: - * Type (enum, default "Smooth all") -> - Smooth all = composite (in="colormatrix", in2="colormatrix") - Smooth edges = composite (in="SourceGraphic", in2="colormatrix") + * Type (enum, default "Smooth edges") -> + Smooth edges = composite1 (in="SourceGraphic", in2="blur") + Smooth all = composite1 (in="blur", in2="blur") * Blur (0.01->10., default 5.) -> blur (stdDeviation) - * Spreading (1->100, default 20) -> colormatrix (value n-1) - * Erosion (0->-100, default -15) -> colormatrix (value n) */ class Crosssmooth : public Inkscape::Extension::Internal::Filter::Filter { @@ -50,12 +48,10 @@ public: "" N_("Cross-smooth, custom -EXP-") "\n" "org.inkscape.effect.filter.Crosssmooth\n" "\n" - "<_item value=\"all\">Smooth all\n" "<_item value=\"edges\">Smooth edges\n" + "<_item value=\"all\">Smooth all\n" "\n" "5\n" - "20\n" - "-15\n" "\n" "all\n" "\n" @@ -63,7 +59,7 @@ public: "\n" "\n" "\n" - "" N_("Smooth the outside of shapes and pictures without altering their contents") "\n" + "" N_("Smooth edges and angles of shapes") "\n" "\n" "\n", new Crosssmooth()); }; @@ -76,27 +72,25 @@ Crosssmooth::get_filter_text (Inkscape::Extension::Extension * ext) if (_filter != NULL) g_free((void *)_filter); std::ostringstream blur; - std::ostringstream spreading; - std::ostringstream erosion; - std::ostringstream cin; + std::ostringstream c1in; blur << ext->get_param_float("blur"); - spreading << ext->get_param_int("spreading"); - erosion << ext->get_param_int("erosion"); const gchar *type = ext->get_param_enum("type"); if((g_ascii_strcasecmp("all", type) == 0)) { - cin << "colormatrix"; + c1in << "blur"; } else { - cin << "SourceGraphic"; + c1in << "SourceGraphic"; } - + _filter = g_strdup_printf( - "\n" + "\n" "\n" - "\n" - "\n" - "\n", blur.str().c_str(), spreading.str().c_str(), erosion.str().c_str(), cin.str().c_str()); + "\n" + "\n" + "\n" + "\n" + "\n", blur.str().c_str(), c1in.str().c_str()); return _filter; }; /* Crosssmooth filter */ -- 2.30.2