Add white noise pixmap generator

This commit is contained in:
Nikita Lisitsa 2020-09-13 11:07:20 +03:00
parent da7b71b504
commit 39765c9d26

View file

@ -0,0 +1,27 @@
#pragma once
#include <psemek/geom/interval.hpp>
#include <psemek/gfx/pixmap.hpp>
#include <random>
namespace psemek::pcg
{
template <typename T = float, typename RNG>
gfx::basic_pixmap<T> white(std::size_t width, std::size_t height, RNG && rng, geom::interval<T> const & range)
{
using dist = std::conditional_t<std::is_floating_point_v<T>, std::uniform_real_distribution<T>, std::uniform_int_distribution<T>>;
dist d{range.min, range.max};
gfx::basic_pixmap<T> result(width, height);
for (std::size_t x = 0; x < width; ++x)
for (std::size_t y = 0; y < height; ++y)
result(x, y) = d(rng);
return result;
}
}