#include #include #include namespace psemek::pcg { static std::vector gauss_coeffs(int size, float sigma) { std::vector res(2 * size + 1); float sum = 0.f; for (int i = -size; i <= size; ++i) { float x = (i / sigma); res[i + size] = std::exp(- x * x); sum += res[i + size]; } for (auto & c : res) c /= sum; return res; } gfx::basic_pixmap blur(gfx::basic_pixmap const & p, int size, float sigma, seamless_tag) { gfx::basic_pixmap res({p.width(), p.height()}, 0.f); auto c = gauss_coeffs(size, sigma); for (int y = 0; y < p.height(); ++y) { for (int x = 0; x < p.width(); ++x) { for (int j = - size; j <= size; ++j) { for (int i = - size; i <= size; ++i) { int ix = (x + i); while (ix < 0) ix += p.width(); if (ix >= p.width()) ix = ix % p.width(); int iy = (y + j); while (iy < 0) iy += p.height(); if (iy >= p.height()) iy = iy % p.height(); res(x, y) += p(ix, iy) * c[i + size] * c[j + size]; } } } } return res; } }