Code

Refactoring work for filter effects renderer initialization
[inkscape.git] / src / display / nr-filter.h
1 #ifndef __NR_FILTER_H__
2 #define __NR_FILTER_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-arena-item.h"
16 #include "display/nr-filter-primitive.h"
17 #include "display/nr-filter-types.h"
18 #include "libnr/nr-pixblock.h"
19 #include "libnr/nr-matrix.h"
20 #include "libnr/nr-rect.h"
21 #include "svg/svg-length.h"
22 #include "sp-filter-units.h"
23 #include "gc-managed.h"
25 struct NRArenaItem;
27 namespace NR {
29 class Filter : public Inkscape::GC::Managed<> {
30 public:
31     int render(NRArenaItem const *item, NRPixBlock *pb);
33     /**
34      * Creates a new filter primitive under this filter object.
35      * New primitive is placed so that it will be executed after all filter
36      * primitives defined beforehand for this filter object.
37      * Should this filter not have enough space for a new primitive, the filter
38      * is enlarged to accomodate the new filter element. It may be enlarged by
39      * more that one element.
40      * Returns a handle (non-negative integer) to the filter primitive created.
41      * Returns -1, if type is not valid filter primitive type or filter
42      * primitive of such type cannot be created.
43      */
44     int add_primitive(FilterPrimitiveType type);
45     /**
46      * Removes all filter primitives from this filter.
47      * All pointers to filter primitives inside this filter should be
48      * considered invalid after calling this function.
49      */
50     void clear_primitives();
51     /**
52      * Replaces filter primitive pointed by 'target' with a new filter
53      * primitive of type 'type'
54      * If 'target' does not correspond to any primitive inside this filter OR
55      * 'type' is not a valid filter primitive type OR
56      * filter primitive of such type cannot be created,
57      * this function returns -1 and doesn't change the internal state of this
58      * filter.
59      * Otherwise, a new filter primitive is created. Any pointers to filter
60      * primitive 'target' should be considered invalid. A handle to the
61      * newly created primitive is returned.
62      */
63     int replace_primitive(int primitive, FilterPrimitiveType type);
65     /**
66      * Returns a pointer to the primitive, which the handle corrensponds to.
67      * If the handle is not valid, returns NULL.
68      */
69     FilterPrimitive *get_primitive(int handle);
71     /**
72      * Sets the slot number 'slot' to be used as result from this filter.
73      * If output is not set, the output from last filter primitive is used as
74      * output from the filter.
75      * It is an error to specify a pre-defined slot as 'slot'. Such call does
76      * not have any effect to the state of filter or its primitives.
77      */
78     void set_output(int slot);
80     void set_x(SVGLength &lenght);
81     void set_y(SVGLength &length);
82     void set_width(SVGLength &length);
83     void set_height(SVGLength &length);
85     /**
86      * Sets the filter effects region.
87      * Passing an unset length (length._set == false) as any of the parameters
88      * results in that parameter not being changed.
89      * Filter will not hold any references to the passed SVGLength object after
90      * function returns.
91      * If any of these parameters does not get set, the default value, as
92      * defined in SVG standard, for that parameter is used instead.
93      */
94     void set_region(SVGLength &x, SVGLength &y,
95                     SVGLength &width, SVGLength &height);
97     /**
98      * Resets the filter effects region to its default value as defined
99      * in SVG standard.
100      */
101     void reset_region();
103     /**
104      * Sets the width of intermediate images in pixels. If not set, suitable
105      * resolution is determined automatically. If x_pixels is less than zero,
106      * calling this function results in no changes to filter state.
107      */
108     void set_resolution(double x_pixels);
110     /**
111      * Sets the width and height of intermediate images in pixels. If not set,
112      * suitable resolution is determined automatically. If either parameter is
113      * less than zero, calling this function results in no changes to filter
114      * state.
115      */
116     void set_resolution(double x_pixels, double y_pixels);
118     /**
119      * Resets the filter resolution to its default value, i.e. automatically
120      * determined.
121      */
122     void reset_resolution();
124     /**
125      * Set the filterUnits-property. If not set, the default value of 
126      * objectBoundingBox is used. If the parameter value is not a
127      * valid enumeration value from SPFilterUnits, no changes to filter state
128      * are made.
129      */
130     void set_filter_units(SPFilterUnits unit);
132     /**
133      * Set the primitiveUnits-properterty. If not set, the default value of
134      * userSpaceOnUseis used. If the parameter value is not a valid
135      * enumeration value from SPFilterUnits, no changes to filter state
136      * are made.
137      */
138     void set_primitive_units(SPFilterUnits unit);
140     /** 
141      * Returns the amount of pixels the rendering area should be enlarged
142      * to prevent visual artefacts when filter needs to read pixels that
143      * are outside its output area (e.g. gaussian blur)
144      */
145     int get_enlarge(Matrix const &m);
146     /**
147      * Given an object bounding box, this function enlarges it so that
148      * it contains the filter effect area.
149      */
150     void bbox_enlarge(NRRectL &bbox);
152     /** Creates a new filter with space for one filter element */
153     Filter();
154     /** 
155      * Creates a new filter with space for n filter elements. If number of
156      * filter elements is known beforehand, it's better to use this
157      * constructor.
158      */
159     Filter(int n);
160     /** Destroys the filter and all its primitives */
161     ~Filter();
163 private:
164     int _primitive_count;
165     int _primitive_table_size;
167     /** Amount of image slots used, when this filter was rendered last time */
168     int _slot_count;
170     /** Image slot, from which filter output should be read.
171      * Negative values mean 'not set' */
172     int _output_slot;
174     SVGLength _region_x;
175     SVGLength _region_y;
176     SVGLength _region_width;
177     SVGLength _region_height;
179     /* x- and y-resolutions for filter rendering.
180      * Negative values mean 'not set'.
181      * If _y_pixels is set, _x_pixels should be set, too. */
182     double _x_pixels;
183     double _y_pixels;
185     SPFilterUnits _filter_units;
186     SPFilterUnits _primitive_units;
188     FilterPrimitive ** _primitive;
190     void _create_constructor_table();
191     void _enlarge_primitive_table();
192     void _common_init();
193 };
196 } /* namespace NR */
201 #endif /* __NR_FILTER_H__ */
202 /*
203   Local Variables:
204   mode:c++
205   c-file-style:"stroustrup"
206   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
207   indent-tabs-mode:nil
208   fill-column:99
209   End:
210 */
211 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :