Code

Merge and cleanup of GSoC C++-ification project.
[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-2007 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-rect-l.h"
18 #include "svg/svg-length.h"
20 namespace Inkscape {
21 namespace Filters {
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     virtual int render(FilterSlot &slot, FilterUnits const &units) = 0;
47     virtual void area_enlarge(NRRectL &area, Geom::Matrix const &m);
49     /**
50      * Sets the input slot number 'slot' to be used as input in rendering
51      * filter primitive 'primitive'
52      * For filter primitive types accepting more than one input, this sets the
53      * first input.
54      * If any of the required input slots is not set, the output of previous
55      * filter primitive is used, or SourceGraphic if this is the first
56      * primitive for this filter.
57      */
58     virtual void set_input(int slot);
60     /**
61      * Sets the input slot number 'slot' to be user as input number 'input' in
62      * rendering filter primitive 'primitive'
63      * First input for a filter primitive is number 0. For primitives with
64      * attributes 'in' and 'in2', these are numbered 0 and 1, respectively.
65      * If any of required input slots for a filter is not set, the output of
66      * previous filter primitive is used, or SourceGraphic if this is the first
67      * filter primitive for this filter.
68      */
69     virtual void set_input(int input, int slot);
71     /**
72      * Sets the slot number 'slot' to be used as output from filter primitive
73      * 'primitive'
74      * If output slot for a filter element is not set, one of the unused image
75      * slots is used.
76      * It is an error to specify a pre-defined slot as 'slot'. Such call does
77      * not have any effect to the state of filter or its primitives.
78      */
79     virtual void set_output(int slot);
81     void set_x(SVGLength &length);
82     void set_y(SVGLength &length);
83     void set_width(SVGLength &length);
84     void set_height(SVGLength &length);
86     /**
87      * Sets the filter primitive subregion. Passing an unset length
88      * (length._set == false) as any parameter results in that parameter
89      * not being changed.
90      * Filter primitive will not hold any references to the passed
91      * SVGLength object after function returns.
92      * If any of the parameters does not get set the default value, as
93      * defined in SVG standard, for that parameter is used instead.
94      */
95     void set_region(SVGLength &x, SVGLength &y,
96                     SVGLength &width, SVGLength &height);
98     /**
99      * Resets the filter primitive subregion to its default value
100      */
101     void reset_region();
103     /**
104      * Queries the filter, which traits it needs from its input buffers.
105      * At the time of writing this, only one trait was needed, having
106      * user coordinate system and input pixelblock coordinates paraller to
107      * each other.
108      */
109     virtual FilterTraits get_input_traits();
111 protected:
112     int _input;
113     int _output;
115     SVGLength _region_x;
116     SVGLength _region_y;
117     SVGLength _region_width;
118     SVGLength _region_height;
119 };
122 } /* namespace Filters */
123 } /* namespace Inkscape */
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:fileencoding=utf-8:textwidth=99 :