Code

Super duper mega (fun!) commit: replaced encoding=utf-8 with fileencoding=utf-8 in...
[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 <juca@members.fsf.org>
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 Inkscape {
30 namespace Filters {
32 enum FilterTurbulenceType {
33     TURBULENCE_FRACTALNOISE,
34     TURBULENCE_TURBULENCE,
35     TURBULENCE_ENDTYPE
36 };
38 struct StitchInfo
39 {
40   int nWidth; // How much to subtract to wrap for stitching.
41   int nHeight;
42   int nWrapX; // Minimum value to wrap.
43   int nWrapY;
44 };
46 /* Produces results in the range [1, 2**31 - 2].
47 Algorithm is: r = (a * r) mod m
48 where a = 16807 and m = 2**31 - 1 = 2147483647
49 See [Park & Miller], CACM vol. 31 no. 10 p. 1195, Oct. 1988
50 To test: the algorithm should produce the result 1043618065
51 as the 10,000th generated number if the original seed is 1.
52 */
53 #define RAND_m 2147483647 /* 2**31 - 1 */
54 #define RAND_a 16807 /* 7**5; primitive root of m */
55 #define RAND_q 127773 /* m / a */
56 #define RAND_r 2836 /* m % a */
57 #define BSize 0x100
58 #define BM 0xff
59 #define PerlinN 0x1000
60 #define NP 12 /* 2^PerlinN */
61 #define NM 0xfff
62 #define s_curve(t) ( t * t * (3. - 2. * t) )
63 #define turb_lerp(t, a, b) ( a + t * (b - a) )
65 class FilterTurbulence : public FilterPrimitive {
66 public:
67     FilterTurbulence();
68     static FilterPrimitive *create();
69     virtual ~FilterTurbulence();
71     virtual int render(FilterSlot &slot, FilterUnits const &units);
72     void update_pixbuffer(NR::IRect &area, FilterUnits const &units);
73     void render_area(NRPixBlock *pix, NR::IRect &full_area, FilterUnits const &units);
75     void set_baseFrequency(int axis, double freq);
76     void set_numOctaves(int num);
77     void set_seed(double s);
78     void set_stitchTiles(bool st);
79     void set_type(FilterTurbulenceType t);
80     void set_updated(bool u);
81     virtual FilterTraits get_input_traits();
82 private:
84     long Turbulence_setup_seed(long lSeed);
85     long TurbulenceRandom(long lSeed);
86     void TurbulenceInit(long lSeed);
87     double TurbulenceNoise2(int nColorChannel, double vec[2], StitchInfo *pStitchInfo);
88     double turbulence(int nColorChannel, double *point);
90     double XbaseFrequency, YbaseFrequency;
91     int numOctaves;
92     double seed;
93     bool stitchTiles;
94     FilterTurbulenceType type;
95     bool updated;
96     NR::IRect updated_area;
97     NRPixBlock *pix;
98     unsigned char *pix_data;
100     int uLatticeSelector[BSize + BSize + 2];
101     double fGradient[4][BSize + BSize + 2][2];
103     double fTileWidth;
104     double fTileHeight;
106     double fTileX;
107     double fTileY;
108 };
110 } /* namespace Filters */
111 } /* namespace Inkscape */
113 #endif /* __NR_FILTER_TURBULENCE_H__ */
114 /*
115   Local Variables:
116   mode:c++
117   c-file-style:"stroustrup"
118   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
119   indent-tabs-mode:nil
120   fill-column:99
121   End:
122 */
123 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :