1 /*
2 * feOffset filter primitive renderer
3 *
4 * Authors:
5 * Niko Kiirala <niko@kiirala.com>
6 *
7 * Copyright (C) 2007 authors
8 *
9 * Released under GNU GPL, read the file 'COPYING' for more information
10 */
12 #include "display/nr-filter-offset.h"
13 #include "display/nr-filter-slot.h"
14 #include "libnr/nr-blit.h"
15 #include "libnr/nr-matrix.h"
16 #include "libnr/nr-pixblock.h"
17 #include "libnr/nr-point.h"
18 #include "libnr/nr-point-matrix-ops.h"
19 #include "libnr/nr-rect-l.h"
21 namespace NR {
23 FilterOffset::FilterOffset() :
24 dx(0), dy(0)
25 {}
27 FilterPrimitive * FilterOffset::create() {
28 return new FilterOffset();
29 }
31 FilterOffset::~FilterOffset()
32 {}
34 int FilterOffset::render(FilterSlot &slot, Matrix const &trans) {
35 NRPixBlock *in = slot.get(_input);
36 NRPixBlock *out = new NRPixBlock;
38 Point offset(dx, dy);
39 offset *= trans;
40 offset[X] -= trans[4];
41 offset[Y] -= trans[5];
43 nr_pixblock_setup_fast(out, in->mode,
44 in->area.x0, in->area.y0, in->area.x1, in->area.y1,
45 true);
46 nr_blit_pixblock_pixblock(out, in);
48 out->area.x0 += static_cast<NR::ICoord>(offset[X]);
49 out->area.y0 += static_cast<NR::ICoord>(offset[Y]);
50 out->area.x1 += static_cast<NR::ICoord>(offset[X]);
51 out->area.y1 += static_cast<NR::ICoord>(offset[Y]);
52 out->visible_area = out->area;
54 out->empty = FALSE;
55 slot.set(_output, out);
57 return 0;
58 }
60 void FilterOffset::set_dx(double amount) {
61 dx = amount;
62 }
64 void FilterOffset::set_dy(double amount) {
65 dy = amount;
66 }
68 void FilterOffset::area_enlarge(NRRectL &area, Matrix const &trans)
69 {
70 Point offset(dx, dy);
71 offset *= trans;
72 offset[X] -= trans[4];
73 offset[Y] -= trans[5];
75 if (offset[X] > 0) {
76 area.x0 -= static_cast<NR::ICoord>(offset[X]);
77 } else {
78 area.x1 -= static_cast<NR::ICoord>(offset[X]);
79 }
81 if (offset[Y] > 0) {
82 area.y0 -= static_cast<NR::ICoord>(offset[Y]);
83 } else {
84 area.y1 -= static_cast<NR::ICoord>(offset[Y]);
85 }
86 }
88 } /* namespace NR */
90 /*
91 Local Variables:
92 mode:c++
93 c-file-style:"stroustrup"
94 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
95 indent-tabs-mode:nil
96 fill-column:99
97 End:
98 */
99 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :