Code

Filters. Experimental filters improvements (new default values and options).
[inkscape.git] / src / extension / internal / filter / color.h
1 #ifndef __INKSCAPE_EXTENSION_INTERNAL_FILTER_COLOR_H__
2 #define __INKSCAPE_EXTENSION_INTERNAL_FILTER_COLOR_H__
3 /* Change the 'COLOR' above to be your file name */
5 /*
6  * Copyright (C) 2010 Authors:
7  *   Ivan Louette (filters)
8  *   Nicolas Dufour (UI) <nicoduf@yahoo.fr>
9  *
10  * Released under GNU GPL, read the file 'COPYING' for more information
11  */
12 /* ^^^ Change the copyright to be you and your e-mail address ^^^ */
14 #include "filter.h"
16 #include "extension/internal/clear-n_.h"
17 #include "extension/system.h"
18 #include "extension/extension.h"
20 namespace Inkscape {
21 namespace Extension {
22 namespace Internal {
23 namespace Filter {
25 class Duochrome : public Inkscape::Extension::Internal::Filter::Filter {
26 protected:
27         virtual gchar const * get_filter_text (Inkscape::Extension::Extension * ext);
29 public:
30         Duochrome ( ) : Filter() { };
31         virtual ~Duochrome ( ) { if (_filter != NULL) g_free((void *)_filter); return; }
33         static void init (void) {
34                 Inkscape::Extension::build_from_mem(
35                         "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
36                                 "<name>" N_("Duochrome, custom -EXP-") "</name>\n"
37                                 "<id>org.inkscape.effect.filter.Duochrome</id>\n"
38 // Using color widgets in tabs makes Inkscape crash...
39 //                  "<param name=\"tab\" type=\"notebook\">\n"
40 //                    "<page name=\"Color1\" _gui-text=\"Color 1\">\n"
41                         "<param name=\"fluo\" gui-text=\"" N_("Fluorescence") "\" type=\"boolean\">false</param>\n"
42                         "<_param name=\"header1\" type=\"groupheader\">Color 1</_param>\n"
43                                         "<param name=\"color1\" gui-text=\"" N_("Color 1") "\" type=\"color\">1364325887</param>\n"
44 //                    "</page>\n"
45 //                    "<page name=\"Color2\" _gui-text=\"Color 2\">\n"
46                         "<_param name=\"header2\" type=\"groupheader\">Color 2</_param>\n"
47                                         "<param name=\"color2\" gui-text=\"" N_("Color 2") "\" type=\"color\">-65281</param>\n"
48 //                    "</page>\n"
49 //                "</param>\n"
50                                 "<effect>\n"
51                                         "<object-type>all</object-type>\n"
52                                         "<effects-menu>\n"
53                                                 "<submenu name=\"" N_("Filters") "\">\n"
54                                                 "<submenu name=\"" N_("Color") "\"/>\n"
55                               "</submenu>\n"
56                                         "</effects-menu>\n"
57                                         "<menu-tip>" N_("Change colors to a two colors palette") "</menu-tip>\n"
58                                 "</effect>\n"
59                         "</inkscape-extension>\n", new Duochrome());
60         };
62 };
64 gchar const *
65 Duochrome::get_filter_text (Inkscape::Extension::Extension * ext)
66 {
67         if (_filter != NULL) g_free((void *)_filter);
69     std::ostringstream a1;
70     std::ostringstream r1;
71     std::ostringstream g1;
72     std::ostringstream b1;
73     std::ostringstream a2;
74     std::ostringstream r2;
75     std::ostringstream g2;
76     std::ostringstream b2;
77     std::ostringstream fluo;
79     guint32 color1 = ext->get_param_color("color1");
80     guint32 color2 = ext->get_param_color("color2");
81     bool fluorescence = ext->get_param_bool("fluo");
82     a1 << (color1 & 0xff) / 255.0F;
83     r1 << ((color1 >> 24) & 0xff);
84     g1 << ((color1 >> 16) & 0xff);
85     b1 << ((color1 >>  8) & 0xff);
86     a2 << (color2 & 0xff) / 255.0F;
87     r2 << ((color2 >> 24) & 0xff);
88     g2 << ((color2 >> 16) & 0xff);
89     b2 << ((color2 >>  8) & 0xff);
90     if (fluorescence) fluo << "";
91     else  fluo << " in=\"result6\"";
93         _filter = g_strdup_printf(
94                 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" color-interpolation-filters=\"sRGB\" height=\"1\" width=\"1\" y=\"0\" x=\"0\" inkscape:label=\"Duochrome, custom -EXP-\">\n"
95             "<feColorMatrix type=\"luminanceToAlpha\" result=\"fbSourceGraphic\" />\n"
96             "<feFlood in=\"fbSourceGraphic\" flood-opacity=\"%s\" flood-color=\"rgb(%s,%s,%s)\" result=\"result1\" />\n"
97             "<feComposite in=\"result1\" in2=\"fbSourceGraphic\" operator=\"out\" result=\"result2\" />\n"
98             "<feComposite in2=\"SourceGraphic\" k2=\"1\" result=\"fbSourceGraphic\" operator=\"arithmetic\" />\n"
99             "<feFlood in=\"fbSourceGraphic\" flood-opacity=\"%s\" flood-color=\"rgb(%s,%s,%s)\" result=\"result2\" />\n"
100             "<feMerge result=\"result5\">\n"
101                 "<feMergeNode in=\"result2\" />\n"
102                 "<feMergeNode in=\"fbSourceGraphic\" />\n"
103             "</feMerge>\n"
104             "<feBlend in2=\"fbSourceGraphic\" mode=\"normal\" blend=\"normal\" result=\"result6\" />\n"
105             "<feColorMatrix type=\"matrix\" values=\"2 -1 0 0 0 0 2 -1 0 0 -1 0 2 0 0 0 0 0 1 0 \" result=\"result10\" />\n"
106             "<feComposite %s in2=\"SourceGraphic\" operator=\"in\" result=\"fbSourceGraphic\" />\n"
107         "</filter>\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());
109         return _filter;
110 };
111 }; /* namespace Filter */
112 }; /* namespace Internal */
113 }; /* namespace Extension */
114 }; /* namespace Inkscape */
116 /* Change the 'COLOR' below to be your file name */
117 #endif /* __INKSCAPE_EXTENSION_INTERNAL_FILTER_COLOR_H__ */