Code

c1012475c3bdb3bb2e715e616e1332422a3e98c4
[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 pointer to the filter primitive created.
41      * Returns NULL, if type is not valid filter primitive type or filter
42      * primitive of such type cannot be created.
43      */
44     FilterPrimitive *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 NULL 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 pointer to the
61      * newly created primitive is returned.
62      */
63     FilterPrimitive *replace_primitive(FilterPrimitive *primitive,
64                                        FilterPrimitiveType type);
66     /**
67      * Sets the slot number 'slot' to be used as result from this filter.
68      * If output is not set, the output from last filter primitive is used as
69      * output from the filter.
70      * It is an error to specify a pre-defined slot as 'slot'. Such call does
71      * not have any effect to the state of filter or its primitives.
72      */
73     void set_output(int slot);
75     void set_x(SVGLength &lenght);
76     void set_y(SVGLength &length);
77     void set_width(SVGLength &length);
78     void set_height(SVGLength &length);
80     /**
81      * Sets the filter effects region.
82      * Passing an unset length (length._set == false) as any of the parameters
83      * results in that parameter not being changed.
84      * Filter will not hold any references to the passed SVGLength object after
85      * function returns.
86      * If any of these parameters does not get set, the default value, as
87      * defined in SVG standard, for that parameter is used instead.
88      */
89     void set_region(SVGLength &x, SVGLength &y,
90                     SVGLength &width, SVGLength &height);
92     /**
93      * Resets the filter effects region to its default value as defined
94      * in SVG standard.
95      */
96     void reset_region();
98     /**
99      * Sets the width of intermediate images in pixels. If not set, suitable
100      * resolution is determined automatically. If x_pixels is less than zero,
101      * calling this function results in no changes to filter state.
102      */
103     void set_resolution(double x_pixels);
105     /**
106      * Sets the width and height of intermediate images in pixels. If not set,
107      * suitable resolution is determined automatically. If either parameter is
108      * less than zero, calling this function results in no changes to filter
109      * state.
110      */
111     void set_resolution(double x_pixels, double y_pixels);
113     /**
114      * Resets the filter resolution to its default value, i.e. automatically
115      * determined.
116      */
117     void reset_resolution();
119     /**
120      * Set the filterUnits-property. If not set, the default value of 
121      * objectBoundingBox is used. If the parameter value is not a
122      * valid enumeration value from SPFilterUnits, no changes to filter state
123      * are made.
124      */
125     void set_filter_units(SPFilterUnits unit);
127     /**
128      * Set the primitiveUnits-properterty. If not set, the default value of
129      * userSpaceOnUseis used. If the parameter value is not a valid
130      * enumeration value from SPFilterUnits, no changes to filter state
131      * are made.
132      */
133     void set_primitive_units(SPFilterUnits unit);
135     /** 
136      * Returns the amount of pixels the rendering area should be enlarged
137      * to prevent visual artefacts when filter needs to read pixels that
138      * are outside its output area (e.g. gaussian blur)
139      */
140     int get_enlarge(Matrix const &m);
141     /**
142      * Given an object bounding box, this function enlarges it so that
143      * it contains the filter effect area.
144      */
145     void bbox_enlarge(NRRectL &bbox);
147     /** Creates a new filter with space for one filter element */
148     Filter();
149     /** 
150      * Creates a new filter with space for n filter elements. If number of
151      * filter elements is known beforehand, it's better to use this
152      * constructor.
153      */
154     Filter(int n);
155     /** Destroys the filter and all its primitives */
156     ~Filter();
158 private:
159     int _primitive_count;
160     int _primitive_table_size;
162     /** Amount of image slots used, when this filter was rendered last time */
163     int _slot_count;
165     /** Image slot, from which filter output should be read.
166      * Negative values mean 'not set' */
167     int _output_slot;
169     SVGLength _region_x;
170     SVGLength _region_y;
171     SVGLength _region_width;
172     SVGLength _region_height;
174     /* x- and y-resolutions for filter rendering.
175      * Negative values mean 'not set'.
176      * If _y_pixels is set, _x_pixels should be set, too. */
177     double _x_pixels;
178     double _y_pixels;
180     SPFilterUnits _filter_units;
181     SPFilterUnits _primitive_units;
183     FilterPrimitive ** _primitive;
185     void _create_constructor_table();
186     void _enlarge_primitive_table();
187     void _common_init();
188 };
191 } /* namespace NR */
196 #endif /* __NR_FILTER_H__ */
197 /*
198   Local Variables:
199   mode:c++
200   c-file-style:"stroustrup"
201   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
202   indent-tabs-mode:nil
203   fill-column:99
204   End:
205 */
206 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :