Inkscape
Vector Graphics Editor
color.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2#ifndef SEEN_INKSCAPE_EXTENSION_INTERNAL_FILTER_COLOR_H__
3#define SEEN_INKSCAPE_EXTENSION_INTERNAL_FILTER_COLOR_H__
4/* Change the 'COLOR' above to be your file name */
5
6/*
7 * Copyright (C) 2013-2015 Authors:
8 * Ivan Louette (filters)
9 * Nicolas Dufour (UI) <nicoduf@yahoo.fr>
10 *
11 * Color filters
12 * Brilliance
13 * Channel painting
14 * Color blindness
15 * Color shift
16 * Colorize
17 * Component transfer
18 * Duochrome
19 * Extract channel
20 * Fade to black or white
21 * Greyscale
22 * Invert
23 * Lighting
24 * Lightness-contrast
25 * Nudge RGB
26 * Nudge CMY
27 * Quadritone
28 * Simple blend
29 * Solarize
30 * Tritone
31 *
32 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
33 */
34/* ^^^ Change the copyright to be you and your e-mail address ^^^ */
35
36#include "filter.h"
37
39#include "extension/system.h"
40#include "extension/extension.h"
41
42namespace Inkscape {
43namespace Extension {
44namespace Internal {
45namespace Filter {
46
65protected:
66 gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override;
67
68public:
69 Brilliance ( ) : Filter() { };
70 ~Brilliance ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; }
71
72 static void init () {
73 // clang-format off
75 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
76 "<name>" N_("Brilliance") "</name>\n"
77 "<id>org.inkscape.effect.filter.Brilliance</id>\n"
78 "<param name=\"brightness\" gui-text=\"" N_("Brightness") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"1\" max=\"10.00\">2</param>\n"
79 "<param name=\"sat\" gui-text=\"" N_("Over-saturation") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0.0\" max=\"10.00\">0.5</param>\n"
80 "<param name=\"lightness\" gui-text=\"" N_("Lightness") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"-10.00\" max=\"10.00\">0</param>\n"
81 "<param name=\"invert\" gui-text=\"" N_("Inverted") "\" type=\"bool\">false</param>\n"
82 "<effect>\n"
83 "<object-type>all</object-type>\n"
84 "<effects-menu>\n"
85 "<submenu name=\"" N_("Filters") "\">\n"
86 "<submenu name=\"" N_("Color") "\"/>\n"
87 "</submenu>\n"
88 "</effects-menu>\n"
89 "<menu-tip>" N_("Brightness filter") "</menu-tip>\n"
90 "</effect>\n"
91 "</inkscape-extension>\n", std::make_unique<Brilliance>());
92 // clang-format on
93 };
94};
95
96gchar const *
98{
99 if (_filter != nullptr) g_free((void *)_filter);
100
101 std::ostringstream brightness;
102 std::ostringstream sat;
103 std::ostringstream lightness;
104
105 if (ext->get_param_bool("invert")) {
106 brightness << -ext->get_param_float("brightness");
107 sat << 1 + ext->get_param_float("sat");
108 lightness << -ext->get_param_float("lightness");
109 } else {
110 brightness << ext->get_param_float("brightness");
111 sat << -ext->get_param_float("sat");
112 lightness << ext->get_param_float("lightness");
113 }
114
115 // clang-format off
116 _filter = g_strdup_printf(
117 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" style=\"color-interpolation-filters:sRGB;\" inkscape:label=\"Brilliance\">\n"
118 "<feColorMatrix values=\"%s %s %s 0 %s %s %s %s 0 %s %s %s %s 0 %s 0 0 0 1 0 \" />\n"
119 "</filter>\n", brightness.str().c_str(), sat.str().c_str(), sat.str().c_str(),
120 lightness.str().c_str(), sat.str().c_str(), brightness.str().c_str(),
121 sat.str().c_str(), lightness.str().c_str(), sat.str().c_str(),
122 sat.str().c_str(), brightness.str().c_str(), lightness.str().c_str() );
123 // clang-format on
124
125 return _filter;
126}; /* Brilliance filter */
127
149protected:
150 gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override;
151
152public:
153 ChannelPaint ( ) : Filter() { };
154 ~ChannelPaint ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; }
155
156 static void init () {
157 // clang-format off
159 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
160 "<name>" N_("Channel Painting") "</name>\n"
161 "<id>org.inkscape.effect.filter.ChannelPaint</id>\n"
162 "<param name=\"tab\" type=\"notebook\">\n"
163 "<page name=\"optionstab\" gui-text=\"Options\">\n"
164 "<param name=\"saturation\" gui-text=\"" N_("Saturation") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0.\" max=\"1.\">1</param>\n"
165 "<param name=\"red\" gui-text=\"" N_("Red") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"-10.\" max=\"10.\">-1</param>\n"
166 "<param name=\"green\" gui-text=\"" N_("Green") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"-10.\" max=\"10.\">0.5</param>\n"
167 "<param name=\"blue\" gui-text=\"" N_("Blue") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"-10.\" max=\"10.\">0.5</param>\n"
168 "<param name=\"alpha\" gui-text=\"" N_("Alpha") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"-10.\" max=\"10.\">1</param>\n"
169 "<param name=\"invert\" gui-text=\"" N_("Inverted") "\" type=\"bool\">false</param>\n"
170 "</page>\n"
171 "<page name=\"colortab\" gui-text=\"Color\">\n"
172 "<param name=\"color\" gui-text=\"" N_("Color") "\" type=\"color\">16777215</param>\n"
173 "</page>\n"
174 "</param>\n"
175 "<effect>\n"
176 "<object-type>all</object-type>\n"
177 "<effects-menu>\n"
178 "<submenu name=\"" N_("Filters") "\">\n"
179 "<submenu name=\"" N_("Color") "\"/>\n"
180 "</submenu>\n"
181 "</effects-menu>\n"
182 "<menu-tip>" N_("Replace RGB by any color") "</menu-tip>\n"
183 "</effect>\n"
184 "</inkscape-extension>\n", std::make_unique<ChannelPaint>());
185 // clang-format on
186 };
187};
188
189gchar const *
191{
192 if (_filter != nullptr) g_free((void *)_filter);
193
194 std::ostringstream saturation;
195 std::ostringstream red;
196 std::ostringstream green;
197 std::ostringstream blue;
198 std::ostringstream alpha;
199 std::ostringstream invert;
200 std::ostringstream floodRed;
201 std::ostringstream floodGreen;
202 std::ostringstream floodBlue;
203 std::ostringstream floodAlpha;
204
205 saturation << ext->get_param_float("saturation");
206 red << ext->get_param_float("red");
207 green << ext->get_param_float("green");
208 blue << ext->get_param_float("blue");
209 alpha << ext->get_param_float("alpha");
210
211 guint32 color = ext->get_param_color("color");
212 floodRed << ((color >> 24) & 0xff);
213 floodGreen << ((color >> 16) & 0xff);
214 floodBlue << ((color >> 8) & 0xff);
215 floodAlpha << (color & 0xff) / 255.0F;
216
217 if (ext->get_param_bool("invert")) {
218 invert << "in";
219 } else {
220 invert << "out";
221 }
222
223 // clang-format off
224 _filter = g_strdup_printf(
225 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" style=\"color-interpolation-filters:sRGB;\" inkscape:label=\"Channel Painting\">\n"
226 "<feColorMatrix values=\"%s\" type=\"saturate\" result=\"colormatrix1\" />\n"
227 "<feColorMatrix values=\"1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 %s %s %s %s 0 \" in=\"SourceGraphic\" result=\"colormatrix2\" />\n"
228 "<feFlood flood-color=\"rgb(%s,%s,%s)\" flood-opacity=\"%s\" result=\"flood\" />\n"
229 "<feComposite in2=\"colormatrix2\" operator=\"%s\" result=\"composite1\" />\n"
230 "<feMerge result=\"merge\">\n"
231 "<feMergeNode in=\"colormatrix1\" />\n"
232 "<feMergeNode in=\"composite1\" />\n"
233 "</feMerge>\n"
234 "<feComposite in=\"merge\" in2=\"SourceGraphic\" operator=\"in\" result=\"composite2\" />\n"
235 "</filter>\n", saturation.str().c_str(), red.str().c_str(), green.str().c_str(),
236 blue.str().c_str(), alpha.str().c_str(), floodRed.str().c_str(),
237 floodGreen.str().c_str(), floodBlue.str().c_str(), floodAlpha.str().c_str(),
238 invert.str().c_str() );
239 // clang-format on
240
241 return _filter;
242}; /* Channel Painting filter */
243
254protected:
255 gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override;
256
257public:
259 ~ColorBlindness ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; }
260
261 static void init () {
262 // clang-format off
264 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
265 "<name>" N_("Color Blindness") "</name>\n"
266 "<id>org.inkscape.effect.filter.ColorBlindness</id>\n"
267 "<param name=\"tab\" type=\"notebook\">\n"
268 "<page name=\"optionstab\" gui-text=\"Options\">\n"
269 "<param name=\"type\" gui-text=\"" N_("Blindness type:") "\" type=\"optiongroup\" appearance=\"combo\">\n"
270 "<option value=\"0.618 0.32 0.062 0 0 0.163 0.775 0.062 0 0 0.163 0.32 0.516 0 0 0 0 0 1 0 \">" N_("Rod monochromacy (atypical achromatopsia)") "</option>\n"
271 "<option value=\"0.299 0.587 0.114 0 0 0.299 0.587 0.114 0 0 0.299 0.587 0.114 0 0 0 0 0 1 0 \">" N_("Cone monochromacy (typical achromatopsia)") "</option>\n"
272 "<option value=\"0.8 0.2 0 0 0 0.2583 0.74167 0 0 0 0 0.14167 0.85833 0 0 0 0 0 1 0 \">" N_("Green weak (deuteranomaly)") "</option>\n"
273 "<option value=\"0.625 0.375 0 0 0 0.7 0.3 0 0 0 0 0.3 0.7 0 0 0 0 0 1 0 \">" N_("Green blind (deuteranopia)") "</option>\n"
274 "<option value=\"0.8166 0.1833 0 0 0 0.333 0.666 0 0 0 0 0.125 0.875 0 0 0 0 0 1 0 \">" N_("Red weak (protanomaly)") "</option>\n"
275 "<option value=\"0.566 0.43333 0 0 0 0.55833 0.4416 0 0 0 0 0.24167 0.75833 0 0 0 0 0 1 0 \">" N_("Red blind (protanopia)") "</option>\n"
276 "<option value=\"0.966 0.033 0 0 0 0 0.733 0.266 0 0 0 0.1833 0.816 0 0 0 0 0 1 0 \">" N_("Blue weak (tritanomaly)") "</option>\n"
277 "<option value=\"0.95 0.05 0 0 0 0.2583 0.4333 0.5667 0 0 0 0.475 0.525 0 0 0 0 0 1 0 \">" N_("Blue blind (tritanopia)") "</option>\n"
278 "</param>\n"
279 "</page>\n"
280 "<page name=\"helptab\" gui-text=\"Help\">\n"
281 "<label xml:space=\"preserve\">\n"
282"Filters based on https://openclipart.org/detail/22299/Color%20Blindness%20filters\n"
283"\n"
284"These filters don't correctly reflect actual color blindness for two main reasons:\n"
285" * Everyone is different, and is not affected exactly the same way.\n"
286" * The filters are in the RGB color space, and ignore confusion lines.\n"
287 "</label>\n"
288 "</page>\n"
289 "</param>\n"
290 "<effect>\n"
291 "<object-type>all</object-type>\n"
292 "<effects-menu>\n"
293 "<submenu name=\"" N_("Filters") "\">\n"
294 "<submenu name=\"" N_("Color") "\"/>\n"
295 "</submenu>\n"
296 "</effects-menu>\n"
297 "<menu-tip>" N_("Simulate color blindness") "</menu-tip>\n"
298 "</effect>\n"
299 "</inkscape-extension>\n", std::make_unique<ColorBlindness>());
300 // clang-format on
301 };
302};
303
304gchar const *
306{
307 if (_filter != nullptr) g_free((void *)_filter);
308
309 std::ostringstream type;
310 type << ext->get_param_optiongroup("type");
311
312 // clang-format off
313 _filter = g_strdup_printf(
314 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" style=\"color-interpolation-filters:sRGB;\" height=\"1\" width=\"1\" y=\"0\" x=\"0\" inkscape:label=\"Color Blindness\">\n"
315 "<feColorMatrix values=\"%s\" type=\"matrix\" result=\"colormatrix1\" />\n"
316 "</filter>\n", type.str().c_str());
317 // clang-format on
318
319 return _filter;
320}; /* Color Blindness filter */
321
333protected:
334 gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override;
335
336public:
337 ColorShift ( ) : Filter() { };
338 ~ColorShift ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; }
339
340 static void init () {
341 // clang-format off
343 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
344 "<name>" N_("Color Shift") "</name>\n"
345 "<id>org.inkscape.effect.filter.ColorShift</id>\n"
346 "<param name=\"shift\" gui-text=\"" N_("Shift (°)") "\" type=\"int\" appearance=\"full\" min=\"0\" max=\"360\">330</param>\n"
347 "<param name=\"sat\" gui-text=\"" N_("Saturation") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0.\" max=\"1\">0.6</param>\n"
348 "<effect>\n"
349 "<object-type>all</object-type>\n"
350 "<effects-menu>\n"
351 "<submenu name=\"" N_("Filters") "\">\n"
352 "<submenu name=\"" N_("Color") "\"/>\n"
353 "</submenu>\n"
354 "</effects-menu>\n"
355 "<menu-tip>" N_("Rotate and desaturate hue") "</menu-tip>\n"
356 "</effect>\n"
357 "</inkscape-extension>\n", std::make_unique<ColorShift>());
358 // clang-format on
359 };
360
361};
362
363gchar const *
365{
366 if (_filter != nullptr) g_free((void *)_filter);
367
368 std::ostringstream shift;
369 std::ostringstream sat;
370
371 shift << ext->get_param_int("shift");
372 sat << ext->get_param_float("sat");
373
374 // clang-format off
375 _filter = g_strdup_printf(
376 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" style=\"color-interpolation-filters:sRGB;\" inkscape:label=\"Color Shift\">\n"
377 "<feColorMatrix type=\"hueRotate\" values=\"%s\" result=\"color1\" />\n"
378 "<feColorMatrix type=\"saturate\" values=\"%s\" result=\"color2\" />\n"
379 "</filter>\n", shift.str().c_str(), sat.str().c_str() );
380 // clang-format on
381
382 return _filter;
383}; /* ColorShift filter */
384
400protected:
401 gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override;
402
403public:
404 Colorize ( ) : Filter() { };
405 ~Colorize ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; }
406
407 static void init () {
408 // clang-format off
410 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
411 "<name>" N_("Colorize") "</name>\n"
412 "<id>org.inkscape.effect.filter.Colorize</id>\n"
413 "<param name=\"tab\" type=\"notebook\">\n"
414 "<page name=\"optionstab\" gui-text=\"Options\">\n"
415 "<param name=\"hlight\" gui-text=\"" N_("Harsh light") "\" type=\"float\" appearance=\"full\" min=\"0\" max=\"10\">0</param>\n"
416 "<param name=\"nlight\" gui-text=\"" N_("Normal light") "\" type=\"float\" appearance=\"full\" min=\"0\" max=\"10\">1</param>\n"
417 "<param name=\"duotone\" gui-text=\"" N_("Duotone") "\" type=\"bool\" >false</param>\n"
418 "<param name=\"blend1\" gui-text=\"" N_("Blend 1:") "\" type=\"optiongroup\" appearance=\"combo\">\n"
419 "<option value=\"multiply\">" N_("Multiply") "</option>\n"
420 "<option value=\"normal\">" N_("Normal") "</option>\n"
421 "<option value=\"screen\">" N_("Screen") "</option>\n"
422 "<option value=\"lighten\">" N_("Lighten") "</option>\n"
423 "<option value=\"darken\">" N_("Darken") "</option>\n"
424 "</param>\n"
425 "<param name=\"blend2\" gui-text=\"" N_("Blend 2:") "\" type=\"optiongroup\" appearance=\"combo\">\n"
426 "<option value=\"screen\">" N_("Screen") "</option>\n"
427 "<option value=\"multiply\">" N_("Multiply") "</option>\n"
428 "<option value=\"normal\">" N_("Normal") "</option>\n"
429 "<option value=\"lighten\">" N_("Lighten") "</option>\n"
430 "<option value=\"darken\">" N_("Darken") "</option>\n"
431 "</param>\n"
432 "</page>\n"
433 "<page name=\"colortab\" gui-text=\"Color\">\n"
434 "<param name=\"color\" gui-text=\"" N_("Color") "\" type=\"color\">-1639776001</param>\n"
435 "</page>\n"
436 "</param>\n"
437 "<effect>\n"
438 "<object-type>all</object-type>\n"
439 "<effects-menu>\n"
440 "<submenu name=\"" N_("Filters") "\">\n"
441 "<submenu name=\"" N_("Color") "\"/>\n"
442 "</submenu>\n"
443 "</effects-menu>\n"
444 "<menu-tip>" N_("Blend image or object with a flood color") "</menu-tip>\n"
445 "</effect>\n"
446 "</inkscape-extension>\n", std::make_unique<Colorize>());
447 // clang-format on
448 };
449
450};
451
452gchar const *
454{
455 if (_filter != nullptr) g_free((void *)_filter);
456
457 std::ostringstream a;
458 std::ostringstream r;
459 std::ostringstream g;
460 std::ostringstream b;
461 std::ostringstream hlight;
462 std::ostringstream nlight;
463 std::ostringstream duotone;
464 std::ostringstream blend1;
465 std::ostringstream blend2;
466
467 guint32 color = ext->get_param_color("color");
468 r << ((color >> 24) & 0xff);
469 g << ((color >> 16) & 0xff);
470 b << ((color >> 8) & 0xff);
471 a << (color & 0xff) / 255.0F;
472
473 hlight << ext->get_param_float("hlight");
474 nlight << ext->get_param_float("nlight");
475 blend1 << ext->get_param_optiongroup("blend1");
476 blend2 << ext->get_param_optiongroup("blend2");
477 if (ext->get_param_bool("duotone")) {
478 duotone << "0";
479 } else {
480 duotone << "1";
481 }
482
483 // clang-format off
484 _filter = g_strdup_printf(
485 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" style=\"color-interpolation-filters:sRGB;\" inkscape:label=\"Colorize\">\n"
486 "<feComposite in2=\"SourceGraphic\" operator=\"arithmetic\" k1=\"%s\" k2=\"%s\" result=\"composite1\" />\n"
487 "<feColorMatrix in=\"composite1\" values=\"%s\" type=\"saturate\" result=\"colormatrix1\" />\n"
488 "<feFlood flood-opacity=\"%s\" flood-color=\"rgb(%s,%s,%s)\" result=\"flood1\" />\n"
489 "<feBlend in=\"flood1\" in2=\"colormatrix1\" mode=\"%s\" result=\"blend1\" />\n"
490 "<feBlend in2=\"blend1\" mode=\"%s\" result=\"blend2\" />\n"
491 "<feColorMatrix in=\"blend2\" values=\"1\" type=\"saturate\" result=\"colormatrix2\" />\n"
492 "<feComposite in=\"colormatrix2\" in2=\"SourceGraphic\" operator=\"in\" k2=\"1\" result=\"composite2\" />\n"
493 "</filter>\n", hlight.str().c_str(), nlight.str().c_str(), duotone.str().c_str(),
494 a.str().c_str(), r.str().c_str(), g.str().c_str(), b.str().c_str(),
495 blend1.str().c_str(), blend2.str().c_str() );
496 // clang-format on
497
498 return _filter;
499}; /* Colorize filter */
500
511protected:
512 gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override;
513
514public:
516 ~ComponentTransfer ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; }
517
518 static void init () {
519 // clang-format off
521 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
522 "<name>" N_("Component Transfer") "</name>\n"
523 "<id>org.inkscape.effect.filter.ComponentTransfer</id>\n"
524 "<param name=\"type\" gui-text=\"" N_("Type:") "\" type=\"optiongroup\" appearance=\"combo\">\n"
525 "<option value=\"identity\">" N_("Identity") "</option>\n"
526 "<option value=\"table\">" N_("Table") "</option>\n"
527 "<option value=\"discrete\">" N_("Discrete") "</option>\n"
528 "<option value=\"linear\">" N_("Linear") "</option>\n"
529 "<option value=\"gamma\">" N_("Gamma") "</option>\n"
530 "</param>\n"
531 "<effect>\n"
532 "<object-type>all</object-type>\n"
533 "<effects-menu>\n"
534 "<submenu name=\"" N_("Filters") "\">\n"
535 "<submenu name=\"" N_("Color") "\"/>\n"
536 "</submenu>\n"
537 "</effects-menu>\n"
538 "<menu-tip>" N_("Basic component transfer structure") "</menu-tip>\n"
539 "</effect>\n"
540 "</inkscape-extension>\n", std::make_unique<ComponentTransfer>());
541 // clang-format on
542 };
543};
544
545gchar const *
547{
548 if (_filter != nullptr) g_free((void *)_filter);
549
550 std::ostringstream CTfunction;
551 const gchar *type = ext->get_param_optiongroup("type");
552
553 if ((g_ascii_strcasecmp("identity", type) == 0)) {
554 CTfunction << "<feFuncR type=\"identity\" tableValues=\"1 0\" />\n"
555 << "<feFuncG type=\"identity\" tableValues=\"1 0\" />\n"
556 << "<feFuncB type=\"identity\" tableValues=\"1 0\" />\n"
557 << "<feFuncA type=\"identity\" tableValues=\"0 1\" />\n";
558 } else if ((g_ascii_strcasecmp("table", type) == 0)) {
559 CTfunction << "<feFuncR type=\"table\" tableValues=\"0 1 0\" />\n"
560 << "<feFuncG type=\"table\" tableValues=\"0 1 0\" />\n"
561 << "<feFuncB type=\"table\" tableValues=\"0 1 0\" />\n";
562 } else if ((g_ascii_strcasecmp("discrete", type) == 0)) {
563 CTfunction << "<feFuncR tableValues=\"0 0.2 0.4 0.6 0.8 1 1\" type=\"discrete\" />\n"
564 << "<feFuncG tableValues=\"0 0.2 0.4 0.6 0.8 1 1\" type=\"discrete\" />\n"
565 << "<feFuncB tableValues=\"0 0.2 0.4 0.6 0.8 1 1\" type=\"discrete\" />\n";
566 } else if ((g_ascii_strcasecmp("linear", type) == 0)) {
567 CTfunction << "<feFuncR type=\"linear\" slope=\".5\" intercept=\".10\" />\n"
568 << "<feFuncG type=\"linear\" slope=\".5\" intercept=\".10\" />\n"
569 << "<feFuncB type=\"linear\" slope=\".5\" intercept=\".10\" />\n";
570 } else { //Gamma
571 CTfunction << "<feFuncR type=\"gamma\" amplitude=\"3\" exponent=\"3\" offset=\"0.1\" />\n"
572 << "<feFuncG type=\"gamma\" amplitude=\"3\" exponent=\"3\" offset=\"0.1\" />\n"
573 << "<feFuncB type=\"gamma\" amplitude=\"3\" exponent=\"3\" offset=\"0.1\" />\n";
574 }
575 // clang-format off
576 _filter = g_strdup_printf(
577 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" style=\"color-interpolation-filters:sRGB;\" inkscape:label=\"Component Transfer\">\n"
578 "<feComponentTransfer>\n"
579 "%s\n"
580 "</feComponentTransfer>\n"
581 "</filter>\n", CTfunction.str().c_str());
582 // clang-format on
583
584 return _filter;
585}; /* ComponentTransfer filter */
586
600protected:
601 gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override;
602
603public:
604 Duochrome ( ) : Filter() { };
605 ~Duochrome ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; }
606
607 static void init () {
608 // clang-format off
610 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
611 "<name>" N_("Duochrome") "</name>\n"
612 "<id>org.inkscape.effect.filter.Duochrome</id>\n"
613 "<param name=\"tab\" type=\"notebook\">\n"
614 "<page name=\"optionstab\" gui-text=\"Options\">\n"
615 "<param name=\"fluo\" gui-text=\"" N_("Fluorescence level") "\" type=\"float\" appearance=\"full\" min=\"0\" max=\"2\">0</param>\n"
616 "<param name=\"swap\" gui-text=\"" N_("Swap:") "\" type=\"optiongroup\" appearance=\"combo\">\n"
617 "<option value=\"none\">" N_("No swap") "</option>\n"
618 "<option value=\"full\">" N_("Color and alpha") "</option>\n"
619 "<option value=\"color\">" N_("Color only") "</option>\n"
620 "<option value=\"alpha\">" N_("Alpha only") "</option>\n"
621 "</param>\n"
622 "</page>\n"
623 "<page name=\"co11tab\" gui-text=\"Color 1\">\n"
624 "<param name=\"color1\" gui-text=\"" N_("Color 1") "\" type=\"color\">1364325887</param>\n"
625 "</page>\n"
626 "<page name=\"co12tab\" gui-text=\"Color 2\">\n"
627 "<param name=\"color2\" gui-text=\"" N_("Color 2") "\" type=\"color\">-65281</param>\n"
628 "</page>\n"
629 "</param>\n"
630 "<effect>\n"
631 "<object-type>all</object-type>\n"
632 "<effects-menu>\n"
633 "<submenu name=\"" N_("Filters") "\">\n"
634 "<submenu name=\"" N_("Color") "\"/>\n"
635 "</submenu>\n"
636 "</effects-menu>\n"
637 "<menu-tip>" N_("Convert luminance values to a duochrome palette") "</menu-tip>\n"
638 "</effect>\n"
639 "</inkscape-extension>\n", std::make_unique<Duochrome>());
640 // clang-format on
641 };
642
643};
644
645gchar const *
647{
648 if (_filter != nullptr) g_free((void *)_filter);
649
650 std::ostringstream a1;
651 std::ostringstream r1;
652 std::ostringstream g1;
653 std::ostringstream b1;
654 std::ostringstream a2;
655 std::ostringstream r2;
656 std::ostringstream g2;
657 std::ostringstream b2;
658 std::ostringstream fluo;
659 std::ostringstream swap1;
660 std::ostringstream swap2;
661 guint32 color1 = ext->get_param_color("color1");
662 guint32 color2 = ext->get_param_color("color2");
663 double fluorescence = ext->get_param_float("fluo");
664 const gchar *swaptype = ext->get_param_optiongroup("swap");
665
666 r1 << ((color1 >> 24) & 0xff);
667 g1 << ((color1 >> 16) & 0xff);
668 b1 << ((color1 >> 8) & 0xff);
669 r2 << ((color2 >> 24) & 0xff);
670 g2 << ((color2 >> 16) & 0xff);
671 b2 << ((color2 >> 8) & 0xff);
672 fluo << fluorescence;
673
674 if ((g_ascii_strcasecmp("full", swaptype) == 0)) {
675 swap1 << "in";
676 swap2 << "out";
677 a1 << (color1 & 0xff) / 255.0F;
678 a2 << (color2 & 0xff) / 255.0F;
679 } else if ((g_ascii_strcasecmp("color", swaptype) == 0)) {
680 swap1 << "in";
681 swap2 << "out";
682 a1 << (color2 & 0xff) / 255.0F;
683 a2 << (color1 & 0xff) / 255.0F;
684 } else if ((g_ascii_strcasecmp("alpha", swaptype) == 0)) {
685 swap1 << "out";
686 swap2 << "in";
687 a1 << (color2 & 0xff) / 255.0F;
688 a2 << (color1 & 0xff) / 255.0F;
689 } else {
690 swap1 << "out";
691 swap2 << "in";
692 a1 << (color1 & 0xff) / 255.0F;
693 a2 << (color2 & 0xff) / 255.0F;
694 }
695
696 // clang-format off
697 _filter = g_strdup_printf(
698 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" style=\"color-interpolation-filters:sRGB;\" inkscape:label=\"Duochrome\">\n"
699 "<feColorMatrix type=\"luminanceToAlpha\" result=\"colormatrix1\" />\n"
700 "<feFlood flood-opacity=\"%s\" flood-color=\"rgb(%s,%s,%s)\" result=\"flood1\" />\n"
701 "<feComposite in2=\"colormatrix1\" operator=\"%s\" result=\"composite1\" />\n"
702 "<feFlood flood-opacity=\"%s\" flood-color=\"rgb(%s,%s,%s)\" result=\"flood2\" />\n"
703 "<feComposite in2=\"colormatrix1\" result=\"composite2\" operator=\"%s\" />\n"
704 "<feComposite in=\"composite2\" in2=\"composite1\" k2=\"1\" k3=\"1\" operator=\"arithmetic\" result=\"composite3\" />\n"
705 "<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"
706 "<feComposite in=\"colormatrix2\" in2=\"composite3\" operator=\"arithmetic\" k2=\"%s\" result=\"composite4\" />\n"
707 "<feBlend in=\"composite4\" in2=\"composite3\" mode=\"normal\" result=\"blend\" />\n"
708 "<feComposite in2=\"SourceGraphic\" operator=\"in\" />\n"
709 "</filter>\n", a1.str().c_str(), r1.str().c_str(), g1.str().c_str(), b1.str().c_str(), swap1.str().c_str(),
710 a2.str().c_str(), r2.str().c_str(), g2.str().c_str(), b2.str().c_str(), swap2.str().c_str(),
711 fluo.str().c_str() );
712 // clang-format on
713
714 return _filter;
715}; /* Duochrome filter */
716
729protected:
730 gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override;
731
732public:
734 ~ExtractChannel ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; }
735
736 static void init () {
737 // clang-format off
739 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
740 "<name>" N_("Extract Channel") "</name>\n"
741 "<id>org.inkscape.effect.filter.ExtractChannel</id>\n"
742 "<param name=\"source\" gui-text=\"" N_("Channel:") "\" type=\"optiongroup\" appearance=\"combo\">\n"
743 "<option value=\"r\">" N_("Red") "</option>\n"
744 "<option value=\"g\">" N_("Green") "</option>\n"
745 "<option value=\"b\">" N_("Blue") "</option>\n"
746 "<option value=\"c\">" N_("Cyan") "</option>\n"
747 "<option value=\"m\">" N_("Magenta") "</option>\n"
748 "<option value=\"y\">" N_("Yellow") "</option>\n"
749 "</param>\n"
750 "<param name=\"blend\" gui-text=\"" N_("Background blend mode:") "\" type=\"optiongroup\" appearance=\"combo\">\n"
751 "<option value=\"multiply\">" N_("Multiply") "</option>\n"
752 "<option value=\"normal\">" N_("Normal") "</option>\n"
753 "<option value=\"screen\">" N_("Screen") "</option>\n"
754 "</param>\n"
755 "<param name=\"alpha\" gui-text=\"" N_("Channel to alpha") "\" type=\"bool\">false</param>\n"
756 "<effect>\n"
757 "<object-type>all</object-type>\n"
758 "<effects-menu>\n"
759 "<submenu name=\"" N_("Filters") "\">\n"
760 "<submenu name=\"" N_("Color") "\"/>\n"
761 "</submenu>\n"
762 "</effects-menu>\n"
763 "<menu-tip>" N_("Extract color channel as a transparent image") "</menu-tip>\n"
764 "</effect>\n"
765 "</inkscape-extension>\n", std::make_unique<ExtractChannel>());
766 // clang-format on
767 };
768};
769
770gchar const *
772{
773 if (_filter != nullptr) g_free((void *)_filter);
774
775 std::ostringstream blend;
776 std::ostringstream colors;
777
778 blend << ext->get_param_optiongroup("blend");
779
780 const gchar *channel = ext->get_param_optiongroup("source");
781 if (ext->get_param_bool("alpha")) {
782 if ((g_ascii_strcasecmp("r", channel) == 0)) {
783 colors << "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0";
784 } else if ((g_ascii_strcasecmp("g", channel) == 0)) {
785 colors << "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0";
786 } else if ((g_ascii_strcasecmp("b", channel) == 0)) {
787 colors << "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0";
788 } else if ((g_ascii_strcasecmp("c", channel) == 0)) {
789 colors << "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 1 0";
790 } else if ((g_ascii_strcasecmp("m", channel) == 0)) {
791 colors << "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 1 0";
792 } else {
793 colors << "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 1 0";
794 }
795 } else {
796 if ((g_ascii_strcasecmp("r", channel) == 0)) {
797 colors << "0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0";
798 } else if ((g_ascii_strcasecmp("g", channel) == 0)) {
799 colors << "0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0";
800 } else if ((g_ascii_strcasecmp("b", channel) == 0)) {
801 colors << "0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0";
802 } else if ((g_ascii_strcasecmp("c", channel) == 0)) {
803 colors << "0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 -1 0 0 1 0";
804 } else if ((g_ascii_strcasecmp("m", channel) == 0)) {
805 colors << "0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 -1 0 1 0";
806 } else {
807 colors << "0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 -1 1 0";
808 }
809 }
810
811 // clang-format off
812 _filter = g_strdup_printf(
813 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" style=\"color-interpolation-filters:sRGB;\" inkscape:label=\"Extract Channel\">\n"
814 "<feColorMatrix in=\"SourceGraphic\" values=\"%s 0 \" result=\"colormatrix\" />\n"
815 "<feBlend in2=\"BackgroundImage\" mode=\"%s\" result=\"blend\" />\n"
816 "</filter>\n", colors.str().c_str(), blend.str().c_str() );
817 // clang-format on
818
819 return _filter;
820}; /* ExtractChannel filter */
821
839protected:
840 gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override;
841
842public:
843 FadeToBW ( ) : Filter() { };
844 ~FadeToBW ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; }
845
846 static void init () {
847 // clang-format off
849 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
850 "<name>" N_("Fade to Black or White") "</name>\n"
851 "<id>org.inkscape.effect.filter.FadeToBW</id>\n"
852 "<param name=\"level\" gui-text=\"" N_("Level") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0\" max=\"1\">1</param>\n"
853 "<param name=\"fadeto\" gui-text=\"" N_("Fade to:") "\" type=\"optiongroup\" appearance=\"combo\">\n"
854 "<option value=\"black\">" N_("Black") "</option>\n"
855 "<option value=\"white\">" N_("White") "</option>\n"
856 "</param>\n"
857 "<effect>\n"
858 "<object-type>all</object-type>\n"
859 "<effects-menu>\n"
860 "<submenu name=\"" N_("Filters") "\">\n"
861 "<submenu name=\"" N_("Color") "\"/>\n"
862 "</submenu>\n"
863 "</effects-menu>\n"
864 "<menu-tip>" N_("Fade to black or white") "</menu-tip>\n"
865 "</effect>\n"
866 "</inkscape-extension>\n", std::make_unique<FadeToBW>());
867 // clang-format on
868 };
869};
870
871gchar const *
873{
874 if (_filter != nullptr) g_free((void *)_filter);
875
876 std::ostringstream level;
877 std::ostringstream wlevel;
878
879 level << ext->get_param_float("level");
880
881 const gchar *fadeto = ext->get_param_optiongroup("fadeto");
882 if ((g_ascii_strcasecmp("white", fadeto) == 0)) {
883 // White
884 wlevel << (1 - ext->get_param_float("level"));
885 } else {
886 // Black
887 wlevel << "0";
888 }
889
890 // clang-format off
891 _filter = g_strdup_printf(
892 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" style=\"color-interpolation-filters:sRGB;\" inkscape:label=\"Fade to Black or White\">\n"
893 "<feColorMatrix values=\"%s 0 0 0 %s 0 %s 0 0 %s 0 0 %s 0 %s 0 0 0 1 0\" />\n"
894 "</filter>\n", level.str().c_str(), wlevel.str().c_str(),
895 level.str().c_str(), wlevel.str().c_str(),
896 level.str().c_str(), wlevel.str().c_str() );
897 // clang-format on
898
899 return _filter;
900}; /* Fade to black or white filter */
901
922protected:
923 gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override;
924
925public:
926 Greyscale ( ) : Filter() { };
927 ~Greyscale ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; }
928
929 static void init () {
930 // clang-format off
932 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
933 "<name>" N_("Greyscale") "</name>\n"
934 "<id>org.inkscape.effect.filter.Greyscale</id>\n"
935 "<param name=\"red\" gui-text=\"" N_("Red") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"-10.00\" max=\"10.00\">0.21</param>\n"
936 "<param name=\"green\" gui-text=\"" N_("Green") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"-10.00\" max=\"10.00\">0.72</param>\n"
937 "<param name=\"blue\" gui-text=\"" N_("Blue") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"-10.00\" max=\"10.00\">0.072</param>\n"
938 "<param name=\"strength\" gui-text=\"" N_("Lightness") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"-10.00\" max=\"10.00\">0</param>\n"
939 "<param name=\"transparent\" gui-text=\"" N_("Transparent") "\" type=\"bool\" >false</param>\n"
940 "<effect>\n"
941 "<object-type>all</object-type>\n"
942 "<effects-menu>\n"
943 "<submenu name=\"" N_("Filters") "\">\n"
944 "<submenu name=\"" N_("Color") "\"/>\n"
945 "</submenu>\n"
946 "</effects-menu>\n"
947 "<menu-tip>" N_("Customize greyscale components") "</menu-tip>\n"
948 "</effect>\n"
949 "</inkscape-extension>\n", std::make_unique<Greyscale>());
950 // clang-format on
951 };
952};
953
954gchar const *
956{
957 if (_filter != nullptr) g_free((void *)_filter);
958
959 std::ostringstream red;
960 std::ostringstream green;
961 std::ostringstream blue;
962 std::ostringstream strength;
963 std::ostringstream redt;
964 std::ostringstream greent;
965 std::ostringstream bluet;
966 std::ostringstream strengtht;
967 std::ostringstream transparency;
968 std::ostringstream line;
969
970 red << ext->get_param_float("red");
971 green << ext->get_param_float("green");
972 blue << ext->get_param_float("blue");
973 strength << ext->get_param_float("strength");
974
975 redt << - ext->get_param_float("red");
976 greent << - ext->get_param_float("green");
977 bluet << - ext->get_param_float("blue");
978 strengtht << 1 - ext->get_param_float("strength");
979
980 if (ext->get_param_bool("transparent")) {
981 line << "0 0 0 0";
982 transparency << redt.str().c_str() << " " << greent.str().c_str() << " " << bluet.str().c_str() << " " << strengtht.str().c_str();
983 } else {
984 line << red.str().c_str() << " " << green.str().c_str() << " " << blue.str().c_str() << " " << strength.str().c_str();
985 transparency << "0 0 0 1";
986 }
987
988 // clang-format off
989 _filter = g_strdup_printf(
990 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" style=\"color-interpolation-filters:sRGB;\" inkscape:label=\"Greyscale\">\n"
991 "<feColorMatrix values=\"%s 0 %s 0 %s 0 %s 0 \" />\n"
992 "</filter>\n", line.str().c_str(), line.str().c_str(), line.str().c_str(), transparency.str().c_str() );
993 // clang-format on
994
995 return _filter;
996}; /* Greyscale filter */
997
1013protected:
1014 gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override;
1015
1016public:
1017 Invert ( ) : Filter() { };
1018 ~Invert ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; }
1019
1020 static void init () {
1021 // clang-format off
1023 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
1024 "<name>" N_("Invert") "</name>\n"
1025 "<id>org.inkscape.effect.filter.Invert</id>\n"
1026 "<param name=\"channels\" gui-text=\"" N_("Invert channels:") "\" type=\"optiongroup\" appearance=\"combo\">\n"
1027 "<option value=\"0\">" N_("No inversion") "</option>\n"
1028 "<option value=\"1\">" N_("Red and blue") "</option>\n"
1029 "<option value=\"2\">" N_("Red and green") "</option>\n"
1030 "<option value=\"3\">" N_("Green and blue") "</option>\n"
1031 "</param>\n"
1032 "<param name=\"opacify\" gui-text=\"" N_("Light transparency") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0.\" max=\"1\">0</param>\n"
1033 "<param name=\"hue\" gui-text=\"" N_("Invert hue") "\" type=\"bool\" >false</param>\n"
1034 "<param name=\"lightness\" gui-text=\"" N_("Invert lightness") "\" type=\"bool\" >false</param>\n"
1035 "<param name=\"transparency\" gui-text=\"" N_("Invert transparency") "\" type=\"bool\" >false</param>\n"
1036 "<effect>\n"
1037 "<object-type>all</object-type>\n"
1038 "<effects-menu>\n"
1039 "<submenu name=\"" N_("Filters") "\">\n"
1040 "<submenu name=\"" N_("Color") "\"/>\n"
1041 "</submenu>\n"
1042 "</effects-menu>\n"
1043 "<menu-tip>" N_("Manage hue, lightness and transparency inversions") "</menu-tip>\n"
1044 "</effect>\n"
1045 "</inkscape-extension>\n", std::make_unique<Invert>());
1046 // clang-format on
1047 };
1048
1049};
1050
1051gchar const *
1053{
1054 if (_filter != nullptr) g_free((void *)_filter);
1055
1056 std::ostringstream line1;
1057 std::ostringstream line2;
1058 std::ostringstream line3;
1059
1060 std::ostringstream col5;
1061 std::ostringstream transparency;
1062 std::ostringstream hue;
1063
1064 if (ext->get_param_bool("hue") ^ ext->get_param_bool("lightness")) {
1065 hue << "<feColorMatrix type=\"hueRotate\" values=\"180\" result=\"color1\" />\n";
1066 } else {
1067 hue << "";
1068 }
1069
1070 if (ext->get_param_bool("transparency")) {
1071 transparency << "0.21 0.72 0.07 " << 1 - ext->get_param_float("opacify");
1072 } else {
1073 transparency << "-0.21 -0.72 -0.07 " << 2 - ext->get_param_float("opacify");
1074 }
1075
1076 if (ext->get_param_bool("lightness")) {
1077 switch (atoi(ext->get_param_optiongroup("channels"))) {
1078 case 1:
1079 line1 << "0 0 -1";
1080 line2 << "0 -1 0";
1081 line3 << "-1 0 0";
1082 break;
1083 case 2:
1084 line1 << "0 -1 0";
1085 line2 << "-1 0 0";
1086 line3 << "0 0 -1";
1087 break;
1088 case 3:
1089 line1 << "-1 0 0";
1090 line2 << "0 0 -1";
1091 line3 << "0 -1 0";
1092 break;
1093 default:
1094 line1 << "-1 0 0";
1095 line2 << "0 -1 0";
1096 line3 << "0 0 -1";
1097 break;
1098 }
1099 col5 << "1";
1100 } else {
1101 switch (atoi(ext->get_param_optiongroup("channels"))) {
1102 case 1:
1103 line1 << "0 0 1";
1104 line2 << "0 1 0";
1105 line3 << "1 0 0";
1106 break;
1107 case 2:
1108 line1 << "0 1 0";
1109 line2 << "1 0 0";
1110 line3 << "0 0 1";
1111 break;
1112 case 3:
1113 line1 << "1 0 0";
1114 line2 << "0 0 1";
1115 line3 << "0 1 0";
1116 break;
1117 default:
1118 line1 << "1 0 0";
1119 line2 << "0 1 0";
1120 line3 << "0 0 1";
1121 break;
1122 }
1123 col5 << "0";
1124 }
1125
1126 // clang-format off
1127 _filter = g_strdup_printf(
1128 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" style=\"color-interpolation-filters:sRGB;\" inkscape:label=\"Invert\">\n"
1129 "%s"
1130 "<feColorMatrix values=\"%s 0 %s %s 0 %s %s 0 %s %s 0 \" result=\"color2\" />\n"
1131 "</filter>\n", hue.str().c_str(),
1132 line1.str().c_str(), col5.str().c_str(),
1133 line2.str().c_str(), col5.str().c_str(),
1134 line3.str().c_str(), col5.str().c_str(),
1135 transparency.str().c_str() );
1136 // clang-format on
1137
1138 return _filter;
1139}; /* Invert filter */
1140
1152protected:
1153 gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override;
1154
1155public:
1156 Lighting ( ) : Filter() { };
1157 ~Lighting ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; }
1158
1159 static void init () {
1160 // clang-format off
1162 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
1163 "<name>" N_("Lighting") "</name>\n"
1164 "<id>org.inkscape.effect.filter.Lighting</id>\n"
1165 "<param name=\"amplitude\" gui-text=\"" N_("Lights") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0.00\" max=\"20.00\">1</param>\n"
1166 "<param name=\"exponent\" gui-text=\"" N_("Shadows") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0.00\" max=\"20.00\">1</param>\n"
1167 "<param name=\"offset\" gui-text=\"" N_("Offset") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"-1.00\" max=\"1.00\">0</param>\n"
1168 "<effect>\n"
1169 "<object-type>all</object-type>\n"
1170 "<effects-menu>\n"
1171 "<submenu name=\"" N_("Filters") "\">\n"
1172 "<submenu name=\"" N_("Color") "\"/>\n"
1173 "</submenu>\n"
1174 "</effects-menu>\n"
1175 "<menu-tip>" N_("Modify lights and shadows separately") "</menu-tip>\n"
1176 "</effect>\n"
1177 "</inkscape-extension>\n", std::make_unique<Lighting>());
1178 // clang-format on
1179 };
1180};
1181
1182gchar const *
1184{
1185 if (_filter != nullptr) g_free((void *)_filter);
1186
1187 std::ostringstream amplitude;
1188 std::ostringstream exponent;
1189 std::ostringstream offset;
1190
1191 amplitude << ext->get_param_float("amplitude");
1192 exponent << ext->get_param_float("exponent");
1193 offset << ext->get_param_float("offset");
1194
1195 // clang-format off
1196 _filter = g_strdup_printf(
1197 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" style=\"color-interpolation-filters:sRGB;\" inkscape:label=\"Lighting\">\n"
1198 "<feComponentTransfer in=\"blur\" result=\"component\" >\n"
1199 "<feFuncR type=\"gamma\" amplitude=\"%s\" exponent=\"%s\" offset=\"%s\" />\n"
1200 "<feFuncG type=\"gamma\" amplitude=\"%s\" exponent=\"%s\" offset=\"%s\" />\n"
1201 "<feFuncB type=\"gamma\" amplitude=\"%s\" exponent=\"%s\" offset=\"%s\" />\n"
1202 "</feComponentTransfer>\n"
1203 "</filter>\n", amplitude.str().c_str(), exponent.str().c_str(), offset.str().c_str(),
1204 amplitude.str().c_str(), exponent.str().c_str(), offset.str().c_str(),
1205 amplitude.str().c_str(), exponent.str().c_str(), offset.str().c_str() );
1206 // clang-format on
1207
1208 return _filter;
1209}; /* Lighting filter */
1210
1227protected:
1228 gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override;
1229
1230public:
1232 ~LightnessContrast ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; }
1233
1234 static void init () {
1235 // clang-format off
1237 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
1238 "<name>" N_("Lightness-Contrast") "</name>\n"
1239 "<id>org.inkscape.effect.filter.LightnessContrast</id>\n"
1240 "<param name=\"lightness\" gui-text=\"" N_("Lightness") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"-100\" max=\"100\">0</param>\n"
1241 "<param name=\"contrast\" gui-text=\"" N_("Contrast") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"-100\" max=\"100\">0</param>\n"
1242 "<effect>\n"
1243 "<object-type>all</object-type>\n"
1244 "<effects-menu>\n"
1245 "<submenu name=\"" N_("Filters") "\">\n"
1246 "<submenu name=\"" N_("Color") "\"/>\n"
1247 "</submenu>\n"
1248 "</effects-menu>\n"
1249 "<menu-tip>" N_("Modify lightness and contrast separately") "</menu-tip>\n"
1250 "</effect>\n"
1251 "</inkscape-extension>\n", std::make_unique<LightnessContrast>());
1252 // clang-format on
1253 };
1254};
1255
1256gchar const *
1258{
1259 if (_filter != nullptr) g_free((void *)_filter);
1260
1261 std::ostringstream lightness;
1262 std::ostringstream contrast;
1263 std::ostringstream contrast5;
1264
1265 double c5;
1266 if (ext->get_param_float("contrast") > 0) {
1267 contrast << (1 + ext->get_param_float("contrast") / 10);
1268 c5 = (- ext->get_param_float("contrast") / 20);
1269 } else {
1270 contrast << (1 + ext->get_param_float("contrast") / 100);
1271 c5 =(- ext->get_param_float("contrast") / 200);
1272 }
1273
1274 contrast5 << c5;
1275 lightness << ((1 - c5) * ext->get_param_float("lightness") / 100);
1276
1277 // clang-format off
1278 _filter = g_strdup_printf(
1279 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" style=\"color-interpolation-filters:sRGB;\" inkscape:label=\"Lightness-Contrast\">\n"
1280 "<feColorMatrix values=\"%s 0 0 %s %s 0 %s 0 %s %s 0 0 %s %s %s 0 0 0 1 0\" />\n"
1281 "</filter>\n", contrast.str().c_str(), lightness.str().c_str(), contrast5.str().c_str(),
1282 contrast.str().c_str(), lightness.str().c_str(), contrast5.str().c_str(),
1283 contrast.str().c_str(), lightness.str().c_str(), contrast5.str().c_str() );
1284 // clang-format on
1285
1286 return _filter;
1287}; /* Lightness-Contrast filter */
1288
1310protected:
1311 gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override;
1312
1313public:
1314 NudgeRGB ( ) : Filter() { };
1315 ~NudgeRGB ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; }
1316
1317 static void init () {
1318 // clang-format off
1320 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
1321 "<name>" N_("Nudge RGB") "</name>\n"
1322 "<id>org.inkscape.effect.filter.NudgeRGB</id>\n"
1323 "<param name=\"tab\" type=\"notebook\">\n"
1324 "<page name=\"offsettab\" gui-text=\"Offset\">\n"
1325 "<label appearance=\"header\">" N_("Red offset") "</label>\n"
1326 "<param name=\"rx\" gui-text=\"" N_("X") "\" type=\"float\" indent=\"1\" appearance=\"full\" precision=\"2\" min=\"-100.\" max=\"100.\">-6</param>\n"
1327 "<param name=\"ry\" gui-text=\"" N_("Y") "\" type=\"float\" indent=\"1\" appearance=\"full\" precision=\"2\" min=\"-100.\" max=\"100.\">-6</param>\n"
1328 "<label appearance=\"header\">" N_("Green offset") "</label>\n"
1329 "<param name=\"gx\" gui-text=\"" N_("X") "\" type=\"float\" indent=\"1\" appearance=\"full\" precision=\"2\" min=\"-100.\" max=\"100.\">6</param>\n"
1330 "<param name=\"gy\" gui-text=\"" N_("Y") "\" type=\"float\" indent=\"1\" appearance=\"full\" precision=\"2\" min=\"-100.\" max=\"100.\">7</param>\n"
1331 "<label appearance=\"header\">" N_("Blue offset") "</label>\n"
1332 "<param name=\"bx\" gui-text=\"" N_("X") "\" type=\"float\" indent=\"1\" appearance=\"full\" precision=\"2\" min=\"-100.\" max=\"100.\">1</param>\n"
1333 "<param name=\"by\" gui-text=\"" N_("Y") "\" type=\"float\" indent=\"1\" appearance=\"full\" precision=\"2\" min=\"-100.\" max=\"100.\">-16</param>\n"
1334 "</page>\n"
1335 "<page name=\"coltab\" gui-text=\"Color\">\n"
1336 "<param name=\"color\" gui-text=\"" N_("Background color") "\" type=\"color\">255</param>\n"
1337 "</page>\n"
1338 "</param>\n"
1339 "<effect>\n"
1340 "<object-type>all</object-type>\n"
1341 "<effects-menu>\n"
1342 "<submenu name=\"" N_("Filters") "\">\n"
1343 "<submenu name=\"" N_("Color") "\"/>\n"
1344 "</submenu>\n"
1345 "</effects-menu>\n"
1346 "<menu-tip>" N_("Nudge RGB channels separately and blend them to different types of backgrounds") "</menu-tip>\n"
1347 "</effect>\n"
1348 "</inkscape-extension>\n", std::make_unique<NudgeRGB>());
1349 // clang-format on
1350 };
1351};
1352
1353gchar const *
1355{
1356 if (_filter != nullptr) g_free((void *)_filter);
1357
1358 std::ostringstream rx;
1359 std::ostringstream ry;
1360 std::ostringstream gx;
1361 std::ostringstream gy;
1362 std::ostringstream bx;
1363 std::ostringstream by;
1364
1365 std::ostringstream a;
1366 std::ostringstream r;
1367 std::ostringstream g;
1368 std::ostringstream b;
1369
1370 rx << ext->get_param_float("rx");
1371 ry << ext->get_param_float("ry");
1372 gx << ext->get_param_float("gx");
1373 gy << ext->get_param_float("gy");
1374 bx << ext->get_param_float("bx");
1375 by << ext->get_param_float("by");
1376
1377 guint32 color = ext->get_param_color("color");
1378 r << ((color >> 24) & 0xff);
1379 g << ((color >> 16) & 0xff);
1380 b << ((color >> 8) & 0xff);
1381 a << (color & 0xff) / 255.0F;
1382
1383 // clang-format off
1384 _filter = g_strdup_printf(
1385 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" style=\"color-interpolation-filters:sRGB;\" inkscape:label=\"Nudge RGB\">\n"
1386 "<feFlood flood-opacity=\"%s\" flood-color=\"rgb(%s,%s,%s)\" result=\"flood\" />\n"
1387 "<feColorMatrix in=\"SourceGraphic\" values=\"0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 \" result=\"colormatrix1\" />\n"
1388 "<feOffset dy=\"%s\" dx=\"%s\" result=\"offset1\" />\n"
1389 "<feBlend in2=\"flood\" mode=\"screen\" result=\"blend1\" />\n"
1390 "<feColorMatrix in=\"SourceGraphic\" values=\"0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 \" result=\"colormatrix2\" />\n"
1391 "<feOffset dy=\"%s\" dx=\"%s\" result=\"offset2\" />\n"
1392 "<feBlend in2=\"blend1\" mode=\"screen\" result=\"blend2\" />\n"
1393 "<feOffset dy=\"%s\" dx=\"%s\" result=\"offset3\" />\n"
1394 "<feColorMatrix in=\"SourceGraphic\" values=\"0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 \" result=\"colormatrix3\" />\n"
1395 "<feBlend in2=\"offset3\" mode=\"screen\" result=\"blend3\" />\n"
1396 "</filter>\n", a.str().c_str(), r.str().c_str(), g.str().c_str(), b.str().c_str(),
1397 rx.str().c_str(), ry.str().c_str(),
1398 gx.str().c_str(), gy.str().c_str(),
1399 bx.str().c_str(), by.str().c_str() );
1400 // clang-format on
1401
1402 return _filter;
1403
1404}; /* Nudge RGB filter */
1405
1426protected:
1427 gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override;
1428
1429public:
1430 NudgeCMY ( ) : Filter() { };
1431 ~NudgeCMY ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; }
1432
1433 static void init () {
1434 // clang-format off
1436 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
1437 "<name>" N_("Nudge CMY") "</name>\n"
1438 "<id>org.inkscape.effect.filter.NudgeCMY</id>\n"
1439 "<param name=\"tab\" type=\"notebook\">\n"
1440 "<page name=\"offsettab\" gui-text=\"Offset\">\n"
1441 "<label appearance=\"header\">" N_("Cyan offset") "</label>\n"
1442 "<param name=\"cx\" gui-text=\"" N_("X") "\" type=\"float\" indent=\"1\" appearance=\"full\" precision=\"2\" min=\"-100.\" max=\"100.\">-6</param>\n"
1443 "<param name=\"cy\" gui-text=\"" N_("Y") "\" type=\"float\" indent=\"1\" appearance=\"full\" precision=\"2\" min=\"-100.\" max=\"100.\">-6</param>\n"
1444 "<label appearance=\"header\">" N_("Magenta offset") "</label>\n"
1445 "<param name=\"mx\" gui-text=\"" N_("X") "\" type=\"float\" indent=\"1\" appearance=\"full\" precision=\"2\" min=\"-100.\" max=\"100.\">6</param>\n"
1446 "<param name=\"my\" gui-text=\"" N_("Y") "\" type=\"float\" indent=\"1\" appearance=\"full\" precision=\"2\" min=\"-100.\" max=\"100.\">7</param>\n"
1447 "<label appearance=\"header\">" N_("Yellow offset") "</label>\n"
1448 "<param name=\"yx\" gui-text=\"" N_("X") "\" type=\"float\" indent=\"1\" appearance=\"full\" precision=\"2\" min=\"-100.\" max=\"100.\">1</param>\n"
1449 "<param name=\"yy\" gui-text=\"" N_("Y") "\" type=\"float\" indent=\"1\" appearance=\"full\" precision=\"2\" min=\"-100.\" max=\"100.\">-16</param>\n"
1450 "</page>\n"
1451 "<page name=\"coltab\" gui-text=\"Color\">\n"
1452 "<param name=\"color\" gui-text=\"" N_("Background color") "\" type=\"color\">-1</param>\n"
1453 "</page>\n"
1454 "</param>\n"
1455 "<effect>\n"
1456 "<object-type>all</object-type>\n"
1457 "<effects-menu>\n"
1458 "<submenu name=\"" N_("Filters") "\">\n"
1459 "<submenu name=\"" N_("Color") "\"/>\n"
1460 "</submenu>\n"
1461 "</effects-menu>\n"
1462 "<menu-tip>" N_("Nudge CMY channels separately and blend them to different types of backgrounds") "</menu-tip>\n"
1463 "</effect>\n"
1464 "</inkscape-extension>\n", std::make_unique<NudgeCMY>());
1465 // clang-format on
1466 };
1467};
1468
1469gchar const *
1471{
1472 if (_filter != nullptr) g_free((void *)_filter);
1473
1474 std::ostringstream cx;
1475 std::ostringstream cy;
1476 std::ostringstream mx;
1477 std::ostringstream my;
1478 std::ostringstream yx;
1479 std::ostringstream yy;
1480
1481 std::ostringstream a;
1482 std::ostringstream r;
1483 std::ostringstream g;
1484 std::ostringstream b;
1485
1486 cx << ext->get_param_float("cx");
1487 cy << ext->get_param_float("cy");
1488 mx << ext->get_param_float("mx");
1489 my << ext->get_param_float("my");
1490 yx << ext->get_param_float("yx");
1491 yy << ext->get_param_float("yy");
1492
1493 guint32 color = ext->get_param_color("color");
1494 r << ((color >> 24) & 0xff);
1495 g << ((color >> 16) & 0xff);
1496 b << ((color >> 8) & 0xff);
1497 a << (color & 0xff) / 255.0F;
1498
1499 // clang-format off
1500 _filter = g_strdup_printf(
1501 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" style=\"color-interpolation-filters:sRGB;\" inkscape:label=\"Nudge CMY\">\n"
1502 "<feFlood flood-opacity=\"%s\" flood-color=\"rgb(%s,%s,%s)\" result=\"flood\" />\n"
1503 "<feColorMatrix in=\"SourceGraphic\" values=\"0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 -1 0 0 1 0 \" result=\"colormatrix1\" />\n"
1504 "<feOffset dy=\"%s\" dx=\"%s\" result=\"offset1\" />\n"
1505 "<feBlend in2=\"flood\" mode=\"multiply\" result=\"blend1\" />\n"
1506 "<feColorMatrix in=\"SourceGraphic\" values=\"0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 -1 0 1 0 \" result=\"colormatrix2\" />\n"
1507 "<feOffset dy=\"%s\" dx=\"%s\" result=\"offset2\" />\n"
1508 "<feBlend in2=\"blend1\" mode=\"multiply\" result=\"blend2\" />\n"
1509 "<feOffset dy=\"%s\" dx=\"%s\" result=\"offset3\" />\n"
1510 "<feColorMatrix in=\"SourceGraphic\" values=\"0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 -1 1 0 \" result=\"colormatrix3\" />\n"
1511 "<feBlend in2=\"offset3\" mode=\"multiply\" result=\"blend3\" />\n"
1512 "</filter>\n", a.str().c_str(), r.str().c_str(), g.str().c_str(), b.str().c_str(),
1513 cx.str().c_str(), cy.str().c_str(),
1514 mx.str().c_str(), my.str().c_str(),
1515 yx.str().c_str(), yy.str().c_str() );
1516 // clang-format on
1517
1518 return _filter;
1519
1520}; /* Nudge CMY filter */
1521
1536protected:
1537 gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override;
1538
1539public:
1540 Quadritone ( ) : Filter() { };
1541 ~Quadritone ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; }
1542
1543 static void init () {
1544 // clang-format off
1546 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
1547 "<name>" N_("Quadritone Fantasy") "</name>\n"
1548 "<id>org.inkscape.effect.filter.Quadritone</id>\n"
1549 "<param name=\"dist\" gui-text=\"" N_("Hue distribution (°)") "\" type=\"int\" appearance=\"full\" min=\"0\" max=\"360\">280</param>\n"
1550 "<param name=\"colors\" gui-text=\"" N_("Colors") "\" type=\"int\" appearance=\"full\" min=\"0\" max=\"360\">100</param>\n"
1551 "<param name=\"blend1\" gui-text=\"" N_("Blend 1:") "\" type=\"optiongroup\" appearance=\"combo\">\n"
1552 "<option value=\"normal\">" N_("Normal") "</option>\n"
1553 "<option value=\"multiply\">" N_("Multiply") "</option>\n"
1554 "<option value=\"screen\">" N_("Screen") "</option>\n"
1555 "</param>\n"
1556 "<param name=\"sat\" gui-text=\"" N_("Over-saturation") "\" type=\"float\" appearance=\"full\" precision=\"2\" min=\"0.00\" max=\"1.00\">0</param>\n"
1557 "<param name=\"blend2\" gui-text=\"" N_("Blend 2:") "\" type=\"optiongroup\" appearance=\"combo\">\n"
1558 "<option value=\"normal\">" N_("Normal") "</option>\n"
1559 "<option value=\"screen\">" N_("Screen") "</option>\n"
1560 "<option value=\"multiply\">" N_("Multiply") "</option>\n"
1561 "<option value=\"lighten\">" N_("Lighten") "</option>\n"
1562 "<option value=\"darken\">" N_("Darken") "</option>\n"
1563 "</param>\n"
1564 "<effect>\n"
1565 "<object-type>all</object-type>\n"
1566 "<effects-menu>\n"
1567 "<submenu name=\"" N_("Filters") "\">\n"
1568 "<submenu name=\"" N_("Color") "\"/>\n"
1569 "</submenu>\n"
1570 "</effects-menu>\n"
1571 "<menu-tip>" N_("Replace hue by two colors") "</menu-tip>\n"
1572 "</effect>\n"
1573 "</inkscape-extension>\n", std::make_unique<Quadritone>());
1574 // clang-format on
1575 };
1576
1577};
1578
1579gchar const *
1581{
1582 if (_filter != nullptr) g_free((void *)_filter);
1583
1584 std::ostringstream dist;
1585 std::ostringstream colors;
1586 std::ostringstream blend1;
1587 std::ostringstream sat;
1588 std::ostringstream blend2;
1589
1590 dist << ext->get_param_int("dist");
1591 colors << ext->get_param_int("colors");
1592 blend1 << ext->get_param_optiongroup("blend1");
1593 sat << ext->get_param_float("sat");
1594 blend2 << ext->get_param_optiongroup("blend2");
1595
1596 // clang-format off
1597 _filter = g_strdup_printf(
1598 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" style=\"color-interpolation-filters:sRGB;\" inkscape:label=\"Quadritone fantasy\">\n"
1599 "<feColorMatrix in=\"SourceGraphic\" type=\"hueRotate\" values=\"%s\" result=\"colormatrix1\" />\n"
1600 "<feColorMatrix type=\"matrix\" values=\"0.5 0 0.5 0 0 0 1 0 0 0 0.5 0 0.5 0 0 0 0 0 1 0 \" result=\"colormatrix2\" />\n"
1601 "<feColorMatrix type=\"hueRotate\" values=\"%s\" result=\"colormatrix3\" />\n"
1602 "<feBlend in2=\"colormatrix3\" mode=\"%s\" result=\"blend1\" />\n"
1603 "<feColorMatrix type=\"matrix\" values=\"2.5 -0.75 -0.75 0 0 -0.75 2.5 -0.75 0 0 -0.75 -0.75 2.5 0 0 0 0 0 1 0 \" result=\"colormatrix4\" />\n"
1604 "<feComposite in=\"colormatrix4\" in2=\"blend1\" operator=\"arithmetic\" k2=\"%s\" result=\"composite1\" />\n"
1605 "<feBlend in2=\"blend1\" mode=\"%s\" result=\"blend2\" />\n"
1606 "</filter>\n", dist.str().c_str(), colors.str().c_str(), blend1.str().c_str(), sat.str().c_str(), blend2.str().c_str() );
1607 // clang-format on
1608
1609 return _filter;
1610}; /* Quadritone filter */
1611
1612
1623protected:
1624 gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override;
1625
1626public:
1627 SimpleBlend ( ) : Filter() { };
1628 ~SimpleBlend ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; }
1629
1630 static void init () {
1631 // clang-format off
1633 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
1634 "<name>" N_("Simple blend") "</name>\n"
1635 "<id>org.inkscape.effect.filter.SimpleBlend</id>\n"
1636 "<param name=\"color\" gui-text=\"" N_("Color") "\" type=\"color\">16777215</param>\n"
1637 "<param name=\"blendmode\" gui-text=\"" N_("Blend mode:") "\" type=\"optiongroup\" appearance=\"combo\">\n"
1638 "<option value=\"normal\">" N_("Normal") "</option>\n"
1639 "<option value=\"multiply\">" N_("Multiply") "</option>\n"
1640 "<option value=\"screen\">" N_("Screen") "</option>\n"
1641 "<option value=\"saturation\">" N_("Saturation") "</option>\n"
1642 "<option value=\"darken\">" N_("Darken") "</option>\n"
1643 "<option value=\"difference\">" N_("Difference") "</option>\n"
1644 "<option value=\"lighten\">" N_("Lighten") "</option>\n"
1645 "<option value=\"luminosity\">" N_("Luminosity") "</option>\n"
1646 "<option value=\"overlay\">" N_("Overlay") "</option>\n"
1647 "<option value=\"color-dodge\">" N_("Color Dodge") "</option>\n"
1648 "<option value=\"color-burn\">" N_("Color Burn") "</option>\n"
1649 "<option value=\"color\">" N_("Color") "</option>\n"
1650 "<option value=\"hard-light\">" N_("Hard Light") "</option>\n"
1651 "<option value=\"hue\">" N_("Hue") "</option>\n"
1652 "<option value=\"exclusion\">" N_("Exclusion") "</option>\n"
1653 "</param>\n"
1654 "<effect>\n"
1655 "<object-type>all</object-type>\n"
1656 "<effects-menu>\n"
1657 "<submenu name=\"" N_("Filters") "\">\n"
1658 "<submenu name=\"" N_("Color") "\"/>\n"
1659 "</submenu>\n"
1660 "</effects-menu>\n"
1661 "<menu-tip>" N_("Simple blend filter") "</menu-tip>\n"
1662 "</effect>\n"
1663 "</inkscape-extension>\n", std::make_unique<SimpleBlend>());
1664 // clang-format on
1665 };
1666};
1667
1668gchar const *
1670{
1671 if (_filter != nullptr) g_free((void *)_filter);
1672
1673 std::ostringstream a;
1674 std::ostringstream r;
1675 std::ostringstream g;
1676 std::ostringstream b;
1677 std::ostringstream blend;
1678
1679 guint32 color = ext->get_param_color("color");
1680 r << ((color >> 24) & 0xff);
1681 g << ((color >> 16) & 0xff);
1682 b << ((color >> 8) & 0xff);
1683 a << (color & 0xff) / 255.0F;
1684 blend << ext->get_param_optiongroup("blendmode");
1685
1686 // clang-format off
1687 _filter = g_strdup_printf(
1688 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" style=\"color-interpolation-filters:sRGB;\" inkscape:label=\"Simple blend\">\n"
1689 "<feFlood result=\"flood1\" flood-color=\"rgb(%s,%s,%s)\" flood-opacity=\"%s\" />\n"
1690 "<feBlend result=\"blend1\" in=\"flood1\" in2=\"SourceGraphic\" mode=\"%s\" />\n"
1691 "<feComposite operator=\"in\" in=\"blend1\" in2=\"SourceGraphic\" />\n"
1692 "</filter>\n", r.str().c_str(), g.str().c_str(), b.str().c_str(),
1693 a.str().c_str(), blend.str().c_str());
1694 // clang-format on
1695
1696 return _filter;
1697}; /* SimpleBlend filter */
1698
1713protected:
1714 gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override;
1715
1716public:
1717 Solarize ( ) : Filter() { };
1718 ~Solarize ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; }
1719
1720 static void init () {
1721 // clang-format off
1723 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
1724 "<name>" N_("Solarize") "</name>\n"
1725 "<id>org.inkscape.effect.filter.Solarize</id>\n"
1726 "<param name=\"rotate\" gui-text=\"" N_("Hue rotation (°)") "\" type=\"int\" appearance=\"full\" min=\"0\" max=\"360\">0</param>\n"
1727 "<param name=\"type\" gui-text=\"" N_("Type:") "\" type=\"optiongroup\" appearance=\"combo\">\n"
1728 "<option value=\"solarize\">" N_("Solarize") "</option>\n"
1729 "<option value=\"moonarize\">" N_("Moonarize") "</option>\n"
1730 "</param>\n"
1731 "<effect>\n"
1732 "<object-type>all</object-type>\n"
1733 "<effects-menu>\n"
1734 "<submenu name=\"" N_("Filters") "\">\n"
1735 "<submenu name=\"" N_("Color") "\"/>\n"
1736 "</submenu>\n"
1737 "</effects-menu>\n"
1738 "<menu-tip>" N_("Classic photographic solarization effect") "</menu-tip>\n"
1739 "</effect>\n"
1740 "</inkscape-extension>\n", std::make_unique<Solarize>());
1741 // clang-format on
1742 };
1743
1744};
1745
1746gchar const *
1748{
1749 if (_filter != nullptr) g_free((void *)_filter);
1750
1751 std::ostringstream rotate;
1752 std::ostringstream blend1;
1753 std::ostringstream blend2;
1754
1755 rotate << ext->get_param_int("rotate");
1756 const gchar *type = ext->get_param_optiongroup("type");
1757 if ((g_ascii_strcasecmp("solarize", type) == 0)) {
1758 // Solarize
1759 blend1 << "darken";
1760 blend2 << "screen";
1761 } else {
1762 // Moonarize
1763 blend1 << "lighten";
1764 blend2 << "multiply";
1765 }
1766
1767 // clang-format off
1768 _filter = g_strdup_printf(
1769 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" style=\"color-interpolation-filters:sRGB;\" inkscape:label=\"Solarize\">\n"
1770 "<feColorMatrix values=\"1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 1 \" />\n"
1771 "<feColorMatrix type=\"hueRotate\" values=\"%s\" result=\"colormatrix2\" />\n"
1772 "<feColorMatrix in=\"colormatrix2\" values=\"-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 1 0 \" result=\"colormatrix3\" />\n"
1773 "<feBlend in=\"colormatrix3\" in2=\"colormatrix2\" mode=\"%s\" result=\"blend1\" />\n"
1774 "<feBlend in2=\"blend1\" mode=\"%s\" result=\"blend2\" />\n"
1775 "<feComposite in2=\"SourceGraphic\" operator=\"in\" />\n"
1776 "</filter>\n", rotate.str().c_str(), blend1.str().c_str(), blend2.str().c_str() );
1777 // clang-format on
1778
1779 return _filter;
1780}; /* Solarize filter */
1781
1804protected:
1805 gchar const * get_filter_text (Inkscape::Extension::Extension * ext) override;
1806
1807public:
1808 Tritone ( ) : Filter() { };
1809 ~Tritone ( ) override { if (_filter != nullptr) g_free((void *)_filter); return; }
1810
1811 static void init () {
1812 // clang-format off
1814 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
1815 "<name>" N_("Tritone") "</name>\n"
1816 "<id>org.inkscape.effect.filter.Tritone</id>\n"
1817 "<param name=\"tab\" type=\"notebook\">\n"
1818 "<page name=\"optionstab\" gui-text=\"Options\">\n"
1819 "<param name=\"type\" gui-text=\"" N_("Type:") "\" type=\"optiongroup\" appearance=\"combo\">\n"
1820 "<option value=\"normal\">" N_("Normal") "</option>\n"
1821 "<option value=\"enhue\">" N_("Enhance hue") "</option>\n"
1822 "<option value=\"phospho\">" N_("Phosphorescence") "</option>\n"
1823 "<option value=\"phosphoB\">" N_("Colored nights") "</option>\n"
1824 "<option value=\"htb\">" N_("Hue to background") "</option>\n"
1825 "</param>\n"
1826 "<param name=\"globalblend\" gui-text=\"" N_("Global blend:") "\" type=\"optiongroup\" appearance=\"combo\">\n"
1827 "<option value=\"lighten\">" N_("Lighten") "</option>\n"
1828 "<option value=\"screen\">" N_("Screen") "</option>\n"
1829 "<option value=\"multiply\">" N_("Multiply") "</option>\n"
1830 "<option value=\"darken\">" N_("Darken") "</option>\n"
1831 "</param>\n"
1832 "<param name=\"glow\" gui-text=\"" N_("Glow") "\" type=\"float\" appearance=\"full\" min=\"0.01\" max=\"10\">0.01</param>\n"
1833 "<param name=\"glowblend\" gui-text=\"" N_("Glow blend:") "\" type=\"optiongroup\" appearance=\"combo\">\n"
1834 "<option value=\"normal\">" N_("Normal") "</option>\n"
1835 "<option value=\"multiply\">" N_("Multiply") "</option>\n"
1836 "<option value=\"darken\">" N_("Darken") "</option>\n"
1837 "</param>\n"
1838 "<param name=\"llight\" gui-text=\"" N_("Local light") "\" type=\"float\" appearance=\"full\" min=\"0\" max=\"10\">0</param>\n"
1839 "<param name=\"glight\" gui-text=\"" N_("Global light") "\" type=\"float\" appearance=\"full\" min=\"0\" max=\"10\">1</param>\n"
1840 "</page>\n"
1841 "<page name=\"co1tab\" gui-text=\"Color\">\n"
1842 "<param name=\"dist\" gui-text=\"" N_("Hue distribution (°):") "\" type=\"int\" appearance=\"full\" min=\"0\" max=\"360\">0</param>\n"
1843 "<param name=\"color\" gui-text=\"" N_("Color") "\" type=\"color\">-73203457</param>\n"
1844 "</page>\n"
1845 "</param>\n"
1846 "<effect>\n"
1847 "<object-type>all</object-type>\n"
1848 "<effects-menu>\n"
1849 "<submenu name=\"" N_("Filters") "\">\n"
1850 "<submenu name=\"" N_("Color") "\"/>\n"
1851 "</submenu>\n"
1852 "</effects-menu>\n"
1853 "<menu-tip>" N_("Create a custom tritone palette with additional glow, blend modes and hue moving") "</menu-tip>\n"
1854 "</effect>\n"
1855 "</inkscape-extension>\n", std::make_unique<Tritone>());
1856 // clang-format on
1857 };
1858
1859};
1860
1861gchar const *
1863{
1864 if (_filter != nullptr) g_free((void *)_filter);
1865
1866 std::ostringstream dist;
1867 std::ostringstream a;
1868 std::ostringstream r;
1869 std::ostringstream g;
1870 std::ostringstream b;
1871 std::ostringstream globalblend;
1872 std::ostringstream glow;
1873 std::ostringstream glowblend;
1874 std::ostringstream llight;
1875 std::ostringstream glight;
1876 std::ostringstream c1in2;
1877 std::ostringstream c2in;
1878 std::ostringstream c2in2;
1879 std::ostringstream b6in2;
1880
1881 guint32 color = ext->get_param_color("color");
1882 r << ((color >> 24) & 0xff);
1883 g << ((color >> 16) & 0xff);
1884 b << ((color >> 8) & 0xff);
1885 a << (color & 0xff) / 255.0F;
1886 globalblend << ext->get_param_optiongroup("globalblend");
1887 dist << ext->get_param_int("dist");
1888 glow << ext->get_param_float("glow");
1889 glowblend << ext->get_param_optiongroup("glowblend");
1890 llight << ext->get_param_float("llight");
1891 glight << ext->get_param_float("glight");
1892
1893 const gchar *type = ext->get_param_optiongroup("type");
1894 if ((g_ascii_strcasecmp("enhue", type) == 0)) {
1895 // Enhance hue
1896 c1in2 << "flood";
1897 c2in << "SourceGraphic";
1898 c2in2 << "blend6";
1899 b6in2 << "composite1";
1900 } else if ((g_ascii_strcasecmp("phospho", type) == 0)) {
1901 // Phosphorescence
1902 c1in2 << "flood";
1903 c2in << "blend6";
1904 c2in2 << "composite1";
1905 b6in2 << "SourceGraphic";
1906 } else if ((g_ascii_strcasecmp("phosphoB", type) == 0)) {
1907 // Phosphorescence B
1908 c1in2 << "SourceGraphic";
1909 c2in << "blend6";
1910 c2in2 << "composite1";
1911 b6in2 << "flood";
1912 } else if ((g_ascii_strcasecmp("htb", type) == 0)) {
1913 // Hue to background
1914 c1in2 << "BackgroundImage";
1915 c2in << "blend2";
1916 c2in2 << "blend6";
1917 b6in2 << "composite1";
1918 } else {
1919 // Normal
1920 c1in2 << "flood";
1921 c2in << "blend2";
1922 c2in2 << "blend6";
1923 b6in2 << "composite";
1924 }
1925
1926 // clang-format off
1927 _filter = g_strdup_printf(
1928 "<filter xmlns:inkscape=\"http://www.inkscape.org/namespaces/inkscape\" style=\"color-interpolation-filters:sRGB;\" inkscape:label=\"Tritone\">\n"
1929 "<feColorMatrix type=\"hueRotate\" values=\"%s\" result=\"colormatrix1\" />\n"
1930 "<feColorMatrix in=\"colormatrix1\" type=\"matrix\" values=\"1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1 \" result=\"colormatrix2\" />\n"
1931 "<feColorMatrix in=\"colormatrix1\" type=\"matrix\" values=\"0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 1 \" result=\"colormatrix3\" />\n"
1932 "<feColorMatrix in=\"colormatrix1\" type=\"matrix\" values=\"0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 \" result=\"colormatrix4\" />\n"
1933 "<feBlend in=\"colormatrix2\" in2=\"colormatrix3\" mode=\"darken\" result=\"blend1\" />\n"
1934 "<feBlend in=\"blend1\" in2=\"colormatrix4\" mode=\"darken\" result=\"blend2\" />\n"
1935 "<feBlend in=\"colormatrix2\" in2=\"colormatrix3\" mode=\"lighten\" result=\"blend3\" />\n"
1936 "<feBlend in=\"blend3\" in2=\"colormatrix4\" mode=\"lighten\" result=\"blend4\" />\n"
1937 "<feComponentTransfer in=\"blend4\" result=\"componentTransfer\">\n"
1938 "<feFuncR type=\"linear\" slope=\"0\" />\n"
1939 "</feComponentTransfer>\n"
1940 "<feBlend in=\"blend2\" in2=\"componentTransfer\" mode=\"%s\" result=\"blend5\" />\n"
1941 "<feColorMatrix in=\"blend5\" type=\"matrix\" values=\"-1 1 0 0 0 -1 1 0 0 0 -1 1 0 0 0 0 0 0 0 1 \" result=\"colormatrix5\" />\n"
1942 "<feFlood flood-opacity=\"%s\" flood-color=\"rgb(%s,%s,%s)\" result=\"flood\" />\n"
1943 "<feComposite in=\"colormatrix5\" in2=\"%s\" operator=\"arithmetic\" k1=\"1\" result=\"composite1\" />\n"
1944 "<feGaussianBlur stdDeviation=\"%s\" result=\"blur\" />\n"
1945 "<feBlend in2=\"%s\" mode=\"%s\" result=\"blend6\" />\n"
1946 "<feComposite in=\"%s\" in2=\"%s\" operator=\"arithmetic\" k1=\"%s\" k2=\"1\" k3=\"%s\" k4=\"0\" result=\"composite2\" />\n"
1947 "<feComposite in2=\"SourceGraphic\" operator=\"in\" result=\"composite3\" />\n"
1948 "</filter>\n", dist.str().c_str(), globalblend.str().c_str(),
1949 a.str().c_str(), r.str().c_str(), g.str().c_str(), b.str().c_str(),
1950 c1in2.str().c_str(), glow.str().c_str(), b6in2.str().c_str(), glowblend.str().c_str(),
1951 c2in.str().c_str(), c2in2.str().c_str(), llight.str().c_str(), glight.str().c_str() );
1952 // clang-format on
1953
1954 return _filter;
1955}; /* Tritone filter */
1956
1957}; /* namespace Filter */
1958}; /* namespace Internal */
1959}; /* namespace Extension */
1960}; /* namespace Inkscape */
1961
1962/* Change the 'COLOR' below to be your file name */
1963#endif /* SEEN_INKSCAPE_EXTENSION_INTERNAL_FILTER_COLOR_H__ */
The object that is the basis for the Extension system.
Definition: extension.h:130
char const * get_param_optiongroup(char const *name, char const *alt) const
Like get_param_optiongroup but with a default on param_not_exist error.
Definition: extension.cpp:757
int get_param_int(char const *name) const
Gets a parameter identified by name with the integer placed in value.
Definition: extension.cpp:662
double get_param_float(char const *name) const
Gets a float parameter identified by name with the double placed in value.
Definition: extension.cpp:690
std::uint32_t get_param_color(char const *name) const
Gets a parameter identified by name with the unsigned int placed in value.
Definition: extension.cpp:788
bool get_param_bool(char const *name) const
Gets a parameter identified by name with the bool placed in value.
Definition: extension.cpp:634
Custom predefined Brilliance filter.
Definition: color.h:64
gchar const * get_filter_text(Inkscape::Extension::Extension *ext) override
Definition: color.h:97
Custom predefined Channel Painting filter.
Definition: color.h:148
gchar const * get_filter_text(Inkscape::Extension::Extension *ext) override
Definition: color.h:190
Custom predefined Color Blindness filter.
Definition: color.h:253
gchar const * get_filter_text(Inkscape::Extension::Extension *ext) override
Definition: color.h:305
Custom predefined Color shift filter.
Definition: color.h:332
gchar const * get_filter_text(Inkscape::Extension::Extension *ext) override
Definition: color.h:364
Custom predefined Colorize filter.
Definition: color.h:399
gchar const * get_filter_text(Inkscape::Extension::Extension *ext) override
Definition: color.h:453
Custom predefined ComponentTransfer filter.
Definition: color.h:510
gchar const * get_filter_text(Inkscape::Extension::Extension *ext) override
Definition: color.h:546
Custom predefined Duochrome filter.
Definition: color.h:599
gchar const * get_filter_text(Inkscape::Extension::Extension *ext) override
Definition: color.h:646
Custom predefined Extract Channel filter.
Definition: color.h:728
gchar const * get_filter_text(Inkscape::Extension::Extension *ext) override
Definition: color.h:771
Custom predefined Fade to Black or White filter.
Definition: color.h:838
gchar const * get_filter_text(Inkscape::Extension::Extension *ext) override
Definition: color.h:872
Custom predefined Greyscale filter.
Definition: color.h:921
gchar const * get_filter_text(Inkscape::Extension::Extension *ext) override
Definition: color.h:955
Custom predefined Invert filter.
Definition: color.h:1012
gchar const * get_filter_text(Inkscape::Extension::Extension *ext) override
Definition: color.h:1052
Custom predefined Lighting filter.
Definition: color.h:1151
gchar const * get_filter_text(Inkscape::Extension::Extension *ext) override
Definition: color.h:1183
Custom predefined Lightness-Contrast filter.
Definition: color.h:1226
gchar const * get_filter_text(Inkscape::Extension::Extension *ext) override
Definition: color.h:1257
Custom predefined Nudge CMY filter.
Definition: color.h:1425
gchar const * get_filter_text(Inkscape::Extension::Extension *ext) override
Definition: color.h:1470
Custom predefined Nudge RGB filter.
Definition: color.h:1309
gchar const * get_filter_text(Inkscape::Extension::Extension *ext) override
Definition: color.h:1354
Custom predefined Quadritone filter.
Definition: color.h:1535
gchar const * get_filter_text(Inkscape::Extension::Extension *ext) override
Definition: color.h:1580
Custom predefined Simple blend filter.
Definition: color.h:1622
gchar const * get_filter_text(Inkscape::Extension::Extension *ext) override
Definition: color.h:1669
Custom predefined Solarize filter.
Definition: color.h:1712
gchar const * get_filter_text(Inkscape::Extension::Extension *ext) override
Definition: color.h:1747
Custom predefined Tritone filter.
Definition: color.h:1803
gchar const * get_filter_text(Inkscape::Extension::Extension *ext) override
Definition: color.h:1862
A way to clear the N_ macro, which is defined as an inline function.
unsigned int guint32
Definition: color.h:22
Inkscape::Extension::Extension: Frontend to certain, possibly pluggable, actions.
double offset
double dist(const Point &a, const Point &b)
Definition: geometry.cpp:310
SBasisOf< T > shift(SBasisOf< T > const &a, int sh)
Definition: sbasis-of.h:435
void build_from_mem(gchar const *buffer, std::unique_ptr< Implementation::Implementation > in_imp)
Create a module from a buffer holding an XML description.
Definition: system.cpp:471
CMYK to sRGB conversion routines.
void invert(const double v[16], double alpha[16])