Add 2d generator sampling to pixmap
This commit is contained in:
parent
150d96e74e
commit
395df40793
1 changed files with 29 additions and 0 deletions
29
libs/pcg/include/psemek/pcg/sample.hpp
Normal file
29
libs/pcg/include/psemek/pcg/sample.hpp
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue