Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
nr-filter-tile.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * feTile filter primitive renderer
4 *
5 * Authors:
6 * Felipe CorrĂȘa da Silva Sanches <juca@members.fsf.org>
7 *
8 * Copyright (C) 2007 authors
9 *
10 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
11 */
12
13#include <glib.h>
14
15#include "display/cairo-utils.h"
19
20namespace Inkscape {
21namespace Filters {
22
23FilterTile::FilterTile() = default;
24
25FilterTile::~FilterTile() = default;
26
28{
29 // This input source contains only the "rendering" tile.
31
32 // For debugging
33 // static int i = 0;
34 // ++i;
35 // std::stringstream filename;
36 // filename << "dump." << i << ".png";
37 // cairo_surface_write_to_png( in, filename.str().c_str() );
38
39 // This is the feTile source area as determined by the input primitive area (see SVG spec).
40 Geom::Rect tile_area = slot.get_primitive_area(_input);
41
42 if (tile_area.width() == 0.0 || tile_area.height() == 0.0) {
43
44 slot.set(_output, in);
45 std::cerr << "FileTile::render_cairo: tile has zero width or height" << std::endl;
46
47 } else {
48
50 // color_interpolation_filters for out same as in.
51 copy_cairo_surface_ci(in, out);
52 cairo_t *ct = cairo_create(out);
53
54 // The rectangle of the "rendering" tile.
55 Geom::Rect sa = slot.get_slot_area();
56
58
59 // Create feTile tile ----------------
60
61 // Get tile area in pixbuf units (tile transformed).
62 Geom::Rect tt = tile_area * trans;
63
64 // Shift between "rendering" tile and feTile tile
65 Geom::Point shift = sa.min() - tt.min();
66
67 // Create feTile tile surface
68 cairo_surface_t *tile = cairo_surface_create_similar(in, cairo_surface_get_content(in),
69 tt.width(), tt.height());
70 cairo_t *ct_tile = cairo_create(tile);
71 cairo_set_source_surface(ct_tile, in, shift[Geom::X], shift[Geom::Y]);
72 cairo_paint(ct_tile);
73
74 // Paint tiles ------------------
75
76 // For debugging
77 // std::stringstream filename;
78 // filename << "tile." << i << ".png";
79 // cairo_surface_write_to_png( tile, filename.str().c_str() );
80
81 // Determine number of feTile rows and columns
83 int tile_cols = std::ceil(pr.width() / tile_area.width());
84 int tile_rows = std::ceil(pr.height() / tile_area.height());
85
86 // Do tiling (TO DO: restrict to slot area.)
87 for (int col = 0; col < tile_cols; ++col) {
88 for (int row = 0; row < tile_rows; ++row) {
89 Geom::Point offset(col * tile_area.width(), row * tile_area.height());
90 offset *= trans;
91 offset[Geom::X] -= trans[4];
92 offset[Geom::Y] -= trans[5];
93
94 cairo_set_source_surface(ct, tile, offset[Geom::X], offset[Geom::Y]);
95 cairo_paint(ct);
96 }
97 }
98 slot.set(_output, out);
99
100 // Clean up
101 cairo_destroy(ct);
102 cairo_surface_destroy(out);
103 cairo_destroy(ct_tile);
104 cairo_surface_destroy(tile);
105 }
106}
107
109{
110 // Set to very large rectangle so we get tile source. It will be clipped later.
111
112 // Note, setting to infinite using Geom::IntRect::infinite() causes overflow/underflow problems.
113 Geom::IntCoord max = std::numeric_limits<Geom::IntCoord>::max() / 4;
114 area = Geom::IntRect(-max, -max, max, max);
115}
116
118{
119 return 1.0;
120}
121
122} // namespace Filters
123} // namespace Inkscape
124
125/*
126 Local Variables:
127 mode:c++
128 c-file-style:"stroustrup"
129 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
130 indent-tabs-mode:nil
131 fill-column:99
132 End:
133*/
134// 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
Axis aligned, non-empty, generic rectangle.
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.
Two-dimensional point that doubles as a vector.
Definition point.h:66
Axis aligned, non-empty rectangle.
Definition rect.h:92
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.
Geom::Rect get_primitive_area(int slot) const
FilterUnits const & get_units() const
void render_cairo(FilterSlot &slot) const override
double complexity(Geom::Affine const &ctm) const override
void area_enlarge(Geom::IntRect &area, Geom::Affine const &trans) const override
Geom::Affine get_matrix_user2pb() const
Gets the user coordinates to pixblock coordinates transformation matrix.
struct _cairo_surface cairo_surface_t
int IntCoord
Type used for integral coordinates.
Definition coord.h:80
@ Y
Definition coord.h:48
@ X
Definition coord.h:48
void shift(T &a, T &b, T const &c)
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