1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Authors:
4  *   Christopher Brown <audiere@gmail.com>
5  *   Ted Gould <ted@gould.cx>
6  *
7  * Copyright (C) 2007 Authors
8  *
9  * Released under GNU GPL v2+, read the file 'COPYING' for more information.
10  */
11 
12 #include "extension/effect.h"
13 #include "extension/system.h"
14 
15 #include "colorize.h"
16 
17 #include "color.h"
18 
19 #include <iostream>
20 #include <Magick++.h>
21 
22 namespace Inkscape {
23 namespace Extension {
24 namespace Internal {
25 namespace Bitmap {
26 
27 void
applyEffect(Magick::Image * image)28 Colorize::applyEffect(Magick::Image *image) {
29 	float r = ((_color >> 24) & 0xff) / 255.0F;
30 	float g = ((_color >> 16) & 0xff) / 255.0F;
31 	float b = ((_color >>  8) & 0xff) / 255.0F;
32 	float a = ((_color      ) & 0xff) / 255.0F;
33 
34     Magick::ColorRGB mc(r,g,b);
35 
36 	image->colorize(a * 100, mc);
37 }
38 
39 void
refreshParameters(Inkscape::Extension::Effect * module)40 Colorize::refreshParameters(Inkscape::Extension::Effect *module) {
41 	_color = module->get_param_color("color");
42 }
43 
44 #include "../clear-n_.h"
45 
46 void
init()47 Colorize::init()
48 {
49     // clang-format off
50     Inkscape::Extension::build_from_mem(
51         "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
52             "<name>" N_("Colorize") "</name>\n"
53             "<id>org.inkscape.effect.bitmap.colorize</id>\n"
54             "<param name=\"color\" gui-text=\"" N_("Color") "\" type=\"color\">0</param>\n"
55             "<effect>\n"
56                 "<object-type>all</object-type>\n"
57                 "<effects-menu>\n"
58                     "<submenu name=\"" N_("Raster") "\" />\n"
59                 "</effects-menu>\n"
60                 "<menu-tip>" N_("Colorize selected bitmap(s) with specified color, using given opacity") "</menu-tip>\n"
61             "</effect>\n"
62         "</inkscape-extension>\n", new Colorize());
63     // clang-format on
64 }
65 
66 }; /* namespace Bitmap */
67 }; /* namespace Internal */
68 }; /* namespace Extension */
69 }; /* namespace Inkscape */
70