Add white noise pixmap generator
This commit is contained in:
parent
da7b71b504
commit
39765c9d26
1 changed files with 27 additions and 0 deletions
27
libs/pcg/include/psemek/pcg/white.hpp
Normal file
27
libs/pcg/include/psemek/pcg/white.hpp
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue