Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
blend.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
5/*
6 * Authors:
7 * Hugo Rodrigues <haa.rodrigues@gmail.com>
8 * Niko Kiirala <niko@kiirala.com>
9 * Abhishek Sharma
10 *
11 * Copyright (C) 2006,2007 authors
12 *
13 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
14 */
15
16#include "blend.h"
17
18#include <cstring>
19
20#include "attributes.h" // for SPAttr
21#include "slot-resolver.h" // for SlotResolver
22
23#include "display/nr-filter-blend.h" // for FilterBlend
24#include "object/filters/sp-filter-primitive.h" // for SPFilterPrimitive
25#include "object/sp-object.h" // for SP_OBJECT_MODIFIED_FLAG
26#include "util/optstr.h" // for assign, to_cstr
27#include "xml/document.h" // for Document
28
29class SPDocument;
30
31namespace Inkscape {
32class DrawingItem;
33
34namespace Filters {
35class FilterPrimitive;
36} // namespace Filters
37} // namespace Inkscape
38
46
47static SPBlendMode read_mode(char const *value)
48{
49 if (!value) {
51 }
52
53 switch (value[0]) {
54 case 'n':
55 if (std::strcmp(value, "normal") == 0)
57 break;
58 case 'm':
59 if (std::strcmp(value, "multiply") == 0)
61 break;
62 case 's':
63 if (std::strcmp(value, "screen") == 0)
65 if (std::strcmp(value, "saturation") == 0)
67 break;
68 case 'd':
69 if (std::strcmp(value, "darken") == 0)
71 if (std::strcmp(value, "difference") == 0)
73 break;
74 case 'l':
75 if (std::strcmp(value, "lighten") == 0)
77 if (std::strcmp(value, "luminosity") == 0)
79 break;
80 case 'o':
81 if (std::strcmp(value, "overlay") == 0)
83 break;
84 case 'c':
85 if (std::strcmp(value, "color-dodge") == 0)
87 if (std::strcmp(value, "color-burn") == 0)
89 if (std::strcmp(value, "color") == 0)
90 return SP_CSS_BLEND_COLOR;
91 break;
92 case 'h':
93 if (std::strcmp(value, "hard-light") == 0)
95 if (std::strcmp(value, "hue") == 0)
96 return SP_CSS_BLEND_HUE;
97 break;
98 case 'e':
99 if (std::strcmp(value, "exclusion") == 0)
101 default:
102 std::cerr << "SPBlendMode: Unimplemented mode: " << value << std::endl;
103 // do nothing by default
104 break;
105 }
106
107 return SP_CSS_BLEND_NORMAL;
108}
109
110void SPFeBlend::set(SPAttr key, char const *value)
111{
112 switch (key) {
113 case SPAttr::MODE: {
114 auto mode = ::read_mode(value);
115 if (mode != blend_mode) {
118 }
119 break;
120 }
121 case SPAttr::IN2: {
122 if (Inkscape::Util::assign(in2_name, value)) {
125 }
126 break;
127 }
128 default:
130 break;
131 }
132}
133
135{
136 if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) {
137 repr = doc->createElement("svg:feBlend");
138 }
139
141
142 char const *mode;
143 switch (blend_mode) {
145 mode = "normal"; break;
147 mode = "multiply"; break;
149 mode = "screen"; break;
151 mode = "darken"; break;
153 mode = "lighten"; break;
155 mode = "overlay"; break;
157 mode = "color-dodge"; break;
159 mode = "color-burn"; break;
161 mode = "hard-light"; break;
163 mode = "soft-light"; break;
165 mode = "difference"; break;
167 mode = "exclusion"; break;
168 case SP_CSS_BLEND_HUE:
169 mode = "hue"; break;
171 mode = "saturation"; break;
173 mode = "color"; break;
175 mode = "luminosity"; break;
176 default:
177 mode = nullptr;
178 }
179
180 repr->setAttribute("mode", mode);
181
182 return SPFilterPrimitive::write(doc, repr, flags);
183}
184
190
191std::unique_ptr<Inkscape::Filters::FilterPrimitive> SPFeBlend::build_renderer(Inkscape::DrawingItem*) const
192{
193 auto blend = std::make_unique<Inkscape::Filters::FilterBlend>();
195
196 blend->set_mode(blend_mode);
197 blend->set_input(1, in2_slot);
198
199 return blend;
200}
201
202/*
203 Local Variables:
204 mode:c++
205 c-file-style:"stroustrup"
206 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
207 indent-tabs-mode:nil
208 fill-column:99
209 End:
210*/
211// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Lookup dictionary for attributes/properties.
SPAttr
Definition attributes.h:27
static SPBlendMode read_mode(char const *value)
Definition blend.cpp:47
SVG blend filter effect.
SVG drawing item for display.
Interface for refcounted XML nodes.
Definition node.h:80
void setAttributeOrRemoveIfEmpty(Inkscape::Util::const_char_ptr key, Inkscape::Util::const_char_ptr value)
Change an attribute of this node.
Definition node.cpp:167
void setAttribute(Util::const_char_ptr key, Util::const_char_ptr value)
Change an attribute of this node.
Definition node.cpp:25
SVGLength x
Typed SVG document implementation.
Definition document.h:101
void build(SPDocument *doc, Inkscape::XML::Node *repr) override
Definition blend.cpp:39
std::optional< std::string > in2_name
Definition blend.h:39
void resolve_slots(SlotResolver &) override
Definition blend.cpp:185
SPBlendMode blend_mode
Definition blend.h:37
int in2_slot
Definition blend.h:40
Inkscape::XML::Node * write(Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, unsigned flags) override
Definition blend.cpp:134
void set(SPAttr key, char const *value) override
Definition blend.cpp:110
std::unique_ptr< Inkscape::Filters::FilterPrimitive > build_renderer(Inkscape::DrawingItem *item) const override
Definition blend.cpp:191
void build(SPDocument *doc, Inkscape::XML::Node *repr) override
Inkscape::XML::Node * write(Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, unsigned flags) override
virtual void resolve_slots(SlotResolver &)
void set(SPAttr key, char const *value) override
void build_renderer_common(Inkscape::Filters::FilterPrimitive *primitive) const
Inkscape::XML::Node * repr
Definition sp-object.h:193
void requestModified(unsigned int flags)
Requests that a modification notification signal be emitted later (e.g.
SPDocument * document
Definition sp-object.h:188
void readAttr(char const *key)
Read value of key attribute from XML node into object.
bool read(char const *str)
auto to_cstr(std::optional< std::string > const &s)
Definition optstr.h:26
bool assign(std::optional< std::string > &a, char const *b)
Definition optstr.h:31
Helper class to stream background task notifications as a series of messages.
static cairo_user_data_key_t key
int mode
Document level base class for all SVG filter primitives.
Interface for XML documents.
Definition document.h:43
virtual Node * createElement(char const *name)=0
SPBlendMode
@ SP_CSS_BLEND_LUMINOSITY
@ SP_CSS_BLEND_DARKEN
@ SP_CSS_BLEND_LIGHTEN
@ SP_CSS_BLEND_DIFFERENCE
@ SP_CSS_BLEND_COLORBURN
@ SP_CSS_BLEND_HARDLIGHT
@ SP_CSS_BLEND_EXCLUSION
@ SP_CSS_BLEND_COLORDODGE
@ SP_CSS_BLEND_SOFTLIGHT
@ SP_CSS_BLEND_SATURATION
@ SP_CSS_BLEND_SCREEN
@ SP_CSS_BLEND_OVERLAY
@ SP_CSS_BLEND_NORMAL
@ SP_CSS_BLEND_HUE
@ SP_CSS_BLEND_COLOR
@ SP_CSS_BLEND_MULTIPLY
Interface for XML documents.