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 * Copyright (C) 2013 Google Inc. All rights reserved.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public License
20 * along with this library; see the file COPYING.LIB. If not, write to
21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
25 #ifndef FETurbulence_h
26 #define FETurbulence_h
28 #include "platform/graphics/filters/Filter.h"
29 #include "platform/graphics/filters/FilterEffect.h"
34 FETURBULENCE_TYPE_UNKNOWN = 0,
35 FETURBULENCE_TYPE_FRACTALNOISE = 1,
36 FETURBULENCE_TYPE_TURBULENCE = 2
39 class PLATFORM_EXPORT FETurbulence : public FilterEffect {
41 static PassRefPtr<FETurbulence> create(Filter*, TurbulenceType, float, float, int, float, bool);
43 TurbulenceType type() const;
44 bool setType(TurbulenceType);
46 float baseFrequencyY() const;
47 bool setBaseFrequencyY(float);
49 float baseFrequencyX() const;
50 bool setBaseFrequencyX(float);
55 int numOctaves() const;
56 bool setNumOctaves(int);
58 bool stitchTiles() const;
59 bool setStitchTiles(bool);
61 static void fillRegionWorker(void*);
63 virtual TextStream& externalRepresentation(TextStream&, int indention) const OVERRIDE;
66 static const int s_blockSize = 256;
67 static const int s_blockMask = s_blockSize - 1;
69 static const int s_minimalRectDimension = (100 * 100); // Empirical data limit for parallel jobs.
72 PaintingData(long paintingSeed, const IntSize& paintingSize)
74 , filterSize(paintingSize)
79 int latticeSelector[2 * s_blockSize + 2];
80 float gradient[4][2 * s_blockSize + 2][2];
95 int width; // How much to subtract to wrap for stitching.
96 int wrapX; // Minimum value to wrap.
101 template<typename Type>
102 friend class ParallelJobs;
104 struct FillRegionParameters {
105 FETurbulence* filter;
106 Uint8ClampedArray* pixelArray;
107 PaintingData* paintingData;
110 float baseFrequencyX;
111 float baseFrequencyY;
114 static void fillRegionWorker(FillRegionParameters*);
116 FETurbulence(Filter*, TurbulenceType, float, float, int, float, bool);
118 virtual void applySoftware() OVERRIDE;
119 virtual PassRefPtr<SkImageFilter> createImageFilter(SkiaImageFilterBuilder*) OVERRIDE;
120 SkShader* createShader();
122 inline void initPaint(PaintingData&);
123 float noise2D(int channel, PaintingData&, StitchData&, const FloatPoint&);
124 unsigned char calculateTurbulenceValueForPoint(int channel, PaintingData&, StitchData&, const FloatPoint&, float, float);
125 inline void fillRegion(Uint8ClampedArray*, PaintingData&, int, int, float, float);
127 TurbulenceType m_type;
128 float m_baseFrequencyX;
129 float m_baseFrequencyY;
135 } // namespace WebCore
137 #endif // FETurbulence_h