Skia
2DGraphicsLibrary
|
SkPerlinNoiseShader creates an image using the Perlin turbulence function. More...
#include <SkPerlinNoiseShader.h>
Classes | |
class | PerlinNoiseShaderContext |
Public Types | |
enum | Type { kFractalNoise_Type, kTurbulence_Type, kFirstType = kFractalNoise_Type, kLastType = kTurbulence_Type } |
About the noise types : the difference between the 2 is just minor tweaks to the algorithm, they're not 2 entirely different noises. More... | |
Public Types inherited from SkShader | |
enum | TileMode { kClamp_TileMode, kRepeat_TileMode, kMirror_TileMode } |
enum | { kTileModeCount = kMirror_TileMode + 1 } |
enum | Flags { kOpaqueAlpha_Flag = 1 << 0, kConstInY32_Flag = 1 << 1, kPrefers4f_Flag = 1 << 2 } |
enum | GradientType { kNone_GradientType, kColor_GradientType, kLinear_GradientType, kRadial_GradientType, kSweep_GradientType, kConical_GradientType, kLast_GradientType = kConical_GradientType } |
If the shader subclass can be represented as a gradient, asAGradient returns the matching GradientType enum (or kNone_GradientType if it cannot). More... | |
Public Types inherited from SkFlattenable | |
enum | Type { kSkColorFilter_Type, kSkDrawable_Type, kSkDrawLooper_Type, kSkImageFilter_Type, kSkMaskFilter_Type, kSkPathEffect_Type, kSkPixelRef_Type, kSkRasterizer_Type, kSkShader_Type, kSkUnused_Type, kSkXfermode_Type, kSkNormalSource_Type } |
typedef sk_sp< SkFlattenable >(* | Factory )(SkReadBuffer &) |
Static Public Member Functions | |
static sk_sp< SkShader > | MakeFractalNoise (SkScalar baseFrequencyX, SkScalar baseFrequencyY, int numOctaves, SkScalar seed, const SkISize *tileSize=nullptr) |
This will construct Perlin noise of the given type (Fractal Noise or Turbulence). More... | |
static sk_sp< SkShader > | MakeTurbulence (SkScalar baseFrequencyX, SkScalar baseFrequencyY, int numOctaves, SkScalar seed, const SkISize *tileSize=nullptr) |
Static Public Member Functions inherited from SkShader | |
static sk_sp< SkShader > | MakeEmptyShader () |
Call this to create a new "empty" shader, that will not draw anything. | |
static sk_sp< SkShader > | MakeColorShader (SkColor) |
Call this to create a new shader that just draws the specified color. More... | |
static sk_sp< SkShader > | MakeColorShader (const SkColor4f &, sk_sp< SkColorSpace >) |
Create a shader that draws the specified color (in the specified colorspace). More... | |
static sk_sp< SkShader > | MakeComposeShader (sk_sp< SkShader > dst, sk_sp< SkShader > src, SkXfermode::Mode) |
static sk_sp< SkShader > | MakeComposeShader (sk_sp< SkShader > dst, sk_sp< SkShader > src, sk_sp< SkXfermode > xfer) |
Create a new compose shader, given shaders dst, src, and a combining xfermode mode. More... | |
static sk_sp< SkShader > | MakeBitmapShader (const SkBitmap &src, TileMode tmx, TileMode tmy, const SkMatrix *localMatrix=nullptr) |
Call this to create a new shader that will draw with the specified bitmap. More... | |
static sk_sp< SkShader > | MakePictureShader (sk_sp< SkPicture > src, TileMode tmx, TileMode tmy, const SkMatrix *localMatrix, const SkRect *tile) |
Call this to create a new shader that will draw with the specified picture. More... | |
Static Public Member Functions inherited from SkFlattenable | |
static Factory | NameToFactory (const char name[]) |
static const char * | FactoryToName (Factory) |
static bool | NameToType (const char name[], Type *type) |
static void | Register (const char name[], Factory, Type) |
Protected Member Functions | |
void | flatten (SkWriteBuffer &) const override |
Override this if your subclass needs to record data that it will need to recreate itself from its CreateProc (returned by getFactory()). | |
Context * | onCreateContext (const ContextRec &, void *storage) const override |
Your subclass must also override contextSize() if it overrides onCreateContext(). More... | |
size_t | onContextSize (const ContextRec &) const override |
Override this if your subclass overrides createContext, to return the correct size of your subclass' context. | |
Protected Member Functions inherited from SkShader | |
bool | computeTotalInverse (const ContextRec &, SkMatrix *totalInverse) const |
virtual bool | onAsLuminanceColor (SkColor *) const |
virtual bool | onIsABitmap (SkBitmap *, SkMatrix *, TileMode[2]) const |
virtual SkImage * | onIsAImage (SkMatrix *, TileMode[2]) const |
Protected Member Functions inherited from SkRefCntBase | |
void | internal_dispose_restore_refcnt_to_1 () const |
Allow subclasses to call this if they've overridden internal_dispose so they can reset fRefCnt before the destructor is called or if they choose not to call the destructor (e.g. More... | |
Private Types | |
typedef SkShader | INHERITED |
Private Member Functions | |
SkPerlinNoiseShader (SkPerlinNoiseShader::Type type, SkScalar baseFrequencyX, SkScalar baseFrequencyY, int numOctaves, SkScalar seed, const SkISize *tileSize) | |
Private Attributes | |
const SkPerlinNoiseShader::Type | fType |
const SkScalar | fBaseFrequencyX |
const SkScalar | fBaseFrequencyY |
const int | fNumOctaves |
const SkScalar | fSeed |
const SkISize | fTileSize |
const bool | fStitchTiles |
Additional Inherited Members | |
Public Member Functions inherited from SkShader | |
SkShader (const SkMatrix *localMatrix=NULL) | |
const SkMatrix & | getLocalMatrix () const |
Returns the local matrix. More... | |
virtual bool | isOpaque () const |
Returns true if the shader is guaranteed to produce only opaque colors, subject to the SkPaint using the shader to apply an opaque alpha value. More... | |
Context * | createContext (const ContextRec &, void *storage) const |
Create the actual object that does the shading. More... | |
size_t | contextSize (const ContextRec &) const |
Return the size of a Context returned by createContext. | |
bool | isABitmap (SkBitmap *outTexture, SkMatrix *outMatrix, TileMode xy[2]) const |
Returns true if this shader is just a bitmap, and if not null, returns the bitmap, localMatrix, and tilemodes. More... | |
bool | isABitmap () const |
SkImage * | isAImage (SkMatrix *localMatrix, TileMode xy[2]) const |
Iff this shader is backed by a single SkImage, return its ptr (the caller must ref this if they want to keep it longer than the lifetime of the shader). More... | |
bool | isAImage () const |
virtual GradientType | asAGradient (GradientInfo *info) const |
virtual bool | asACompose (ComposeRec *) const |
virtual sk_sp < GrFragmentProcessor > | asFragmentProcessor (const AsFPArgs &) const |
Returns a GrFragmentProcessor that implements the shader for the GPU backend. More... | |
bool | asLuminanceColor (SkColor *) const |
If the shader can represent its "average" luminance in a single color, return true and if color is not NULL, return that color. More... | |
sk_sp< SkShader > | makeWithLocalMatrix (const SkMatrix &) const |
Return a shader that will apply the specified localMatrix to this shader. More... | |
sk_sp< SkShader > | makeWithColorFilter (sk_sp< SkColorFilter >) const |
Create a new shader that produces the same colors as invoking this shader and then applying the colorfilter. | |
virtual SkShader * | refAsALocalMatrixShader (SkMatrix *localMatrix) const |
If this shader can be represented by another shader + a localMatrix, return that shader and, if not NULL, the localMatrix. More... | |
Public Member Functions inherited from SkFlattenable | |
virtual Factory | getFactory () const =0 |
Implement this to return a factory function pointer that can be called to recreate your class given a buffer (previously written to by your override of flatten(). | |
virtual const char * | getTypeName () const |
Returns the name of the object's class. More... | |
Public Member Functions inherited from SkRefCntBase | |
SkRefCntBase () | |
Default construct, initializing the reference count to 1. | |
virtual | ~SkRefCntBase () |
Destruct, asserting that the reference count is 1. | |
int32_t | getRefCnt () const |
Return the reference count. More... | |
void | validate () const |
bool | unique () const |
May return true if the caller is the only owner. More... | |
void | ref () const |
Increment the reference count. More... | |
void | unref () const |
Decrement the reference count. More... | |
SkPerlinNoiseShader creates an image using the Perlin turbulence function.
It can produce tileable noise if asked to stitch tiles and provided a tile size. In order to fill a large area with repeating noise, set the stitchTiles flag to true, and render exactly a single tile of noise. Without this flag, the result will contain visible seams between tiles.
The algorithm used is described here : http://www.w3.org/TR/SVG/filters.html#feTurbulenceElement
About the noise types : the difference between the 2 is just minor tweaks to the algorithm, they're not 2 entirely different noises.
The output looks different, but once the noise is generated in the [1, -1] range, the output is brought back in the [0, 1] range by doing : kFractalNoise_Type : noise * 0.5 + 0.5 kTurbulence_Type : abs(noise) Very little differences between the 2 types, although you can tell the difference visually.
|
static |
This will construct Perlin noise of the given type (Fractal Noise or Turbulence).
Both base frequencies (X and Y) have a usual range of (0..1).
The number of octaves provided should be fairly small, although no limit is enforced. Each octave doubles the frequency, so 10 octaves would produce noise from baseFrequency * 1, * 2, * 4, ..., * 512, which quickly yields insignificantly small periods and resembles regular unstructured noise rather than Perlin noise.
If tileSize isn't NULL or an empty size, the tileSize parameter will be used to modify the frequencies so that the noise will be tileable for the given tile size. If tileSize is NULL or an empty size, the frequencies will be used as is without modification.
|
overrideprotectedvirtual |
Your subclass must also override contextSize() if it overrides onCreateContext().
Base class impl returns NULL.
Reimplemented from SkShader.