Code

Improved handling bounding boxes and rotated/skewed coordinates in filters
[inkscape.git] / src / display / nr-filter-primitive.h
1 #ifndef __NR_FILTER_PRIMITIVE_H__
2 #define __NR_FILTER_PRIMITIVE_H__
4 /*
5  * SVG filters rendering
6  *
7  * Author:
8  *   Niko Kiirala <niko@kiirala.com>
9  *
10  * Copyright (C) 2006 Niko Kiirala
11  *
12  * Released under GNU GPL, read the file 'COPYING' for more information
13  */
15 #include "display/nr-filter-slot.h"
16 #include "libnr/nr-pixblock.h"
17 #include "libnr/nr-matrix.h"
18 #include "libnr/nr-rect-l.h"
19 #include "svg/svg-length.h"
21 namespace NR {
23 /*
24  * Different filter effects need different types of inputs. This is what
25  * traits are used for: one can specify, what special restrictions
26  * there are for inputs.
27  *
28  * Example: gaussian blur requires that x- and y-axis of input image
29  * are paraller to blurred object's x- and y-axis, respectively.
30  * Otherwise blur wouldn't rotate with the object.
31  *
32  * Values here should be powers of two, so these can be used as bitfield.
33  * That is: any combination ef existing traits can be specified. (excluding
34  * TRAIT_ANYTHING, which is alias for no traits defined)
35  */
36 enum FilterTraits {
37     TRAIT_ANYTHING = 0,
38     TRAIT_PARALLER = 1
39 };
41 class FilterPrimitive {
42 public:
43     FilterPrimitive();
44     virtual ~FilterPrimitive();
46     int render(FilterSlot &slot, NRMatrix const *trans);
47     virtual int render(FilterSlot &slot, Matrix const &trans) = 0;
48     virtual void area_enlarge(NRRectL &area, Matrix const &m);
50     /**
51      * Sets the input slot number 'slot' to be used as input in rendering
52      * filter primitive 'primitive'
53      * For filter primitive types accepting more than one input, this sets the
54      * first input.
55      * If any of the required input slots is not set, the output of previous
56      * filter primitive is used, or SourceGraphic if this is the first
57      * primitive for this filter.
58      */
59     virtual void set_input(int slot);
61     /**
62      * Sets the input slot number 'slot' to be user as input number 'input' in
63      * rendering filter primitive 'primitive'
64      * First input for a filter primitive is number 0. For primitives with
65      * attributes 'in' and 'in2', these are numbered 0 and 1, respectively.
66      * If any of required input slots for a filter is not set, the output of
67      * previous filter primitive is used, or SourceGraphic if this is the first
68      * filter primitive for this filter.
69      */
70     virtual void set_input(int input, int slot);
72     /**
73      * Sets the slot number 'slot' to be used as output from filter primitive
74      * 'primitive'
75      * If output slot for a filter element is not set, one of the unused image
76      * slots is used.
77      * It is an error to specify a pre-defined slot as 'slot'. Such call does
78      * not have any effect to the state of filter or its primitives.
79      */
80     virtual void set_output(int slot);
82     void set_x(SVGLength &length);
83     void set_y(SVGLength &length);
84     void set_width(SVGLength &length);
85     void set_height(SVGLength &length);
87     /**
88      * Sets the filter primitive subregion. Passing an unset length
89      * (length._set == false) as any parameter results in that parameter
90      * not being changed.
91      * Filter primitive will not hold any references to the passed
92      * SVGLength object after function returns.
93      * If any of the parameters does not get set the default value, as
94      * defined in SVG standard, for that parameter is used instead.
95      */
96     void set_region(SVGLength &x, SVGLength &y,
97                     SVGLength &width, SVGLength &height);
99     /**
100      * Resets the filter primitive subregion to its default value
101      */
102     void reset_region();
104     /**
105      * Queries the filter, which traits it needs from its input buffers.
106      * At the time of writing this, only one trait was needed, having
107      * user coordinate system and input pixelblock coordinates paraller to
108      * each other.
109      */
110     virtual FilterTraits get_input_traits();
112 protected:
113     int _input;
114     int _output;
116     SVGLength _region_x;
117     SVGLength _region_y;
118     SVGLength _region_width;
119     SVGLength _region_height;
120 };
123 } /* namespace NR */
128 #endif /* __NR_FILTER_PRIMITIVE_H__ */
129 /*
130   Local Variables:
131   mode:c++
132   c-file-style:"stroustrup"
133   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
134   indent-tabs-mode:nil
135   fill-column:99
136   End:
137 */
138 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :