1/*
2 * Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org>
4 * Copyright (C) 2005 Eric Seidel <eric@webkit.org>
5 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org>
6 * Copyright (C) 2010 Renata Hodovan <reni@inf.u-szeged.hu>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB.  If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 */
23
24#ifndef FETurbulence_h
25#define FETurbulence_h
26
27#if ENABLE(FILTERS)
28#include "FilterEffect.h"
29#include "Filter.h"
30
31namespace WebCore {
32
33enum TurbulenceType {
34    FETURBULENCE_TYPE_UNKNOWN = 0,
35    FETURBULENCE_TYPE_FRACTALNOISE = 1,
36    FETURBULENCE_TYPE_TURBULENCE = 2
37};
38
39class FETurbulence : public FilterEffect {
40public:
41    static PassRefPtr<FETurbulence> create(Filter*, TurbulenceType, float, float, int, float, bool);
42
43    TurbulenceType type() const;
44    bool setType(TurbulenceType);
45
46    float baseFrequencyY() const;
47    bool setBaseFrequencyY(float);
48
49    float baseFrequencyX() const;
50    bool setBaseFrequencyX(float);
51
52    float seed() const;
53    bool setSeed(float);
54
55    int numOctaves() const;
56    bool setNumOctaves(int);
57
58    bool stitchTiles() const;
59    bool setStitchTiles(bool);
60
61    virtual void apply();
62    virtual void dump();
63
64    virtual void determineAbsolutePaintRect() { setAbsolutePaintRect(enclosingIntRect(maxEffectRect())); }
65
66    virtual TextStream& externalRepresentation(TextStream&, int indention) const;
67
68private:
69    static const int s_blockSize = 256;
70    static const int s_blockMask = s_blockSize - 1;
71
72    struct PaintingData {
73        long seed;
74        int latticeSelector[2 * s_blockSize + 2];
75        float gradient[4][2 * s_blockSize + 2][2];
76        int width; // How much to subtract to wrap for stitching.
77        int height;
78        int wrapX; // Minimum value to wrap.
79        int wrapY;
80        int channel;
81        IntSize filterSize;
82
83        PaintingData(long paintingSeed, const IntSize& paintingSize);
84        inline long random();
85    };
86
87    FETurbulence(Filter*, TurbulenceType, float, float, int, float, bool);
88
89    inline void initPaint(PaintingData&);
90    float noise2D(PaintingData&, const FloatPoint&);
91    unsigned char calculateTurbulenceValueForPoint(PaintingData&, const FloatPoint&);
92
93    TurbulenceType m_type;
94    float m_baseFrequencyX;
95    float m_baseFrequencyY;
96    int m_numOctaves;
97    float m_seed;
98    bool m_stitchTiles;
99};
100
101} // namespace WebCore
102
103#endif // ENABLE(FILTERS)
104
105#endif // FETurbulence_h
106