Add 2d generator sampling to pixmap

This commit is contained in:
Nikita Lisitsa 2020-09-13 11:04:25 +03:00
parent 150d96e74e
commit 395df40793

View file

@ -0,0 +1,29 @@
#pragma once
#include <psemek/gfx/pixmap.hpp>
namespace psemek::pcg
{
template <typename Gen>
auto sample(Gen && gen, std::size_t width, std::size_t height)
{
using R = decltype(gen(0.f, 0.f));
gfx::basic_pixmap<R> result({width, height});
for (std::size_t j = 0; j < height; ++j)
{
for (std::size_t i = 0; i < width; ++i)
{
float ti = (i + 0.5f) / width;
float tj = (j + 0.5f) / height;
result(i, j) = gen(ti, tj);
}
}
return result;
}
}