Code

1a1644276717099f41e749e0c244442a5c5e558c
[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                         "<param name=\"fluo\" gui-text=\"" N_("Fluorescence level:") "\" type=\"float\" min=\"0\" max=\"2\">0</param>\n"
39                         "<param name=\"swap\" gui-text=\"" N_("Swap:") "\" type=\"enum\">\n"
40                             "<_item value=\"none\">No swap</_item>\n"
41                             "<_item value=\"full\">Color and alpha</_item>\n"
42                             "<_item value=\"color\">Color only</_item>\n"
43                             "<_item value=\"alpha\">Alpha only</_item>\n"
44                         "</param>\n"
45                         "<_param name=\"header1\" type=\"groupheader\">Color 1</_param>\n"
46                                         "<param name=\"color1\" gui-text=\"" N_("Color 1") "\" type=\"color\">1364325887</param>\n"
47                         "<_param name=\"header2\" type=\"groupheader\">Color 2</_param>\n"
48                                         "<param name=\"color2\" gui-text=\"" N_("Color 2") "\" type=\"color\">-65281</param>\n"
49                                 "<effect>\n"
50                                         "<object-type>all</object-type>\n"
51                                         "<effects-menu>\n"
52                                                 "<submenu name=\"" N_("Filters") "\">\n"
53                                                 "<submenu name=\"" N_("Experimental") "\"/>\n"
54                               "</submenu>\n"
55                                         "</effects-menu>\n"
56                                         "<menu-tip>" N_("Convert luminance values to a duochrome palette") "</menu-tip>\n"
57                                 "</effect>\n"
58                         "</inkscape-extension>\n", new Duochrome());
59         };
61 };
63 gchar const *
64 Duochrome::get_filter_text (Inkscape::Extension::Extension * ext)
65 {
66         if (_filter != NULL) g_free((void *)_filter);
68     std::ostringstream a1;
69     std::ostringstream r1;
70     std::ostringstream g1;
71     std::ostringstream b1;
72     std::ostringstream a2;
73     std::ostringstream r2;
74     std::ostringstream g2;
75     std::ostringstream b2;
76     std::ostringstream fluo;
77     std::ostringstream swap1;
78     std::ostringstream swap2;
79     guint32 color1 = ext->get_param_color("color1");
80     guint32 color2 = ext->get_param_color("color2");
81     float fluorescence = ext->get_param_float("fluo");
82     const gchar *swaptype = ext->get_param_enum("swap");
84     r1 << ((color1 >> 24) & 0xff);
85     g1 << ((color1 >> 16) & 0xff);
86     b1 << ((color1 >>  8) & 0xff);
87     r2 << ((color2 >> 24) & 0xff);
88     g2 << ((color2 >> 16) & 0xff);
89     b2 << ((color2 >>  8) & 0xff);
90     fluo << fluorescence;
92     if((g_ascii_strcasecmp("full", swaptype) == 0)) {
93         swap1 << "in";
94         swap2 << "out";
95         a1 << (color1 & 0xff) / 255.0F;
96         a2 << (color2 & 0xff) / 255.0F;
97     } else if((g_ascii_strcasecmp("color", swaptype) == 0)) {
98         swap1 << "in";
99         swap2 << "out";
100         a1 << (color2 & 0xff) / 255.0F;
101         a2 << (color1 & 0xff) / 255.0F;
102     } else if((g_ascii_strcasecmp("alpha", swaptype) == 0)) {
103         swap1 << "out";
104         swap2 << "in";
105         a1 << (color2 & 0xff) / 255.0F;
106         a2 << (color1 & 0xff) / 255.0F;
107     } else {
108         swap1 << "out";
109         swap2 << "in";
110         a1 << (color1 & 0xff) / 255.0F;
111         a2 << (color2 & 0xff) / 255.0F;
112     }
114         _filter = g_strdup_printf(
115                 "<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"
116             "<feColorMatrix type=\"luminanceToAlpha\" result=\"colormatrix1\" />\n"
117             "<feFlood flood-opacity=\"%s\" flood-color=\"rgb(%s,%s,%s)\" result=\"flood1\" />\n"
118             "<feComposite in2=\"colormatrix1\" operator=\"%s\" result=\"composite1\" />\n"
119             "<feFlood in=\"colormatrix1\" flood-opacity=\"%s\" flood-color=\"rgb(%s,%s,%s)\" result=\"flood2\" />\n"
120             "<feComposite in2=\"colormatrix1\" result=\"composite2\" operator=\"%s\" />\n"
121             "<feComposite in=\"composite2\" in2=\"composite1\" k2=\"1\"  k3=\"1\" operator=\"arithmetic\" result=\"composite3\" />\n"
122             "<feColorMatrix in=\"composite3\" type=\"matrix\" values=\"2 -1 0 0 0 0 2 -1 0 0 -1 0 2 0 0 0 0 0 1 0 \" result=\"colormatrix2\" />\n"
123             "<feComposite in=\"colormatrix2\" in2=\"composite3\" operator=\"arithmetic\" k2=\"%s\" result=\"composite4\" />\n"
124             "<feBlend in=\"composite4\" in2=\"composite3\" blend=\"normal\" mode=\"normal\" result=\"blend\" />\n"
125             "<feComposite in2=\"SourceGraphic\" operator=\"in\" />\n"
126         "</filter>\n", a1.str().c_str(), r1.str().c_str(), g1.str().c_str(), b1.str().c_str(), swap1.str().c_str(), a2.str().c_str(), r2.str().c_str(), g2.str().c_str(), b2.str().c_str(), swap2.str().c_str(), fluo.str().c_str());
128         return _filter;
129 };
130 }; /* namespace Filter */
131 }; /* namespace Internal */
132 }; /* namespace Extension */
133 }; /* namespace Inkscape */
135 /* Change the 'COLOR' below to be your file name */
136 #endif /* __INKSCAPE_EXTENSION_INTERNAL_FILTER_COLOR_H__ */