// SPDX-License-Identifier: GPL-2.0-or-later #ifndef SEEN_INKSCAPE_EXTENSION_INTERNAL_FILTER_BUMPS_H__ #define SEEN_INKSCAPE_EXTENSION_INTERNAL_FILTER_BUMPS_H__ /* Change the 'BUMPS' above to be your file name */ /* * Copyright (C) 2011 Authors: * Ivan Louette (filters) * Nicolas Dufour (UI) * * Bump filters * Bump * Wax bump * * 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 Bump filter. All purpose bump filter Filter's parameters: Options * Image simplification (0.01->10., default 0.01) -> blur1 (stdDeviation) * Bump simplification (0.01->10., default 0.01) -> blur2 (stdDeviation) * Crop (-50.->50., default 0.) -> composite1 (k3) * Red (-50.->50., default 0.) -> colormatrix1 (values) * Green (-50.->50., default 0.) -> colormatrix1 (values) * Blue (-50.->50., default 0.) -> colormatrix1 (values) * Bump from background (boolean, default false) -> colormatrix1 (false: in="SourceGraphic", true: in="BackgroundImage") Lighting * Lighting type (enum, default specular) -> lighting block * Height (0.->50., default 5.) -> lighting (surfaceScale) * Lightness (0.->5., default 1.) -> lighting [diffuselighting (diffuseConstant)|specularlighting (specularConstant)] * Precision (1->128, default 15) -> lighting (specularExponent) * Color (guint, default -1 (RGB:255,255,255))-> lighting (lighting-color) Light source * Azimuth (0->360, default 225) -> lightsOptions (distantAzimuth) * Elevation (0->180, default 45) -> lightsOptions (distantElevation) * X location [point] (-5000->5000, default 526) -> lightsOptions (x) * Y location [point] (-5000->5000, default 372) -> lightsOptions (y) * Z location [point] (0->5000, default 150) -> lightsOptions (z) * X location [spot] (-5000->5000, default 526) -> lightsOptions (x) * Y location [spot] (-5000->5000, default 372) -> lightsOptions (y) * Z location [spot] (-5000->5000, default 150) -> lightsOptions (z) * X target (-5000->5000, default 0) -> lightsOptions (pointsAtX) * Y target (-5000->5000, default 0) -> lightsOptions (pointsAtX) * Z target (-5000->0, default -1000) -> lightsOptions (pointsAtX) * Specular exponent (1->100, default 1) -> lightsOptions (specularExponent) * Cone angle (0->100, default 50) -> lightsOptions (limitingConeAngle) Color bump * Blend type (enum, default normal) -> blend (mode) * Image color (guint, default -987158017 (RGB:197,41,41)) -> flood (flood-color) * Color bump (boolean, default false) -> composite2 (false: in="diffuselighting", true in="flood") */ class Bump : public Inkscape::Extension::Internal::Filter::Filter { protected: gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override; public: Bump ( ) : Filter() { }; ~Bump ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; } static void init () { // clang-format off Inkscape::Extension::build_from_mem( "\n" "" N_("Bump") "\n" "org.inkscape.effect.filter.Bump\n" "\n" "\n" "0.01\n" "0.01\n" "0\n" "\n" "0\n" "0\n" "0\n" "false\n" "\n" "\n" "\n" "\n" "\n" "\n" "5\n" "1\n" "15\n" "-1\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "225\n" "45\n" "\n" "526\n" "372\n" "150\n" "\n" "526\n" "372\n" "150\n" "0\n" "0\n" "-1000\n" "1\n" "50\n" "\n" "\n" "-987158017\n" "false\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "all\n" "\n" "\n" "\n" "\n" "\n" "" N_("All purposes bump filter") "\n" "\n" "\n", new Bump()); // clang-format on }; }; gchar const * Bump::get_filter_text (Inkscape::Extension::Extension * ext) { if (_filter != nullptr) g_free((void *)_filter); std::ostringstream simplifyImage; std::ostringstream simplifyBump; std::ostringstream red; std::ostringstream green; std::ostringstream blue; std::ostringstream crop; std::ostringstream bumpSource; std::ostringstream blend; std::ostringstream lightStart; std::ostringstream lightOptions; std::ostringstream lightEnd; std::ostringstream floodRed; std::ostringstream floodGreen; std::ostringstream floodBlue; std::ostringstream floodAlpha; std::ostringstream colorize; simplifyImage << ext->get_param_float("simplifyImage"); simplifyBump << ext->get_param_float("simplifyBump"); red << ext->get_param_float("red"); green << ext->get_param_float("green"); blue << ext->get_param_float("blue"); crop << ext->get_param_float("crop"); blend << ext->get_param_optiongroup("blend"); guint32 lightingColor = ext->get_param_color("lightingColor"); guint32 imageColor = ext->get_param_color("imageColor"); if (ext->get_param_bool("background")) { bumpSource << "BackgroundImage" ; } else { bumpSource << "blur1" ; } const gchar *lightType = ext->get_param_optiongroup("lightType"); if ((g_ascii_strcasecmp("specular", lightType) == 0)) { // Specular lightStart << "> 24) & 0xff) << "," << ((lightingColor >> 16) & 0xff) << "," << ((lightingColor >> 8) & 0xff) << ")\" surfaceScale=\"" << ext->get_param_float("height") << "\" specularConstant=\"" << ext->get_param_float("lightness") << "\" specularExponent=\"" << ext->get_param_int("precision") << "\" result=\"lighting\">"; lightEnd << ""; } else { // Diffuse lightStart << "> 24) & 0xff) << "," << ((lightingColor >> 16) & 0xff) << "," << ((lightingColor >> 8) & 0xff) << ")\" surfaceScale=\"" << ext->get_param_float("height") << "\" diffuseConstant=\"" << ext->get_param_float("lightness") << "\" result=\"lighting\">"; lightEnd << ""; } const gchar *lightSource = ext->get_param_optiongroup("lightSource"); if ((g_ascii_strcasecmp("distant", lightSource) == 0)) { // Distant lightOptions << "get_param_int("distantAzimuth") << "\" elevation=\"" << ext->get_param_int("distantElevation") << "\" />"; } else if ((g_ascii_strcasecmp("point", lightSource) == 0)) { // Point lightOptions << "get_param_int("pointX") << "\" y=\"" << ext->get_param_int("pointY") << "\" x=\"" << ext->get_param_int("pointZ") << "\" />"; } else { // Spot lightOptions << "get_param_int("pointX") << "\" y=\"" << ext->get_param_int("pointY") << "\" z=\"" << ext->get_param_int("pointZ") << "\" pointsAtX=\"" << ext->get_param_int("spotAtX") << "\" pointsAtY=\"" << ext->get_param_int("spotAtY") << "\" pointsAtZ=\"" << ext->get_param_int("spotAtZ") << "\" specularExponent=\"" << ext->get_param_int("spotExponent") << "\" limitingConeAngle=\"" << ext->get_param_int("spotConeAngle") << "\" />"; } floodRed << ((imageColor >> 24) & 0xff); floodGreen << ((imageColor >> 16) & 0xff); floodBlue << ((imageColor >> 8) & 0xff); floodAlpha << (imageColor & 0xff) / 255.0F; if (ext->get_param_bool("colorize")) { colorize << "flood" ; } else { colorize << "blur1" ; } // clang-format off _filter = g_strdup_printf( "\n" "\n" "\n" "\n" "\n" "\n" "%s\n" "%s\n" "%s\n" "\n" "\n" "\n" "\n" "\n", simplifyImage.str().c_str(), bumpSource.str().c_str(), red.str().c_str(), green.str().c_str(), blue.str().c_str(), crop.str().c_str(), simplifyBump.str().c_str(), lightStart.str().c_str(), lightOptions.str().c_str(), lightEnd.str().c_str(), floodRed.str().c_str(), floodGreen.str().c_str(), floodBlue.str().c_str(), floodAlpha.str().c_str(), colorize.str().c_str(), blend.str().c_str()); // clang-format on return _filter; }; /* Bump filter */ /** \brief Custom predefined Wax Bump filter. Turns an image to jelly Filter's parameters: Options * Image simplification (0.01->10., default 1.5) -> blur1 (stdDeviation) * Bump simplification (0.01->10., default 1) -> blur2 (stdDeviation) * Crop (-10.->10., default 1.) -> colormatrix2 (4th value of the last line) * Red (-10.->10., default 0.) -> colormatrix2 (values, substract 0.21) * Green (-10.->10., default 0.) -> colormatrix2 (values, substract 0.72) * Blue (-10.->10., default 0.) -> colormatrix2 (values, substract 0.07) * Background (enum, default color) -> * color: colormatrix1 (in="flood1") * image: colormatrix1 (in="SourceGraphic") * blurred image: colormatrix1 (in="blur1") * Background opacity (0.->1., default 0) -> colormatrix1 (last value) Lighting (specular, distant light) * Color (guint, default -1 (RGB:255,255,255))-> lighting (lighting-color) * Height (-50.->50., default 5.) -> lighting (surfaceScale) * Lightness (0.->10., default 1.4) -> lighting [diffuselighting (diffuseConstant)|specularlighting (specularConstant)] * Precision (0->50, default 35) -> lighting (specularExponent) * Azimuth (0->360, default 225) -> lightsOptions (distantAzimuth) * Elevation (0->180, default 60) -> lightsOptions (distantElevation) * Lighting blend (enum, default screen) -> blend1 (mode) * Highlight blend (enum, default screen) -> blend2 (mode) Bump * Transparency type (enum [in,atop], default atop) -> composite2 (operator) * Color (guint, default -520083713 (RGB:225,0,38)) -> flood2 (flood-color) * Revert bump (boolean, default false) -> composite1 (false: operator="out", true operator="in") */ class WaxBump : public Inkscape::Extension::Internal::Filter::Filter { protected: gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override; public: WaxBump ( ) : Filter() { }; ~WaxBump ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; } static void init () { // clang-format off Inkscape::Extension::build_from_mem( "\n" "" N_("Wax Bump") "\n" "org.inkscape.effect.filter.WaxBump\n" "\n" "\n" "1.5\n" "1\n" "1\n" "\n" "0\n" "0\n" "0\n" "\n" "\n" "\n" "\n" "\n" "0\n" "\n" "\n" "-1\n" "5\n" "1.4\n" "35\n" "225\n" "60\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "-520083713\n" "false\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "all\n" "\n" "\n" "\n" "\n" "\n" "" N_("Turns an image to jelly") "\n" "\n" "\n", new WaxBump()); // clang-format on }; }; gchar const * WaxBump::get_filter_text (Inkscape::Extension::Extension * ext) { if (_filter != nullptr) g_free((void *)_filter); std::ostringstream simplifyImage; std::ostringstream simplifyBump; std::ostringstream crop; std::ostringstream red; std::ostringstream green; std::ostringstream blue; std::ostringstream background; std::ostringstream bgopacity; std::ostringstream height; std::ostringstream lightness; std::ostringstream precision; std::ostringstream distantAzimuth; std::ostringstream distantElevation; std::ostringstream lightRed; std::ostringstream lightGreen; std::ostringstream lightBlue; std::ostringstream floodRed; std::ostringstream floodGreen; std::ostringstream floodBlue; std::ostringstream floodAlpha; std::ostringstream revert; std::ostringstream lightingblend; std::ostringstream highlightblend; std::ostringstream transparency; simplifyImage << ext->get_param_float("simplifyImage"); simplifyBump << ext->get_param_float("simplifyBump"); crop << ext->get_param_float("crop"); red << ext->get_param_float("red") - 0.21; green << ext->get_param_float("green") - 0.72; blue << ext->get_param_float("blue") - 0.07; background << ext->get_param_optiongroup("background"); bgopacity << ext->get_param_float("bgopacity"); height << ext->get_param_float("height"); lightness << ext->get_param_float("lightness"); precision << ext->get_param_int("precision"); distantAzimuth << ext->get_param_int("distantAzimuth"); distantElevation << ext->get_param_int("distantElevation"); guint32 lightingColor = ext->get_param_color("lightingColor"); lightRed << ((lightingColor >> 24) & 0xff); lightGreen << ((lightingColor >> 16) & 0xff); lightBlue << ((lightingColor >> 8) & 0xff); guint32 imageColor = ext->get_param_color("imageColor"); floodRed << ((imageColor >> 24) & 0xff); floodGreen << ((imageColor >> 16) & 0xff); floodBlue << ((imageColor >> 8) & 0xff); floodAlpha << (imageColor & 0xff) / 255.0F; if (ext->get_param_bool("revert")) { revert << "in" ; } else { revert << "out" ; } lightingblend << ext->get_param_optiongroup("lightingblend"); highlightblend << ext->get_param_optiongroup("highlightblend"); transparency << ext->get_param_optiongroup("transparency"); // clang-format off _filter = g_strdup_printf( "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n" "\n", simplifyImage.str().c_str(), background.str().c_str(), bgopacity.str().c_str(), red.str().c_str(), green.str().c_str(), blue.str().c_str(), crop.str().c_str(), floodRed.str().c_str(), floodGreen.str().c_str(), floodBlue.str().c_str(), floodAlpha.str().c_str(), revert.str().c_str(), simplifyBump.str().c_str(), lightRed.str().c_str(), lightGreen.str().c_str(), lightBlue.str().c_str(), lightness.str().c_str(), height.str().c_str(), precision.str().c_str(), distantElevation.str().c_str(), distantAzimuth.str().c_str(), lightingblend.str().c_str(), transparency.str().c_str(), highlightblend.str().c_str() ); // clang-format on return _filter; }; /* Wax bump filter */ }; /* namespace Filter */ }; /* namespace Internal */ }; /* namespace Extension */ }; /* namespace Inkscape */ /* Change the 'BUMPS' below to be your file name */ #endif /* SEEN_INKSCAPE_EXTENSION_INTERNAL_FILTER_BUMPS_H__ */