Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
nr-filter-flood.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * feFlood filter primitive renderer
4 *
5 * Authors:
6 * Felipe CorrĂȘa da Silva Sanches <juca@members.fsf.org>
7 * Tavmjong Bah <tavmjong@free.fr> (use primitive filter region)
8 *
9 * Copyright (C) 2007, 2011 authors
10 *
11 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
12 */
13
14#ifdef HAVE_CONFIG_H
15#include "config.h" // only include where actually required!
16#endif
17
18#include "display/cairo-utils.h"
21
22namespace Inkscape {
23namespace Filters {
24
25FilterFlood::FilterFlood() = default;
26
28
30{
31 cairo_surface_t *input = slot.getcairo(_input);
32
33 double r = SP_RGBA32_R_F(color);
34 double g = SP_RGBA32_G_F(color);
35 double b = SP_RGBA32_B_F(color);
36 double a = SP_RGBA32_A_F(color);
37
38 cairo_surface_t *out = ink_cairo_surface_create_same_size(input, CAIRO_CONTENT_COLOR_ALPHA);
39
40 // Flood color is always defined in terms of sRGB, preconvert to linearRGB
41 // if color_interpolation_filters set to linearRGB (for efficiency assuming
42 // next filter primitive has same value of cif).
44 r = srgb_to_linear(r);
45 g = srgb_to_linear(g);
46 b = srgb_to_linear(b);
47 }
49
50 // Get filter primitive area in user units
52
53 // Convert to Cairo units
54 Geom::Rect fp_cairo = fp * slot.get_units().get_matrix_user2pb();
55
56 // Get area in slot (tile to fill)
57 Geom::Rect sa = slot.get_slot_area();
58
59 // Get overlap
60 Geom::OptRect optoverlap = intersect(fp_cairo, sa);
61 if (optoverlap) {
62 Geom::Rect overlap = *optoverlap;
63
64 auto d = fp_cairo.min() - sa.min();
65 if (d.x() < 0.0) d.x() = 0.0;
66 if (d.y() < 0.0) d.y() = 0.0;
67
68 cairo_t *ct = cairo_create(out);
69 cairo_set_source_rgba(ct, r, g, b, a);
70 cairo_set_operator(ct, CAIRO_OPERATOR_SOURCE);
71 cairo_rectangle(ct, d.x(), d.y(), overlap.width(), overlap.height());
72 cairo_fill(ct);
73 cairo_destroy(ct);
74 }
75
76 slot.set(_output, out);
77 cairo_surface_destroy(out);
78}
79
81{
82 // flood is a per-pixel primitive and is immutable under transformations
83 return true;
84}
85
90
92{
93 // flood is actually less expensive than normal rendering,
94 // but when flood is processed, the object has already been rendered
95 return 1.0;
96}
97
98} // namespace Filters
99} // namespace Inkscape
100
101/*
102 Local Variables:
103 mode:c++
104 c-file-style:"stroustrup"
105 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
106 indent-tabs-mode:nil
107 fill-column:99
108 End:
109*/
110// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
cairo_surface_t * ink_cairo_surface_create_same_size(cairo_surface_t *s, cairo_content_t c)
static guint32 srgb_to_linear(const guint32 c, const guint32 a)
void set_cairo_surface_ci(cairo_surface_t *surface, SPColorInterpolation ci)
Set the color_interpolation_value for a Cairo surface.
Cairo integration helpers.
3x3 matrix representing an affine transformation.
Definition affine.h:70
C height() const
Get the vertical extent of the rectangle.
C width() const
Get the horizontal extent of the rectangle.
CPoint min() const
Get the corner of the rectangle with smallest coordinate values.
Axis-aligned rectangle that can be empty.
Definition rect.h:203
Axis aligned, non-empty rectangle.
Definition rect.h:92
void render_cairo(FilterSlot &slot) const override
double complexity(Geom::Affine const &ctm) const override
bool can_handle_affine(Geom::Affine const &) const override
Indicate whether the filter primitive can handle the given affine.
Geom::Rect filter_primitive_area(FilterUnits const &units) const
Returns the filter primitive area in user coordinate system.
cairo_surface_t * getcairo(int slot)
Returns the pixblock in specified slot.
void set(int slot, cairo_surface_t *s)
Sets or re-sets the pixblock associated with given slot.
FilterUnits const & get_units() const
Geom::Affine get_matrix_user2pb() const
Gets the user coordinates to pixblock coordinates transformation matrix.
constexpr double SP_RGBA32_G_F(uint32_t v)
Definition utils.h:47
constexpr double SP_RGBA32_R_F(uint32_t v)
Definition utils.h:43
constexpr double SP_RGBA32_A_F(uint32_t v)
Definition utils.h:55
constexpr double SP_RGBA32_B_F(uint32_t v)
Definition utils.h:51
void intersect(intersections_info &xs, D2< SBasis > const &A, D2< SBasis > const &B)
double c[8][4]
unsigned int guint32
struct _cairo_surface cairo_surface_t
Helper class to stream background task notifications as a series of messages.
void cairo_rectangle(cairo_t *cr, Geom::Rect const &r)
struct _cairo cairo_t
Definition path-cairo.h:16
@ SP_CSS_COLOR_INTERPOLATION_LINEARRGB
void cairo_set_source_rgba(cairo_t *cr, colour c)