1
#define __SP_FEBLEND_CPP__
4
* SVG <feBlend> implementation.
9
* Hugo Rodrigues <haa.rodrigues@gmail.com>
10
* Niko Kiirala <niko@kiirala.com>
12
* Copyright (C) 2006,2007 authors
14
* Released under GNU GPL, read the file 'COPYING' for more information
23
#include "attributes.h"
25
#include "sp-feblend.h"
28
#include "display/nr-filter.h"
29
#include "display/nr-filter-primitive.h"
30
#include "display/nr-filter-blend.h"
31
#include "display/nr-filter-types.h"
33
/* FeBlend base class */
35
static void sp_feBlend_class_init(SPFeBlendClass *klass);
36
static void sp_feBlend_init(SPFeBlend *feBlend);
38
static void sp_feBlend_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr);
39
static void sp_feBlend_release(SPObject *object);
40
static void sp_feBlend_set(SPObject *object, unsigned int key, gchar const *value);
41
static void sp_feBlend_update(SPObject *object, SPCtx *ctx, guint flags);
42
static Inkscape::XML::Node *sp_feBlend_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
43
static void sp_feBlend_build_renderer(SPFilterPrimitive *sp_prim, NR::Filter *filter);
45
static SPFilterPrimitiveClass *feBlend_parent_class;
50
static GType feBlend_type = 0;
53
GTypeInfo feBlend_info = {
54
sizeof(SPFeBlendClass),
56
(GClassInitFunc) sp_feBlend_class_init,
60
(GInstanceInitFunc) sp_feBlend_init,
61
NULL, /* value_table */
63
feBlend_type = g_type_register_static(SP_TYPE_FILTER_PRIMITIVE, "SPFeBlend", &feBlend_info, (GTypeFlags)0);
69
sp_feBlend_class_init(SPFeBlendClass *klass)
71
SPObjectClass *sp_object_class = (SPObjectClass *)klass;
72
SPFilterPrimitiveClass *sp_primitive_class = (SPFilterPrimitiveClass *)klass;
74
feBlend_parent_class = (SPFilterPrimitiveClass*)g_type_class_peek_parent(klass);
76
sp_object_class->build = sp_feBlend_build;
77
sp_object_class->release = sp_feBlend_release;
78
sp_object_class->write = sp_feBlend_write;
79
sp_object_class->set = sp_feBlend_set;
80
sp_object_class->update = sp_feBlend_update;
82
sp_primitive_class->build_renderer = sp_feBlend_build_renderer;
86
sp_feBlend_init(SPFeBlend *feBlend)
88
feBlend->in2 = NR::NR_FILTER_SLOT_NOT_SET;
92
* Reads the Inkscape::XML::Node, and initializes SPFeBlend variables. For this to get called,
93
* our name must be associated with a repr via "sp_object_type_register". Best done through
94
* sp-object-repr.cpp's repr_name_entries array.
97
sp_feBlend_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr)
99
if (((SPObjectClass *) feBlend_parent_class)->build) {
100
((SPObjectClass *) feBlend_parent_class)->build(object, document, repr);
103
/*LOAD ATTRIBUTES FROM REPR HERE*/
104
sp_object_read_attr(object, "mode");
105
sp_object_read_attr(object, "in2");
109
* Drops any allocated memory.
112
sp_feBlend_release(SPObject *object)
114
if (((SPObjectClass *) feBlend_parent_class)->release)
115
((SPObjectClass *) feBlend_parent_class)->release(object);
118
static NR::FilterBlendMode sp_feBlend_readmode(gchar const *value)
120
if (!value) return NR::BLEND_NORMAL;
123
if (strncmp(value, "normal", 6) == 0)
124
return NR::BLEND_NORMAL;
127
if (strncmp(value, "multiply", 8) == 0)
128
return NR::BLEND_MULTIPLY;
131
if (strncmp(value, "screen", 6) == 0)
132
return NR::BLEND_SCREEN;
135
if (strncmp(value, "darken", 6) == 0)
136
return NR::BLEND_DARKEN;
139
if (strncmp(value, "lighten", 7) == 0)
140
return NR::BLEND_LIGHTEN;
143
// do nothing by default
146
return NR::BLEND_NORMAL;
150
* Sets a specific value in the SPFeBlend.
153
sp_feBlend_set(SPObject *object, unsigned int key, gchar const *value)
155
SPFeBlend *feBlend = SP_FEBLEND(object);
158
NR::FilterBlendMode mode;
161
/*DEAL WITH SETTING ATTRIBUTES HERE*/
163
mode = sp_feBlend_readmode(value);
164
if (mode != feBlend->blend_mode) {
165
feBlend->blend_mode = mode;
166
object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
170
input = sp_filter_primitive_read_in(feBlend, value);
171
if (input != feBlend->in2) {
172
feBlend->in2 = input;
173
object->parent->requestModified(SP_OBJECT_MODIFIED_FLAG);
177
if (((SPObjectClass *) feBlend_parent_class)->set)
178
((SPObjectClass *) feBlend_parent_class)->set(object, key, value);
185
* Receives update notifications.
188
sp_feBlend_update(SPObject *object, SPCtx *ctx, guint flags)
190
if (flags & SP_OBJECT_MODIFIED_FLAG) {
191
sp_object_read_attr(object, "mode");
192
sp_object_read_attr(object, "in2");
195
if (((SPObjectClass *) feBlend_parent_class)->update) {
196
((SPObjectClass *) feBlend_parent_class)->update(object, ctx, flags);
201
* Writes its settings to an incoming repr object, if any.
203
static Inkscape::XML::Node *
204
sp_feBlend_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags)
206
// Inkscape-only object, not copied during an "plain SVG" dump:
207
if (flags & SP_OBJECT_WRITE_EXT) {
210
// repr->mergeFrom(SP_OBJECT_REPR(object), "id");
212
repr = SP_OBJECT_REPR(object)->duplicate(doc);
216
if (((SPObjectClass *) feBlend_parent_class)->write) {
217
((SPObjectClass *) feBlend_parent_class)->write(object, doc, repr, flags);
223
static void sp_feBlend_build_renderer(SPFilterPrimitive *primitive, NR::Filter *filter) {
224
g_assert(primitive != NULL);
225
g_assert(filter != NULL);
227
SPFeBlend *sp_blend = SP_FEBLEND(primitive);
229
int primitive_n = filter->add_primitive(NR::NR_FILTER_BLEND);
230
NR::FilterPrimitive *nr_primitive = filter->get_primitive(primitive_n);
231
NR::FilterBlend *nr_blend = dynamic_cast<NR::FilterBlend*>(nr_primitive);
232
g_assert(nr_blend != NULL);
234
sp_filter_primitive_renderer_common(primitive, nr_primitive);
236
nr_blend->set_mode(sp_blend->blend_mode);
237
nr_blend->set_input(1, sp_blend->in2);
243
c-file-style:"stroustrup"
244
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
249
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :