7#ifndef SkPerlinNoiseShaderImpl_DEFINED
8#define SkPerlinNoiseShaderImpl_DEFINED
36 static constexpr int kBlockSize = 256;
37 static constexpr int kBlockMask = kBlockSize - 1;
38 static constexpr int kPerlinNoise = 4096;
39 static constexpr int kRandMaximum =
SK_MaxS32;
91 , fPermutationsBitmap(that.fPermutationsBitmap)
92 , fNoiseBitmap(that.fNoiseBitmap) {
111 static constexpr int kRandAmplitude = 16807;
112 static constexpr int kRandQ = 127773;
113 static constexpr int kRandR = 2836;
131 if (
fSeed > kRandMaximum - 1) {
132 fSeed = kRandMaximum - 1;
134 for (
int channel = 0; channel < 4; ++channel) {
135 for (
int i = 0;
i < kBlockSize; ++
i) {
137 fNoise[channel][
i][0] = (random() % (2 * kBlockSize));
138 fNoise[channel][
i][1] = (random() % (2 * kBlockSize));
141 for (
int i = kBlockSize - 1;
i > 0; --
i) {
143 int j = random() % kBlockSize;
153 uint16_t noise[4][kBlockSize][2];
154 for (
int i = 0;
i < kBlockSize; ++
i) {
155 for (
int channel = 0; channel < 4; ++channel) {
156 for (
int j = 0; j < 2; ++j) {
157 noise[channel][
i][j] =
fNoise[channel][
i][j];
162 for (
int i = 0;
i < kBlockSize; ++
i) {
163 for (
int channel = 0; channel < 4; ++channel) {
164 for (
int j = 0; j < 2; ++j) {
172 static constexpr SkScalar kHalfMax16bits = 32767.5f;
176 for (
int channel = 0; channel < 4; ++channel) {
177 for (
int i = 0;
i < kBlockSize; ++
i) {
180 (
fNoise[channel][
i][1] - kBlockSize) * kInvBlockSizef);
193 SkASSERT(tileWidth > 0 && tileHeight > 0);
230 return fPermutationsBitmap;
255 return std::make_unique<PaintingData>(fTileSize, fSeed, fBaseFrequencyX, fBaseFrequencyY);
269 const int fNumOctaves;
272 const bool fStitchTiles;
274 mutable SkOnce fInitPaintingDataOnce;
275 std::unique_ptr<PaintingData> fPaintingData;
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
#define SK_FLATTENABLE_HOOKS(type)
static constexpr float sk_ieee_float_divide(float numer, float denom)
static constexpr int32_t SK_MaxS32
#define SkScalarFloorToScalar(x)
#define SkScalarTruncToInt(x)
#define SkScalarRoundToInt(x)
#define SkScalarCeilToScalar(x)
bool installPixels(const SkImageInfo &info, void *pixels, size_t rowBytes, void(*releaseProc)(void *addr, void *context), void *context)
bool drawsNothing() const
ShaderType type() const override
friend void SkRegisterPerlinNoiseShaderFlattenable()
SkPerlinNoiseShader(SkPerlinNoiseShaderType type, SkScalar baseFrequencyX, SkScalar baseFrequencyY, int numOctaves, SkScalar seed, const SkISize *tileSize)
SkPerlinNoiseShaderType noiseType() const
bool appendStages(const SkStageRec &rec, const SkShaders::MatrixRec &mRec) const override
static const int kMaxOctaves
std::unique_ptr< PaintingData > getPaintingData() const
void flatten(SkWriteBuffer &) const override
static float min(float r, float g, float b)
constexpr int32_t width() const
void set(int32_t w, int32_t h)
constexpr int32_t height() const
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
static SkImageInfo MakeA8(int width, int height)
const SkBitmap & getNoiseBitmap() const
PaintingData(const PaintingData &that)
StitchData fStitchDataInit
PaintingData(const SkISize &tileSize, SkScalar seed, SkScalar baseFrequencyX, SkScalar baseFrequencyY)
uint16_t fNoise[4][kBlockSize][2]
const SkBitmap & getPermutationsBitmap() const
uint8_t fLatticeSelector[kBlockSize]
bool operator==(const StitchData &other) const
StitchData(SkScalar w, SkScalar h)
static constexpr SkPoint Make(float x, float y)
void set(float x, float y)