1 #ifndef __NR_FILTER_TURBULENCE_H__
2 #define __NR_FILTER_TURBULENCE_H__
4 /*
5 * feTurbulence filter primitive renderer
6 *
7 * Authors:
8 * Felipe Sanches <felipe.sanches@gmail.com>
9 * Niko Kiirala <niko@kiirala.com>
10 *
11 * Copyright (C) 2007 authors
12 *
13 * Released under GNU GPL, read the file 'COPYING' for more information
14 */
16 #include "display/nr-filter-primitive.h"
17 #include "display/nr-filter-slot.h"
18 #include "display/nr-filter-units.h"
19 #include "libnr/nr-rect-l.h"
21 namespace NR {
23 enum FilterTurbulenceType {
24 TURBULENCE_FRACTALNOISE,
25 TURBULENCE_TURBULENCE,
26 TURBULENCE_ENDTYPE
27 };
29 struct StitchInfo
30 {
31 int nWidth; // How much to subtract to wrap for stitching.
32 int nHeight;
33 int nWrapX; // Minimum value to wrap.
34 int nWrapY;
35 };
37 /* Produces results in the range [1, 2**31 - 2].
38 Algorithm is: r = (a * r) mod m
39 where a = 16807 and m = 2**31 - 1 = 2147483647
40 See [Park & Miller], CACM vol. 31 no. 10 p. 1195, Oct. 1988
41 To test: the algorithm should produce the result 1043618065
42 as the 10,000th generated number if the original seed is 1.
43 */
44 #define RAND_m 2147483647 /* 2**31 - 1 */
45 #define RAND_a 16807 /* 7**5; primitive root of m */
46 #define RAND_q 127773 /* m / a */
47 #define RAND_r 2836 /* m % a */
48 #define BSize 0x100
49 #define BM 0xff
50 #define PerlinN 0x1000
51 #define NP 12 /* 2^PerlinN */
52 #define NM 0xfff
53 #define s_curve(t) ( t * t * (3. - 2. * t) )
54 #define turb_lerp(t, a, b) ( a + t * (b - a) )
56 class FilterTurbulence : public FilterPrimitive {
57 public:
58 FilterTurbulence();
59 static FilterPrimitive *create();
60 virtual ~FilterTurbulence();
62 virtual int render(FilterSlot &slot, FilterUnits const &units);
63 void update_pixbuffer(FilterSlot &slot, IRect &area);
65 void set_baseFrequency(int axis, double freq);
66 void set_numOctaves(int num);
67 void set_seed(double s);
68 void set_stitchTiles(bool st);
69 void set_type(FilterTurbulenceType t);
70 void set_updated(bool u);
71 virtual FilterTraits get_input_traits();
72 private:
74 long Turbulence_setup_seed(long lSeed);
75 long TurbulenceRandom(long lSeed);
76 void TurbulenceInit(long lSeed);
77 double TurbulenceNoise2(int nColorChannel, double vec[2], StitchInfo *pStitchInfo);
78 double turbulence(int nColorChannel, double *point);
80 double XbaseFrequency, YbaseFrequency;
81 int numOctaves;
82 double seed;
83 bool stitchTiles;
84 FilterTurbulenceType type;
85 bool updated;
86 IRect updated_area;
87 NRPixBlock *pix;
88 unsigned char *pix_data;
90 int uLatticeSelector[BSize + BSize + 2];
91 double fGradient[4][BSize + BSize + 2][2];
93 double fTileWidth;
94 double fTileHeight;
96 double fTileX;
97 double fTileY;
98 };
100 } /* namespace NR */
102 #endif /* __NR_FILTER_TURBULENCE_H__ */
103 /*
104 Local Variables:
105 mode:c++
106 c-file-style:"stroustrup"
107 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
108 indent-tabs-mode:nil
109 fill-column:99
110 End:
111 */
112 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :