Code

fix by kur9kin for endless loop from bug 212332
[inkscape.git] / src / display / nr-filter-turbulence.h
1 #ifndef __NR_FILTER_TURBULENCE_H__
2 #define __NR_FILTER_TURBULENCE_H__
4 /*
5  * feTurbulence filter primitive renderer
6  *
7  * Authors:
8  *   World Wide Web Consortium <http://www.w3.org/>
9  *   Felipe Corrêa da Silva Sanches <felipe.sanches@gmail.com>
10  *   Niko Kiirala <niko@kiirala.com>
11  *
12  * This file has a considerable amount of code adapted from
13  *  the W3C SVG filter specs, available at:
14  *  http://www.w3.org/TR/SVG11/filters.html#feTurbulence
15  *
16  * W3C original code is licensed under the terms of
17  *  the (GPL compatible) W3C® SOFTWARE NOTICE AND LICENSE:
18  *  http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
19  *
20  * Copyright (C) 2007 authors
21  * Released under GNU GPL, read the file 'COPYING' for more information
22  */
24 #include "display/nr-filter-primitive.h"
25 #include "display/nr-filter-slot.h"
26 #include "display/nr-filter-units.h"
27 #include "libnr/nr-rect-l.h"
29 namespace NR {
31 enum FilterTurbulenceType {
32     TURBULENCE_FRACTALNOISE,
33     TURBULENCE_TURBULENCE,
34     TURBULENCE_ENDTYPE
35 };
37 struct StitchInfo
38 {
39   int nWidth; // How much to subtract to wrap for stitching.
40   int nHeight;
41   int nWrapX; // Minimum value to wrap.
42   int nWrapY;
43 };
45 /* Produces results in the range [1, 2**31 - 2].
46 Algorithm is: r = (a * r) mod m
47 where a = 16807 and m = 2**31 - 1 = 2147483647
48 See [Park & Miller], CACM vol. 31 no. 10 p. 1195, Oct. 1988
49 To test: the algorithm should produce the result 1043618065
50 as the 10,000th generated number if the original seed is 1.
51 */
52 #define RAND_m 2147483647 /* 2**31 - 1 */
53 #define RAND_a 16807 /* 7**5; primitive root of m */
54 #define RAND_q 127773 /* m / a */
55 #define RAND_r 2836 /* m % a */
56 #define BSize 0x100
57 #define BM 0xff
58 #define PerlinN 0x1000
59 #define NP 12 /* 2^PerlinN */
60 #define NM 0xfff
61 #define s_curve(t) ( t * t * (3. - 2. * t) )
62 #define turb_lerp(t, a, b) ( a + t * (b - a) )
64 class FilterTurbulence : public FilterPrimitive {
65 public:
66     FilterTurbulence();
67     static FilterPrimitive *create();
68     virtual ~FilterTurbulence();
70     virtual int render(FilterSlot &slot, FilterUnits const &units);
71     void update_pixbuffer(IRect &area, FilterUnits const &units);
72     void render_area(NRPixBlock *pix, IRect &full_area, FilterUnits const &units);
74     void set_baseFrequency(int axis, double freq);
75     void set_numOctaves(int num);
76     void set_seed(double s);
77     void set_stitchTiles(bool st);
78     void set_type(FilterTurbulenceType t);
79     void set_updated(bool u);
80     virtual FilterTraits get_input_traits();
81 private:
83     long Turbulence_setup_seed(long lSeed);
84     long TurbulenceRandom(long lSeed);
85     void TurbulenceInit(long lSeed);
86     double TurbulenceNoise2(int nColorChannel, double vec[2], StitchInfo *pStitchInfo);
87     double turbulence(int nColorChannel, double *point);
89     double XbaseFrequency, YbaseFrequency;
90     int numOctaves;
91     double seed;
92     bool stitchTiles;
93     FilterTurbulenceType type;
94     bool updated;
95     IRect updated_area;
96     NRPixBlock *pix;
97     unsigned char *pix_data;
99     int uLatticeSelector[BSize + BSize + 2];
100     double fGradient[4][BSize + BSize + 2][2];
102     double fTileWidth;
103     double fTileHeight;
105     double fTileX;
106     double fTileY;
107 };
109 } /* namespace NR */
111 #endif /* __NR_FILTER_TURBULENCE_H__ */
112 /*
113   Local Variables:
114   mode:c++
115   c-file-style:"stroustrup"
116   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
117   indent-tabs-mode:nil
118   fill-column:99
119   End:
120 */
121 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :