From ee4956cfe78fc822d0cadcc24f3e49d199bd0fe6 Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Thu, 28 Jul 2011 20:09:35 +0200 Subject: Filters. New Bump custom predefined filter. Translations. inkscape.pot and French translation update. (bzr r10512) --- src/extension/internal/filter/bumps.h | 272 +++++++++++++++++++++++++++ src/extension/internal/filter/filter-all.cpp | 6 +- 2 files changed, 275 insertions(+), 3 deletions(-) create mode 100644 src/extension/internal/filter/bumps.h (limited to 'src') diff --git a/src/extension/internal/filter/bumps.h b/src/extension/internal/filter/bumps.h new file mode 100644 index 000000000..5b0be2b7e --- /dev/null +++ b/src/extension/internal/filter/bumps.h @@ -0,0 +1,272 @@ +#ifndef __INKSCAPE_EXTENSION_INTERNAL_FILTER_BUMPS_H__ +#define __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 + * + * Released under GNU GPL, 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 (-1.->1., 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: + virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext); + +public: + Bump ( ) : Filter() { }; + virtual ~Bump ( ) { if (_filter != NULL) g_free((void *)_filter); return; } + + static void init (void) { + Inkscape::Extension::build_from_mem( + "\n" + "" N_("Bump, custom (Bumps)") "\n" + "org.inkscape.effect.filter.Bump\n" + "\n" + "\n" + "0.01\n" + "0.01\n" + "0\n" + "<_param name=\"sourceHeader\" type=\"description\" appearance=\"header\">Bump source\n" + "0\n" + "0\n" + "0\n" + "false\n" + "\n" + "\n" + "\n" + "<_item value=\"specular\">" N_("Specular") "\n" + "<_item value=\"diffuse\">" N_("Diffuse") "\n" + "\n" + "5\n" + "1\n" + "15\n" + "-1\n" + "\n" + "\n" + "\n" + "<_item value=\"distant\">" N_("Distant") "\n" + "<_item value=\"point\">" N_("Point") "\n" + "<_item value=\"spot\">" N_("Spot") "\n" + "\n" + "<_param name=\"distantHeader\" type=\"description\" appearance=\"header\">Distant light options\n" + "225\n" + "45\n" + "<_param name=\"pointHeader\" type=\"description\" appearance=\"header\">Point light options\n" + "526\n" + "372\n" + "150\n" + "<_param name=\"spotHeader\" type=\"description\" appearance=\"header\">Spot light options\n" + "526\n" + "372\n" + "150\n" + "0\n" + "0\n" + "-1000\n" + "1\n" + "50\n" + "\n" + "\n" + "-987158017\n" + "false\n" + "\n" + "<_item value=\"normal\">" N_("Normal") "\n" + "<_item value=\"darken\">" N_("Darken") "\n" + "<_item value=\"screen\">" N_("Screen") "\n" + "<_item value=\"multiply\">" N_("Multiply") "\n" + "<_item value=\"lighten\">" N_("Lighten") "\n" + "\n" + "\n" + "\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "\n" + "\n" + "" N_("All purposes bump filter") "\n" + "\n" + "\n", new Bump()); + }; + +}; + +gchar const * +Bump::get_filter_text (Inkscape::Extension::Extension * ext) +{ + if (_filter != NULL) 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 lightRed; + std::ostringstream lightGreen; + std::ostringstream lightBlue; + std::ostringstream floodRed; + std::ostringstream floodGreen; + std::ostringstream floodBlue; + 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_enum("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_enum("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_enum("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); + + if (ext->get_param_bool("colorize")) { + colorize << "flood" ; + } else { + colorize << "blur1" ; + } + + _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(), + colorize.str().c_str(), blend.str().c_str()); + + return _filter; + +}; /* Cross blur filter */ + + +}; /* namespace Filter */ +}; /* namespace Internal */ +}; /* namespace Extension */ +}; /* namespace Inkscape */ + +/* Change the 'BUMPS' below to be your file name */ +#endif /* __INKSCAPE_EXTENSION_INTERNAL_FILTER_BUMPS_H__ */ diff --git a/src/extension/internal/filter/filter-all.cpp b/src/extension/internal/filter/filter-all.cpp index ed8b4e180..210d1d87a 100755 --- a/src/extension/internal/filter/filter-all.cpp +++ b/src/extension/internal/filter/filter-all.cpp @@ -10,7 +10,7 @@ /* Put your filter here */ #include "abc.h" #include "blurs.h" -//#include "bumps.h" +#include "bumps.h" #include "color.h" #include "drop-shadow.h" #include "image.h" @@ -36,7 +36,7 @@ Filter::filters_all (void ) /* Experimental custom predefined filters */ - // ABCs + // ABC Blur::init(); CleanEdges::init(); ColorShift::init(); @@ -53,7 +53,7 @@ Filter::filters_all (void ) CrossBlur::init(); // Bumps -// SpecularBump::init(); + Bump::init(); // Color Brightness::init(); -- cgit v1.2.3