#ifndef OLSENNOISE_HPP #define OLSENNOISE_HPP #include "map.h" namespace OlsenNoise { using irow_type = Eigen::Array; using ibuffer_type = std::vector; // std::vector> genNoise(std::vector xgrid, // std::vector ygrid); ibuffer_type genNoise(int x_start, int y_start, int width, int height); constexpr int maxIterations = 7; namespace priv { constexpr std::array, 3> blur3x3 = { {{1, 1, 1}, {1, 1, 1}, {1, 1, 1}}}; constexpr int blurEdge = 2, scaleFactor = 2; }; // namespace priv inline void olsennoise(int iterations, irow_type& pixels, int stride, int x, int y, int width, int height); inline void olsennoise(irow_type& pixels, int stride, int x, int y, int width, int height); inline constexpr int getRequiredDim(int dim) { return dim + priv::blurEdge + priv::scaleFactor; } void convolve(irow_type& pixels, int offset, int stride, int x, int y, int width, int height, const std::array, 3>& matrix = priv::blur3x3); irow_type trim(int width, int height, const irow_type& workingpixels, int workingstride); inline unsigned hashrandom(const irow_type& elements); namespace priv { void olsennoise(irow_type& pixels, int stride, int x_within_field, int y_within_field, int width, int height, int iteration); void applyNoise(irow_type& pixels, int stride, int x_within_field, int y_within_field, int width, int height, int iteration); void applyScale(irow_type& pixels, int stride, int width, int height, int factor); void applyShift(irow_type& pixels, int stride, int shiftX, int shiftY, int width, int height); void clearValues(irow_type& pixels, int stride, int width, int height); void applyBlur(irow_type& pixels, int stride, int width, int height); inline constexpr int crimp(int color) { return (color >= 0xFF) ? 0xFF : (color < 0) ? 0 : color; } int convolve(irow_type& pixels, int stride, int index, const std::array, 3>& matrix); inline unsigned long long hash(unsigned long long hash) { unsigned long long h = hash; switch (hash & 3u) { case 3u: hash += h; hash ^= hash << 32u; hash ^= h << 36u; hash += hash >> 22u; break; case 2u: hash += h; hash ^= hash << 22u; hash += hash >> 34u; break; case 1u: hash += h; hash ^= hash << 20u; hash += hash >> 2u; } hash ^= hash << 6u; hash += hash >> 10u; hash ^= hash << 8u; hash += hash >> 34u; hash ^= hash << 50u; hash += hash >> 12u; return hash; } }; // namespace priv inline void olsennoise(int iterations, irow_type& pixels, int stride, int x, int y, int width, int height) { priv::olsennoise(pixels, stride, x, y, width, height, iterations); // Calls the main routine. } inline void olsennoise(irow_type& pixels, int stride, int x, int y, int width, int height) { priv::olsennoise(pixels, stride, x, y, width, height, maxIterations); } unsigned hashrandom(const irow_type& elements) { unsigned long long hash{0}; for (unsigned i : kblib::indirect(elements.data(), elements.data() + elements.size())) { hash ^= i; hash = priv::hash(hash); } return static_cast(hash); } }; // namespace OlsenNoise #endif // OLSENNOISE_HPP