Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
gaussian-blur.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 "gaussian-blur.h"
17#include "attributes.h" // for SPAttr
18#include "display/nr-filter-gaussian.h" // for FilterGaussian
19#include "object/filters/sp-filter-primitive.h" // for SPFilterPrimitive
20#include "object/sp-object.h" // for SP_OBJECT_MODIFIED_FLAG
21#include "util/numeric/converters.h" // for format_number
22#include "xml/node.h" // for Node
23
24class SPDocument;
25
26namespace Inkscape {
27class DrawingItem;
28namespace Filters {
29class FilterPrimitive;
30} // namespace Filters
31} // namespace Inkscape
32
38
39void SPGaussianBlur::set(SPAttr key, char const *value)
40{
41 switch (key) {
43 stdDeviation.set(value);
45 break;
46 default:
48 break;
49 }
50}
51
52std::unique_ptr<Inkscape::Filters::FilterPrimitive> SPGaussianBlur::build_renderer(Inkscape::DrawingItem*) const
53{
54 auto blur = std::make_unique<Inkscape::Filters::FilterGaussian>();
56
57 float num = stdDeviation.getNumber();
58
59 if (num >= 0.0) {
61 if (optnum >= 0.0) {
62 blur->set_deviation(num, optnum);
63 } else {
64 blur->set_deviation(num);
65 }
66 }
67
68 return blur;
69}
70
72{
73 double num = stdDeviation.getNumber();
74 std::string arg = Inkscape::Util::format_number(num);
75
77 if (optnum != num && optnum != -1) {
79 }
80 getRepr()->setAttribute("stdDeviation", arg);
81}
82
88{
89 double x = stdDeviation.getNumber();
90 double y = stdDeviation.getOptNumber();
91 if (y == -1.0) {
92 y = x;
93 }
94 // If not within the default 10% margin (see
95 // http://www.w3.org/TR/SVG11/filters.html#FilterEffectsRegion), specify margins
96 // The 2.4 is an empirical coefficient: at that distance the cutoff is practically invisible
97 // (the opacity at 2.4 * radius is about 3e-3)
98 auto r = region;
99 r.expandBy(2.4 * x, 2.4 * y);
100 return r;
101}
102
103/*
104 Local Variables:
105 mode:c++
106 c-file-style:"stroustrup"
107 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
108 indent-tabs-mode:nil
109 fill-column:99
110 End:
111*/
112// 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
@ STDDEVIATION
void expandBy(C amount)
Expand the rectangle in both directions by the specified amount.
Axis aligned, non-empty rectangle.
Definition rect.h:92
SVG drawing item for display.
Interface for refcounted XML nodes.
Definition node.h:80
void setAttribute(Util::const_char_ptr key, Util::const_char_ptr value)
Change an attribute of this node.
Definition node.cpp:25
float getOptNumber(bool or_num=false) const
float getNumber() const
void set(char const *str)
SVGLength y
SVGLength x
Typed SVG document implementation.
Definition document.h:101
void build(SPDocument *doc, Inkscape::XML::Node *repr) override
void set(SPAttr key, char const *value) override
void build_renderer_common(Inkscape::Filters::FilterPrimitive *primitive) const
void set_deviation(const NumberOptNumber &stdDeviation)
void build(SPDocument *document, Inkscape::XML::Node *repr) override
Geom::Rect calculate_region(Geom::Rect const &region) const override
Calculate the region taken up by gaussian blur.
void set(SPAttr key, char const *value) override
NumberOptNumber stdDeviation
std::unique_ptr< Inkscape::Filters::FilterPrimitive > build_renderer(Inkscape::DrawingItem *item) const override
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.
Inkscape::XML::Node * getRepr()
Returns the XML representation of tree.
Utility functions to convert ascii representations to numbers.
SVG Gaussian blur filter effect.
std::string format_number(double val, unsigned int precision=3)
Definition converters.h:110
Helper class to stream background task notifications as a series of messages.
static cairo_user_data_key_t key
int num
Definition scribble.cpp:47
Document level base class for all SVG filter primitives.
Interface for XML nodes.