Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
nr-filter-offset.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * feOffset filter primitive renderer
4 *
5 * Authors:
6 * Niko Kiirala <niko@kiirala.com>
7 *
8 * Copyright (C) 2007 authors
9 *
10 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
11 */
12
13#include "display/cairo-utils.h"
17
18namespace Inkscape {
19namespace Filters {
20
21using Geom::X;
22using Geom::Y;
23
25 : dx(0)
26 , dy(0) {}
27
29
31{
34 // color_interpolation_filters for out same as in. See spec (DisplacementMap).
35 copy_cairo_surface_ci(in, out);
36 cairo_t *ct = cairo_create(out);
37
39 slot.set_primitive_area(_output, vp); // Needed for tiling
40
42 double x = dx * p2pb.expansionX();
43 double y = dy * p2pb.expansionY();
44
45 cairo_set_source_surface(ct, in, x, y);
46 cairo_paint(ct);
47 cairo_destroy(ct);
48
49 slot.set(_output, out);
50 cairo_surface_destroy(out);
51}
52
54{
55 return true;
56}
57
58void FilterOffset::set_dx(double amount)
59{
60 dx = amount;
61}
62
63void FilterOffset::set_dy(double amount)
64{
65 dy = amount;
66}
67
69{
71 offset *= trans;
72 offset[X] -= trans[4];
73 offset[Y] -= trans[5];
74 double x0, y0, x1, y1;
75 x0 = area.left();
76 y0 = area.top();
77 x1 = area.right();
78 y1 = area.bottom();
79
80 if (offset[X] > 0) {
81 x0 -= std::ceil(offset[X]);
82 } else {
83 x1 -= std::floor(offset[X]);
84 }
85
86 if (offset[Y] > 0) {
87 y0 -= std::ceil(offset[Y]);
88 } else {
89 y1 -= std::floor(offset[Y]);
90 }
91
92 area = Geom::IntRect(x0, y0, x1, y1);
93}
94
96{
97 return 1.02;
98}
99
100} // namespace Filters
101} // namespace Inkscape
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 :
void copy_cairo_surface_ci(cairo_surface_t *in, cairo_surface_t *out)
cairo_surface_t * ink_cairo_surface_create_identical(cairo_surface_t *s)
Create a surface that differs only in pixel content.
Cairo integration helpers.
3x3 matrix representing an affine transformation.
Definition affine.h:70
Coord expansionX() const
Calculates the amount of x-scaling imparted by the Affine.
Definition affine.cpp:64
Coord expansionY() const
Calculates the amount of y-scaling imparted by the Affine.
Definition affine.cpp:71
Axis aligned, non-empty, generic rectangle.
C right() const
Return rightmost coordinate of the rectangle (+X is to the right).
C top() const
Return top coordinate of the rectangle (+Y is downwards).
C left() const
Return leftmost coordinate of the rectangle (+X is to the right).
C bottom() const
Return bottom coordinate of the rectangle (+Y is downwards).
Two-dimensional point that doubles as a vector.
Definition point.h:66
Axis aligned, non-empty rectangle.
Definition rect.h:92
bool can_handle_affine(Geom::Affine const &) const override
Indicate whether the filter primitive can handle the given affine.
void area_enlarge(Geom::IntRect &area, Geom::Affine const &trans) const override
void render_cairo(FilterSlot &slot) const override
double complexity(Geom::Affine const &ctm) const override
Geom::Rect filter_primitive_area(FilterUnits const &units) const
Returns the filter primitive area in user coordinate system.
void set_primitive_area(int slot, Geom::Rect &area)
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_primitiveunits2pb() const
Gets the primitiveUnits to pixblock coordinates transformation matrix.
struct _cairo_surface cairo_surface_t
@ Y
Definition coord.h:48
@ X
Definition coord.h:48
double offset
GenericRect< IntCoord > IntRect
Definition forward.h:57
Helper class to stream background task notifications as a series of messages.
struct _cairo cairo_t
Definition path-cairo.h:16