// SPDX-License-Identifier: GPL-2.0-or-later #ifndef SEEN_INKSCAPE_EXTENSION_INTERNAL_FILTER_TRANSPARENCY_H__ #define SEEN_INKSCAPE_EXTENSION_INTERNAL_FILTER_TRANSPARENCY_H__ /* Change the 'TRANSPARENCY' above to be your file name */ /* * Copyright (C) 2011 Authors: * Ivan Louette (filters) * Nicolas Dufour (UI) * * Fill and transparency filters * Blend * Channel transparency * Light eraser * Opacity * Silhouette * * Released under GNU GPL v2+, 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 { /** \brief Custom predefined Blend filter. Blend objects 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: gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override; public: Blend ( ) : Filter() { }; ~Blend ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; } static void init () { // clang-format off Inkscape::Extension::build_from_mem( "\n" "" N_("Blend") "\n" "org.inkscape.effect.filter.Blend\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "all\n" "\n" "\n" "\n" "\n" "\n" "" N_("Blend objects with background images or with themselves") "\n" "\n" "\n", new Blend()); // clang-format on }; }; gchar const * Blend::get_filter_text (Inkscape::Extension::Extension * ext) { if (_filter != nullptr) g_free((void *)_filter); std::ostringstream source; std::ostringstream mode; source << ext->get_param_optiongroup("source"); mode << ext->get_param_optiongroup("mode"); // clang-format off _filter = g_strdup_printf( "\n" "\n" "\n", source.str().c_str(), mode.str().c_str() ); // clang-format on return _filter; }; /* Blend filter */ /** \brief Custom predefined Channel transparency filter. Channel transparency filter. Filter's parameters: * Saturation (0.->1., default 1.) -> colormatrix1 (values) * Red (-10.->10., default -1.) -> colormatrix2 (values) * Green (-10.->10., default 0.5) -> colormatrix2 (values) * Blue (-10.->10., default 0.5) -> colormatrix2 (values) * Alpha (-10.->10., default 1.) -> colormatrix2 (values) * Flood colors (guint, default 16777215) -> flood (flood-opacity, flood-color) * Inverted (boolean, default false) -> composite1 (operator, true='in', false='out') Matrix: 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 R G B A 0 */ class ChannelTransparency : public Inkscape::Extension::Internal::Filter::Filter { protected: gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override; public: ChannelTransparency ( ) : Filter() { }; ~ChannelTransparency ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; } static void init () { // clang-format off Inkscape::Extension::build_from_mem( "\n" "" N_("Channel Transparency") "\n" "org.inkscape.effect.filter.ChannelTransparency\n" "-1\n" "0.5\n" "0.5\n" "1\n" "false\n" "\n" "all\n" "\n" "\n" "\n" "\n" "\n" "" N_("Replace RGB with transparency") "\n" "\n" "\n", new ChannelTransparency()); // clang-format on }; }; gchar const * ChannelTransparency::get_filter_text (Inkscape::Extension::Extension * ext) { if (_filter != nullptr) g_free((void *)_filter); std::ostringstream red; std::ostringstream green; std::ostringstream blue; std::ostringstream alpha; std::ostringstream invert; red << ext->get_param_float("red"); green << ext->get_param_float("green"); blue << ext->get_param_float("blue"); alpha << ext->get_param_float("alpha"); if (!ext->get_param_bool("invert")) { invert << "in"; } else { invert << "xor"; } // clang-format off _filter = g_strdup_printf( "\n" "\n" "\n" "\n", red.str().c_str(), green.str().c_str(), blue.str().c_str(), alpha.str().c_str(), invert.str().c_str()); // clang-format on return _filter; }; /* Channel transparency filter */ /** \brief Custom predefined LightEraser filter. Make the lightest parts of the object progressively transparent. Filter's parameters: * Expansion (0.->1000., default 50) -> colormatrix (4th value, multiplicator) * Erosion (1.->1000., default 100) -> colormatrix (first 3 values, multiplicator) * Global opacity (0.->1., default 1.) -> composite (k2) * Inverted (boolean, default false) -> colormatrix (values, true: first 3 values positive, 4th negative) */ class LightEraser : public Inkscape::Extension::Internal::Filter::Filter { protected: gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override; public: LightEraser ( ) : Filter() { }; ~LightEraser ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; } static void init () { // clang-format off Inkscape::Extension::build_from_mem( "\n" "" N_("Light Eraser") "\n" "org.inkscape.effect.filter.LightEraser\n" "50\n" "100\n" "1\n" "false\n" "\n" "all\n" "\n" "\n" "\n" "\n" "\n" "" N_("Make the lightest parts of the object progressively transparent") "\n" "\n" "\n", new LightEraser()); // clang-format on }; }; gchar const * LightEraser::get_filter_text (Inkscape::Extension::Extension * ext) { if (_filter != nullptr) g_free((void *)_filter); std::ostringstream expand; std::ostringstream erode; std::ostringstream opacity; opacity << ext->get_param_float("opacity"); if (ext->get_param_bool("invert")) { expand << (ext->get_param_float("erode") * 0.2125) << " " << (ext->get_param_float("erode") * 0.7154) << " " << (ext->get_param_float("erode") * 0.0721); erode << (-ext->get_param_float("expand")); } else { expand << (-ext->get_param_float("erode") * 0.2125) << " " << (-ext->get_param_float("erode") * 0.7154) << " " << (-ext->get_param_float("erode") * 0.0721); erode << ext->get_param_float("expand"); } // clang-format off _filter = g_strdup_printf( "\n" "\n" "\n" "\n", expand.str().c_str(), erode.str().c_str(), opacity.str().c_str()); // clang-format on return _filter; }; /* Light Eraser filter */ /** \brief Custom predefined Opacity filter. Set opacity and strength of opacity boundaries. Filter's parameters: * Expansion (0.->1000., default 5) -> colormatrix (last-1th value) * Erosion (0.->1000., default 1) -> colormatrix (last value) * Global opacity (0.->1., default 1.) -> composite (k2) */ class Opacity : public Inkscape::Extension::Internal::Filter::Filter { protected: gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override; public: Opacity ( ) : Filter() { }; ~Opacity ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; } static void init () { // clang-format off Inkscape::Extension::build_from_mem( "\n" "" N_("Opacity") "\n" "org.inkscape.effect.filter.Opacity\n" "5\n" "1\n" "1\n" "\n" "all\n" "\n" "\n" "\n" "\n" "\n" "" N_("Set opacity and strength of opacity boundaries") "\n" "\n" "\n", new Opacity()); // clang-format on }; }; gchar const * Opacity::get_filter_text (Inkscape::Extension::Extension * ext) { if (_filter != nullptr) g_free((void *)_filter); std::ostringstream matrix; std::ostringstream opacity; opacity << ext->get_param_float("opacity"); matrix << (ext->get_param_float("expand")) << " " << (-ext->get_param_float("erode")); // clang-format off _filter = g_strdup_printf( "\n" "\n" "\n" "\n", matrix.str().c_str(), opacity.str().c_str()); // clang-format on return _filter; }; /* Opacity filter */ /** \brief Custom predefined Silhouette filter. Repaint anything visible monochrome Filter's parameters: * Blur (0.01->50., default 0.01) -> blur (stdDeviation) * Cutout (boolean, default False) -> composite (false=in, true=out) * Color (guint, default 0,0,0,255) -> flood (flood-color, flood-opacity) */ class Silhouette : public Inkscape::Extension::Internal::Filter::Filter { protected: gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override; public: Silhouette ( ) : Filter() { }; ~Silhouette ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; } static void init () { // clang-format off Inkscape::Extension::build_from_mem( "\n" "" N_("Silhouette") "\n" "org.inkscape.effect.filter.Silhouette\n" "0.01\n" "false\n" "255\n" "\n" "all\n" "\n" "\n" "\n" "\n" "\n" "" N_("Repaint anything visible monochrome") "\n" "\n" "\n", new Silhouette()); // clang-format on }; }; gchar const * Silhouette::get_filter_text (Inkscape::Extension::Extension * ext) { if (_filter != nullptr) g_free((void *)_filter); std::ostringstream a; std::ostringstream r; std::ostringstream g; std::ostringstream b; std::ostringstream cutout; std::ostringstream blur; guint32 color = ext->get_param_color("color"); r << ((color >> 24) & 0xff); g << ((color >> 16) & 0xff); b << ((color >> 8) & 0xff); a << (color & 0xff) / 255.0F; if (ext->get_param_bool("cutout")) cutout << "out"; else cutout << "in"; blur << ext->get_param_float("blur"); // clang-format off _filter = g_strdup_printf( "\n" "\n" "\n" "\n" "\n", a.str().c_str(), r.str().c_str(), g.str().c_str(), b.str().c_str(), cutout.str().c_str(), blur.str().c_str()); // clang-format on return _filter; }; /* Silhouette filter */ }; /* namespace Filter */ }; /* namespace Internal */ }; /* namespace Extension */ }; /* namespace Inkscape */ /* Change the 'TRANSPARENCY' below to be your file name */ #endif /* SEEN_INKSCAPE_EXTENSION_INTERNAL_FILTER_TRANSPARENCY_H__ */