1/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkPerlinNoiseShader_DEFINED
9#define SkPerlinNoiseShader_DEFINED
10
11#include "include/core/SkShader.h"
12
13/** \class SkPerlinNoiseShader
14
15 SkPerlinNoiseShader creates an image using the Perlin turbulence function.
16
17 It can produce tileable noise if asked to stitch tiles and provided a tile size.
18 In order to fill a large area with repeating noise, set the stitchTiles flag to
19 true, and render exactly a single tile of noise. Without this flag, the result
20 will contain visible seams between tiles.
21
22 The algorithm used is described here :
23 http://www.w3.org/TR/SVG/filters.html#feTurbulenceElement
24*/
25class SK_API SkPerlinNoiseShader {
26public:
27 /**
28 * This will construct Perlin noise of the given type (Fractal Noise or Turbulence).
29 *
30 * Both base frequencies (X and Y) have a usual range of (0..1) and must be non-negative.
31 *
32 * The number of octaves provided should be fairly small, with a limit of 255 enforced.
33 * Each octave doubles the frequency, so 10 octaves would produce noise from
34 * baseFrequency * 1, * 2, * 4, ..., * 512, which quickly yields insignificantly small
35 * periods and resembles regular unstructured noise rather than Perlin noise.
36 *
37 * If tileSize isn't NULL or an empty size, the tileSize parameter will be used to modify
38 * the frequencies so that the noise will be tileable for the given tile size. If tileSize
39 * is NULL or an empty size, the frequencies will be used as is without modification.
40 */
41 static sk_sp<SkShader> MakeFractalNoise(SkScalar baseFrequencyX, SkScalar baseFrequencyY,
42 int numOctaves, SkScalar seed,
43 const SkISize* tileSize = nullptr);
44 static sk_sp<SkShader> MakeTurbulence(SkScalar baseFrequencyX, SkScalar baseFrequencyY,
45 int numOctaves, SkScalar seed,
46 const SkISize* tileSize = nullptr);
47 /**
48 * Creates an Improved Perlin Noise shader. The z value is roughly equivalent to the seed of the
49 * other two types, but minor variations to z will only slightly change the noise.
50 */
51 static sk_sp<SkShader> MakeImprovedNoise(SkScalar baseFrequencyX, SkScalar baseFrequencyY,
52 int numOctaves, SkScalar z);
53
54 static void RegisterFlattenables();
55
56private:
57 SkPerlinNoiseShader() = delete;
58};
59
60#endif
61